Skip to content

Commit 68c19e6

Browse files
authored
Multiplayer Fixes [AARD-2105] (#1296)
2 parents 8e72603 + 4222ebc commit 68c19e6

File tree

10 files changed

+181
-124
lines changed

10 files changed

+181
-124
lines changed

fission/src/mirabuf/MirabufSceneObject.ts

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import * as THREE from "three"
33
import type { mirabuf } from "@/proto/mirabuf"
44
import type {
55
FieldConfiguration,
6-
MetadataUpdateData,
6+
LocalSceneObjectId,
7+
RemoteSceneObjectId,
78
RobotConfiguration,
89
UpdateObjectData,
910
} from "@/systems/multiplayer/types"
@@ -118,19 +119,6 @@ class MirabufSceneObject extends SceneObject implements ContextSupplier {
118119

119120
private _collision?: (event: OnContactAddedEvent) => void
120121

121-
public get multiplayerInfo(): MetadataUpdateData {
122-
return {
123-
sceneObjectKey: this.id,
124-
alliance: this._alliance,
125-
station: this._station,
126-
}
127-
}
128-
129-
public set multiplayerInfo(info: MetadataUpdateData) {
130-
this._alliance = info.alliance
131-
this._station = info.station
132-
}
133-
134122
public get scoringZones(): Readonly<ScoringZoneSceneObject[]> {
135123
return this._scoringZones
136124
}
@@ -242,10 +230,16 @@ class MirabufSceneObject extends SceneObject implements ContextSupplier {
242230
this._station = station
243231
}
244232

245-
public constructor(mirabufInstance: MirabufInstance, assemblyName: string, progressHandle?: ProgressHandle) {
233+
public constructor(
234+
mirabufInstance: MirabufInstance,
235+
assemblyName: string,
236+
progressHandle?: ProgressHandle,
237+
multiplayerOwnerId?: string
238+
) {
246239
super()
247240
this._mirabufInstance = mirabufInstance
248241
this._assemblyName = assemblyName
242+
this._multiplayerOwningClientId = multiplayerOwnerId
249243

250244
progressHandle?.update("Creating mechanism...", 0.9)
251245

@@ -343,7 +337,9 @@ class MirabufSceneObject extends SceneObject implements ContextSupplier {
343337
this.updateScoringZones()
344338
this.updateProtectedZones()
345339

346-
setSpotlightAssembly(this)
340+
if (this.isOwnObject) {
341+
setSpotlightAssembly(this)
342+
}
347343

348344
this.updateBatches()
349345

@@ -353,7 +349,7 @@ class MirabufSceneObject extends SceneObject implements ContextSupplier {
353349

354350
const cameraControls = World.sceneRenderer.currentCameraControls as CustomOrbitControls
355351

356-
if (this.miraType === MiraType.ROBOT || !cameraControls.focusProvider) {
352+
if (this.isOwnObject && (this.miraType === MiraType.ROBOT || !cameraControls.focusProvider)) {
357353
cameraControls.focusProvider = this
358354
}
359355

@@ -848,12 +844,12 @@ class MirabufSceneObject extends SceneObject implements ContextSupplier {
848844

849845
public async sendPreferences() {
850846
if (!World.multiplayerSystem) return
851-
847+
const data = this.getPreferenceData()
852848
await World.multiplayerSystem.broadcast({
853849
type: "configureObject",
854850
data: {
855-
sceneObjectKey: this.id,
856-
objectConfigurationData: this.getPreferenceData(),
851+
sceneObjectKey: this.id as RemoteSceneObjectId,
852+
objectConfigurationData: data,
857853
},
858854
})
859855
}
@@ -896,20 +892,25 @@ class MirabufSceneObject extends SceneObject implements ContextSupplier {
896892
: {
897893
intakePreferences: JSON.stringify(this._intakePreferences),
898894
ejectorPreferences: JSON.stringify(this._ejectorPreferences),
895+
alliance: this._alliance,
896+
station: this.station,
899897
}
900898
}
901899

902900
public setPreferenceData(preferences: FieldConfiguration | RobotConfiguration) {
903901
if (this.miraType === MiraType.FIELD) {
904902
const config = preferences as FieldConfiguration
905903
this._fieldPreferences = JSON.parse(config.fieldPreferences)
906-
// this.updateScoringZones()
907-
// this.updateProtectedZones()
908904
} else {
909905
const config = preferences as RobotConfiguration
910906
this._intakePreferences = JSON.parse(config.intakePreferences)
911907
this._ejectorPreferences = JSON.parse(config.ejectorPreferences)
908+
this._alliance = config.alliance
909+
this._station = config.station
912910
}
911+
this.updateScoringZones()
912+
this.updateProtectedZones()
913+
this.updateIntakeSensor()
913914
}
914915

915916
public updateSimConfig(config: SimConfigData | undefined) {
@@ -923,8 +924,8 @@ class MirabufSceneObject extends SceneObject implements ContextSupplier {
923924
}
924925

925926
public enablePhysics() {
926-
if (World.multiplayerSystem?.getOwnSceneObjectIDs().includes(this.id)) {
927-
World.multiplayerSystem.broadcast({ type: "enableObjectPhysics", data: this.id })
927+
if (World.multiplayerSystem?.getOwnSceneObjectIDs().includes(this.id as LocalSceneObjectId)) {
928+
World.multiplayerSystem.broadcast({ type: "enableObjectPhysics", data: this.id as RemoteSceneObjectId })
928929
}
929930

930931
this._mirabufInstance.parser.rigidNodes.forEach(rn => {
@@ -934,8 +935,8 @@ class MirabufSceneObject extends SceneObject implements ContextSupplier {
934935
}
935936

936937
public disablePhysics() {
937-
if (World.multiplayerSystem?.getOwnSceneObjectIDs().includes(this.id)) {
938-
World.multiplayerSystem.broadcast({ type: "disableObjectPhysics", data: this.id })
938+
if (World.multiplayerSystem?.getOwnSceneObjectIDs().includes(this.id as LocalSceneObjectId)) {
939+
World.multiplayerSystem.broadcast({ type: "disableObjectPhysics", data: this.id as RemoteSceneObjectId })
939940
}
940941

941942
this._mirabufInstance.parser.rigidNodes.forEach(rn => {
@@ -1034,7 +1035,6 @@ class MirabufSceneObject extends SceneObject implements ContextSupplier {
10341035
data.items.push({
10351036
name: "Remove",
10361037
func: () => {
1037-
World.multiplayerSystem?.broadcast({ type: "deleteObject", data: this.id })
10381038
World.sceneRenderer.removeSceneObject(this.id)
10391039
},
10401040
})
@@ -1063,7 +1063,7 @@ class MirabufSceneObject extends SceneObject implements ContextSupplier {
10631063
.filter(n => n != null)
10641064

10651065
return {
1066-
sceneObjectKey: this.id,
1066+
sceneObjectKey: this.id as RemoteSceneObjectId,
10671067
gamePiecesControlled,
10681068
bodies,
10691069
}
@@ -1088,15 +1088,16 @@ class MirabufSceneObject extends SceneObject implements ContextSupplier {
10881088

10891089
export async function createMirabuf(
10901090
assembly: mirabuf.Assembly,
1091-
progressHandle?: ProgressHandle
1091+
progressHandle?: ProgressHandle,
1092+
multiplayerOwnerId?: string
10921093
): Promise<MirabufSceneObject | null | undefined> {
10931094
const parser = new MirabufParser(assembly, progressHandle)
10941095
if (parser.maxErrorSeverity >= ParseErrorSeverity.UNIMPORTABLE) {
10951096
console.error(`Assembly Parser produced significant errors for '${assembly.info!.name!}'`)
10961097
return
10971098
}
10981099

1099-
return new MirabufSceneObject(new MirabufInstance(parser), assembly.info!.name!, progressHandle)
1100+
return new MirabufSceneObject(new MirabufInstance(parser), assembly.info!.name!, progressHandle, multiplayerOwnerId)
11001101
}
11011102

11021103
/**

0 commit comments

Comments
 (0)