@@ -241,43 +241,74 @@ class MultiplayerSystem {
241
241
}
242
242
243
243
handlePeerUpdate ( data : UpdateObjectData [ ] ) {
244
- data . forEach ( ( { sceneObjectKey, linearVelocityStr, angularVelocityStr, positionStr, rotationStr } ) => {
245
- // const rootBody: Jolt.Body = JSON.parse(encodedRootBody)
246
- const lin : { x : number ; y : number ; z : number } = JSON . parse ( linearVelocityStr )
247
- const ang : { x : number ; y : number ; z : number } = JSON . parse ( angularVelocityStr )
248
- const pos : { x : number ; y : number ; z : number } = JSON . parse ( positionStr )
249
- const rot : { x : number ; y : number ; z : number ; w : number } = JSON . parse ( rotationStr )
250
-
251
- const linearVelocity = new JOLT . Vec3 ( lin . x , lin . y , lin . z )
252
- const angularVelocity = new JOLT . Vec3 ( ang . x , ang . y , ang . z )
253
- const position = new JOLT . RVec3 ( pos . x , pos . y , pos . z )
254
- const rotation = new JOLT . Quat ( rot . x , rot . y , rot . z , rot . w )
255
-
256
- const sceneObject = World . sceneRenderer . sceneObjects . get ( sceneObjectKey )
257
- if ( sceneObject == null ) {
258
- console . error (
259
- `Multiplayer SceneObject: ${ sceneObjectKey } not found in sceneObjects map. Multiplayer SceneObjects must be initialized before being updated.`
260
- )
261
- return
262
- } else if ( ! ( sceneObject instanceof MirabufSceneObject ) ) {
263
- console . error ( `Multiplayer SceneObject: ${ sceneObjectKey } not MirabufSceneObject` )
264
- console . log ( sceneObject )
265
- return
266
- }
244
+ data . forEach (
245
+ ( {
246
+ sceneObjectKey,
247
+ gamePiecesControlled,
248
+ linearVelocityStr,
249
+ angularVelocityStr,
250
+ positionStr,
251
+ rotationStr,
252
+ } ) => {
253
+ // const rootBody: Jolt.Body = JSON.parse(encodedRootBody)
254
+ const lin : { x : number ; y : number ; z : number } = JSON . parse ( linearVelocityStr )
255
+ const ang : { x : number ; y : number ; z : number } = JSON . parse ( angularVelocityStr )
256
+ const pos : { x : number ; y : number ; z : number } = JSON . parse ( positionStr )
257
+ const rot : { x : number ; y : number ; z : number ; w : number } = JSON . parse ( rotationStr )
258
+
259
+ const linearVelocity = new JOLT . Vec3 ( lin . x , lin . y , lin . z )
260
+ const angularVelocity = new JOLT . Vec3 ( ang . x , ang . y , ang . z )
261
+ const position = new JOLT . RVec3 ( pos . x , pos . y , pos . z )
262
+ const rotation = new JOLT . Quat ( rot . x , rot . y , rot . z , rot . w )
263
+
264
+ const sceneObject = World . sceneRenderer . sceneObjects . get ( sceneObjectKey )
265
+ if ( sceneObject == null ) {
266
+ console . error (
267
+ `Multiplayer SceneObject: ${ sceneObjectKey } not found in sceneObjects map. Multiplayer SceneObjects must be initialized before being updated.`
268
+ )
269
+ return
270
+ } else if ( ! ( sceneObject instanceof MirabufSceneObject ) ) {
271
+ console . error ( `Multiplayer SceneObject: ${ sceneObjectKey } not MirabufSceneObject` )
272
+ console . log ( sceneObject )
273
+ return
274
+ }
267
275
268
- const clientMechanism = sceneObject . mechanism
269
- const clientBodyId = clientMechanism . nodeToBody . get ( clientMechanism . rootBody )
270
- if ( ! clientBodyId ) {
271
- console . error ( `Body not found` )
272
- return
273
- }
276
+ // Set all the ejectables that are in activeEjectables but not gamePiecesControlled
277
+ sceneObject . activeEjectables
278
+ . filter ( id => ! gamePiecesControlled . includes ( id . GetIndexAndSequenceNumber ( ) ) )
279
+ // We're not ejecting the actual game piece here, but the robots should be configured to eject in the same order so it's fine
280
+ . forEach ( _ => sceneObject . eject ( ) )
281
+
282
+ // Set all the ejectables that are in gamePiecesControlled but not activeEjectables
283
+ gamePiecesControlled
284
+ . filter ( id => ! sceneObject . activeEjectables . map ( n => n . GetIndexAndSequenceNumber ( ) ) . includes ( id ) )
285
+ . forEach ( id => {
286
+ const bodyId = new JOLT . BodyID ( id )
287
+ return sceneObject . setEjectable ( bodyId )
288
+ } )
274
289
275
- const clientBody = World . physicsSystem . getBody ( clientBodyId ) !
276
- clientBody . SetLinearVelocity ( linearVelocity )
277
- clientBody . SetAngularVelocity ( angularVelocity )
278
- World . physicsSystem . setBodyPosition ( clientBodyId , position )
279
- World . physicsSystem . setBodyRotation ( clientBodyId , rotation )
280
- } )
290
+ // const piecesSet = gamePiecesControlled.map(id => {
291
+ // const bodyId = new JOLT.BodyID(id)
292
+ // return sceneObject.setEjectable(bodyId)
293
+ // })
294
+ // if (piecesSet.some(success => !success)) {
295
+ // console.error(`Failed to set object(s) as ejectables`)
296
+ // }
297
+
298
+ const clientMechanism = sceneObject . mechanism
299
+ const clientBodyId = clientMechanism . nodeToBody . get ( clientMechanism . rootBody )
300
+ if ( ! clientBodyId ) {
301
+ console . error ( `Body not found` )
302
+ return
303
+ }
304
+
305
+ const clientBody = World . physicsSystem . getBody ( clientBodyId ) !
306
+ clientBody . SetLinearVelocity ( linearVelocity )
307
+ clientBody . SetAngularVelocity ( angularVelocity )
308
+ World . physicsSystem . setBodyPosition ( clientBodyId , position )
309
+ World . physicsSystem . setBodyRotation ( clientBodyId , rotation )
310
+ }
311
+ )
281
312
}
282
313
283
314
handleCollision ( data : CollisionData ) {
0 commit comments