quake2ts 0.0.286 → 0.0.289
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/package.json +1 -1
- package/packages/client/dist/browser/index.global.js +13 -13
- package/packages/client/dist/browser/index.global.js.map +1 -1
- package/packages/client/dist/cjs/index.cjs +669 -79
- package/packages/client/dist/cjs/index.cjs.map +1 -1
- package/packages/client/dist/esm/index.js +669 -79
- package/packages/client/dist/esm/index.js.map +1 -1
- package/packages/client/dist/tsconfig.tsbuildinfo +1 -1
- package/packages/client/dist/types/demo/handler.d.ts +9 -1
- package/packages/client/dist/types/demo/handler.d.ts.map +1 -1
- package/packages/client/dist/types/entities.d.ts +22 -2
- package/packages/client/dist/types/entities.d.ts.map +1 -1
- package/packages/engine/dist/browser/index.global.js +16 -16
- package/packages/engine/dist/browser/index.global.js.map +1 -1
- package/packages/engine/dist/cjs/index.cjs +327 -0
- package/packages/engine/dist/cjs/index.cjs.map +1 -1
- package/packages/engine/dist/esm/index.js +327 -0
- package/packages/engine/dist/esm/index.js.map +1 -1
- package/packages/engine/dist/tsconfig.tsbuildinfo +1 -1
- package/packages/game/dist/browser/index.global.js +3 -3
- package/packages/game/dist/browser/index.global.js.map +1 -1
- package/packages/game/dist/cjs/index.cjs +492 -1
- package/packages/game/dist/cjs/index.cjs.map +1 -1
- package/packages/game/dist/esm/index.js +492 -1
- package/packages/game/dist/esm/index.js.map +1 -1
- package/packages/game/dist/tsconfig.tsbuildinfo +1 -1
- package/packages/server/dist/index.cjs +54 -11
- package/packages/server/dist/index.d.cts +6 -1
- package/packages/server/dist/index.d.ts +6 -1
- package/packages/server/dist/index.js +56 -13
- package/packages/shared/dist/browser/index.global.js +1 -1
- package/packages/shared/dist/browser/index.global.js.map +1 -1
- package/packages/shared/dist/cjs/index.cjs +509 -0
- package/packages/shared/dist/cjs/index.cjs.map +1 -1
- package/packages/shared/dist/esm/index.js +507 -0
- package/packages/shared/dist/esm/index.js.map +1 -1
- package/packages/shared/dist/tsconfig.tsbuildinfo +1 -1
- package/packages/shared/dist/types/net/index.d.ts +1 -0
- package/packages/shared/dist/types/net/index.d.ts.map +1 -1
- package/packages/shared/dist/types/protocol/crc.d.ts +5 -0
- package/packages/shared/dist/types/protocol/crc.d.ts.map +1 -0
- package/packages/shared/dist/types/protocol/index.d.ts +1 -0
- package/packages/shared/dist/types/protocol/index.d.ts.map +1 -1
- package/packages/tools/dist/tsconfig.tsbuildinfo +1 -1
|
@@ -2297,6 +2297,333 @@ var BinaryStream = class {
|
|
|
2297
2297
|
out.z = norm[2];
|
|
2298
2298
|
}
|
|
2299
2299
|
};
|
|
2300
|
+
var BinaryWriter = class {
|
|
2301
|
+
constructor(sizeOrBuffer = 1400) {
|
|
2302
|
+
if (typeof sizeOrBuffer === "number") {
|
|
2303
|
+
this.buffer = new Uint8Array(sizeOrBuffer);
|
|
2304
|
+
this.fixed = false;
|
|
2305
|
+
} else {
|
|
2306
|
+
this.buffer = sizeOrBuffer;
|
|
2307
|
+
this.fixed = true;
|
|
2308
|
+
}
|
|
2309
|
+
this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
|
|
2310
|
+
this.offset = 0;
|
|
2311
|
+
}
|
|
2312
|
+
ensureSpace(bytes) {
|
|
2313
|
+
if (this.offset + bytes > this.buffer.byteLength) {
|
|
2314
|
+
if (this.fixed) {
|
|
2315
|
+
throw new Error(`Buffer overflow: capacity ${this.buffer.byteLength}, needed ${this.offset + bytes}`);
|
|
2316
|
+
}
|
|
2317
|
+
const newSize = Math.max(this.buffer.byteLength * 2, this.offset + bytes);
|
|
2318
|
+
const newBuffer = new Uint8Array(newSize);
|
|
2319
|
+
newBuffer.set(this.buffer);
|
|
2320
|
+
this.buffer = newBuffer;
|
|
2321
|
+
this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
|
|
2322
|
+
}
|
|
2323
|
+
}
|
|
2324
|
+
writeByte(value) {
|
|
2325
|
+
this.ensureSpace(1);
|
|
2326
|
+
this.view.setUint8(this.offset, value);
|
|
2327
|
+
this.offset += 1;
|
|
2328
|
+
}
|
|
2329
|
+
writeChar(value) {
|
|
2330
|
+
this.ensureSpace(1);
|
|
2331
|
+
this.view.setInt8(this.offset, value);
|
|
2332
|
+
this.offset += 1;
|
|
2333
|
+
}
|
|
2334
|
+
writeShort(value) {
|
|
2335
|
+
this.ensureSpace(2);
|
|
2336
|
+
this.view.setInt16(this.offset, value, true);
|
|
2337
|
+
this.offset += 2;
|
|
2338
|
+
}
|
|
2339
|
+
writeLong(value) {
|
|
2340
|
+
this.ensureSpace(4);
|
|
2341
|
+
this.view.setInt32(this.offset, value, true);
|
|
2342
|
+
this.offset += 4;
|
|
2343
|
+
}
|
|
2344
|
+
writeFloat(value) {
|
|
2345
|
+
this.ensureSpace(4);
|
|
2346
|
+
this.view.setFloat32(this.offset, value, true);
|
|
2347
|
+
this.offset += 4;
|
|
2348
|
+
}
|
|
2349
|
+
writeString(value) {
|
|
2350
|
+
const len2 = value.length;
|
|
2351
|
+
this.ensureSpace(len2 + 1);
|
|
2352
|
+
for (let i = 0; i < len2; i++) {
|
|
2353
|
+
this.view.setUint8(this.offset + i, value.charCodeAt(i));
|
|
2354
|
+
}
|
|
2355
|
+
this.view.setUint8(this.offset + len2, 0);
|
|
2356
|
+
this.offset += len2 + 1;
|
|
2357
|
+
}
|
|
2358
|
+
writeCoord(value) {
|
|
2359
|
+
this.writeShort(Math.trunc(value * 8));
|
|
2360
|
+
}
|
|
2361
|
+
writeAngle(value) {
|
|
2362
|
+
this.writeByte(Math.trunc(value * 256 / 360) & 255);
|
|
2363
|
+
}
|
|
2364
|
+
writeAngle16(value) {
|
|
2365
|
+
this.writeShort(Math.trunc(value * 65536 / 360) & 65535);
|
|
2366
|
+
}
|
|
2367
|
+
writePos(pos) {
|
|
2368
|
+
this.writeCoord(pos.x);
|
|
2369
|
+
this.writeCoord(pos.y);
|
|
2370
|
+
this.writeCoord(pos.z);
|
|
2371
|
+
}
|
|
2372
|
+
writeDir(dir) {
|
|
2373
|
+
let maxDot = -1;
|
|
2374
|
+
let bestIndex = 0;
|
|
2375
|
+
if (dir.x === 0 && dir.y === 0 && dir.z === 0) {
|
|
2376
|
+
this.writeByte(0);
|
|
2377
|
+
return;
|
|
2378
|
+
}
|
|
2379
|
+
for (let i = 0; i < ANORMS.length; i++) {
|
|
2380
|
+
const norm = ANORMS[i];
|
|
2381
|
+
const dot2 = dir.x * norm[0] + dir.y * norm[1] + dir.z * norm[2];
|
|
2382
|
+
if (dot2 > maxDot) {
|
|
2383
|
+
maxDot = dot2;
|
|
2384
|
+
bestIndex = i;
|
|
2385
|
+
}
|
|
2386
|
+
}
|
|
2387
|
+
this.writeByte(bestIndex);
|
|
2388
|
+
}
|
|
2389
|
+
getData() {
|
|
2390
|
+
return this.buffer.slice(0, this.offset);
|
|
2391
|
+
}
|
|
2392
|
+
getBuffer() {
|
|
2393
|
+
return this.buffer;
|
|
2394
|
+
}
|
|
2395
|
+
getOffset() {
|
|
2396
|
+
return this.offset;
|
|
2397
|
+
}
|
|
2398
|
+
reset() {
|
|
2399
|
+
this.offset = 0;
|
|
2400
|
+
}
|
|
2401
|
+
};
|
|
2402
|
+
var _NetChan = class _NetChan2 {
|
|
2403
|
+
constructor() {
|
|
2404
|
+
this.qport = 0;
|
|
2405
|
+
this.incomingSequence = 0;
|
|
2406
|
+
this.outgoingSequence = 0;
|
|
2407
|
+
this.incomingAcknowledged = 0;
|
|
2408
|
+
this.incomingReliableAcknowledged = false;
|
|
2409
|
+
this.incomingReliableSequence = 0;
|
|
2410
|
+
this.outgoingReliableSequence = 0;
|
|
2411
|
+
this.reliableLength = 0;
|
|
2412
|
+
this.lastReceived = 0;
|
|
2413
|
+
this.lastSent = 0;
|
|
2414
|
+
this.remoteAddress = null;
|
|
2415
|
+
this.reliableMessage = new BinaryWriter(_NetChan2.MAX_MSGLEN);
|
|
2416
|
+
const now = Date.now();
|
|
2417
|
+
this.lastReceived = now;
|
|
2418
|
+
this.lastSent = now;
|
|
2419
|
+
this.qport = Math.floor(Math.random() * 65536);
|
|
2420
|
+
}
|
|
2421
|
+
/**
|
|
2422
|
+
* Setup the netchan with specific settings
|
|
2423
|
+
*/
|
|
2424
|
+
setup(qport, address = null) {
|
|
2425
|
+
this.qport = qport;
|
|
2426
|
+
this.remoteAddress = address;
|
|
2427
|
+
this.reset();
|
|
2428
|
+
}
|
|
2429
|
+
/**
|
|
2430
|
+
* Reset the netchan state
|
|
2431
|
+
*/
|
|
2432
|
+
reset() {
|
|
2433
|
+
this.incomingSequence = 0;
|
|
2434
|
+
this.outgoingSequence = 0;
|
|
2435
|
+
this.incomingAcknowledged = 0;
|
|
2436
|
+
this.incomingReliableAcknowledged = false;
|
|
2437
|
+
this.incomingReliableSequence = 0;
|
|
2438
|
+
this.outgoingReliableSequence = 0;
|
|
2439
|
+
this.reliableLength = 0;
|
|
2440
|
+
this.reliableMessage.reset();
|
|
2441
|
+
this.lastReceived = Date.now();
|
|
2442
|
+
this.lastSent = Date.now();
|
|
2443
|
+
}
|
|
2444
|
+
/**
|
|
2445
|
+
* Transmits a packet containing reliable and unreliable data
|
|
2446
|
+
*/
|
|
2447
|
+
transmit(unreliableData) {
|
|
2448
|
+
this.outgoingSequence++;
|
|
2449
|
+
this.lastSent = Date.now();
|
|
2450
|
+
const headerSize = _NetChan2.PACKET_HEADER;
|
|
2451
|
+
const reliableSize = this.reliableLength > 0 ? this.reliableLength + 2 : 0;
|
|
2452
|
+
let unreliableSize = unreliableData ? unreliableData.length : 0;
|
|
2453
|
+
if (headerSize + reliableSize + unreliableSize > _NetChan2.MAX_MSGLEN) {
|
|
2454
|
+
unreliableSize = _NetChan2.MAX_MSGLEN - headerSize - reliableSize;
|
|
2455
|
+
if (unreliableSize < 0) unreliableSize = 0;
|
|
2456
|
+
}
|
|
2457
|
+
const buffer = new ArrayBuffer(headerSize + reliableSize + unreliableSize);
|
|
2458
|
+
const view = new DataView(buffer);
|
|
2459
|
+
const result = new Uint8Array(buffer);
|
|
2460
|
+
let sequence = this.outgoingSequence;
|
|
2461
|
+
if (this.reliableLength > 0) {
|
|
2462
|
+
sequence |= 2147483648;
|
|
2463
|
+
if ((this.outgoingReliableSequence & 1) !== 0) {
|
|
2464
|
+
sequence |= 1073741824;
|
|
2465
|
+
}
|
|
2466
|
+
}
|
|
2467
|
+
view.setUint32(0, sequence, true);
|
|
2468
|
+
let ack = this.incomingSequence;
|
|
2469
|
+
if ((this.incomingReliableSequence & 1) !== 0) {
|
|
2470
|
+
ack |= 2147483648;
|
|
2471
|
+
}
|
|
2472
|
+
view.setUint32(4, ack, true);
|
|
2473
|
+
view.setUint16(8, this.qport, true);
|
|
2474
|
+
let offset = headerSize;
|
|
2475
|
+
if (this.reliableLength > 0) {
|
|
2476
|
+
view.setUint16(offset, this.reliableLength, true);
|
|
2477
|
+
offset += 2;
|
|
2478
|
+
const reliableBuffer = this.reliableMessage.getBuffer();
|
|
2479
|
+
const reliableBytes = reliableBuffer.subarray(0, this.reliableLength);
|
|
2480
|
+
result.set(reliableBytes, offset);
|
|
2481
|
+
offset += this.reliableLength;
|
|
2482
|
+
}
|
|
2483
|
+
if (unreliableData && unreliableSize > 0) {
|
|
2484
|
+
const chunk = unreliableData.slice(0, unreliableSize);
|
|
2485
|
+
result.set(chunk, offset);
|
|
2486
|
+
}
|
|
2487
|
+
return result;
|
|
2488
|
+
}
|
|
2489
|
+
/**
|
|
2490
|
+
* Processes a received packet
|
|
2491
|
+
* Returns the payload data (reliable + unreliable) to be processed, or null if discarded
|
|
2492
|
+
*/
|
|
2493
|
+
process(packet) {
|
|
2494
|
+
if (packet.length < _NetChan2.PACKET_HEADER) {
|
|
2495
|
+
return null;
|
|
2496
|
+
}
|
|
2497
|
+
this.lastReceived = Date.now();
|
|
2498
|
+
const view = new DataView(packet.buffer, packet.byteOffset, packet.byteLength);
|
|
2499
|
+
const sequence = view.getUint32(0, true);
|
|
2500
|
+
const ack = view.getUint32(4, true);
|
|
2501
|
+
const qport = view.getUint16(8, true);
|
|
2502
|
+
if (this.qport !== qport) {
|
|
2503
|
+
return null;
|
|
2504
|
+
}
|
|
2505
|
+
const seqNumberClean = sequence & ~(2147483648 | 1073741824);
|
|
2506
|
+
if ((seqNumberClean - this.incomingSequence | 0) <= 0) {
|
|
2507
|
+
return null;
|
|
2508
|
+
}
|
|
2509
|
+
this.incomingSequence = seqNumberClean;
|
|
2510
|
+
const ackNumber = ack & ~2147483648;
|
|
2511
|
+
const ackReliable = (ack & 2147483648) !== 0;
|
|
2512
|
+
if (ackNumber > this.incomingAcknowledged) {
|
|
2513
|
+
this.incomingAcknowledged = ackNumber;
|
|
2514
|
+
}
|
|
2515
|
+
if (this.reliableLength > 0) {
|
|
2516
|
+
const receivedAckBit = ackReliable ? 1 : 0;
|
|
2517
|
+
const currentReliableBit = this.outgoingReliableSequence & 1;
|
|
2518
|
+
if (receivedAckBit !== currentReliableBit) {
|
|
2519
|
+
this.reliableLength = 0;
|
|
2520
|
+
this.reliableMessage.reset();
|
|
2521
|
+
this.outgoingReliableSequence ^= 1;
|
|
2522
|
+
}
|
|
2523
|
+
}
|
|
2524
|
+
const hasReliableData = (sequence & 2147483648) !== 0;
|
|
2525
|
+
const reliableSeqBit = (sequence & 1073741824) !== 0 ? 1 : 0;
|
|
2526
|
+
let payloadOffset = _NetChan2.PACKET_HEADER;
|
|
2527
|
+
let reliableData = null;
|
|
2528
|
+
if (hasReliableData) {
|
|
2529
|
+
if (payloadOffset + 2 > packet.byteLength) return null;
|
|
2530
|
+
const reliableLen = view.getUint16(payloadOffset, true);
|
|
2531
|
+
payloadOffset += 2;
|
|
2532
|
+
const expectedBit = this.incomingReliableSequence & 1;
|
|
2533
|
+
if (reliableSeqBit === expectedBit) {
|
|
2534
|
+
this.incomingReliableSequence++;
|
|
2535
|
+
if (payloadOffset + reliableLen > packet.byteLength) return null;
|
|
2536
|
+
reliableData = packet.slice(payloadOffset, payloadOffset + reliableLen);
|
|
2537
|
+
}
|
|
2538
|
+
payloadOffset += reliableLen;
|
|
2539
|
+
}
|
|
2540
|
+
const unreliableData = packet.slice(payloadOffset);
|
|
2541
|
+
if (reliableData && reliableData.length > 0) {
|
|
2542
|
+
const totalLen = reliableData.length + unreliableData.length;
|
|
2543
|
+
const result = new Uint8Array(totalLen);
|
|
2544
|
+
result.set(reliableData, 0);
|
|
2545
|
+
result.set(unreliableData, reliableData.length);
|
|
2546
|
+
return result;
|
|
2547
|
+
}
|
|
2548
|
+
if (unreliableData) {
|
|
2549
|
+
return unreliableData;
|
|
2550
|
+
}
|
|
2551
|
+
return new Uint8Array(0);
|
|
2552
|
+
}
|
|
2553
|
+
/**
|
|
2554
|
+
* Checks if reliable message buffer is empty and ready for new data
|
|
2555
|
+
*/
|
|
2556
|
+
canSendReliable() {
|
|
2557
|
+
return this.reliableLength === 0;
|
|
2558
|
+
}
|
|
2559
|
+
/**
|
|
2560
|
+
* Writes a byte to the reliable message buffer
|
|
2561
|
+
*/
|
|
2562
|
+
writeReliableByte(value) {
|
|
2563
|
+
if (this.reliableLength + 1 > _NetChan2.MAX_MSGLEN - _NetChan2.HEADER_OVERHEAD) {
|
|
2564
|
+
throw new Error("NetChan reliable buffer overflow");
|
|
2565
|
+
}
|
|
2566
|
+
this.reliableMessage.writeByte(value);
|
|
2567
|
+
this.reliableLength++;
|
|
2568
|
+
}
|
|
2569
|
+
/**
|
|
2570
|
+
* Writes a short to the reliable message buffer
|
|
2571
|
+
*/
|
|
2572
|
+
writeReliableShort(value) {
|
|
2573
|
+
if (this.reliableLength + 2 > _NetChan2.MAX_MSGLEN - _NetChan2.HEADER_OVERHEAD) {
|
|
2574
|
+
throw new Error("NetChan reliable buffer overflow");
|
|
2575
|
+
}
|
|
2576
|
+
this.reliableMessage.writeShort(value);
|
|
2577
|
+
this.reliableLength += 2;
|
|
2578
|
+
}
|
|
2579
|
+
/**
|
|
2580
|
+
* Writes a long to the reliable message buffer
|
|
2581
|
+
*/
|
|
2582
|
+
writeReliableLong(value) {
|
|
2583
|
+
if (this.reliableLength + 4 > _NetChan2.MAX_MSGLEN - _NetChan2.HEADER_OVERHEAD) {
|
|
2584
|
+
throw new Error("NetChan reliable buffer overflow");
|
|
2585
|
+
}
|
|
2586
|
+
this.reliableMessage.writeLong(value);
|
|
2587
|
+
this.reliableLength += 4;
|
|
2588
|
+
}
|
|
2589
|
+
/**
|
|
2590
|
+
* Writes a string to the reliable message buffer
|
|
2591
|
+
*/
|
|
2592
|
+
writeReliableString(value) {
|
|
2593
|
+
const len2 = value.length + 1;
|
|
2594
|
+
if (this.reliableLength + len2 > _NetChan2.MAX_MSGLEN - _NetChan2.HEADER_OVERHEAD) {
|
|
2595
|
+
throw new Error("NetChan reliable buffer overflow");
|
|
2596
|
+
}
|
|
2597
|
+
this.reliableMessage.writeString(value);
|
|
2598
|
+
this.reliableLength += len2;
|
|
2599
|
+
}
|
|
2600
|
+
/**
|
|
2601
|
+
* Returns the current reliable data buffer
|
|
2602
|
+
*/
|
|
2603
|
+
getReliableData() {
|
|
2604
|
+
if (this.reliableLength === 0) {
|
|
2605
|
+
return new Uint8Array(0);
|
|
2606
|
+
}
|
|
2607
|
+
const buffer = this.reliableMessage.getBuffer();
|
|
2608
|
+
return buffer.subarray(0, this.reliableLength);
|
|
2609
|
+
}
|
|
2610
|
+
/**
|
|
2611
|
+
* Checks if we need to send a keepalive packet
|
|
2612
|
+
*/
|
|
2613
|
+
needsKeepalive(currentTime) {
|
|
2614
|
+
return currentTime - this.lastSent > 1e3;
|
|
2615
|
+
}
|
|
2616
|
+
/**
|
|
2617
|
+
* Checks if the connection has timed out
|
|
2618
|
+
*/
|
|
2619
|
+
isTimedOut(currentTime, timeoutMs = 3e4) {
|
|
2620
|
+
return currentTime - this.lastReceived > timeoutMs;
|
|
2621
|
+
}
|
|
2622
|
+
};
|
|
2623
|
+
_NetChan.MAX_MSGLEN = 1400;
|
|
2624
|
+
_NetChan.FRAGMENT_SIZE = 1024;
|
|
2625
|
+
_NetChan.PACKET_HEADER = 10;
|
|
2626
|
+
_NetChan.HEADER_OVERHEAD = _NetChan.PACKET_HEADER + 2;
|
|
2300
2627
|
var AmmoType = /* @__PURE__ */ ((AmmoType22) => {
|
|
2301
2628
|
AmmoType22[AmmoType22["Bullets"] = 0] = "Bullets";
|
|
2302
2629
|
AmmoType22[AmmoType22["Shells"] = 1] = "Shells";
|
|
@@ -8827,7 +9154,7 @@ var BinaryStream2 = class {
|
|
|
8827
9154
|
out.z = norm[2];
|
|
8828
9155
|
}
|
|
8829
9156
|
};
|
|
8830
|
-
var
|
|
9157
|
+
var BinaryWriter2 = class {
|
|
8831
9158
|
constructor(sizeOrBuffer = 1400) {
|
|
8832
9159
|
if (typeof sizeOrBuffer === "number") {
|
|
8833
9160
|
this.buffer = new Uint8Array(sizeOrBuffer);
|
|
@@ -9019,6 +9346,231 @@ var NetworkMessageBuilder = class {
|
|
|
9019
9346
|
this.writeByte(best);
|
|
9020
9347
|
}
|
|
9021
9348
|
};
|
|
9349
|
+
var _NetChan3 = class _NetChan4 {
|
|
9350
|
+
constructor() {
|
|
9351
|
+
this.qport = 0;
|
|
9352
|
+
this.incomingSequence = 0;
|
|
9353
|
+
this.outgoingSequence = 0;
|
|
9354
|
+
this.incomingAcknowledged = 0;
|
|
9355
|
+
this.incomingReliableAcknowledged = false;
|
|
9356
|
+
this.incomingReliableSequence = 0;
|
|
9357
|
+
this.outgoingReliableSequence = 0;
|
|
9358
|
+
this.reliableLength = 0;
|
|
9359
|
+
this.lastReceived = 0;
|
|
9360
|
+
this.lastSent = 0;
|
|
9361
|
+
this.remoteAddress = null;
|
|
9362
|
+
this.reliableMessage = new BinaryWriter2(_NetChan4.MAX_MSGLEN);
|
|
9363
|
+
const now = Date.now();
|
|
9364
|
+
this.lastReceived = now;
|
|
9365
|
+
this.lastSent = now;
|
|
9366
|
+
this.qport = Math.floor(Math.random() * 65536);
|
|
9367
|
+
}
|
|
9368
|
+
/**
|
|
9369
|
+
* Setup the netchan with specific settings
|
|
9370
|
+
*/
|
|
9371
|
+
setup(qport, address = null) {
|
|
9372
|
+
this.qport = qport;
|
|
9373
|
+
this.remoteAddress = address;
|
|
9374
|
+
this.reset();
|
|
9375
|
+
}
|
|
9376
|
+
/**
|
|
9377
|
+
* Reset the netchan state
|
|
9378
|
+
*/
|
|
9379
|
+
reset() {
|
|
9380
|
+
this.incomingSequence = 0;
|
|
9381
|
+
this.outgoingSequence = 0;
|
|
9382
|
+
this.incomingAcknowledged = 0;
|
|
9383
|
+
this.incomingReliableAcknowledged = false;
|
|
9384
|
+
this.incomingReliableSequence = 0;
|
|
9385
|
+
this.outgoingReliableSequence = 0;
|
|
9386
|
+
this.reliableLength = 0;
|
|
9387
|
+
this.reliableMessage.reset();
|
|
9388
|
+
this.lastReceived = Date.now();
|
|
9389
|
+
this.lastSent = Date.now();
|
|
9390
|
+
}
|
|
9391
|
+
/**
|
|
9392
|
+
* Transmits a packet containing reliable and unreliable data
|
|
9393
|
+
*/
|
|
9394
|
+
transmit(unreliableData) {
|
|
9395
|
+
this.outgoingSequence++;
|
|
9396
|
+
this.lastSent = Date.now();
|
|
9397
|
+
const headerSize = _NetChan4.PACKET_HEADER;
|
|
9398
|
+
const reliableSize = this.reliableLength > 0 ? this.reliableLength + 2 : 0;
|
|
9399
|
+
let unreliableSize = unreliableData ? unreliableData.length : 0;
|
|
9400
|
+
if (headerSize + reliableSize + unreliableSize > _NetChan4.MAX_MSGLEN) {
|
|
9401
|
+
unreliableSize = _NetChan4.MAX_MSGLEN - headerSize - reliableSize;
|
|
9402
|
+
if (unreliableSize < 0) unreliableSize = 0;
|
|
9403
|
+
}
|
|
9404
|
+
const buffer = new ArrayBuffer(headerSize + reliableSize + unreliableSize);
|
|
9405
|
+
const view = new DataView(buffer);
|
|
9406
|
+
const result = new Uint8Array(buffer);
|
|
9407
|
+
let sequence = this.outgoingSequence;
|
|
9408
|
+
if (this.reliableLength > 0) {
|
|
9409
|
+
sequence |= 2147483648;
|
|
9410
|
+
if ((this.outgoingReliableSequence & 1) !== 0) {
|
|
9411
|
+
sequence |= 1073741824;
|
|
9412
|
+
}
|
|
9413
|
+
}
|
|
9414
|
+
view.setUint32(0, sequence, true);
|
|
9415
|
+
let ack = this.incomingSequence;
|
|
9416
|
+
if ((this.incomingReliableSequence & 1) !== 0) {
|
|
9417
|
+
ack |= 2147483648;
|
|
9418
|
+
}
|
|
9419
|
+
view.setUint32(4, ack, true);
|
|
9420
|
+
view.setUint16(8, this.qport, true);
|
|
9421
|
+
let offset = headerSize;
|
|
9422
|
+
if (this.reliableLength > 0) {
|
|
9423
|
+
view.setUint16(offset, this.reliableLength, true);
|
|
9424
|
+
offset += 2;
|
|
9425
|
+
const reliableBuffer = this.reliableMessage.getBuffer();
|
|
9426
|
+
const reliableBytes = reliableBuffer.subarray(0, this.reliableLength);
|
|
9427
|
+
result.set(reliableBytes, offset);
|
|
9428
|
+
offset += this.reliableLength;
|
|
9429
|
+
}
|
|
9430
|
+
if (unreliableData && unreliableSize > 0) {
|
|
9431
|
+
const chunk = unreliableData.slice(0, unreliableSize);
|
|
9432
|
+
result.set(chunk, offset);
|
|
9433
|
+
}
|
|
9434
|
+
return result;
|
|
9435
|
+
}
|
|
9436
|
+
/**
|
|
9437
|
+
* Processes a received packet
|
|
9438
|
+
* Returns the payload data (reliable + unreliable) to be processed, or null if discarded
|
|
9439
|
+
*/
|
|
9440
|
+
process(packet) {
|
|
9441
|
+
if (packet.length < _NetChan4.PACKET_HEADER) {
|
|
9442
|
+
return null;
|
|
9443
|
+
}
|
|
9444
|
+
this.lastReceived = Date.now();
|
|
9445
|
+
const view = new DataView(packet.buffer, packet.byteOffset, packet.byteLength);
|
|
9446
|
+
const sequence = view.getUint32(0, true);
|
|
9447
|
+
const ack = view.getUint32(4, true);
|
|
9448
|
+
const qport = view.getUint16(8, true);
|
|
9449
|
+
if (this.qport !== qport) {
|
|
9450
|
+
return null;
|
|
9451
|
+
}
|
|
9452
|
+
const seqNumberClean = sequence & ~(2147483648 | 1073741824);
|
|
9453
|
+
if ((seqNumberClean - this.incomingSequence | 0) <= 0) {
|
|
9454
|
+
return null;
|
|
9455
|
+
}
|
|
9456
|
+
this.incomingSequence = seqNumberClean;
|
|
9457
|
+
const ackNumber = ack & ~2147483648;
|
|
9458
|
+
const ackReliable = (ack & 2147483648) !== 0;
|
|
9459
|
+
if (ackNumber > this.incomingAcknowledged) {
|
|
9460
|
+
this.incomingAcknowledged = ackNumber;
|
|
9461
|
+
}
|
|
9462
|
+
if (this.reliableLength > 0) {
|
|
9463
|
+
const receivedAckBit = ackReliable ? 1 : 0;
|
|
9464
|
+
const currentReliableBit = this.outgoingReliableSequence & 1;
|
|
9465
|
+
if (receivedAckBit !== currentReliableBit) {
|
|
9466
|
+
this.reliableLength = 0;
|
|
9467
|
+
this.reliableMessage.reset();
|
|
9468
|
+
this.outgoingReliableSequence ^= 1;
|
|
9469
|
+
}
|
|
9470
|
+
}
|
|
9471
|
+
const hasReliableData = (sequence & 2147483648) !== 0;
|
|
9472
|
+
const reliableSeqBit = (sequence & 1073741824) !== 0 ? 1 : 0;
|
|
9473
|
+
let payloadOffset = _NetChan4.PACKET_HEADER;
|
|
9474
|
+
let reliableData = null;
|
|
9475
|
+
if (hasReliableData) {
|
|
9476
|
+
if (payloadOffset + 2 > packet.byteLength) return null;
|
|
9477
|
+
const reliableLen = view.getUint16(payloadOffset, true);
|
|
9478
|
+
payloadOffset += 2;
|
|
9479
|
+
const expectedBit = this.incomingReliableSequence & 1;
|
|
9480
|
+
if (reliableSeqBit === expectedBit) {
|
|
9481
|
+
this.incomingReliableSequence++;
|
|
9482
|
+
if (payloadOffset + reliableLen > packet.byteLength) return null;
|
|
9483
|
+
reliableData = packet.slice(payloadOffset, payloadOffset + reliableLen);
|
|
9484
|
+
}
|
|
9485
|
+
payloadOffset += reliableLen;
|
|
9486
|
+
}
|
|
9487
|
+
const unreliableData = packet.slice(payloadOffset);
|
|
9488
|
+
if (reliableData && reliableData.length > 0) {
|
|
9489
|
+
const totalLen = reliableData.length + unreliableData.length;
|
|
9490
|
+
const result = new Uint8Array(totalLen);
|
|
9491
|
+
result.set(reliableData, 0);
|
|
9492
|
+
result.set(unreliableData, reliableData.length);
|
|
9493
|
+
return result;
|
|
9494
|
+
}
|
|
9495
|
+
if (unreliableData) {
|
|
9496
|
+
return unreliableData;
|
|
9497
|
+
}
|
|
9498
|
+
return new Uint8Array(0);
|
|
9499
|
+
}
|
|
9500
|
+
/**
|
|
9501
|
+
* Checks if reliable message buffer is empty and ready for new data
|
|
9502
|
+
*/
|
|
9503
|
+
canSendReliable() {
|
|
9504
|
+
return this.reliableLength === 0;
|
|
9505
|
+
}
|
|
9506
|
+
/**
|
|
9507
|
+
* Writes a byte to the reliable message buffer
|
|
9508
|
+
*/
|
|
9509
|
+
writeReliableByte(value) {
|
|
9510
|
+
if (this.reliableLength + 1 > _NetChan4.MAX_MSGLEN - _NetChan4.HEADER_OVERHEAD) {
|
|
9511
|
+
throw new Error("NetChan reliable buffer overflow");
|
|
9512
|
+
}
|
|
9513
|
+
this.reliableMessage.writeByte(value);
|
|
9514
|
+
this.reliableLength++;
|
|
9515
|
+
}
|
|
9516
|
+
/**
|
|
9517
|
+
* Writes a short to the reliable message buffer
|
|
9518
|
+
*/
|
|
9519
|
+
writeReliableShort(value) {
|
|
9520
|
+
if (this.reliableLength + 2 > _NetChan4.MAX_MSGLEN - _NetChan4.HEADER_OVERHEAD) {
|
|
9521
|
+
throw new Error("NetChan reliable buffer overflow");
|
|
9522
|
+
}
|
|
9523
|
+
this.reliableMessage.writeShort(value);
|
|
9524
|
+
this.reliableLength += 2;
|
|
9525
|
+
}
|
|
9526
|
+
/**
|
|
9527
|
+
* Writes a long to the reliable message buffer
|
|
9528
|
+
*/
|
|
9529
|
+
writeReliableLong(value) {
|
|
9530
|
+
if (this.reliableLength + 4 > _NetChan4.MAX_MSGLEN - _NetChan4.HEADER_OVERHEAD) {
|
|
9531
|
+
throw new Error("NetChan reliable buffer overflow");
|
|
9532
|
+
}
|
|
9533
|
+
this.reliableMessage.writeLong(value);
|
|
9534
|
+
this.reliableLength += 4;
|
|
9535
|
+
}
|
|
9536
|
+
/**
|
|
9537
|
+
* Writes a string to the reliable message buffer
|
|
9538
|
+
*/
|
|
9539
|
+
writeReliableString(value) {
|
|
9540
|
+
const len2 = value.length + 1;
|
|
9541
|
+
if (this.reliableLength + len2 > _NetChan4.MAX_MSGLEN - _NetChan4.HEADER_OVERHEAD) {
|
|
9542
|
+
throw new Error("NetChan reliable buffer overflow");
|
|
9543
|
+
}
|
|
9544
|
+
this.reliableMessage.writeString(value);
|
|
9545
|
+
this.reliableLength += len2;
|
|
9546
|
+
}
|
|
9547
|
+
/**
|
|
9548
|
+
* Returns the current reliable data buffer
|
|
9549
|
+
*/
|
|
9550
|
+
getReliableData() {
|
|
9551
|
+
if (this.reliableLength === 0) {
|
|
9552
|
+
return new Uint8Array(0);
|
|
9553
|
+
}
|
|
9554
|
+
const buffer = this.reliableMessage.getBuffer();
|
|
9555
|
+
return buffer.subarray(0, this.reliableLength);
|
|
9556
|
+
}
|
|
9557
|
+
/**
|
|
9558
|
+
* Checks if we need to send a keepalive packet
|
|
9559
|
+
*/
|
|
9560
|
+
needsKeepalive(currentTime) {
|
|
9561
|
+
return currentTime - this.lastSent > 1e3;
|
|
9562
|
+
}
|
|
9563
|
+
/**
|
|
9564
|
+
* Checks if the connection has timed out
|
|
9565
|
+
*/
|
|
9566
|
+
isTimedOut(currentTime, timeoutMs = 3e4) {
|
|
9567
|
+
return currentTime - this.lastReceived > timeoutMs;
|
|
9568
|
+
}
|
|
9569
|
+
};
|
|
9570
|
+
_NetChan3.MAX_MSGLEN = 1400;
|
|
9571
|
+
_NetChan3.FRAGMENT_SIZE = 1024;
|
|
9572
|
+
_NetChan3.PACKET_HEADER = 10;
|
|
9573
|
+
_NetChan3.HEADER_OVERHEAD = _NetChan3.PACKET_HEADER + 2;
|
|
9022
9574
|
var AmmoType2 = /* @__PURE__ */ ((AmmoType22) => {
|
|
9023
9575
|
AmmoType22[AmmoType22["Bullets"] = 0] = "Bullets";
|
|
9024
9576
|
AmmoType22[AmmoType22["Shells"] = 1] = "Shells";
|
|
@@ -9557,6 +10109,91 @@ var DEMO_ITEM_MAPPING = [
|
|
|
9557
10109
|
// IT_ITEM_COMPASS
|
|
9558
10110
|
];
|
|
9559
10111
|
|
|
10112
|
+
// src/entities.ts
|
|
10113
|
+
function lerp2(a, b, t) {
|
|
10114
|
+
return a + (b - a) * t;
|
|
10115
|
+
}
|
|
10116
|
+
function lerpAngle(a, b, t) {
|
|
10117
|
+
return lerp2(a, b, t);
|
|
10118
|
+
}
|
|
10119
|
+
function buildRenderableEntities(latestEntities, previousEntities, alpha, configStrings, imports) {
|
|
10120
|
+
const renderables = [];
|
|
10121
|
+
const assets = imports.engine.assets;
|
|
10122
|
+
if (!assets) return renderables;
|
|
10123
|
+
let prevMap;
|
|
10124
|
+
if (previousEntities instanceof Map) {
|
|
10125
|
+
prevMap = previousEntities;
|
|
10126
|
+
} else {
|
|
10127
|
+
prevMap = new Map(previousEntities.map((e) => [e.number, e]));
|
|
10128
|
+
}
|
|
10129
|
+
for (const ent of latestEntities) {
|
|
10130
|
+
const prev = prevMap.get(ent.number) ?? ent;
|
|
10131
|
+
const modelIndex = ent.modelIndex ?? ent.modelindex;
|
|
10132
|
+
const skinNum = ent.skinNum ?? ent.skinnum;
|
|
10133
|
+
if (modelIndex === void 0) continue;
|
|
10134
|
+
const modelName = configStrings.getModelName(modelIndex);
|
|
10135
|
+
if (!modelName) continue;
|
|
10136
|
+
const model = assets.getMd2Model(modelName) || assets.getMd3Model(modelName);
|
|
10137
|
+
if (!model) continue;
|
|
10138
|
+
const origin = {
|
|
10139
|
+
x: lerp2(prev.origin.x, ent.origin.x, alpha),
|
|
10140
|
+
y: lerp2(prev.origin.y, ent.origin.y, alpha),
|
|
10141
|
+
z: lerp2(prev.origin.z, ent.origin.z, alpha)
|
|
10142
|
+
};
|
|
10143
|
+
const angles = {
|
|
10144
|
+
x: lerpAngle(prev.angles.x, ent.angles.x, alpha),
|
|
10145
|
+
y: lerpAngle(prev.angles.y, ent.angles.y, alpha),
|
|
10146
|
+
z: lerpAngle(prev.angles.z, ent.angles.z, alpha)
|
|
10147
|
+
};
|
|
10148
|
+
const frame = ent.frame;
|
|
10149
|
+
const prevFrame = prev.frame;
|
|
10150
|
+
const scaleA = prev.scale !== void 0 ? prev.scale : 1;
|
|
10151
|
+
const scaleB = ent.scale !== void 0 ? ent.scale : 1;
|
|
10152
|
+
const scale3 = lerp2(scaleA, scaleB, alpha);
|
|
10153
|
+
const getAlpha = (val) => val === void 0 || val === 0 ? 255 : val;
|
|
10154
|
+
const alphaA = getAlpha(prev.alpha);
|
|
10155
|
+
const alphaB = getAlpha(ent.alpha);
|
|
10156
|
+
const alphaVal = lerp2(alphaA, alphaB, alpha);
|
|
10157
|
+
const normalizedAlpha = alphaVal / 255;
|
|
10158
|
+
const mat = mat4_exports.create();
|
|
10159
|
+
mat4_exports.translate(mat, mat, [origin.x, origin.y, origin.z]);
|
|
10160
|
+
mat4_exports.rotateZ(mat, mat, angles.z * Math.PI / 180);
|
|
10161
|
+
mat4_exports.rotateY(mat, mat, angles.y * Math.PI / 180);
|
|
10162
|
+
mat4_exports.rotateX(mat, mat, angles.x * Math.PI / 180);
|
|
10163
|
+
mat4_exports.scale(mat, mat, [scale3, scale3, scale3]);
|
|
10164
|
+
const skinName = skinNum !== void 0 && skinNum > 0 ? configStrings.getImageName(skinNum) : void 0;
|
|
10165
|
+
if (model.header.magic === 844121161) {
|
|
10166
|
+
renderables.push({
|
|
10167
|
+
type: "md2",
|
|
10168
|
+
model,
|
|
10169
|
+
// Cast to Md2Model
|
|
10170
|
+
blend: {
|
|
10171
|
+
frame0: prevFrame,
|
|
10172
|
+
frame1: frame,
|
|
10173
|
+
lerp: alpha
|
|
10174
|
+
},
|
|
10175
|
+
transform: mat,
|
|
10176
|
+
skin: skinName,
|
|
10177
|
+
alpha: normalizedAlpha
|
|
10178
|
+
});
|
|
10179
|
+
} else if (model.header.magic === 860898377) {
|
|
10180
|
+
renderables.push({
|
|
10181
|
+
type: "md3",
|
|
10182
|
+
model,
|
|
10183
|
+
blend: {
|
|
10184
|
+
frame0: prevFrame,
|
|
10185
|
+
frame1: frame,
|
|
10186
|
+
lerp: alpha
|
|
10187
|
+
},
|
|
10188
|
+
transform: mat,
|
|
10189
|
+
alpha: normalizedAlpha
|
|
10190
|
+
// Lighting? Skins?
|
|
10191
|
+
});
|
|
10192
|
+
}
|
|
10193
|
+
}
|
|
10194
|
+
return renderables;
|
|
10195
|
+
}
|
|
10196
|
+
|
|
9560
10197
|
// src/demo/handler.ts
|
|
9561
10198
|
var MAX_CONFIGSTRINGS3 = 32768;
|
|
9562
10199
|
var ClientNetworkHandler = class {
|
|
@@ -9564,6 +10201,8 @@ var ClientNetworkHandler = class {
|
|
|
9564
10201
|
this.configstrings = new Array(MAX_CONFIGSTRINGS3).fill("");
|
|
9565
10202
|
this.entities = /* @__PURE__ */ new Map();
|
|
9566
10203
|
// Current frame entities
|
|
10204
|
+
this.previousEntities = /* @__PURE__ */ new Map();
|
|
10205
|
+
// Previous frame entities
|
|
9567
10206
|
this.baselines = /* @__PURE__ */ new Map();
|
|
9568
10207
|
this.previousFrame = null;
|
|
9569
10208
|
this.latestFrame = null;
|
|
@@ -9587,8 +10226,10 @@ var ClientNetworkHandler = class {
|
|
|
9587
10226
|
console.log(`Demo: Server Data - Protocol: ${protocol}, Level: ${levelName}, Tick: ${tickRate ?? 10}`);
|
|
9588
10227
|
this.configstrings.fill("");
|
|
9589
10228
|
this.entities.clear();
|
|
10229
|
+
this.previousEntities.clear();
|
|
9590
10230
|
this.baselines.clear();
|
|
9591
10231
|
this.latestFrame = null;
|
|
10232
|
+
this.previousFrame = null;
|
|
9592
10233
|
this.playerNum = playerNum;
|
|
9593
10234
|
if (this.callbacks?.onServerData) {
|
|
9594
10235
|
this.callbacks.onServerData(protocol, tickRate);
|
|
@@ -9606,6 +10247,7 @@ var ClientNetworkHandler = class {
|
|
|
9606
10247
|
onFrame(frame) {
|
|
9607
10248
|
if (this.latestFrame) {
|
|
9608
10249
|
this.previousFrame = this.latestFrame;
|
|
10250
|
+
this.previousEntities = this.entities;
|
|
9609
10251
|
}
|
|
9610
10252
|
this.latestFrame = frame;
|
|
9611
10253
|
this.stats = [...frame.playerState.stats];
|
|
@@ -9916,7 +10558,10 @@ var ClientNetworkHandler = class {
|
|
|
9916
10558
|
if (this.previousFrame && timeMs !== void 0) {
|
|
9917
10559
|
const latestServerTime = this.latestFrame.serverFrame * 100;
|
|
9918
10560
|
const previousServerTime = this.previousFrame.serverFrame * 100;
|
|
9919
|
-
if (timeMs
|
|
10561
|
+
if (timeMs <= 1) {
|
|
10562
|
+
const previousState = this.convertFrameToPredictionState(this.previousFrame);
|
|
10563
|
+
return interpolatePredictionState(previousState, latestState, Math.max(0, Math.min(1, timeMs)));
|
|
10564
|
+
} else if (timeMs >= previousServerTime && timeMs <= latestServerTime) {
|
|
9920
10565
|
const alpha = (timeMs - previousServerTime) / (latestServerTime - previousServerTime);
|
|
9921
10566
|
const previousState = this.convertFrameToPredictionState(this.previousFrame);
|
|
9922
10567
|
return interpolatePredictionState(previousState, latestState, Math.max(0, Math.min(1, alpha)));
|
|
@@ -9924,6 +10569,27 @@ var ClientNetworkHandler = class {
|
|
|
9924
10569
|
}
|
|
9925
10570
|
return latestState;
|
|
9926
10571
|
}
|
|
10572
|
+
getRenderableEntities(alpha, configStrings) {
|
|
10573
|
+
if (!this.latestFrame) return [];
|
|
10574
|
+
if (!this.imports) return [];
|
|
10575
|
+
const latest = Array.from(this.entities.values());
|
|
10576
|
+
const previous = this.previousEntities.size > 0 ? this.previousEntities : latest;
|
|
10577
|
+
return buildRenderableEntities(
|
|
10578
|
+
latest,
|
|
10579
|
+
previous,
|
|
10580
|
+
alpha,
|
|
10581
|
+
configStrings,
|
|
10582
|
+
this.imports
|
|
10583
|
+
);
|
|
10584
|
+
}
|
|
10585
|
+
getDemoCamera(alpha) {
|
|
10586
|
+
const ps = this.getPredictionState(alpha);
|
|
10587
|
+
return {
|
|
10588
|
+
origin: ps.origin,
|
|
10589
|
+
angles: ps.viewAngles,
|
|
10590
|
+
fov: ps.fov ?? 90
|
|
10591
|
+
};
|
|
10592
|
+
}
|
|
9927
10593
|
get latestServerFrame() {
|
|
9928
10594
|
return this.latestFrame?.serverFrame ?? 0;
|
|
9929
10595
|
}
|
|
@@ -10842,82 +11508,6 @@ var WheelMenuSystem = class {
|
|
|
10842
11508
|
}
|
|
10843
11509
|
};
|
|
10844
11510
|
|
|
10845
|
-
// src/entities.ts
|
|
10846
|
-
function lerp2(a, b, t) {
|
|
10847
|
-
return a + (b - a) * t;
|
|
10848
|
-
}
|
|
10849
|
-
function lerpAngle(a, b, t) {
|
|
10850
|
-
return lerp2(a, b, t);
|
|
10851
|
-
}
|
|
10852
|
-
function buildRenderableEntities(latestEntities, previousEntities, alpha, configStrings, imports) {
|
|
10853
|
-
const renderables = [];
|
|
10854
|
-
const assets = imports.engine.assets;
|
|
10855
|
-
if (!assets) return renderables;
|
|
10856
|
-
const prevMap = new Map(previousEntities.map((e) => [e.number, e]));
|
|
10857
|
-
for (const ent of latestEntities) {
|
|
10858
|
-
const prev = prevMap.get(ent.number) ?? ent;
|
|
10859
|
-
const modelName = configStrings.getModelName(ent.modelIndex);
|
|
10860
|
-
if (!modelName) continue;
|
|
10861
|
-
const model = assets.getMd2Model(modelName) || assets.getMd3Model(modelName);
|
|
10862
|
-
if (!model) continue;
|
|
10863
|
-
const origin = {
|
|
10864
|
-
x: lerp2(prev.origin.x, ent.origin.x, alpha),
|
|
10865
|
-
y: lerp2(prev.origin.y, ent.origin.y, alpha),
|
|
10866
|
-
z: lerp2(prev.origin.z, ent.origin.z, alpha)
|
|
10867
|
-
};
|
|
10868
|
-
const angles = {
|
|
10869
|
-
x: lerpAngle(prev.angles.x, ent.angles.x, alpha),
|
|
10870
|
-
y: lerpAngle(prev.angles.y, ent.angles.y, alpha),
|
|
10871
|
-
z: lerpAngle(prev.angles.z, ent.angles.z, alpha)
|
|
10872
|
-
};
|
|
10873
|
-
const frame = ent.frame;
|
|
10874
|
-
const prevFrame = prev.frame;
|
|
10875
|
-
const scaleA = prev.scale !== void 0 ? prev.scale : 1;
|
|
10876
|
-
const scaleB = ent.scale !== void 0 ? ent.scale : 1;
|
|
10877
|
-
const scale3 = lerp2(scaleA, scaleB, alpha);
|
|
10878
|
-
const getAlpha = (val) => val === void 0 || val === 0 ? 255 : val;
|
|
10879
|
-
const alphaA = getAlpha(prev.alpha);
|
|
10880
|
-
const alphaB = getAlpha(ent.alpha);
|
|
10881
|
-
const alphaVal = lerp2(alphaA, alphaB, alpha);
|
|
10882
|
-
const normalizedAlpha = alphaVal / 255;
|
|
10883
|
-
const mat = mat4_exports.create();
|
|
10884
|
-
mat4_exports.translate(mat, mat, [origin.x, origin.y, origin.z]);
|
|
10885
|
-
mat4_exports.rotateZ(mat, mat, angles.z * Math.PI / 180);
|
|
10886
|
-
mat4_exports.rotateY(mat, mat, angles.y * Math.PI / 180);
|
|
10887
|
-
mat4_exports.rotateX(mat, mat, angles.x * Math.PI / 180);
|
|
10888
|
-
mat4_exports.scale(mat, mat, [scale3, scale3, scale3]);
|
|
10889
|
-
if (model.header.magic === 844121161) {
|
|
10890
|
-
renderables.push({
|
|
10891
|
-
type: "md2",
|
|
10892
|
-
model,
|
|
10893
|
-
// Cast to Md2Model
|
|
10894
|
-
blend: {
|
|
10895
|
-
frame0: prevFrame,
|
|
10896
|
-
frame1: frame,
|
|
10897
|
-
lerp: alpha
|
|
10898
|
-
},
|
|
10899
|
-
transform: mat,
|
|
10900
|
-
skin: ent.skinNum > 0 ? configStrings.getImageName(ent.skinNum) : void 0,
|
|
10901
|
-
alpha: normalizedAlpha
|
|
10902
|
-
});
|
|
10903
|
-
} else if (model.header.magic === 860898377) {
|
|
10904
|
-
renderables.push({
|
|
10905
|
-
type: "md3",
|
|
10906
|
-
model,
|
|
10907
|
-
blend: {
|
|
10908
|
-
frame0: prevFrame,
|
|
10909
|
-
frame1: frame,
|
|
10910
|
-
lerp: alpha
|
|
10911
|
-
},
|
|
10912
|
-
transform: mat,
|
|
10913
|
-
alpha: normalizedAlpha
|
|
10914
|
-
// Lighting? Skins?
|
|
10915
|
-
});
|
|
10916
|
-
}
|
|
10917
|
-
}
|
|
10918
|
-
return renderables;
|
|
10919
|
-
}
|
|
10920
|
-
|
|
10921
11511
|
// src/net/browserWsDriver.ts
|
|
10922
11512
|
var BrowserWebSocketNetDriver = class {
|
|
10923
11513
|
constructor() {
|
|
@@ -11048,7 +11638,7 @@ var MultiplayerConnection = class {
|
|
|
11048
11638
|
if (this.commandHistory.length > CMD_BACKUP) {
|
|
11049
11639
|
this.commandHistory.shift();
|
|
11050
11640
|
}
|
|
11051
|
-
const writer = new
|
|
11641
|
+
const writer = new BinaryWriter2();
|
|
11052
11642
|
writer.writeLong(0);
|
|
11053
11643
|
writer.writeLong(0);
|
|
11054
11644
|
writer.writeByte(ClientCommand.move);
|