@divinevoxel/vlox 0.0.71 → 0.0.73

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 (271) hide show
  1. package/Contexts/Base/Main/InitDataGenerator.js +0 -9
  2. package/Contexts/Base/Remote/DataSync.types.d.ts +0 -5
  3. package/Contexts/Base/Remote/InitDataSync.js +17 -31
  4. package/Contexts/Render/DivineVoxelEngineRender.d.ts +1 -1
  5. package/Contexts/World/DivineVoxelEngineWorld.d.ts +1 -1
  6. package/Init/StartConstructor.js +7 -7
  7. package/Init/StartWorld.d.ts +1 -1
  8. package/Init/StartWorld.js +0 -12
  9. package/Math/Indexing.d.ts +12 -3
  10. package/Math/Indexing.js +24 -15
  11. package/Mesher/Functions/CompactVoxelMesh.d.ts +2 -2
  12. package/Mesher/Functions/CompactVoxelMesh.js +4 -5
  13. package/Mesher/Functions/MeshSection.d.ts +1 -1
  14. package/Mesher/Functions/MeshSection.js +72 -66
  15. package/Mesher/Functions/MeshTexture.d.ts +1 -1
  16. package/Mesher/Functions/MeshTexture.js +3 -4
  17. package/Mesher/Functions/MeshVoxel.js +20 -26
  18. package/Mesher/Geomtry/Primitives/QuadVertexData.d.ts +12 -10
  19. package/Mesher/Geomtry/Primitives/QuadVertexData.js +49 -56
  20. package/Mesher/Geomtry/VoxelGeometryBuilder.d.ts +2 -2
  21. package/Mesher/Geomtry/VoxelGeometryBuilder.js +108 -125
  22. package/Mesher/Geomtry/VoxelMesh.d.ts +1 -1
  23. package/Mesher/Geomtry/VoxelMesh.js +2 -2
  24. package/Mesher/{Tools → Geomtry}/VoxelMeshBVHBuilder.d.ts +2 -9
  25. package/Mesher/{Tools → Geomtry}/VoxelMeshBVHBuilder.js +4 -16
  26. package/Mesher/Geomtry/{Buffers.d.ts → VoxelMeshBuffers.d.ts} +9 -8
  27. package/Mesher/Geomtry/VoxelMeshBuffers.js +49 -0
  28. package/Mesher/{Tools → Geomtry}/VoxelMeshVertexStructCursor.d.ts +10 -0
  29. package/Mesher/{Tools → Geomtry}/VoxelMeshVertexStructCursor.js +10 -0
  30. package/Mesher/Geomtry/index.d.ts +0 -1
  31. package/Mesher/Geomtry/index.js +0 -1
  32. package/Mesher/InitMesher.js +2 -11
  33. package/Mesher/InitTask.js +10 -22
  34. package/Mesher/Models/Common/BoundsFunctions.d.ts +1 -3
  35. package/Mesher/Models/Common/BoundsFunctions.js +0 -16
  36. package/Mesher/Models/Common/Calc/CalcConstants.js +14 -31
  37. package/Mesher/Models/Common/Calc/FaceDataCalc.d.ts +2 -8
  38. package/Mesher/Models/Common/Calc/FaceDataCalc.js +50 -52
  39. package/Mesher/Models/Nodes/Custom/Liquid/FlowGradient.d.ts +2 -2
  40. package/Mesher/Models/Nodes/Custom/Liquid/FlowGradient.js +1 -1
  41. package/Mesher/Models/Nodes/Custom/Liquid/LiquidGeomtryNode.d.ts +1 -5
  42. package/Mesher/Models/Nodes/Custom/Liquid/LiquidGeomtryNode.js +40 -42
  43. package/Mesher/Models/Nodes/GeometryNode.d.ts +3 -5
  44. package/Mesher/Models/Nodes/GeometryNode.js +1 -2
  45. package/Mesher/Models/Nodes/Ruled/BoxVoxelGeometryNode.d.ts +3 -6
  46. package/Mesher/Models/Nodes/Ruled/BoxVoxelGeometryNode.js +55 -40
  47. package/Mesher/Models/Nodes/Ruled/QuadVoxelGeometryNode.d.ts +2 -6
  48. package/Mesher/Models/Nodes/Ruled/QuadVoxelGeometryNode.js +52 -51
  49. package/Mesher/Models/Nodes/Ruleless/RulelessBoxVoxelGeometryNode.d.ts +2 -6
  50. package/Mesher/Models/Nodes/Ruleless/RulelessBoxVoxelGeometryNode.js +18 -19
  51. package/Mesher/Models/Nodes/Ruleless/RulelessQuadVoxelGeometryNode.d.ts +2 -6
  52. package/Mesher/Models/Nodes/Ruleless/RulelessQuadVoxelGeometryNode.js +37 -40
  53. package/Mesher/{Tools → Models/Protocols}/OutlinedVoxelTool.d.ts +1 -1
  54. package/Mesher/{Tools → Models/Protocols}/OutlinedVoxelTool.js +1 -1
  55. package/Mesher/Models/RenderedMaterials.d.ts +6 -0
  56. package/Mesher/{RenderedMaterials.js → Models/RenderedMaterials.js} +2 -2
  57. package/Mesher/Models/VoxelConstructor.d.ts +4 -5
  58. package/Mesher/Models/VoxelConstructor.js +23 -12
  59. package/Mesher/Models/{VoxelGeometryLookUp.d.ts → VoxelGeometryBuilderCacheSpace.d.ts} +6 -14
  60. package/Mesher/Models/{VoxelGeometryLookUp.js → VoxelGeometryBuilderCacheSpace.js} +26 -44
  61. package/Mesher/{Tools/VoxelMesherDataTool.d.ts → Models/VoxelModelBuilder.d.ts} +10 -8
  62. package/Mesher/{Tools/VoxelMesherDataTool.js → Models/VoxelModelBuilder.js} +44 -19
  63. package/Mesher/Models/VoxelModelConstructorRegister.js +3 -3
  64. package/Models/Defaults/CubeVoxelGeometry.js +4 -0
  65. package/Models/Defaults/CubeVoxelModels.js +344 -344
  66. package/Models/Defaults/LiquidVoxelModel.js +2 -2
  67. package/Models/Defaults/PanelVoxelModels.js +432 -432
  68. package/Models/Defaults/StairVoxelModel.js +576 -576
  69. package/Models/Examples.js +469 -456
  70. package/Models/Indexing/VoxelAOResultsIndex.d.ts +4 -4
  71. package/Models/Indexing/VoxelAOResultsIndex.js +15 -9
  72. package/Models/Indexing/VoxelFaceCullResultsIndex.d.ts +3 -3
  73. package/Models/Indexing/VoxelFaceCullResultsIndex.js +14 -9
  74. package/Models/Indexing/VoxelFaceTransparentResultsIndex.d.ts +1 -1
  75. package/Models/Indexing/VoxelFaceTransparentResultsIndex.js +1 -1
  76. package/Models/Rules/Functions/BuildFinalInputs.js +9 -7
  77. package/Models/Rules/Functions/BuildGeomtryInputs.js +8 -5
  78. package/Models/Rules/Functions/BuildRules.js +4 -4
  79. package/Models/Rules/{VoxelModelManager.d.ts → VoxelModelRuleBuilderRegister.d.ts} +1 -1
  80. package/Models/Rules/VoxelModelRuleBuilderRegister.js +178 -0
  81. package/Models/VoxelModel.types.d.ts +14 -5
  82. package/Renderer/Classes/SectorMesh.d.ts +3 -4
  83. package/Renderer/Classes/SectorMesh.js +6 -11
  84. package/Renderer/InitTasks.js +6 -7
  85. package/Renderer/MeshManager.js +2 -2
  86. package/Renderer/MeshRegister.js +2 -1
  87. package/Settings/EngineSettings.d.ts +1 -1
  88. package/Settings/EngineSettings.js +3 -5
  89. package/Settings/EngineSettings.types.d.ts +17 -18
  90. package/Settings/EngineSettings.types.js +16 -15
  91. package/Tasks/IWG/IWG.d.ts +2 -1
  92. package/Tasks/IWG/IWG.js +9 -3
  93. package/Tasks/IWG/Internal/Classes/BuildQueue.d.ts +11 -0
  94. package/Tasks/IWG/Internal/Classes/BuildQueue.js +49 -0
  95. package/Tasks/IWG/Internal/Classes/Generator.d.ts +6 -1
  96. package/Tasks/IWG/Internal/Classes/Generator.js +14 -2
  97. package/Tasks/IWG/Internal/Classes/IWGTaskBase.js +2 -2
  98. package/Tasks/IWG/Internal/Functions/getSectorState.js +4 -7
  99. package/Tasks/IWG/Internal/Functions/runBuildUpdate.js +21 -2
  100. package/Tasks/IWG/Internal/Functions/runWorldUpdate.js +5 -6
  101. package/Tasks/IWG/Internal/IWGTasks.d.ts +0 -4
  102. package/Tasks/IWG/Internal/IWGTasks.js +12 -31
  103. package/Tasks/IWG/Internal/IWGTools.d.ts +1 -1
  104. package/Tasks/IWG/Procedures/SaveAllSectors.js +2 -0
  105. package/Tasks/Propagation/Flow/FlowManager.d.ts +0 -2
  106. package/Tasks/Propagation/Flow/FlowManager.js +86 -87
  107. package/Tasks/Propagation/Flow/WorldFlow.js +2 -3
  108. package/Tasks/Propagation/Illumanation/WorldRGB.js +1 -2
  109. package/Tasks/Update/InitTasks.d.ts +2 -1
  110. package/Tasks/Update/InitTasks.js +6 -6
  111. package/Tasks/Update/UpdateTask.d.ts +3 -1
  112. package/Tasks/Update/UpdateTask.js +28 -2
  113. package/Tasks/Update/VoxelUpdate.js +21 -7
  114. package/Tasks/WorldGeneration/WorldGenBrush.js +2 -1
  115. package/Templates/Cursor/TemplateCursor.d.ts +2 -2
  116. package/Templates/Cursor/TemplateCursor.js +1 -2
  117. package/Templates/Functions/CreateTemplate.js +1 -1
  118. package/Templates/VoxelTemplate.js +6 -8
  119. package/Templates/VoxelTemplates.types.d.ts +1 -1
  120. package/Textures/Classes/CompiledTexture.d.ts +18 -0
  121. package/Textures/Classes/CompiledTexture.js +50 -0
  122. package/Textures/Classes/CompiledTextureAnimation.d.ts +12 -0
  123. package/Textures/Classes/CompiledTextureAnimation.js +27 -0
  124. package/Textures/Classes/TextureAnimationTexture.d.ts +10 -0
  125. package/Textures/Classes/TextureAnimationTexture.js +32 -0
  126. package/Textures/Functions/BuildTextureData.d.ts +10 -0
  127. package/Textures/Functions/BuildTextureData.js +205 -0
  128. package/Textures/Texture.types.d.ts +50 -64
  129. package/Textures/TextureManager.d.ts +8 -19
  130. package/Textures/TextureManager.js +28 -166
  131. package/Tools/Brush/Brush.d.ts +1 -3
  132. package/Tools/Brush/Brush.js +43 -12
  133. package/Util/Binary/BinaryArrays.d.ts +6 -0
  134. package/Util/Binary/BinaryArrays.js +25 -0
  135. package/Util/Binary/BinaryBuffer.d.ts +29 -0
  136. package/Util/Binary/BinaryBuffer.js +130 -0
  137. package/Util/Binary/BinaryFunctions.d.ts +3 -0
  138. package/Util/Binary/BinaryFunctions.js +11 -0
  139. package/Util/StringPalette.d.ts +1 -0
  140. package/Util/StringPalette.js +8 -0
  141. package/Voxels/Cursor/DataCursor.interface.d.ts +5 -0
  142. package/Voxels/Cursor/VoxelCursor.d.ts +6 -6
  143. package/Voxels/Cursor/VoxelCursor.interface.d.ts +11 -16
  144. package/Voxels/Cursor/VoxelCursor.interface.js +35 -58
  145. package/Voxels/Cursor/VoxelCursor.js +13 -12
  146. package/Voxels/Cursor/VoxelLightData.d.ts +3 -4
  147. package/Voxels/Cursor/VoxelLightData.js +8 -7
  148. package/Voxels/Data/VoxelPalettesRegister.d.ts +8 -0
  149. package/Voxels/Data/VoxelPalettesRegister.js +8 -0
  150. package/Voxels/Data/VoxelTag.types.d.ts +56 -0
  151. package/Voxels/Data/VoxelTag.types.js +23 -0
  152. package/Voxels/{State → Data}/VoxelTagStates.d.ts +2 -2
  153. package/Voxels/{State → Data}/VoxelTagStates.js +5 -5
  154. package/Voxels/Data/VoxelTagsRegister.d.ts +9 -0
  155. package/Voxels/Data/VoxelTagsRegister.js +32 -0
  156. package/Voxels/Functions/BuildStateData.js +12 -12
  157. package/Voxels/Functions/BuildTagAndPaletteData.d.ts +13 -0
  158. package/Voxels/Functions/BuildTagAndPaletteData.js +55 -0
  159. package/Voxels/Indexes/VoxelIndex.js +3 -3
  160. package/Voxels/InitVoxelData.js +31 -73
  161. package/Voxels/State/Schema/StateSchema.d.ts +1 -1
  162. package/Voxels/Types/Voxel.types.d.ts +20 -42
  163. package/Voxels/Types/Voxel.types.js +6 -17
  164. package/Voxels/Types/VoxelModelCompiledData.types.d.ts +11 -13
  165. package/Voxels/Types/VoxelSubstances.types.d.ts +2 -15
  166. package/Voxels/Types/VoxelSubstances.types.js +1 -9
  167. package/World/Archive/Archive.types.d.ts +38 -34
  168. package/World/Archive/Functions/ArchiveArea.js +18 -30
  169. package/World/Archive/Functions/ArchiveSector.js +484 -213
  170. package/World/Archive/Functions/ImportSector.d.ts +3 -3
  171. package/World/Archive/Functions/ImportSector.js +205 -151
  172. package/World/Archive/Functions/Shared.d.ts +6 -0
  173. package/World/Archive/Functions/Shared.js +75 -0
  174. package/World/Archive/InitTasks.js +30 -13
  175. package/World/Cursor/SectionCursor.d.ts +3 -2
  176. package/World/Cursor/SectionCursor.js +9 -4
  177. package/World/Cursor/SectorCursor.d.ts +3 -2
  178. package/World/Cursor/SectorCursor.js +5 -3
  179. package/World/Cursor/WorldCursor.d.ts +2 -2
  180. package/World/Cursor/WorldCursor.js +6 -3
  181. package/World/Cursor/WorldVoxelCursor.d.ts +7 -7
  182. package/World/Cursor/WorldVoxelCursor.js +21 -24
  183. package/World/InitTasks.d.ts +1 -1
  184. package/World/Lock/WorldLock.d.ts +1 -1
  185. package/World/Section/Section.d.ts +31 -23
  186. package/World/Section/Section.js +116 -18
  187. package/World/Section/SectionState.d.ts +10 -0
  188. package/World/Section/SectionState.js +11 -0
  189. package/World/Sector/Sector.d.ts +24 -9
  190. package/World/Sector/Sector.js +92 -21
  191. package/World/Sector/SectorHeightMap.js +3 -5
  192. package/World/Sector/SectorState.d.ts +21 -0
  193. package/World/Sector/SectorState.js +28 -0
  194. package/World/WorldRegister.d.ts +4 -0
  195. package/World/WorldRegister.js +15 -3
  196. package/World/WorldSpaces.d.ts +6 -0
  197. package/World/WorldSpaces.js +25 -6
  198. package/package.json +1 -1
  199. package/Data/Cursor/DataCursor.interface.d.ts +0 -5
  200. package/Data/Cursor/DataCursor.interface.js +0 -2
  201. package/Data/Register/MappedDataRegister.d.ts +0 -5
  202. package/Data/Register/MappedDataRegister.js +0 -9
  203. package/Data/Register/MappedRegisterBase.d.ts +0 -14
  204. package/Data/Register/MappedRegisterBase.js +0 -50
  205. package/Data/Structs/StructBuilder.d.ts +0 -34
  206. package/Data/Structs/StructBuilder.js +0 -157
  207. package/Data/Structs/StructBuilder.types.d.ts +0 -30
  208. package/Mesher/Functions/CompactMesh.d.ts +0 -2
  209. package/Mesher/Functions/CompactMesh.js +0 -42
  210. package/Mesher/Geomtry/Buffers.js +0 -81
  211. package/Mesher/Geomtry/GeometryNormals.d.ts +0 -10
  212. package/Mesher/Geomtry/GeometryNormals.js +0 -52
  213. package/Mesher/Geomtry/MeshData.types.d.ts +0 -13
  214. package/Mesher/Geomtry/MeshData.types.js +0 -6
  215. package/Mesher/Geomtry/Tools/MesherDataTools.d.ts +0 -7
  216. package/Mesher/Geomtry/Tools/MesherDataTools.js +0 -12
  217. package/Mesher/Geomtry/Tools/index.d.ts +0 -1
  218. package/Mesher/Geomtry/Tools/index.js +0 -1
  219. package/Mesher/RenderedMaterials.d.ts +0 -6
  220. package/Models/Rules/VoxelModelManager.js +0 -82
  221. package/Textures/TextureAnimations.d.ts +0 -4
  222. package/Textures/TextureAnimations.js +0 -35
  223. package/Textures/TextureArray.d.ts +0 -47
  224. package/Textures/TextureArray.js +0 -202
  225. package/Textures/TextureBuilder.d.ts +0 -13
  226. package/Textures/TextureBuilder.js +0 -120
  227. package/Textures/TextureRegister.d.ts +0 -9
  228. package/Textures/TextureRegister.js +0 -28
  229. package/Tools/Data/SubstanceDataTool.d.ts +0 -13
  230. package/Tools/Data/SubstanceDataTool.js +0 -51
  231. package/Voxels/Palettes/MaterialPalette.d.ts +0 -9
  232. package/Voxels/Palettes/MaterialPalette.js +0 -11
  233. package/Voxels/Palettes/SubstancePalette.d.ts +0 -9
  234. package/Voxels/Palettes/SubstancePalette.js +0 -11
  235. package/Voxels/Palettes/VoxelPalette.d.ts +0 -11
  236. package/Voxels/Palettes/VoxelPalette.js +0 -15
  237. package/Voxels/Segments/MaterialDataGenerator.d.ts +0 -6
  238. package/Voxels/Segments/MaterialDataGenerator.js +0 -12
  239. package/Voxels/Segments/SubstanceDataGenerator.d.ts +0 -6
  240. package/Voxels/Segments/SubstanceDataGenerator.js +0 -35
  241. package/Voxels/Segments/VoxelDataGenerator.d.ts +0 -10
  242. package/Voxels/Segments/VoxelDataGenerator.js +0 -56
  243. package/Voxels/Structs/Builder/SubstanceStructBuilder.d.ts +0 -2
  244. package/Voxels/Structs/Builder/SubstanceStructBuilder.js +0 -42
  245. package/Voxels/Structs/Builder/VoxelStructBuilder.d.ts +0 -2
  246. package/Voxels/Structs/Builder/VoxelStructBuilder.js +0 -68
  247. package/Voxels/Structs/SubstanceStruct.d.ts +0 -17
  248. package/Voxels/Structs/SubstanceStruct.js +0 -17
  249. package/Voxels/Structs/VoxelStruct.d.ts +0 -27
  250. package/Voxels/Structs/VoxelStruct.js +0 -29
  251. package/World/Section/SectionHeightMap.d.ts +0 -10
  252. package/World/Section/SectionHeightMap.js +0 -39
  253. package/World/Section/SectionStruct.d.ts +0 -8
  254. package/World/Section/SectionStruct.js +0 -29
  255. package/World/Section/SectionStructProperties.d.ts +0 -10
  256. package/World/Section/SectionStructProperties.js +0 -11
  257. package/World/Sector/SectorStruct.d.ts +0 -1
  258. package/World/Sector/SectorStruct.js +0 -46
  259. package/World/Sector/SectorStructIds.d.ts +0 -13
  260. package/World/Sector/SectorStructIds.js +0 -14
  261. package/World/Structs/WorldDataStructProperties.d.ts +0 -8
  262. package/World/Structs/WorldDataStructProperties.js +0 -9
  263. /package/Mesher/{VoxelShaderData.d.ts → Geomtry/VoxelShaderData.d.ts} +0 -0
  264. /package/Mesher/{VoxelShaderData.js → Geomtry/VoxelShaderData.js} +0 -0
  265. /package/{Data/Functions → Util/Binary}/Palettes.d.ts +0 -0
  266. /package/{Data/Functions → Util/Binary}/Palettes.js +0 -0
  267. /package/{Data/Structs/StructBuilder.types.js → Voxels/Cursor/DataCursor.interface.js} +0 -0
  268. /package/Voxels/{VoxelLevelReader.d.ts → Cursor/VoxelLevelReader.d.ts} +0 -0
  269. /package/Voxels/{VoxelLevelReader.js → Cursor/VoxelLevelReader.js} +0 -0
  270. /package/World/{Storage → Types}/WorldStorage.interface.d.ts +0 -0
  271. /package/World/{Storage → Types}/WorldStorage.interface.js +0 -0
