@@ -14,24 +14,27 @@ export interface BinaryNodeData {
1414 nodeId : number ;
1515 position : Vec3 ;
1616 velocity : Vec3 ;
17- // SSSP data removed - now fetched via REST API when needed
18- // This reduces binary message size from 34 to 26 bytes per node
17+ ssspDistance : number ; // Shortest path distance from source
18+ ssspParent : number ; // Parent node for path reconstruction
1919}
2020
2121/**
22- * Node binary format (Optimized ):
23- * - Node ID: 4 bytes (uint32 ) - full node ID without flags
22+ * Node binary format (Updated to match server ):
23+ * - Node ID: 2 bytes (uint16 ) - optimized size
2424 * - Position: 12 bytes (3 float32 values)
2525 * - Velocity: 12 bytes (3 float32 values)
26- * Total: 28 bytes per node (reduced from 34)
26+ * - SSSP Distance: 4 bytes (float32)
27+ * - SSSP Parent: 4 bytes (int32)
28+ * Total: 34 bytes per node
2729 *
28- * SSSP and other analytics data are fetched via REST API when needed
30+ * SSSP data is included for real-time path visualization
2931 */
30- export const BINARY_NODE_SIZE = 28 ;
32+ export const BINARY_NODE_SIZE = 34 ;
3133export const BINARY_NODE_ID_OFFSET = 0 ;
32- export const BINARY_POSITION_OFFSET = 4 ;
33- export const BINARY_VELOCITY_OFFSET = 16 ;
34- // SSSP offsets removed - data no longer in binary protocol
34+ export const BINARY_POSITION_OFFSET = 2 ; // After uint16 node ID
35+ export const BINARY_VELOCITY_OFFSET = 14 ; // After position (2 + 12)
36+ export const BINARY_SSSP_DISTANCE_OFFSET = 26 ; // After velocity (14 + 12)
37+ export const BINARY_SSSP_PARENT_OFFSET = 30 ; // After distance (26 + 4)
3538
3639// Node type flag constants (must match server) - adjusted for u16
3740export const AGENT_NODE_FLAG = 0x8000 ; // Bit 15 indicates agent node
@@ -107,24 +110,28 @@ export function parseBinaryNodeData(buffer: ArrayBuffer): BinaryNodeData[] {
107110 break ;
108111 }
109112
110- // Read node ID (uint32, 4 bytes) - no flags needed anymore
111- const nodeId = view . getUint32 ( offset + BINARY_NODE_ID_OFFSET , true ) ;
113+ // Read node ID (uint16, 2 bytes)
114+ const nodeId = view . getUint16 ( offset + BINARY_NODE_ID_OFFSET , true ) ;
112115
113116 // Read position (3 float32 values, 12 bytes)
114117 const position : Vec3 = {
115118 x : view . getFloat32 ( offset + BINARY_POSITION_OFFSET , true ) ,
116119 y : view . getFloat32 ( offset + BINARY_POSITION_OFFSET + 4 , true ) ,
117120 z : view . getFloat32 ( offset + BINARY_POSITION_OFFSET + 8 , true )
118121 } ;
119-
122+
120123 // Read velocity (3 float32 values, 12 bytes)
121124 const velocity : Vec3 = {
122125 x : view . getFloat32 ( offset + BINARY_VELOCITY_OFFSET , true ) ,
123126 y : view . getFloat32 ( offset + BINARY_VELOCITY_OFFSET + 4 , true ) ,
124127 z : view . getFloat32 ( offset + BINARY_VELOCITY_OFFSET + 8 , true )
125128 } ;
126129
127- // SSSP data removed - fetched via REST API when needed
130+ // Read SSSP distance (float32, 4 bytes)
131+ const ssspDistance = view . getFloat32 ( offset + BINARY_SSSP_DISTANCE_OFFSET , true ) ;
132+
133+ // Read SSSP parent (int32, 4 bytes)
134+ const ssspParent = view . getInt32 ( offset + BINARY_SSSP_PARENT_OFFSET , true ) ;
128135
129136 // Basic validation to detect corrupted data
130137 const isValid =
@@ -136,7 +143,7 @@ export function parseBinaryNodeData(buffer: ArrayBuffer): BinaryNodeData[] {
136143 ! isNaN ( velocity . z ) && isFinite ( velocity . z ) ;
137144
138145 if ( isValid ) {
139- nodes . push ( { nodeId, position, velocity } ) ;
146+ nodes . push ( { nodeId, position, velocity, ssspDistance , ssspParent } ) ;
140147 } else {
141148 console . warn ( `Skipping corrupted node data at offset ${ offset } (nodeId: ${ nodeId } )` ) ;
142149 }
@@ -158,15 +165,15 @@ export function createBinaryNodeData(nodes: BinaryNodeData[]): ArrayBuffer {
158165
159166 nodes . forEach ( ( node , i ) => {
160167 const offset = i * BINARY_NODE_SIZE ;
161-
168+
162169 // Write node ID (uint16, 2 bytes)
163170 view . setUint16 ( offset + BINARY_NODE_ID_OFFSET , node . nodeId , true ) ;
164-
171+
165172 // Write position (3 float32 values, 12 bytes)
166173 view . setFloat32 ( offset + BINARY_POSITION_OFFSET , node . position . x , true ) ;
167174 view . setFloat32 ( offset + BINARY_POSITION_OFFSET + 4 , node . position . y , true ) ;
168175 view . setFloat32 ( offset + BINARY_POSITION_OFFSET + 8 , node . position . z , true ) ;
169-
176+
170177 // Write velocity (3 float32 values, 12 bytes)
171178 view . setFloat32 ( offset + BINARY_VELOCITY_OFFSET , node . velocity . x , true ) ;
172179 view . setFloat32 ( offset + BINARY_VELOCITY_OFFSET + 4 , node . velocity . y , true ) ;
0 commit comments