Skip to content

Commit

Permalink
Adds a client-defined sort order for loading chunks
Browse files Browse the repository at this point in the history
Changes chunk add logic to process neighborhood in sorted order without
re-sorting each time
Also renames some `world` properties to be internal
Should fix fenomas#168
  • Loading branch information
fenomas committed Sep 28, 2021
1 parent c902f9f commit 2cead27
Show file tree
Hide file tree
Showing 6 changed files with 239 additions and 149 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ See [history.md](docs/history.md) for changes and migration for each version.
Recent changes:

* `v0.31`:
* Change the speed of the world with `noa.timeScale`
* Change the speed of the world! See `noa.timeScale`
* Now possible to control chunk processing order: `noa.world.chunkSortingDistFn`
* `v0.30`:
* Engine now a named class, use `import {Engine} from 'noa-engine'`
* many performance and size optimizations
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "noa-engine",
"version": "0.30.0",
"version": "0.31.0",
"description": "Experimental voxel game engine",
"main": "src/index.js",
"typings": "dist/src/index.d.ts",
Expand Down
4 changes: 4 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,10 @@ function deprecateStuff(noa) {
ver = '0.30'
dep(noa, '_tickRate', 'tickRate is now at `noa.tickRate`')
dep(noa.container, '_tickRate', 'tickRate is now at `noa.tickRate`')
ver = '0.31'
dep(noa.world, 'chunkSize', 'effectively an internal, so changed to `_chunkSize`')
dep(noa.world, 'chunkAddDistance', 'set this with `noa.world.setAddRemoveDistance`')
dep(noa.world, 'chunkRemoveDistance', 'set this with `noa.world.setAddRemoveDistance`')
}


Expand Down
2 changes: 1 addition & 1 deletion src/lib/sceneOctreeManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export class SceneOctreeManager {
*/

var NOP = () => { }
var bs = blockSize * rendering.noa.world.chunkSize
var bs = blockSize * rendering.noa.world._chunkSize

var recurseRebaseBlocks = (parent, offset) => {
parent.blocks.forEach(child => {
Expand Down
12 changes: 9 additions & 3 deletions src/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ function doNdarrayZero(tgt, i0, j0, k0, si, sj, sk) {



// iterate over 3D locations a fixed area from the origin
// and exiting if the callback returns true
// iterates over 3D positions a given manhattan distance from (0,0,0)
// and exit early if the callback returns true
// skips locations beyond a horiz or vertical max distance
export function iterateOverShellAtDistance(d, xmax, ymax, cb) {
if (d === 0) return cb(0, 0, 0)
Expand Down Expand Up @@ -193,6 +193,12 @@ LocationQueue.prototype.add = function (i, j, k) {
this.arr.push([i, j, k, id])
this.hash[id] = true
}
LocationQueue.prototype.addToFront = function (i, j, k) {
var id = locationHasher(i, j, k)
if (this.hash[id]) return
this.arr.unshift([i, j, k, id])
this.hash[id] = true
}
LocationQueue.prototype.removeByIndex = function (ix) {
var el = this.arr[ix]
delete this.hash[el[3]]
Expand Down Expand Up @@ -228,7 +234,7 @@ LocationQueue.prototype.copyFrom = function (queue) {
}
LocationQueue.prototype.sortByDistance = function (locToDist) {
var hash = {}
for (var loc of this.arr) hash[loc] = locToDist(loc)
for (var loc of this.arr) hash[loc] = locToDist(loc[0], loc[1], loc[2])
this.arr.sort((a, b) => hash[b] - hash[a]) // DESCENDING!
hash = null
}
Expand Down
Loading

0 comments on commit 2cead27

Please sign in to comment.