@@ -1,54 +1,65 @@
1
1
  import { StringPalette } from "../../../Util/StringPalette";
2
2
  import { NumberPalette } from "../../../Util/NumberPalette";
3
3
  import { WorldRegister } from "../../../World/WorldRegister";
4
- import { VoxelPalette } from "../../../Voxels/Palettes/VoxelPalette";
5
- import { VoxelStruct } from "../../../Voxels/Structs/VoxelStruct";
6
- import { VoxelStructIds } from "../../../Voxels/Types/Voxel.types";
7
- import { Section, Sector } from "../../../World/index";
8
- import { convertToPaletteBuffer } from "../../../Data/Functions/Palettes";
9
4
  import { SchemaRegister } from "../../../Voxels/State/SchemaRegister";
5
+ import { VoxelPalettesRegister } from "../../../Voxels/Data/VoxelPalettesRegister";
6
+ import { VoxelTagsRegister } from "../../../Voxels/Data/VoxelTagsRegister";
7
+ import { VoxelLightData } from "../../../Voxels/Cursor/VoxelLightData";
8
+ import { EngineSettings } from "../../../Settings/EngineSettings";
9
+ import { setNibbleArrayIndex } from "../../../Util/Binary/BinaryArrays";
10
+ import { BinaryBuffer } from "../../../Util/Binary/BinaryBuffer";
11
+ import { compareSection, lightSegments, lightSemgnetGet, uint16To4CharString, } from "./Shared";
12
+ function getProcessedData(buffer) {
13
+ return {
14
+ buffer,
15
+ allTheSame: true,
16
+ isPaletted: false,
17
+ remapped: false,
18
+ value: 0,
19
+ };
20
+ }
10
21
  const getProcessedSection = (section) => {
11
22
  return {
12
- section,
23
+ original: section,
13
24
  palettes: getSectionPalettes(),
25
+ isBuriedAllTheSame: false,
26
+ buriedValue: 0,
27
+ isVoxelMapAllTheSame: false,
28
+ voxelMapValue: 0,
29
+ isDirtyMapAllTheSame: false,
30
+ dirtyMapValue: 0,
14
31
  // ids
15
- ids: new Uint16Array(section.ids.length),
16
- idsAllTheSame: true,
17
- remappedIds: false,
32
+ ids: getProcessedData(new Uint16Array(section.ids.length)),
18
33
  // light
19
- light: new Uint16Array(section.light.length),
20
- lightAllTheSame: true,
21
- isLightPaletted: false,
22
- remappedLight: false,
34
+ light: {
35
+ sun: getProcessedData(new Uint8Array(section.light.length)),
36
+ red: getProcessedData(new Uint8Array(section.light.length)),
37
+ green: getProcessedData(new Uint8Array(section.light.length)),
38
+ blue: getProcessedData(new Uint8Array(section.light.length)),
39
+ },
23
40
  // level
24
- level: new Uint8Array(section.level.length),
25
- levelAllTheSame: true,
26
- isLevelPaletted: false,
27
- remappedLevel: false,
41
+ level: getProcessedData(new Uint8Array(section.level.length)),
28
42
  // state
29
- state: new Uint16Array(section.state.length),
30
- stateAllTheSame: true,
31
- isStatePaletted: false,
32
- remappedState: false,
43
+ state: getProcessedData(new Uint16Array(section.level.length)),
33
44
  // mod
34
- mod: new Uint16Array(section.mod.length),
35
- modAllTheSame: true,
36
- isModPaletted: false,
37
- remappedMod: false,
45
+ mod: getProcessedData(new Uint16Array(section.mod.length)),
38
46
  // secondary
39
- secondary: new Uint16Array(section.secondary.length),
40
- isSecondaryPaletted: false,
41
- secondaryAllTheSame: true,
42
- remappedSecondary: false,
47
+ secondary: getProcessedData(new Uint16Array(section.mod.length)),
43
48
  };
44
49
  };
