@bloopjs/web 0.0.79 → 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.
@@ -1 +1 @@
1
- {"version":3,"file":"scaffold.d.ts","sourceRoot":"","sources":["../../src/netcode/scaffold.ts"],"names":[],"mappings":"AAAA,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,CAqJN"}
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.79",
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.79",
37
- "@bloopjs/engine": "0.0.79",
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/App.ts CHANGED
@@ -20,7 +20,7 @@ export type StartOptions = {
20
20
  /** A pre-mounted sim instance, defaults to mount with default options */
21
21
  sim?: Sim;
22
22
  /** An override url to use to fetch the engine wasm */
23
- engineWasmUrl?: URL;
23
+ wasmUrl?: URL;
24
24
  /** Whether the sim should pause before running the first frame, defaults to false */
25
25
  startPaused?: boolean;
26
26
  /** Whether the sim should be recording to tape from initialization, defaults to true */
@@ -38,7 +38,7 @@ export async function start(opts: StartOptions): Promise<App> {
38
38
  if (!opts.sim) {
39
39
  const { sim } = await mount(opts.game, {
40
40
  startRecording: opts.startRecording ?? true,
41
- wasmUrl: opts.engineWasmUrl,
41
+ wasmUrl: opts.wasmUrl,
42
42
  });
43
43
  opts.sim = sim;
44
44
  }
@@ -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.net.receivePacket(packetData);
44
+ app.sim.emit.packet(packetData);
44
45
 
45
46
  if (remotePeerId == null) {
46
47
  return;
47
48
  }
48
49
 
49
- const peerState = app.sim.net.getPeerState(remotePeerId);
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.net.getOutboundPacket(remotePeerId);
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.net.disconnectPeer(remotePeerId);
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.net.setLocalPeer(localPeerId);
127
- app.sim.net.connectPeer(remotePeerId);
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.net.disconnectPeer(remotePeerId);
152
+ app.sim.emit.network("peer:leave", { peerId: remotePeerId });
150
153
  sessionActive = false;
151
154
  opts?.onSessionEnd?.();
152
155
  }