quake2ts 0.0.198 → 0.0.200

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.
Files changed (29) hide show
  1. package/package.json +1 -1
  2. package/packages/client/dist/browser/index.global.js +13 -13
  3. package/packages/client/dist/browser/index.global.js.map +1 -1
  4. package/packages/client/dist/cjs/index.cjs +88 -28
  5. package/packages/client/dist/cjs/index.cjs.map +1 -1
  6. package/packages/client/dist/esm/index.js +88 -28
  7. package/packages/client/dist/esm/index.js.map +1 -1
  8. package/packages/client/dist/tsconfig.tsbuildinfo +1 -1
  9. package/packages/client/dist/types/cgameBridge.d.ts +12 -1
  10. package/packages/client/dist/types/cgameBridge.d.ts.map +1 -1
  11. package/packages/client/dist/types/demo/handler.d.ts +1 -0
  12. package/packages/client/dist/types/demo/handler.d.ts.map +1 -1
  13. package/packages/client/dist/types/index.d.ts.map +1 -1
  14. package/packages/engine/dist/browser/index.global.js.map +1 -1
  15. package/packages/engine/dist/cjs/index.cjs.map +1 -1
  16. package/packages/engine/dist/esm/index.js.map +1 -1
  17. package/packages/engine/dist/tsconfig.tsbuildinfo +1 -1
  18. package/packages/engine/dist/types/index.d.ts +1 -1
  19. package/packages/engine/dist/types/index.d.ts.map +1 -1
  20. package/packages/game/dist/browser/index.global.js +2 -2
  21. package/packages/game/dist/browser/index.global.js.map +1 -1
  22. package/packages/game/dist/cjs/index.cjs +106 -2
  23. package/packages/game/dist/cjs/index.cjs.map +1 -1
  24. package/packages/game/dist/esm/index.js +106 -2
  25. package/packages/game/dist/esm/index.js.map +1 -1
  26. package/packages/game/dist/tsconfig.tsbuildinfo +1 -1
  27. package/packages/game/dist/types/entities/playerStats.d.ts +3 -0
  28. package/packages/game/dist/types/entities/playerStats.d.ts.map +1 -0
  29. package/packages/game/dist/types/index.d.ts.map +1 -1
@@ -3844,18 +3844,20 @@ var import_cgame2 = require("@quake2ts/cgame");
3844
3844
  var import_cgame3 = require("@quake2ts/cgame");
3845
3845
 
3846
3846
  // src/cgameBridge.ts
