Skip to content

Commit

Permalink
rename
Browse files Browse the repository at this point in the history
  • Loading branch information
ClementPasteau committed May 24, 2024
1 parent dd933ab commit cba1076
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 28 deletions.
14 changes: 1 addition & 13 deletions Extensions/Multiplayer/messageManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,6 @@ namespace gdjs {
);
objectOwnershipChangeMessageNames.forEach((messageName) => {
if (gdjs.evtTools.p2p.onEvent(messageName, false)) {
// TODO: Catch, log error and ignore to avoid to crash the game.
let data;
try {
data = JSON.parse(gdjs.evtTools.p2p.getEventData(messageName));
Expand All @@ -392,7 +391,6 @@ namespace gdjs {
return;
}
const messageSender = gdjs.evtTools.p2p.getEventSender(messageName);
logger.info(`Received message ${messageName} with data ${data}.`);
if (data) {
const matches = changeOwnerMessageNameRegex.exec(messageName);
if (!matches) {
Expand Down Expand Up @@ -1221,6 +1219,7 @@ namespace gdjs {

const handleSceneUpdatedMessages = (runtimeScene: gdjs.RuntimeScene) => {
if (gdjs.multiplayer.isPlayerHost()) {
// Only other players need to update their scene.
return;
}

Expand Down Expand Up @@ -1361,9 +1360,6 @@ namespace gdjs {
for (const playerNumber in _playersLastHeartbeatInfo) {
playersPings[playerNumber] = getPlayerPing(parseInt(playerNumber, 10));
}
logger.info(
'Sending heartbeat message with pings ' + JSON.stringify(playersPings)
);
return {
messageName: `${heartbeatMessageNamePrefix}#${gdjs.multiplayer.getPlayerNumber()}`,
messageData: {
Expand Down Expand Up @@ -1421,11 +1417,6 @@ namespace gdjs {

// If we are not the host, save what the host told us about the pings.
if (!gdjs.multiplayer.isPlayerHost()) {
logger.info(
`Received heartbeat from player ${playerNumber} with pings ${JSON.stringify(
data.playersPings
)}.`
);
// If one player is missing from the heartbeat, it means they have disconnected.
const missingPlayerNumbers = Object.keys(_playersPings).filter(
(playerNumber) => data.playersPings[playerNumber] === undefined
Expand All @@ -1444,9 +1435,6 @@ namespace gdjs {
// If we are the host, compute the pings.
const now = data.now;
const timeDifference = Math.round(Date.now() - now);
logger.info(
`Received heartbeat from player ${playerNumber} with time difference of ${timeDifference}ms.`
);
const playerLastHeartbeatInfo =
_playersLastHeartbeatInfo[playerNumber] || {};
const playerLastHeartbeatDurations =
Expand Down
10 changes: 6 additions & 4 deletions Extensions/Multiplayer/multiplayerobjectruntimebehavior.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace gdjs {
// The number of times per second the variables should be synchronized.
_variablesTickRate: number = 1;
// The last data sent to synchronize the variables.
_lastSentVariableSyncData: VariableSyncData[] | undefined;
_lastSentVariableSyncData: VariableNetworkSyncData[] | undefined;
// When we know that the variables have been updated, we can force sending them
// on the same tickrate as the object update for a number of times
// to ensure they are received, without the need of an acknowledgment.
Expand All @@ -50,7 +50,7 @@ namespace gdjs {
_effectsTickRate: number = 1;
// The last data sent to synchronize the effects.
_lastSentEffectSyncData:
| { [effectName: string]: EffectSyncData }
| { [effectName: string]: EffectNetworkSyncData }
| undefined;
// When we know that the effects have been updated, we can force sending them
// on the same tickrate as the object update for a number of times
Expand Down Expand Up @@ -183,7 +183,9 @@ namespace gdjs {
return haveBasicObjectNetworkSyncDataChanged;
}

areVariablesDifferentFromLastSync(variablesSyncData: VariableSyncData[]) {
areVariablesDifferentFromLastSync(
variablesSyncData: VariableNetworkSyncData[]
) {
if (!this._lastSentVariableSyncData) {
return true;
}
Expand All @@ -198,7 +200,7 @@ namespace gdjs {
}

areEffectsDifferentFromLastSync(effectsSyncData: {
[effectName: string]: EffectSyncData;
[effectName: string]: EffectNetworkSyncData;
}) {
if (!this._lastSentEffectSyncData) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ namespace gdjs {
};
}

updateFromNetworkSyncData(networkSyncData: BehaviorSyncData): void {
updateFromNetworkSyncData(networkSyncData: BehaviorNetworkSyncData): void {
super.updateFromNetworkSyncData(networkSyncData);

const behaviorSpecificProps = networkSyncData.props;
Expand Down
4 changes: 2 additions & 2 deletions GDJS/Runtime/runtimebehavior.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ namespace gdjs {
return false;
}

getNetworkSyncData(): BehaviorSyncData {
getNetworkSyncData(): BehaviorNetworkSyncData {
// To be redefined by behaviors that need to synchronize properties
// while calling super() to get the common properties.
return {
Expand All @@ -86,7 +86,7 @@ namespace gdjs {
* Update the behavior properties using the provided data.
* @param networkSyncData The new properties of the behavior.
*/
updateFromNetworkSyncData(networkSyncData: BehaviorSyncData): void {
updateFromNetworkSyncData(networkSyncData: BehaviorNetworkSyncData): void {
// Must be redefined by behaviors that need to synchronize properties
// while calling super() to get the common properties.
if (networkSyncData.act !== this._activated) {
Expand Down
16 changes: 8 additions & 8 deletions GDJS/Runtime/types/project-data.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ declare interface ObjectNetworkSyncData extends BasicObjectNetworkSyncData {
[behaviorName: string]: any;
};
/** The variables of the object */
var?: VariableSyncData[];
var?: VariableNetworkSyncData[];
/** The effects of the object */
eff?: {
[effectName: string]: EffectSyncData;
[effectName: string]: EffectNetworkSyncData;
};
/** The timers of the object */
tim?: {
Expand Down Expand Up @@ -110,10 +110,10 @@ declare type VariableData = Readonly<{
/** A variable child of a container. Those always have a name. */
declare type RootVariableData = Omit<VariableData, 'name'> & { name: string };

declare type VariableSyncData = {
declare type VariableNetworkSyncData = {
name: string;
value: string | float | boolean;
children?: VariableSyncData[];
children?: VariableNetworkSyncData[];
type: VariableType;
};

Expand All @@ -125,7 +125,7 @@ declare type BehaviorData = {
type: string;
};

declare type BehaviorSyncData = {
declare type BehaviorNetworkSyncData = {
act: boolean;
props: any;
};
Expand Down Expand Up @@ -154,11 +154,11 @@ declare interface LayoutData {
}

declare interface LayoutNetworkSyncData {
var?: VariableSyncData[];
var?: VariableNetworkSyncData[];
}

declare interface GameNetworkSyncData {
var?: VariableSyncData[];
var?: VariableNetworkSyncData[];
}

declare interface EventsFunctionsExtensionData {
Expand Down Expand Up @@ -259,7 +259,7 @@ declare interface EffectData {
};
}

declare interface EffectSyncData {
declare interface EffectNetworkSyncData {
ena: boolean;
fc: {
[name: string]: any;
Expand Down

0 comments on commit cba1076

Please sign in to comment.