quake2ts 0.0.173 → 0.0.175

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.
@@ -47,6 +47,7 @@ export interface GameStateSnapshot {
47
47
  readonly damageAlpha: number;
48
48
  readonly damageIndicators: any[];
49
49
  }
50
+ import { UserCommand } from '@quake2ts/shared';
50
51
  import { Entity } from './entities/entity.js';
51
52
  import { GameTraceResult } from './imports.js';
52
53
  export interface GameExports extends GameSimulation<GameStateSnapshot> {
@@ -56,12 +57,14 @@ export interface GameExports extends GameSimulation<GameStateSnapshot> {
56
57
  centerprintf(entity: Entity, message: string): void;
57
58
  readonly time: number;
58
59
  readonly deathmatch: boolean;
60
+ readonly random: RandomGenerator;
59
61
  trace(start: Vec3, mins: Vec3 | null, maxs: Vec3 | null, end: Vec3, passent: Entity | null, contentmask: number): GameTraceResult;
60
62
  multicast(origin: Vec3, type: MulticastType, event: ServerCommand, ...args: any[]): void;
61
63
  unicast(ent: Entity, reliable: boolean, event: ServerCommand, ...args: any[]): void;
62
64
  createSave(mapName: string, difficulty: number, playtimeSeconds: number): GameSaveFile;
63
65
  loadSave(save: GameSaveFile): void;
64
66
  clientBegin(client: PlayerClient): Entity;
67
+ clientThink(ent: Entity, cmd: UserCommand): void;
65
68
  }
66
69
  export { hashGameState, hashEntitySystem } from './checksum.js';
67
70
  export * from './save/index.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,cAAc,EAEf,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,OAAO,EAAc,KAAK,eAAe,EAAE,MAAM,YAAY,CAAC;AAC9D,OAAO,EAAiC,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC9E,OAAO,EA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AClI,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,aAAa,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IACzF,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IACpF,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,YAAY,CAAC;IACvF,QAAQ,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI,CAAC;IACnC,WAAW,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM,CAAC;IAC1C,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,WAAW,GAAG,IAAI,CAAC;CAClD;AAED,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAChE,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,OAAO,EAAyB,YAAY,EAAa,MAAM,sBAAsB,CAAC;AAItF,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAI7D,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,YAAY,EAAE,WAAW,EAAE,CAAC;AAE5B,wBAAgB,UAAU,CACxB,EAAE,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,OAAO,EAAE,EAAE,WAAW,EACzD,MAAM,EAAE,UAAU,EAClB,OAAO,EAAE,iBAAiB,GACzB,WAAW,CAuTb"}
@@ -262,35 +262,41 @@ var DedicatedServer = class {
262
262
  constructor(port = 27910) {
263
263
  this.port = port;
264
264
  this.wss = null;
265
- this.clients = new Array(MAX_CLIENTS).fill(null);
266
265
  this.game = null;
267
266
  this.frameInterval = null;
268
- this.startTime = 0;
269
- this.frameCount = 0;
270
- // Physics
271
- this.collisionModel = null;
267
+ this.svs = {
268
+ clients: new Array(MAX_CLIENTS).fill(null)
269
+ };
270
+ this.sv = {
271
+ startTime: 0,
272
+ time: 0,
273
+ frame: 0,
274
+ mapName: "",
275
+ collisionModel: null
276
+ };
272
277
  }
273
278
  async start(mapName) {
274
279
  console.log(`Starting Dedicated Server on port ${this.port}...`);
280
+ this.sv.mapName = mapName;
275
281
  this.wss = new import_ws2.WebSocketServer({ port: this.port });
276
282
  this.wss.on("connection", (ws) => {
277
283
  console.log("New connection");
278
284
  this.handleConnection(ws);
279
285
  });
280
286
  try {
281
- console.log(`Loading map ${mapName}...`);
282
- const mapData = await import_promises.default.readFile(mapName);
287
+ console.log(`Loading map ${this.sv.mapName}...`);
288
+ const mapData = await import_promises.default.readFile(this.sv.mapName);
283
289
  const arrayBuffer = mapData.buffer.slice(mapData.byteOffset, mapData.byteOffset + mapData.byteLength);
284
290
  const bspMap = (0, import_engine.parseBsp)(arrayBuffer);
285
- this.collisionModel = bspMap;
291
+ this.sv.collisionModel = bspMap;
286
292
  console.log(`Map loaded successfully.`);
287
293
  } catch (e) {
288
294
  console.warn("Failed to load map:", e);
289
295
  }
290
- this.startTime = Date.now();
296
+ this.sv.startTime = Date.now();
291
297
  const imports = {
292
298
  trace: (start, mins, maxs, end, passent, contentmask) => {
293
- if (!this.collisionModel) {
299
+ if (!this.sv.collisionModel) {
294
300
  return {
295
301
  fraction: 1,
296
302
  endpos: { ...end },
@@ -307,7 +313,7 @@ var DedicatedServer = class {
307
313
  end,
308
314
  mins: mins || void 0,
309
315
  maxs: maxs || void 0,
310
- model: this.collisionModel
316
+ model: this.sv.collisionModel
311
317
  });
312
318
  return {
313
319
  allsolid: result.allsolid,
@@ -347,7 +353,7 @@ var DedicatedServer = class {
347
353
  handleConnection(ws) {
348
354
  let clientIndex = -1;
349
355
  for (let i = 0; i < MAX_CLIENTS; i++) {
350
- if (this.clients[i] === null || this.clients[i].state === 0 /* Free */) {
356
+ if (this.svs.clients[i] === null || this.svs.clients[i].state === 0 /* Free */) {
351
357
  clientIndex = i;
352
358
  break;
353
359
  }
@@ -359,7 +365,7 @@ var DedicatedServer = class {
359
365
  const driver = new WebSocketNetDriver();
360
366
  driver.attach(ws);
361
367
  const client = createClient(clientIndex, driver);
362
- this.clients[clientIndex] = client;
368
+ this.svs.clients[clientIndex] = client;
363
369
  driver.onMessage((data) => this.onClientMessage(client, data));
364
370
  driver.onClose(() => this.onClientDisconnect(client));
365
371
  }
@@ -381,7 +387,7 @@ var DedicatedServer = class {
381
387
  }
382
388
  onClientDisconnect(client) {
383
389
  console.log(`Client ${client.index} disconnected`);
384
- this.clients[client.index] = null;
390
+ this.svs.clients[client.index] = null;
385
391
  }
386
392
  handleMove(client, cmd) {
387
393
  client.lastCmd = cmd;
@@ -410,34 +416,42 @@ var DedicatedServer = class {
410
416
  const writer = new import_shared2.BinaryWriter();
411
417
  writer.writeByte(import_shared2.ServerCommand.serverdata);
412
418
  writer.writeLong(34);
413
- writer.writeLong(this.frameCount);
419
+ writer.writeLong(this.sv.frame);
414
420
  writer.writeByte(0);
415
421
  writer.writeString("baseq2");
416
422
  writer.writeShort(client.index);
417
423
  writer.writeString("maps/test.bsp");
418
424
  client.net.send(writer.getData());
419
425
  }
426
+ SV_ReadPackets() {
427
+ }
420
428
  runFrame() {
421
429
  if (!this.game) return;
422
- this.frameCount++;
430
+ this.sv.frame++;
431
+ this.SV_ReadPackets();
432
+ for (const client of this.svs.clients) {
433
+ if (client && client.state === 3 /* Active */ && client.edict) {
434
+ this.game.clientThink(client.edict, client.lastCmd);
435
+ }
436
+ }
423
437
  this.game.frame({
424
- frame: this.frameCount,
438
+ frame: this.sv.frame,
425
439
  deltaMs: FRAME_TIME_MS,
426
440
  nowMs: Date.now()
427
441
  });
428
- this.sendClientMessages();
442
+ this.SV_SendClientMessages();
429
443
  }
430
- sendClientMessages() {
431
- for (const client of this.clients) {
444
+ SV_SendClientMessages() {
445
+ for (const client of this.svs.clients) {
432
446
  if (client && client.state === 3 /* Active */) {
433
- this.sendClientFrame(client);
447
+ this.SV_SendClientFrame(client);
434
448
  }
435
449
  }
436
450
  }
437
- sendClientFrame(client) {
451
+ SV_SendClientFrame(client) {
438
452
  const writer = new import_shared2.BinaryWriter();
439
453
  writer.writeByte(import_shared2.ServerCommand.frame);
440
- writer.writeLong(this.frameCount);
454
+ writer.writeLong(this.sv.frame);
441
455
  writer.writeLong(0);
442
456
  writer.writeByte(0);
443
457
  writer.writeByte(0);
@@ -453,7 +467,7 @@ var DedicatedServer = class {
453
467
  multicast(origin, type, event, ...args) {
454
468
  }
455
469
  unicast(ent, reliable, event, ...args) {
456
- const client = this.clients.find((c) => c?.edict === ent);
470
+ const client = this.svs.clients.find((c) => c?.edict === ent);
457
471
  if (client) {
458
472
  }
459
473
  }
@@ -20,12 +20,10 @@ declare class WebSocketNetDriver implements NetDriver {
20
20
  declare class DedicatedServer implements GameEngine {
21
21
  private port;
22
22
  private wss;
23
- private clients;
23
+ private svs;
24
+ private sv;
24
25
  private game;
25
26
  private frameInterval;
26
- private startTime;
27
- private frameCount;
28
- private collisionModel;
29
27
  constructor(port?: number);
30
28
  start(mapName: string): Promise<void>;
31
29
  stop(): void;
@@ -37,9 +35,10 @@ declare class DedicatedServer implements GameEngine {
37
35
  private handleStringCmd;
38
36
  private spawnClient;
39
37
  private sendServerData;
38
+ private SV_ReadPackets;
40
39
  private runFrame;
41
- private sendClientMessages;
42
- private sendClientFrame;
40
+ private SV_SendClientMessages;
41
+ private SV_SendClientFrame;
43
42
  trace(start: any, end: any): any;
44
43
  multicast(origin: any, type: MulticastType, event: ServerCommand, ...args: any[]): void;
45
44
  unicast(ent: Entity, reliable: boolean, event: ServerCommand, ...args: any[]): void;
@@ -20,12 +20,10 @@ declare class WebSocketNetDriver implements NetDriver {
20
20
  declare class DedicatedServer implements GameEngine {
21
21
  private port;
22
22
  private wss;
23
- private clients;
23
+ private svs;
24
+ private sv;
24
25
  private game;
25
26
  private frameInterval;
26
- private startTime;
27
- private frameCount;
28
- private collisionModel;
29
27
  constructor(port?: number);
30
28
  start(mapName: string): Promise<void>;
31
29
  stop(): void;
@@ -37,9 +35,10 @@ declare class DedicatedServer implements GameEngine {
37
35
  private handleStringCmd;
38
36
  private spawnClient;
39
37
  private sendServerData;
38
+ private SV_ReadPackets;
40
39
  private runFrame;
41
- private sendClientMessages;
42
- private sendClientFrame;
40
+ private SV_SendClientMessages;
41
+ private SV_SendClientFrame;
43
42
  trace(start: any, end: any): any;
44
43
  multicast(origin: any, type: MulticastType, event: ServerCommand, ...args: any[]): void;
45
44
  unicast(ent: Entity, reliable: boolean, event: ServerCommand, ...args: any[]): void;
@@ -222,35 +222,41 @@ var DedicatedServer = class {
222
222
  constructor(port = 27910) {
223
223
  this.port = port;
224
224
  this.wss = null;
225
- this.clients = new Array(MAX_CLIENTS).fill(null);
226
225
  this.game = null;
227
226
  this.frameInterval = null;
228
- this.startTime = 0;
229
- this.frameCount = 0;
230
- // Physics
231
- this.collisionModel = null;
227
+ this.svs = {
228
+ clients: new Array(MAX_CLIENTS).fill(null)
229
+ };
230
+ this.sv = {
231
+ startTime: 0,
232
+ time: 0,
233
+ frame: 0,
234
+ mapName: "",
235
+ collisionModel: null
236
+ };
232
237
  }
233
238
  async start(mapName) {
234
239
  console.log(`Starting Dedicated Server on port ${this.port}...`);
240
+ this.sv.mapName = mapName;
235
241
  this.wss = new WebSocketServer({ port: this.port });
236
242
  this.wss.on("connection", (ws) => {
237
243
  console.log("New connection");
238
244
  this.handleConnection(ws);
239
245
  });
240
246
  try {
241
- console.log(`Loading map ${mapName}...`);
242
- const mapData = await fs.readFile(mapName);
247
+ console.log(`Loading map ${this.sv.mapName}...`);
248
+ const mapData = await fs.readFile(this.sv.mapName);
243
249
  const arrayBuffer = mapData.buffer.slice(mapData.byteOffset, mapData.byteOffset + mapData.byteLength);
244
250
  const bspMap = parseBsp(arrayBuffer);
245
- this.collisionModel = bspMap;
251
+ this.sv.collisionModel = bspMap;
246
252
  console.log(`Map loaded successfully.`);
247
253
  } catch (e) {
248
254
  console.warn("Failed to load map:", e);
249
255
  }
250
- this.startTime = Date.now();
256
+ this.sv.startTime = Date.now();
251
257
  const imports = {
252
258
  trace: (start, mins, maxs, end, passent, contentmask) => {
253
- if (!this.collisionModel) {
259
+ if (!this.sv.collisionModel) {
254
260
  return {
255
261
  fraction: 1,
256
262
  endpos: { ...end },
@@ -267,7 +273,7 @@ var DedicatedServer = class {
267
273
  end,
268
274
  mins: mins || void 0,
269
275
  maxs: maxs || void 0,
270
- model: this.collisionModel
276
+ model: this.sv.collisionModel
271
277
  });
272
278
  return {
273
279
  allsolid: result.allsolid,
@@ -307,7 +313,7 @@ var DedicatedServer = class {
307
313
  handleConnection(ws) {
308
314
  let clientIndex = -1;
309
315
  for (let i = 0; i < MAX_CLIENTS; i++) {
310
- if (this.clients[i] === null || this.clients[i].state === 0 /* Free */) {
316
+ if (this.svs.clients[i] === null || this.svs.clients[i].state === 0 /* Free */) {
311
317
  clientIndex = i;
312
318
  break;
313
319
  }
@@ -319,7 +325,7 @@ var DedicatedServer = class {
319
325
  const driver = new WebSocketNetDriver();
320
326
  driver.attach(ws);
321
327
  const client = createClient(clientIndex, driver);
322
- this.clients[clientIndex] = client;
328
+ this.svs.clients[clientIndex] = client;
323
329
  driver.onMessage((data) => this.onClientMessage(client, data));
324
330
  driver.onClose(() => this.onClientDisconnect(client));
325
331
  }
@@ -341,7 +347,7 @@ var DedicatedServer = class {
341
347
  }
342
348
  onClientDisconnect(client) {
343
349
  console.log(`Client ${client.index} disconnected`);
344
- this.clients[client.index] = null;
350
+ this.svs.clients[client.index] = null;
345
351
  }
346
352
  handleMove(client, cmd) {
347
353
  client.lastCmd = cmd;
@@ -370,34 +376,42 @@ var DedicatedServer = class {
370
376
  const writer = new BinaryWriter();
371
377
  writer.writeByte(ServerCommand.serverdata);
372
378
  writer.writeLong(34);
373
- writer.writeLong(this.frameCount);
379
+ writer.writeLong(this.sv.frame);
374
380
  writer.writeByte(0);
375
381
  writer.writeString("baseq2");
376
382
  writer.writeShort(client.index);
377
383
  writer.writeString("maps/test.bsp");
378
384
  client.net.send(writer.getData());
379
385
  }
386
+ SV_ReadPackets() {
387
+ }
380
388
  runFrame() {
381
389
  if (!this.game) return;
382
- this.frameCount++;
390
+ this.sv.frame++;
391
+ this.SV_ReadPackets();
392
+ for (const client of this.svs.clients) {
393
+ if (client && client.state === 3 /* Active */ && client.edict) {
394
+ this.game.clientThink(client.edict, client.lastCmd);
395
+ }
396
+ }
383
397
  this.game.frame({
384
- frame: this.frameCount,
398
+ frame: this.sv.frame,
385
399
  deltaMs: FRAME_TIME_MS,
386
400
  nowMs: Date.now()
387
401
  });
388
- this.sendClientMessages();
402
+ this.SV_SendClientMessages();
389
403
  }
390
- sendClientMessages() {
391
- for (const client of this.clients) {
404
+ SV_SendClientMessages() {
405
+ for (const client of this.svs.clients) {
392
406
  if (client && client.state === 3 /* Active */) {
393
- this.sendClientFrame(client);
407
+ this.SV_SendClientFrame(client);
394
408
  }
395
409
  }
396
410
  }
397
- sendClientFrame(client) {
411
+ SV_SendClientFrame(client) {
398
412
  const writer = new BinaryWriter();
399
413
  writer.writeByte(ServerCommand.frame);
400
- writer.writeLong(this.frameCount);
414
+ writer.writeLong(this.sv.frame);
401
415
  writer.writeLong(0);
402
416
  writer.writeByte(0);
403
417
  writer.writeByte(0);
@@ -413,7 +427,7 @@ var DedicatedServer = class {
413
427
  multicast(origin, type, event, ...args) {
414
428
  }
415
429
  unicast(ent, reliable, event, ...args) {
416
- const client = this.clients.find((c) => c?.edict === ent);
430
+ const client = this.svs.clients.find((c) => c?.edict === ent);
417
431
  if (client) {
418
432
  }
419
433
  }