3847
- function createCGameImport(imports) {
3847
+ function createCGameImport(imports, state) {
3848
+ const picCache = /* @__PURE__ */ new Map();
3849
+ const pendingPics = /* @__PURE__ */ new Set();
3848
3850
  const getRenderer = () => imports.engine.renderer;
3849
3851
  return {
3850
- // Frame timing - stubbed for now until we fix the access pattern
3852
+ // Frame timing
3851
3853
  get tick_rate() {
3852
- return 10;
3854
+ return state.tickRate;
3853
3855
  },
3854
3856
  get frame_time_s() {
3855
- return 0;
3857
+ return state.frameTimeMs / 1e3;
3856
3858
  },
3857
3859
  get frame_time_ms() {
3858
- return 0;
3860
+ return state.frameTimeMs;
3859
3861
  },
3860
3862
  // Console
3861
3863
  Com_Print: (msg) => {
@@ -3866,7 +3868,7 @@ function createCGameImport(imports) {
3866
3868
  },
3867
3869
  // Config strings
3868
3870
  get_configstring: (num) => {
3869
- return "";
3871
+ return state.configStrings.get(num) || "";
3870
3872
  },
3871
3873
  // Memory (No-op in JS)
3872
3874
  TagMalloc: (size, tag) => ({}),
@@ -3876,27 +3878,27 @@ function createCGameImport(imports) {
3876
3878
  },
3877
3879
  // Cvars
3878
3880
  cvar: (name, value, flags) => {
3881
+ const existing = imports.host?.cvars?.get(name);
3882
+ if (existing) return existing;
3879
3883
  return null;
3880
3884
  },
3881
3885
  cvar_set: (name, value) => {
3882
- if (imports.host?.cvars) {
3883
- imports.host.cvars.setValue(name, value);
3884
- }
3886
+ imports.host?.cvars?.setValue(name, value);
3885
3887
  },
3886
3888
  cvar_forceset: (name, value) => {
3887
- if (imports.host?.cvars) {
3888
- imports.host.cvars.setValue(name, value);
3889
- }
3889
+ imports.host?.cvars?.setValue(name, value);
3890
3890
  },
3891
3891
  // Client state
3892
3892
  CL_FrameValid: () => true,
3893
- CL_FrameTime: () => 0,
3894
- CL_ClientTime: () => 0,
3895
- CL_ServerFrame: () => 0,
3896
- CL_ServerProtocol: () => 34,
3893
+ // Always assume valid for now
3894
+ CL_FrameTime: () => state.frameTimeMs,
3895
+ CL_ClientTime: () => state.frameTimeMs,
3896
+ // Use frame time as client time
3897
+ CL_ServerFrame: () => state.serverFrame,
3898
+ CL_ServerProtocol: () => state.serverProtocol,
3897
3899
  // Client info
3898
3900
  CL_GetClientName: (playerNum) => {
3899
- return `Player ${playerNum}`;
3901
+ return state.getClientName(playerNum);
3900
3902
  },
3901
3903
  CL_GetClientPic: (playerNum) => {
3902
3904
  return "";
@@ -3905,25 +3907,55 @@ function createCGameImport(imports) {
3905
3907
  return "";
3906
3908
  },
3907
3909
  CL_GetKeyBinding: (key) => {
3908
- return `[${key}]`;
3910
+ return state.getKeyBinding(key);
3909
3911
  },
3910
3912
  // Drawing
3911
3913
  Draw_RegisterPic: (name) => {
3912
- if (imports.engine.assets) {
3914
+ if (picCache.has(name)) {
3913
3915
  return name;
3914
3916
  }
3917
+ if (pendingPics.has(name)) {
3918
+ return name;
3919
+ }
3920
+ pendingPics.add(name);
3921
+ if (imports.engine.assets) {
3922
+ imports.engine.assets.loadTexture(name).then((texture) => {
3923
+ if (imports.engine.renderer) {
3924
+ const pic = imports.engine.renderer.registerTexture(name, texture);
3925
+ picCache.set(name, pic);
3926
+ }
3927
+ pendingPics.delete(name);
3928
+ }).catch((err) => {
3929
+ console.warn(`[CGameImport] Failed to load pic: ${name}`, err);
3930
+ pendingPics.delete(name);
3931
+ });
3932
+ }
3915
3933
  return name;
3916
3934
  },
3917
- Draw_GetPicSize: (pic) => {
3918
- return { width: 32, height: 32 };
3935
+ Draw_GetPicSize: (picHandle) => {
3936
+ const name = picHandle;
3937
+ const pic = picCache.get(name);
3938
+ if (pic) {
3939
+ return { width: pic.width, height: pic.height };
3940
+ }
3941
+ return { width: 0, height: 0 };
3919
3942
  },
3920
3943
  SCR_DrawChar: (x, y, char) => {
3921
3944
  getRenderer()?.drawString(x, y, String.fromCharCode(char));
3922
3945
  },
3923
- SCR_DrawPic: (x, y, pic) => {
3924
- const name = pic;
3946
+ SCR_DrawPic: (x, y, picHandle) => {
3947
+ const name = picHandle;
3948
+ const pic = picCache.get(name);
3949
+ if (pic) {
3950
+ getRenderer()?.drawPic(x, y, pic);
3951
+ }
3925
3952
  },
3926
- SCR_DrawColorPic: (x, y, pic, color, alpha) => {
3953
+ SCR_DrawColorPic: (x, y, picHandle, color, alpha) => {
3954
+ const name = picHandle;
3955
+ const pic = picCache.get(name);
3956
+ if (pic) {
3957
+ getRenderer()?.drawPic(x, y, pic, [color.x, color.y, color.z, alpha]);
3958
+ }
3927
3959
  },
3928
3960
  SCR_DrawFontString: (x, y, str3) => {
3929
3961
  getRenderer()?.drawString(x, y, str3);
@@ -3939,6 +3971,7 @@ function createCGameImport(imports) {
3939
3971
  SCR_SetAltTypeface: (alt) => {
3940
3972
  },
3941
3973
  SCR_DrawBind: (x, y, command) => {
3974
+ const key = state.getKeyBinding(command);
3942
3975
  getRenderer()?.drawString(x, y, `[${command}]`);
3943
3976
  },
3944
3977
  // Localization
@@ -3946,11 +3979,10 @@ function createCGameImport(imports) {
3946
3979
  // State queries
3947
3980
  CL_GetTextInput: () => "",
3948
3981
  CL_GetWarnAmmoCount: () => 5,
3949
- // Low ammo threshold
3950
- CL_InAutoDemoLoop: () => false,
3982
+ CL_InAutoDemoLoop: () => state.inAutoDemo,
3951
3983
  // Prediction Trace
3952
3984
  PM_Trace: (start, end, mins, maxs) => {
3953
- return imports.engine.trace(start, end);
3985
+ return imports.engine.trace(start, end, mins, maxs);
3954
3986
  }
3955
3987
  };
3956
3988
  }
@@ -4852,6 +4884,9 @@ var ClientNetworkHandler = class {
4852
4884
  }
4853
4885
  return latestState;
4854
4886
  }
4887
+ get latestServerFrame() {
4888
+ return this.latestFrame?.serverFrame ?? 0;
4889
+ }
4855
4890
  };
4856
4891
 
4857
4892
  // src/configStrings.ts
@@ -6266,7 +6301,32 @@ function createClient(imports) {
6266
6301
  let lastRendered;
6267
6302
  let lastView;
6268
6303
  let camera;
6269
- const cgameImport = createCGameImport(imports);
6304
+ let clientInAutoDemo = false;
6305
+ const stateProvider = {
6306
+ get tickRate() {
6307
+ return 10;
6308
+ },
6309
+ // Default 10Hz
6310
+ get frameTimeMs() {
6311
+ return latestFrame?.timeMs ?? 0;
6312
+ },
6313
+ get serverFrame() {
6314
+ return demoHandler.latestServerFrame;
6315
+ },
6316
+ // Corrected access
6317
+ get serverProtocol() {
6318
+ return 34;
6319
+ },
6320
+ get configStrings() {
6321
+ return configStrings;
6322
+ },
6323
+ getClientName: (num) => `Player ${num}`,
6324
+ getKeyBinding: (key) => `[${key}]`,
6325
+ get inAutoDemo() {
6326
+ return clientInAutoDemo;
6327
+ }
6328
+ };
6329
+ const cgameImport = createCGameImport(imports, stateProvider);
6270
6330
  const cg = (0, import_cgame2.GetCGameAPI)(cgameImport);
6271
6331
  let fovValue = 90;
6272
6332
  let isZooming = false;