Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
b9b2b6a
first commit
NeylMahfouf2608 Mar 10, 2025
824ef94
TOFIX
NeylMahfouf2608 Mar 11, 2025
806e759
psuh for save
NeylMahfouf2608 Mar 13, 2025
4d6719a
WIP working version with saving on localstorage
NeylMahfouf2608 Mar 24, 2025
91eb239
Update Model3DRuntimeObject.ts
NeylMahfouf2608 Mar 24, 2025
1365d10
updated all runtimesobjects to have syncOptions, moved loading logic…
NeylMahfouf2608 Apr 8, 2025
751f71c
Update multiplayerobjectruntimebehavior.ts
NeylMahfouf2608 Apr 8, 2025
fd9331c
Update after clement comments on pr. Fixed several missed points and …
NeylMahfouf2608 Apr 9, 2025
d48b55c
last small details for concept (still needs support for expression ma…
NeylMahfouf2608 Apr 9, 2025
9b00761
Update PhysicsCharacter3DRuntimeBehavior.ts
NeylMahfouf2608 Apr 9, 2025
9e2bd6d
added a try catch for indexeDB opening
NeylMahfouf2608 Apr 9, 2025
15a6e97
wip soundManager management in save/load
NeylMahfouf2608 Apr 14, 2025
83bd850
fix soundManager save/load
NeylMahfouf2608 Apr 14, 2025
ace65de
small update (abort tween management)
NeylMahfouf2608 Apr 16, 2025
d5c4558
final functionnal commit to review
NeylMahfouf2608 Apr 17, 2025
8606b25
Update howler-sound-manager.ts
NeylMahfouf2608 Apr 17, 2025
8ac201c
Update howler-sound-manager.ts
NeylMahfouf2608 Apr 17, 2025
0f140c6
Update scenestack.ts
NeylMahfouf2608 Apr 17, 2025
cbc9975
Update scenestack.ts
NeylMahfouf2608 Apr 17, 2025
0860551
created loadRequestOptions type + added security and consistency on i…
NeylMahfouf2608 Apr 18, 2025
026f496
updated loadRequest signature and loading system in scenestack
NeylMahfouf2608 Apr 18, 2025
5f74967
fixed confusion between constants + added nullification for _loadRequ…
NeylMahfouf2608 Apr 18, 2025
1f3e8cd
forgot format
NeylMahfouf2608 Apr 18, 2025
082e7d2
[NOT WORKING] fixed variable null object misconception in savestate f…
NeylMahfouf2608 Apr 18, 2025
5ed0abd
Update scenestack.ts
NeylMahfouf2608 Apr 18, 2025
7711ea8
forced "syncOptions" parameter existence, repaired normalized value t…
NeylMahfouf2608 Apr 23, 2025
0b1f3b7
2 exemples for demonstrating the simplicity of the system
NeylMahfouf2608 Apr 23, 2025
7efb701
Improve naming and typing
AlexandreSi Apr 29, 2025
78adaa6
Refactor loading logic
AlexandreSi Apr 29, 2025
31d9ff4
Use array maps to simplify code reading
AlexandreSi Apr 29, 2025
8be1d93
Update comment
AlexandreSi Apr 30, 2025
9b76c5c
Prevent losing control when loading save
AlexandreSi Apr 30, 2025
03dec17
Split responsibility into different booleans
AlexandreSi Apr 30, 2025
ac691a7
Rename instructions and parameters
AlexandreSi Apr 30, 2025
c06a5d4
Simplify logic
AlexandreSi Apr 30, 2025
f13feaa
Add TODOs
AlexandreSi Apr 30, 2025
a01507a
Use const variable
AlexandreSi Apr 30, 2025
aeeab60
Store data as a JS object
AlexandreSi Apr 30, 2025
20203d8
WIP: Support saving and restoring tweens
AlexandreSi Apr 30, 2025
049058e
Create tween setter factory
AlexandreSi May 2, 2025
c652778
Prettier
AlexandreSi May 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions Extensions/3D/A_RuntimeObject3D.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ namespace gdjs {
type Object3DNetworkSyncDataType = {
// z is position on the Z axis, different from zo, which is Z order
z: number;
w: number;
h: number;
d: number;
rx: number;
ry: number;
Expand Down Expand Up @@ -112,12 +110,12 @@ namespace gdjs {
return true;
}

getNetworkSyncData(): Object3DNetworkSyncData {
getNetworkSyncData(
syncOptions: GetNetworkSyncDataOptions
): Object3DNetworkSyncData {
return {
...super.getNetworkSyncData(),
...super.getNetworkSyncData(syncOptions),
z: this.getZ(),
w: this.getWidth(),
h: this.getHeight(),
d: this.getDepth(),
rx: this.getRotationX(),
ry: this.getRotationY(),
Expand All @@ -127,11 +125,12 @@ namespace gdjs {
};
}

updateFromNetworkSyncData(networkSyncData: Object3DNetworkSyncData) {
super.updateFromNetworkSyncData(networkSyncData);
updateFromNetworkSyncData(
networkSyncData: Object3DNetworkSyncData,
options: UpdateFromNetworkSyncDataOptions
) {
super.updateFromNetworkSyncData(networkSyncData, options);
if (networkSyncData.z !== undefined) this.setZ(networkSyncData.z);
if (networkSyncData.w !== undefined) this.setWidth(networkSyncData.w);
if (networkSyncData.h !== undefined) this.setHeight(networkSyncData.h);
if (networkSyncData.d !== undefined) this.setDepth(networkSyncData.d);
if (networkSyncData.rx !== undefined)
this.setRotationX(networkSyncData.rx);
Expand Down
11 changes: 7 additions & 4 deletions Extensions/3D/Cube3DRuntimeObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -434,9 +434,11 @@ namespace gdjs {
return true;
}

getNetworkSyncData(): Cube3DObjectNetworkSyncData {
getNetworkSyncData(
syncOptions: GetNetworkSyncDataOptions
): Cube3DObjectNetworkSyncData {
return {
...super.getNetworkSyncData(),
...super.getNetworkSyncData(syncOptions),
mt: this._materialType,
fo: this._facesOrientation,
bfu: this._backFaceUpThroughWhichAxisRotation,
Expand All @@ -448,9 +450,10 @@ namespace gdjs {
}

updateFromNetworkSyncData(
networkSyncData: Cube3DObjectNetworkSyncData
networkSyncData: Cube3DObjectNetworkSyncData,
options: UpdateFromNetworkSyncDataOptions
): void {
super.updateFromNetworkSyncData(networkSyncData);
super.updateFromNetworkSyncData(networkSyncData, options);

if (networkSyncData.mt !== undefined) {
this._materialType = networkSyncData.mt;
Expand Down
35 changes: 35 additions & 0 deletions Extensions/3D/CustomRuntimeObject3D.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
namespace gdjs {
type CustomObject3DNetworkSyncDataType = CustomObjectNetworkSyncDataType & {
z: float;
d: float;
rx: float;
ry: float;
ifz: boolean;
};

/**
* Base class for 3D custom objects.
*/
Expand Down Expand Up @@ -78,6 +86,33 @@ namespace gdjs {
}
}

getNetworkSyncData(
syncOptions: GetNetworkSyncDataOptions
): CustomObject3DNetworkSyncDataType {
return {
...super.getNetworkSyncData(syncOptions),
z: this.getZ(),
d: this.getDepth(),
rx: this.getRotationX(),
ry: this.getRotationY(),
ifz: this.isFlippedZ(),
};
}

updateFromNetworkSyncData(
networkSyncData: CustomObject3DNetworkSyncDataType,
options: UpdateFromNetworkSyncDataOptions
): void {
super.updateFromNetworkSyncData(networkSyncData, options);
if (networkSyncData.z !== undefined) this.setZ(networkSyncData.z);
if (networkSyncData.d !== undefined) this.setDepth(networkSyncData.d);
if (networkSyncData.rx !== undefined)
this.setRotationX(networkSyncData.rx);
if (networkSyncData.ry !== undefined)
this.setRotationY(networkSyncData.ry);
if (networkSyncData.ifz !== undefined) this.flipZ(networkSyncData.ifz);
}

/**
* Set the object position on the Z axis.
*/
Expand Down
16 changes: 12 additions & 4 deletions Extensions/3D/Model3DRuntimeObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace gdjs {
/** The base parameters of the Model3D object */
content: Object3DDataContent & {
modelResourceName: string;
depth: number;
rotationX: number;
rotationY: number;
rotationZ: number;
Expand Down Expand Up @@ -198,9 +199,11 @@ namespace gdjs {
return true;
}

getNetworkSyncData(): Model3DObjectNetworkSyncData {
getNetworkSyncData(
syncOptions: GetNetworkSyncDataOptions
): Model3DObjectNetworkSyncData {
return {
...super.getNetworkSyncData(),
...super.getNetworkSyncData(syncOptions),
mt: this._materialType,
op: this._originPoint,
cp: this._centerPoint,
Expand All @@ -209,13 +212,15 @@ namespace gdjs {
ass: this._animationSpeedScale,
ap: this._animationPaused,
cfd: this._crossfadeDuration,
d: this.getDepth(),
};
}

updateFromNetworkSyncData(
networkSyncData: Model3DObjectNetworkSyncData
networkSyncData: Model3DObjectNetworkSyncData,
options: UpdateFromNetworkSyncDataOptions
): void {
super.updateFromNetworkSyncData(networkSyncData);
super.updateFromNetworkSyncData(networkSyncData, options);

if (networkSyncData.mt !== undefined) {
this._materialType = networkSyncData.mt;
Expand Down Expand Up @@ -243,6 +248,9 @@ namespace gdjs {
if (networkSyncData.cfd !== undefined) {
this._crossfadeDuration = networkSyncData.cfd;
}
if (networkSyncData.d !== undefined) {
this.setDepth(networkSyncData.d);
}
Comment on lines +251 to +253
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this already done by RuntimeObject3D?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed it should, I don't think we need that, the super() call should handle it.

}

_reloadModel(objectData: Model3DObjectData) {
Expand Down
11 changes: 7 additions & 4 deletions Extensions/BBText/bbtextruntimeobject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,11 @@ namespace gdjs {
return true;
}

override getNetworkSyncData(): BBTextObjectNetworkSyncData {
override getNetworkSyncData(
syncOptions: GetNetworkSyncDataOptions
): BBTextObjectNetworkSyncData {
return {
...super.getNetworkSyncData(),
...super.getNetworkSyncData(syncOptions),
text: this._text,
o: this._opacity,
c: this._color,
Expand All @@ -162,9 +164,10 @@ namespace gdjs {
}

override updateFromNetworkSyncData(
networkSyncData: BBTextObjectNetworkSyncData
networkSyncData: BBTextObjectNetworkSyncData,
options: UpdateFromNetworkSyncDataOptions
): void {
super.updateFromNetworkSyncData(networkSyncData);
super.updateFromNetworkSyncData(networkSyncData, options);
if (this._text !== undefined) {
this.setBBText(networkSyncData.text);
}
Expand Down
11 changes: 7 additions & 4 deletions Extensions/BitmapText/bitmaptextruntimeobject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,11 @@ namespace gdjs {
return true;
}

override getNetworkSyncData(): BitmapTextObjectNetworkSyncData {
override getNetworkSyncData(
syncOptions: GetNetworkSyncDataOptions
): BitmapTextObjectNetworkSyncData {
return {
...super.getNetworkSyncData(),
...super.getNetworkSyncData(syncOptions),
text: this._text,
opa: this._opacity,
tint: this._tint,
Expand All @@ -172,9 +174,10 @@ namespace gdjs {
}

override updateFromNetworkSyncData(
networkSyncData: BitmapTextObjectNetworkSyncData
networkSyncData: BitmapTextObjectNetworkSyncData,
options: UpdateFromNetworkSyncDataOptions
): void {
super.updateFromNetworkSyncData(networkSyncData);
super.updateFromNetworkSyncData(networkSyncData, options);
if (this._text !== undefined) {
this.setText(networkSyncData.text);
}
Expand Down
13 changes: 9 additions & 4 deletions Extensions/Lighting/lightruntimeobject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,21 @@ namespace gdjs {
return true;
}

getNetworkSyncData(): LightNetworkSyncData {
getNetworkSyncData(
syncOptions: GetNetworkSyncDataOptions
): LightNetworkSyncData {
return {
...super.getNetworkSyncData(),
...super.getNetworkSyncData(syncOptions),
rad: this.getRadius(),
col: this.getColor(),
};
}

updateFromNetworkSyncData(networkSyncData: LightNetworkSyncData): void {
super.updateFromNetworkSyncData(networkSyncData);
updateFromNetworkSyncData(
networkSyncData: LightNetworkSyncData,
options: UpdateFromNetworkSyncDataOptions
): void {
super.updateFromNetworkSyncData(networkSyncData, options);

if (networkSyncData.rad !== undefined) {
this.setRadius(networkSyncData.rad);
Expand Down
12 changes: 7 additions & 5 deletions Extensions/Multiplayer/messageManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,9 @@ namespace gdjs {
behavior.playerNumber = ownerPlayerNumber;
}

instance.updateFromNetworkSyncData(messageData);
instance.updateFromNetworkSyncData(messageData, {
clearMemory: false,
});

setLastClockReceivedForInstanceOnScene({
sceneNetworkId,
Expand Down Expand Up @@ -1737,7 +1739,7 @@ namespace gdjs {
return;
}

runtimeScene.updateFromNetworkSyncData(messageData);
runtimeScene.updateFromNetworkSyncData(messageData, {});
} else {
// If the game is not ready to receive game update messages, we need to save the data for later use.
// This can happen when joining a game that is already running.
Expand Down Expand Up @@ -1890,7 +1892,7 @@ namespace gdjs {
const messageData = message.getData();
const messageSender = message.getSender();
if (gdjs.multiplayer.isReadyToSendOrReceiveGameUpdateMessages()) {
runtimeScene.getGame().updateFromNetworkSyncData(messageData);
runtimeScene.getGame().updateFromNetworkSyncData(messageData, {});
} else {
// If the game is not ready to receive game update messages, we need to save the data for later use.
// This can happen when joining a game that is already running.
Expand Down Expand Up @@ -1918,7 +1920,7 @@ namespace gdjs {
// Reapply the game saved updates.
lastReceivedGameSyncDataUpdates.getUpdates().forEach((messageData) => {
debugLogger.info(`Reapplying saved update of game.`);
runtimeScene.getGame().updateFromNetworkSyncData(messageData);
runtimeScene.getGame().updateFromNetworkSyncData(messageData, {});
});
// Game updates are always applied properly, so we can clear them.
lastReceivedGameSyncDataUpdates.clear();
Expand All @@ -1937,7 +1939,7 @@ namespace gdjs {

debugLogger.info(`Reapplying saved update of scene ${sceneNetworkId}.`);

runtimeScene.updateFromNetworkSyncData(messageData);
runtimeScene.updateFromNetworkSyncData(messageData, {});
// We only remove the message if it was successfully applied, so it can be reapplied later,
// in case we were not on the right scene.
lastReceivedSceneSyncDataUpdates.remove(messageData);
Expand Down
18 changes: 15 additions & 3 deletions Extensions/Multiplayer/multiplayerobjectruntimebehavior.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,9 @@ namespace gdjs {

const instanceNetworkId = this._getOrCreateInstanceNetworkId();
const objectName = this.owner.getName();
const objectNetworkSyncData = this.owner.getNetworkSyncData();
const objectNetworkSyncData = this.owner.getNetworkSyncData({
forceSyncEverything: false,
});

// this._logToConsoleWithThrottle(
// `Synchronizing object ${this.owner.getName()} (instance ${
Expand All @@ -293,13 +295,16 @@ namespace gdjs {
x: objectNetworkSyncData.x,
y: objectNetworkSyncData.y,
z: objectNetworkSyncData.z,
w: objectNetworkSyncData.w,
h: objectNetworkSyncData.h,
zo: objectNetworkSyncData.zo,
a: objectNetworkSyncData.a,
hid: objectNetworkSyncData.hid,
lay: objectNetworkSyncData.lay,
if: objectNetworkSyncData.if,
pfx: objectNetworkSyncData.pfx,
pfy: objectNetworkSyncData.pfy,
n: objectNetworkSyncData.n,
});
const shouldSyncObjectBasicInfo =
!this._hasObjectBasicInfoBeenSyncedRecently() ||
Expand Down Expand Up @@ -369,13 +374,16 @@ namespace gdjs {
this._lastSentBasicObjectSyncData = {
x: objectNetworkSyncData.x,
y: objectNetworkSyncData.y,
w: objectNetworkSyncData.w,
h: objectNetworkSyncData.h,
zo: objectNetworkSyncData.zo,
a: objectNetworkSyncData.a,
hid: objectNetworkSyncData.hid,
lay: objectNetworkSyncData.lay,
if: objectNetworkSyncData.if,
pfx: objectNetworkSyncData.pfx,
pfy: objectNetworkSyncData.pfy,
n: objectNetworkSyncData.n,
};
this._numberOfForcedBasicObjectUpdates = Math.max(
this._numberOfForcedBasicObjectUpdates - 1,
Expand Down Expand Up @@ -443,7 +451,9 @@ namespace gdjs {
objectOwner: this.playerNumber,
objectName,
instanceNetworkId,
objectNetworkSyncData: this.owner.getNetworkSyncData(),
objectNetworkSyncData: this.owner.getNetworkSyncData({
forceSyncEverything: false,
}),
sceneNetworkId,
});
this._sendDataToPeersWithIncreasedClock(
Expand Down Expand Up @@ -593,7 +603,9 @@ namespace gdjs {
debugLogger.info(
'Sending update message to move the object immediately.'
);
const objectNetworkSyncData = this.owner.getNetworkSyncData();
const objectNetworkSyncData = this.owner.getNetworkSyncData({
forceSyncEverything: false,
});
const {
messageName: updateMessageName,
messageData: updateMessageData,
Expand Down
Loading