@divinevoxel/vlox 0.0.79 → 0.0.81

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.
Files changed (167) hide show
  1. package/Builder/Tools/Brush/BrushTool.d.ts +12 -2
  2. package/Builder/Tools/Brush/BrushTool.js +53 -28
  3. package/Builder/Tools/Debug/DebugTool.d.ts +18 -0
  4. package/Builder/Tools/Debug/DebugTool.js +36 -0
  5. package/Builder/Tools/Path/PahtTool.d.ts +1 -1
  6. package/Builder/Tools/Path/PahtTool.js +1 -1
  7. package/Builder/Tools/Sculpt/SculptTool.js +8 -0
  8. package/Builder/Tools/Wrench/WrenchTool.js +10 -23
  9. package/Builder/Util/SurfaceBoxSelection.js +2 -0
  10. package/Builder/VoxelBuildSpace.js +3 -3
  11. package/Contexts/Base/Remote/InitDataSync.js +1 -1
  12. package/Math/UtilFunctions.js +7 -8
  13. package/Math/VoxelFaces.d.ts +2 -2
  14. package/Math/VoxelFaces.js +46 -55
  15. package/Math/WorldIndexing.d.ts +11 -0
  16. package/Math/WorldIndexing.js +34 -0
  17. package/Mesher/Geometry/Geometry.types.d.ts +2 -2
  18. package/Mesher/Geometry/Geometry.types.js +7 -20
  19. package/Mesher/Geometry/Primitives/QuadVertexData.js +118 -119
  20. package/Mesher/Geometry/Primitives/TriangleVertexData.js +89 -90
  21. package/Mesher/Geometry/Proto/ProtoMesh.d.ts +1 -1
  22. package/Mesher/Geometry/Proto/ProtoMesh.js +22 -29
  23. package/Mesher/Geometry/Proto/ProtoMeshBuffer.d.ts +4 -2
  24. package/Mesher/Geometry/Proto/ProtoMeshBuffer.js +14 -6
  25. package/Mesher/Geometry/Shapes/Box.js +6 -7
  26. package/Mesher/Geometry/Transform/TransformBox.js +8 -9
  27. package/Mesher/Geometry/Transform/TransformQuad.js +4 -5
  28. package/Mesher/Geometry/Transform/TransformTriangle.js +3 -4
  29. package/Mesher/InitMesher.js +4 -9
  30. package/Mesher/Items/Geometry/ItemGeometryBuilder.js +7 -8
  31. package/Mesher/Items/MeshTexture.js +125 -57
  32. package/Mesher/Voxels/Base/BuildVoxel.d.ts +6 -0
  33. package/Mesher/Voxels/Base/BuildVoxel.js +101 -0
  34. package/Mesher/Voxels/Base/CompactVoxelSectionMesh.js +1 -21
  35. package/Mesher/Voxels/Base/MeshSectionBase.js +3 -26
  36. package/Mesher/Voxels/Geometry/VoxelGeometryBuilder.js +33 -31
  37. package/Mesher/Voxels/Geometry/VoxelShaderData.js +3 -7
  38. package/Mesher/Voxels/MeshTemplate.js +6 -26
  39. package/Mesher/Voxels/MeshVoxel.js +5 -10
  40. package/Mesher/Voxels/Models/Common/Calc/CalcConstants.js +41 -42
  41. package/Mesher/Voxels/Models/Common/Calc/FaceDataCalc.js +6 -9
  42. package/Mesher/Voxels/Models/Common/Faces/CullRulledFace.js +64 -47
  43. package/Mesher/Voxels/Models/Common/Faces/ShadeRulledFace.js +57 -43
  44. package/Mesher/Voxels/Models/Nodes/Custom/Liquid/FlowGradient.js +4 -5
  45. package/Mesher/Voxels/Models/Nodes/Custom/Liquid/LiquidGeometryNode.d.ts +1 -1
  46. package/Mesher/Voxels/Models/Nodes/Custom/Liquid/LiquidGeometryNode.js +116 -118
  47. package/Mesher/Voxels/Models/Nodes/Default/QuadVoxelGeometryNode.js +4 -4
  48. package/Mesher/Voxels/Models/Nodes/VoxelGeometryConstructor.js +2 -2
  49. package/Mesher/Voxels/Models/Procedures/Default/OutlinedTextureProcedure.js +19 -21
  50. package/Mesher/Voxels/Models/Procedures/Default/PillarTextureProcedure.js +45 -38
  51. package/Mesher/Voxels/Models/RenderedMaterials.d.ts +1 -1
  52. package/Mesher/Voxels/Models/RenderedMaterials.js +8 -5
  53. package/Mesher/Voxels/Models/VoxelGeometryBuilderCacheSpace.d.ts +18 -4
  54. package/Mesher/Voxels/Models/VoxelGeometryBuilderCacheSpace.js +135 -22
  55. package/Mesher/Voxels/Models/VoxelGeometryBuilderCacheSpaceN.d.ts +33 -0
  56. package/Mesher/Voxels/Models/VoxelGeometryBuilderCacheSpaceN.js +204 -0
  57. package/Mesher/Voxels/Models/{VoxelModelConstructorRegister.d.ts → VoxelGeometryConstructorRegister.d.ts} +1 -6
  58. package/Mesher/Voxels/Models/VoxelGeometryConstructorRegister.js +20 -0
  59. package/Mesher/Voxels/Models/VoxelModelBuilder.js +15 -16
  60. package/Mesher/Voxels/Models/VoxelModelEffect.d.ts +1 -3
  61. package/Mesher/Voxels/Models/VoxelModelEffect.js +1 -3
  62. package/Renderer/DVERenderNode.types.d.ts +1 -0
  63. package/Renderer/InitTasks.js +2 -0
  64. package/Tasks/Paint/Erase/EraseVoxel.js +1 -1
  65. package/Tasks/Propagation/Illumanation/RGBUpdate.js +191 -48
  66. package/Tasks/Propagation/Illumanation/SunUpdate.d.ts +1 -1
  67. package/Tasks/Propagation/Illumanation/SunUpdate.js +167 -63
  68. package/Tasks/Propagation/Illumanation/WorldSun.js +96 -60
  69. package/Tasks/WorldGeneration/WorldGenBrush.d.ts +2 -0
  70. package/Tasks/WorldGeneration/WorldGenBrush.js +31 -0
  71. package/Templates/Archive/ArchivedVoxelTemplate.js +1 -1
  72. package/Templates/Archive/Functions/CreateArchivedTemplate.js +1 -1
  73. package/Templates/Archive/Functions/CreateArchivedTemplateFromFull.d.ts +6 -0
  74. package/Templates/Archive/Functions/CreateArchivedTemplateFromFull.js +174 -0
  75. package/Textures/Classes/CompactedTextureReader.d.ts +22 -0
  76. package/Textures/Classes/CompactedTextureReader.js +90 -0
  77. package/Textures/Classes/CompiledTexture.d.ts +4 -1
  78. package/Textures/Classes/CompiledTexture.js +36 -8
  79. package/Textures/Classes/TextureAtlasIndex.d.ts +7 -0
  80. package/Textures/Classes/TextureAtlasIndex.js +14 -0
  81. package/Textures/Classes/TextureLoader.d.ts +20 -0
  82. package/Textures/Classes/TextureLoader.js +95 -0
  83. package/Textures/Functions/BuildTextureData.d.ts +1 -1
  84. package/Textures/Functions/BuildTextureData.js +19 -122
  85. package/Textures/Functions/CreateCompactedTexture.d.ts +6 -0
  86. package/Textures/Functions/CreateCompactedTexture.js +105 -0
  87. package/Textures/Functions/ReadCompactedTexture.d.ts +2 -0
  88. package/Textures/Functions/ReadCompactedTexture.js +42 -0
  89. package/Textures/Texture.types.d.ts +14 -0
  90. package/Textures/TextureManager.d.ts +7 -1
  91. package/Textures/TextureManager.js +13 -0
  92. package/Tools/Brush/Brush.d.ts +4 -2
  93. package/Tools/Brush/Brush.js +28 -6
  94. package/Util/BinaryBuffer/Functions/BinaryBufferConvert.d.ts +1 -1
  95. package/Util/TickInterval.d.ts +3 -0
  96. package/Util/TickInterval.js +31 -3
  97. package/Voxels/Archive/VoxelPaletteArchiveReader.d.ts +1 -0
  98. package/Voxels/Archive/VoxelPaletteArchiveReader.js +9 -10
  99. package/Voxels/Archive/VoxelPaletteArechive.js +5 -4
  100. package/Voxels/Cursor/VoxelCursor.interface.d.ts +1 -1
  101. package/Voxels/Cursor/VoxelCursor.interface.js +22 -16
  102. package/Voxels/Data/VoxelLUT.d.ts +69 -42
  103. package/Voxels/Data/VoxelLUT.js +110 -53
  104. package/Voxels/Functions/BuildLUTs.js +100 -45
  105. package/Voxels/Functions/Geometry/CalcFunctions.js +6 -7
  106. package/Voxels/Functions/Geometry/Compile/BuildCompiled.d.ts +1 -1
  107. package/Voxels/Functions/Geometry/Inputs/BuildBoxInputs.d.ts +1 -1
  108. package/Voxels/Functions/Geometry/Inputs/BuildCustomInputs.d.ts +1 -1
  109. package/Voxels/Functions/Geometry/Inputs/BuildQuadInputs.d.ts +1 -1
  110. package/Voxels/Functions/Geometry/Inputs/BuildTriangleInputs.d.ts +1 -1
  111. package/Voxels/Functions/Geometry/Inputs/BuildTriangleInputs.js +3 -0
  112. package/Voxels/Indexes/VoxelIndex.js +3 -1
  113. package/Voxels/InitVoxelData.js +3 -1
  114. package/Voxels/Interaction/Functions/PickVoxel.js +3 -5
  115. package/Voxels/Interaction/Functions/PickVoxelWorld.js +4 -6
  116. package/Voxels/Models/Defaults/Examples.d.ts +2 -0
  117. package/Voxels/Models/Defaults/Examples.js +151 -2
  118. package/Voxels/State/Reltional/ReltionalStateBuilder.js +2 -0
  119. package/Voxels/State/Schema/BinarySchema.d.ts +1 -0
  120. package/Voxels/State/Schema/BinarySchema.js +14 -0
  121. package/Voxels/State/VoxelSchemas.d.ts +11 -4
  122. package/Voxels/State/VoxelSchemas.js +42 -9
  123. package/Voxels/Types/PaintVoxelData.js +6 -2
  124. package/World/Archive/Classes/ImportedSection.js +1 -1
  125. package/World/Archive/Classes/ImportedSector.js +0 -1
  126. package/World/Archive/Functions/Sector/ArchiveSector.js +2 -2
  127. package/World/Archive/Functions/Sector/ImportSector.d.ts +1 -0
  128. package/World/Archive/Functions/Sector/ImportSector.js +183 -7
  129. package/World/Cursor/SectorCursor.js +1 -4
  130. package/World/Cursor/WorldCursor.d.ts +12 -3
  131. package/World/Cursor/WorldCursor.js +60 -30
  132. package/World/InitTasks.js +1 -1
  133. package/World/Lock/Function/LockSectors.js +5 -1
  134. package/World/Lock/Function/UnLockSectors.js +5 -1
  135. package/World/SnapShot/SectionSnapShot.d.ts +7 -3
  136. package/World/SnapShot/SectionSnapShot.js +47 -21
  137. package/World/SnapShot/SectionSnapShotCursor.d.ts +4 -2
  138. package/World/SnapShot/SectionSnapShotCursor.js +23 -11
  139. package/World/SnapShot/SnapShots.d.ts +1 -2
  140. package/World/SnapShot/SnapShots.js +3 -3
  141. package/World/WorldSpaces.d.ts +7 -0
  142. package/World/WorldSpaces.js +35 -13
  143. package/WorldSimulation/Dimensions/DimensionSegment.d.ts +2 -0
  144. package/WorldSimulation/Dimensions/DimensionSegment.js +9 -1
  145. package/WorldSimulation/Dimensions/DimensionSimulation.js +6 -7
  146. package/WorldSimulation/Dimensions/Generator.d.ts +4 -0
  147. package/WorldSimulation/Dimensions/Generator.js +15 -1
  148. package/WorldSimulation/Dimensions/SimulationSector.d.ts +1 -0
  149. package/WorldSimulation/Dimensions/SimulationSector.js +18 -0
  150. package/WorldSimulation/Internal/WorldSimulationTasks.js +11 -7
  151. package/WorldSimulation/Procedures/InitalLoad.d.ts +1 -0
  152. package/WorldSimulation/Procedures/InitalLoad.js +18 -8
  153. package/WorldSimulation/Tasks/SimulationTaskBase.d.ts +4 -1
  154. package/WorldSimulation/Tasks/SimulationTaskBase.js +13 -2
  155. package/WorldSimulation/Tasks/TaskSegment.d.ts +4 -2
  156. package/WorldSimulation/Tasks/TaskSegment.js +36 -22
  157. package/WorldSimulation/Voxels/Ticks/Types/LiquidVoxelUpdate.js +1 -2
  158. package/WorldSimulation/WorldSimulation.d.ts +6 -3
  159. package/WorldSimulation/WorldSimulation.js +44 -20
  160. package/package.json +1 -1
  161. package/Mesher/Items/MeshTextureO.d.ts +0 -1
  162. package/Mesher/Items/MeshTextureO.js +0 -277
  163. package/Mesher/Voxels/Models/VoxelConstructor.d.ts +0 -8
  164. package/Mesher/Voxels/Models/VoxelConstructor.js +0 -78
  165. package/Mesher/Voxels/Models/VoxelModelConstructorRegister.js +0 -37
  166. package/WorldSimulation/Procedures/BuildOnly.d.ts +0 -10
  167. package/WorldSimulation/Procedures/BuildOnly.js +0 -55
