@antha/multiplayer-p2p-lock-step 0.15.1 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -17,6 +17,14 @@ export type AnthaMultiplayerP2pLockStepState<MultiplayerPacket extends JsonCompa
|
|
|
17
17
|
connectionState: ApiAndRoomConnectionState;
|
|
18
18
|
};
|
|
19
19
|
};
|
|
20
|
+
/**
|
|
21
|
+
* Indicates whether a p2p-lock-step multiplayer room is currently connected.
|
|
22
|
+
*
|
|
23
|
+
* @category Util
|
|
24
|
+
*/
|
|
25
|
+
export declare function isMultiplayerRoomConnected({ multiplayerP2pLockStep, }: Readonly<Partial<SelectFrom<AnthaMultiplayerP2pLockStepState, {
|
|
26
|
+
multiplayerP2pLockStep: true;
|
|
27
|
+
}>>>): boolean;
|
|
20
28
|
/**
|
|
21
29
|
* Options for {@link createAnthaMultiplayerP2pLockStepMod}.
|
|
22
30
|
*
|
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
import { defineAnthaMod } from '@antha/engine';
|
|
2
2
|
import { emptyApiAndRoomConnectionState, MultiplayerControllerConnectionEvent, } from '@antha/multiplayer-core';
|
|
3
3
|
import { log, } from '@augment-vir/common';
|
|
4
|
-
import { P2pLockStepMultiplayerController, } from './p2p-lock-step-multiplayer-controller.js';
|
|
4
|
+
import { MultiplayerControllerFrameEvent, P2pLockStepMultiplayerController, } from './p2p-lock-step-multiplayer-controller.js';
|
|
5
|
+
/**
|
|
6
|
+
* Indicates whether a p2p-lock-step multiplayer room is currently connected.
|
|
7
|
+
*
|
|
8
|
+
* @category Util
|
|
9
|
+
*/
|
|
10
|
+
export function isMultiplayerRoomConnected({ multiplayerP2pLockStep, }) {
|
|
11
|
+
return !!multiplayerP2pLockStep?.multiplayerController.roomId;
|
|
12
|
+
}
|
|
5
13
|
/**
|
|
6
14
|
* Create the engine mod that owns p2p-lock-step multiplayer state.
|
|
7
15
|
*
|
|
@@ -10,7 +18,7 @@ import { P2pLockStepMultiplayerController, } from './p2p-lock-step-multiplayer-c
|
|
|
10
18
|
export function createAnthaMultiplayerP2pLockStepMod(options = {}) {
|
|
11
19
|
return defineAnthaMod({
|
|
12
20
|
modName: 'antha-multiplayer-p2p-lock-step',
|
|
13
|
-
execute({ state }) {
|
|
21
|
+
execute({ engine, state }) {
|
|
14
22
|
if (options.debugMultiplayer == undefined) {
|
|
15
23
|
state.debugMultiplayer = options.debugMultiplayer;
|
|
16
24
|
}
|
|
@@ -32,6 +40,11 @@ export function createAnthaMultiplayerP2pLockStepMod(options = {}) {
|
|
|
32
40
|
log.if(!!state.debugMultiplayer).faint(`[multiplayer] mod connection state updated: api=${String(newConnectionState.api)} room=${String(newConnectionState.room)}`);
|
|
33
41
|
state.multiplayerP2pLockStep.connectionState = newConnectionState;
|
|
34
42
|
});
|
|
43
|
+
state.multiplayerP2pLockStep.multiplayerController.listen(MultiplayerControllerFrameEvent, ({ detail }) => {
|
|
44
|
+
engine.dispatch(new MultiplayerControllerFrameEvent({
|
|
45
|
+
detail,
|
|
46
|
+
}));
|
|
47
|
+
});
|
|
35
48
|
}
|
|
36
49
|
},
|
|
37
50
|
cleanup({ state }) {
|
|
@@ -33,10 +33,13 @@ export type P2pLockStepMessage<MultiplayerPacket extends JsonCompatibleValue> =
|
|
|
33
33
|
actions: MultiplayerPacket[];
|
|
34
34
|
}
|
|
35
35
|
/** Sent from the host to clients when a frame is ready. */
|
|
36
|
-
| {
|
|
36
|
+
| ({
|
|
37
37
|
type: P2pLockStepMessageType.Frame;
|
|
38
38
|
actions: FrameEventDetail<MultiplayerPacket>[];
|
|
39
|
-
}
|
|
39
|
+
} & PartialWithUndefined<{
|
|
40
|
+
/** Whether this frame is meant for syncing a new client. */
|
|
41
|
+
isSynchronizationFrame: boolean;
|
|
42
|
+
}>);
|
|
40
43
|
/**
|
|
41
44
|
* Constructor parameters for {@link P2pLockStepMultiplayerController}.
|
|
42
45
|
*
|
|
@@ -340,6 +340,7 @@ export class P2pLockStepMultiplayerController extends ListenTarget {
|
|
|
340
340
|
this.roomConnection.sendToOnlyOneClient(clientId, {
|
|
341
341
|
type: P2pLockStepMessageType.Frame,
|
|
342
342
|
actions: [],
|
|
343
|
+
isSynchronizationFrame: true,
|
|
343
344
|
});
|
|
344
345
|
}
|
|
345
346
|
}
|
|
@@ -371,7 +372,6 @@ export class P2pLockStepMultiplayerController extends ListenTarget {
|
|
|
371
372
|
this.debugLog(`member received frame with ${message.actions.length} actions; sending ${this.frameActions.length} local actions back to host`);
|
|
372
373
|
const currentFrameActions = this.frameActions;
|
|
373
374
|
this.frameActions = [];
|
|
374
|
-
this.calculateFps();
|
|
375
375
|
this.roomConnection.sendMessage({
|
|
376
376
|
actions: currentFrameActions.map(({ packet }) => {
|
|
377
377
|
return packet;
|
|
@@ -379,9 +379,12 @@ export class P2pLockStepMultiplayerController extends ListenTarget {
|
|
|
379
379
|
sourceClientId: this.clientId,
|
|
380
380
|
type: P2pLockStepMessageType.Actions,
|
|
381
381
|
});
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
382
|
+
if (!message.isSynchronizationFrame) {
|
|
383
|
+
this.calculateFps();
|
|
384
|
+
this.dispatch(new MultiplayerControllerFrameEvent({
|
|
385
|
+
detail: message.actions,
|
|
386
|
+
}));
|
|
387
|
+
}
|
|
385
388
|
}
|
|
386
389
|
}
|
|
387
390
|
/** Recalculate the current data-flow FPS from completed frames. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antha/multiplayer-p2p-lock-step",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"description": "Multiplayer mod for the Antha engine.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vir",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"istanbul-smart-text-reporter": "^1.1.5"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
|
-
"@antha/multiplayer-core": "^0.
|
|
52
|
+
"@antha/multiplayer-core": "^0.17.0"
|
|
53
53
|
},
|
|
54
54
|
"engines": {
|
|
55
55
|
"node": ">=22"
|