quake2ts 0.0.7

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 (149) hide show
  1. package/apps/viewer/dist/browser/index.global.js +2 -0
  2. package/apps/viewer/dist/browser/index.global.js.map +1 -0
  3. package/apps/viewer/dist/cjs/index.cjs +1087 -0
  4. package/apps/viewer/dist/cjs/index.cjs.map +1 -0
  5. package/apps/viewer/dist/esm/index.js +1060 -0
  6. package/apps/viewer/dist/esm/index.js.map +1 -0
  7. package/apps/viewer/dist/tsconfig.tsbuildinfo +1 -0
  8. package/apps/viewer/dist/types/index.d.ts +7 -0
  9. package/apps/viewer/dist/types/index.d.ts.map +1 -0
  10. package/package.json +107 -0
  11. package/packages/client/dist/browser/index.global.js +2 -0
  12. package/packages/client/dist/browser/index.global.js.map +1 -0
  13. package/packages/client/dist/cjs/index.cjs +57 -0
  14. package/packages/client/dist/cjs/index.cjs.map +1 -0
  15. package/packages/client/dist/esm/index.js +32 -0
  16. package/packages/client/dist/esm/index.js.map +1 -0
  17. package/packages/client/dist/tsconfig.tsbuildinfo +1 -0
  18. package/packages/client/dist/types/index.d.ts +14 -0
  19. package/packages/client/dist/types/index.d.ts.map +1 -0
  20. package/packages/engine/dist/browser/index.global.js +2 -0
  21. package/packages/engine/dist/browser/index.global.js.map +1 -0
  22. package/packages/engine/dist/cjs/index.cjs +1823 -0
  23. package/packages/engine/dist/cjs/index.cjs.map +1 -0
  24. package/packages/engine/dist/esm/index.js +1764 -0
  25. package/packages/engine/dist/esm/index.js.map +1 -0
  26. package/packages/engine/dist/tsconfig.tsbuildinfo +1 -0
  27. package/packages/engine/dist/types/assets/browserIngestion.d.ts +7 -0
  28. package/packages/engine/dist/types/assets/browserIngestion.d.ts.map +1 -0
  29. package/packages/engine/dist/types/assets/bsp.d.ts +157 -0
  30. package/packages/engine/dist/types/assets/bsp.d.ts.map +1 -0
  31. package/packages/engine/dist/types/assets/cache.d.ts +17 -0
  32. package/packages/engine/dist/types/assets/cache.d.ts.map +1 -0
  33. package/packages/engine/dist/types/assets/ingestion.d.ts +31 -0
  34. package/packages/engine/dist/types/assets/ingestion.d.ts.map +1 -0
  35. package/packages/engine/dist/types/assets/md2.d.ts +73 -0
  36. package/packages/engine/dist/types/assets/md2.d.ts.map +1 -0
  37. package/packages/engine/dist/types/assets/pak.d.ts +28 -0
  38. package/packages/engine/dist/types/assets/pak.d.ts.map +1 -0
  39. package/packages/engine/dist/types/assets/vfs.d.ts +23 -0
  40. package/packages/engine/dist/types/assets/vfs.d.ts.map +1 -0
  41. package/packages/engine/dist/types/configstrings.d.ts +34 -0
  42. package/packages/engine/dist/types/configstrings.d.ts.map +1 -0
  43. package/packages/engine/dist/types/cvars.d.ts +43 -0
  44. package/packages/engine/dist/types/cvars.d.ts.map +1 -0
  45. package/packages/engine/dist/types/host.d.ts +42 -0
  46. package/packages/engine/dist/types/host.d.ts.map +1 -0
  47. package/packages/engine/dist/types/index.d.ts +37 -0
  48. package/packages/engine/dist/types/index.d.ts.map +1 -0
  49. package/packages/engine/dist/types/loop.d.ts +40 -0
  50. package/packages/engine/dist/types/loop.d.ts.map +1 -0
  51. package/packages/engine/dist/types/render/bsp.d.ts +49 -0
  52. package/packages/engine/dist/types/render/bsp.d.ts.map +1 -0
  53. package/packages/engine/dist/types/render/context.d.ts +36 -0
  54. package/packages/engine/dist/types/render/context.d.ts.map +1 -0
  55. package/packages/engine/dist/types/render/resources.d.ts +56 -0
  56. package/packages/engine/dist/types/render/resources.d.ts.map +1 -0
  57. package/packages/engine/dist/types/render/shaderProgram.d.ts +18 -0
  58. package/packages/engine/dist/types/render/shaderProgram.d.ts.map +1 -0
  59. package/packages/engine/dist/types/runtime.d.ts +15 -0
  60. package/packages/engine/dist/types/runtime.d.ts.map +1 -0
  61. package/packages/game/dist/browser/index.global.js +2 -0
  62. package/packages/game/dist/browser/index.global.js.map +1 -0
  63. package/packages/game/dist/cjs/index.cjs +758 -0
  64. package/packages/game/dist/cjs/index.cjs.map +1 -0
  65. package/packages/game/dist/esm/index.js +725 -0
  66. package/packages/game/dist/esm/index.js.map +1 -0
  67. package/packages/game/dist/tsconfig.tsbuildinfo +1 -0
  68. package/packages/game/dist/types/entities/entity.d.ts +92 -0
  69. package/packages/game/dist/types/entities/entity.d.ts.map +1 -0
  70. package/packages/game/dist/types/entities/index.d.ts +3 -0
  71. package/packages/game/dist/types/entities/index.d.ts.map +1 -0
  72. package/packages/game/dist/types/entities/pool.d.ts +18 -0
  73. package/packages/game/dist/types/entities/pool.d.ts.map +1 -0
  74. package/packages/game/dist/types/entities/system.d.ts +18 -0
  75. package/packages/game/dist/types/entities/system.d.ts.map +1 -0
  76. package/packages/game/dist/types/entities/thinkScheduler.d.ts +8 -0
  77. package/packages/game/dist/types/entities/thinkScheduler.d.ts.map +1 -0
  78. package/packages/game/dist/types/index.d.ts +26 -0
  79. package/packages/game/dist/types/index.d.ts.map +1 -0
  80. package/packages/game/dist/types/level.d.ts +14 -0
  81. package/packages/game/dist/types/level.d.ts.map +1 -0
  82. package/packages/game/dist/types/loop.d.ts +29 -0
  83. package/packages/game/dist/types/loop.d.ts.map +1 -0
  84. package/packages/shared/dist/browser/index.global.js +2 -0
  85. package/packages/shared/dist/browser/index.global.js.map +1 -0
  86. package/packages/shared/dist/cjs/index.cjs +2793 -0
  87. package/packages/shared/dist/cjs/index.cjs.map +1 -0
  88. package/packages/shared/dist/esm/index.js +2594 -0
  89. package/packages/shared/dist/esm/index.js.map +1 -0
  90. package/packages/shared/dist/tsconfig.tsbuildinfo +1 -0
  91. package/packages/shared/dist/types/bsp/collision.d.ts +112 -0
  92. package/packages/shared/dist/types/bsp/collision.d.ts.map +1 -0
  93. package/packages/shared/dist/types/bsp/contents.d.ts +71 -0
  94. package/packages/shared/dist/types/bsp/contents.d.ts.map +1 -0
  95. package/packages/shared/dist/types/index.d.ts +25 -0
  96. package/packages/shared/dist/types/index.d.ts.map +1 -0
  97. package/packages/shared/dist/types/math/angles.d.ts +17 -0
  98. package/packages/shared/dist/types/math/angles.d.ts.map +1 -0
  99. package/packages/shared/dist/types/math/color.d.ts +12 -0
  100. package/packages/shared/dist/types/math/color.d.ts.map +1 -0
  101. package/packages/shared/dist/types/math/random.d.ts +48 -0
  102. package/packages/shared/dist/types/math/random.d.ts.map +1 -0
  103. package/packages/shared/dist/types/math/vec3.d.ts +76 -0
  104. package/packages/shared/dist/types/math/vec3.d.ts.map +1 -0
  105. package/packages/shared/dist/types/pmove/categorize.d.ts +36 -0
  106. package/packages/shared/dist/types/pmove/categorize.d.ts.map +1 -0
  107. package/packages/shared/dist/types/pmove/constants.d.ts +75 -0
  108. package/packages/shared/dist/types/pmove/constants.d.ts.map +1 -0
  109. package/packages/shared/dist/types/pmove/currents.d.ts +58 -0
  110. package/packages/shared/dist/types/pmove/currents.d.ts.map +1 -0
  111. package/packages/shared/dist/types/pmove/dimensions.d.ts +14 -0
  112. package/packages/shared/dist/types/pmove/dimensions.d.ts.map +1 -0
  113. package/packages/shared/dist/types/pmove/duck.d.ts +39 -0
  114. package/packages/shared/dist/types/pmove/duck.d.ts.map +1 -0
  115. package/packages/shared/dist/types/pmove/fly.d.ts +34 -0
  116. package/packages/shared/dist/types/pmove/fly.d.ts.map +1 -0
  117. package/packages/shared/dist/types/pmove/jump.d.ts +26 -0
  118. package/packages/shared/dist/types/pmove/jump.d.ts.map +1 -0
  119. package/packages/shared/dist/types/pmove/move.d.ts +58 -0
  120. package/packages/shared/dist/types/pmove/move.d.ts.map +1 -0
  121. package/packages/shared/dist/types/pmove/pmove.d.ts +36 -0
  122. package/packages/shared/dist/types/pmove/pmove.d.ts.map +1 -0
  123. package/packages/shared/dist/types/pmove/slide.d.ts +63 -0
  124. package/packages/shared/dist/types/pmove/slide.d.ts.map +1 -0
  125. package/packages/shared/dist/types/pmove/snap.d.ts +40 -0
  126. package/packages/shared/dist/types/pmove/snap.d.ts.map +1 -0
  127. package/packages/shared/dist/types/pmove/special.d.ts +39 -0
  128. package/packages/shared/dist/types/pmove/special.d.ts.map +1 -0
  129. package/packages/shared/dist/types/pmove/stuck.d.ts +21 -0
  130. package/packages/shared/dist/types/pmove/stuck.d.ts.map +1 -0
  131. package/packages/shared/dist/types/pmove/types.d.ts +48 -0
  132. package/packages/shared/dist/types/pmove/types.d.ts.map +1 -0
  133. package/packages/shared/dist/types/pmove/view.d.ts +19 -0
  134. package/packages/shared/dist/types/pmove/view.d.ts.map +1 -0
  135. package/packages/shared/dist/types/pmove/water.d.ts +21 -0
  136. package/packages/shared/dist/types/pmove/water.d.ts.map +1 -0
  137. package/packages/shared/dist/types/protocol/configstrings.d.ts +51 -0
  138. package/packages/shared/dist/types/protocol/configstrings.d.ts.map +1 -0
  139. package/packages/shared/dist/types/protocol/cvar.d.ts +15 -0
  140. package/packages/shared/dist/types/protocol/cvar.d.ts.map +1 -0
  141. package/packages/tools/dist/browser/index.global.js +2 -0
  142. package/packages/tools/dist/browser/index.global.js.map +1 -0
  143. package/packages/tools/dist/cjs/index.cjs +33 -0
  144. package/packages/tools/dist/cjs/index.cjs.map +1 -0
  145. package/packages/tools/dist/esm/index.js +8 -0
  146. package/packages/tools/dist/esm/index.js.map +1 -0
  147. package/packages/tools/dist/tsconfig.tsbuildinfo +1 -0
  148. package/packages/tools/dist/types/index.d.ts +7 -0
  149. package/packages/tools/dist/types/index.d.ts.map +1 -0
