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
|
@@ -2329,6 +2329,333 @@ var BinaryStream = class {
|
|
|
2329
2329
|
out.z = norm[2];
|
|
2330
2330
|
}
|
|
2331
2331
|
};
|
|
2332
|
+
var BinaryWriter = class {
|
|
2333
|
+
constructor(sizeOrBuffer = 1400) {
|
|
2334
|
+
if (typeof sizeOrBuffer === "number") {
|
|
2335
|
+
this.buffer = new Uint8Array(sizeOrBuffer);
|
|
2336
|
+
this.fixed = false;
|
|
2337
|
+
} else {
|
|
2338
|
+
this.buffer = sizeOrBuffer;
|
|
2339
|
+
this.fixed = true;
|
|
2340
|
+
}
|
|
2341
|
+
this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
|
|
2342
|
+
this.offset = 0;
|
|
2343
|
+
}
|
|
2344
|
+
ensureSpace(bytes) {
|
|
2345
|
+
if (this.offset + bytes > this.buffer.byteLength) {
|
|
2346
|
+
if (this.fixed) {
|
|
2347
|
+
throw new Error(`Buffer overflow: capacity ${this.buffer.byteLength}, needed ${this.offset + bytes}`);
|
|
2348
|
+
}
|
|
2349
|
+
const newSize = Math.max(this.buffer.byteLength * 2, this.offset + bytes);
|
|
2350
|
+
const newBuffer = new Uint8Array(newSize);
|
|
2351
|
+
newBuffer.set(this.buffer);
|
|
2352
|
+
this.buffer = newBuffer;
|
|
2353
|
+
this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
|
|
2354
|
+
}
|
|
2355
|
+
}
|
|
2356
|
+
writeByte(value) {
|
|
2357
|
+
this.ensureSpace(1);
|
|
2358
|
+
this.view.setUint8(this.offset, value);
|
|
2359
|
+
this.offset += 1;
|
|
2360
|
+
}
|
|
2361
|
+
writeChar(value) {
|
|
2362
|
+
this.ensureSpace(1);
|
|
2363
|
+
this.view.setInt8(this.offset, value);
|
|
2364
|
+
this.offset += 1;
|
|
2365
|
+
}
|
|
2366
|
+
writeShort(value) {
|
|
2367
|
+
this.ensureSpace(2);
|
|
2368
|
+
this.view.setInt16(this.offset, value, true);
|
|
2369
|
+
this.offset += 2;
|
|
2370
|
+
}
|
|
2371
|
+
writeLong(value) {
|
|
2372
|
+
this.ensureSpace(4);
|
|
2373
|
+
this.view.setInt32(this.offset, value, true);
|
|
2374
|
+
this.offset += 4;
|
|
2375
|
+
}
|
|
2376
|
+
writeFloat(value) {
|
|
2377
|
+
this.ensureSpace(4);
|
|
2378
|
+
this.view.setFloat32(this.offset, value, true);
|
|
2379
|
+
this.offset += 4;
|
|
2380
|
+
}
|
|
2381
|
+
writeString(value) {
|
|
2382
|
+
const len2 = value.length;
|
|
2383
|
+
this.ensureSpace(len2 + 1);
|
|
2384
|
+
for (let i = 0; i < len2; i++) {
|
|
2385
|
+
this.view.setUint8(this.offset + i, value.charCodeAt(i));
|
|
2386
|
+
}
|
|
2387
|
+
this.view.setUint8(this.offset + len2, 0);
|
|
2388
|
+
this.offset += len2 + 1;
|
|
2389
|
+
}
|
|
2390
|
+
writeCoord(value) {
|
|
2391
|
+
this.writeShort(Math.trunc(value * 8));
|
|
2392
|
+
}
|
|
2393
|
+
writeAngle(value) {
|
|
2394
|
+
this.writeByte(Math.trunc(value * 256 / 360) & 255);
|
|
2395
|
+
}
|
|
2396
|
+
writeAngle16(value) {
|
|
2397
|
+
this.writeShort(Math.trunc(value * 65536 / 360) & 65535);
|
|
2398
|
+
}
|
|
2399
|
+
writePos(pos) {
|
|
2400
|
+
this.writeCoord(pos.x);
|
|
2401
|
+
this.writeCoord(pos.y);
|
|
2402
|
+
this.writeCoord(pos.z);
|
|
2403
|
+
}
|
|
2404
|
+
writeDir(dir) {
|
|
2405
|
+
let maxDot = -1;
|
|
2406
|
+
let bestIndex = 0;
|
|
2407
|
+
if (dir.x === 0 && dir.y === 0 && dir.z === 0) {
|
|
2408
|
+
this.writeByte(0);
|
|
2409
|
+
return;
|
|
2410
|
+
}
|
|
2411
|
+
for (let i = 0; i < ANORMS.length; i++) {
|
|
2412
|
+
const norm = ANORMS[i];
|
|
2413
|
+
const dot2 = dir.x * norm[0] + dir.y * norm[1] + dir.z * norm[2];
|
|
2414
|
+
if (dot2 > maxDot) {
|
|
2415
|
+
maxDot = dot2;
|
|
2416
|
+
bestIndex = i;
|
|
2417
|
+
}
|
|
2418
|
+
}
|
|
2419
|
+
this.writeByte(bestIndex);
|
|
2420
|
+
}
|
|
2421
|
+
getData() {
|
|
2422
|
+
return this.buffer.slice(0, this.offset);
|
|
2423
|
+
}
|
|
2424
|
+
getBuffer() {
|
|
2425
|
+
return this.buffer;
|
|
2426
|
+
}
|
|
2427
|
+
getOffset() {
|
|
2428
|
+
return this.offset;
|
|
2429
|
+
}
|
|
2430
|
+
reset() {
|
|
2431
|
+
this.offset = 0;
|
|
2432
|
+
}
|
|
2433
|
+
};
|
|
2434
|
+
var _NetChan = class _NetChan2 {
|
|
2435
|
+
constructor() {
|
|
2436
|
+
this.qport = 0;
|
|
2437
|
+
this.incomingSequence = 0;
|
|
2438
|
+
this.outgoingSequence = 0;
|
|
2439
|
+
this.incomingAcknowledged = 0;
|
|
2440
|
+
this.incomingReliableAcknowledged = false;
|
|
2441
|
+
this.incomingReliableSequence = 0;
|
|
2442
|
+
this.outgoingReliableSequence = 0;
|
|
2443
|
+
this.reliableLength = 0;
|
|
2444
|
+
this.lastReceived = 0;
|
|
2445
|
+
this.lastSent = 0;
|
|
2446
|
+
this.remoteAddress = null;
|
|
2447
|
+
this.reliableMessage = new BinaryWriter(_NetChan2.MAX_MSGLEN);
|
|
2448
|
+
const now = Date.now();
|
|
2449
|
+
this.lastReceived = now;
|
|
2450
|
+
this.lastSent = now;
|
|
2451
|
+
this.qport = Math.floor(Math.random() * 65536);
|
|
2452
|
+
}
|
|
2453
|
+
/**
|
|
2454
|
+
* Setup the netchan with specific settings
|
|
2455
|
+
*/
|
|
2456
|
+
setup(qport, address = null) {
|
|
2457
|
+
this.qport = qport;
|
|
2458
|
+
this.remoteAddress = address;
|
|
2459
|
+
this.reset();
|
|
2460
|
+
}
|
|
2461
|
+
/**
|
|
2462
|
+
* Reset the netchan state
|
|
2463
|
+
*/
|
|
2464
|
+
reset() {
|
|
2465
|
+
this.incomingSequence = 0;
|
|
2466
|
+
this.outgoingSequence = 0;
|
|
2467
|
+
this.incomingAcknowledged = 0;
|
|
2468
|
+
this.incomingReliableAcknowledged = false;
|
|
2469
|
+
this.incomingReliableSequence = 0;
|
|
2470
|
+
this.outgoingReliableSequence = 0;
|
|
2471
|
+
this.reliableLength = 0;
|
|
2472
|
+
this.reliableMessage.reset();
|
|
2473
|
+
this.lastReceived = Date.now();
|
|
2474
|
+
this.lastSent = Date.now();
|
|
2475
|
+
}
|
|
2476
|
+
/**
|
|
2477
|
+
* Transmits a packet containing reliable and unreliable data
|
|
2478
|
+
*/
|
|
2479
|
+
transmit(unreliableData) {
|
|
2480
|
+
this.outgoingSequence++;
|
|
2481
|
+
this.lastSent = Date.now();
|
|
2482
|
+
const headerSize = _NetChan2.PACKET_HEADER;
|
|
2483
|
+
const reliableSize = this.reliableLength > 0 ? this.reliableLength + 2 : 0;
|
|
2484
|
+
let unreliableSize = unreliableData ? unreliableData.length : 0;
|
|
2485
|
+
if (headerSize + reliableSize + unreliableSize > _NetChan2.MAX_MSGLEN) {
|
|
2486
|
+
unreliableSize = _NetChan2.MAX_MSGLEN - headerSize - reliableSize;
|
|
2487
|
+
if (unreliableSize < 0) unreliableSize = 0;
|
|
2488
|
+
}
|
|
2489
|
+
const buffer = new ArrayBuffer(headerSize + reliableSize + unreliableSize);
|
|
2490
|
+
const view = new DataView(buffer);
|
|
2491
|
+
const result = new Uint8Array(buffer);
|
|
2492
|
+
let sequence = this.outgoingSequence;
|
|
2493
|
+
if (this.reliableLength > 0) {
|
|
2494
|
+
sequence |= 2147483648;
|
|
2495
|
+
if ((this.outgoingReliableSequence & 1) !== 0) {
|
|
2496
|
+
sequence |= 1073741824;
|
|
2497
|
+
}
|
|
2498
|
+
}
|
|
2499
|
+
view.setUint32(0, sequence, true);
|
|
2500
|
+
let ack = this.incomingSequence;
|
|
2501
|
+
if ((this.incomingReliableSequence & 1) !== 0) {
|
|
2502
|
+
ack |= 2147483648;
|
|
2503
|
+
}
|
|
2504
|
+
view.setUint32(4, ack, true);
|
|
2505
|
+
view.setUint16(8, this.qport, true);
|
|
2506
|
+
let offset = headerSize;
|
|
2507
|
+
if (this.reliableLength > 0) {
|
|
2508
|
+
view.setUint16(offset, this.reliableLength, true);
|
|
2509
|
+
offset += 2;
|
|
2510
|
+
const reliableBuffer = this.reliableMessage.getBuffer();
|
|
2511
|
+
const reliableBytes = reliableBuffer.subarray(0, this.reliableLength);
|
|
2512
|
+
result.set(reliableBytes, offset);
|
|
2513
|
+
offset += this.reliableLength;
|
|
2514
|
+
}
|
|
2515
|
+
if (unreliableData && unreliableSize > 0) {
|
|
2516
|
+
const chunk = unreliableData.slice(0, unreliableSize);
|
|
2517
|
+
result.set(chunk, offset);
|
|
2518
|
+
}
|
|
2519
|
+
return result;
|
|
2520
|
+
}
|
|
2521
|
+
/**
|
|
2522
|
+
* Processes a received packet
|
|
2523
|
+
* Returns the payload data (reliable + unreliable) to be processed, or null if discarded
|
|
2524
|
+
*/
|
|
2525
|
+
process(packet) {
|
|
2526
|
+
if (packet.length < _NetChan2.PACKET_HEADER) {
|
|
2527
|
+
return null;
|
|
2528
|
+
}
|
|
2529
|
+
this.lastReceived = Date.now();
|
|
2530
|
+
const view = new DataView(packet.buffer, packet.byteOffset, packet.byteLength);
|
|
2531
|
+
const sequence = view.getUint32(0, true);
|
|
2532
|
+
const ack = view.getUint32(4, true);
|
|
2533
|
+
const qport = view.getUint16(8, true);
|
|
2534
|
+
if (this.qport !== qport) {
|
|
2535
|
+
return null;
|
|
2536
|
+
}
|
|
2537
|
+
const seqNumberClean = sequence & ~(2147483648 | 1073741824);
|
|
2538
|
+
if ((seqNumberClean - this.incomingSequence | 0) <= 0) {
|
|
2539
|
+
return null;
|
|
2540
|
+
}
|
|
2541
|
+
this.incomingSequence = seqNumberClean;
|
|
2542
|
+
const ackNumber = ack & ~2147483648;
|
|
2543
|
+
const ackReliable = (ack & 2147483648) !== 0;
|
|
2544
|
+
if (ackNumber > this.incomingAcknowledged) {
|
|
2545
|
+
this.incomingAcknowledged = ackNumber;
|
|
2546
|
+
}
|
|
2547
|
+
if (this.reliableLength > 0) {
|
|
2548
|
+
const receivedAckBit = ackReliable ? 1 : 0;
|
|
2549
|
+
const currentReliableBit = this.outgoingReliableSequence & 1;
|
|
2550
|
+
if (receivedAckBit !== currentReliableBit) {
|
|
2551
|
+
this.reliableLength = 0;
|
|
2552
|
+
this.reliableMessage.reset();
|
|
2553
|
+
this.outgoingReliableSequence ^= 1;
|
|
2554
|
+
}
|
|
2555
|
+
}
|
|
2556
|
+
const hasReliableData = (sequence & 2147483648) !== 0;
|
|
2557
|
+
const reliableSeqBit = (sequence & 1073741824) !== 0 ? 1 : 0;
|
|
2558
|
+
let payloadOffset = _NetChan2.PACKET_HEADER;
|
|
2559
|
+
let reliableData = null;
|
|
2560
|
+
if (hasReliableData) {
|
|
2561
|
+
if (payloadOffset + 2 > packet.byteLength) return null;
|
|
2562
|
+
const reliableLen = view.getUint16(payloadOffset, true);
|
|
2563
|
+
payloadOffset += 2;
|
|
2564
|
+
const expectedBit = this.incomingReliableSequence & 1;
|
|
2565
|
+
if (reliableSeqBit === expectedBit) {
|
|
2566
|
+
this.incomingReliableSequence++;
|
|
2567
|
+
if (payloadOffset + reliableLen > packet.byteLength) return null;
|
|
2568
|
+
reliableData = packet.slice(payloadOffset, payloadOffset + reliableLen);
|
|
2569
|
+
}
|
|
2570
|
+
payloadOffset += reliableLen;
|
|
2571
|
+
}
|
|
2572
|
+
const unreliableData = packet.slice(payloadOffset);
|
|
2573
|
+
if (reliableData && reliableData.length > 0) {
|
|
2574
|
+
const totalLen = reliableData.length + unreliableData.length;
|
|
2575
|
+
const result = new Uint8Array(totalLen);
|
|
2576
|
+
result.set(reliableData, 0);
|
|
2577
|
+
result.set(unreliableData, reliableData.length);
|
|
2578
|
+
return result;
|
|
2579
|
+
}
|
|
2580
|
+
if (unreliableData) {
|
|
2581
|
+
return unreliableData;
|
|
2582
|
+
}
|
|
2583
|
+
return new Uint8Array(0);
|
|
2584
|
+
}
|
|
2585
|
+
/**
|
|
2586
|
+
* Checks if reliable message buffer is empty and ready for new data
|
|
2587
|
+
*/
|
|
2588
|
+
canSendReliable() {
|
|
2589
|
+
return this.reliableLength === 0;
|
|
2590
|
+
}
|
|
2591
|
+
/**
|
|
2592
|
+
* Writes a byte to the reliable message buffer
|
|
2593
|
+
*/
|
|
2594
|
+
writeReliableByte(value) {
|
|
2595
|
+
if (this.reliableLength + 1 > _NetChan2.MAX_MSGLEN - _NetChan2.HEADER_OVERHEAD) {
|
|
2596
|
+
throw new Error("NetChan reliable buffer overflow");
|
|
2597
|
+
}
|
|
2598
|
+
this.reliableMessage.writeByte(value);
|
|
2599
|
+
this.reliableLength++;
|
|
2600
|
+
}
|
|
2601
|
+
/**
|
|
2602
|
+
* Writes a short to the reliable message buffer
|
|
2603
|
+
*/
|
|
2604
|
+
writeReliableShort(value) {
|
|
2605
|
+
if (this.reliableLength + 2 > _NetChan2.MAX_MSGLEN - _NetChan2.HEADER_OVERHEAD) {
|
|
2606
|
+
throw new Error("NetChan reliable buffer overflow");
|
|
2607
|
+
}
|
|
2608
|
+
this.reliableMessage.writeShort(value);
|
|
2609
|
+
this.reliableLength += 2;
|
|
2610
|
+
}
|
|
2611
|
+
/**
|
|
2612
|
+
* Writes a long to the reliable message buffer
|
|
2613
|
+
*/
|
|
2614
|
+
writeReliableLong(value) {
|
|
2615
|
+
if (this.reliableLength + 4 > _NetChan2.MAX_MSGLEN - _NetChan2.HEADER_OVERHEAD) {
|
|
2616
|
+
throw new Error("NetChan reliable buffer overflow");
|
|
2617
|
+
}
|
|
2618
|
+
this.reliableMessage.writeLong(value);
|
|
2619
|
+
this.reliableLength += 4;
|
|
2620
|
+
}
|
|
2621
|
+
/**
|
|
2622
|
+
* Writes a string to the reliable message buffer
|
|
2623
|
+
*/
|
|
2624
|
+
writeReliableString(value) {
|
|
2625
|
+
const len2 = value.length + 1;
|
|
2626
|
+
if (this.reliableLength + len2 > _NetChan2.MAX_MSGLEN - _NetChan2.HEADER_OVERHEAD) {
|
|
2627
|
+
throw new Error("NetChan reliable buffer overflow");
|
|
2628
|
+
}
|
|
2629
|
+
this.reliableMessage.writeString(value);
|
|
2630
|
+
this.reliableLength += len2;
|
|
2631
|
+
}
|
|
2632
|
+
/**
|
|
2633
|
+
* Returns the current reliable data buffer
|
|
2634
|
+
*/
|
|
2635
|
+
getReliableData() {
|
|
2636
|
+
if (this.reliableLength === 0) {
|
|
2637
|
+
return new Uint8Array(0);
|
|
2638
|
+
}
|
|
2639
|
+
const buffer = this.reliableMessage.getBuffer();
|
|
2640
|
+
return buffer.subarray(0, this.reliableLength);
|
|
2641
|
+
}
|
|
2642
|
+
/**
|
|
2643
|
+
* Checks if we need to send a keepalive packet
|
|
2644
|
+
*/
|
|
2645
|
+
needsKeepalive(currentTime) {
|
|
2646
|
+
return currentTime - this.lastSent > 1e3;
|
|
2647
|
+
}
|
|
2648
|
+
/**
|
|
2649
|
+
* Checks if the connection has timed out
|
|
2650
|
+
*/
|
|
2651
|
+
isTimedOut(currentTime, timeoutMs = 3e4) {
|
|
2652
|
+
return currentTime - this.lastReceived > timeoutMs;
|
|
2653
|
+
}
|
|
2654
|
+
};
|
|
2655
|
+
_NetChan.MAX_MSGLEN = 1400;
|
|
2656
|
+
_NetChan.FRAGMENT_SIZE = 1024;
|
|
2657
|
+
_NetChan.PACKET_HEADER = 10;
|
|
2658
|
+
_NetChan.HEADER_OVERHEAD = _NetChan.PACKET_HEADER + 2;
|
|
2332
2659
|
var AmmoType = /* @__PURE__ */ ((AmmoType22) => {
|
|
2333
2660
|
AmmoType22[AmmoType22["Bullets"] = 0] = "Bullets";
|
|
2334
2661
|
AmmoType22[AmmoType22["Shells"] = 1] = "Shells";
|
|
@@ -8859,7 +9186,7 @@ var BinaryStream2 = class {
|
|
|
8859
9186
|
out.z = norm[2];
|
|
8860
9187
|
}
|
|
8861
9188
|
};
|
|
8862
|
-
var
|
|
9189
|
+
var BinaryWriter2 = class {
|
|
8863
9190
|
constructor(sizeOrBuffer = 1400) {
|
|
8864
9191
|
if (typeof sizeOrBuffer === "number") {
|
|
8865
9192
|
this.buffer = new Uint8Array(sizeOrBuffer);
|
|
@@ -9051,6 +9378,231 @@ var NetworkMessageBuilder = class {
|
|
|
9051
9378
|
this.writeByte(best);
|
|
9052
9379
|
}
|
|
9053
9380
|
};
|
|
9381
|
+
var _NetChan3 = class _NetChan4 {
|
|
9382
|
+
constructor() {
|
|
9383
|
+
this.qport = 0;
|
|
9384
|
+
this.incomingSequence = 0;
|
|
9385
|
+
this.outgoingSequence = 0;
|
|
9386
|
+
this.incomingAcknowledged = 0;
|
|
9387
|
+
this.incomingReliableAcknowledged = false;
|
|
9388
|
+
this.incomingReliableSequence = 0;
|
|
9389
|
+
this.outgoingReliableSequence = 0;
|
|
9390
|
+
this.reliableLength = 0;
|
|
9391
|
+
this.lastReceived = 0;
|
|
9392
|
+
this.lastSent = 0;
|
|
9393
|
+
this.remoteAddress = null;
|
|
9394
|
+
this.reliableMessage = new BinaryWriter2(_NetChan4.MAX_MSGLEN);
|
|
9395
|
+
const now = Date.now();
|
|
9396
|
+
this.lastReceived = now;
|
|
9397
|
+
this.lastSent = now;
|
|
9398
|
+
this.qport = Math.floor(Math.random() * 65536);
|
|
9399
|
+
}
|
|
9400
|
+
/**
|
|
9401
|
+
* Setup the netchan with specific settings
|
|
9402
|
+
*/
|
|
9403
|
+
setup(qport, address = null) {
|
|
9404
|
+
this.qport = qport;
|
|
9405
|
+
this.remoteAddress = address;
|
|
9406
|
+
this.reset();
|
|
9407
|
+
}
|
|
9408
|
+
/**
|
|
9409
|
+
* Reset the netchan state
|
|
9410
|
+
*/
|
|
9411
|
+
reset() {
|
|
9412
|
+
this.incomingSequence = 0;
|
|
9413
|
+
this.outgoingSequence = 0;
|
|
9414
|
+
this.incomingAcknowledged = 0;
|
|
9415
|
+
this.incomingReliableAcknowledged = false;
|
|
9416
|
+
this.incomingReliableSequence = 0;
|
|
9417
|
+
this.outgoingReliableSequence = 0;
|
|
9418
|
+
this.reliableLength = 0;
|
|
9419
|
+
this.reliableMessage.reset();
|
|
9420
|
+
this.lastReceived = Date.now();
|
|
9421
|
+
this.lastSent = Date.now();
|
|
9422
|
+
}
|
|
9423
|
+
/**
|
|
9424
|
+
* Transmits a packet containing reliable and unreliable data
|
|
9425
|
+
*/
|
|
9426
|
+
transmit(unreliableData) {
|
|
9427
|
+
this.outgoingSequence++;
|
|
9428
|
+
this.lastSent = Date.now();
|
|
9429
|
+
const headerSize = _NetChan4.PACKET_HEADER;
|
|
9430
|
+
const reliableSize = this.reliableLength > 0 ? this.reliableLength + 2 : 0;
|
|
9431
|
+
let unreliableSize = unreliableData ? unreliableData.length : 0;
|
|
9432
|
+
if (headerSize + reliableSize + unreliableSize > _NetChan4.MAX_MSGLEN) {
|
|
9433
|
+
unreliableSize = _NetChan4.MAX_MSGLEN - headerSize - reliableSize;
|
|
9434
|
+
if (unreliableSize < 0) unreliableSize = 0;
|
|
9435
|
+
}
|
|
9436
|
+
const buffer = new ArrayBuffer(headerSize + reliableSize + unreliableSize);
|
|
9437
|
+
const view = new DataView(buffer);
|
|
9438
|
+
const result = new Uint8Array(buffer);
|
|
9439
|
+
let sequence = this.outgoingSequence;
|
|
9440
|
+
if (this.reliableLength > 0) {
|
|
9441
|
+
sequence |= 2147483648;
|
|
9442
|
+
if ((this.outgoingReliableSequence & 1) !== 0) {
|
|
9443
|
+
sequence |= 1073741824;
|
|
9444
|
+
}
|
|
9445
|
+
}
|
|
9446
|
+
view.setUint32(0, sequence, true);
|
|
9447
|
+
let ack = this.incomingSequence;
|
|
9448
|
+
if ((this.incomingReliableSequence & 1) !== 0) {
|
|
9449
|
+
ack |= 2147483648;
|
|
9450
|
+
}
|
|
9451
|
+
view.setUint32(4, ack, true);
|
|
9452
|
+
view.setUint16(8, this.qport, true);
|
|
9453
|
+
let offset = headerSize;
|
|
9454
|
+
if (this.reliableLength > 0) {
|
|
9455
|
+
view.setUint16(offset, this.reliableLength, true);
|
|
9456
|
+
offset += 2;
|
|
9457
|
+
const reliableBuffer = this.reliableMessage.getBuffer();
|
|
9458
|
+
const reliableBytes = reliableBuffer.subarray(0, this.reliableLength);
|
|
9459
|
+
result.set(reliableBytes, offset);
|
|
9460
|
+
offset += this.reliableLength;
|
|
9461
|
+
}
|
|
9462
|
+
if (unreliableData && unreliableSize > 0) {
|
|
9463
|
+
const chunk = unreliableData.slice(0, unreliableSize);
|
|
9464
|
+
result.set(chunk, offset);
|
|
9465
|
+
}
|
|
9466
|
+
return result;
|
|
9467
|
+
}
|
|
9468
|
+
/**
|
|
9469
|
+
* Processes a received packet
|
|
9470
|
+
* Returns the payload data (reliable + unreliable) to be processed, or null if discarded
|
|
9471
|
+
*/
|
|
9472
|
+
process(packet) {
|
|
9473
|
+
if (packet.length < _NetChan4.PACKET_HEADER) {
|
|
9474
|
+
return null;
|
|
9475
|
+
}
|
|
9476
|
+
this.lastReceived = Date.now();
|
|
9477
|
+
const view = new DataView(packet.buffer, packet.byteOffset, packet.byteLength);
|
|
9478
|
+
const sequence = view.getUint32(0, true);
|
|
9479
|
+
const ack = view.getUint32(4, true);
|
|
9480
|
+
const qport = view.getUint16(8, true);
|
|
9481
|
+
if (this.qport !== qport) {
|
|
9482
|
+
return null;
|
|
9483
|
+
}
|
|
9484
|
+
const seqNumberClean = sequence & ~(2147483648 | 1073741824);
|
|
9485
|
+
if ((seqNumberClean - this.incomingSequence | 0) <= 0) {
|
|
9486
|
+
return null;
|
|
9487
|
+
}
|
|
9488
|
+
this.incomingSequence = seqNumberClean;
|
|
9489
|
+
const ackNumber = ack & ~2147483648;
|
|
9490
|
+
const ackReliable = (ack & 2147483648) !== 0;
|
|
9491
|
+
if (ackNumber > this.incomingAcknowledged) {
|
|
9492
|
+
this.incomingAcknowledged = ackNumber;
|
|
9493
|
+
}
|
|
9494
|
+
if (this.reliableLength > 0) {
|
|
9495
|
+
const receivedAckBit = ackReliable ? 1 : 0;
|
|
9496
|
+
const currentReliableBit = this.outgoingReliableSequence & 1;
|
|
9497
|
+
if (receivedAckBit !== currentReliableBit) {
|
|
9498
|
+
this.reliableLength = 0;
|
|
9499
|
+
this.reliableMessage.reset();
|
|
9500
|
+
this.outgoingReliableSequence ^= 1;
|
|
9501
|
+
}
|
|
9502
|
+
}
|
|
9503
|
+
const hasReliableData = (sequence & 2147483648) !== 0;
|
|
9504
|
+
const reliableSeqBit = (sequence & 1073741824) !== 0 ? 1 : 0;
|
|
9505
|
+
let payloadOffset = _NetChan4.PACKET_HEADER;
|
|
9506
|
+
let reliableData = null;
|
|
9507
|
+
if (hasReliableData) {
|
|
9508
|
+
if (payloadOffset + 2 > packet.byteLength) return null;
|
|
9509
|
+
const reliableLen = view.getUint16(payloadOffset, true);
|
|
9510
|
+
payloadOffset += 2;
|
|
9511
|
+
const expectedBit = this.incomingReliableSequence & 1;
|
|
9512
|
+
if (reliableSeqBit === expectedBit) {
|
|
9513
|
+
this.incomingReliableSequence++;
|
|
9514
|
+
if (payloadOffset + reliableLen > packet.byteLength) return null;
|
|
9515
|
+
reliableData = packet.slice(payloadOffset, payloadOffset + reliableLen);
|
|
9516
|
+
}
|
|
9517
|
+
payloadOffset += reliableLen;
|
|
9518
|
+
}
|
|
9519
|
+
const unreliableData = packet.slice(payloadOffset);
|
|
9520
|
+
if (reliableData && reliableData.length > 0) {
|
|
9521
|
+
const totalLen = reliableData.length + unreliableData.length;
|
|
9522
|
+
const result = new Uint8Array(totalLen);
|
|
9523
|
+
result.set(reliableData, 0);
|
|
9524
|
+
result.set(unreliableData, reliableData.length);
|
|
9525
|
+
return result;
|
|
9526
|
+
}
|
|
9527
|
+
if (unreliableData) {
|
|
9528
|
+
return unreliableData;
|
|
9529
|
+
}
|
|
9530
|
+
return new Uint8Array(0);
|
|
9531
|
+
}
|
|
9532
|
+
/**
|
|
9533
|
+
* Checks if reliable message buffer is empty and ready for new data
|
|
9534
|
+
*/
|
|
9535
|
+
canSendReliable() {
|
|
9536
|
+
return this.reliableLength === 0;
|
|
9537
|
+
}
|
|
9538
|
+
/**
|
|
9539
|
+
* Writes a byte to the reliable message buffer
|
|
9540
|
+
*/
|
|
9541
|
+
writeReliableByte(value) {
|
|
9542
|
+
if (this.reliableLength + 1 > _NetChan4.MAX_MSGLEN - _NetChan4.HEADER_OVERHEAD) {
|
|
9543
|
+
throw new Error("NetChan reliable buffer overflow");
|
|
9544
|
+
}
|
|
9545
|
+
this.reliableMessage.writeByte(value);
|
|
9546
|
+
this.reliableLength++;
|
|
9547
|
+
}
|
|
9548
|
+
/**
|
|
9549
|
+
* Writes a short to the reliable message buffer
|
|
9550
|
+
*/
|
|
9551
|
+
writeReliableShort(value) {
|
|
9552
|
+
if (this.reliableLength + 2 > _NetChan4.MAX_MSGLEN - _NetChan4.HEADER_OVERHEAD) {
|
|
9553
|
+
throw new Error("NetChan reliable buffer overflow");
|
|
9554
|
+
}
|
|
9555
|
+
this.reliableMessage.writeShort(value);
|
|
9556
|
+
this.reliableLength += 2;
|
|
9557
|
+
}
|
|
9558
|
+
/**
|
|
9559
|
+
* Writes a long to the reliable message buffer
|
|
9560
|
+
*/
|
|
9561
|
+
writeReliableLong(value) {
|
|
9562
|
+
if (this.reliableLength + 4 > _NetChan4.MAX_MSGLEN - _NetChan4.HEADER_OVERHEAD) {
|
|
9563
|
+
throw new Error("NetChan reliable buffer overflow");
|
|
9564
|
+
}
|
|
9565
|
+
this.reliableMessage.writeLong(value);
|
|
9566
|
+
this.reliableLength += 4;
|
|
9567
|
+
}
|
|
9568
|
+
/**
|
|
9569
|
+
* Writes a string to the reliable message buffer
|
|
9570
|
+
*/
|
|
9571
|
+
writeReliableString(value) {
|
|
9572
|
+
const len2 = value.length + 1;
|
|
9573
|
+
if (this.reliableLength + len2 > _NetChan4.MAX_MSGLEN - _NetChan4.HEADER_OVERHEAD) {
|
|
9574
|
+
throw new Error("NetChan reliable buffer overflow");
|
|
9575
|
+
}
|
|
9576
|
+
this.reliableMessage.writeString(value);
|
|
9577
|
+
this.reliableLength += len2;
|
|
9578
|
+
}
|
|
9579
|
+
/**
|
|
9580
|
+
* Returns the current reliable data buffer
|
|
9581
|
+
*/
|
|
9582
|
+
getReliableData() {
|
|
9583
|
+
if (this.reliableLength === 0) {
|
|
9584
|
+
return new Uint8Array(0);
|
|
9585
|
+
}
|
|
9586
|
+
const buffer = this.reliableMessage.getBuffer();
|
|
9587
|
+
return buffer.subarray(0, this.reliableLength);
|
|
9588
|
+
}
|
|
9589
|
+
/**
|
|
9590
|
+
* Checks if we need to send a keepalive packet
|
|
9591
|
+
*/
|
|
9592
|
+
needsKeepalive(currentTime) {
|
|
9593
|
+
return currentTime - this.lastSent > 1e3;
|
|
9594
|
+
}
|
|
9595
|
+
/**
|
|
9596
|
+
* Checks if the connection has timed out
|
|
9597
|
+
*/
|
|
9598
|
+
isTimedOut(currentTime, timeoutMs = 3e4) {
|
|
9599
|
+
return currentTime - this.lastReceived > timeoutMs;
|
|
9600
|
+
}
|
|
9601
|
+
};
|
|
9602
|
+
_NetChan3.MAX_MSGLEN = 1400;
|
|
9603
|
+
_NetChan3.FRAGMENT_SIZE = 1024;
|
|
9604
|
+
_NetChan3.PACKET_HEADER = 10;
|
|
9605
|
+
_NetChan3.HEADER_OVERHEAD = _NetChan3.PACKET_HEADER + 2;
|
|
9054
9606
|
var AmmoType2 = /* @__PURE__ */ ((AmmoType22) => {
|
|
9055
9607
|
AmmoType22[AmmoType22["Bullets"] = 0] = "Bullets";
|
|
9056
9608
|
AmmoType22[AmmoType22["Shells"] = 1] = "Shells";
|
|
@@ -9589,6 +10141,91 @@ var DEMO_ITEM_MAPPING = [
|
|
|
9589
10141
|
// IT_ITEM_COMPASS
|
|
9590
10142
|
];
|
|
9591
10143
|
|
|
10144
|
+
// src/entities.ts
|
|
10145
|
+
function lerp2(a, b, t) {
|
|
10146
|
+
return a + (b - a) * t;
|
|
10147
|
+
}
|
|
10148
|
+
function lerpAngle(a, b, t) {
|
|
10149
|
+
return lerp2(a, b, t);
|
|
10150
|
+
}
|
|
10151
|
+
function buildRenderableEntities(latestEntities, previousEntities, alpha, configStrings, imports) {
|
|
10152
|
+
const renderables = [];
|
|
10153
|
+
const assets = imports.engine.assets;
|
|
10154
|
+
if (!assets) return renderables;
|
|
10155
|
+
let prevMap;
|
|
10156
|
+
if (previousEntities instanceof Map) {
|
|
10157
|
+
prevMap = previousEntities;
|
|
10158
|
+
} else {
|
|
10159
|
+
prevMap = new Map(previousEntities.map((e) => [e.number, e]));
|
|
10160
|
+
}
|
|
10161
|
+
for (const ent of latestEntities) {
|
|
10162
|
+
const prev = prevMap.get(ent.number) ?? ent;
|
|
10163
|
+
const modelIndex = ent.modelIndex ?? ent.modelindex;
|
|
10164
|
+
const skinNum = ent.skinNum ?? ent.skinnum;
|
|
10165
|
+
if (modelIndex === void 0) continue;
|
|
10166
|
+
const modelName = configStrings.getModelName(modelIndex);
|
|
10167
|
+
if (!modelName) continue;
|
|
10168
|
+
const model = assets.getMd2Model(modelName) || assets.getMd3Model(modelName);
|
|
10169
|
+
if (!model) continue;
|
|
10170
|
+
const origin = {
|
|
10171
|
+
x: lerp2(prev.origin.x, ent.origin.x, alpha),
|
|
10172
|
+
y: lerp2(prev.origin.y, ent.origin.y, alpha),
|
|
10173
|
+
z: lerp2(prev.origin.z, ent.origin.z, alpha)
|
|
10174
|
+
};
|
|
10175
|
+
const angles = {
|
|
10176
|
+
x: lerpAngle(prev.angles.x, ent.angles.x, alpha),
|
|
10177
|
+
y: lerpAngle(prev.angles.y, ent.angles.y, alpha),
|
|
10178
|
+
z: lerpAngle(prev.angles.z, ent.angles.z, alpha)
|
|
10179
|
+
};
|
|
10180
|
+
const frame = ent.frame;
|
|
10181
|
+
const prevFrame = prev.frame;
|
|
10182
|
+
const scaleA = prev.scale !== void 0 ? prev.scale : 1;
|
|
10183
|
+
const scaleB = ent.scale !== void 0 ? ent.scale : 1;
|
|
10184
|
+
const scale3 = lerp2(scaleA, scaleB, alpha);
|
|
10185
|
+
const getAlpha = (val) => val === void 0 || val === 0 ? 255 : val;
|
|
10186
|
+
const alphaA = getAlpha(prev.alpha);
|
|
10187
|
+
const alphaB = getAlpha(ent.alpha);
|
|
10188
|
+
const alphaVal = lerp2(alphaA, alphaB, alpha);
|
|
10189
|
+
const normalizedAlpha = alphaVal / 255;
|
|
10190
|
+
const mat = mat4_exports.create();
|
|
10191
|
+
mat4_exports.translate(mat, mat, [origin.x, origin.y, origin.z]);
|
|
10192
|
+
mat4_exports.rotateZ(mat, mat, angles.z * Math.PI / 180);
|
|
10193
|
+
mat4_exports.rotateY(mat, mat, angles.y * Math.PI / 180);
|
|
10194
|
+
mat4_exports.rotateX(mat, mat, angles.x * Math.PI / 180);
|
|
10195
|
+
mat4_exports.scale(mat, mat, [scale3, scale3, scale3]);
|
|
10196
|
+
const skinName = skinNum !== void 0 && skinNum > 0 ? configStrings.getImageName(skinNum) : void 0;
|
|
10197
|
+
if (model.header.magic === 844121161) {
|
|
10198
|
+
renderables.push({
|
|
10199
|
+
type: "md2",
|
|
10200
|
+
model,
|
|
10201
|
+
// Cast to Md2Model
|
|
10202
|
+
blend: {
|
|
10203
|
+
frame0: prevFrame,
|
|
10204
|
+
frame1: frame,
|
|
10205
|
+
lerp: alpha
|
|
10206
|
+
},
|
|
10207
|
+
transform: mat,
|
|
10208
|
+
skin: skinName,
|
|
10209
|
+
alpha: normalizedAlpha
|
|
10210
|
+
});
|
|
10211
|
+
} else if (model.header.magic === 860898377) {
|
|
10212
|
+
renderables.push({
|
|
10213
|
+
type: "md3",
|
|
10214
|
+
model,
|
|
10215
|
+
blend: {
|
|
10216
|
+
frame0: prevFrame,
|
|
10217
|
+
frame1: frame,
|
|
10218
|
+
lerp: alpha
|
|
10219
|
+
},
|
|
10220
|
+
transform: mat,
|
|
10221
|
+
alpha: normalizedAlpha
|
|
10222
|
+
// Lighting? Skins?
|
|
10223
|
+
});
|
|
10224
|
+
}
|
|
10225
|
+
}
|
|
10226
|
+
return renderables;
|
|
10227
|
+
}
|
|
10228
|
+
|
|
9592
10229
|
// src/demo/handler.ts
|
|
9593
10230
|
var MAX_CONFIGSTRINGS3 = 32768;
|
|
9594
10231
|
var ClientNetworkHandler = class {
|
|
@@ -9596,6 +10233,8 @@ var ClientNetworkHandler = class {
|
|
|
9596
10233
|
this.configstrings = new Array(MAX_CONFIGSTRINGS3).fill("");
|
|
9597
10234
|
this.entities = /* @__PURE__ */ new Map();
|
|
9598
10235
|
// Current frame entities
|
|
10236
|
+
this.previousEntities = /* @__PURE__ */ new Map();
|
|
10237
|
+
// Previous frame entities
|
|
9599
10238
|
this.baselines = /* @__PURE__ */ new Map();
|
|
9600
10239
|
this.previousFrame = null;
|
|
9601
10240
|
this.latestFrame = null;
|
|
@@ -9619,8 +10258,10 @@ var ClientNetworkHandler = class {
|
|
|
9619
10258
|
console.log(`Demo: Server Data - Protocol: ${protocol}, Level: ${levelName}, Tick: ${tickRate ?? 10}`);
|
|
9620
10259
|
this.configstrings.fill("");
|
|
9621
10260
|
this.entities.clear();
|
|
10261
|
+
this.previousEntities.clear();
|
|
9622
10262
|
this.baselines.clear();
|
|
9623
10263
|
this.latestFrame = null;
|
|
10264
|
+
this.previousFrame = null;
|
|
9624
10265
|
this.playerNum = playerNum;
|
|
9625
10266
|
if (this.callbacks?.onServerData) {
|
|
9626
10267
|
this.callbacks.onServerData(protocol, tickRate);
|
|
@@ -9638,6 +10279,7 @@ var ClientNetworkHandler = class {
|
|
|
9638
10279
|
onFrame(frame) {
|
|
9639
10280
|
if (this.latestFrame) {
|
|
9640
10281
|
this.previousFrame = this.latestFrame;
|
|
10282
|
+
this.previousEntities = this.entities;
|
|
9641
10283
|
}
|
|
9642
10284
|
this.latestFrame = frame;
|
|
9643
10285
|
this.stats = [...frame.playerState.stats];
|
|
@@ -9948,7 +10590,10 @@ var ClientNetworkHandler = class {
|
|
|
9948
10590
|
if (this.previousFrame && timeMs !== void 0) {
|
|
9949
10591
|
const latestServerTime = this.latestFrame.serverFrame * 100;
|
|
9950
10592
|
const previousServerTime = this.previousFrame.serverFrame * 100;
|
|
9951
|
-
if (timeMs
|
|
10593
|
+
if (timeMs <= 1) {
|
|
10594
|
+
const previousState = this.convertFrameToPredictionState(this.previousFrame);
|
|
10595
|
+
return (0, import_cgame.interpolatePredictionState)(previousState, latestState, Math.max(0, Math.min(1, timeMs)));
|
|
10596
|
+
} else if (timeMs >= previousServerTime && timeMs <= latestServerTime) {
|
|
9952
10597
|
const alpha = (timeMs - previousServerTime) / (latestServerTime - previousServerTime);
|
|
9953
10598
|
const previousState = this.convertFrameToPredictionState(this.previousFrame);
|
|
9954
10599
|
return (0, import_cgame.interpolatePredictionState)(previousState, latestState, Math.max(0, Math.min(1, alpha)));
|
|
@@ -9956,6 +10601,27 @@ var ClientNetworkHandler = class {
|
|
|
9956
10601
|
}
|
|
9957
10602
|
return latestState;
|
|
9958
10603
|
}
|
|
10604
|
+
getRenderableEntities(alpha, configStrings) {
|
|
10605
|
+
if (!this.latestFrame) return [];
|
|
10606
|
+
if (!this.imports) return [];
|
|
10607
|
+
const latest = Array.from(this.entities.values());
|
|
10608
|
+
const previous = this.previousEntities.size > 0 ? this.previousEntities : latest;
|
|
10609
|
+
return buildRenderableEntities(
|
|
10610
|
+
latest,
|
|
10611
|
+
previous,
|
|
10612
|
+
alpha,
|
|
10613
|
+
configStrings,
|
|
10614
|
+
this.imports
|
|
10615
|
+
);
|
|
10616
|
+
}
|
|
10617
|
+
getDemoCamera(alpha) {
|
|
10618
|
+
const ps = this.getPredictionState(alpha);
|
|
10619
|
+
return {
|
|
10620
|
+
origin: ps.origin,
|
|
10621
|
+
angles: ps.viewAngles,
|
|
10622
|
+
fov: ps.fov ?? 90
|
|
10623
|
+
};
|
|
10624
|
+
}
|
|
9959
10625
|
get latestServerFrame() {
|
|
9960
10626
|
return this.latestFrame?.serverFrame ?? 0;
|
|
9961
10627
|
}
|
|
@@ -10874,82 +11540,6 @@ var WheelMenuSystem = class {
|
|
|
10874
11540
|
}
|
|
10875
11541
|
};
|
|
10876
11542
|
|
|
10877
|
-
// src/entities.ts
|
|
10878
|
-
function lerp2(a, b, t) {
|
|
10879
|
-
return a + (b - a) * t;
|
|
10880
|
-
}
|
|
10881
|
-
function lerpAngle(a, b, t) {
|
|
10882
|
-
return lerp2(a, b, t);
|
|
10883
|
-
}
|
|
10884
|
-
function buildRenderableEntities(latestEntities, previousEntities, alpha, configStrings, imports) {
|
|
10885
|
-
const renderables = [];
|
|
10886
|
-
const assets = imports.engine.assets;
|
|
10887
|
-
if (!assets) return renderables;
|
|
10888
|
-
const prevMap = new Map(previousEntities.map((e) => [e.number, e]));
|
|
10889
|
-
for (const ent of latestEntities) {
|
|
10890
|
-
const prev = prevMap.get(ent.number) ?? ent;
|
|
10891
|
-
const modelName = configStrings.getModelName(ent.modelIndex);
|
|
10892
|
-
if (!modelName) continue;
|
|
10893
|
-
const model = assets.getMd2Model(modelName) || assets.getMd3Model(modelName);
|
|
10894
|
-
if (!model) continue;
|
|
10895
|
-
const origin = {
|
|
10896
|
-
x: lerp2(prev.origin.x, ent.origin.x, alpha),
|
|
10897
|
-
y: lerp2(prev.origin.y, ent.origin.y, alpha),
|
|
10898
|
-
z: lerp2(prev.origin.z, ent.origin.z, alpha)
|
|
10899
|
-
};
|
|
10900
|
-
const angles = {
|
|
10901
|
-
x: lerpAngle(prev.angles.x, ent.angles.x, alpha),
|
|
10902
|
-
y: lerpAngle(prev.angles.y, ent.angles.y, alpha),
|
|
10903
|
-
z: lerpAngle(prev.angles.z, ent.angles.z, alpha)
|
|
10904
|
-
};
|
|
10905
|
-
const frame = ent.frame;
|
|
10906
|
-
const prevFrame = prev.frame;
|
|
10907
|
-
const scaleA = prev.scale !== void 0 ? prev.scale : 1;
|
|
10908
|
-
const scaleB = ent.scale !== void 0 ? ent.scale : 1;
|
|
10909
|
-
const scale3 = lerp2(scaleA, scaleB, alpha);
|
|
10910
|
-
const getAlpha = (val) => val === void 0 || val === 0 ? 255 : val;
|
|
10911
|
-
const alphaA = getAlpha(prev.alpha);
|
|
10912
|
-
const alphaB = getAlpha(ent.alpha);
|
|
10913
|
-
const alphaVal = lerp2(alphaA, alphaB, alpha);
|
|
10914
|
-
const normalizedAlpha = alphaVal / 255;
|
|
10915
|
-
const mat = mat4_exports.create();
|
|
10916
|
-
mat4_exports.translate(mat, mat, [origin.x, origin.y, origin.z]);
|
|
10917
|
-
mat4_exports.rotateZ(mat, mat, angles.z * Math.PI / 180);
|
|
10918
|
-
mat4_exports.rotateY(mat, mat, angles.y * Math.PI / 180);
|
|
10919
|
-
mat4_exports.rotateX(mat, mat, angles.x * Math.PI / 180);
|
|
10920
|
-
mat4_exports.scale(mat, mat, [scale3, scale3, scale3]);
|
|
10921
|
-
if (model.header.magic === 844121161) {
|
|
10922
|
-
renderables.push({
|
|
10923
|
-
type: "md2",
|
|
10924
|
-
model,
|
|
10925
|
-
// Cast to Md2Model
|
|
10926
|
-
blend: {
|
|
10927
|
-
frame0: prevFrame,
|
|
10928
|
-
frame1: frame,
|
|
10929
|
-
lerp: alpha
|
|
10930
|
-
},
|
|
10931
|
-
transform: mat,
|
|
10932
|
-
skin: ent.skinNum > 0 ? configStrings.getImageName(ent.skinNum) : void 0,
|
|
10933
|
-
alpha: normalizedAlpha
|
|
10934
|
-
});
|
|
10935
|
-
} else if (model.header.magic === 860898377) {
|
|
10936
|
-
renderables.push({
|
|
10937
|
-
type: "md3",
|
|
10938
|
-
model,
|
|
10939
|
-
blend: {
|
|
10940
|
-
frame0: prevFrame,
|
|
10941
|
-
frame1: frame,
|
|
10942
|
-
lerp: alpha
|
|
10943
|
-
},
|
|
10944
|
-
transform: mat,
|
|
10945
|
-
alpha: normalizedAlpha
|
|
10946
|
-
// Lighting? Skins?
|
|
10947
|
-
});
|
|
10948
|
-
}
|
|
10949
|
-
}
|
|
10950
|
-
return renderables;
|
|
10951
|
-
}
|
|
10952
|
-
|
|
10953
11543
|
// src/net/browserWsDriver.ts
|
|
10954
11544
|
var BrowserWebSocketNetDriver = class {
|
|
10955
11545
|
constructor() {
|
|
@@ -11080,7 +11670,7 @@ var MultiplayerConnection = class {
|
|
|
11080
11670
|
if (this.commandHistory.length > CMD_BACKUP) {
|
|
11081
11671
|
this.commandHistory.shift();
|
|
11082
11672
|
}
|
|
11083
|
-
const writer = new
|
|
11673
|
+
const writer = new BinaryWriter2();
|
|
11084
11674
|
writer.writeLong(0);
|
|
11085
11675
|
writer.writeLong(0);
|
|
11086
11676
|
writer.writeByte(ClientCommand.move);
|