@divinevoxel/vlox 0.0.5 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Contexts/Base/Remote/InitWorldDataSync.js +2 -4
- package/Contexts/Render/DVERenderThreads.d.ts +1 -1
- package/Contexts/Render/DVERenderThreads.js +2 -2
- package/Contexts/Render/DivineVoxelEngineRender.d.ts +5 -5
- package/Contexts/Render/DivineVoxelEngineRender.js +1 -1
- package/Contexts/World/DivineVoxelEngineWorld.d.ts +5 -5
- package/Init/StartRenderer.js +5 -5
- package/Math/Indexing.js +6 -6
- package/Mesher/Functions/CompactVoxelMesh.js +40 -7
- package/Mesher/Functions/MeshSection.js +16 -9
- package/Mesher/Functions/MeshTexture.d.ts +1 -1
- package/Mesher/Functions/MeshVoxel.js +5 -4
- package/Mesher/Geomtry/Buffers.d.ts +19 -0
- package/Mesher/Geomtry/Buffers.js +81 -0
- package/Mesher/Geomtry/Tools/MesherDataTools.d.ts +3 -3
- package/Mesher/Geomtry/Tools/MesherDataTools.js +2 -2
- package/Mesher/Geomtry/VoxelGeometryBuilder.js +3 -3
- package/Mesher/Geomtry/VoxelMesh.d.ts +12 -0
- package/Mesher/Geomtry/VoxelMesh.js +25 -0
- package/Mesher/InitTask.js +1 -2
- package/Mesher/Models/Common/BoxGeometryNode.js +2 -1
- package/Mesher/Models/Nodes/Ruled/BoxVoxelGeometryNode.js +10 -7
- package/Mesher/Models/Nodes/Ruled/QuadVoxelGeometryNode.js +7 -7
- package/Mesher/Models/Nodes/VoxelGeometryConstructor.js +1 -1
- package/Mesher/Models/VoxelConstructor.d.ts +0 -2
- package/Mesher/Models/VoxelConstructor.js +9 -15
- package/Mesher/Models/VoxelGeometryLookUp.d.ts +20 -11
- package/Mesher/Models/VoxelGeometryLookUp.js +84 -50
- package/Mesher/Tools/VoxelMeshBVHBuilder.js +20 -25
- package/Mesher/Tools/VoxelMeshVertexStructCursor.d.ts +3 -1
- package/Mesher/Tools/VoxelMesherDataTool.d.ts +3 -2
- package/Mesher/Tools/VoxelMesherDataTool.js +8 -3
- package/Renderer/Classes/DVESectionMeshes.d.ts +1 -0
- package/Renderer/Classes/SectionMesh.d.ts +1 -2
- package/Renderer/Classes/SectionMesh.js +0 -3
- package/Renderer/InitTasks.js +16 -1
- package/Renderer/MeshManager.js +4 -0
- package/Renderer/MeshRegister.d.ts +1 -6
- package/Renderer/index.d.ts +0 -1
- package/Renderer/index.js +0 -1
- package/Settings/EngineSettings.d.ts +5 -5
- package/Settings/EngineSettings.js +15 -15
- package/Settings/EngineSettings.types.d.ts +62 -44
- package/Settings/EngineSettings.types.js +44 -42
- package/Tasks/IWG/IWG.d.ts +3 -0
- package/Tasks/IWG/IWG.js +3 -0
- package/Tasks/IWG/Internal/Functions/cullSectors.js +1 -2
- package/Tasks/IWG/Internal/Functions/getSectorState.js +1 -1
- package/Tasks/IWG/Internal/Functions/runBuildUpdate.js +1 -2
- package/Tasks/IWG/Internal/Functions/runWorldUpdate.js +1 -2
- package/Tasks/IWG/Internal/IWGTasks.js +7 -13
- package/Tasks/Propagation/Explosion/ExplosionManager.js +1 -1
- package/Tasks/Propagation/Flow/WorldFlow.js +6 -8
- package/Tasks/Propagation/Illumanation/RGBUpdate.js +2 -2
- package/Tasks/Propagation/Illumanation/WorldRGB.js +2 -3
- package/Tasks/Propagation/Illumanation/WorldSun.js +11 -5
- package/Tasks/Update/VoxelUpdate.js +21 -26
- package/Tasks/WorldGeneration/WorldGenRegister.js +5 -8
- package/Tasks/WorldGeneration/WorldGeneration.d.ts +0 -2
- package/Tasks/WorldGeneration/WorldGeneration.js +0 -2
- package/Templates/Cursor/TemplateVoxelCursor.d.ts +1 -0
- package/Templates/Cursor/TemplateVoxelCursor.js +1 -0
- package/Textures/TextureBuilder.d.ts +1 -1
- package/Textures/TextureBuilder.js +1 -1
- package/Textures/TextureManager.js +1 -1
- package/Tools/Brush/Brush.d.ts +1 -0
- package/Tools/Brush/Brush.js +8 -11
- package/Voxels/Cursor/VoxelCursor.d.ts +1 -0
- package/Voxels/Cursor/VoxelCursor.interface.d.ts +5 -0
- package/Voxels/Cursor/VoxelCursor.interface.js +5 -5
- package/Voxels/Cursor/VoxelCursor.js +5 -3
- package/Voxels/VoxelLevelReader.d.ts +10 -0
- package/Voxels/VoxelLevelReader.js +20 -0
- package/World/Archive/Functions/ArchiveSector.d.ts +1 -1
- package/World/Archive/Functions/ArchiveSector.js +2 -3
- package/World/Archive/InitTasks.js +2 -3
- package/World/Cursor/SectionCursor.js +1 -2
- package/World/Cursor/SectorCursor.d.ts +1 -0
- package/World/Cursor/SectorCursor.js +8 -3
- package/World/Cursor/WorldCursor.js +1 -2
- package/World/Cursor/WorldVoxelCursor.d.ts +1 -5
- package/World/Cursor/WorldVoxelCursor.js +1 -5
- package/World/InitTasks.js +5 -10
- package/World/Lock/WorldLock.js +4 -5
- package/World/Sector/SectorHeightMap.js +4 -6
- package/World/WorldRegister.d.ts +4 -6
- package/World/WorldRegister.js +24 -20
- package/World/WorldSpaces.d.ts +21 -0
- package/World/WorldSpaces.js +58 -7
- package/package.json +1 -1
- package/Mesher/Geomtry/Mesh.d.ts +0 -11
- package/Mesher/Geomtry/Mesh.js +0 -23
- package/Renderer/Classes/DVESectionMeshInterface.d.ts +0 -3
- package/Renderer/Classes/DVESectionMeshInterface.js +0 -1
- package/Voxels/VoxelStateReader.d.ts +0 -12
- package/Voxels/VoxelStateReader.js +0 -30
- package/World/WorldBounds.d.ts +0 -20
- package/World/WorldBounds.js +0 -53
|
@@ -4,7 +4,7 @@ export declare class TextureBuilder {
|
|
|
4
4
|
static finalImagWidth: number;
|
|
5
5
|
static finalImageHeight: number;
|
|
6
6
|
static _canvas: HTMLCanvasElement;
|
|
7
|
-
static defineTextureDimensions(textureSize: number
|
|
7
|
+
static defineTextureDimensions(textureSize: number): void;
|
|
8
8
|
static setUpImageCreation(): void;
|
|
9
9
|
static createMaterialTexture(name: string, images: Map<string, HTMLImageElement | string | false>, width?: number, height?: number): Promise<HTMLImageElement[]>;
|
|
10
10
|
static getRawData(imageSrc: string): Promise<Uint8ClampedArray>;
|
|
@@ -4,7 +4,7 @@ export class TextureBuilder {
|
|
|
4
4
|
static finalImagWidth = 16;
|
|
5
5
|
static finalImageHeight = 16;
|
|
6
6
|
static _canvas = document.createElement("canvas");
|
|
7
|
-
static defineTextureDimensions(textureSize
|
|
7
|
+
static defineTextureDimensions(textureSize) {
|
|
8
8
|
this.finalImagWidth = textureSize < 256 ? 256 : textureSize;
|
|
9
9
|
this.finalImageHeight = textureSize < 256 ? 256 : textureSize;
|
|
10
10
|
this._textureSize = textureSize;
|
|
@@ -17,7 +17,7 @@ export class TextureManager {
|
|
|
17
17
|
return this._ready;
|
|
18
18
|
}
|
|
19
19
|
static async init() {
|
|
20
|
-
TextureBuilder.defineTextureDimensions(EngineSettings.settings.textures.textureSize
|
|
20
|
+
TextureBuilder.defineTextureDimensions(EngineSettings.settings.textures.textureSize);
|
|
21
21
|
for (const [key, type] of this.textureTypes) {
|
|
22
22
|
await type.build();
|
|
23
23
|
}
|
package/Tools/Brush/Brush.d.ts
CHANGED
package/Tools/Brush/Brush.js
CHANGED
|
@@ -29,8 +29,7 @@ export class BrushTool {
|
|
|
29
29
|
return this;
|
|
30
30
|
}
|
|
31
31
|
newSector() {
|
|
32
|
-
WorldRegister.
|
|
33
|
-
WorldRegister.sectors.new(this.x, this.y, this.z);
|
|
32
|
+
WorldRegister.sectors.new(this.dimension, this.x, this.y, this.z);
|
|
34
33
|
}
|
|
35
34
|
setData(data) {
|
|
36
35
|
this.data.id = data.id ? data.id : airId;
|
|
@@ -103,6 +102,7 @@ export class BrushTool {
|
|
|
103
102
|
this.y = 0;
|
|
104
103
|
this.z = 0;
|
|
105
104
|
}
|
|
105
|
+
_debug = false;
|
|
106
106
|
_paint() {
|
|
107
107
|
if (!this.dataCursor.inBounds(this.x, this.y, this.z))
|
|
108
108
|
return false;
|
|
@@ -113,7 +113,10 @@ export class BrushTool {
|
|
|
113
113
|
if (id < 0)
|
|
114
114
|
return false;
|
|
115
115
|
voxel.setId(id);
|
|
116
|
-
|
|
116
|
+
if (this._debug) {
|
|
117
|
+
console.warn(this.x, this.y, this.z, this.data.state);
|
|
118
|
+
}
|
|
119
|
+
voxel.setState(this.data.state);
|
|
117
120
|
voxel.setLevel(this.data.level);
|
|
118
121
|
voxel.setMod(this.data.mod);
|
|
119
122
|
if (this.data.secondaryVoxelId) {
|
|
@@ -127,19 +130,13 @@ export class BrushTool {
|
|
|
127
130
|
if (voxel.isLightSource() && voxel.getLightSourceValue()) {
|
|
128
131
|
voxel.setLight(voxel.getLightSourceValue());
|
|
129
132
|
}
|
|
130
|
-
|
|
131
|
-
DataHooks.paint.onRichVoxelPaint.notify([
|
|
132
|
-
this.voxelCursor.getStringId(),
|
|
133
|
-
[this.dimenion, x, y, z],
|
|
134
|
-
]);
|
|
135
|
-
} */
|
|
136
|
-
voxel.updateHeightMap(0);
|
|
133
|
+
voxel.updateVoxel(0);
|
|
137
134
|
}
|
|
138
135
|
_erase() {
|
|
139
136
|
const voxel = this.dataCursor.getVoxel(this.x, this.y, this.z);
|
|
140
137
|
if (!voxel)
|
|
141
138
|
return;
|
|
142
|
-
voxel.copyRaw(air).
|
|
139
|
+
voxel.copyRaw(air).updateVoxel(1);
|
|
143
140
|
}
|
|
144
141
|
paint() {
|
|
145
142
|
this._paint();
|
|
@@ -19,6 +19,11 @@ export declare abstract class VoxelCursorInterface {
|
|
|
19
19
|
abstract state: WritableArrayLike<number>;
|
|
20
20
|
abstract secondary: WritableArrayLike<number>;
|
|
21
21
|
abstract mod: WritableArrayLike<number>;
|
|
22
|
+
/**
|
|
23
|
+
*
|
|
24
|
+
* @param mode 0 for add 1 for remove
|
|
25
|
+
*/
|
|
26
|
+
abstract updateVoxel(mode: 0 | 1): void;
|
|
22
27
|
_lightData: VoxelLightData;
|
|
23
28
|
_substanceData: SubstanceDataTool;
|
|
24
29
|
process(): void;
|
|
@@ -2,7 +2,7 @@ import { VoxelStructIds } from "../Types/Voxel.types";
|
|
|
2
2
|
import { VoxelLightData } from "./VoxelLightData";
|
|
3
3
|
import { MappedDataRegister } from "../../Data/Register/MappedDataRegister";
|
|
4
4
|
import { VoxelStruct } from "../Structs/VoxelStruct";
|
|
5
|
-
import {
|
|
5
|
+
import { VoxelLevelReader } from "../VoxelLevelReader";
|
|
6
6
|
import { VoxelTagStates } from "../State/VoxelTagStates";
|
|
7
7
|
import { VoxelPalette } from "../Palettes/VoxelPalette";
|
|
8
8
|
import { SubstancePalette } from "../Palettes/SubstancePalette";
|
|
@@ -84,17 +84,17 @@ export class VoxelCursorInterface {
|
|
|
84
84
|
return this;
|
|
85
85
|
}
|
|
86
86
|
getLevel() {
|
|
87
|
-
return
|
|
87
|
+
return VoxelLevelReader.getLevel(this.level[this._index]);
|
|
88
88
|
}
|
|
89
89
|
setLevel(level) {
|
|
90
|
-
this.level[this._index] =
|
|
90
|
+
this.level[this._index] = VoxelLevelReader.setLevel(this.level[this._index], level);
|
|
91
91
|
return this;
|
|
92
92
|
}
|
|
93
93
|
getLevelState() {
|
|
94
|
-
return
|
|
94
|
+
return VoxelLevelReader.getLevelState(this.level[this._index]);
|
|
95
95
|
}
|
|
96
96
|
setLevelState(state) {
|
|
97
|
-
this.level[this._index] =
|
|
97
|
+
this.level[this._index] = VoxelLevelReader.setLevelState(this.level[this._index], state);
|
|
98
98
|
return this;
|
|
99
99
|
}
|
|
100
100
|
getState() {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { VoxelCursorInterface } from "./VoxelCursor.interface";
|
|
2
2
|
import { VoxelPalette } from "../../Voxels/Palettes/VoxelPalette";
|
|
3
|
-
import {
|
|
3
|
+
import { VoxelLevelReader } from "../VoxelLevelReader";
|
|
4
4
|
export class VoxelCursor extends VoxelCursorInterface {
|
|
5
5
|
static VoxelDataToRaw(data, light = 0) {
|
|
6
6
|
const id = (data.id !== undefined && VoxelPalette.ids.getNumberId(data.id)) || 0;
|
|
@@ -9,9 +9,9 @@ export class VoxelCursor extends VoxelCursorInterface {
|
|
|
9
9
|
0;
|
|
10
10
|
let levleData = 0;
|
|
11
11
|
if (data.level !== undefined)
|
|
12
|
-
levleData =
|
|
12
|
+
levleData = VoxelLevelReader.setLevel(levleData, data.level);
|
|
13
13
|
if (data.levelState !== undefined)
|
|
14
|
-
levleData =
|
|
14
|
+
levleData = VoxelLevelReader.setLevelState(levleData, data.levelState);
|
|
15
15
|
return [id, light, levleData, data.state || 0, data.mod || 0, secondaryId];
|
|
16
16
|
}
|
|
17
17
|
ids = [0];
|
|
@@ -21,4 +21,6 @@ export class VoxelCursor extends VoxelCursorInterface {
|
|
|
21
21
|
secondary = [0];
|
|
22
22
|
mod = [0];
|
|
23
23
|
loadIn() { }
|
|
24
|
+
updateVoxel(mode) {
|
|
25
|
+
}
|
|
24
26
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**# Voxel Reader
|
|
2
|
+
* ---
|
|
3
|
+
* Used to decode voxel state data.
|
|
4
|
+
*/
|
|
5
|
+
export declare class VoxelLevelReader {
|
|
6
|
+
static getLevel(levelData: number): number;
|
|
7
|
+
static setLevel(levelData: number, level: number): number;
|
|
8
|
+
static getLevelState(levelData: number): number;
|
|
9
|
+
static setLevelState(levelData: number, levelState: number): number;
|
|
10
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const LEVEL_MASK = 0b0000_1111;
|
|
2
|
+
const LEVEL_STATE_MASK = 0b1111_0000;
|
|
3
|
+
/**# Voxel Reader
|
|
4
|
+
* ---
|
|
5
|
+
* Used to decode voxel state data.
|
|
6
|
+
*/
|
|
7
|
+
export class VoxelLevelReader {
|
|
8
|
+
static getLevel(levelData) {
|
|
9
|
+
return levelData & LEVEL_MASK;
|
|
10
|
+
}
|
|
11
|
+
static setLevel(levelData, level) {
|
|
12
|
+
return (levelData & ~LEVEL_MASK) | level;
|
|
13
|
+
}
|
|
14
|
+
static getLevelState(levelData) {
|
|
15
|
+
return (levelData & LEVEL_STATE_MASK) >> 4;
|
|
16
|
+
}
|
|
17
|
+
static setLevelState(levelData, levelState) {
|
|
18
|
+
return (levelData & ~LEVEL_STATE_MASK) | (levelState << 4);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -3,5 +3,5 @@ import { ArchivedSectorData } from "../Archive.types";
|
|
|
3
3
|
type ArchiveColumnProps = {
|
|
4
4
|
location: LocationData;
|
|
5
5
|
};
|
|
6
|
-
export default function
|
|
6
|
+
export default function ArchiveSector(archiveData: ArchiveColumnProps): ArchivedSectorData;
|
|
7
7
|
export {};
|
|
@@ -132,9 +132,8 @@ function GetArchivedSection(archiveSection, sectorPalettes) {
|
|
|
132
132
|
},
|
|
133
133
|
};
|
|
134
134
|
}
|
|
135
|
-
export default function
|
|
136
|
-
WorldRegister.
|
|
137
|
-
const sector = WorldRegister.sectors.get(archiveData.location[1], archiveData.location[2], archiveData.location[3]);
|
|
135
|
+
export default function ArchiveSector(archiveData) {
|
|
136
|
+
const sector = WorldRegister.sectors.get(archiveData.location[0], archiveData.location[1], archiveData.location[2], archiveData.location[3]);
|
|
138
137
|
if (!sector)
|
|
139
138
|
throw new Error(`Column at location ${location} does not exist when trying to arhicve it.`);
|
|
140
139
|
if (!sectorStructInstance)
|
|
@@ -2,10 +2,9 @@ import { Threads } from "@amodx/threads";
|
|
|
2
2
|
import ArchiveSector from "./Functions/ArchiveSector";
|
|
3
3
|
import { WorldRegister } from "../WorldRegister";
|
|
4
4
|
import ImportSector from "./Functions/ImportSector";
|
|
5
|
-
import { compressBinaryObject, expandBinaryObject } from "../../Util/BinaryObject";
|
|
5
|
+
import { compressBinaryObject, expandBinaryObject, } from "../../Util/BinaryObject";
|
|
6
6
|
function runArchiveSector(location) {
|
|
7
|
-
WorldRegister.
|
|
8
|
-
const sector = WorldRegister.sectors.get(location[1], location[2], location[3]);
|
|
7
|
+
const sector = WorldRegister.sectors.get(location[0], location[1], location[2], location[3]);
|
|
9
8
|
if (!sector)
|
|
10
9
|
throw new Error(`Sector at location ${location.toString()} does not exist`);
|
|
11
10
|
const archived = ArchiveSector({
|
|
@@ -36,8 +36,7 @@ export class SectionCursor extends DataCursorInterface {
|
|
|
36
36
|
this._sectionPosition.z = sectionPos[2];
|
|
37
37
|
return;
|
|
38
38
|
}
|
|
39
|
-
WorldRegister.
|
|
40
|
-
const sector = WorldRegister.sectors.get(x || 0, y || 0, z || 0);
|
|
39
|
+
const sector = WorldRegister.sectors.get(sectionOrDimension, x || 0, y || 0, z || 0);
|
|
41
40
|
if (!sector)
|
|
42
41
|
return false;
|
|
43
42
|
this._section = sector.getSection(y || 0);
|
|
@@ -13,5 +13,6 @@ export declare class SectorCursor extends DataCursorInterface implements WorldSe
|
|
|
13
13
|
_sectorPosition: Vector3Like;
|
|
14
14
|
inBounds(x: number, y: number, z: number): boolean;
|
|
15
15
|
setSector(dimension: string, x: number, y: number, z: number): boolean;
|
|
16
|
+
getSection(x: number, y: number, z: number): Section | null;
|
|
16
17
|
getVoxel(x: number, y: number, z: number): WorldVoxelCursor | null;
|
|
17
18
|
}
|
|
@@ -29,8 +29,7 @@ export class SectorCursor extends DataCursorInterface {
|
|
|
29
29
|
return true;
|
|
30
30
|
}
|
|
31
31
|
setSector(dimension, x, y, z) {
|
|
32
|
-
WorldRegister.
|
|
33
|
-
const sector = WorldRegister.sectors.get(x, y, z);
|
|
32
|
+
const sector = WorldRegister.sectors.get(dimension, x, y, z);
|
|
34
33
|
if (!sector)
|
|
35
34
|
return false;
|
|
36
35
|
this._current = sector;
|
|
@@ -39,7 +38,7 @@ export class SectorCursor extends DataCursorInterface {
|
|
|
39
38
|
this._sectorPosition.z = sector.position[2];
|
|
40
39
|
return true;
|
|
41
40
|
}
|
|
42
|
-
|
|
41
|
+
getSection(x, y, z) {
|
|
43
42
|
if (!this._current)
|
|
44
43
|
return null;
|
|
45
44
|
const section = this._current.sections[WorldSpaces.section.getIndex(x, y, z)];
|
|
@@ -49,6 +48,12 @@ export class SectorCursor extends DataCursorInterface {
|
|
|
49
48
|
this._section = null;
|
|
50
49
|
return null;
|
|
51
50
|
}
|
|
51
|
+
return section;
|
|
52
|
+
}
|
|
53
|
+
getVoxel(x, y, z) {
|
|
54
|
+
if (!this._current)
|
|
55
|
+
return null;
|
|
56
|
+
const section = this.getSection(x, y, z);
|
|
52
57
|
this._section = section;
|
|
53
58
|
this._voxelIndex = WorldSpaces.voxel.getIndex(x, y, z);
|
|
54
59
|
WorldSpaces.voxel.getPosition(x, y, z, this._voxelPosition);
|
|
@@ -2,7 +2,6 @@ import { Vector3Like } from "@amodx/math";
|
|
|
2
2
|
import { SectorCursor } from "./SectorCursor";
|
|
3
3
|
import { WorldSpaces } from "../WorldSpaces";
|
|
4
4
|
import { DataCursorInterface } from "../../Data/Cursor/DataCursor.interface";
|
|
5
|
-
import { WorldBounds } from "../WorldBounds";
|
|
6
5
|
let cursorCache = [];
|
|
7
6
|
const tempPosition = Vector3Like.Create();
|
|
8
7
|
export class WorldCursor extends DataCursorInterface {
|
|
@@ -23,7 +22,7 @@ export class WorldCursor extends DataCursorInterface {
|
|
|
23
22
|
this.origin.z = sectorPos.z / WorldSpaces.sector.bounds.z;
|
|
24
23
|
}
|
|
25
24
|
inBounds(x, y, z) {
|
|
26
|
-
return
|
|
25
|
+
return WorldSpaces.world.inBounds(x, y, z);
|
|
27
26
|
}
|
|
28
27
|
getSector(x, y, z) {
|
|
29
28
|
const sectorPos = WorldSpaces.sector.getPosition(x, y, z, tempPosition);
|
|
@@ -14,10 +14,6 @@ export declare class WorldVoxelCursor extends VoxelCursorInterface {
|
|
|
14
14
|
/**
|
|
15
15
|
*
|
|
16
16
|
* @param mode 0 for add 1 for remove
|
|
17
|
-
* @param x
|
|
18
|
-
* @param y
|
|
19
|
-
* @param z
|
|
20
|
-
* @returns
|
|
21
17
|
*/
|
|
22
|
-
|
|
18
|
+
updateVoxel(mode: 0 | 1): boolean;
|
|
23
19
|
}
|
|
@@ -36,12 +36,8 @@ export class WorldVoxelCursor extends VoxelCursorInterface {
|
|
|
36
36
|
/**
|
|
37
37
|
*
|
|
38
38
|
* @param mode 0 for add 1 for remove
|
|
39
|
-
* @param x
|
|
40
|
-
* @param y
|
|
41
|
-
* @param z
|
|
42
|
-
* @returns
|
|
43
39
|
*/
|
|
44
|
-
|
|
40
|
+
updateVoxel(mode) {
|
|
45
41
|
Section.StateStruct.setData(this._section.sectionState);
|
|
46
42
|
const voxelPos = this.dataCursor._voxelPosition;
|
|
47
43
|
if (mode == 0) {
|
package/World/InitTasks.js
CHANGED
|
@@ -29,8 +29,7 @@ export default function ({ threads, worldStorage, }) {
|
|
|
29
29
|
}
|
|
30
30
|
};
|
|
31
31
|
Threads.registerTask("add-sector", async (location) => {
|
|
32
|
-
WorldRegister.
|
|
33
|
-
const sector = WorldRegister.sectors.get(location[1], location[2], location[3]);
|
|
32
|
+
const sector = WorldRegister.sectors.get(location[0], location[1], location[2], location[3]);
|
|
34
33
|
if (sector) {
|
|
35
34
|
for (const thread of threads) {
|
|
36
35
|
thread.runTask(WorldDataSyncIds.SyncSector, [location, sector]);
|
|
@@ -38,8 +37,7 @@ export default function ({ threads, worldStorage, }) {
|
|
|
38
37
|
return;
|
|
39
38
|
}
|
|
40
39
|
if (!sector && !worldStorage) {
|
|
41
|
-
WorldRegister.
|
|
42
|
-
WorldRegister.sectors.new(location[1], location[2], location[3]);
|
|
40
|
+
WorldRegister.sectors.new(location[0], location[1], location[2], location[3]);
|
|
43
41
|
}
|
|
44
42
|
if (worldStorage) {
|
|
45
43
|
const sectorPos = WorldSpaces.sector.getPosition(location[1], location[2], location[3]);
|
|
@@ -56,8 +54,7 @@ export default function ({ threads, worldStorage, }) {
|
|
|
56
54
|
const success = await worldStorage.loadSector(sectorLocation);
|
|
57
55
|
loadInMap.delete(sectorId);
|
|
58
56
|
if (!success) {
|
|
59
|
-
WorldRegister.
|
|
60
|
-
WorldRegister.sectors.new(sectorLocation[1], sectorLocation[2], sectorLocation[3]);
|
|
57
|
+
WorldRegister.sectors.new(sectorLocation[0], sectorLocation[1], sectorLocation[2], sectorLocation[3]);
|
|
61
58
|
}
|
|
62
59
|
return;
|
|
63
60
|
}
|
|
@@ -71,16 +68,14 @@ export default function ({ threads, worldStorage, }) {
|
|
|
71
68
|
Threads.registerTask("unload-sector", (location) => {
|
|
72
69
|
if (WorldLock.isLocked(location))
|
|
73
70
|
return [false];
|
|
74
|
-
WorldRegister.
|
|
75
|
-
WorldRegister.sectors.remove(location[1], location[2], location[3]);
|
|
71
|
+
WorldRegister.sectors.remove(location[0], location[1], location[2], location[3]);
|
|
76
72
|
for (const thread of threads) {
|
|
77
73
|
thread.runTask(WorldDataSyncIds.UnSyncSector, location);
|
|
78
74
|
}
|
|
79
75
|
return [false];
|
|
80
76
|
});
|
|
81
77
|
Threads.registerTask("load-sector", ([location, sector]) => {
|
|
82
|
-
WorldRegister.
|
|
83
|
-
WorldRegister.sectors.add(location[1], location[2], location[3], sector);
|
|
78
|
+
WorldRegister.sectors.add(location[0], location[1], location[2], location[3], sector);
|
|
84
79
|
for (const thread of threads) {
|
|
85
80
|
thread.runTask(WorldDataSyncIds.SyncSector, [location, sector]);
|
|
86
81
|
}
|
package/World/Lock/WorldLock.js
CHANGED
|
@@ -23,8 +23,7 @@ export class WorldLock {
|
|
|
23
23
|
sectorPos.z,
|
|
24
24
|
];
|
|
25
25
|
location[0] = dim;
|
|
26
|
-
WorldRegister.
|
|
27
|
-
if (WorldRegister.sectors.get(location[1], location[2], location[3]))
|
|
26
|
+
if (WorldRegister.sectors.get(location[0], location[1], location[2], location[3]))
|
|
28
27
|
continue;
|
|
29
28
|
allFound = false;
|
|
30
29
|
const key = location.toString();
|
|
@@ -33,7 +32,7 @@ export class WorldLock {
|
|
|
33
32
|
this._loadMap.set(key, true);
|
|
34
33
|
let success = false;
|
|
35
34
|
if (!this.worldStorage) {
|
|
36
|
-
if (WorldRegister.sectors.get(location[1], location[2], location[3])) {
|
|
35
|
+
if (WorldRegister.sectors.get(location[0], location[1], location[2], location[3])) {
|
|
37
36
|
success = true;
|
|
38
37
|
}
|
|
39
38
|
}
|
|
@@ -41,10 +40,10 @@ export class WorldLock {
|
|
|
41
40
|
success = await this.worldStorage.loadSector(location);
|
|
42
41
|
}
|
|
43
42
|
this._loadMap.delete(key);
|
|
44
|
-
if (WorldRegister.sectors.get(location[1], location[2], location[3]))
|
|
43
|
+
if (WorldRegister.sectors.get(location[0], location[1], location[2], location[3]))
|
|
45
44
|
return;
|
|
46
45
|
if (!success) {
|
|
47
|
-
WorldRegister.sectors.new(location[1], location[2], location[3]);
|
|
46
|
+
WorldRegister.sectors.new(location[0], location[1], location[2], location[3]);
|
|
48
47
|
}
|
|
49
48
|
}
|
|
50
49
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { $2dMooreNeighborhood } from "../../Math/CardinalNeighbors";
|
|
2
2
|
import { SectionHeightMap } from "../Section/SectionHeightMap";
|
|
3
|
-
import { WorldBounds } from "../WorldBounds";
|
|
4
3
|
import { WorldRegister } from "../WorldRegister";
|
|
5
4
|
import { WorldSpaces } from "../WorldSpaces";
|
|
6
5
|
export class SectorHeightMap {
|
|
@@ -21,13 +20,12 @@ export class SectorHeightMap {
|
|
|
21
20
|
return maxHeight;
|
|
22
21
|
}
|
|
23
22
|
static getAbsolute(location) {
|
|
24
|
-
WorldRegister.
|
|
25
|
-
const sector = WorldRegister.sectors.get(location[1], location[2], location[3]);
|
|
23
|
+
const sector = WorldRegister.sectors.get(location[0], location[1], location[2], location[3]);
|
|
26
24
|
if (!sector)
|
|
27
|
-
return
|
|
25
|
+
return WorldSpaces.world.bounds.MinY;
|
|
28
26
|
if (sector.sections.length == 0)
|
|
29
|
-
return
|
|
30
|
-
let maxHeight =
|
|
27
|
+
return WorldSpaces.world.bounds.MinY;
|
|
28
|
+
let maxHeight = WorldSpaces.world.bounds.MinY;
|
|
31
29
|
const positon = [location[1], location[2], location[3]];
|
|
32
30
|
let y = positon[1];
|
|
33
31
|
for (let i = 0; i < sector.sections.length; i++) {
|
package/World/WorldRegister.d.ts
CHANGED
|
@@ -18,18 +18,16 @@ declare class WorldRegisterDimensions {
|
|
|
18
18
|
}
|
|
19
19
|
declare class WorldRegisterSectors {
|
|
20
20
|
static setSecotrPool(enabled: boolean): void;
|
|
21
|
-
static add(x: number, y: number, z: number, sector: SectorData): Sector;
|
|
22
|
-
static new(x: number, y: number, z: number): boolean;
|
|
23
|
-
static get(x: number, y: number, z: number): false | Sector;
|
|
24
|
-
static remove(x: number, y: number, z: number): boolean;
|
|
21
|
+
static add(dimensionId: string, x: number, y: number, z: number, sector: SectorData): Sector;
|
|
22
|
+
static new(dimensionId: string, x: number, y: number, z: number): boolean;
|
|
23
|
+
static get(dimensionId: string, x: number, y: number, z: number): false | Sector;
|
|
24
|
+
static remove(dimensionId: string, x: number, y: number, z: number): boolean;
|
|
25
25
|
}
|
|
26
26
|
export declare class WorldRegister {
|
|
27
27
|
static _dimensions: Map<string, Dimension>;
|
|
28
28
|
static _hooks: typeof WorldDataHooks;
|
|
29
29
|
static dimensions: typeof WorldRegisterDimensions;
|
|
30
30
|
static sectors: typeof WorldRegisterSectors;
|
|
31
|
-
static _currentDimension: Dimension;
|
|
32
|
-
static setDimension(dimensionId: string): void;
|
|
33
31
|
static clearAll(): void;
|
|
34
32
|
}
|
|
35
33
|
export {};
|
package/World/WorldRegister.js
CHANGED
|
@@ -42,33 +42,45 @@ class WorldRegisterSectors {
|
|
|
42
42
|
SectorPool._enabled = enabled;
|
|
43
43
|
SectorPool._secotrs.length = 0;
|
|
44
44
|
}
|
|
45
|
-
static add(x, y, z, sector) {
|
|
45
|
+
static add(dimensionId, x, y, z, sector) {
|
|
46
|
+
let dimension = WorldRegister.dimensions.get(dimensionId);
|
|
47
|
+
if (!dimension)
|
|
48
|
+
dimension = WorldRegister.dimensions.add(dimensionId);
|
|
46
49
|
WorldSpaces.sector.getPositionVec3Array(x, y, z, sector.position);
|
|
47
50
|
const newSector = new Sector(sector);
|
|
48
|
-
|
|
51
|
+
dimension.sectors.set(WorldSpaces.hash.hashVec3Array(newSector.position), newSector);
|
|
49
52
|
return newSector;
|
|
50
53
|
}
|
|
51
|
-
static new(x, y, z) {
|
|
52
|
-
if (this.get(x, y, z))
|
|
54
|
+
static new(dimensionId, x, y, z) {
|
|
55
|
+
if (this.get(dimensionId, x, y, z))
|
|
53
56
|
return false;
|
|
54
|
-
|
|
55
|
-
|
|
57
|
+
let dimension = WorldRegister.dimensions.get(dimensionId);
|
|
58
|
+
if (!dimension)
|
|
59
|
+
dimension = WorldRegister.dimensions.add(dimensionId);
|
|
60
|
+
const sector = this.add(dimensionId, x, y, z, Sector.CreateNew());
|
|
61
|
+
WorldDataHooks.sectors.onNew([dimensionId, x, y, z], sector);
|
|
56
62
|
return true;
|
|
57
63
|
}
|
|
58
|
-
static get(x, y, z) {
|
|
59
|
-
|
|
64
|
+
static get(dimensionId, x, y, z) {
|
|
65
|
+
let dimension = WorldRegister.dimensions.get(dimensionId);
|
|
66
|
+
if (!dimension)
|
|
67
|
+
return false;
|
|
68
|
+
const sector = dimension.sectors.get(WorldSpaces.hash.hashVec3(WorldSpaces.sector.getPosition(x, y, z, tempPosition)));
|
|
60
69
|
return sector || false;
|
|
61
70
|
}
|
|
62
|
-
static remove(x, y, z) {
|
|
71
|
+
static remove(dimensionId, x, y, z) {
|
|
72
|
+
let dimension = WorldRegister.dimensions.get(dimensionId);
|
|
73
|
+
if (!dimension)
|
|
74
|
+
return false;
|
|
63
75
|
const position = WorldSpaces.sector.getPosition(x, y, z, tempPosition);
|
|
64
76
|
const sectorKey = WorldSpaces.hash.hashVec3(position);
|
|
65
|
-
const sector =
|
|
77
|
+
const sector = dimension.sectors.get(sectorKey);
|
|
66
78
|
if (!sector)
|
|
67
79
|
return false;
|
|
68
80
|
if (SectorPool._enabled)
|
|
69
81
|
SectorPool.returnSector(sector);
|
|
70
|
-
|
|
71
|
-
|
|
82
|
+
WorldDataHooks.sectors.onRemove([dimensionId, position.x, position.y, position.z], sector);
|
|
83
|
+
dimension.sectors.delete(sectorKey);
|
|
72
84
|
return true;
|
|
73
85
|
}
|
|
74
86
|
}
|
|
@@ -77,14 +89,6 @@ export class WorldRegister {
|
|
|
77
89
|
static _hooks = WorldDataHooks;
|
|
78
90
|
static dimensions = WorldRegisterDimensions;
|
|
79
91
|
static sectors = WorldRegisterSectors;
|
|
80
|
-
static _currentDimension;
|
|
81
|
-
static setDimension(dimensionId) {
|
|
82
|
-
let dimension = this.dimensions.get(dimensionId);
|
|
83
|
-
if (!dimension) {
|
|
84
|
-
dimension = this.dimensions.add(dimensionId);
|
|
85
|
-
}
|
|
86
|
-
this._currentDimension = dimension;
|
|
87
|
-
}
|
|
88
92
|
static clearAll() {
|
|
89
93
|
this._dimensions.clear();
|
|
90
94
|
}
|
package/World/WorldSpaces.d.ts
CHANGED
|
@@ -1,4 +1,24 @@
|
|
|
1
1
|
import { Vec3Array, Vector3Like } from "@amodx/math";
|
|
2
|
+
declare class WorldBounds {
|
|
3
|
+
static bounds: {
|
|
4
|
+
MinZ: number;
|
|
5
|
+
MaxZ: number;
|
|
6
|
+
MinX: number;
|
|
7
|
+
MaxX: number;
|
|
8
|
+
MinY: number;
|
|
9
|
+
MaxY: number;
|
|
10
|
+
};
|
|
11
|
+
static setWorldBounds(minX: number, minY: number, minZ: number, maxX: number, maxY: number, maxZ: number): void;
|
|
12
|
+
static inBounds(x: number, y: number, z: number): boolean;
|
|
13
|
+
static getWorldWidth(): number;
|
|
14
|
+
static getWorldDepth(): number;
|
|
15
|
+
static getWorldHeightY(): number;
|
|
16
|
+
static getWorldDimensions(): {
|
|
17
|
+
width: number;
|
|
18
|
+
depth: number;
|
|
19
|
+
height: number;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
2
22
|
declare class SectorSpace {
|
|
3
23
|
static power2Axes: Vector3Like;
|
|
4
24
|
static bounds: Vector3Like;
|
|
@@ -27,6 +47,7 @@ declare class Hash {
|
|
|
27
47
|
}
|
|
28
48
|
export declare class WorldSpaces {
|
|
29
49
|
static hash: typeof Hash;
|
|
50
|
+
static world: typeof WorldBounds;
|
|
30
51
|
static sector: typeof SectorSpace;
|
|
31
52
|
static section: typeof SectionSpace;
|
|
32
53
|
static voxel: typeof VoxelSpace;
|