@@ -0,0 +1,758 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ DeadFlag: () => DeadFlag,
24
+ ENTITY_FIELD_METADATA: () => ENTITY_FIELD_METADATA,
25
+ Entity: () => Entity,
26
+ EntitySystem: () => EntitySystem,
27
+ MoveType: () => MoveType,
28
+ Solid: () => Solid,
29
+ createGame: () => createGame
30
+ });
31
+ module.exports = __toCommonJS(index_exports);
32
+
33
+ // ../shared/dist/esm/index.js
34
+ var ZERO_VEC3 = { x: 0, y: 0, z: 0 };
35
+ var DEG_TO_RAD = Math.PI / 180;
36
+ var DEG2RAD_FACTOR = Math.PI / 180;
37
+ var RAD2DEG_FACTOR = 180 / Math.PI;
38
+ var CONTENTS_SOLID = 1 << 0;
39
+ var CONTENTS_WINDOW = 1 << 1;
40
+ var CONTENTS_AUX = 1 << 2;
41
+ var CONTENTS_LAVA = 1 << 3;
42
+ var CONTENTS_SLIME = 1 << 4;
43
+ var CONTENTS_WATER = 1 << 5;
44
+ var CONTENTS_MIST = 1 << 6;
45
+ var CONTENTS_NO_WATERJUMP = 1 << 13;
46
+ var CONTENTS_PROJECTILECLIP = 1 << 14;
47
+ var CONTENTS_AREAPORTAL = 1 << 15;
48
+ var CONTENTS_PLAYERCLIP = 1 << 16;
49
+ var CONTENTS_MONSTERCLIP = 1 << 17;
50
+ var CONTENTS_CURRENT_0 = 1 << 18;
51
+ var CONTENTS_CURRENT_90 = 1 << 19;
52
+ var CONTENTS_CURRENT_180 = 1 << 20;
53
+ var CONTENTS_CURRENT_270 = 1 << 21;
54
+ var CONTENTS_CURRENT_UP = 1 << 22;
55
+ var CONTENTS_CURRENT_DOWN = 1 << 23;
56
+ var CONTENTS_ORIGIN = 1 << 24;
57
+ var CONTENTS_MONSTER = 1 << 25;
58
+ var CONTENTS_DEADMONSTER = 1 << 26;
59
+ var CONTENTS_DETAIL = 1 << 27;
60
+ var CONTENTS_TRANSLUCENT = 1 << 28;
61
+ var CONTENTS_LADDER = 1 << 29;
62
+ var CONTENTS_PLAYER = 1 << 30;
63
+ var CONTENTS_PROJECTILE = 1 << 31;
64
+ var SURF_LIGHT = 1 << 0;
65
+ var SURF_SLICK = 1 << 1;
66
+ var SURF_SKY = 1 << 2;
67
+ var SURF_WARP = 1 << 3;
68
+ var SURF_TRANS33 = 1 << 4;
69
+ var SURF_TRANS66 = 1 << 5;
70
+ var SURF_FLOWING = 1 << 6;
71
+ var SURF_NODRAW = 1 << 7;
72
+ var SURF_ALPHATEST = 1 << 25;
73
+ var SURF_N64_UV = 1 << 28;
74
+ var SURF_N64_SCROLL_X = 1 << 29;
75
+ var SURF_N64_SCROLL_Y = 1 << 30;
76
+ var SURF_N64_SCROLL_FLIP = 1 << 31;
77
+ var MASK_SOLID = CONTENTS_SOLID | CONTENTS_WINDOW;
78
+ var MASK_PLAYERSOLID = CONTENTS_SOLID | CONTENTS_PLAYERCLIP | CONTENTS_WINDOW | CONTENTS_MONSTER | CONTENTS_PLAYER;
79
+ var MASK_DEADSOLID = CONTENTS_SOLID | CONTENTS_PLAYERCLIP | CONTENTS_WINDOW;
80
+ var MASK_MONSTERSOLID = CONTENTS_SOLID | CONTENTS_MONSTERCLIP | CONTENTS_WINDOW | CONTENTS_MONSTER | CONTENTS_PLAYER;
81
+ var MASK_WATER = CONTENTS_WATER | CONTENTS_LAVA | CONTENTS_SLIME;
82
+ var MASK_OPAQUE = CONTENTS_SOLID | CONTENTS_SLIME | CONTENTS_LAVA;
83
+ var MASK_SHOT = CONTENTS_SOLID | CONTENTS_MONSTER | CONTENTS_PLAYER | CONTENTS_WINDOW | CONTENTS_DEADMONSTER;
84
+ var MASK_CURRENT = CONTENTS_CURRENT_0 | CONTENTS_CURRENT_90 | CONTENTS_CURRENT_180 | CONTENTS_CURRENT_270 | CONTENTS_CURRENT_UP | CONTENTS_CURRENT_DOWN;
85
+ var MASK_BLOCK_SIGHT = CONTENTS_SOLID | CONTENTS_LAVA | CONTENTS_SLIME | CONTENTS_MONSTER | CONTENTS_PLAYER;
86
+ var MASK_NAV_SOLID = CONTENTS_SOLID | CONTENTS_PLAYERCLIP | CONTENTS_WINDOW;
87
+ var MASK_LADDER_NAV_SOLID = CONTENTS_SOLID | CONTENTS_WINDOW;
88
+ var MASK_WALK_NAV_SOLID = CONTENTS_SOLID | CONTENTS_PLAYERCLIP | CONTENTS_WINDOW | CONTENTS_MONSTERCLIP;
89
+ var MASK_PROJECTILE = MASK_SHOT | CONTENTS_PROJECTILECLIP;
90
+ var MAX_CLIENTS = 256;
91
+ var MAX_LIGHTSTYLES = 256;
92
+ var MAX_MODELS = 8192;
93
+ var MAX_SOUNDS = 2048;
94
+ var MAX_IMAGES = 512;
95
+ var MAX_ITEMS = 256;
96
+ var MAX_GENERAL = MAX_CLIENTS * 2;
97
+ var MAX_SHADOW_LIGHTS = 256;
98
+ var MAX_WHEEL_ITEMS = 32;
99
+ var ConfigStringIndex = ((ConfigStringIndex2) => {
100
+ ConfigStringIndex2[ConfigStringIndex2["Name"] = 0] = "Name";
101
+ ConfigStringIndex2[ConfigStringIndex2["CdTrack"] = 1] = "CdTrack";
102
+ ConfigStringIndex2[ConfigStringIndex2["Sky"] = 2] = "Sky";
103
+ ConfigStringIndex2[ConfigStringIndex2["SkyAxis"] = 3] = "SkyAxis";
104
+ ConfigStringIndex2[ConfigStringIndex2["SkyRotate"] = 4] = "SkyRotate";
105
+ ConfigStringIndex2[ConfigStringIndex2["StatusBar"] = 5] = "StatusBar";
106
+ ConfigStringIndex2[ConfigStringIndex2["AirAccel"] = 59] = "AirAccel";
107
+ ConfigStringIndex2[ConfigStringIndex2["MaxClients"] = 60] = "MaxClients";
108
+ ConfigStringIndex2[ConfigStringIndex2["MapChecksum"] = 61] = "MapChecksum";
109
+ ConfigStringIndex2[ConfigStringIndex2["Models"] = 62] = "Models";
110
+ ConfigStringIndex2[ConfigStringIndex2["Sounds"] = 62 + MAX_MODELS] = "Sounds";
111
+ ConfigStringIndex2[ConfigStringIndex2["Images"] = ConfigStringIndex2.Sounds + MAX_SOUNDS] = "Images";
112
+ ConfigStringIndex2[ConfigStringIndex2["Lights"] = ConfigStringIndex2.Images + MAX_IMAGES] = "Lights";
113
+ ConfigStringIndex2[ConfigStringIndex2["ShadowLights"] = ConfigStringIndex2.Lights + MAX_LIGHTSTYLES] = "ShadowLights";
114
+ ConfigStringIndex2[ConfigStringIndex2["Items"] = ConfigStringIndex2.ShadowLights + MAX_SHADOW_LIGHTS] = "Items";
115
+ ConfigStringIndex2[ConfigStringIndex2["PlayerSkins"] = ConfigStringIndex2.Items + MAX_ITEMS] = "PlayerSkins";
116
+ ConfigStringIndex2[ConfigStringIndex2["General"] = ConfigStringIndex2.PlayerSkins + MAX_CLIENTS] = "General";
117
+ ConfigStringIndex2[ConfigStringIndex2["WheelWeapons"] = ConfigStringIndex2.General + MAX_GENERAL] = "WheelWeapons";
118
+ ConfigStringIndex2[ConfigStringIndex2["WheelAmmo"] = ConfigStringIndex2.WheelWeapons + MAX_WHEEL_ITEMS] = "WheelAmmo";
119
+ ConfigStringIndex2[ConfigStringIndex2["WheelPowerups"] = ConfigStringIndex2.WheelAmmo + MAX_WHEEL_ITEMS] = "WheelPowerups";
120
+ ConfigStringIndex2[ConfigStringIndex2["CdLoopCount"] = ConfigStringIndex2.WheelPowerups + MAX_WHEEL_ITEMS] = "CdLoopCount";
121
+ ConfigStringIndex2[ConfigStringIndex2["GameStyle"] = ConfigStringIndex2.CdLoopCount + 1] = "GameStyle";
122
+ ConfigStringIndex2[ConfigStringIndex2["MaxConfigStrings"] = ConfigStringIndex2.GameStyle + 1] = "MaxConfigStrings";
123
+ return ConfigStringIndex2;
124
+ })(ConfigStringIndex || {});
125
+ var MAX_CONFIGSTRINGS = ConfigStringIndex.MaxConfigStrings;
126
+ var WATERJUMP_CLEAR = 8 | 16 | 32 | 1024;
127
+
128
+ // src/entities/entity.ts
129
+ var MoveType = /* @__PURE__ */ ((MoveType2) => {
130
+ MoveType2[MoveType2["None"] = 0] = "None";
131
+ MoveType2[MoveType2["Noclip"] = 1] = "Noclip";
132
+ MoveType2[MoveType2["Push"] = 2] = "Push";
133
+ MoveType2[MoveType2["Stop"] = 3] = "Stop";
134
+ MoveType2[MoveType2["Walk"] = 4] = "Walk";
135
+ MoveType2[MoveType2["Step"] = 5] = "Step";
136
+ MoveType2[MoveType2["Fly"] = 6] = "Fly";
137
+ MoveType2[MoveType2["Toss"] = 7] = "Toss";
138
+ MoveType2[MoveType2["FlyMissile"] = 8] = "FlyMissile";
139
+ MoveType2[MoveType2["Bounce"] = 9] = "Bounce";
140
+ return MoveType2;
141
+ })(MoveType || {});
142
+ var Solid = /* @__PURE__ */ ((Solid2) => {
143
+ Solid2[Solid2["Not"] = 0] = "Not";
144
+ Solid2[Solid2["Trigger"] = 1] = "Trigger";
145
+ Solid2[Solid2["BoundingBox"] = 2] = "BoundingBox";
146
+ Solid2[Solid2["Bsp"] = 3] = "Bsp";
147
+ return Solid2;
148
+ })(Solid || {});
149
+ var DeadFlag = /* @__PURE__ */ ((DeadFlag2) => {
150
+ DeadFlag2[DeadFlag2["Alive"] = 0] = "Alive";
151
+ DeadFlag2[DeadFlag2["Dying"] = 1] = "Dying";
152
+ DeadFlag2[DeadFlag2["Dead"] = 2] = "Dead";
153
+ DeadFlag2[DeadFlag2["Respawnable"] = 3] = "Respawnable";
154
+ return DeadFlag2;
155
+ })(DeadFlag || {});
156
+ var ZERO = { ...ZERO_VEC3 };
157
+ function copyVec3() {
158
+ return { ...ZERO };
159
+ }
160
+ var Entity = class {
161
+ constructor(index) {
162
+ this.inUse = false;
163
+ this.freePending = false;
164
+ this.linkPrevious = null;
165
+ this.linkNext = null;
166
+ this.classname = "";
167
+ this.spawnflags = 0;
168
+ this.origin = copyVec3();
169
+ this.old_origin = copyVec3();
170
+ this.velocity = copyVec3();
171
+ this.avelocity = copyVec3();
172
+ this.angles = copyVec3();
173
+ this.mins = copyVec3();
174
+ this.maxs = copyVec3();
175
+ this.size = copyVec3();
176
+ this.mass = 0;
177
+ this.gravity = 1;
178
+ this.movetype = 0 /* None */;
179
+ this.modelindex = 0;
180
+ this.frame = 0;
181
+ this.skin = 0;
182
+ this.effects = 0;
183
+ this.renderfx = 0;
184
+ this.health = 0;
185
+ this.max_health = 0;
186
+ this.takedamage = false;
187
+ this.dmg = 0;
188
+ this.deadflag = 0 /* Alive */;
189
+ this.enemy = null;
190
+ this.movetarget = null;
191
+ this.goalentity = null;
192
+ this.ideal_yaw = 0;
193
+ this.yaw_speed = 0;
194
+ this.groundentity = null;
195
+ this.groundentity_linkcount = 0;
196
+ this.waterlevel = 0;
197
+ this.watertype = 0;
198
+ this.nextthink = 0;
199
+ this.solid = 0 /* Not */;
200
+ this.flags = 0;
201
+ this.svflags = 0;
202
+ this.index = index;
203
+ }
204
+ reset() {
205
+ this.inUse = false;
206
+ this.freePending = false;
207
+ this.linkPrevious = null;
208
+ this.linkNext = null;
209
+ this.classname = "";
210
+ this.spawnflags = 0;
211
+ this.target = void 0;
212
+ this.targetname = void 0;
213
+ this.team = void 0;
214
+ this.message = void 0;
215
+ this.origin = copyVec3();
216
+ this.old_origin = copyVec3();
217
+ this.velocity = copyVec3();
218
+ this.avelocity = copyVec3();
219
+ this.angles = copyVec3();
220
+ this.mins = copyVec3();
221
+ this.maxs = copyVec3();
222
+ this.size = copyVec3();
223
+ this.mass = 0;
224
+ this.gravity = 1;
225
+ this.movetype = 0 /* None */;
226
+ this.modelindex = 0;
227
+ this.frame = 0;
228
+ this.skin = 0;
229
+ this.effects = 0;
230
+ this.renderfx = 0;
231
+ this.health = 0;
232
+ this.max_health = 0;
233
+ this.takedamage = false;
234
+ this.dmg = 0;
235
+ this.deadflag = 0 /* Alive */;
236
+ this.enemy = null;
237
+ this.movetarget = null;
238
+ this.goalentity = null;
239
+ this.ideal_yaw = 0;
240
+ this.yaw_speed = 0;
241
+ this.groundentity = null;
242
+ this.groundentity_linkcount = 0;
243
+ this.waterlevel = 0;
244
+ this.watertype = 0;
245
+ this.nextthink = 0;
246
+ this.think = void 0;
247
+ this.touch = void 0;
248
+ this.use = void 0;
249
+ this.pain = void 0;
250
+ this.die = void 0;
251
+ this.solid = 0 /* Not */;
252
+ this.flags = 0;
253
+ this.svflags = 0;
254
+ }
255
+ };
256
+ var ENTITY_FIELD_METADATA = [
257
+ { name: "classname", type: "string", save: true },
258
+ { name: "spawnflags", type: "int", save: true },
259
+ { name: "target", type: "string", save: true },
260
+ { name: "targetname", type: "string", save: true },
261
+ { name: "team", type: "string", save: true },
262
+ { name: "message", type: "string", save: true },
263
+ { name: "origin", type: "vec3", save: true },
264
+ { name: "old_origin", type: "vec3", save: true },
265
+ { name: "velocity", type: "vec3", save: true },
266
+ { name: "avelocity", type: "vec3", save: true },
267
+ { name: "angles", type: "vec3", save: true },
268
+ { name: "mins", type: "vec3", save: true },
269
+ { name: "maxs", type: "vec3", save: true },
270
+ { name: "size", type: "vec3", save: true },
271
+ { name: "mass", type: "int", save: true },
272
+ { name: "gravity", type: "float", save: true },
273
+ { name: "movetype", type: "int", save: true },
274
+ { name: "modelindex", type: "int", save: true },
275
+ { name: "frame", type: "int", save: true },
276
+ { name: "skin", type: "int", save: true },
277
+ { name: "effects", type: "int", save: true },
278
+ { name: "renderfx", type: "int", save: true },
279
+ { name: "health", type: "int", save: true },
280
+ { name: "max_health", type: "int", save: true },
281
+ { name: "takedamage", type: "boolean", save: true },
282
+ { name: "dmg", type: "int", save: true },
283
+ { name: "deadflag", type: "int", save: true },
284
+ { name: "enemy", type: "entity", save: true },
285
+ { name: "movetarget", type: "entity", save: true },
286
+ { name: "goalentity", type: "entity", save: true },
287
+ { name: "ideal_yaw", type: "float", save: true },
288
+ { name: "yaw_speed", type: "float", save: true },
289
+ { name: "groundentity", type: "entity", save: true },
290
+ { name: "groundentity_linkcount", type: "int", save: true },
291
+ { name: "waterlevel", type: "int", save: true },
292
+ { name: "watertype", type: "int", save: true },
293
+ { name: "nextthink", type: "float", save: true },
294
+ { name: "solid", type: "int", save: true },
295
+ { name: "flags", type: "int", save: true },
296
+ { name: "svflags", type: "int", save: true },
297
+ { name: "think", type: "callback", save: false },
298
+ { name: "touch", type: "callback", save: false },
299
+ { name: "use", type: "callback", save: false },
300
+ { name: "pain", type: "callback", save: false },
301
+ { name: "die", type: "callback", save: false }
302
+ ];
303
+
304
+ // src/entities/pool.ts
305
+ var MAX_EDICTS = 2048;
306
+ var WORLD_INDEX = 0;
307
+ var EntityPool = class {
308
+ constructor(maxEntities = MAX_EDICTS) {
309
+ this.freeList = [];
310
+ this.pendingFree = [];
311
+ this.activeHead = null;
312
+ if (maxEntities < 1 || !Number.isInteger(maxEntities)) {
313
+ throw new Error("EntityPool requires a positive integer size");
314
+ }
315
+ this.entities = new Array(maxEntities);
316
+ for (let i = 0; i < maxEntities; i += 1) {
317
+ this.entities[i] = new Entity(i);
318
+ if (i !== WORLD_INDEX) {
319
+ this.freeList.push(i);
320
+ }
321
+ }
322
+ const world = this.entities[WORLD_INDEX];
323
+ world.inUse = true;
324
+ world.classname = "worldspawn";
325
+ this.activeHead = world;
326
+ }
327
+ get world() {
328
+ return this.entities[WORLD_INDEX];
329
+ }
330
+ get capacity() {
331
+ return this.entities.length;
332
+ }
333
+ get activeCount() {
334
+ let count = 0;
335
+ for (const _ of this) {
336
+ count += 1;
337
+ }
338
+ return count;
339
+ }
340
+ [Symbol.iterator]() {
341
+ let current = this.activeHead;
342
+ return {
343
+ next: () => {
344
+ if (!current) {
345
+ return { done: true, value: void 0 };
346
+ }
347
+ const value = current;
348
+ current = current.linkNext;
349
+ return { done: false, value };
350
+ }
351
+ };
352
+ }
353
+ spawn() {
354
+ const index = this.freeList.pop();
355
+ if (index === void 0) {
356
+ throw new Error("No free entities available");
357
+ }
358
+ const entity = this.entities[index];
359
+ entity.reset();
360
+ entity.inUse = true;
361
+ this.link(entity);
362
+ return entity;
363
+ }
364
+ deferFree(entity) {
365
+ if (entity.index === WORLD_INDEX) {
366
+ throw new Error("Cannot free world entity");
367
+ }
368
+ if (!entity.inUse || entity.freePending) {
369
+ return;
370
+ }
371
+ this.unlink(entity);
372
+ entity.inUse = false;
373
+ entity.freePending = true;
374
+ this.pendingFree.push(entity.index);
375
+ }
376
+ flushFreeList() {
377
+ if (this.pendingFree.length === 0) {
378
+ return;
379
+ }
380
+ for (const index of this.pendingFree) {
381
+ const entity = this.entities[index];
382
+ entity.reset();
383
+ this.freeList.push(index);
384
+ }
385
+ this.pendingFree.length = 0;
386
+ }
387
+ link(entity) {
388
+ entity.linkNext = this.activeHead;
389
+ if (this.activeHead) {
390
+ this.activeHead.linkPrevious = entity;
391
+ }
392
+ this.activeHead = entity;
393
+ entity.linkPrevious = null;
394
+ }
395
+ unlink(entity) {
396
+ if (entity.linkPrevious) {
397
+ entity.linkPrevious.linkNext = entity.linkNext;
398
+ }
399
+ if (entity.linkNext) {
400
+ entity.linkNext.linkPrevious = entity.linkPrevious;
401
+ }
402
+ if (this.activeHead === entity) {
403
+ this.activeHead = entity.linkNext;
404
+ }
405
+ entity.linkPrevious = null;
406
+ entity.linkNext = null;
407
+ }
408
+ };
409
+
410
+ // src/entities/thinkScheduler.ts
411
+ var ThinkScheduler = class {
412
+ constructor() {
413
+ this.queue = [];
414
+ }
415
+ schedule(entity, timeSeconds) {
416
+ entity.nextthink = timeSeconds;
417
+ this.queue.push({ entity, time: timeSeconds });
418
+ this.queue.sort((a, b) => a.time === b.time ? a.entity.index - b.entity.index : a.time - b.time);
419
+ }
420
+ cancel(entity) {
421
+ if (this.queue.length === 0) {
422
+ return;
423
+ }
424
+ for (let i = this.queue.length - 1; i >= 0; i -= 1) {
425
+ if (this.queue[i].entity === entity) {
426
+ this.queue.splice(i, 1);
427
+ }
428
+ }
429
+ }
430
+ runDueThinks(currentTimeSeconds) {
431
+ while (this.queue.length > 0) {
432
+ const next = this.queue[0];
433
+ if (next.time > currentTimeSeconds) {
434
+ break;
435
+ }
436
+ this.queue.shift();
437
+ const { entity, time } = next;
438
+ if (!entity.inUse || entity.freePending) {
439
+ continue;
440
+ }
441
+ if (!entity.think) {
442
+ continue;
443
+ }
444
+ if (entity.nextthink !== time) {
445
+ continue;
446
+ }
447
+ entity.think(entity);
448
+ }
449
+ }
450
+ };
451
+
452
+ // src/entities/system.ts
453
+ function computeBounds(entity) {
454
+ return {
455
+ min: {
456
+ x: entity.origin.x + entity.mins.x,
457
+ y: entity.origin.y + entity.mins.y,
458
+ z: entity.origin.z + entity.mins.z
459
+ },
460
+ max: {
461
+ x: entity.origin.x + entity.maxs.x,
462
+ y: entity.origin.y + entity.maxs.y,
463
+ z: entity.origin.z + entity.maxs.z
464
+ }
465
+ };
466
+ }
467
+ function boundsIntersect(a, b) {
468
+ return !(a.min.x > b.max.x || a.max.x < b.min.x || a.min.y > b.max.y || a.max.y < b.min.y || a.min.z > b.max.z || a.max.z < b.min.z);
469
+ }
470
+ var EntitySystem = class {
471
+ constructor(maxEntities) {
472
+ this.currentTimeSeconds = 0;
473
+ this.pool = new EntityPool(maxEntities);
474
+ this.thinkScheduler = new ThinkScheduler();
475
+ }
476
+ get world() {
477
+ return this.pool.world;
478
+ }
479
+ get activeCount() {
480
+ return this.pool.activeCount;
481
+ }
482
+ get timeSeconds() {
483
+ return this.currentTimeSeconds;
484
+ }
485
+ forEachEntity(callback) {
486
+ for (const entity of this.pool) {
487
+ callback(entity);
488
+ }
489
+ }
490
+ spawn() {
491
+ return this.pool.spawn();
492
+ }
493
+ free(entity) {
494
+ this.thinkScheduler.cancel(entity);
495
+ this.pool.deferFree(entity);
496
+ }
497
+ scheduleThink(entity, nextThinkSeconds) {
498
+ this.thinkScheduler.schedule(entity, nextThinkSeconds);
499
+ }
500
+ beginFrame(timeSeconds) {
501
+ this.currentTimeSeconds = timeSeconds;
502
+ }
503
+ runFrame() {
504
+ this.thinkScheduler.runDueThinks(this.currentTimeSeconds);
505
+ this.runTouches();
506
+ this.pool.flushFreeList();
507
+ }
508
+ runTouches() {
509
+ const world = this.pool.world;
510
+ const activeEntities = [];
511
+ for (const entity of this.pool) {
512
+ if (entity === world) {
513
+ continue;
514
+ }
515
+ if (!entity.inUse || entity.freePending) {
516
+ continue;
517
+ }
518
+ activeEntities.push(entity);
519
+ }
520
+ for (let i = 0; i < activeEntities.length; i += 1) {
521
+ const first = activeEntities[i];
522
+ let firstBounds = null;
523
+ for (let j = i + 1; j < activeEntities.length; j += 1) {
524
+ const second = activeEntities[j];
525
+ if (!first.touch && !second.touch) {
526
+ continue;
527
+ }
528
+ if (!firstBounds) {
529
+ firstBounds = computeBounds(first);
530
+ }
531
+ const secondBounds = computeBounds(second);
532
+ if (!boundsIntersect(firstBounds, secondBounds)) {
533
+ continue;
534
+ }
535
+ if (first.touch) {
536
+ first.touch(first, second);
537
+ }
538
+ if (second.touch) {
539
+ second.touch(second, first);
540
+ }
541
+ }
542
+ }
543
+ }
544
+ };
545
+
546
+ // src/loop.ts
547
+ var orderedStageNames = [
548
+ "prep",
549
+ "simulate",
550
+ "finish"
551
+ ];
552
+ var GameFrameLoop = class {
553
+ constructor(initialStages) {
554
+ this.timeMs = 0;
555
+ this.frame = 0;
556
+ this.stageHandlers = {
557
+ prep: [],
558
+ simulate: [],
559
+ finish: []
560
+ };
561
+ this.stageCounts = {
562
+ prep: 0,
563
+ simulate: 0,
564
+ finish: 0
565
+ };
566
+ this.stageCompactionNeeded = {
567
+ prep: false,
568
+ simulate: false,
569
+ finish: false
570
+ };
571
+ if (initialStages) {
572
+ for (const stageName of orderedStageNames) {
573
+ const handler = initialStages[stageName];
574
+ if (handler) {
575
+ this.addStage(stageName, handler);
576
+ }
577
+ }
578
+ }
579
+ }
580
+ addStage(stage, handler) {
581
+ const handlers = this.stageHandlers[stage];
582
+ handlers.push(handler);
583
+ this.stageCounts[stage] += 1;
584
+ return () => {
585
+ const index = handlers.indexOf(handler);
586
+ if (index >= 0 && handlers[index]) {
587
+ handlers[index] = void 0;
588
+ this.stageCounts[stage] -= 1;
589
+ this.stageCompactionNeeded[stage] = true;
590
+ }
591
+ };
592
+ }
593
+ reset(startTimeMs) {
594
+ this.timeMs = startTimeMs;
595
+ this.frame = 0;
596
+ }
597
+ advance(step) {
598
+ const previousTimeMs = this.timeMs;
599
+ this.timeMs = previousTimeMs + step.deltaMs;
600
+ this.frame = step.frame;
601
+ const context = {
602
+ ...step,
603
+ timeMs: this.timeMs,
604
+ previousTimeMs,
605
+ deltaSeconds: step.deltaMs / 1e3
606
+ };
607
+ this.runStage("prep", context);
608
+ if (this.stageCounts.simulate === 0) {
609
+ throw new Error("GameFrameLoop requires at least one simulate stage");
610
+ }
611
+ this.runStage("simulate", context);
612
+ this.runStage("finish", context);
613
+ return context;
614
+ }
615
+ runStage(stage, context) {
616
+ const handlers = this.stageHandlers[stage];
617
+ for (let i = 0; i < handlers.length; i += 1) {
618
+ const handler = handlers[i];
619
+ if (!handler) {
620
+ continue;
621
+ }
622
+ handler(context);
623
+ }
624
+ if (this.stageCompactionNeeded[stage]) {
625
+ this.compactStageHandlers(stage);
626
+ }
627
+ }
628
+ compactStageHandlers(stage) {
629
+ const handlers = this.stageHandlers[stage];
630
+ let writeIndex = 0;
631
+ for (let readIndex = 0; readIndex < handlers.length; readIndex += 1) {
632
+ const handler = handlers[readIndex];
633
+ if (handler) {
634
+ handlers[writeIndex] = handler;
635
+ writeIndex += 1;
636
+ }
637
+ }
638
+ handlers.length = writeIndex;
639
+ this.stageCompactionNeeded[stage] = false;
640
+ }
641
+ get time() {
642
+ return this.timeMs;
643
+ }
644
+ get frameNumber() {
645
+ return this.frame;
646
+ }
647
+ };
648
+
649
+ // src/level.ts
650
+ var ZERO_STATE = {
651
+ frameNumber: 0,
652
+ timeSeconds: 0,
653
+ previousTimeSeconds: 0,
654
+ deltaSeconds: 0
655
+ };
656
+ var LevelClock = class {
657
+ constructor() {
658
+ this.state = ZERO_STATE;
659
+ }
660
+ start(startTimeMs) {
661
+ const startSeconds = startTimeMs / 1e3;
662
+ this.state = {
663
+ frameNumber: 0,
664
+ timeSeconds: startSeconds,
665
+ previousTimeSeconds: startSeconds,
666
+ deltaSeconds: 0
667
+ };
668
+ }
669
+ tick(context) {
670
+ this.state = {
671
+ frameNumber: context.frame,
672
+ timeSeconds: context.timeMs / 1e3,
673
+ previousTimeSeconds: context.previousTimeMs / 1e3,
674
+ deltaSeconds: context.deltaSeconds
675
+ };
676
+ return this.state;
677
+ }
678
+ get current() {
679
+ return this.state;
680
+ }
681
+ };
682
+
683
+ // src/index.ts
684
+ var ZERO_VEC32 = { x: 0, y: 0, z: 0 };
685
+ function createGame(engine, options) {
686
+ const gravity = options.gravity;
687
+ const levelClock = new LevelClock();
688
+ const frameLoop = new GameFrameLoop();
689
+ const entities = new EntitySystem();
690
+ frameLoop.addStage("prep", (context) => {
691
+ levelClock.tick(context);
692
+ entities.beginFrame(levelClock.current.timeSeconds);
693
+ });
694
+ frameLoop.addStage("simulate", ({ deltaSeconds }) => {
695
+ velocity = {
696
+ x: velocity.x + gravity.x * deltaSeconds,
697
+ y: velocity.y + gravity.y * deltaSeconds,
698
+ z: velocity.z + gravity.z * deltaSeconds
699
+ };
700
+ origin = {
701
+ x: origin.x + velocity.x * deltaSeconds,
702
+ y: origin.y + velocity.y * deltaSeconds,
703
+ z: origin.z + velocity.z * deltaSeconds
704
+ };
705
+ entities.runFrame();
706
+ });
707
+ let origin = { ...ZERO_VEC32 };
708
+ let velocity = { ...ZERO_VEC32 };
709
+ const snapshot = (frame) => ({
710
+ frame,
711
+ timeMs: frameLoop.time,
712
+ state: {
713
+ gravity: { ...gravity },
714
+ origin: { ...origin },
715
+ velocity: { ...velocity },
716
+ level: { ...levelClock.current },
717
+ entities: {
718
+ activeCount: entities.activeCount,
719
+ worldClassname: entities.world.classname
720
+ }
721
+ }
722
+ });
723
+ const resetState = (startTimeMs) => {
724
+ frameLoop.reset(startTimeMs);
725
+ levelClock.start(startTimeMs);
726
+ origin = { ...ZERO_VEC32 };
727
+ velocity = { ...ZERO_VEC32 };
728
+ entities.beginFrame(startTimeMs / 1e3);
729
+ entities.runFrame();
730
+ };
731
+ return {
732
+ init(startTimeMs) {
733
+ resetState(startTimeMs);
734
+ void engine.trace({ x: 0, y: 0, z: 0 }, gravity);
735
+ return snapshot(0);
736
+ },
737
+ shutdown() {
738
+ },
739
+ spawnWorld() {
740
+ },
741
+ frame(step) {
742
+ const context = frameLoop.advance(step);
743
+ return snapshot(context.frame);
744
+ },
745
+ entities
746
+ };
747
+ }
748
+ // Annotate the CommonJS export names for ESM import in node:
749
+ 0 && (module.exports = {
750
+ DeadFlag,
751
+ ENTITY_FIELD_METADATA,
752
+ Entity,
753
+ EntitySystem,
754
+ MoveType,
755
+ Solid,
756
+ createGame
757
+ });
758
+ //# sourceMappingURL=index.cjs.map