@@ -9,7 +9,7 @@ import PreferencesSystem from "@/systems/preferences/PreferencesSystem.ts"
9
9
import type PhysicsSystem from "../physics/PhysicsSystem"
10
10
import World from "../World"
11
11
import { peerMessageHandlers } from "./MessageHandlers"
12
- import type { ClientInfo , EncodedAssembly , Message , MessageType } from "./types"
12
+ import type { ClientInfo , InitObjectData , Message , MessageType } from "./types"
13
13
import Jolt from "@azaleacolburn/jolt-physics"
14
14
15
15
export const COLLISION_TIMEOUT = 500
@@ -157,11 +157,17 @@ class MultiplayerSystem {
157
157
158
158
// Called by the host, initializes the world with some defined set of objects, robots can be spawned in later
159
159
async initWorld ( physicsSystem : PhysicsSystem ) {
160
- const sceneObjects = World . sceneRenderer . mirabufSceneObjects
161
- . getAll ( )
162
- . map ( sceneObject =>
163
- mirabuf . Assembly . encode ( sceneObject . mirabufInstance . parser . assembly ) . finish ( )
164
- ) as EncodedAssembly [ ]
160
+ const sceneObjects : InitObjectData [ ] = await Promise . all (
161
+ World . sceneRenderer . mirabufSceneObjects . getAll ( ) . map ( async sceneObject => ( {
162
+ sceneObjectKey : sceneObject . id ,
163
+ assemblyHash : await MirabufCachingService . hashBuffer (
164
+ mirabuf . Assembly . encode ( sceneObject . mirabufInstance . parser . assembly ) . finish ( ) . buffer as ArrayBuffer
165
+ ) ,
166
+ miraType : sceneObject . miraType ,
167
+ initialPreferences : sceneObject . getPreferenceData ( ) ,
168
+ bodyIds : sceneObject . getAllBodyIds ( ) . map ( id => id . GetIndexAndSequenceNumber ( ) ) ,
169
+ } ) )
170
+ )
165
171
166
172
await this . broadcast ( {
167
173
type : "init" ,
@@ -179,23 +185,25 @@ class MultiplayerSystem {
179
185
this . _connections . set ( conn . peer , conn )
180
186
MultiplayerStateEvent . dispatch ( MultiplayerStateEventType . PEER_CHANGE )
181
187
await this . send ( conn . peer , { type : "info" , data : this . info } )
182
- for ( const objectId of this . getOwnSceneObjectIDs ( ) ) {
183
- const obj = World . sceneRenderer . sceneObjects . get ( objectId )
184
- if ( ! ( obj instanceof MirabufSceneObject ) ) return
185
- const hash = await MirabufCachingService . hashBuffer (
186
- mirabuf . Assembly . encode ( obj . mirabufInstance . parser . assembly ) . finish ( )
187
- )
188
- await this . send ( conn . peer , {
189
- type : "newObject" ,
190
- data : {
191
- sceneObjectKey : objectId ,
192
- assemblyHash : hash ,
193
- miraType : obj . miraType ,
194
- initialPreferences : obj . getPreferenceData ( ) ,
195
- } ,
196
- } )
197
- await this . send ( conn . peer , { type : "metadataUpdate" , data : obj . multiplayerInfo } )
198
- }
188
+ // I don't think this is necessary if we just move the call to initWorld
189
+ // for (const objectId of this.getOwnSceneObjectIDs()) {
190
+ // const obj = World.sceneRenderer.sceneObjects.get(objectId)
191
+ // if (!(obj instanceof MirabufSceneObject)) return
192
+ // const hash = await MirabufCachingService.hashBuffer(
193
+ // mirabuf.Assembly.encode(obj.mirabufInstance.parser.assembly).finish().buffer as ArrayBuffer
194
+ // )
195
+ // await this.send(conn.peer, {
196
+ // type: "newObject",
197
+ // data: {
198
+ // sceneObjectKey: objectId,
199
+ // assemblyHash: hash,
200
+ // miraType: obj.miraType,
201
+ // initialPreferences: obj.getPreferenceData(),
202
+ // bodyIds: obj.getAllBodies(),
203
+ // },
204
+ // })
205
+ // await this.send(conn.peer, { type: "metadataUpdate", data: obj.multiplayerInfo })
206
+ // }
199
207
} )
200
208
201
209
conn . on ( "data" , async ( data : unknown ) => {
0 commit comments