@@ -19,5 +19,6 @@ export declare class BinarySchema {
19
19
  setValue(id: string, value: string): this;
20
20
  getEncoded(): number;
21
21
  getSchema(): VoxelBinaryStateSchemaNode[];
22
+ totalStates(): number;
22
23
  }
23
24
  export {};
@@ -149,4 +149,18 @@ export class BinarySchema {
149
149
  getSchema() {
150
150
  return this.nodes.map((_) => _.data);
151
151
  }
152
+ totalStates() {
153
+ if (this.nodes.length === 0)
154
+ return 1;
155
+ let total = 1;
156
+ for (const node of this.nodes) {
157
+ if (node.data.values) {
158
+ total *= node.data.values.length;
159
+ }
160
+ else {
161
+ total *= node.bitMask + 1;
162
+ }
163
+ }
164
+ return total;
165
+ }
152
166
  }
@@ -4,19 +4,26 @@ import { VoxelBinaryStateSchemaNode, VoxelModelRelationsSchemaNodes } from "./St
4
4
  export type VoxelSchemasExport = {
5
5
  state: [key: string, VoxelBinaryStateSchemaNode[]][];
6
6
  mod: [key: string, VoxelBinaryStateSchemaNode[]][];
7
- reltioanlState: [key: string, VoxelBinaryStateSchemaNode[]][];
7
+ relationalState: [key: string, VoxelBinaryStateSchemaNode[]][];
8
8
  reltionalStateBuilder: [key: string, VoxelModelRelationsSchemaNodes[]][];
9
- reltioanlMod: [key: string, VoxelBinaryStateSchemaNode[]][];
9
+ relationalMod: [key: string, VoxelBinaryStateSchemaNode[]][];
10
10
  reltionalModBuilder: [key: string, VoxelModelRelationsSchemaNodes[]][];
11
11
  };
