@bloopjs/web 0.0.50 → 0.0.51

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 CHANGED
@@ -81,6 +81,8 @@ __export2(exports_engine, {
81
81
  SNAPSHOT_HEADER_ENGINE_LEN_OFFSET: () => SNAPSHOT_HEADER_ENGINE_LEN_OFFSET,
82
82
  PlayerInputContext: () => PlayerInputContext,
83
83
  PLAYER_INPUTS_SIZE: () => PLAYER_INPUTS_SIZE,
84
+ NetContext: () => NetContext,
85
+ NET_CTX_OFFSET: () => NET_CTX_OFFSET,
84
86
  MouseContext: () => MouseContext,
85
87
  MOUSE_OFFSET: () => MOUSE_OFFSET,
86
88
  MOUSE_BUTTONS_OFFSET: () => MOUSE_BUTTONS_OFFSET,
@@ -1145,10 +1147,30 @@ class TimeContext {
1145
1147
  return this.dataView.getUint32(8, true) / 1000;
1146
1148
  }
1147
1149
  }
1150
+
1151
+ class NetContext {
1152
+ dataView;
1153
+ constructor(dataView) {
1154
+ this.dataView = dataView;
1155
+ }
1156
+ get peerCount() {
1157
+ if (!this.dataView) {
1158
+ throw new Error("NetContext DataView is not initialized");
1159
+ }
1160
+ return this.dataView.getUint8(0);
1161
+ }
1162
+ get matchFrame() {
1163
+ if (!this.dataView) {
1164
+ throw new Error("NetContext DataView is not initialized");
1165
+ }
1166
+ return this.dataView.getUint32(4, true);
1167
+ }
1168
+ }
1148
1169
  var DEFAULT_WASM_URL = new URL("../wasm/bloop.wasm", import.meta.url);
1149
1170
  var TIME_CTX_OFFSET = 0;
1150
1171
  var INPUT_CTX_OFFSET = TIME_CTX_OFFSET + 4;
1151
1172
  var EVENTS_OFFSET = INPUT_CTX_OFFSET + 4;
1173
+ var NET_CTX_OFFSET = EVENTS_OFFSET + 4;
1152
1174
  var SNAPSHOT_HEADER_LEN = 16;
1153
1175
  var SNAPSHOT_HEADER_USER_LEN_OFFSET = 4;
1154
1176
  var SNAPSHOT_HEADER_ENGINE_LEN_OFFSET = 8;
@@ -1401,8 +1423,10 @@ async function mount(opts) {
1401
1423
  opts.hooks.setBuffer(memory.buffer);
1402
1424
  opts.hooks.systemsCallback(system_handle, ptr);
1403
1425
  },
1404
- __before_frame: function(frame) {
1426
+ __before_frame: function(ptr, frame) {
1405
1427
  try {
1428
+ opts.hooks.setBuffer(memory.buffer);
1429
+ opts.hooks.setContext(ptr);
1406
1430
  opts.hooks.beforeFrame?.(frame);
1407
1431
  } catch (e) {
1408
1432
  console.error("Error in beforeFrame hook:", e);
@@ -1461,7 +1485,8 @@ class Bloop {
1461
1485
  get players() {
1462
1486
  return inputs.players;
1463
1487
  },
1464
- rawPointer: -1
1488
+ rawPointer: -1,
1489
+ net: new NetContext
1465
1490
  };
1466
1491
  }
1467
1492
  get bag() {
@@ -1508,9 +1533,11 @@ class Bloop {
1508
1533
  const dv = new DataView(this.#engineBuffer, ptr);
1509
1534
  const timeCtxPtr = dv.getUint32(TIME_CTX_OFFSET, true);
1510
1535
  const inputCtxPtr = dv.getUint32(INPUT_CTX_OFFSET, true);
1536
+ const netCtxPtr = dv.getUint32(NET_CTX_OFFSET, true);
1511
1537
  this.#context.rawPointer = ptr;
1512
1538
  this.#context.inputs.dataView = new DataView(this.#engineBuffer, inputCtxPtr);
1513
1539
  this.#context.time.dataView = new DataView(this.#engineBuffer, timeCtxPtr);
1540
+ this.#context.net.dataView = new DataView(this.#engineBuffer, netCtxPtr);
1514
1541
  },
1515
1542
  systemsCallback: (system_handle, ptr) => {
1516
1543
  this.hooks.setContext(ptr);
@@ -2588,6 +2615,7 @@ var DEFAULT_WASM_URL2 = new URL("../wasm/bloop.wasm", import.meta.url);
2588
2615
  var TIME_CTX_OFFSET2 = 0;
2589
2616
  var INPUT_CTX_OFFSET2 = TIME_CTX_OFFSET2 + 4;
2590
2617
  var EVENTS_OFFSET2 = INPUT_CTX_OFFSET2 + 4;
2618
+ var NET_CTX_OFFSET2 = EVENTS_OFFSET2 + 4;
2591
2619
 
2592
2620
  // ../../node_modules/partysocket/dist/chunk-V6LO7DXK.mjs
2593
2621
  if (!globalThis.EventTarget || !globalThis.Event) {
@@ -5105,7 +5133,7 @@ class App {
5105
5133
  }
5106
5134
  this.game.hooks.beforeFrame = (frame) => {
5107
5135
  logger.frameNumber = this.#sim.time.frame;
5108
- logger.matchFrame = this.#sim.wasm.get_match_frame();
5136
+ logger.matchFrame = this.game.context.net.matchFrame;
5109
5137
  this.beforeFrame.notify(frame);
5110
5138
  };
5111
5139
  this.subscribe();
@@ -5403,5 +5431,5 @@ export {
5403
5431
  App
5404
5432
  };
5405
5433
 
5406
- //# debugId=C0F22781B267720E64756E2164756E21
5434
+ //# debugId=9734AFFABAFBA4F864756E2164756E21
5407
5435
  //# sourceMappingURL=mod.js.map