@bloopjs/web 0.0.62 → 0.0.64
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 +28 -37
- package/dist/mod.js.map +4 -4
- package/package.json +3 -3
package/dist/mod.js
CHANGED
|
@@ -87,6 +87,7 @@ __export2(exports_engine, {
|
|
|
87
87
|
MouseContext: () => MouseContext,
|
|
88
88
|
MOUSE_OFFSET: () => MOUSE_OFFSET,
|
|
89
89
|
MOUSE_BUTTONS_OFFSET: () => MOUSE_BUTTONS_OFFSET,
|
|
90
|
+
MAX_ROLLBACK_FRAMES: () => MAX_ROLLBACK_FRAMES,
|
|
90
91
|
MAX_PLAYERS: () => MAX_PLAYERS,
|
|
91
92
|
KeyboardContext: () => KeyboardContext,
|
|
92
93
|
KEYBOARD_SIZE: () => KEYBOARD_SIZE,
|
|
@@ -1129,50 +1130,50 @@ class KeyboardContext {
|
|
|
1129
1130
|
}
|
|
1130
1131
|
}
|
|
1131
1132
|
|
|
1132
|
-
class
|
|
1133
|
+
class NetContext {
|
|
1133
1134
|
dataView;
|
|
1134
1135
|
constructor(dataView) {
|
|
1135
1136
|
this.dataView = dataView;
|
|
1136
1137
|
}
|
|
1137
|
-
get
|
|
1138
|
+
get peerCount() {
|
|
1138
1139
|
if (!this.dataView) {
|
|
1139
|
-
throw new Error("
|
|
1140
|
+
throw new Error("NetContext DataView is not initialized");
|
|
1140
1141
|
}
|
|
1141
|
-
return this.dataView.
|
|
1142
|
+
return this.dataView.getUint8(0);
|
|
1142
1143
|
}
|
|
1143
|
-
get
|
|
1144
|
-
|
|
1145
|
-
throw new Error("TimeContext DataView is not initialized");
|
|
1146
|
-
}
|
|
1147
|
-
return this.dataView.getUint32(4, true) / 1000;
|
|
1144
|
+
get isInSession() {
|
|
1145
|
+
return this.peerCount > 0;
|
|
1148
1146
|
}
|
|
1149
|
-
get
|
|
1147
|
+
get matchFrame() {
|
|
1150
1148
|
if (!this.dataView) {
|
|
1151
|
-
throw new Error("
|
|
1149
|
+
throw new Error("NetContext DataView is not initialized");
|
|
1152
1150
|
}
|
|
1153
|
-
return this.dataView.getUint32(
|
|
1151
|
+
return this.dataView.getUint32(4, true);
|
|
1154
1152
|
}
|
|
1155
1153
|
}
|
|
1156
1154
|
|
|
1157
|
-
class
|
|
1155
|
+
class TimeContext {
|
|
1158
1156
|
dataView;
|
|
1159
1157
|
constructor(dataView) {
|
|
1160
1158
|
this.dataView = dataView;
|
|
1161
1159
|
}
|
|
1162
|
-
get
|
|
1160
|
+
get frame() {
|
|
1163
1161
|
if (!this.dataView) {
|
|
1164
|
-
throw new Error("
|
|
1162
|
+
throw new Error("TimeContext DataView is not initialized");
|
|
1165
1163
|
}
|
|
1166
|
-
return this.dataView.
|
|
1164
|
+
return this.dataView.getUint32(0, true);
|
|
1167
1165
|
}
|
|
1168
|
-
get
|
|
1169
|
-
|
|
1166
|
+
get dt() {
|
|
1167
|
+
if (!this.dataView) {
|
|
1168
|
+
throw new Error("TimeContext DataView is not initialized");
|
|
1169
|
+
}
|
|
1170
|
+
return this.dataView.getUint32(4, true) / 1000;
|
|
1170
1171
|
}
|
|
1171
|
-
get
|
|
1172
|
+
get time() {
|
|
1172
1173
|
if (!this.dataView) {
|
|
1173
|
-
throw new Error("
|
|
1174
|
+
throw new Error("TimeContext DataView is not initialized");
|
|
1174
1175
|
}
|
|
1175
|
-
return this.dataView.getUint32(
|
|
1176
|
+
return this.dataView.getUint32(8, true) / 1000;
|
|
1176
1177
|
}
|
|
1177
1178
|
}
|
|
1178
1179
|
var TAPE_MAGIC = 1413566533;
|
|
@@ -1191,6 +1192,7 @@ function readTapeHeader(tape) {
|
|
|
1191
1192
|
};
|
|
1192
1193
|
}
|
|
1193
1194
|
var DEFAULT_WASM_URL = new URL("../wasm/bloop.wasm", import.meta.url);
|
|
1195
|
+
var MAX_ROLLBACK_FRAMES = 500;
|
|
1194
1196
|
var TIME_CTX_OFFSET = 0;
|
|
1195
1197
|
var INPUT_CTX_OFFSET = TIME_CTX_OFFSET + 4;
|
|
1196
1198
|
var EVENTS_OFFSET = INPUT_CTX_OFFSET + 4;
|
|
@@ -1292,7 +1294,9 @@ class Sim {
|
|
|
1292
1294
|
this.wasm.tick();
|
|
1293
1295
|
}
|
|
1294
1296
|
cloneSession(source) {
|
|
1295
|
-
|
|
1297
|
+
if (source.isRecording) {
|
|
1298
|
+
this.loadTape(source.saveTape());
|
|
1299
|
+
}
|
|
1296
1300
|
this.restore(source.snapshot());
|
|
1297
1301
|
}
|
|
1298
1302
|
pause() {
|
|
@@ -1338,7 +1342,7 @@ class Sim {
|
|
|
1338
1342
|
return copy;
|
|
1339
1343
|
}
|
|
1340
1344
|
static NETWORK_MAX_PACKET_BYTES = 2 * 1024 * 1024;
|
|
1341
|
-
record(maxEvents, maxPacketBytes) {
|
|
1345
|
+
record(maxEvents = 1024, maxPacketBytes = Sim.NETWORK_MAX_PACKET_BYTES) {
|
|
1342
1346
|
const serializer = this.#serialize ? this.#serialize() : null;
|
|
1343
1347
|
const size = serializer ? serializer.size : 0;
|
|
1344
1348
|
const result = this.wasm.start_recording(size, maxEvents, maxPacketBytes);
|
|
@@ -1422,19 +1426,6 @@ class Sim {
|
|
|
1422
1426
|
sessionEnd() {
|
|
1423
1427
|
this.wasm.session_end();
|
|
1424
1428
|
}
|
|
1425
|
-
emitInputs(peer, matchFrame, events) {
|
|
1426
|
-
if (events.length === 0) {
|
|
1427
|
-
this.wasm.session_emit_inputs(peer, matchFrame, 0, 0);
|
|
1428
|
-
return;
|
|
1429
|
-
}
|
|
1430
|
-
const ptr = this.wasm.alloc(events.byteLength);
|
|
1431
|
-
assert(ptr > 0, `failed to allocate ${events.byteLength} bytes for events`);
|
|
1432
|
-
const memoryView = new Uint8Array(this.buffer, ptr, events.byteLength);
|
|
1433
|
-
memoryView.set(events);
|
|
1434
|
-
const eventCount = events.byteLength / 12;
|
|
1435
|
-
this.wasm.session_emit_inputs(peer, matchFrame, ptr, eventCount);
|
|
1436
|
-
this.wasm.free(ptr, events.byteLength);
|
|
1437
|
-
}
|
|
1438
1429
|
}
|
|
1439
1430
|
async function mount(opts, options) {
|
|
1440
1431
|
const wasmUrl = options?.wasmUrl ?? opts.wasmUrl ?? DEFAULT_WASM_URL;
|
|
@@ -6318,5 +6309,5 @@ export {
|
|
|
6318
6309
|
App
|
|
6319
6310
|
};
|
|
6320
6311
|
|
|
6321
|
-
//# debugId=
|
|
6312
|
+
//# debugId=138F12AC7B53936064756E2164756E21
|
|
6322
6313
|
//# sourceMappingURL=mod.js.map
|