@woosh/meep-engine 2.164.0 → 2.165.1
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/README.md +137 -108
- package/build/bundle-worker-image-decoder.js +1 -1
- package/build/bundle-worker-terrain.js +1 -1
- package/package.json +1 -1
- package/samples/generation/SampleGenerator0.js +3 -3
- package/samples/generation/filters/SampleGroundMoistureFilter.js +63 -56
- package/samples/generation/filters/SampleNoise20_0.js +6 -1
- package/samples/generation/themes/SampleTheme0.js +47 -47
- package/src/core/binary/BitImage2.d.ts +91 -0
- package/src/core/binary/BitImage2.d.ts.map +1 -0
- package/src/core/binary/BitImage2.js +242 -0
- package/src/core/color/YCoCg/rgb_to_ycocg.d.ts +17 -0
- package/src/core/color/YCoCg/rgb_to_ycocg.d.ts.map +1 -0
- package/src/core/color/YCoCg/rgb_to_ycocg.js +20 -0
- package/src/core/color/YCoCg/ycocg_to_rgb.d.ts +14 -0
- package/src/core/color/YCoCg/ycocg_to_rgb.d.ts.map +1 -0
- package/src/core/color/YCoCg/ycocg_to_rgb.js +17 -0
- package/src/core/geom/2d/oriented-box/min_area_rect_2d.d.ts +22 -0
- package/src/core/geom/2d/oriented-box/min_area_rect_2d.d.ts.map +1 -0
- package/src/core/geom/2d/oriented-box/min_area_rect_2d.js +69 -0
- package/src/core/geom/2d/packing/skyline.d.ts +116 -0
- package/src/core/geom/2d/packing/skyline.d.ts.map +1 -0
- package/src/core/geom/2d/packing/skyline.js +258 -0
- package/src/core/geom/2d/triangle/tri2_rasterize_conservative.d.ts +18 -0
- package/src/core/geom/2d/triangle/tri2_rasterize_conservative.d.ts.map +1 -0
- package/src/core/geom/2d/triangle/tri2_rasterize_conservative.js +86 -0
- package/src/core/geom/3d/atlas/ATLAS_PORT_PLAN.md +486 -0
- package/src/core/geom/3d/atlas/BFF_PLAN.md +174 -0
- package/src/core/geom/3d/atlas/Chart.d.ts +58 -0
- package/src/core/geom/3d/atlas/Chart.d.ts.map +1 -0
- package/src/core/geom/3d/atlas/Chart.js +77 -0
- package/src/core/geom/3d/atlas/REVIEW_02.md +392 -0
- package/src/core/geom/3d/atlas/atlas_bench_lib.d.ts +73 -0
- package/src/core/geom/3d/atlas/atlas_bench_lib.d.ts.map +1 -0
- package/src/core/geom/3d/atlas/atlas_bench_lib.js +315 -0
- package/src/core/geom/3d/atlas/atlas_chart_type.d.ts +17 -0
- package/src/core/geom/3d/atlas/atlas_chart_type.d.ts.map +1 -0
- package/src/core/geom/3d/atlas/atlas_chart_type.js +16 -0
- package/src/core/geom/3d/atlas/atlas_compute_charts.d.ts +25 -0
- package/src/core/geom/3d/atlas/atlas_compute_charts.d.ts.map +1 -0
- package/src/core/geom/3d/atlas/atlas_compute_charts.js +188 -0
- package/src/core/geom/3d/atlas/atlas_extract_chart.d.ts +17 -0
- package/src/core/geom/3d/atlas/atlas_extract_chart.d.ts.map +1 -0
- package/src/core/geom/3d/atlas/atlas_extract_chart.js +107 -0
- package/src/core/geom/3d/atlas/atlas_generate.d.ts +39 -0
- package/src/core/geom/3d/atlas/atlas_generate.d.ts.map +1 -0
- package/src/core/geom/3d/atlas/atlas_generate.js +43 -0
- package/src/core/geom/3d/atlas/atlas_test_fixtures.d.ts +84 -0
- package/src/core/geom/3d/atlas/atlas_test_fixtures.d.ts.map +1 -0
- package/src/core/geom/3d/atlas/atlas_test_fixtures.js +266 -0
- package/src/core/geom/3d/atlas/atlas_write_chart_uvs.d.ts +25 -0
- package/src/core/geom/3d/atlas/atlas_write_chart_uvs.d.ts.map +1 -0
- package/src/core/geom/3d/atlas/atlas_write_chart_uvs.js +36 -0
- package/src/core/geom/3d/atlas/data/atlas_build_edge_dihedrals.d.ts +22 -0
- package/src/core/geom/3d/atlas/data/atlas_build_edge_dihedrals.d.ts.map +1 -0
- package/src/core/geom/3d/atlas/data/atlas_build_edge_dihedrals.js +62 -0
- package/src/core/geom/3d/atlas/data/atlas_build_edge_lengths.d.ts +9 -0
- package/src/core/geom/3d/atlas/data/atlas_build_edge_lengths.d.ts.map +1 -0
- package/src/core/geom/3d/atlas/data/atlas_build_edge_lengths.js +33 -0
- package/src/core/geom/3d/atlas/data/atlas_build_face_areas.d.ts +9 -0
- package/src/core/geom/3d/atlas/data/atlas_build_face_areas.d.ts.map +1 -0
- package/src/core/geom/3d/atlas/data/atlas_build_face_areas.js +50 -0
- package/src/core/geom/3d/atlas/io/atlas_mesh_weld_colocals.d.ts +27 -0
- package/src/core/geom/3d/atlas/io/atlas_mesh_weld_colocals.d.ts.map +1 -0
- package/src/core/geom/3d/atlas/io/atlas_mesh_weld_colocals.js +39 -0
- package/src/core/geom/3d/atlas/io/bt_loop_uv.d.ts +22 -0
- package/src/core/geom/3d/atlas/io/bt_loop_uv.d.ts.map +1 -0
- package/src/core/geom/3d/atlas/io/bt_loop_uv.js +57 -0
- package/src/core/geom/3d/atlas/pack/ChartPlacement.d.ts +36 -0
- package/src/core/geom/3d/atlas/pack/ChartPlacement.d.ts.map +1 -0
- package/src/core/geom/3d/atlas/pack/ChartPlacement.js +46 -0
- package/src/core/geom/3d/atlas/pack/atlas_pack_charts.d.ts +62 -0
- package/src/core/geom/3d/atlas/pack/atlas_pack_charts.d.ts.map +1 -0
- package/src/core/geom/3d/atlas/pack/atlas_pack_charts.js +551 -0
- package/src/core/geom/3d/atlas/param/atlas_chart_param_validity.d.ts +22 -0
- package/src/core/geom/3d/atlas/param/atlas_chart_param_validity.d.ts.map +1 -0
- package/src/core/geom/3d/atlas/param/atlas_chart_param_validity.js +73 -0
- package/src/core/geom/3d/atlas/param/atlas_chart_parameterize_bff.d.ts +37 -0
- package/src/core/geom/3d/atlas/param/atlas_chart_parameterize_bff.d.ts.map +1 -0
- package/src/core/geom/3d/atlas/param/atlas_chart_parameterize_bff.js +270 -0
- package/src/core/geom/3d/atlas/param/atlas_chart_parameterize_lscm.d.ts +23 -0
- package/src/core/geom/3d/atlas/param/atlas_chart_parameterize_lscm.d.ts.map +1 -0
- package/src/core/geom/3d/atlas/param/atlas_chart_parameterize_lscm.js +224 -0
- package/src/core/geom/3d/atlas/param/atlas_chart_parameterize_ortho.d.ts +14 -0
- package/src/core/geom/3d/atlas/param/atlas_chart_parameterize_ortho.d.ts.map +1 -0
- package/src/core/geom/3d/atlas/param/atlas_chart_parameterize_ortho.js +38 -0
- package/src/core/geom/3d/atlas/param/atlas_chart_stretch_metric.d.ts +22 -0
- package/src/core/geom/3d/atlas/param/atlas_chart_stretch_metric.d.ts.map +1 -0
- package/src/core/geom/3d/atlas/param/atlas_chart_stretch_metric.js +86 -0
- package/src/core/geom/3d/atlas/param/atlas_piecewise_resegment.d.ts +20 -0
- package/src/core/geom/3d/atlas/param/atlas_piecewise_resegment.d.ts.map +1 -0
- package/src/core/geom/3d/atlas/param/atlas_piecewise_resegment.js +183 -0
- package/src/core/geom/3d/atlas/param/fit_plane_basis.d.ts +27 -0
- package/src/core/geom/3d/atlas/param/fit_plane_basis.d.ts.map +1 -0
- package/src/core/geom/3d/atlas/param/fit_plane_basis.js +66 -0
- package/src/core/geom/3d/atlas/segment/RegionGraph.d.ts +31 -0
- package/src/core/geom/3d/atlas/segment/RegionGraph.d.ts.map +1 -0
- package/src/core/geom/3d/atlas/segment/RegionGraph.js +40 -0
- package/src/core/geom/3d/atlas/segment/atlas_build_region_graph.d.ts +23 -0
- package/src/core/geom/3d/atlas/segment/atlas_build_region_graph.d.ts.map +1 -0
- package/src/core/geom/3d/atlas/segment/atlas_build_region_graph.js +136 -0
- package/src/core/geom/3d/atlas/segment/atlas_compute_planar_regions.d.ts +24 -0
- package/src/core/geom/3d/atlas/segment/atlas_compute_planar_regions.d.ts.map +1 -0
- package/src/core/geom/3d/atlas/segment/atlas_compute_planar_regions.js +77 -0
- package/src/core/geom/3d/atlas/segment/atlas_merge_charts.d.ts +27 -0
- package/src/core/geom/3d/atlas/segment/atlas_merge_charts.d.ts.map +1 -0
- package/src/core/geom/3d/atlas/segment/atlas_merge_charts.js +113 -0
- package/src/core/geom/3d/atlas/segment/atlas_segment_charts.d.ts +44 -0
- package/src/core/geom/3d/atlas/segment/atlas_segment_charts.d.ts.map +1 -0
- package/src/core/geom/3d/atlas/segment/atlas_segment_charts.js +275 -0
- package/src/core/geom/3d/atlas/segment/atlas_segment_charts_atomic.d.ts +22 -0
- package/src/core/geom/3d/atlas/segment/atlas_segment_charts_atomic.d.ts.map +1 -0
- package/src/core/geom/3d/atlas/segment/atlas_segment_charts_atomic.js +199 -0
- package/src/core/geom/3d/line/line3_compute_point_segment_point_distance_unfolded.d.ts +32 -0
- package/src/core/geom/3d/line/line3_compute_point_segment_point_distance_unfolded.d.ts.map +1 -0
- package/src/core/geom/3d/line/line3_compute_point_segment_point_distance_unfolded.js +64 -0
- package/src/core/geom/3d/mat4/m4_from_rotation_translation_scale.d.ts +20 -0
- package/src/core/geom/3d/mat4/m4_from_rotation_translation_scale.d.ts.map +1 -0
- package/src/core/geom/3d/mat4/m4_from_rotation_translation_scale.js +66 -0
- package/src/core/geom/3d/sphere/harmonics/sh3_dering_optimize_positive.d.ts.map +1 -1
- package/src/core/geom/3d/sphere/harmonics/sh3_dering_optimize_positive.js +13 -11
- package/src/core/geom/3d/sphere/sphere_compute_bounding_of_2_spheres.d.ts.map +1 -1
- package/src/core/geom/3d/sphere/sphere_compute_bounding_of_2_spheres.js +4 -3
- package/src/core/geom/3d/topology/simplify/decimate_edge_collapse_snap.d.ts.map +1 -1
- package/src/core/geom/3d/topology/simplify/decimate_edge_collapse_snap.js +4 -3
- package/src/core/geom/3d/topology/simplify/quadratic/Quadric3.d.ts.map +1 -1
- package/src/core/geom/3d/topology/simplify/quadratic/Quadric3.js +4 -3
- package/src/core/geom/3d/topology/simplify/quadratic/apply_border_penalty_to_vertex_quadrics.d.ts.map +1 -1
- package/src/core/geom/3d/topology/simplify/quadratic/apply_border_penalty_to_vertex_quadrics.js +10 -6
- package/src/core/geom/3d/topology/struct/TopoMesh.js +2 -2
- package/src/core/geom/3d/topology/struct/TopoTriangle.d.ts +0 -2
- package/src/core/geom/3d/topology/struct/TopoTriangle.d.ts.map +1 -1
- package/src/core/geom/3d/topology/struct/TopoTriangle.js +2 -2
- package/src/core/geom/3d/topology/struct/binary/query/bt_mesh_face_find_path_polyanya.d.ts.map +1 -1
- package/src/core/geom/3d/topology/struct/binary/query/bt_mesh_face_find_path_polyanya.js +8 -27
- package/src/core/geom/vec3/v3_cotangent.d.ts +20 -0
- package/src/core/geom/vec3/v3_cotangent.d.ts.map +1 -0
- package/src/core/geom/vec3/v3_cotangent.js +29 -0
- package/src/core/geom/vec3/v3_matrix3_multiply.d.ts +19 -0
- package/src/core/geom/vec3/v3_matrix3_multiply.d.ts.map +1 -0
- package/src/core/geom/vec3/v3_matrix3_multiply.js +30 -0
- package/src/core/geom/vec3/v3_multiply.d.ts +16 -0
- package/src/core/geom/vec3/v3_multiply.d.ts.map +1 -0
- package/src/core/geom/vec3/v3_multiply.js +19 -0
- package/src/core/math/linalg/cg/cg_solve.d.ts +24 -0
- package/src/core/math/linalg/cg/cg_solve.d.ts.map +1 -0
- package/src/core/math/linalg/cg/cg_solve.js +106 -0
- package/src/core/math/linalg/cg/cg_solve_normal_equations.d.ts +21 -0
- package/src/core/math/linalg/cg/cg_solve_normal_equations.d.ts.map +1 -0
- package/src/core/math/linalg/cg/cg_solve_normal_equations.js +59 -0
- package/src/core/math/linalg/eigen/matrix_symmetric_3x3_eigen.d.ts +19 -0
- package/src/core/math/linalg/eigen/matrix_symmetric_3x3_eigen.d.ts.map +1 -0
- package/src/core/math/linalg/eigen/matrix_symmetric_3x3_eigen.js +117 -0
- package/src/core/math/linalg/sparse/SparseMatrixCSR.d.ts +50 -0
- package/src/core/math/linalg/sparse/SparseMatrixCSR.d.ts.map +1 -0
- package/src/core/math/linalg/sparse/SparseMatrixCSR.js +88 -0
- package/src/core/math/linalg/sparse/spm_matvec.d.ts +9 -0
- package/src/core/math/linalg/sparse/spm_matvec.d.ts.map +1 -0
- package/src/core/math/linalg/sparse/spm_matvec.js +22 -0
- package/src/core/math/linalg/sparse/spm_matvec_transpose.d.ts +12 -0
- package/src/core/math/linalg/sparse/spm_matvec_transpose.d.ts.map +1 -0
- package/src/core/math/linalg/sparse/spm_matvec_transpose.js +29 -0
- package/src/core/math/physics/mie/MIE_PARTICLES_STANDARD_PRECOMPUTED.d.ts +39 -0
- package/src/core/math/physics/mie/MIE_PARTICLES_STANDARD_PRECOMPUTED.js +22 -1
- package/src/core/math/physics/mie/compute_mie_particle_properties_rgb.d.ts.map +1 -1
- package/src/core/math/physics/mie/compute_mie_particle_properties_rgb.js +32 -9
- package/src/core/math/physics/mie/compute_mie_phase.d.ts +2 -3
- package/src/core/math/physics/mie/compute_mie_phase.d.ts.map +1 -1
- package/src/core/math/physics/mie/compute_mie_phase.js +1 -3
- package/src/core/math/physics/mie/lorenz_mie_coefs.d.ts +0 -1
- package/src/core/math/physics/mie/lorenz_mie_coefs.d.ts.map +1 -1
- package/src/core/math/physics/mie/lorenz_mie_coefs.js +0 -7
- package/src/engine/REVIEW_2026_07_03.md +211 -0
- package/src/engine/animation/curve/actionProcessorOperations/curveActions.d.ts.map +1 -1
- package/src/engine/animation/curve/actionProcessorOperations/curveActions.js +3 -2
- package/src/engine/animation/curve/compression/sample_animation_curve_to_float_array.js +1 -1
- package/src/engine/animation/keyed2/AnimationTrackPlayback.d.ts.map +1 -1
- package/src/engine/animation/keyed2/AnimationTrackPlayback.js +3 -1
- package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterNone.js +2 -2
- package/src/engine/asset/preloader/AssetPreloader.d.ts.map +1 -1
- package/src/engine/asset/preloader/AssetPreloader.js +6 -0
- package/src/engine/control/first-person/sensors/FirstPersonSensorsSystem.d.ts.map +1 -1
- package/src/engine/control/first-person/sensors/FirstPersonSensorsSystem.js +5 -2
- package/src/engine/ecs/Entity.js +1 -1
- package/src/engine/ecs/EntityComponentDataset.d.ts.map +1 -1
- package/src/engine/ecs/EntityComponentDataset.js +1 -0
- package/src/engine/ecs/EntityManager.js +1 -1
- package/src/engine/ecs/EntityObserver.js +1 -1
- package/src/engine/ecs/animation/AnimationClip.js +1 -1
- package/src/engine/ecs/attachment/AttachmentSystem.js +2 -2
- package/src/engine/ecs/attachment/TransformAttachmentBinding.d.ts.map +1 -1
- package/src/engine/ecs/attachment/TransformAttachmentBinding.js +14 -3
- package/src/engine/ecs/fow/FogOfWar.js +2 -2
- package/src/engine/ecs/fow/shader/screenSpaceFogOfWarShader.d.ts.map +1 -1
- package/src/engine/ecs/fow/shader/screenSpaceFogOfWarShader.js +8 -0
- package/src/engine/ecs/gui/hud/HeadsUpDisplaySystem.js +3 -3
- package/src/engine/ecs/gui/position/ViewportPosition.d.ts +3 -1
- package/src/engine/ecs/gui/position/ViewportPosition.d.ts.map +1 -1
- package/src/engine/ecs/gui/position/ViewportPosition.js +4 -1
- package/src/engine/ecs/storage/binary/BinarySerializationRegistry.d.ts +10 -0
- package/src/engine/ecs/storage/binary/BinarySerializationRegistry.d.ts.map +1 -1
- package/src/engine/ecs/storage/binary/BinarySerializationRegistry.js +43 -0
- package/src/engine/ecs/storage/binary/object-v2/BinaryObjectDeSerializer.d.ts +93 -0
- package/src/engine/ecs/storage/binary/object-v2/BinaryObjectDeSerializer.d.ts.map +1 -0
- package/src/engine/ecs/storage/binary/object-v2/BinaryObjectDeSerializer.js +315 -0
- package/src/engine/ecs/storage/binary/object-v2/BinaryObjectSerializer.d.ts +48 -0
- package/src/engine/ecs/storage/binary/object-v2/BinaryObjectSerializer.d.ts.map +1 -0
- package/src/engine/ecs/storage/binary/object-v2/BinaryObjectSerializer.js +331 -0
- package/src/engine/ecs/storage/binary/object-v2/DESIGN.md +199 -0
- package/src/engine/ecs/storage/binary/object-v2/ObjectBinaryFormat.d.ts +53 -0
- package/src/engine/ecs/storage/binary/object-v2/ObjectBinaryFormat.d.ts.map +1 -0
- package/src/engine/ecs/storage/binary/object-v2/ObjectBinaryFormat.js +57 -0
- package/src/engine/ecs/storage/binary/object-v2/ObjectSerializationAdapter.d.ts +53 -0
- package/src/engine/ecs/storage/binary/object-v2/ObjectSerializationAdapter.d.ts.map +1 -0
- package/src/engine/ecs/storage/binary/object-v2/ObjectSerializationAdapter.js +56 -0
- package/src/engine/ecs/storage/binary/object-v2/README.md +110 -0
- package/src/engine/ecs/storage/binary/object-v2/objectStringCodec.d.ts +13 -0
- package/src/engine/ecs/storage/binary/object-v2/objectStringCodec.d.ts.map +1 -0
- package/src/engine/ecs/storage/binary/object-v2/objectStringCodec.js +48 -0
- package/src/engine/ecs/storage/binary/object-v2/serializerTestHarness.d.ts +29 -0
- package/src/engine/ecs/storage/binary/object-v2/serializerTestHarness.d.ts.map +1 -0
- package/src/engine/ecs/storage/binary/object-v2/serializerTestHarness.js +44 -0
- package/src/engine/ecs/terrain/ecs/Terrain.d.ts.map +1 -1
- package/src/engine/ecs/terrain/ecs/Terrain.js +4 -3
- package/src/engine/ecs/terrain/tiles/TerrainTile.js +2 -2
- package/src/engine/ecs/terrain/tiles/TerrainTileManager.d.ts.map +1 -1
- package/src/engine/ecs/terrain/tiles/TerrainTileManager.js +9 -8
- package/src/engine/graphics/GraphicsEngine.d.ts.map +1 -1
- package/src/engine/graphics/GraphicsEngine.js +2 -1
- package/src/engine/graphics/camera/makeScreenScissorFrustum.d.ts.map +1 -1
- package/src/engine/graphics/camera/makeScreenScissorFrustum.js +11 -10
- package/src/engine/graphics/canvas/canvas2d_draw_linear_scale.d.ts.map +1 -1
- package/src/engine/graphics/canvas/canvas2d_draw_linear_scale.js +3 -1
- package/src/engine/graphics/ecs/animation/animator/graph/definition/serialization/readAnimationGraphDefinitionFromJSON.d.ts +1 -1
- package/src/engine/graphics/ecs/animation/animator/graph/definition/serialization/readAnimationGraphDefinitionFromJSON.d.ts.map +1 -1
- package/src/engine/graphics/ecs/animation/animator/graph/definition/serialization/readAnimationGraphDefinitionFromJSON.js +2 -2
- package/src/engine/graphics/ecs/animation/animator/graph/definition/serialization/writeAnimationGraphDefinitionToJSON.d.ts.map +1 -1
- package/src/engine/graphics/ecs/animation/animator/graph/definition/serialization/writeAnimationGraphDefinitionToJSON.js +2 -0
- package/src/engine/graphics/ecs/camera/Camera.d.ts.map +1 -1
- package/src/engine/graphics/ecs/camera/Camera.js +4 -0
- package/src/engine/graphics/ecs/camera/auto_set_camera_clipping_planes.d.ts.map +1 -1
- package/src/engine/graphics/ecs/camera/auto_set_camera_clipping_planes.js +7 -2
- package/src/engine/graphics/ecs/camera/set_camera_aspect_ratio.js +1 -1
- package/src/engine/graphics/ecs/decal/v2/FPDecalSystem.js +2 -2
- package/src/engine/graphics/ecs/decal/v2/prototypeDecalSystem.js +2 -2
- package/src/engine/graphics/ecs/highlight/system/ShadedGeometryHighlightSystem.d.ts.map +1 -1
- package/src/engine/graphics/ecs/highlight/system/ShadedGeometryHighlightSystem.js +4 -1
- package/src/engine/graphics/ecs/light/binding/LightBinding.js +2 -2
- package/src/engine/graphics/ecs/mesh/MeshSystem.js +1 -1
- package/src/engine/graphics/ecs/mesh/SkeletonUtils.js +1 -1
- package/src/engine/graphics/ecs/mesh-v2/ShadedGeometry.js +2 -2
- package/src/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.d.ts.map +1 -1
- package/src/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.js +0 -1
- package/src/engine/graphics/ecs/mesh-v2/sg_hierarchy_compute_bounding_box_via_parent_entity.js +1 -1
- package/src/engine/graphics/ecs/path/tube/build/computeFrenetFrames.d.ts.map +1 -1
- package/src/engine/graphics/ecs/path/tube/build/computeFrenetFrames.js +8 -7
- package/src/engine/graphics/ecs/water/WaterSystem.d.ts +6 -0
- package/src/engine/graphics/ecs/water/WaterSystem.d.ts.map +1 -1
- package/src/engine/graphics/ecs/water/WaterSystem.js +12 -1
- package/src/engine/graphics/geometry/MikkT/AvgTSpace.d.ts.map +1 -1
- package/src/engine/graphics/geometry/MikkT/AvgTSpace.js +11 -6
- package/src/engine/graphics/geometry/MikkT/BuildNeighborsFast.d.ts.map +1 -1
- package/src/engine/graphics/geometry/MikkT/BuildNeighborsFast.js +2 -3
- package/src/engine/graphics/geometry/MikkT/CalcTexArea.d.ts.map +1 -1
- package/src/engine/graphics/geometry/MikkT/CalcTexArea.js +3 -4
- package/src/engine/graphics/geometry/MikkT/DegenEpilogue.js +4 -4
- package/src/engine/graphics/geometry/MikkT/EvalTspace.d.ts.map +1 -1
- package/src/engine/graphics/geometry/MikkT/EvalTspace.js +11 -8
- package/src/engine/graphics/geometry/MikkT/GenerateSharedVerticesIndexList.d.ts.map +1 -1
- package/src/engine/graphics/geometry/MikkT/GenerateSharedVerticesIndexList.js +7 -8
- package/src/engine/graphics/geometry/MikkT/GenerateTSpaces.js +8 -8
- package/src/engine/graphics/geometry/MikkT/InitTriInfo.d.ts.map +1 -1
- package/src/engine/graphics/geometry/MikkT/InitTriInfo.js +30 -25
- package/src/engine/graphics/geometry/MikkT/MikkTSpace.js +7 -7
- package/src/engine/graphics/geometry/MikkT/NormalizeSafe.d.ts +0 -1
- package/src/engine/graphics/geometry/MikkT/NormalizeSafe.d.ts.map +1 -1
- package/src/engine/graphics/geometry/MikkT/NormalizeSafe.js +6 -4
- package/src/engine/graphics/geometry/MikkT/STSpace.d.ts +0 -2
- package/src/engine/graphics/geometry/MikkT/STSpace.d.ts.map +1 -1
- package/src/engine/graphics/geometry/MikkT/STSpace.js +3 -3
- package/src/engine/graphics/geometry/MikkT/v3_scale_dot_sub_normalize.d.ts +0 -2
- package/src/engine/graphics/geometry/MikkT/v3_scale_dot_sub_normalize.d.ts.map +1 -1
- package/src/engine/graphics/geometry/MikkT/v3_scale_dot_sub_normalize.js +0 -1
- package/src/engine/graphics/geometry/buffered/ensureGeometryBoundingSphere.js +1 -1
- package/src/engine/graphics/geometry/buffered/query/bvh32_geometry_nearest.d.ts.map +1 -1
- package/src/engine/graphics/geometry/buffered/query/bvh32_geometry_nearest.js +0 -15
- package/src/engine/graphics/geometry/instancing/InstancedMeshGroup.js +10 -10
- package/src/engine/graphics/geometry/optimization/merge/merge_geometry_hierarchy.js +1 -1
- package/src/engine/graphics/impostors/octahedral/ImpostorBaker.d.ts +0 -2
- package/src/engine/graphics/impostors/octahedral/ImpostorBaker.d.ts.map +1 -1
- package/src/engine/graphics/impostors/octahedral/ImpostorBaker.js +4 -3
- package/src/engine/graphics/impostors/octahedral/grid/HemiOctahedralUvEncoder.js +2 -2
- package/src/engine/graphics/impostors/octahedral/grid/UvEncoder.d.ts +17 -7
- package/src/engine/graphics/impostors/voxel/VoxelImpostorBaker.js +2 -2
- package/src/engine/graphics/material/SplatMaterial.js +1 -1
- package/src/engine/graphics/particles/particular/engine/emitter/ParticleEmitter.d.ts.map +1 -1
- package/src/engine/graphics/particles/particular/engine/emitter/ParticleEmitter.js +3 -2
- package/src/engine/graphics/particles/particular/engine/emitter/ParticlePool.js +1 -1
- package/src/engine/graphics/particles/particular/engine/utils/volume/ParticleVolume.js +3 -3
- package/src/engine/graphics/particles/particular/engine/utils/volume/prototypeParticleVolume.js +4 -3
- package/src/engine/graphics/particles/particular/group/ParticleGroup.d.ts.map +1 -1
- package/src/engine/graphics/particles/particular/group/ParticleGroup.js +3 -2
- package/src/engine/graphics/render/forward_plus/LightManager.js +2 -2
- package/src/engine/graphics/render/forward_plus/model/Decal.d.ts +0 -2
- package/src/engine/graphics/render/forward_plus/model/Decal.d.ts.map +1 -1
- package/src/engine/graphics/render/forward_plus/model/Decal.js +3 -3
- package/src/engine/graphics/render/forward_plus/plugin/ForwardPlusRenderingPlugin.js +1 -1
- package/src/engine/graphics/render/forward_plus/prototype/prototypeLightManager.js +4 -3
- package/src/engine/graphics/render/visibility/hiz/prototypeHiZ.js +6 -4
- package/src/engine/graphics/sh3/gi/material/MaterialTransformer.d.ts +1 -8
- package/src/engine/graphics/sh3/gi/material/MaterialTransformer.d.ts.map +1 -1
- package/src/engine/graphics/sh3/gi/material/MaterialTransformer.js +2 -14
- package/src/engine/graphics/sh3/gi/material/ProbeResolutionStage.d.ts +9 -0
- package/src/engine/graphics/sh3/gi/material/ProbeResolutionStage.d.ts.map +1 -0
- package/src/engine/graphics/sh3/gi/material/ProbeResolutionStage.js +14 -0
- package/src/engine/graphics/sh3/lightmap/ARTIFACTS_PLAN.md +146 -0
- package/src/engine/graphics/sh3/lightmap/CODE_REVIEW.md +121 -0
- package/src/engine/graphics/sh3/lightmap/LIGHTMAPPER_REVIEW.md +183 -0
- package/src/engine/graphics/sh3/lightmap/bake_lightmap_for_scene.d.ts +90 -0
- package/src/engine/graphics/sh3/lightmap/bake_lightmap_for_scene.d.ts.map +1 -0
- package/src/engine/graphics/sh3/lightmap/bake_lightmap_for_scene.js +681 -0
- package/src/engine/graphics/sh3/lightmap/lightmap_build_geometry.d.ts +32 -0
- package/src/engine/graphics/sh3/lightmap/lightmap_build_geometry.d.ts.map +1 -0
- package/src/engine/graphics/sh3/lightmap/lightmap_build_geometry.js +155 -0
- package/src/engine/graphics/sh3/lightmap/lightmap_denoise.d.ts +49 -0
- package/src/engine/graphics/sh3/lightmap/lightmap_denoise.d.ts.map +1 -0
- package/src/engine/graphics/sh3/lightmap/lightmap_denoise.js +136 -0
- package/src/engine/graphics/sh3/lightmap/lightmap_dilate.d.ts +19 -0
- package/src/engine/graphics/sh3/lightmap/lightmap_dilate.d.ts.map +1 -0
- package/src/engine/graphics/sh3/lightmap/lightmap_dilate.js +89 -0
- package/src/engine/graphics/sh3/lightmap/lightmap_gather.d.ts +54 -0
- package/src/engine/graphics/sh3/lightmap/lightmap_gather.d.ts.map +1 -0
- package/src/engine/graphics/sh3/lightmap/lightmap_gather.js +168 -0
- package/src/engine/graphics/sh3/lightmap/lightmap_rasterize_triangle.d.ts +30 -0
- package/src/engine/graphics/sh3/lightmap/lightmap_rasterize_triangle.d.ts.map +1 -0
- package/src/engine/graphics/sh3/lightmap/lightmap_rasterize_triangle.js +145 -0
- package/src/engine/graphics/sh3/lightmap/lightmap_seam_fix.d.ts +38 -0
- package/src/engine/graphics/sh3/lightmap/lightmap_seam_fix.d.ts.map +1 -0
- package/src/engine/graphics/sh3/lightmap/lightmap_seam_fix.js +152 -0
- package/src/engine/graphics/sh3/lightmap/prototypeLightmapBaker.d.ts +2 -0
- package/src/engine/graphics/sh3/lightmap/prototypeLightmapBaker.d.ts.map +1 -0
- package/src/engine/graphics/sh3/lightmap/prototypeLightmapBaker.js +186 -0
- package/src/engine/graphics/sh3/lpg/LightProbeGrid.d.ts +69 -0
- package/src/engine/graphics/sh3/lpg/LightProbeGrid.d.ts.map +1 -0
- package/src/engine/graphics/sh3/lpg/LightProbeGrid.js +173 -0
- package/src/engine/graphics/sh3/lpg/LightProbeGridBaker.d.ts +24 -0
- package/src/engine/graphics/sh3/lpg/LightProbeGridBaker.d.ts.map +1 -0
- package/src/engine/graphics/sh3/lpg/LightProbeGridBaker.js +88 -0
- package/src/engine/graphics/sh3/lpg/build_light_probe_grid_for_scene.d.ts +20 -0
- package/src/engine/graphics/sh3/lpg/build_light_probe_grid_for_scene.d.ts.map +1 -0
- package/src/engine/graphics/sh3/lpg/build_light_probe_grid_for_scene.js +79 -0
- package/src/engine/graphics/sh3/lpg/light_probe_grid_obtain_storage_cached.d.ts +11 -0
- package/src/engine/graphics/sh3/lpg/light_probe_grid_obtain_storage_cached.d.ts.map +1 -0
- package/src/engine/graphics/sh3/lpg/light_probe_grid_obtain_storage_cached.js +84 -0
- package/src/engine/graphics/sh3/lpg/light_probe_grid_textures.d.ts +29 -0
- package/src/engine/graphics/sh3/lpg/light_probe_grid_textures.d.ts.map +1 -0
- package/src/engine/graphics/sh3/lpg/light_probe_grid_textures.js +160 -0
- package/src/engine/graphics/sh3/lpg/material/LightProbeGridMaterialTransformer.d.ts +23 -0
- package/src/engine/graphics/sh3/lpg/material/LightProbeGridMaterialTransformer.d.ts.map +1 -0
- package/src/engine/graphics/sh3/lpg/material/LightProbeGridMaterialTransformer.js +228 -0
- package/src/engine/graphics/sh3/lpg/material/chunk_lpg_get_irradiance_at.d.ts +2 -0
- package/src/engine/graphics/sh3/lpg/material/chunk_lpg_get_irradiance_at.d.ts.map +1 -0
- package/src/engine/graphics/sh3/lpg/material/chunk_lpg_get_irradiance_at.js +24 -0
- package/src/engine/graphics/sh3/lpg/material/common.d.ts +3 -0
- package/src/engine/graphics/sh3/lpg/material/common.d.ts.map +1 -0
- package/src/engine/graphics/sh3/lpg/material/common.js +73 -0
- package/src/engine/graphics/sh3/lpg/material/space_fragment/build_fragment_shader.d.ts +6 -0
- package/src/engine/graphics/sh3/lpg/material/space_fragment/build_fragment_shader.d.ts.map +1 -0
- package/src/engine/graphics/sh3/lpg/material/space_fragment/build_fragment_shader.js +42 -0
- package/src/engine/graphics/sh3/lpg/material/space_fragment/build_vertex_shader.d.ts +6 -0
- package/src/engine/graphics/sh3/lpg/material/space_fragment/build_vertex_shader.d.ts.map +1 -0
- package/src/engine/graphics/sh3/lpg/material/space_fragment/build_vertex_shader.js +49 -0
- package/src/engine/graphics/sh3/lpg/material/space_fragment/space_fragment_transform_shader.d.ts +9 -0
- package/src/engine/graphics/sh3/lpg/material/space_fragment/space_fragment_transform_shader.d.ts.map +1 -0
- package/src/engine/graphics/sh3/lpg/material/space_fragment/space_fragment_transform_shader.js +12 -0
- package/src/engine/graphics/sh3/lpg/material/space_vertex/build_fragment_shader.d.ts +6 -0
- package/src/engine/graphics/sh3/lpg/material/space_vertex/build_fragment_shader.d.ts.map +1 -0
- package/src/engine/graphics/sh3/lpg/material/space_vertex/build_fragment_shader.js +30 -0
- package/src/engine/graphics/sh3/lpg/material/space_vertex/build_vertex_shader.d.ts +6 -0
- package/src/engine/graphics/sh3/lpg/material/space_vertex/build_vertex_shader.d.ts.map +1 -0
- package/src/engine/graphics/sh3/lpg/material/space_vertex/build_vertex_shader.js +41 -0
- package/src/engine/graphics/sh3/lpg/material/space_vertex/preamble.frag.d.ts +3 -0
- package/src/engine/graphics/sh3/lpg/material/space_vertex/preamble.frag.d.ts.map +1 -0
- package/src/engine/graphics/sh3/lpg/material/space_vertex/preamble.frag.js +15 -0
- package/src/engine/graphics/sh3/lpg/material/space_vertex/preamble.vert.d.ts +3 -0
- package/src/engine/graphics/sh3/lpg/material/space_vertex/preamble.vert.d.ts.map +1 -0
- package/src/engine/graphics/sh3/lpg/material/space_vertex/preamble.vert.js +9 -0
- package/src/engine/graphics/sh3/lpg/material/space_vertex/space_vertex_transform_shader.d.ts +9 -0
- package/src/engine/graphics/sh3/lpg/material/space_vertex/space_vertex_transform_shader.d.ts.map +1 -0
- package/src/engine/graphics/sh3/lpg/material/space_vertex/space_vertex_transform_shader.js +12 -0
- package/src/engine/graphics/sh3/lpg/serialization/LightProbeGridSerializationAdapter.d.ts +20 -0
- package/src/engine/graphics/sh3/lpg/serialization/LightProbeGridSerializationAdapter.d.ts.map +1 -0
- package/src/engine/graphics/sh3/lpg/serialization/LightProbeGridSerializationAdapter.js +59 -0
- package/src/engine/graphics/sh3/path_tracer/PathTracedMesh.d.ts.map +1 -1
- package/src/engine/graphics/sh3/path_tracer/PathTracedMesh.js +2 -2
- package/src/engine/graphics/sh3/path_tracer/PathTracer.js +2 -2
- package/src/engine/graphics/sh3/path_tracer/material/MaterialConverter.d.ts.map +1 -1
- package/src/engine/graphics/sh3/path_tracer/material/MaterialConverter.js +8 -0
- package/src/engine/graphics/sh3/path_tracer/prepare_scene_gltf.d.ts.map +1 -1
- package/src/engine/graphics/sh3/path_tracer/prepare_scene_gltf.js +6 -4
- package/src/engine/graphics/sh3/path_tracer/prototypePathTracer.js +3 -3
- package/src/engine/graphics/sh3/path_tracer/texture/sample_material.d.ts.map +1 -1
- package/src/engine/graphics/sh3/path_tracer/texture/sample_material.js +5 -4
- package/src/engine/graphics/sh3/prototypeLightProbeGrid.d.ts +2 -0
- package/src/engine/graphics/sh3/prototypeLightProbeGrid.d.ts.map +1 -0
- package/src/engine/graphics/sh3/prototypeLightProbeGrid.js +170 -0
- package/src/engine/graphics/sh3/sky/hosek/prototype_hosek.js +2 -2
- package/src/engine/graphics/texture/atlas/AtlasLookupTexture.js +1 -1
- package/src/engine/graphics/texture/atlas/CachingTextureAtlas.js +1 -1
- package/src/engine/graphics/texture/sampler/resize/sampler2d_scale_down_lanczos.js +1 -1
- package/src/engine/graphics/texture/sampler/sampler2d_copy_with_margins.js +3 -3
- package/src/engine/graphics/util/build_max_height_pyramid.d.ts.map +1 -1
- package/src/engine/graphics/util/build_max_height_pyramid.js +5 -2
- package/src/engine/grid/transform2grid/Transform2GridPositionSystem.js +1 -1
- package/src/engine/input/devices/KeyboardDevice.d.ts +61 -14
- package/src/engine/input/devices/KeyboardDevice.d.ts.map +1 -1
- package/src/engine/input/devices/KeyboardDevice.js +41 -15
- package/src/engine/input/devices/isHTMLElementFocusable.d.ts.map +1 -1
- package/src/engine/input/devices/isHTMLElementFocusable.js +2 -9
- package/src/engine/input/ecs/components/InputBinding.d.ts +7 -1
- package/src/engine/input/ecs/components/InputBinding.d.ts.map +1 -1
- package/src/engine/input/ecs/components/InputBinding.js +8 -1
- package/src/engine/input/ecs/systems/InputControllerSystem.js +1 -1
- package/src/engine/intelligence/behavior/decorator/OverrideContextBehavior.d.ts +2 -1
- package/src/engine/intelligence/behavior/decorator/OverrideContextBehavior.d.ts.map +1 -1
- package/src/engine/intelligence/behavior/decorator/OverrideContextBehavior.js +6 -2
- package/src/engine/intelligence/behavior/selector/WeightedElement.js +1 -1
- package/src/engine/knowledge/database/StaticKnowledgeDatabase.d.ts.map +1 -1
- package/src/engine/knowledge/database/StaticKnowledgeDatabase.js +2 -4
- package/src/engine/logging/elastic/ElasticSearchLogger.d.ts +1 -2
- package/src/engine/logging/elastic/ElasticSearchLogger.d.ts.map +1 -1
- package/src/engine/logging/elastic/ElasticSearchLogger.js +14 -10
- package/src/engine/navigation/ecs/path_following/PathFollower.js +1 -1
- package/src/engine/navigation/grid/find_path_on_grid_astar.d.ts.map +1 -1
- package/src/engine/navigation/grid/find_path_on_grid_astar.js +5 -2
- package/src/engine/network/orchestrator/ServerAuthoritativeServer.d.ts +1 -1
- package/src/engine/network/orchestrator/ServerAuthoritativeServer.d.ts.map +1 -1
- package/src/engine/network/orchestrator/ServerAuthoritativeServer.js +17 -0
- package/src/engine/physics/fluid/ecs/FluidObstacleSystem.d.ts +4 -4
- package/src/engine/physics/fluid/ecs/FluidSystem.d.ts +3 -3
- package/src/engine/scene/SceneManager.d.ts.map +1 -1
- package/src/engine/scene/SceneManager.js +4 -2
- package/src/engine/simulation/Ticker.d.ts.map +1 -1
- package/src/engine/simulation/Ticker.js +9 -0
- package/src/engine/sound/ecs/emitter/SoundEmitterSystem.d.ts.map +1 -1
- package/src/engine/sound/ecs/emitter/SoundEmitterSystem.js +6 -1
- package/src/engine/sound/material/concrete/json/serializeSoundMaterialToJSON.js +1 -1
- package/src/engine/sound/simulation/prototypeAcousticSolver.js +261 -143
- package/src/generation/theme/ThemeEngine.d.ts +9 -0
- package/src/generation/theme/ThemeEngine.d.ts.map +1 -1
- package/src/generation/theme/ThemeEngine.js +37 -2
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
import { assert } from "../../../../../core/assert.js";
|
|
2
|
+
import { BinaryBuffer } from "../../../../../core/binary/BinaryBuffer.js";
|
|
3
|
+
import { writeObjectString } from "./objectStringCodec.js";
|
|
4
|
+
import {
|
|
5
|
+
OBJECT_FORMAT_VERSION,
|
|
6
|
+
OBJECT_MAGIC,
|
|
7
|
+
TAG_ADAPTER_OBJECT,
|
|
8
|
+
TAG_ARRAY,
|
|
9
|
+
TAG_BIGINT,
|
|
10
|
+
TAG_FALSE,
|
|
11
|
+
TAG_FLOAT,
|
|
12
|
+
TAG_NEG_INT,
|
|
13
|
+
TAG_NULL,
|
|
14
|
+
TAG_PLAIN_OBJECT,
|
|
15
|
+
TAG_POS_INT,
|
|
16
|
+
TAG_REF,
|
|
17
|
+
TAG_REFLECT_OBJECT,
|
|
18
|
+
TAG_STRING,
|
|
19
|
+
TAG_TRUE,
|
|
20
|
+
TAG_UNDEFINED
|
|
21
|
+
} from "./ObjectBinaryFormat.js";
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Largest integer magnitude that {@link BinaryBuffer.writeUintVar} accepts; larger integers fall back to float64.
|
|
25
|
+
* @readonly
|
|
26
|
+
* @type {number}
|
|
27
|
+
*/
|
|
28
|
+
const MAX_VARINT = 2147483647;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Writer half of the general object-graph binary serializer. See {@link BinaryObjectDeSerializer} for the reader
|
|
32
|
+
* and `DESIGN.md` for the wire format and rationale.
|
|
33
|
+
*
|
|
34
|
+
* Serializes an arbitrary value — primitives, arrays, plain objects and class instances — with **no per-class
|
|
35
|
+
* setup required**. Class instances are serialized by reflection over their own enumerable fields by default; if a
|
|
36
|
+
* class has a hand-written adapter registered in the {@link BinarySerializationRegistry}, that adapter is used
|
|
37
|
+
* instead (compact, custom, versioned). Shared references and cycles are preserved via first-seen object indices.
|
|
38
|
+
*
|
|
39
|
+
* Class names and reflective field-name sets are interned into two tables that are written ahead of the body, so
|
|
40
|
+
* repeated types cost their name once. The body is built into a scratch buffer first and copied in after the
|
|
41
|
+
* tables — the only extra work versus single-pass is that final byte copy.
|
|
42
|
+
*
|
|
43
|
+
* @author Alex Goldring
|
|
44
|
+
* @copyright Company Named Limited (c) 2026
|
|
45
|
+
*/
|
|
46
|
+
export class BinaryObjectSerializer {
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Adapter + migrator + class-name registry.
|
|
50
|
+
* @type {BinarySerializationRegistry|null}
|
|
51
|
+
*/
|
|
52
|
+
#registry = null;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Scratch buffer the value graph (body) is written into before it is copied in after the tables.
|
|
56
|
+
* @type {BinaryBuffer}
|
|
57
|
+
*/
|
|
58
|
+
#body = new BinaryBuffer();
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Object/array instance -> its assigned index, for reference de-duplication and cycle detection.
|
|
62
|
+
* @type {Map<Object, number>}
|
|
63
|
+
*/
|
|
64
|
+
#refs = new Map();
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* typeName -> class-table index.
|
|
68
|
+
* @type {Map<string, number>}
|
|
69
|
+
*/
|
|
70
|
+
#classIndex = new Map();
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Ordered class-table records, flushed ahead of the body.
|
|
74
|
+
* @type {Array<{typeName:string, version:number}>}
|
|
75
|
+
*/
|
|
76
|
+
#classList = [];
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* shape key (JSON of the field-name list) -> shape-table index.
|
|
80
|
+
* @type {Map<string, number>}
|
|
81
|
+
*/
|
|
82
|
+
#shapeIndex = new Map();
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Ordered shape-table records (each an ordered field-name list), flushed ahead of the body.
|
|
86
|
+
* @type {Array<string[]>}
|
|
87
|
+
*/
|
|
88
|
+
#shapeList = [];
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* @param {BinarySerializationRegistry} registry
|
|
92
|
+
*/
|
|
93
|
+
constructor(registry) {
|
|
94
|
+
this.setRegistry(registry);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* @param {BinarySerializationRegistry} registry
|
|
99
|
+
*/
|
|
100
|
+
setRegistry(registry) {
|
|
101
|
+
assert.defined(registry, 'registry');
|
|
102
|
+
assert.ok(registry.isBinarySerializationRegistry, 'registry is not a BinarySerializationRegistry');
|
|
103
|
+
|
|
104
|
+
this.#registry = registry;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
#reset() {
|
|
108
|
+
this.#body.position = 0;
|
|
109
|
+
this.#refs.clear();
|
|
110
|
+
this.#classIndex.clear();
|
|
111
|
+
this.#classList.length = 0;
|
|
112
|
+
this.#shapeIndex.clear();
|
|
113
|
+
this.#shapeList.length = 0;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Serialize `value` and its whole object graph into `buffer` as a complete document (header + tables + body).
|
|
118
|
+
*
|
|
119
|
+
* @param {BinaryBuffer} buffer target, written at the current {@link BinaryBuffer.position}
|
|
120
|
+
* @param {*} value any value; objects may be plain, class instances (reflective or adapter-backed) or arrays
|
|
121
|
+
*/
|
|
122
|
+
serialize(buffer, value) {
|
|
123
|
+
this.#reset();
|
|
124
|
+
|
|
125
|
+
// build the body first so the interning tables are complete before we emit them
|
|
126
|
+
this.writeValue(this.#body, value);
|
|
127
|
+
|
|
128
|
+
// header
|
|
129
|
+
buffer.writeUint16(OBJECT_MAGIC);
|
|
130
|
+
buffer.writeUint8(OBJECT_FORMAT_VERSION);
|
|
131
|
+
|
|
132
|
+
// class table
|
|
133
|
+
buffer.writeUintVar(this.#classList.length);
|
|
134
|
+
for (let i = 0; i < this.#classList.length; i++) {
|
|
135
|
+
const record = this.#classList[i];
|
|
136
|
+
writeObjectString(buffer, record.typeName);
|
|
137
|
+
buffer.writeUintVar(record.version);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// shape table
|
|
141
|
+
buffer.writeUintVar(this.#shapeList.length);
|
|
142
|
+
for (let i = 0; i < this.#shapeList.length; i++) {
|
|
143
|
+
const names = this.#shapeList[i];
|
|
144
|
+
buffer.writeUintVar(names.length);
|
|
145
|
+
for (let j = 0; j < names.length; j++) {
|
|
146
|
+
writeObjectString(buffer, names[j]);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// body
|
|
151
|
+
buffer.writeBytes(this.#body.raw_bytes, 0, this.#body.position);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* @param {string} typeName
|
|
156
|
+
* @param {number} version
|
|
157
|
+
* @returns {number} class-table index
|
|
158
|
+
*/
|
|
159
|
+
#internClass(typeName, version) {
|
|
160
|
+
let index = this.#classIndex.get(typeName);
|
|
161
|
+
|
|
162
|
+
if (index === undefined) {
|
|
163
|
+
index = this.#classList.length;
|
|
164
|
+
this.#classList.push({ typeName, version });
|
|
165
|
+
this.#classIndex.set(typeName, index);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return index;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* @param {string[]} names ordered field names
|
|
173
|
+
* @returns {number} shape-table index
|
|
174
|
+
*/
|
|
175
|
+
#internShape(names) {
|
|
176
|
+
const key = JSON.stringify(names);
|
|
177
|
+
|
|
178
|
+
let index = this.#shapeIndex.get(key);
|
|
179
|
+
|
|
180
|
+
if (index === undefined) {
|
|
181
|
+
index = this.#shapeList.length;
|
|
182
|
+
this.#shapeList.push(names);
|
|
183
|
+
this.#shapeIndex.set(key, index);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return index;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Write a single value. Nesting adapters call this to serialize a child of any type (including `null`).
|
|
191
|
+
*
|
|
192
|
+
* @param {BinaryBuffer} buffer
|
|
193
|
+
* @param {*} value
|
|
194
|
+
*/
|
|
195
|
+
writeValue(buffer, value) {
|
|
196
|
+
if (value === null) {
|
|
197
|
+
buffer.writeUint8(TAG_NULL);
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const type = typeof value;
|
|
202
|
+
|
|
203
|
+
switch (type) {
|
|
204
|
+
case "undefined":
|
|
205
|
+
buffer.writeUint8(TAG_UNDEFINED);
|
|
206
|
+
return;
|
|
207
|
+
case "boolean":
|
|
208
|
+
buffer.writeUint8(value ? TAG_TRUE : TAG_FALSE);
|
|
209
|
+
return;
|
|
210
|
+
case "number":
|
|
211
|
+
if (Number.isInteger(value) && value >= -MAX_VARINT && value <= MAX_VARINT) {
|
|
212
|
+
if (value >= 0) {
|
|
213
|
+
buffer.writeUint8(TAG_POS_INT);
|
|
214
|
+
buffer.writeUintVar(value);
|
|
215
|
+
} else {
|
|
216
|
+
buffer.writeUint8(TAG_NEG_INT);
|
|
217
|
+
buffer.writeUintVar(-value);
|
|
218
|
+
}
|
|
219
|
+
} else {
|
|
220
|
+
buffer.writeUint8(TAG_FLOAT);
|
|
221
|
+
buffer.writeFloat64(value);
|
|
222
|
+
}
|
|
223
|
+
return;
|
|
224
|
+
case "string":
|
|
225
|
+
buffer.writeUint8(TAG_STRING);
|
|
226
|
+
writeObjectString(buffer, value);
|
|
227
|
+
return;
|
|
228
|
+
case "bigint":
|
|
229
|
+
buffer.writeUint8(TAG_BIGINT);
|
|
230
|
+
writeObjectString(buffer, value.toString());
|
|
231
|
+
return;
|
|
232
|
+
case "function":
|
|
233
|
+
throw new Error("Cannot serialize a function value");
|
|
234
|
+
case "symbol":
|
|
235
|
+
throw new Error("Cannot serialize a symbol value");
|
|
236
|
+
default:
|
|
237
|
+
// object, handled below
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// from here `value` is a non-null object (or array)
|
|
241
|
+
|
|
242
|
+
const existingIndex = this.#refs.get(value);
|
|
243
|
+
|
|
244
|
+
if (existingIndex !== undefined) {
|
|
245
|
+
// seen before — emit a back-reference (handles shared references and cycles)
|
|
246
|
+
buffer.writeUint8(TAG_REF);
|
|
247
|
+
buffer.writeUintVar(existingIndex);
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// assign this instance its index BEFORE writing contents, so a cyclic child can refer back to it
|
|
252
|
+
this.#refs.set(value, this.#refs.size);
|
|
253
|
+
|
|
254
|
+
if (Array.isArray(value)) {
|
|
255
|
+
buffer.writeUint8(TAG_ARRAY);
|
|
256
|
+
buffer.writeUintVar(value.length);
|
|
257
|
+
for (let i = 0; i < value.length; i++) {
|
|
258
|
+
this.writeValue(buffer, value[i]);
|
|
259
|
+
}
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
const prototype = Object.getPrototypeOf(value);
|
|
264
|
+
const ctor = prototype === null ? undefined : prototype.constructor;
|
|
265
|
+
|
|
266
|
+
// prefer the adapter-registered name (survives minification, keyed on the constructor), then the class's
|
|
267
|
+
// own static typeName (the deliberate escape hatch from name mangling). The typeName must be OWN, not
|
|
268
|
+
// inherited: a subclass without its own typeName would otherwise be misclassified as its ancestor.
|
|
269
|
+
let typeName = this.#registry.getClassName(ctor);
|
|
270
|
+
if (typeName === undefined && ctor !== undefined && Object.prototype.hasOwnProperty.call(ctor, "typeName")) {
|
|
271
|
+
typeName = ctor.typeName;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
if (typeName !== undefined && typeName !== null) {
|
|
275
|
+
const adapter = this.#registry.getAdapter(typeName);
|
|
276
|
+
|
|
277
|
+
if (adapter !== undefined) {
|
|
278
|
+
// hand-written adapter takes over the payload layout for this class
|
|
279
|
+
const classIdx = this.#internClass(typeName, adapter.version);
|
|
280
|
+
buffer.writeUint8(TAG_ADAPTER_OBJECT);
|
|
281
|
+
buffer.writeUintVar(classIdx);
|
|
282
|
+
adapter.initialize(this);
|
|
283
|
+
adapter.serialize(buffer, value);
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// reflective class instance — reconstructed via the module registry on read
|
|
288
|
+
this.#writeReflected(buffer, TAG_REFLECT_OBJECT, this.#internClass(typeName, 0), value);
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
if (prototype === Object.prototype || prototype === null) {
|
|
293
|
+
// plain object — reconstructed as {} on read
|
|
294
|
+
this.#writeReflected(buffer, TAG_PLAIN_OBJECT, -1, value);
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
throw new Error(`Cannot serialize instance of '${ctor && ctor.name}': it has no registered adapter and no static 'typeName'. Add a static typeName (so it survives minification) or register an adapter.`);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* Write a reflective object body: `[classIdx] shapeIdx value*`.
|
|
303
|
+
*
|
|
304
|
+
* @param {BinaryBuffer} buffer
|
|
305
|
+
* @param {number} tag {@link TAG_REFLECT_OBJECT} or {@link TAG_PLAIN_OBJECT}
|
|
306
|
+
* @param {number} classIdx class-table index, or -1 for a plain object (not written)
|
|
307
|
+
* @param {Object} value
|
|
308
|
+
*/
|
|
309
|
+
#writeReflected(buffer, tag, classIdx, value) {
|
|
310
|
+
const names = Object.keys(value);
|
|
311
|
+
const shapeIdx = this.#internShape(names);
|
|
312
|
+
|
|
313
|
+
buffer.writeUint8(tag);
|
|
314
|
+
|
|
315
|
+
if (classIdx >= 0) {
|
|
316
|
+
buffer.writeUintVar(classIdx);
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
buffer.writeUintVar(shapeIdx);
|
|
320
|
+
|
|
321
|
+
for (let i = 0; i < names.length; i++) {
|
|
322
|
+
this.writeValue(buffer, value[names[i]]);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* @readonly
|
|
329
|
+
* @type {boolean}
|
|
330
|
+
*/
|
|
331
|
+
BinaryObjectSerializer.prototype.isBinaryObjectSerializer = true;
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
# Object-graph binary serialization — design
|
|
2
|
+
|
|
3
|
+
## 1. Purpose
|
|
4
|
+
|
|
5
|
+
A **general-purpose** binary serializer for arbitrary JavaScript object graphs, layered on the existing
|
|
6
|
+
[`BinaryClassSerializationAdapter`](../BinaryClassSerializationAdapter.js) / upgrader / registry machinery.
|
|
7
|
+
|
|
8
|
+
The defining goal — and the thing an earlier draft got wrong — is that you can serialize an object of class `X`
|
|
9
|
+
**without hand-writing an adapter for it**. Classes are serialized by reflection over their own fields by default; a
|
|
10
|
+
hand-written adapter is an *optional override* for classes that want a compact or custom encoding.
|
|
11
|
+
|
|
12
|
+
What it does:
|
|
13
|
+
|
|
14
|
+
- **Reflection by default.** Plain objects and class instances are serialized field-by-field with no per-class setup.
|
|
15
|
+
- **Adapters as an override.** If a class has an adapter registered in the [`BinarySerializationRegistry`](../BinarySerializationRegistry.js),
|
|
16
|
+
that adapter owns the encoding (compact, custom, versioned). Reflection is the fallback, not the only path.
|
|
17
|
+
- **Reference semantics.** Shared references are preserved as one instance, and cycles are handled — objects are
|
|
18
|
+
tracked by identity and re-encoded as back-references.
|
|
19
|
+
- **Compact framing.** Class names and reflective field-name sets ("shapes") are interned into two tables written
|
|
20
|
+
ahead of the body and referenced by a small integer, so a thousand same-class objects pay for the name once.
|
|
21
|
+
- **Versioning + bidirectional migration.** Adapter-backed classes carry a version; on read, a mismatch is migrated
|
|
22
|
+
through the registered [`BinaryClassUpgrader`](../BinaryClassUpgrader.js) chain in *either* direction.
|
|
23
|
+
- **Minification-safe identity.** A class is identified by its adapter registration or its static `typeName`, never by
|
|
24
|
+
the minifier-mangled `constructor.name`.
|
|
25
|
+
|
|
26
|
+
## 2. Where it sits
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
BinaryBuffer byte stream
|
|
30
|
+
└─ BinaryClassSerializationAdapter per-class hand-written serialize/deserialize (optional override)
|
|
31
|
+
└─ BinarySerializationRegistry typeName → adapter, migrator graph, class → typeName
|
|
32
|
+
└─ ModuleRegistry typeName → class (for reflective reconstruction)
|
|
33
|
+
└─ BinaryObjectSerializer / BinaryObjectDeSerializer ← THIS: reflection + adapters + references + tables
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
This complements the existing storage layer rather than duplicating it. [`BinaryBufferSerializer`](../../BinaryBufferSerializer.js)
|
|
37
|
+
serializes an ECS dataset as *homogeneous collections of components* (one class name per collection, delegating nested
|
|
38
|
+
objects to the older adapter-only `object/BinaryObjectSerializationAdapter`). This system is the general graph tool it
|
|
39
|
+
was missing: heterogeneous graphs, adapter-less classes, and shared/cyclic references. It could serve as a drop-in for
|
|
40
|
+
that nested-object role; that integration is deliberately out of scope here.
|
|
41
|
+
|
|
42
|
+
## 3. Wire format
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
DOCUMENT := HEADER CLASS_TABLE SHAPE_TABLE BODY
|
|
46
|
+
|
|
47
|
+
HEADER := u16(OBJECT_MAGIC=0x4F33) u8(OBJECT_FORMAT_VERSION=1)
|
|
48
|
+
|
|
49
|
+
CLASS_TABLE := uvar(count) record* record := utf8(typeName) uvar(version)
|
|
50
|
+
SHAPE_TABLE := uvar(count) shape* shape := uvar(fieldCount) utf8(name)*
|
|
51
|
+
|
|
52
|
+
BODY := VALUE
|
|
53
|
+
|
|
54
|
+
VALUE := u8(TAG_NULL) | u8(TAG_UNDEFINED) | u8(TAG_FALSE) | u8(TAG_TRUE)
|
|
55
|
+
| u8(TAG_POS_INT) uvar(n) // n >= 0, fits a varint
|
|
56
|
+
| u8(TAG_NEG_INT) uvar(-n) // n < 0, fits a varint
|
|
57
|
+
| u8(TAG_FLOAT) float64 // any other number (float, NaN, ±Infinity, huge int)
|
|
58
|
+
| u8(TAG_STRING) utf8
|
|
59
|
+
| u8(TAG_BIGINT) utf8(decimal)
|
|
60
|
+
| u8(TAG_REF) uvar(objectIndex) // back-reference to an already-seen object/array
|
|
61
|
+
| u8(TAG_ARRAY) uvar(length) VALUE*
|
|
62
|
+
| u8(TAG_PLAIN_OBJECT) uvar(shapeIdx) VALUE* // reconstructed as {}
|
|
63
|
+
| u8(TAG_REFLECT_OBJECT) uvar(classIdx) uvar(shapeIdx) VALUE* // new Klass() + field assignment
|
|
64
|
+
| u8(TAG_ADAPTER_OBJECT) uvar(classIdx) <adapter payload>
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
**Object indices.** Every `ARRAY`, `PLAIN_OBJECT`, `REFLECT_OBJECT` and `ADAPTER_OBJECT` is assigned an index in
|
|
68
|
+
first-seen order — the writer keeps an identity `Map`, the reader an array. Indices are *not written* for new objects
|
|
69
|
+
(both sides count in lock-step); only `TAG_REF` carries an explicit index. Both sides register an object **before**
|
|
70
|
+
reading/writing its contents, so a cyclic child resolves to the (partially built) parent.
|
|
71
|
+
|
|
72
|
+
**Two version numbers.** `OBJECT_FORMAT_VERSION` versions the framing; the per-class `version` in the class table
|
|
73
|
+
versions one class's payload and drives migration. They never interfere.
|
|
74
|
+
|
|
75
|
+
**Prepended tables.** The body is built into a scratch buffer while the class/shape tables fill; the document then
|
|
76
|
+
writes header + tables + a byte-copy of the body. Reading is a single forward pass (the tables come first). The only
|
|
77
|
+
cost over single-pass writing is that final copy — as intended.
|
|
78
|
+
|
|
79
|
+
## 4. Reflection
|
|
80
|
+
|
|
81
|
+
A class instance with no adapter, or a plain object, is written by enumerating `Object.keys(value)` (own enumerable
|
|
82
|
+
string keys, in insertion order). The ordered name list is interned into the shape table; the body carries the shape
|
|
83
|
+
index and one `VALUE` per field. This *reads* the instance's fields but never mutates it, and assumes no special field
|
|
84
|
+
names — it serializes whatever is there.
|
|
85
|
+
|
|
86
|
+
On read:
|
|
87
|
+
- `PLAIN_OBJECT` → `{}`, fields assigned.
|
|
88
|
+
- `REFLECT_OBJECT` → `new Klass()` (from the module registry, or the adapter's `klass` if one happens to be
|
|
89
|
+
registered), fields assigned over it.
|
|
90
|
+
|
|
91
|
+
Because the shape is self-describing, reflective encoding is naturally tolerant of additive field changes: a reader
|
|
92
|
+
simply materialises whatever fields the shape lists. Semantic changes that need real migration are a reason to graduate
|
|
93
|
+
the class to an adapter.
|
|
94
|
+
|
|
95
|
+
**Strings and keys are NUL-safe.** All strings this system writes itself — type names, field names, string values and
|
|
96
|
+
bigints — use a byte-length-prefixed UTF-8 codec ([`objectStringCodec.js`](./objectStringCodec.js)), not
|
|
97
|
+
`BinaryBuffer.writeUTF8String`. The latter is NUL-*terminated* on read, so it cannot round-trip a string (or object
|
|
98
|
+
key) containing `U+0000`; the byte-length prefix has no terminator and round-trips every code point. (Strings an
|
|
99
|
+
*adapter* writes with `buffer.writeUTF8String` still follow that primitive's own behaviour — another reason adapters
|
|
100
|
+
own their encoding.)
|
|
101
|
+
|
|
102
|
+
## 5. Adapters (the override)
|
|
103
|
+
|
|
104
|
+
When the writer's registry has an adapter for a value's class, the value is written as `ADAPTER_OBJECT`: a class-table
|
|
105
|
+
index plus the adapter's own payload. The adapter fully controls the bytes (e.g. three `float64`s for a `Vector3`,
|
|
106
|
+
skipping field names and per-value tags), and can recurse into arbitrary children through the driving context via
|
|
107
|
+
`this.context.writeValue` / `readValue` (see [`ObjectSerializationAdapter`](./ObjectSerializationAdapter.js)). Adapter
|
|
108
|
+
objects participate in the same reference table, so shared/cyclic adapter instances work too.
|
|
109
|
+
|
|
110
|
+
Adapters are the extension point for anything reflection shouldn't own: `Vector3`, typed arrays, `Map`/`Set`/`Date`,
|
|
111
|
+
quantised or bit-packed encodings, or classes needing explicit migration.
|
|
112
|
+
|
|
113
|
+
## 6. Reference semantics
|
|
114
|
+
|
|
115
|
+
Objects and arrays are tracked by **identity**. The first time an instance is seen it is encoded in full and assigned
|
|
116
|
+
the next index; every later occurrence — whether a shared child or a cycle back to an ancestor — is a `TAG_REF` to that
|
|
117
|
+
index. This preserves object identity across the graph (`restored.a === restored.b`) and makes cyclic graphs
|
|
118
|
+
serialisable instead of stack-overflowing. Primitives are never reference-tracked.
|
|
119
|
+
|
|
120
|
+
## 7. Versioning & migration
|
|
121
|
+
|
|
122
|
+
Adapter classes store their `version` once per class in the table. On read, the deserializer resolves migration
|
|
123
|
+
**lazily, on the first `ADAPTER_OBJECT` of the class** — never at class-table time — because whether a class was written
|
|
124
|
+
via an adapter (and so whether the version means anything) is a property of the body tag, not of the reader's registry.
|
|
125
|
+
If the stored version differs from the reader's adapter version (in *either* direction), the payload is run through the
|
|
126
|
+
shortest [`BinaryClassUpgrader`](../BinaryClassUpgrader.js) chain the registry can find. The chain is really a
|
|
127
|
+
*migrator*: it can move down a version as readily as up, so there is no artificial "data must not be newer" rule — only
|
|
128
|
+
"a path must exist".
|
|
129
|
+
|
|
130
|
+
Reflective classes are stored at version 0 and are never migrated (their shapes already make them additively tolerant).
|
|
131
|
+
|
|
132
|
+
**Nesting caveat.** A migrator reads one object's payload and rewrites it; the fresh scratch buffers make this
|
|
133
|
+
re-entrant. As with the existing collection path, migrating an *adapter class whose payload itself nests other objects*
|
|
134
|
+
requires the migrator to reproduce that nested framing — rare, and a reason to migrate leaf classes or use reflection.
|
|
135
|
+
|
|
136
|
+
## 8. Class identity & minification
|
|
137
|
+
|
|
138
|
+
The name written for a class is resolved, in order:
|
|
139
|
+
1. the name its adapter is registered under (`registry.getClassName(constructor)` — a reverse index keyed on the
|
|
140
|
+
constructor object, so it survives minification), else
|
|
141
|
+
2. the class's static `typeName` (the deliberate escape hatch: a minifier mangles `constructor.name` but leaves a
|
|
142
|
+
`static typeName = "Foo"` string intact).
|
|
143
|
+
|
|
144
|
+
A class instance with neither an adapter nor a `typeName` cannot be safely round-tripped and is rejected at write time
|
|
145
|
+
with a message pointing at the fix. Plain objects (prototype `Object.prototype` or null) need no name — they round-trip
|
|
146
|
+
as `{}`.
|
|
147
|
+
|
|
148
|
+
## 9. Registries
|
|
149
|
+
|
|
150
|
+
- **Serializer** needs only a `BinarySerializationRegistry` (adapters + `getClassName` + versions).
|
|
151
|
+
- **Deserializer** needs the same registry plus a `ModuleRegistry` (`typeName → class`) to reconstruct reflective
|
|
152
|
+
class instances. The module registry is optional when the data has no reflective class instances (plain objects,
|
|
153
|
+
arrays and adapter-backed classes don't need it). A reflective class missing from it is a clear read-time error.
|
|
154
|
+
|
|
155
|
+
## 10. Non-goals & limitations
|
|
156
|
+
|
|
157
|
+
- **Not self-contained for exotic built-ins.** `Date`, `Map`, `Set`, `RegExp`, typed arrays and `ArrayBuffer` are not
|
|
158
|
+
handled natively — register an adapter for them. This keeps the core small; the adapter mechanism is the seam.
|
|
159
|
+
- **Functions and symbols** cannot be serialized (thrown at write). Symbol-keyed and non-enumerable properties are
|
|
160
|
+
ignored (`Object.keys` semantics), matching JSON expectations.
|
|
161
|
+
- **Reconstruction uses `new Klass()`** — classes need a usable no-argument constructor. Null-prototype objects come
|
|
162
|
+
back as ordinary `{}`.
|
|
163
|
+
- **Depth, not breadth, is the limit.** References make cyclic/shared graphs safe, but a pathologically deep graph can
|
|
164
|
+
still exhaust the call stack.
|
|
165
|
+
|
|
166
|
+
## 11. Security posture
|
|
167
|
+
|
|
168
|
+
Deserialization only ever constructs (a) classes with a registered adapter, or (b) classes present in the module
|
|
169
|
+
registry, or (c) plain objects/arrays. It never instantiates an attacker-named arbitrary type and never invokes
|
|
170
|
+
stream-driven methods beyond a class's own `deserialize`. This registry/module allow-list is the standard mitigation
|
|
171
|
+
for the reflective-deserializer RCE lineage (Java `Serializable`, `pickle`, .NET `BinaryFormatter`). Reflection does
|
|
172
|
+
read *all* own-enumerable fields of the objects you hand it — use an adapter when a class must control or withhold
|
|
173
|
+
fields.
|
|
174
|
+
|
|
175
|
+
## 12. API
|
|
176
|
+
|
|
177
|
+
`BinaryObjectSerializer(registry)` — `serialize(buffer, value)`, `writeValue(buffer, value)` (for nesting adapters).
|
|
178
|
+
|
|
179
|
+
`BinaryObjectDeSerializer(registry, modules?)` — `deserialize(buffer)`, `readValue(buffer)` (for nesting adapters),
|
|
180
|
+
`setModuleRegistry(modules)`.
|
|
181
|
+
|
|
182
|
+
`ObjectSerializationAdapter extends BinaryClassSerializationAdapter` — base for nesting adapters; `initialize(context)`
|
|
183
|
+
captures the serializer/deserializer into `this.context`.
|
|
184
|
+
|
|
185
|
+
`BinarySerializationRegistry.getClassName(klass)` — reverse of `registerAdapter`; constructor → registered name.
|
|
186
|
+
|
|
187
|
+
## 13. Tests
|
|
188
|
+
|
|
189
|
+
- `*.reflection.spec.js` — primitives (incl. bigint, NaN/±Infinity, large-int→float), plain objects, arrays, reflective
|
|
190
|
+
class instances, nesting, field-order preservation, no-mutation.
|
|
191
|
+
- `*.references.spec.js` — shared references, self-cycles, mutual cycles, self-containing arrays, cycles through class
|
|
192
|
+
instances and container adapters.
|
|
193
|
+
- `*.adapters.spec.js` — adapter used & respected, adapter framing vs reflective, adapter objects nested/shared,
|
|
194
|
+
container adapter recursing through the context.
|
|
195
|
+
- `*.versioning.spec.js` — forward migration, **backward** migration, version-match no-op, missing-path error, shared
|
|
196
|
+
class-table migration.
|
|
197
|
+
- `*.errors.spec.js` — function/symbol rejection, missing typeName, missing module registry, bad magic / format
|
|
198
|
+
version, `typeName`-as-identity, class+shape interning, large homogeneous collection.
|
|
199
|
+
- `BinarySerializationRegistry.spec.js` — `getClassName` reverse-lookup.
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared wire-format constants for the general object-graph binary serializer.
|
|
3
|
+
*
|
|
4
|
+
* A document is: `HEADER CLASS_TABLE SHAPE_TABLE BODY`, where BODY is a single self-describing VALUE. Every
|
|
5
|
+
* object/array in the body is assigned an implicit index in first-seen order so later occurrences of the same
|
|
6
|
+
* instance (shared references, cycles) encode as a compact back-reference. Class names and reflective field-name
|
|
7
|
+
* sets ("shapes") are interned into the two prepended tables and referenced by index, so a graph of a thousand
|
|
8
|
+
* same-class objects pays for the class name and field names exactly once.
|
|
9
|
+
*
|
|
10
|
+
* @author Alex Goldring
|
|
11
|
+
* @copyright Company Named Limited (c) 2026
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Magic marker at the head of a document (`'O','3'`). Lets a reader reject a foreign/corrupt stream.
|
|
15
|
+
* @readonly
|
|
16
|
+
* @type {number}
|
|
17
|
+
*/
|
|
18
|
+
export const OBJECT_MAGIC: number;
|
|
19
|
+
/**
|
|
20
|
+
* Version of the framing (header + tables + value tags). Independent of any individual class's payload version.
|
|
21
|
+
* @readonly
|
|
22
|
+
* @type {number}
|
|
23
|
+
*/
|
|
24
|
+
export const OBJECT_FORMAT_VERSION: number;
|
|
25
|
+
/** `null`. @readonly @type {number} */
|
|
26
|
+
export const TAG_NULL: number;
|
|
27
|
+
/** `undefined`. @readonly @type {number} */
|
|
28
|
+
export const TAG_UNDEFINED: number;
|
|
29
|
+
/** boolean `false`. @readonly @type {number} */
|
|
30
|
+
export const TAG_FALSE: number;
|
|
31
|
+
/** boolean `true`. @readonly @type {number} */
|
|
32
|
+
export const TAG_TRUE: number;
|
|
33
|
+
/** non-negative integer that fits a varint; followed by `uvar(value)`. @readonly @type {number} */
|
|
34
|
+
export const TAG_POS_INT: number;
|
|
35
|
+
/** negative integer that fits a varint; followed by `uvar(-value)`. @readonly @type {number} */
|
|
36
|
+
export const TAG_NEG_INT: number;
|
|
37
|
+
/** any other number (float, NaN, Infinity, out-of-range integer); followed by `float64`. @readonly @type {number} */
|
|
38
|
+
export const TAG_FLOAT: number;
|
|
39
|
+
/** string; followed by a length-prefixed UTF-8 string. @readonly @type {number} */
|
|
40
|
+
export const TAG_STRING: number;
|
|
41
|
+
/** bigint; followed by its base-10 string form. @readonly @type {number} */
|
|
42
|
+
export const TAG_BIGINT: number;
|
|
43
|
+
/** back-reference to an already-seen object/array; followed by `uvar(objectIndex)`. @readonly @type {number} */
|
|
44
|
+
export const TAG_REF: number;
|
|
45
|
+
/** array; followed by `uvar(length)` then `length` VALUEs. @readonly @type {number} */
|
|
46
|
+
export const TAG_ARRAY: number;
|
|
47
|
+
/** plain object (reconstructed as `{}`); followed by `uvar(shapeIndex)` then one VALUE per field. @readonly @type {number} */
|
|
48
|
+
export const TAG_PLAIN_OBJECT: number;
|
|
49
|
+
/** reflective class instance; followed by `uvar(classIndex) uvar(shapeIndex)` then one VALUE per field. @readonly @type {number} */
|
|
50
|
+
export const TAG_REFLECT_OBJECT: number;
|
|
51
|
+
/** class instance serialized by a registered adapter; followed by `uvar(classIndex)` then the adapter payload. @readonly @type {number} */
|
|
52
|
+
export const TAG_ADAPTER_OBJECT: number;
|
|
53
|
+
//# sourceMappingURL=ObjectBinaryFormat.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ObjectBinaryFormat.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/ecs/storage/binary/object-v2/ObjectBinaryFormat.js"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH;;;;GAIG;AACH,2BAFU,MAAM,CAEmB;AAEnC;;;;GAIG;AACH,oCAFU,MAAM,CAEuB;AAIvC,uCAAuC;AACvC,uBAD6B,MAAM,CACT;AAC1B,4CAA4C;AAC5C,4BADkC,MAAM,CACT;AAC/B,gDAAgD;AAChD,wBADsC,MAAM,CACjB;AAC3B,+CAA+C;AAC/C,uBADqC,MAAM,CACjB;AAC1B,mGAAmG;AACnG,0BADyF,MAAM,CAClE;AAC7B,gGAAgG;AAChG,0BADsF,MAAM,CAC/D;AAC7B,qHAAqH;AACrH,wBAD2G,MAAM,CACtF;AAC3B,mFAAmF;AACnF,yBADyE,MAAM,CACnD;AAC5B,4EAA4E;AAC5E,yBADkE,MAAM,CAC5C;AAC5B,gHAAgH;AAChH,sBADsG,MAAM,CACnF;AACzB,uFAAuF;AACvF,wBAD6E,MAAM,CACvD;AAC5B,8HAA8H;AAC9H,+BADoH,MAAM,CACvF;AACnC,oIAAoI;AACpI,iCAD0H,MAAM,CAC3F;AACrC,2IAA2I;AAC3I,iCADiI,MAAM,CAClG"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared wire-format constants for the general object-graph binary serializer.
|
|
3
|
+
*
|
|
4
|
+
* A document is: `HEADER CLASS_TABLE SHAPE_TABLE BODY`, where BODY is a single self-describing VALUE. Every
|
|
5
|
+
* object/array in the body is assigned an implicit index in first-seen order so later occurrences of the same
|
|
6
|
+
* instance (shared references, cycles) encode as a compact back-reference. Class names and reflective field-name
|
|
7
|
+
* sets ("shapes") are interned into the two prepended tables and referenced by index, so a graph of a thousand
|
|
8
|
+
* same-class objects pays for the class name and field names exactly once.
|
|
9
|
+
*
|
|
10
|
+
* @author Alex Goldring
|
|
11
|
+
* @copyright Company Named Limited (c) 2026
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Magic marker at the head of a document (`'O','3'`). Lets a reader reject a foreign/corrupt stream.
|
|
16
|
+
* @readonly
|
|
17
|
+
* @type {number}
|
|
18
|
+
*/
|
|
19
|
+
export const OBJECT_MAGIC = 0x4F33;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Version of the framing (header + tables + value tags). Independent of any individual class's payload version.
|
|
23
|
+
* @readonly
|
|
24
|
+
* @type {number}
|
|
25
|
+
*/
|
|
26
|
+
export const OBJECT_FORMAT_VERSION = 1;
|
|
27
|
+
|
|
28
|
+
// --- value tags (one byte, first byte of every VALUE) ---
|
|
29
|
+
|
|
30
|
+
/** `null`. @readonly @type {number} */
|
|
31
|
+
export const TAG_NULL = 0;
|
|
32
|
+
/** `undefined`. @readonly @type {number} */
|
|
33
|
+
export const TAG_UNDEFINED = 1;
|
|
34
|
+
/** boolean `false`. @readonly @type {number} */
|
|
35
|
+
export const TAG_FALSE = 2;
|
|
36
|
+
/** boolean `true`. @readonly @type {number} */
|
|
37
|
+
export const TAG_TRUE = 3;
|
|
38
|
+
/** non-negative integer that fits a varint; followed by `uvar(value)`. @readonly @type {number} */
|
|
39
|
+
export const TAG_POS_INT = 4;
|
|
40
|
+
/** negative integer that fits a varint; followed by `uvar(-value)`. @readonly @type {number} */
|
|
41
|
+
export const TAG_NEG_INT = 5;
|
|
42
|
+
/** any other number (float, NaN, Infinity, out-of-range integer); followed by `float64`. @readonly @type {number} */
|
|
43
|
+
export const TAG_FLOAT = 6;
|
|
44
|
+
/** string; followed by a length-prefixed UTF-8 string. @readonly @type {number} */
|
|
45
|
+
export const TAG_STRING = 7;
|
|
46
|
+
/** bigint; followed by its base-10 string form. @readonly @type {number} */
|
|
47
|
+
export const TAG_BIGINT = 8;
|
|
48
|
+
/** back-reference to an already-seen object/array; followed by `uvar(objectIndex)`. @readonly @type {number} */
|
|
49
|
+
export const TAG_REF = 9;
|
|
50
|
+
/** array; followed by `uvar(length)` then `length` VALUEs. @readonly @type {number} */
|
|
51
|
+
export const TAG_ARRAY = 10;
|
|
52
|
+
/** plain object (reconstructed as `{}`); followed by `uvar(shapeIndex)` then one VALUE per field. @readonly @type {number} */
|
|
53
|
+
export const TAG_PLAIN_OBJECT = 11;
|
|
54
|
+
/** reflective class instance; followed by `uvar(classIndex) uvar(shapeIndex)` then one VALUE per field. @readonly @type {number} */
|
|
55
|
+
export const TAG_REFLECT_OBJECT = 12;
|
|
56
|
+
/** class instance serialized by a registered adapter; followed by `uvar(classIndex)` then the adapter payload. @readonly @type {number} */
|
|
57
|
+
export const TAG_ADAPTER_OBJECT = 13;
|