12
12
  export declare class VoxelSchemas {
13
13
  static state: Map<string, BinarySchema>;
14
+ static stateMap: BinarySchema[];
14
15
  static mod: Map<string, BinarySchema>;
15
- static reltioanlState: Map<string, BinarySchema>;
16
+ static modMap: BinarySchema[];
17
+ static relationalState: Map<string, BinarySchema>;
18
+ static relationalStateMap: BinarySchema[];
16
19
  static reltionalStateBuilder: Map<string, ReltionalStateBuilder>;
17
- static reltioanlMod: Map<string, BinarySchema>;
20
+ static reltionalStateBuilderMap: ReltionalStateBuilder[];
21
+ static relationalMod: Map<string, BinarySchema>;
22
+ static relationalModMap: BinarySchema[];
18
23
  static reltionalModBuilder: Map<string, ReltionalStateBuilder>;
24
+ static reltionalModBuilderMap: ReltionalStateBuilder[];
19
25
  static getStateSchema(voxelId: string): BinarySchema | undefined;
26
+ static buildMaps(): void;
20
27
  static export(): VoxelSchemasExport;
21
28
  static import(exported: VoxelSchemasExport): void;
22
29
  }
@@ -4,30 +4,62 @@ import { BinarySchema } from "./Schema/BinarySchema";
4
4
  export class VoxelSchemas {
5
5
  //maps voxel model ids to the their state scehma
6
6
  static state = new Map();
7
+ //maps voxel model number ids to their state schemas
8
+ static stateMap = [];
7
9
  //maps voxel ids to their mod schemao
8
10
  static mod = new Map();
11
+ //maps voxel number ids to their state schemas
12
+ static modMap = [];
9
13
  //maps voxel model ids to their reltional state schema
10
- static reltioanlState = new Map();
14
+ static relationalState = new Map();
15
+ //maps voxel model number ids to their reltional state schema
16
+ static relationalStateMap = [];
11
17
  //maps voxel model ids = their reltional state builder
12
18
  static reltionalStateBuilder = new Map();
19
+ //maps voxel model number ids = their reltional state builder
20
+ static reltionalStateBuilderMap = [];
13
21
  //maps voxel ids to their reltional mod schema
14
- static reltioanlMod = new Map();
15
- //maps voxel ids = their reltional mod builder
22
+ static relationalMod = new Map();
23
+ //maps voxel number ids to their reltional mod schema
24
+ static relationalModMap = [];
25
+ //maps voxel ids to their reltional mod builder
16
26
  static reltionalModBuilder = new Map();
27
+ //maps voxel number ids to their reltional mod builder
28
+ static reltionalModBuilderMap = [];
17
29
  static getStateSchema(voxelId) {
18
30
  const modelId = VoxelLUT.models.getStringId(VoxelLUT.modelsIndex[VoxelLUT.voxelIds.getNumberId(voxelId)]);
19
31
  return this.state.get(modelId);
20
32
  }
33
+ static buildMaps() {
34
+ for (const [key, schema] of this.state) {
35
+ this.stateMap[VoxelLUT.models.getNumberId(key)] = schema;
36
+ }
37
+ for (const [key, schema] of this.relationalState) {
38
+ this.relationalStateMap[VoxelLUT.models.getNumberId(key)] = schema;
39
+ }
40
+ for (const [key, schema] of this.reltionalStateBuilder) {
41
+ this.reltionalStateBuilderMap[VoxelLUT.models.getNumberId(key)] = schema;
42
+ }
43
+ for (const [key, schema] of this.mod) {
44
+ this.modMap[VoxelLUT.voxelIds.getNumberId(key)] = schema;
45
+ }
46
+ for (const [key, schema] of this.relationalMod) {
47
+ this.relationalModMap[VoxelLUT.voxelIds.getNumberId(key)] = schema;
48
+ }
49
+ for (const [key, schema] of this.reltionalModBuilder) {
50
+ this.reltionalModBuilderMap[VoxelLUT.voxelIds.getNumberId(key)] = schema;
51
+ }
52
+ }
21
53
  static export() {
22
54
  return {
23
55
  state: [...this.state].map(([key, value]) => [key, value.getSchema()]),
24
56
  mod: [...this.mod].map(([key, value]) => [key, value.getSchema()]),
25
- reltioanlState: [...this.reltioanlState].map(([key, value]) => [
57
+ relationalState: [...this.relationalState].map(([key, value]) => [
26
58
  key,
27
59
  value.getSchema(),
28
60
  ]),
29
61
  reltionalStateBuilder: [...this.reltionalStateBuilder].map(([key, value]) => [key, value.getSchema()]),
30
- reltioanlMod: [...this.reltioanlMod].map(([key, value]) => [
62
+ relationalMod: [...this.relationalMod].map(([key, value]) => [
31
63
  key,
32
64
  value.getSchema(),
33
65
  ]),
@@ -40,21 +72,22 @@ export class VoxelSchemas {
40
72
  static import(exported) {
41
73
  this.state = new Map(exported.state.map(([key, nodes]) => [key, new BinarySchema(nodes)]));
42
74
  this.mod = new Map(exported.mod.map(([key, nodes]) => [key, new BinarySchema(nodes)]));
43
- this.reltioanlState = new Map(exported.reltioanlState.map(([key, nodes]) => [
75
+ this.relationalState = new Map(exported.relationalState.map(([key, nodes]) => [
44
76
  key,
45
77
  new BinarySchema(nodes),
46
78
  ]));
47
79
  this.reltionalStateBuilder = new Map(exported.reltionalStateBuilder.map(([key, nodes]) => [
48
80
  key,
49
- new ReltionalStateBuilder(this.reltioanlState.get(key), nodes),
81
+ new ReltionalStateBuilder(this.relationalState.get(key), nodes),
50
82
  ]));
51
- this.reltioanlMod = new Map(exported.reltioanlMod.map(([key, nodes]) => [
83
+ this.relationalMod = new Map(exported.relationalMod.map(([key, nodes]) => [
52
84
  key,
53
85
  new BinarySchema(nodes),
54
86
  ]));
55
87
  this.reltionalModBuilder = new Map(exported.reltionalModBuilder.map(([key, nodes]) => [
56
88
  key,
57
- new ReltionalStateBuilder(this.reltioanlMod.get(key), nodes),
89
+ new ReltionalStateBuilder(this.relationalMod.get(key), nodes),
58
90
  ]));
91
+ this.buildMaps();
59
92
  }
60
93
  }
@@ -21,13 +21,17 @@ export class PaintVoxelData {
21
21
  }
22
22
  /**Transforms numeric voxel data into a PaintVoxelData object */
23
23
  static FromRaw(data, paintData = PaintVoxelData.Create()) {
24
- const [trueVoxelId, state, mod] = VoxelLUT.voxels[data[0]];
24
+ const trueVoxelId = VoxelLUT.voxelIdToTrueId[data[0]];
25
+ const state = VoxelLUT.voxelIdToState[data[0]];
26
+ const mod = VoxelLUT.voxelIdToMod[data[0]];
25
27
  paintData.id = VoxelLUT.voxelIds.getStringId(trueVoxelId);
26
28
  paintData.state = state;
27
29
  paintData.mod = mod;
28
30
  paintData.name = VoxelLUT.voxelIdToNameMap.get(paintData.id) || "";
29
31
  if (data[3] !== 0) {
30
- const [trueVoxelId, state, mod] = VoxelLUT.voxels[data[3]];
32
+ const trueVoxelId = VoxelLUT.voxelIdToTrueId[data[3]];
33
+ const state = VoxelLUT.voxelIdToState[data[3]];
34
+ const mod = VoxelLUT.voxelIdToMod[data[3]];
31
35
  paintData.secondaryVoxelId = VoxelLUT.voxelIds.getStringId(trueVoxelId);
32
36
  paintData.secondaryState = state;
33
37
  paintData.secondaryMod = mod;
@@ -153,7 +153,7 @@ export class ImportedSection {
153
153
  return value;
154
154
  }
155
155
  getSecondary(index) {
156
- const trueVoxelId = VoxelLUT.voxels[this.getId(index)][0];
156
+ const trueVoxelId = VoxelLUT.voxelIdToTrueId[this.getId(index)];
157
157
  const value = this.buffers.secondary.getValue(index);
158
158
  if (VoxelTagsRegister.VoxelTags[trueVoxelId]["dve_can_have_secondary"]) {
159
159
  if (this.buffers.ids.isValue) {
@@ -29,7 +29,6 @@ class ImportedSectorPalettes {
29
29
  };
30
30
  }
31
31
  }
32
- const temp = ["", 0, 0];
33
32
  export class ImportedSector {
34
33
  sector;
35
34
  sections = [];
@@ -34,7 +34,7 @@ export default function ArchiveSector(archiveData) {
34
34
  if (!processedSection.palettes.voxels.isRegistered(voxelId))
35
35
  processedSection.palettes.voxels.register(voxelId);
36
36
  let voxelSecondary = 0;
37
- if (VoxelTagsRegister.VoxelTags[VoxelLUT.voxels[section.ids[i]][0]]["dve_can_have_secondary"]) {
37
+ if (VoxelTagsRegister.VoxelTags[VoxelLUT.voxelIdToTrueId[section.ids[i]]]["dve_can_have_secondary"]) {
38
38
  voxelSecondary = sectorPalettes.voxels.register(section.secondary[i]);
39
39
  if (!processedSection.palettes.secondaryVoxels.isRegistered(voxelSecondary))
40
40
  processedSection.palettes.secondaryVoxels.register(voxelSecondary);
@@ -140,7 +140,7 @@ export default function ArchiveSector(archiveData) {
140
140
  const length = archivedSection.original.ids.length;
141
141
  for (let i = 0; i < length; i++) {
142
142
  let secondary = false;
143
- if (VoxelTagsRegister.VoxelTags[VoxelLUT.voxels[archivedSection.original.ids[i]][0]]["dve_can_have_secondary"] &&
143
+ if (VoxelTagsRegister.VoxelTags[VoxelLUT.voxelIdToTrueId[archivedSection.original.ids[i]]]["dve_can_have_secondary"] &&
144
144
  archivedSection.original.secondary[i] !== 0) {
145
145
  secondary = true;
146
146
  }
@@ -2,6 +2,7 @@ import { SectorData } from "../../../index";
2
2
  import { ArchivedSectorData } from "../../Types/index";
3
3
  type RunData = {
4
4
  version?: number;
5
+ healLight?: boolean;
5
6
  };
6
7
  export default function ImportSector(archivedSector: ArchivedSectorData, archiveData: RunData): SectorData;
7
8
  export {};
@@ -2,30 +2,206 @@ import { WorldSpaces } from "../../../WorldSpaces";
2
2
  import { Sector } from "../../../index";
3
3
  import { ImportedSector } from "../../Classes/ImportedSector";
4
4
  import { Vector3Like } from "@amodx/math";
5
+ import { VoxelLUT } from "../../../../Voxels/Data/VoxelLUT";
6
+ import { VoxelTagsRegister } from "../../../../Voxels/Data/VoxelTagsRegister";
7
+ import { BinaryBufferFormat } from "../../../../Util/BinaryBuffer/index";
8
+ import { lightSemgnetSet } from "../../Functions/Shared/LightSegments";
5
9
  export default function ImportSector(archivedSector, archiveData) {
6
10
  const sector = new Sector();
7
11
  sector.setBuffer(Sector.CreateNewBuffer());
8
12
  sector.position[0] = archivedSector.position.x;
9
13
  sector.position[1] = archivedSector.position.y;
10
14
  sector.position[2] = archivedSector.position.z;
15
+ if (archiveData.healLight) {
16
+ archivedSector.flags["dve_is_world_progation_done"] = false;
17
+ archivedSector.flags["dve_is_world_sun_done"] = false;
18
+ }
11
19
  sector.loadFlags(archivedSector.flags);
12
20
  sector.loadTimestamps(archivedSector.timestamps);
13
21
  const importedSector = new ImportedSector(archivedSector);
14
22
  const position = Vector3Like.Create();
23
+ const sectionVolume = WorldSpaces.section.volumne;
15
24
  for (const importedSection of importedSector.sections) {
16
25
  const archivedSection = importedSection.section;
17
26
  const section = sector.sections[importedSection.sectionIndex];
18
27
  archivedSection.flags && section.loadFlags(archivedSection.flags);
19
- section.dirtyMap.fill(0xff);
20
- for (let i = 0; i < section.ids.length; i++) {
21
- section.ids[i] = importedSection.getId(i);
22
- section.level[i] = importedSection.getLevel(i);
23
- section.light[i] = importedSection.getLight(i);
24
- section.secondary[i] = importedSection.getSecondary(i);
28
+ section.dirtyMap.fill(0);
29
+ const idsBuffer = importedSection.buffers.ids;
30
+ const levelBuffer = importedSection.buffers.level;
31
+ const secondaryBuffer = importedSection.buffers.secondary;
32
+ const lightBuffers = importedSection.buffers.light;
33
+ const sectionPalettes = importedSection.palettes;
34
+ const sectorPalettes = importedSection.sector.palettes;
35
+ const voxelReader = importedSection.sector.voxels;
36
+ let voxelIdLUT = null;
37
+ if (!idsBuffer.isValue && sectionPalettes.voxels) {
38
+ const paletteSize = sectionPalettes.voxels.size;
39
+ voxelIdLUT = new Uint16Array(paletteSize);
40
+ for (let p = 0; p < paletteSize; p++) {
41
+ const paletteValue = sectionPalettes.voxels.getValue(p);
42
+ voxelIdLUT[p] = VoxelLUT.getVoxelIdFromString(...voxelReader.getVoxelData(paletteValue));
43
+ }
44
+ }
45
+ let secondaryIdLUT = null;
46
+ if (!secondaryBuffer.isValue && sectionPalettes.secondaryVoxels) {
47
+ const paletteSize = sectionPalettes.secondaryVoxels.size;
48
+ secondaryIdLUT = new Uint16Array(paletteSize);
49
+ for (let p = 0; p < paletteSize; p++) {
50
+ const paletteValue = sectionPalettes.secondaryVoxels.getValue(p);
51
+ secondaryIdLUT[p] = VoxelLUT.getVoxelIdFromString(...voxelReader.getVoxelData(paletteValue));
52
+ }
53
+ }
54
+ if (idsBuffer.isValue) {
55
+ const voxelId = VoxelLUT.getVoxelIdFromString(...voxelReader.getVoxelData(idsBuffer.getValue(0)));
56
+ section.ids.fill(voxelId);
57
+ }
58
+ if (levelBuffer.isValue) {
59
+ let levelValue = levelBuffer.getValue(0);
60
+ if (sectionPalettes.level) {
61
+ levelValue = sectionPalettes.level.getValue(levelValue);
62
+ }
63
+ else if (sectorPalettes.level) {
64
+ levelValue = sectorPalettes.level.getValue(levelValue);
65
+ }
66
+ section.level.fill(levelValue);
67
+ }
68
+ const sunIsValue = lightBuffers.sun.isValue;
69
+ const redIsValue = lightBuffers.red.isValue;
70
+ const greenIsValue = lightBuffers.green.isValue;
71
+ const blueIsValue = lightBuffers.blue.isValue;
72
+ if (sunIsValue && redIsValue && greenIsValue && blueIsValue) {
73
+ let finalLight = 0;
74
+ finalLight = lightSemgnetSet.sun(lightBuffers.sun.getValue(0), finalLight);
75
+ finalLight = lightSemgnetSet.red(lightBuffers.red.getValue(0), finalLight);
76
+ finalLight = lightSemgnetSet.green(lightBuffers.green.getValue(0), finalLight);
77
+ finalLight = lightSemgnetSet.blue(lightBuffers.blue.getValue(0), finalLight);
78
+ section.light.fill(finalLight);
79
+ }
80
+ const needsPerVoxelIds = !idsBuffer.isValue;
81
+ const needsPerVoxelLevel = !levelBuffer.isValue;
82
+ const needsPerVoxelSecondary = !secondaryBuffer.isValue;
83
+ const needsPerVoxelLight = !(sunIsValue &&
84
+ redIsValue &&
85
+ greenIsValue &&
86
+ blueIsValue);
87
+ if (!needsPerVoxelIds &&
88
+ !needsPerVoxelLevel &&
89
+ !needsPerVoxelSecondary &&
90
+ !needsPerVoxelLight) {
91
+ const staticId = section.ids[0];
92
+ const trueVoxelId = VoxelLUT.voxelIdToTrueId[staticId];
93
+ if (VoxelTagsRegister.VoxelTags[trueVoxelId]?.["dve_can_have_secondary"]) {
94
+ const secondaryValue = VoxelLUT.getVoxelIdFromString(...voxelReader.getVoxelData(secondaryBuffer.getValue(0)));
95
+ section.secondary.fill(secondaryValue);
96
+ }
97
+ const staticSecondary = section.secondary[0];
98
+ if (staticId !== 0 || staticSecondary !== 0) {
99
+ for (let i = 0; i < sectionVolume; i++) {
100
+ section.setHasVoxel(WorldSpaces.voxel.getPositionFromIndex(i, position).y, true);
101
+ }
102
+ }
103
+ if (archiveData.healLight) {
104
+ section.light.fill(0);
105
+ }
106
+ continue;
107
+ }
108
+ const sunPalette = sectionPalettes.light.sun || sectorPalettes.light.sun;
109
+ const redPalette = sectionPalettes.light.red || sectorPalettes.light.red;
110
+ const greenPalette = sectionPalettes.light.green || sectorPalettes.light.green;
111
+ const bluePalette = sectionPalettes.light.blue || sectorPalettes.light.blue;
112
+ const sunIsNibble = lightBuffers.sun.format === BinaryBufferFormat.NibbleArray;
113
+ const redIsNibble = lightBuffers.red.format === BinaryBufferFormat.NibbleArray;
114
+ const greenIsNibble = lightBuffers.green.format === BinaryBufferFormat.NibbleArray;
115
+ const blueIsNibble = lightBuffers.blue.format === BinaryBufferFormat.NibbleArray;
116
+ for (let i = 0; i < sectionVolume; i++) {
117
+ let voxelId;
118
+ if (needsPerVoxelIds) {
119
+ const rawValue = idsBuffer.getValue(i);
120
+ if (voxelIdLUT) {
121
+ voxelId = voxelIdLUT[rawValue];
122
+ }
123
+ else {
124
+ voxelId = VoxelLUT.getVoxelIdFromString(...voxelReader.getVoxelData(rawValue));
125
+ }
126
+ section.ids[i] = voxelId;
127
+ }
128
+ else {
129
+ voxelId = section.ids[i];
130
+ }
131
+ if (needsPerVoxelLevel) {
132
+ let levelValue = levelBuffer.getValue(i);
133
+ if (sectionPalettes.level) {
134
+ levelValue = sectionPalettes.level.getValue(levelValue);
135
+ }
136
+ else if (sectorPalettes.level) {
137
+ levelValue = sectorPalettes.level.getValue(levelValue);
138
+ }
139
+ section.level[i] = levelValue;
140
+ }
141
+ if (needsPerVoxelLight) {
142
+ let finalLight = 0;
143
+ if (!sunIsValue) {
144
+ let sunValue = lightBuffers.sun.getValue(i);
145
+ if (!sunIsNibble && sunPalette) {
146
+ sunValue = sunPalette.getValue(sunValue);
147
+ }
148
+ finalLight = lightSemgnetSet.sun(sunValue, finalLight);
149
+ }
150
+ else {
151
+ finalLight = lightSemgnetSet.sun(lightBuffers.sun.getValue(0), finalLight);
152
+ }
153
+ if (!redIsValue) {
154
+ let redValue = lightBuffers.red.getValue(i);
155
+ if (!redIsNibble && redPalette) {
156
+ redValue = redPalette.getValue(redValue);
157
+ }
158
+ finalLight = lightSemgnetSet.red(redValue, finalLight);
159
+ }
160
+ else {
161
+ finalLight = lightSemgnetSet.red(lightBuffers.red.getValue(0), finalLight);
162
+ }
163
+ if (!greenIsValue) {
164
+ let greenValue = lightBuffers.green.getValue(i);
165
+ if (!greenIsNibble && greenPalette) {
166
+ greenValue = greenPalette.getValue(greenValue);
167
+ }
168
+ finalLight = lightSemgnetSet.green(greenValue, finalLight);
169
+ }
170
+ else {
171
+ finalLight = lightSemgnetSet.green(lightBuffers.green.getValue(0), finalLight);
172
+ }
173
+ if (!blueIsValue) {
174
+ let blueValue = lightBuffers.blue.getValue(i);
175
+ if (!blueIsNibble && bluePalette) {
176
+ blueValue = bluePalette.getValue(blueValue);
177
+ }
178
+ finalLight = lightSemgnetSet.blue(blueValue, finalLight);
179
+ }
180
+ else {
181
+ finalLight = lightSemgnetSet.blue(lightBuffers.blue.getValue(0), finalLight);
182
+ }
183
+ section.light[i] = finalLight;
184
+ }
185
+ const trueVoxelId = VoxelLUT.voxelIdToTrueId[voxelId];
186
+ const rawSecondary = secondaryBuffer.getValue(i);
187
+ if (VoxelTagsRegister.VoxelTags[trueVoxelId]?.["dve_can_have_secondary"]) {
188
+ if (secondaryIdLUT) {
189
+ section.secondary[i] = secondaryIdLUT[rawSecondary];
190
+ }
191
+ else {
192
+ section.secondary[i] = VoxelLUT.getVoxelIdFromString(...voxelReader.getVoxelData(rawSecondary));
193
+ }
194
+ }
195
+ else {
196
+ section.secondary[i] = 0;
197
+ }
25
198
  if (section.ids[i] !== 0 || section.secondary[i] !== 0) {
26
- section.setHasVoxel(WorldSpaces.voxel.getPositionFromIndex(i, position).y - 1, true);
199
+ section.setHasVoxel(WorldSpaces.voxel.getPositionFromIndex(i, position).y, true);
27
200
  }
28
201
  }
202
+ if (archiveData.healLight) {
203
+ section.light.fill(0);
204
+ }
29
205
  }
30
206
  sector.setBitFlag(Sector.FlagIds.stored, true);
31
207
  return sector;
@@ -46,10 +46,7 @@ export class SectorCursor {
46
46
  return null;
47
47
  const section = this._current.sections[WorldSpaces.section.getIndex(x, y, z)];
48
48
  if (!section) {
49
- if (!section)
50
- throw new Error(`Could not load section at ${x}-${y}-${z} | ${WorldSpaces.section.getIndex(x, y, z)}`);
51
- this._section = null;
52
- return null;
49
+ throw new Error(`Could not load section at ${x}-${y}-${z} | ${WorldSpaces.section.getIndex(x, y, z)}`);
53
50
  }
54
51
  return section;
55
52
  }
@@ -3,11 +3,20 @@ import { SectorCursor } from "./SectorCursor";
3
3
  import { DataCursorInterface } from "../../Voxels/Cursor/DataCursor.interface";
4
4
  import { BoundingBox } from "@amodx/math/Geometry/Bounds/BoundingBox";
5
5
  export declare class WorldCursor implements DataCursorInterface {
6
- volumeBounds: BoundingBox;
7
- sectorCursors: Record<number, Record<number, SectorCursor | null>>;
6
+ sectorCursors: Map<number, Map<number, SectorCursor>>;
7
+ activeCursors: SectorCursor[];
8
8
  origin: Vector3Like;
9
9
  dimension: number;
10
- _lastPosition: Vector3Like;
10
+ _sectorPowerX: number;
11
+ _sectorPowerY: number;
12
+ _sectorPowerZ: number;
13
+ _minX: number;
14
+ _minY: number;
15
+ _minZ: number;
16
+ _maxX: number;
17
+ _maxY: number;
18
+ _maxZ: number;
19
+ volumeBounds: BoundingBox;
11
20
  constructor();
12
21
  private updateBounds;
13
22
  setFocalPoint(dimension: number, x: number, y: number, z: number): void;
@@ -5,55 +5,85 @@ import { BoundingBox } from "@amodx/math/Geometry/Bounds/BoundingBox";
5
5
  let cursorCache = [];
6
6
  const tempPosition = Vector3Like.Create();
7
7
  export class WorldCursor {
8
- volumeBounds = new BoundingBox();
9
- sectorCursors = {};
8
+ sectorCursors = new Map();
9
+ activeCursors = [];
10
10
  origin = Vector3Like.Create();
11
11
  dimension = 0;
12
- _lastPosition = Vector3Like.Create();
12
+ _sectorPowerX = 0;
13
+ _sectorPowerY = 0;
14
+ _sectorPowerZ = 0;
15
+ _minX = 0;
16
+ _minY = 0;
17
+ _minZ = 0;
18
+ _maxX = 0;
19
+ _maxY = 0;
20
+ _maxZ = 0;
21
+ volumeBounds = new BoundingBox();
13
22
  constructor() {
14
23
  this.updateBounds();
15
24
  }
16
25
  updateBounds() {
26
+ const world = WorldSpaces.world.bounds;
27
+ this._minX = world.MinX;
28
+ this._minY = world.MinY;
29
+ this._minZ = world.MinZ;
30
+ this._maxX = world.MaxX;
31
+ this._maxY = world.MaxY;
32
+ this._maxZ = world.MaxZ;
33
+ this._sectorPowerX = WorldSpaces.sector.power2Axes.x;
34
+ this._sectorPowerY = WorldSpaces.sector.power2Axes.y;
35
+ this._sectorPowerZ = WorldSpaces.sector.power2Axes.z;
17
36
  this.volumeBounds.setMinMax(Vector3Like.Create(WorldSpaces.world.bounds.MinX, WorldSpaces.world.bounds.MinY, WorldSpaces.world.bounds.MinZ), Vector3Like.Create(WorldSpaces.world.bounds.MaxX, WorldSpaces.world.bounds.MaxY, WorldSpaces.world.bounds.MaxZ));
18
37
  }
19
38
  setFocalPoint(dimension, x, y, z) {
20
- const sectorPos = WorldSpaces.sector.getPosition(x, y, z, tempPosition);
21
- for (const row in this.sectorCursors) {
22
- for (const col in this.sectorCursors[row]) {
23
- const cursor = this.sectorCursors[row][col];
24
- if (!cursor)
25
- continue;
39
+ const sectorPosX = (x >> this._sectorPowerX) << this._sectorPowerX;
40
+ const sectorPosY = (y >> this._sectorPowerY) << this._sectorPowerY;
41
+ const sectorPosZ = (z >> this._sectorPowerZ) << this._sectorPowerZ;
42
+ this.sectorCursors.forEach((row) => {
43
+ row.forEach((cursor) => {
26
44
  cursorCache.push(cursor);
27
- this.sectorCursors[row][col] = null;
28
- }
29
- }
45
+ });
46
+ row.clear();
47
+ });
48
+ this.sectorCursors.clear();
30
49
  this.dimension = dimension;
31
- this.origin.x = sectorPos.x / WorldSpaces.sector.bounds.x;
32
- this.origin.y = sectorPos.y / WorldSpaces.sector.bounds.y;
33
- this.origin.z = sectorPos.z / WorldSpaces.sector.bounds.z;
50
+ this.origin.x = sectorPosX >> this._sectorPowerX;
51
+ this.origin.y = sectorPosY >> this._sectorPowerY;
52
+ this.origin.z = sectorPosZ >> this._sectorPowerZ;
34
53
  this.getSector(x, y, z);
35
54
  }
36
55
  inBounds(x, y, z) {
37
- return WorldSpaces.world.inBounds(x, y, z);
56
+ return (x >= this._minX &&
57
+ x <= this._maxX &&
58
+ y >= this._minY &&
59
+ y <= this._maxY &&
60
+ z >= this._minZ &&
61
+ z <= this._maxZ);
38
62
  }
39
63
  getSector(x, y, z) {
40
64
  if (!this.inBounds(x, y, z))
41
65
  return null;
42
- const sectorPos = WorldSpaces.sector.getPosition(x, y, z, tempPosition);
43
- const cx = sectorPos.x / WorldSpaces.sector.bounds.x - this.origin.x;
44
- const cz = sectorPos.z / WorldSpaces.sector.bounds.z - this.origin.z;
45
- let cursor = this.sectorCursors[cx]?.[cz];
46
- if (!cursor) {
47
- cursor = cursorCache.length ? cursorCache.shift() : new SectorCursor();
48
- if (!cursor.loadSector(this.dimension, sectorPos.x, sectorPos.y, sectorPos.z)) {
49
- cursorCache.push(cursor);
50
- return null;
51
- }
52
- if (!this.sectorCursors[cx]) {
53
- this.sectorCursors[cx] = {};
54
- }
55
- this.sectorCursors[cx][cz] = cursor;
66
+ const sectorPosX = (x >> this._sectorPowerX) << this._sectorPowerX;
67
+ const sectorPosY = (y >> this._sectorPowerY) << this._sectorPowerY;
68
+ const sectorPosZ = (z >> this._sectorPowerZ) << this._sectorPowerZ;
69
+ const cx = (sectorPosX >> this._sectorPowerX) - this.origin.x;
70
+ const cz = (sectorPosZ >> this._sectorPowerZ) - this.origin.z;
71
+ let row = this.sectorCursors.get(cx);
72
+ if (row) {
73
+ const cursor = row.get(cz);
74
+ if (cursor)
75
+ return cursor;
76
+ }
77
+ else {
78
+ row = new Map();
79
+ this.sectorCursors.set(cx, row);
80
+ }
81
+ const cursor = cursorCache.length ? cursorCache.pop() : new SectorCursor();
82
+ if (!cursor.loadSector(this.dimension, sectorPosX, sectorPosY, sectorPosZ)) {
83
+ cursorCache.push(cursor);
84
+ return null;
56
85
  }
86
+ row.set(cz, cursor);
57
87
  return cursor;
58
88
  }
59
89
  getVoxel(x, y, z) {
@@ -10,7 +10,7 @@ export default function ({ threads, worldStorage, }) {
10
10
  WorldRegister.sectors.setSecotrBufferPool(true);
11
11
  const loadInMap = new Map();
12
12
  Threads.registerTask("cache-snap-shot", (data) => {
13
- const snapShot = SnapShots._pendingCache.shift();
13
+ const snapShot = SnapShots._pendingCache.pop();
14
14
  snapShot.restore(data);
15
15
  SnapShots._readyCache.push(snapShot);
16
16
  });
@@ -21,7 +21,11 @@ export default async function LockSectors(dimension, bounds) {
21
21
  }
22
22
  }
23
23
  }
24
- await Promise.all(waitingToLockSectors.map((_) => _.waitTillCheckedIn()));
24
+ const proms = [];
25
+ for (const _ of waitingToLockSectors) {
26
+ proms.push(_.waitTillCheckedIn());
27
+ }
28
+ await Promise.all(proms);
25
29
  for (const sector of waitingToLockSectors) {
26
30
  sector.setLocked(true);
27
31
  }
@@ -21,7 +21,11 @@ export default async function UnLockSectors(dimension, bounds) {
21
21
  }
22
22
  }
23
23
  }
24
- await Promise.all(waitingToLockSectors.map((_) => _.waitTillCheckedIn()));
24
+ const proms = [];
25
+ for (const _ of waitingToLockSectors) {
26
+ proms.push(_.waitTillCheckedIn());
27
+ }
28
+ await Promise.all(proms);
25
29
  for (const sector of waitingToLockSectors) {
26
30
  sector.setLocked(false);
27
31
  }
@@ -1,16 +1,20 @@
1
- import { Flat3DIndex } from "@amodx/math";
2
1
  import { LocationData } from "../../Math";
3
2
  export interface SectionSnapShotTransferData {
4
3
  location: LocationData;
5
4
  sections: Uint8Array[];
5
+ used: boolean[];
6
6
  }
7
7
  export declare class SectionSnapShot {
8
8
  sections: Uint8Array[];
9
9
  location: LocationData;
10
- index: Flat3DIndex;
11
10
  private _buffers;
11
+ private _used;
12
+ private _sectionSizeX;
13
+ private _sectionSizeY;
14
+ private _sectionSizeZ;
12
15
  constructor();
13
- setLocation([dimension, x, y, z]: LocationData): void;
16
+ private _updateSizes;
17
+ setLocation(dimension: number, x: number, y: number, z: number): void;
14
18
  storeSnapShot(): void;
15
19
  private _isTransfered;
16
20
  isTransfered(): boolean;