45
- let sectorStructInstance;
46
- let sectionStructInstance;
50
+ function getLightPalette() {
51
+ return {
52
+ sun: new NumberPalette(),
53
+ red: new NumberPalette(),
54
+ green: new NumberPalette(),
55
+ blue: new NumberPalette(),
56
+ };
57
+ }
47
58
  function getSectionPalettes() {
48
59
  return {
49
60
  ids: new NumberPalette(),
50
61
  level: new NumberPalette(),
51
- light: new NumberPalette(),
62
+ light: getLightPalette(),
52
63
  state: new NumberPalette(),
53
64
  mod: new NumberPalette(),
54
65
  secondaryId: new NumberPalette(),
@@ -59,7 +70,7 @@ function getColumnPalettes() {
59
70
  return {
60
71
  ids: new StringPalette(),
61
72
  level: new NumberPalette(),
62
- light: new NumberPalette(),
73
+ light: getLightPalette(),
63
74
  stateIdMap: [],
64
75
  state: new NumberPalette(),
65
76
  modIdMap: [],
@@ -68,103 +79,315 @@ function getColumnPalettes() {
68
79
  secondaryState: new NumberPalette(),
69
80
  };
70
81
  }
82
+ function getLightBuffer(light, buffer) {
83
+ const array = new Uint8Array(buffer.length / 2);
84
+ for (let i = 0; i < buffer.length; i++) {
85
+ let l = 0;
86
+ if (light == "sun")
87
+ l = lightData.getS(buffer[i]);
88
+ if (light == "red")
89
+ l = lightData.getR(buffer[i]);
90
+ if (light == "green")
91
+ l = lightData.getG(buffer[i]);
92
+ if (light == "blue")
93
+ l = lightData.getB(buffer[i]);
94
+ setNibbleArrayIndex(array, i, l);
95
+ }
96
+ return array;
97
+ }
71
98
  function GetArchivedSection(archiveSection, sectorPalettes) {
72
- sectionStructInstance.setData(archiveSection.section.sectionState);
73
99
  const palettes = {};
74
- if (archiveSection.remappedIds)
100
+ if (archiveSection.ids.remapped)
75
101
  palettes.id = Uint16Array.from(archiveSection.palettes.ids._palette);
76
- if (archiveSection.remappedLevel)
102
+ if (archiveSection.level.remapped)
77
103
  palettes.level = Uint8Array.from(archiveSection.palettes.level._palette);
78
- if (archiveSection.remappedLight)
79
- palettes.light = Uint16Array.from(archiveSection.palettes.light._palette);
80
- if (archiveSection.remappedState)
104
+ if (archiveSection.light.sun.remapped) {
105
+ palettes.light ??= {};
106
+ palettes.light.sun = Uint8Array.from(archiveSection.palettes.light.sun._palette);
107
+ }
108
+ if (archiveSection.light.red.remapped) {
109
+ palettes.light ??= {};
110
+ palettes.light.red = Uint8Array.from(archiveSection.palettes.light.red._palette);
111
+ }
112
+ if (archiveSection.light.green.remapped) {
113
+ palettes.light ??= {};
114
+ palettes.light.green = Uint8Array.from(archiveSection.palettes.light.green._palette);
115
+ }
116
+ if (archiveSection.light.blue.remapped) {
117
+ palettes.light ??= {};
118
+ palettes.light.blue = Uint8Array.from(archiveSection.palettes.light.blue._palette);
119
+ }
120
+ if (archiveSection.state.remapped)
81
121
  palettes.state = Uint16Array.from(archiveSection.palettes.state._palette);
82
- if (archiveSection.remappedMod)
122
+ if (archiveSection.mod.remapped)
83
123
  palettes.mod = Uint16Array.from(archiveSection.palettes.mod._palette);
84
- if (archiveSection.remappedSecondary) {
124
+ if (archiveSection.secondary.remapped) {
85
125
  palettes.secondaryId = Uint16Array.from(archiveSection.palettes.secondaryId._palette);
86
126
  palettes.secondaryState = Uint16Array.from(archiveSection.palettes.secondaryState._palette);
87
127
  }
128
+ const buffers = {};
129
+ //id
130
+ if (archiveSection.ids.allTheSame) {
131
+ if (archiveSection.ids.buffer[0] !== 0) {
132
+ buffers.id = archiveSection.ids.buffer[0];
133
+ }
134
+ }
135
+ else if (archiveSection.ids.isPaletted) {
136
+ const type = BinaryBuffer.DetermineSubByteArray(archiveSection.ids.remapped
137
+ ? archiveSection.palettes.ids.size
138
+ : sectorPalettes.ids.size);
139
+ buffers.id = BinaryBuffer.Create({
140
+ buffer: BinaryBuffer.Convert(archiveSection.ids.buffer, "16-bit", type),
141
+ type,
142
+ });
143
+ }
144
+ else {
145
+ buffers.id = BinaryBuffer.Create({
146
+ buffer: archiveSection.ids.buffer,
147
+ });
148
+ }
149
+ //level
150
+ if (archiveSection.level.allTheSame) {
151
+ if (archiveSection.level.buffer[0] !== 0) {
152
+ buffers.level = archiveSection.level.buffer[0];
153
+ }
154
+ }
155
+ else if (archiveSection.level.isPaletted) {
156
+ const type = BinaryBuffer.DetermineSubByteArray(archiveSection.level.remapped
157
+ ? archiveSection.palettes.level.size
158
+ : sectorPalettes.level.size);
159
+ buffers.level = BinaryBuffer.Create({
160
+ buffer: BinaryBuffer.Convert(archiveSection.level.buffer, "8-bit", type),
161
+ type,
162
+ });
163
+ }
164
+ else {
165
+ buffers.level = BinaryBuffer.Create({
166
+ buffer: archiveSection.original.level.slice(),
167
+ });
168
+ }
169
+ for (const semgnet of lightSegments) {
170
+ if (archiveSection.light[semgnet].allTheSame) {
171
+ if (archiveSection.light[semgnet].value !== 0) {
172
+ buffers.light ??= {};
173
+ buffers.light[semgnet] = archiveSection.light[semgnet].value;
174
+ }
175
+ }
176
+ else if (archiveSection.light[semgnet].isPaletted) {
177
+ const type = BinaryBuffer.DetermineSubByteArray(archiveSection.light[semgnet].remapped
178
+ ? archiveSection.palettes.light[semgnet].size
179
+ : sectorPalettes.light[semgnet].size);
180
+ buffers.light ??= {};
181
+ buffers.light[semgnet] = BinaryBuffer.Create({
182
+ buffer: BinaryBuffer.Convert(archiveSection.light[semgnet].buffer, "8-bit", type),
183
+ type,
184
+ });
185
+ }
186
+ else {
187
+ buffers.light ??= {};
188
+ buffers.light[semgnet] = BinaryBuffer.Create({
189
+ buffer: getLightBuffer(semgnet, archiveSection.original.light),
190
+ type: "4-bit",
191
+ });
192
+ }
193
+ }
194
+ if (archiveSection.state.allTheSame) {
195
+ if (archiveSection.state.buffer[0] !== 0) {
196
+ buffers.state = archiveSection.state.buffer[0];
197
+ }
198
+ }
199
+ else if (archiveSection.state.isPaletted) {
200
+ const type = BinaryBuffer.DetermineSubByteArray(archiveSection.state.remapped
201
+ ? archiveSection.palettes.state.size
202
+ : sectorPalettes.state.size);
203
+ buffers.state = BinaryBuffer.Create({
204
+ buffer: BinaryBuffer.Convert(archiveSection.state.buffer, "16-bit", type),
205
+ type,
206
+ });
207
+ }
208
+ else {
209
+ buffers.state = BinaryBuffer.Create({
210
+ buffer: archiveSection.state.buffer,
211
+ });
212
+ }
213
+ if (archiveSection.mod.allTheSame) {
214
+ if (archiveSection.mod.buffer[0] !== 0) {
215
+ buffers.mod = archiveSection.mod.buffer[0];
216
+ }
217
+ }
218
+ else if (archiveSection.mod.isPaletted) {
219
+ const type = BinaryBuffer.DetermineSubByteArray(archiveSection.mod.remapped
220
+ ? archiveSection.palettes.mod.size
221
+ : sectorPalettes.mod.size);
222
+ buffers.mod = BinaryBuffer.Create({
223
+ buffer: BinaryBuffer.Convert(archiveSection.mod.buffer, "16-bit", type),
224
+ type,
225
+ });
226
+ }
227
+ else {
228
+ buffers.mod = BinaryBuffer.Create({
229
+ buffer: archiveSection.mod.buffer,
230
+ });
231
+ }
232
+ if (archiveSection.secondary.allTheSame) {
233
+ if (archiveSection.secondary.buffer[0] !== 0) {
234
+ buffers.secondary = archiveSection.secondary.buffer[0];
235
+ }
236
+ }
237
+ else if (archiveSection.secondary.isPaletted) {
238
+ const type = BinaryBuffer.DetermineSubByteArray(archiveSection.secondary.remapped
239
+ ? Math.max(archiveSection.palettes.secondaryState.size, archiveSection.palettes.secondaryId.size)
240
+ : Math.max(sectorPalettes.secondaryState.size, sectorPalettes.secondaryId.size));
241
+ buffers.secondary = BinaryBuffer.Create({
242
+ buffer: BinaryBuffer.Convert(archiveSection.secondary.buffer, "16-bit", type),
243
+ type,
244
+ });
245
+ }
246
+ else {
247
+ buffers.secondary = BinaryBuffer.Create({
248
+ buffer: archiveSection.secondary.buffer,
249
+ });
250
+ }
251
+ if (archiveSection.isBuriedAllTheSame) {
252
+ if (archiveSection.buriedValue !== 0) {
253
+ buffers.buried = archiveSection.buriedValue;
254
+ }
255
+ }
256
+ else {
257
+ buffers.buried = archiveSection.original.buried.slice();
258
+ }
259
+ if (archiveSection.isVoxelMapAllTheSame) {
260
+ if (archiveSection.voxelMapValue !== 0) {
261
+ buffers.voxelMap = archiveSection.voxelMapValue;
262
+ }
263
+ }
264
+ else {
265
+ buffers.voxelMap = archiveSection.original.voxelMap.slice();
266
+ }
267
+ if (archiveSection.isDirtyMapAllTheSame) {
268
+ if (archiveSection.dirtyMapValue !== 0) {
269
+ buffers.dirtyMap = archiveSection.dirtyMapValue;
270
+ }
271
+ }
272
+ else {
273
+ buffers.dirtyMap = archiveSection.original.dirtyMap.slice();
274
+ }
275
+ const flags = archiveSection.original.storeFlags();
88
276
  return {
89
- state: Object.values(sectionStructInstance.serialize()),
90
- palettes,
91
- buffers: {
92
- id: archiveSection.idsAllTheSame
93
- ? archiveSection.ids[0]
94
- : convertToPaletteBuffer(archiveSection.remappedIds
95
- ? archiveSection.palettes.ids.size
96
- : sectorPalettes.ids.size, archiveSection.ids),
97
- level: archiveSection.isLevelPaletted
98
- ? archiveSection.level[0]
99
- : archiveSection.isLevelPaletted
100
- ? convertToPaletteBuffer(archiveSection.remappedLevel
101
- ? archiveSection.palettes.level.size
102
- : sectorPalettes.level.size, archiveSection.level)
103
- : new Uint8Array(archiveSection.section.level.slice()),
104
- light: archiveSection.lightAllTheSame
105
- ? archiveSection.light[0]
106
- : archiveSection.isLightPaletted
107
- ? convertToPaletteBuffer(archiveSection.remappedLight
108
- ? archiveSection.palettes.light.size
109
- : sectorPalettes.light.size, archiveSection.light)
110
- : new Uint16Array(archiveSection.section.light.slice()),
111
- state: archiveSection.stateAllTheSame
112
- ? archiveSection.state[0]
113
- : archiveSection.isStatePaletted
114
- ? convertToPaletteBuffer(archiveSection.remappedState
115
- ? archiveSection.palettes.state.size
116
- : sectorPalettes.state.size, archiveSection.state)
117
- : new Uint16Array(archiveSection.section.state.slice()),
118
- mod: archiveSection.modAllTheSame
119
- ? archiveSection.mod[0]
120
- : archiveSection.isModPaletted
121
- ? convertToPaletteBuffer(archiveSection.remappedMod
122
- ? archiveSection.palettes.mod.size
123
- : sectorPalettes.mod.size, archiveSection.mod)
124
- : new Uint16Array(archiveSection.section.mod.slice()),
125
- secondary: archiveSection.secondaryAllTheSame
126
- ? archiveSection.secondary[0]
127
- : archiveSection.isSecondaryPaletted
128
- ? convertToPaletteBuffer(archiveSection.remappedSecondary
129
- ? Math.max(archiveSection.palettes.secondaryState.size, archiveSection.palettes.secondaryId.size)
130
- : Math.max(sectorPalettes.secondaryState.size, sectorPalettes.secondaryId.size), archiveSection.secondary)
131
- : new Uint16Array(archiveSection.secondary),
132
- },
277
+ ...(Object.keys(flags).length ? { flags } : {}),
278
+ ...(Object.keys(palettes).length ? { palettes } : {}),
279
+ buffers,
280
+ };
281
+ }
282
+ function RemoveDuplicates(data) {
283
+ const duplicateSectionMap = new Map();
284
+ let duplicateSections = [];
285
+ for (let i = 0; i < data.sections.length; i++) {
286
+ for (let j = 0; j < data.sections.length; j++) {
287
+ const section1 = data.sections[i];
288
+ const section2 = data.sections[j];
289
+ if (i == j)
290
+ continue;
291
+ if (typeof section1 == "string" || typeof section2 == "string")
292
+ continue;
293
+ let index = -1;
294
+ if (compareSection(section1, section2)) {
295
+ if (duplicateSectionMap.has(section2)) {
296
+ index = duplicateSectionMap.get(section2)[1];
297
+ }
298
+ else {
299
+ let found = false;
300
+ for (let k = 0; k < duplicateSections.length; k++) {
301
+ if (compareSection(section1, duplicateSections[k])) {
302
+ index = k;
303
+ found = true;
304
+ }
305
+ }
306
+ if (!found) {
307
+ duplicateSections.push(section1);
308
+ index = duplicateSections.length - 1;
309
+ }
310
+ }
311
+ duplicateSectionMap.set(section1, [i, index]);
312
+ }
313
+ }
314
+ }
315
+ const sections = {};
316
+ for (const [object, [sectionIndex, index]] of duplicateSectionMap) {
317
+ const id = uint16To4CharString(index);
318
+ if (!sections[id])
319
+ sections[id] = object;
320
+ data.sections[sectionIndex] = id;
321
+ }
322
+ data.duplicates = {
323
+ sections,
133
324
  };
134
325
  }
326
+ const lightData = new VoxelLightData();
135
327
  export default function ArchiveSector(archiveData) {
136
328
  const sector = WorldRegister.sectors.get(archiveData.location[0], archiveData.location[1], archiveData.location[2], archiveData.location[3]);
137
329
  if (!sector)
138
330
  throw new Error(`Column at location ${location} does not exist when trying to arhicve it.`);
139
- if (!sectorStructInstance)
140
- sectorStructInstance = Sector.StateStruct.instantiate();
141
- if (!sectionStructInstance)
142
- sectionStructInstance = Section.StateStruct.instantiate();
143
331
  const sectorPalettes = getColumnPalettes();
144
- sectorStructInstance.setData(sector.sectorState);
145
- const sectorState = sectorStructInstance.serialize();
146
332
  const processedSections = [];
147
333
  for (const section of sector.sections) {
148
- const length = section.ids.length;
149
- let firstId = -1;
150
- let firstLight = -1;
151
- let firstLevel = -1;
152
- let firstState = -1;
153
- let firstMod = -1;
154
- let firstSecondary = -1;
155
334
  const processedSection = getProcessedSection(section);
335
+ {
336
+ let value = section.buried[0];
337
+ processedSection.isBuriedAllTheSame = true;
338
+ for (let i = 0; i < section.buried.length; i++) {
339
+ if (value != section.buried[i]) {
340
+ processedSection.isBuriedAllTheSame = false;
341
+ break;
342
+ }
343
+ }
344
+ processedSection.buriedValue = value;
345
+ }
346
+ {
347
+ let value = section.voxelMap[0];
348
+ processedSection.isVoxelMapAllTheSame = true;
349
+ for (let i = 0; i < section.voxelMap.length; i++) {
350
+ if (value != section.voxelMap[i]) {
351
+ processedSection.isVoxelMapAllTheSame = false;
352
+ break;
353
+ }
354
+ }
355
+ processedSection.voxelMapValue = value;
356
+ }
357
+ {
358
+ let value = section.dirtyMap[0];
359
+ processedSection.isDirtyMapAllTheSame = true;
360
+ for (let i = 0; i < section.dirtyMap.length; i++) {
361
+ if (value != section.dirtyMap[i]) {
362
+ processedSection.isDirtyMapAllTheSame = false;
363
+ break;
364
+ }
365
+ }
366
+ processedSection.dirtyMapValue = value;
367
+ }
368
+ const firstId = section.ids[0];
369
+ const firstLight = section.light[0];
370
+ const firstLevel = section.level[0];
371
+ const firstState = section.state[0];
372
+ const firstMod = section.mod[0];
373
+ const firstSecondary = section.secondary[0];
374
+ const firstLightLevels = {
375
+ sun: lightData.getS(firstLight),
376
+ red: lightData.getR(firstLight),
377
+ green: lightData.getG(firstLight),
378
+ blue: lightData.getB(firstLight),
379
+ };
380
+ const length = section.ids.length;
156
381
  for (let i = 0; i < length; i++) {
157
- const stringId = VoxelPalette.ids.getStringId(section.ids[i]);
158
- VoxelStruct.setStringVoxel(stringId);
382
+ const stringId = VoxelPalettesRegister.voxels.getStringId(section.ids[i]);
159
383
  const voxelId = !sectorPalettes.ids.isRegistered(stringId)
160
384
  ? sectorPalettes.ids.register(stringId)
161
385
  : sectorPalettes.ids.getNumberId(stringId);
386
+ processedSection.ids.value = voxelId;
162
387
  if (!processedSection.palettes.ids.isRegistered(voxelId))
163
388
  processedSection.palettes.ids.register(voxelId);
164
- if (firstId == -1)
165
- firstId = voxelId;
166
- const secondaryId = VoxelStruct.instance[VoxelStructIds.canHaveSecondary] == 1 &&
167
- VoxelPalette.ids.getStringId(section.secondary[i]);
389
+ const secondaryId = VoxelTagsRegister.VoxelTags[section.ids[i]]["dve_can_have_secondary"] &&
390
+ VoxelPalettesRegister.voxels.getStringId(section.secondary[i]);
168
391
  const voxelSecondary = secondaryId
169
392
  ? !sectorPalettes.secondaryId.isRegistered(secondaryId)
170
393
  ? sectorPalettes.secondaryId.register(secondaryId)
@@ -172,20 +395,19 @@ export default function ArchiveSector(archiveData) {
172
395
  : !sectorPalettes.secondaryState.isRegistered(section.secondary[i])
173
396
  ? sectorPalettes.secondaryState.register(section.secondary[i])
174
397
  : sectorPalettes.secondaryState.getId(section.secondary[i]);
175
- secondaryId
176
- ? !processedSection.palettes.secondaryId.isRegistered(voxelSecondary) &&
177
- processedSection.palettes.secondaryId.register(voxelSecondary)
178
- : !processedSection.palettes.secondaryState.isRegistered(voxelSecondary) &&
398
+ if (VoxelTagsRegister.VoxelTags[section.ids[i]]["dve_can_have_secondary"]) {
399
+ if (!processedSection.palettes.secondaryId.isRegistered(voxelSecondary))
400
+ processedSection.palettes.secondaryId.register(voxelSecondary);
401
+ }
402
+ else {
403
+ if (!processedSection.palettes.secondaryState.isRegistered(voxelSecondary))
179
404
  processedSection.palettes.secondaryState.register(voxelSecondary);
180
- if (firstSecondary == -1)
181
- firstSecondary = section.secondary[i];
405
+ }
182
406
  const voxelLevel = !sectorPalettes.level.isRegistered(section.level[i])
183
407
  ? sectorPalettes.level.register(section.level[i])
184
408
  : sectorPalettes.level.getId(section.level[i]);
185
409
  if (!processedSection.palettes.level.isRegistered(section.level[i]))
186
410
  processedSection.palettes.level.register(section.level[i]);
187
- if (firstLevel == -1)
188
- firstLevel = voxelLevel;
189
411
  let voxelState = -1;
190
412
  if (!sectorPalettes.state.isRegistered(section.state[i])) {
191
413
  voxelState = sectorPalettes.state.register(section.state[i]);
@@ -198,12 +420,10 @@ export default function ArchiveSector(archiveData) {
198
420
  }
199
421
  if (!processedSection.palettes.state.isRegistered(voxelState))
200
422
  processedSection.palettes.state.register(voxelState);
201
- if (firstState == -1)
202
- firstState = voxelState;
203
423
  let voxelMod = -1;
204
424
  if (!sectorPalettes.mod.isRegistered(section.mod[i])) {
205
425
  voxelMod = sectorPalettes.mod.register(section.mod[i]);
206
- sectorPalettes.stateIdMap[voxelMod] = secondaryId
426
+ sectorPalettes.modIdMap[voxelMod] = secondaryId
207
427
  ? section.secondary[i]
208
428
  : section.ids[i];
209
429
  }
@@ -212,99 +432,147 @@ export default function ArchiveSector(archiveData) {
212
432
  }
213
433
  if (!processedSection.palettes.mod.isRegistered(voxelMod))
214
434
  processedSection.palettes.mod.register(voxelMod);
215
- if (firstMod == -1)
216
- firstMod = voxelMod;
217
- const voxelLight = !sectorPalettes.light.isRegistered(section.light[i])
218
- ? sectorPalettes.light.register(section.light[i])
219
- : sectorPalettes.light.getId(section.light[i]);
220
- if (!processedSection.palettes.light.isRegistered(section.light[i]))
221
- processedSection.palettes.light.register(section.light[i]);
222
- if (firstLight == -1)
223
- firstLight = voxelLight;
224
- if (voxelId != firstId)
225
- processedSection.idsAllTheSame = false;
226
- if (voxelLevel != firstLevel)
227
- processedSection.levelAllTheSame = false;
228
- if (voxelState != firstState)
229
- processedSection.stateAllTheSame = false;
230
- if (voxelMod != firstMod)
231
- processedSection.modAllTheSame = false;
232
- if (voxelLight != firstLight)
233
- processedSection.lightAllTheSame = false;
234
- if (voxelSecondary != firstSecondary)
235
- processedSection.secondaryAllTheSame = false;
236
- processedSection.ids[i] = voxelId;
237
- processedSection.level[i] = voxelLevel;
238
- processedSection.state[i] = voxelState;
239
- processedSection.mod[i] = voxelMod;
240
- processedSection.secondary[i] = voxelSecondary;
241
- processedSection.light[i] = voxelLight;
435
+ for (let l = 0; l < lightSegments.length; l++) {
436
+ const segment = lightSegments[l];
437
+ const light = lightSemgnetGet[segment](section.light[i]);
438
+ if (light != firstLightLevels[segment])
439
+ processedSection.light[segment].allTheSame = false;
440
+ processedSection.light[segment].value = light;
441
+ const voxelLight = !sectorPalettes.light[segment].isRegistered(light)
442
+ ? sectorPalettes.light[segment].register(light)
443
+ : sectorPalettes.light[segment].getId(light);
444
+ if (!processedSection.palettes.light[segment].isRegistered(light))
445
+ processedSection.palettes.light[segment].register(light);
446
+ processedSection.light[segment].buffer[i] = voxelLight;
447
+ }
448
+ if (section.ids[i] != firstId)
449
+ processedSection.ids.allTheSame = false;
450
+ if (section.level[i] != firstLevel)
451
+ processedSection.level.allTheSame = false;
452
+ if (section.state[i] != firstState)
453
+ processedSection.state.allTheSame = false;
454
+ if (section.mod[i] != firstMod)
455
+ processedSection.mod.allTheSame = false;
456
+ if (section.secondary[i] != firstSecondary)
457
+ processedSection.secondary.allTheSame = false;
458
+ processedSection.ids.buffer[i] = voxelId;
459
+ processedSection.level.buffer[i] = voxelLevel;
460
+ processedSection.state.buffer[i] = voxelState;
461
+ processedSection.mod.buffer[i] = voxelMod;
462
+ processedSection.secondary.buffer[i] = voxelSecondary;
242
463
  }
243
464
  processedSections.push(processedSection);
244
465
  }
245
- for (const section of processedSections) {
246
- const reMapIds = section.palettes.ids.size < sectorPalettes.ids.size &&
247
- section.palettes.ids.size <= 255 &&
248
- !section.idsAllTheSame;
249
- const reMapLevel = section.palettes.level.size < sectorPalettes.level.size &&
250
- section.palettes.level.size <= 255 &&
251
- !section.levelAllTheSame;
252
- const reMapState = section.palettes.state.size < sectorPalettes.state.size &&
253
- section.palettes.state.size <= 255 &&
254
- !section.stateAllTheSame;
255
- const reMapMod = section.palettes.mod.size < sectorPalettes.mod.size &&
256
- section.palettes.mod.size <= 255 &&
257
- !section.modAllTheSame;
258
- const reMapLight = section.palettes.light.size < sectorPalettes.light.size &&
259
- section.palettes.light.size <= 255 &&
260
- !section.lightAllTheSame;
261
- const reMapSecondary = Math.max(section.palettes.secondaryId.size, section.palettes.secondaryState.size) <
262
- Math.max(sectorPalettes.secondaryState.size, sectorPalettes.secondaryId.size) &&
263
- Math.max(section.palettes.secondaryId.size, section.palettes.secondaryState.size) <= 255 &&
264
- !section.secondaryAllTheSame;
265
- section.isLightPaletted =
266
- sectorPalettes.light.size < 65_535 && section.palettes.light.size < 255;
267
- section.isLevelPaletted =
268
- sectorPalettes.level.size < 255 && section.palettes.level.size < 255;
269
- section.isStatePaletted =
270
- sectorPalettes.state.size < 65_535 && section.palettes.state.size < 255;
271
- section.isModPaletted =
272
- sectorPalettes.mod.size < 65_535 && section.palettes.mod.size < 255;
273
- section.isSecondaryPaletted =
274
- sectorPalettes.secondaryState.size < 65_535 &&
275
- section.palettes.secondaryState.size < 255 &&
276
- section.palettes.secondaryId.size < 255;
277
- section.remappedIds = reMapIds;
278
- section.remappedLight = reMapLight && section.isLightPaletted;
279
- section.remappedState = reMapState && section.isStatePaletted;
280
- section.remappedMod = reMapMod && section.isModPaletted;
281
- section.remappedSecondary = reMapSecondary && section.isSecondaryPaletted;
282
- if (!reMapIds && !reMapLight && !reMapSecondary && !reMapState)
466
+ let neededPalettes = {
467
+ level: false,
468
+ light: {
469
+ sun: false,
470
+ red: false,
471
+ green: false,
472
+ blue: false,
473
+ },
474
+ };
475
+ for (const archivedSection of processedSections) {
476
+ //ids
477
+ archivedSection.ids.isPaletted =
478
+ sectorPalettes.ids.size <= BinaryBuffer.BytePaletteMax ||
479
+ archivedSection.palettes.ids.size <= BinaryBuffer.BytePaletteMax;
480
+ archivedSection.ids.remapped =
481
+ sectorPalettes.ids.size > BinaryBuffer.BytePaletteMax &&
482
+ archivedSection.palettes.ids.size <= BinaryBuffer.BytePaletteMax &&
483
+ !archivedSection.ids.allTheSame;
484
+ //level
485
+ archivedSection.level.isPaletted =
486
+ sectorPalettes.level.size <= BinaryBuffer.NibblePaletteMax &&
487
+ archivedSection.palettes.level.size <= BinaryBuffer.NibblePaletteMax;
488
+ archivedSection.level.remapped =
489
+ sectorPalettes.level.size > BinaryBuffer.NibblePaletteMax &&
490
+ archivedSection.palettes.level.size <= BinaryBuffer.NibblePaletteMax &&
491
+ !archivedSection.level.allTheSame;
492
+ if (archivedSection.level.isPaletted && !archivedSection.level.remapped) {
493
+ neededPalettes.level = true;
494
+ }
495
+ //state
496
+ archivedSection.state.isPaletted =
497
+ sectorPalettes.state.size <= BinaryBuffer.BytePaletteMax ||
498
+ archivedSection.palettes.state.size <= BinaryBuffer.BytePaletteMax;
499
+ archivedSection.state.remapped =
500
+ sectorPalettes.state.size > BinaryBuffer.BytePaletteMax &&
501
+ archivedSection.palettes.state.size <= BinaryBuffer.BytePaletteMax &&
502
+ !archivedSection.state.allTheSame;
503
+ //mod
504
+ archivedSection.mod.isPaletted =
505
+ sectorPalettes.mod.size <= BinaryBuffer.BytePaletteMax ||
506
+ archivedSection.palettes.mod.size <= BinaryBuffer.BytePaletteMax;
507
+ archivedSection.mod.remapped =
508
+ sectorPalettes.mod.size > BinaryBuffer.BytePaletteMax &&
509
+ archivedSection.palettes.mod.size <= BinaryBuffer.BytePaletteMax &&
510
+ !archivedSection.mod.allTheSame;
511
+ for (const semgnet of lightSegments) {
512
+ archivedSection.light[semgnet].isPaletted =
513
+ sectorPalettes.light[semgnet].size <=
514
+ BinaryBuffer.HalfNibblePaletteMax ||
515
+ archivedSection.palettes.light[semgnet].size <=
516
+ BinaryBuffer.HalfNibblePaletteMax;
517
+ archivedSection.light[semgnet].remapped =
518
+ sectorPalettes.light[semgnet].size >
519
+ BinaryBuffer.HalfNibblePaletteMax &&
520
+ archivedSection.palettes.light[semgnet].size <=
521
+ BinaryBuffer.HalfNibblePaletteMax &&
522
+ !archivedSection.light[semgnet].allTheSame;
523
+ if (archivedSection.light[semgnet].isPaletted &&
524
+ !archivedSection.light[semgnet].remapped) {
525
+ neededPalettes.light[semgnet] = true;
526
+ }
527
+ }
528
+ //secondary
529
+ archivedSection.secondary.isPaletted =
530
+ (sectorPalettes.secondaryState.size <= BinaryBuffer.BytePaletteMax &&
531
+ sectorPalettes.secondaryId.size <= BinaryBuffer.BytePaletteMax) ||
532
+ (archivedSection.palettes.secondaryState.size <=
533
+ BinaryBuffer.BytePaletteMax &&
534
+ archivedSection.palettes.secondaryId.size <=
535
+ BinaryBuffer.BytePaletteMax);
536
+ archivedSection.secondary.remapped =
537
+ Math.max(sectorPalettes.secondaryState.size, sectorPalettes.secondaryId.size) > BinaryBuffer.BytePaletteMax &&
538
+ Math.max(archivedSection.palettes.secondaryId.size, archivedSection.palettes.secondaryState.size) <= BinaryBuffer.BytePaletteMax &&
539
+ !archivedSection.secondary.allTheSame;
540
+ if (!archivedSection.ids.remapped &&
541
+ !archivedSection.light.sun.remapped &&
542
+ !archivedSection.light.red.remapped &&
543
+ !archivedSection.light.green.remapped &&
544
+ !archivedSection.light.blue.remapped &&
545
+ !archivedSection.secondary.remapped &&
546
+ !archivedSection.mod.remapped &&
547
+ !archivedSection.level.remapped)
283
548
  continue;
284
- const length = section.section.ids.length;
549
+ const length = archivedSection.original.ids.length;
285
550
  for (let i = 0; i < length; i++) {
286
- VoxelStruct.setVoxel(section.ids[i]);
287
- if (reMapIds)
288
- section.ids[i] = section.palettes.ids.getId(section.ids[i]);
289
- if (reMapLight)
290
- section.light[i] = section.palettes.light.getId(section.section.light[i]);
291
- if (reMapLevel)
292
- section.level[i] = section.palettes.level.getId(section.section.level[i]);
293
- if (reMapState)
294
- section.state[i] = section.palettes.state.getId(sectorPalettes.state.getId(section.section.state[i]));
295
- if (reMapMod)
296
- section.mod[i] = section.palettes.mod.getId(sectorPalettes.mod.getId(section.section.mod[i]));
297
- if (reMapSecondary)
298
- section.secondary[i] =
299
- VoxelStruct.instance[VoxelStructIds.canHaveSecondary] == 1
300
- ? section.palettes.secondaryId.getId(section.secondary[i])
301
- : section.palettes.secondaryState.getId(section.secondary[i]);
551
+ if (archivedSection.ids.remapped)
552
+ archivedSection.ids.buffer[i] = archivedSection.palettes.ids.getId(archivedSection.ids.buffer[i]);
553
+ for (let l = 0; l < lightSegments.length; l++) {
554
+ const segment = lightSegments[l];
555
+ if (archivedSection.light[segment].remapped) {
556
+ archivedSection.light[segment].buffer[i] =
557
+ archivedSection.palettes.light[segment].getId(lightSemgnetGet[segment](archivedSection.original.light[i]));
558
+ }
559
+ }
560
+ if (archivedSection.level.remapped)
561
+ archivedSection.level.buffer[i] = archivedSection.palettes.level.getId(archivedSection.original.level[i]);
562
+ if (archivedSection.state.remapped)
563
+ archivedSection.state.buffer[i] = archivedSection.palettes.state.getId(sectorPalettes.state.getId(archivedSection.state.buffer[i]));
564
+ if (archivedSection.mod.remapped)
565
+ archivedSection.mod.buffer[i] = archivedSection.palettes.mod.getId(sectorPalettes.mod.getId(archivedSection.mod.buffer[i]));
566
+ if (archivedSection.secondary.remapped)
567
+ archivedSection.secondary.buffer[i] = VoxelTagsRegister.VoxelTags[archivedSection.original.ids[i]]["dve_can_have_secondary"]
568
+ ? archivedSection.palettes.secondaryId.getId(archivedSection.secondary.buffer[i])
569
+ : archivedSection.palettes.secondaryState.getId(archivedSection.secondary.buffer[i]);
302
570
  }
303
571
  }
304
572
  const stateMap = {};
305
573
  for (let i = 0; i < sectorPalettes.state._palette.length; i++) {
306
574
  const state = sectorPalettes.state._palette[i];
307
- const voxelId = VoxelPalette.ids.getStringId(sectorPalettes.stateIdMap[i]);
575
+ const voxelId = VoxelPalettesRegister.voxels.getStringId(sectorPalettes.stateIdMap[i]);
308
576
  if (!SchemaRegister.hasVoxelSchema(voxelId))
309
577
  continue;
310
578
  const schema = SchemaRegister.getVoxelSchemas(voxelId);
@@ -313,7 +581,7 @@ export default function ArchiveSector(archiveData) {
313
581
  const modMap = {};
314
582
  for (let i = 0; i < sectorPalettes.mod._palette.length; i++) {
315
583
  const mod = sectorPalettes.mod._palette[i];
316
- const voxelId = VoxelPalette.ids.getStringId(sectorPalettes.modIdMap[i]);
584
+ const voxelId = VoxelPalettesRegister.voxels.getStringId(sectorPalettes.modIdMap[i]);
317
585
  if (!SchemaRegister.hasVoxelSchema(voxelId))
318
586
  continue;
319
587
  const schema = SchemaRegister.getVoxelSchemas(voxelId);
@@ -329,26 +597,29 @@ export default function ArchiveSector(archiveData) {
329
597
  modMap,
330
598
  state: new Uint16Array(sectorPalettes.state._palette),
331
599
  mod: new Uint16Array(sectorPalettes.mod._palette),
600
+ light: {},
601
+ secondaryId: sectorPalettes.secondaryId._palette,
602
+ secondaryState: new Uint16Array(sectorPalettes.secondaryState._palette),
332
603
  };
333
- if (sectorPalettes.light.size < 255)
334
- palettes.light = new Uint16Array(sectorPalettes.light._palette);
335
- if (sectorPalettes.level.size < 255)
604
+ if (neededPalettes.level) {
336
605
  palettes.level = new Uint8Array(sectorPalettes.level._palette);
337
- if (sectorPalettes.light.size < 255)
338
- palettes.light = new Uint16Array(sectorPalettes.light._palette);
339
- if (sectorPalettes.secondaryId.size > 0)
340
- palettes.secondaryId = sectorPalettes.secondaryId._palette;
341
- if (sectorPalettes.secondaryState.size < 255)
342
- palettes.secondaryState = new Uint16Array(sectorPalettes.secondaryState._palette);
343
- return {
606
+ }
607
+ for (const segment of lightSegments) {
608
+ if (neededPalettes.light[segment]) {
609
+ palettes.light[segment] = new Uint8Array(sectorPalettes.light[segment]._palette);
610
+ }
611
+ }
612
+ const archivedSector = {
344
613
  version: "",
614
+ vloxVersion: EngineSettings.version,
345
615
  location: [...archiveData.location],
346
- sectorState,
616
+ flags: sector.storeFlags(),
617
+ timestamps: sector.storeTimestamps(),
347
618
  buffers: {},
348
- keys: {
349
- sectionState: [...sectionStructInstance.getKeys()],
350
- },
351
619
  palettes,
620
+ duplicates: {},
352
621
  sections,
353
622
  };
623
+ RemoveDuplicates(archivedSector);
624
+ return archivedSector;
354
625
  }