@bloopjs/web 0.0.80 → 0.0.81
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.
- package/dist/mod.js +489 -96
- package/dist/mod.js.map +5 -5
- package/dist/netcode/scaffold.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/netcode/scaffold.ts +13 -10
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scaffold.d.ts","sourceRoot":"","sources":["../../src/netcode/scaffold.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"scaffold.d.ts","sourceRoot":"","sources":["../../src/netcode/scaffold.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAIrC,MAAM,MAAM,uBAAuB,GAAG;IACpC,yCAAyC;IACzC,cAAc,CAAC,EAAE,MAAM,IAAI,CAAC;IAC5B,+BAA+B;IAC/B,YAAY,CAAC,EAAE,MAAM,IAAI,CAAC;CAC3B,CAAC;AAEF;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,GAAG,EACR,IAAI,CAAC,EAAE,uBAAuB,GAC7B,IAAI,CAuJN"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bloopjs/web",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.81",
|
|
4
4
|
"author": "Neil Sarkar",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
"typescript": "^5"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@bloopjs/bloop": "0.0.
|
|
37
|
-
"@bloopjs/engine": "0.0.
|
|
36
|
+
"@bloopjs/bloop": "0.0.81",
|
|
37
|
+
"@bloopjs/engine": "0.0.81",
|
|
38
38
|
"@preact/signals": "^1.3.1",
|
|
39
39
|
"partysocket": "^1.1.6",
|
|
40
40
|
"preact": "^10.25.4"
|
package/src/netcode/scaffold.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { unwrap } from "@bloopjs/bloop";
|
|
1
2
|
import type { App } from "../App.ts";
|
|
2
3
|
import * as Debug from "../debugui/mod.ts";
|
|
3
4
|
import { logger } from "./logs.ts";
|
|
@@ -40,13 +41,16 @@ export function joinRollbackRoom(
|
|
|
40
41
|
|
|
41
42
|
function receivePackets() {
|
|
42
43
|
for (const packetData of incomingPackets) {
|
|
43
|
-
app.sim.
|
|
44
|
+
app.sim.emit.packet(packetData);
|
|
44
45
|
|
|
45
46
|
if (remotePeerId == null) {
|
|
46
47
|
return;
|
|
47
48
|
}
|
|
48
49
|
|
|
49
|
-
const peerState =
|
|
50
|
+
const peerState = unwrap(
|
|
51
|
+
app.sim.net.peers[remotePeerId],
|
|
52
|
+
`Remote peer state not found for peerId ${remotePeerId}`,
|
|
53
|
+
);
|
|
50
54
|
Debug.updatePeer(remoteStringPeerId!, {
|
|
51
55
|
ack: peerState.ack,
|
|
52
56
|
seq: peerState.seq,
|
|
@@ -70,7 +74,7 @@ export function joinRollbackRoom(
|
|
|
70
74
|
return;
|
|
71
75
|
}
|
|
72
76
|
|
|
73
|
-
const packet = app.sim.
|
|
77
|
+
const packet = app.sim.getOutboundPacket(remotePeerId);
|
|
74
78
|
|
|
75
79
|
if (!packet) {
|
|
76
80
|
console.warn("[netcode] No packet to send");
|
|
@@ -97,7 +101,7 @@ export function joinRollbackRoom(
|
|
|
97
101
|
onDataChannelClose(peerId, reliable) {
|
|
98
102
|
console.log(`Data channel closed: ${peerId} (reliable: ${reliable})`);
|
|
99
103
|
if (!reliable && remotePeerId !== null) {
|
|
100
|
-
app.sim.
|
|
104
|
+
app.sim.emit.network("peer:leave", { peerId: remotePeerId });
|
|
101
105
|
sessionActive = false;
|
|
102
106
|
opts?.onSessionEnd?.();
|
|
103
107
|
}
|
|
@@ -119,12 +123,11 @@ export function joinRollbackRoom(
|
|
|
119
123
|
remoteStringPeerId = peerId;
|
|
120
124
|
Debug.setRemoteId(remotePeerId);
|
|
121
125
|
|
|
122
|
-
// Initialize the session in the engine (2 players)
|
|
123
|
-
app.sim.sessionInit(2);
|
|
124
|
-
|
|
125
126
|
// Set up local and remote peers in net state
|
|
126
|
-
app.sim.
|
|
127
|
-
app.sim.
|
|
127
|
+
app.sim.emit.network("peer:join", { peerId: localPeerId });
|
|
128
|
+
app.sim.emit.network("peer:join", { peerId: remotePeerId });
|
|
129
|
+
app.sim.emit.network("peer:assign_local_id", { peerId: localPeerId });
|
|
130
|
+
app.sim.emit.network("session:start", {});
|
|
128
131
|
|
|
129
132
|
sessionActive = true;
|
|
130
133
|
console.log(`[netcode] Session started at frame ${app.sim.time.frame}`);
|
|
@@ -146,7 +149,7 @@ export function joinRollbackRoom(
|
|
|
146
149
|
onPeerDisconnected(peerId) {
|
|
147
150
|
Debug.removePeer(peerId);
|
|
148
151
|
if (remotePeerId !== null && peerId === remoteStringPeerId) {
|
|
149
|
-
app.sim.
|
|
152
|
+
app.sim.emit.network("peer:leave", { peerId: remotePeerId });
|
|
150
153
|
sessionActive = false;
|
|
151
154
|
opts?.onSessionEnd?.();
|
|
152
155
|
}
|