Skip to content

Commit 03dec17

Browse files
committed
Split responsibility into different booleans
1 parent 9b76c5c commit 03dec17

File tree

5 files changed

+27
-16
lines changed

5 files changed

+27
-16
lines changed

GDJS/Runtime/runtimegame.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1391,7 +1391,7 @@ namespace gdjs {
13911391
if (syncData.ss) {
13921392
this._sceneStack.updateFromNetworkSyncData(syncData.ss);
13931393
}
1394-
if (options.clearMemory && syncData.sm) {
1394+
if (options.syncSounds && syncData.sm) {
13951395
this.getSoundManager().updateFromNetworkSyncData(syncData.sm);
13961396
}
13971397
if (syncData.extVar) {

GDJS/Runtime/runtimescene.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,10 @@ namespace gdjs {
127127
*/
128128
loadFromScene(
129129
sceneAndExtensionsData: SceneAndExtensionsData | null,
130-
options?: UpdateFromNetworkSyncDataOptions
130+
options?: {
131+
preventInitialInstancesCreation: boolean;
132+
preventSoundManagerClearing: boolean;
133+
}
131134
) {
132135
if (!sceneAndExtensionsData) {
133136
logger.error('loadFromScene was called without a scene');
@@ -186,7 +189,7 @@ namespace gdjs {
186189
}
187190

188191
// Create initial instances of objects
189-
if (!options || !options.clearMemory)
192+
if (!options || !options.preventInitialInstancesCreation)
190193
this.createObjectsFrom(
191194
sceneData.instances,
192195
0,
@@ -215,7 +218,7 @@ namespace gdjs {
215218
if (
216219
sceneData.stopSoundsOnStartup &&
217220
this._runtimeGame &&
218-
(!options || !options.clearMemory)
221+
(!options || !options.preventSoundManagerClearing)
219222
) {
220223
this._runtimeGame.getSoundManager().clearAll();
221224
}
@@ -885,7 +888,7 @@ namespace gdjs {
885888
}
886889
}
887890
}
888-
if (syncData.timeManager && options.clearMemory) {
891+
if (syncData.timeManager && options.syncTimers) {
889892
this._timeManager.updateFromNetworkSyncData(syncData.timeManager);
890893
}
891894
}

GDJS/Runtime/scenestack.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ namespace gdjs {
3838
const options: UpdateFromNetworkSyncDataOptions = {
3939
clearMemory: true,
4040
keepControl: true,
41+
syncSounds: true,
42+
syncTimers: true,
43+
ignoreVariableOwnership: true,
4144
};
4245

4346
this._runtimeGame.updateFromNetworkSyncData(
@@ -202,40 +205,42 @@ namespace gdjs {
202205
// Avoid a risk of displaying an intermediate loading screen
203206
// during 1 frame.
204207
if (this._runtimeGame.areSceneAssetsReady(newSceneName)) {
205-
return this._loadNewScene(
206-
newSceneName,
207-
options || {},
208-
externalLayoutName
209-
);
208+
return this._loadNewScene(newSceneName, externalLayoutName, options);
210209
}
211210

212211
this._isNextLayoutLoading = true;
213212
this._runtimeGame.loadSceneAssets(newSceneName).then(() => {
214-
this._loadNewScene(newSceneName, options || {}, undefined);
213+
this._loadNewScene(newSceneName, undefined, options);
215214
this._isNextLayoutLoading = false;
216215
});
217216
return null;
218217
}
219218

220219
private _loadNewScene(
221220
newSceneName: string,
222-
options: UpdateFromNetworkSyncDataOptions,
223-
externalLayoutName?: string
221+
externalLayoutName?: string,
222+
options?: UpdateFromNetworkSyncDataOptions
224223
): gdjs.RuntimeScene {
225224
this._throwIfDisposed();
225+
const preventInitialInstancesCreation = !!options;
226+
const preventSoundManagerClearing = !!options;
227+
226228
// Load the new one
227229
const newScene = new gdjs.RuntimeScene(this._runtimeGame);
228230
newScene.loadFromScene(
229231
this._runtimeGame.getSceneAndExtensionsData(newSceneName),
230-
options
232+
{
233+
preventInitialInstancesCreation,
234+
preventSoundManagerClearing,
235+
}
231236
);
232237
this._wasFirstSceneLoaded = true;
233238

234239
// Optionally create the objects from an external layout.
235240
if (externalLayoutName) {
236241
const externalLayoutData =
237242
this._runtimeGame.getExternalLayoutData(externalLayoutName);
238-
if (externalLayoutData && !options.clearMemory) {
243+
if (externalLayoutData && !preventInitialInstancesCreation) {
239244
newScene.createObjectsFrom(
240245
externalLayoutData.instances,
241246
0,

GDJS/Runtime/types/project-data.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ declare type GetNetworkSyncDataOptions = {
4747

4848
declare type UpdateFromNetworkSyncDataOptions = {
4949
clearMemory?: boolean;
50+
syncSounds?: boolean;
51+
syncTimers?: boolean;
5052
keepControl?: boolean;
53+
ignoreVariableOwnership?: boolean;
5154
};
5255

5356
/** Object containing basic properties for all objects synchronizing over the network. */

GDJS/Runtime/variablescontainer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ namespace gdjs {
374374
// - If we are not the owner of the variable, then assume that we missed the ownership change message, so update the variable's
375375
// ownership and then update the variable.
376376
const syncedVariableOwner = variableSyncData.owner;
377-
if (!options.clearMemory) {
377+
if (!options.ignoreVariableOwnership) {
378378
const currentPlayerNumber = gdjs.multiplayer.getCurrentPlayerNumber();
379379

380380
const currentVariableOwner = variable.getPlayerOwnership();

0 commit comments

Comments
 (0)