Nuclide
Software Development Kit for id Technology (BETA)
defs.h
1/*
2 * Copyright (c) 2016-2022 Vera Visions LLC.
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
13 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
14 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15*/
16
17#include "api_func.h"
18#include "../shared/api.h"
19#include "../shared/entityDef.h"
20#include "text.h"
21#include "textmenu.h"
22#include "font.h"
23#include "fade.h"
24#include "cmd.h"
25#include "util.h"
26#include "NSView.h"
27#include "NSRadar.h"
28#include "crosshair.h"
29#include "hud.h"
30
31var bool g_net_debug = false;
32var bool g_cheats = false;
33
34var float g_modelSpinAngle;
35var float g_modelSpinPitch;
36var float g_modelSpinRoll;
37var float g_modelBobHeight;
38var float autocvar_cg_modelSpinSpeed = 120.0f;
39var float autocvar_cg_modelSpinRoll = 0.0f;
40var float autocvar_cg_modelSpinRollSpeed = 0.0f;
41var float autocvar_cg_modelSpinPitch = 0.0f;
42var float autocvar_cg_modelSpinPitchSpeed = 0.0f;
43var float autocvar_cg_modelBobHeight = 0.0f;
44var float autocvar_cg_modelBobHeightSpeed = 0.0f;
45
46#define PRINTFLAG(x) if (cvar("net_showUpdates") || g_net_debug) \
47 print(sprintf("%f %s read update %s\n", time, classname, #x));
48
49#define READENTITY_BYTE(field, changedflag) {\
50 if (flChanged & changedflag) {\
51 field = readbyte();\
52 PRINTFLAG(changedflag); \
53 }\
54}
55
56#define READENTITY_SHORT(field, changedflag) {\
57 if (flChanged & changedflag) {\
58 field = readshort();\
59 PRINTFLAG(changedflag); \
60 }\
61}
62
63#define READENTITY_FLOAT(field, changedflag) {\
64 if (flChanged & changedflag) {\
65 field = readfloat();\
66 PRINTFLAG(changedflag); \
67 }\
68}
69
70#define READENTITY_INT(field, changedflag) {\
71 if (flChanged & changedflag) {\
72 field = readint();\
73 PRINTFLAG(changedflag); \
74 }\
75}
76
77#define READENTITY_STRING(field, changedflag) {\
78 if (flChanged & changedflag) {\
79 field = readstring();\
80 PRINTFLAG(changedflag); \
81 }\
82}
83
84#define READENTITY_COORD(field, changedflag) {\
85 if (flChanged & changedflag) {\
86 field = readcoord();\
87 PRINTFLAG(changedflag); \
88 }\
89}
90
91#define READENTITY_ANGLE(field, changedflag) {\
92 if (flChanged & changedflag) {\
93 field = readangle();\
94 PRINTFLAG(changedflag); \
95 }\
96}
97
98#define READENTITY_ENTITY(field, changedflag) {\
99 if (flChanged & changedflag) {\
100 field = findentity(world, ::entnum, readentitynum());\
101 PRINTFLAG(changedflag); \
102 }\
103}
104
105#define READENTITY_ENTNUM(field, changedflag) {\
106 if (flChanged & changedflag) {\
107 field = readentitynum();\
108 PRINTFLAG(changedflag); \
109 }\
110}
111
112#define READENTITY_COLOR(field, changedflag) {\
113 if (flChanged & changedflag) {\
114 field = readbyte() / 255;\
115 PRINTFLAG(changedflag); \
116 }\
117}
118
119#define READENTITY_MODELINDEX(field, changedflag) {\
120 if (flChanged & changedflag) {\
121 field = readshort();\
122 PRINTFLAG(changedflag); \
123 }\
124}
125
126/* undocumented printcall types */
127#define PRINT_LOW 0
128#define PRINT_MEDIUM 1
129#define PRINT_HIGH 2
130#define PRINT_CHAT 3
131
132var bool g_dlight_cached = false;
133var bool g_client_world_loaded = false;
134
135const float MASK_GLOWS = 16;
136var bool g_focus;
137bool Util_IsFocused(void);
138
139/* fonts */
140font_s FONT_16;
141font_s FONT_20;
142font_s FONT_CON;
143font_s FONT_CENTERPRINT;
144
145//var string g_shellchrome;
146var float g_shellchromeshader;
147var float g_shellchromeshader_cull;
148
149/* clientside cvars */
150var float autocvar_in_zoomSensitivity = 1.0f;
151var int autocvar_pm_stairSmoothing = TRUE;
152var int autocvar_pm_thirdPerson = FALSE;
153var int autocvar_cg_viewmodelFlip = FALSE;
154var vector autocvar_con_color = [255,150,0];
155var vector autocvar_vgui_color = [255,170,0];
156var vector autocvar_cg_viewmodelOffset = [0,0,0];
157var int autocvar_cg_viewmodelPass = 0;
158var float autocvar_cg_viewmodelFov = 90.0f;
159var float autocvar_cg_viewmodelScale = 1.0f;
160var float autocvar_cg_hudAspect = 0.0f;
161var bool autocvar_pm_crouchToggle = false;
162
163/* particle descriptors */
164var float PART_DUSTMOTE;
165var float PART_BURNING;
166
167/* misc globals */
168vector video_mins;
169vector g_vidsize;
170vector mouse_pos;
171int g_iIntermission;
172
173/* this actually belongs in builtins.h since its an undocumented global */
174float clframetime;
175
176string(string modelname, int frame, float frametime) spriteframe = #0;
177
178void CSQC_UpdateSeat(void);
179
181void
182drawstring_r(vector p, string t, vector s, vector c, float a, float f)
183{
184 p[0] -= stringwidth(t, TRUE, s);
185 drawstring(p, t, s, c, a, f);
186}
187
188void GameMessage_Setup(string, int);
189void View_SetMuzzleflash(int);
190
191void Event_Callback(float mtime, __inout float btime);
192void View_AddEvent(void(void) pCallback, float flTime);
193void View_PlayAnimation(int);
194void View_PlayAnimation(int);
195
196void View_EnableViewmodel(void);
197void View_DisableViewmodel(void);
198void View_SetViewmodelSkin(float);
199
201void drawrect(vector pos, vector sz, float thickness, vector rgb, float al, optional float dfl)
202{
203 /* top */
204 drawfill(pos, [sz[0], thickness], rgb, al, dfl);
205 /* bottom */
206 drawfill(pos + [0, sz[1] - thickness], [sz[0], thickness], rgb, al, dfl);
207 /* left */
208 drawfill(pos + [0, thickness], [thickness, sz[1] - (thickness * 2)], rgb, al, dfl);
209 /* right */
210 drawfill(pos + [sz[0] - thickness, thickness], [thickness, sz[1] - (thickness * 2)], rgb, al, dfl);
211}
212
216void
217drawpic3d(vector worldpos, string mat, vector sz, vector rgb, float alpha)
218{
219 static bool
220 drawpic3d_visible(vector p1) {
221 vector delta;
222 float fov;
223 vector p2 = g_view.GetCameraOrigin();
224 vector ang = g_view.GetCameraAngle();
225
226 makevectors(ang);
227 delta = normalize (p1 - p2);
228 fov = delta * v_forward;
229
230 if (fov > (g_view.GetAFOV()/180)) {
231 traceline(p2, p1, MOVE_WORLDONLY, self);
232 if (trace_fraction == 1.0) {
233 return (1);
234 }
235 }
236 return (0);
237 }
238
239 if (drawpic3d_visible(worldpos) == true) {
240 vector vecProj = project(worldpos) - (sz/2);
241 drawpic(vecProj, mat, sz, rgb, alpha);
242 }
243}
244
246void
247drawcone(vector vecOrigin, vector vecAngle, int iDivisions, float flLength, float flRadius, vector vecColor, float flAlpha)
248{
249 vector c;
250 vector e0;
251 vector e1;
252 float angDelta;
253
254 static vector
255 perpendicularCross(vector v)
256 {
257 float min = fabs(v[0]);
258 vector ca = [1, 0, 0];
259
260 if (fabs(v[1]) < min) {
261 min = fabs(v.y);
262 ca = [0, 1, 0];
263 }
264
265 if (fabs(v[2]) < min) {
266 ca = [0, 0, 1];
267 }
268
269 return crossproduct(v, ca);
270 }
271
272 makevectors(vecAngle + [0, 0, 0]);
273 vecAngle = v_forward * -1;
274 c = vecOrigin + (-vecAngle * flLength);
275 e0 = perpendicularCross(vecAngle);
276 e1 = crossproduct(e0, vecAngle);
277 angDelta = 360.0 / (iDivisions-1) * (M_PI / 180.0f);
278
279 R_BeginPolygon("debugcone");
280 R_PolygonVertex(vecOrigin, [0,0], vecColor, flAlpha);
281 for (int i = 0; i < iDivisions; ++i) {
282 vector vecPoint;
283 float rad = angDelta * i;
284 vecPoint = c + (((e0 * cos(rad)) + (e1 * sin(rad))) * flRadius);
285 R_PolygonVertex(vecPoint, [0,0], vecColor, flAlpha);
286 }
287 R_EndPolygon();
288}
289
291void
292precache_cubemap(string path)
293{
294 precache_pic(strcat(path, "_bk"));
295 precache_pic(strcat(path, "_dn"));
296 precache_pic(strcat(path, "_ft"));
297 precache_pic(strcat(path, "_lf"));
298 precache_pic(strcat(path, "_rt"));
299 precache_pic(strcat(path, "_up"));
300}
301
302typedef enum
303{
304 STANCE_DEFAULT = 0,
305 STANCE_CROUCH = 1,
306 STANCE_PRONE = 2,
307} movementStance_t;
308
309struct
310{
311 /* viewmodel stuff */
312 entity m_eViewModel;
313 entity m_eMuzzleflash;
314 int m_iVMBones;
315 entity m_eViewModelL;
316 entity m_eMuzzleflashL;
317 int m_iVMBonesL;
318
319 void(void) m_pEventCall;
320 float m_flEventTime;
321 float m_flEventFrame;
322 float m_flEventMdl;
323 entity m_iEventEntity;
324
325 int m_iLastWeapon;
326 int m_iOldWeapon;
327
328 /* damage overlay */
329 float m_flDamageAlpha;
330 vector m_vecDamagePos;
331 int m_iDamageFlags;
332
333 /* +zoomin cmd */
334 int m_iZoomed;
335 float m_flZoomTime;
336
337 /* player fields */
338 entity m_ePlayer;
339 vector m_vecPredictedOrigin;
340 vector m_vecPredictedOriginOld;
341 vector m_vecPredictedVelocity;
342 float m_flPredictedFlags;
343
344 /* camera fields */
345 vector m_vecCameraOrigin;
346 vector m_vecCameraAngle;
347 float m_flCameraTime;
348
349 int m_iHUDWeaponSelected;
350 float m_flHUDWeaponSelectTime;
351
352 int m_iScoresVisible;
353
354 /* saturn controller */
355 int m_iSaturnMenu;
356
357 /* centerprint related */
358 float m_flCenterprintAlpha;
359 float m_flCenterprintTime;
360 float m_iCenterprintLines;
361 string m_strCenterprintBuffer[18];
362
363 /* chat related */
364 float m_flPrintTime;
365 string m_strPrintBuffer[5];
366 int m_iPrintLines;
367
368 bool m_iInputAttack;
369 bool m_iInputAttack2;
370 bool m_iInputReload;
371 bool m_iInputUse;
372 bool m_iInputDuck;
373 bool m_iInputSprint;
374 bool m_iInputProne;
375 bool m_iInputJump;
376 movementStance_t m_dForceStance;
377 float m_flInputBlockTime;
378
379 /* fading */
380 float m_flFadeDuration;
381 float m_flFadeHold;
382 float m_flFadeMaxAlpha;
383 float m_flFadeStyle;
384 float m_flFadeAlpha;
385 float m_flFadeTime;
386 float m_flSprintLerp;
387 vector m_vecFadeColor;
388 int m_iFadeActive;
389
390 /* shake */
391 float m_flShakeFreq;
392 float m_flShakeDuration;
393 float m_flShakeTime;
394 float m_flShakeAmp;
395
396 vector m_vecLag;
397
398 /* vehicles */
399 float m_flVehTransition;
400 vector m_vecVehEntry;
401
402 /* new XR helpers */
403 bool m_bMoveForward;
404
405 bool m_bInterfaceFocused;
406 bool m_bSpecInput;
407
408 int m_iLeanDir;
409 float m_flLeaning;
410 int m_iSprinting;
411
412 int m_iSelectedWeapon;
413 bool m_bCommandMenu;
414} g_seats[4], *pSeat;
415
416.float modelindex2;
417.float modelindex3;
418.float modelindex4;
419
420var vector g_vecMousePos;
421var vector g_hudmins;
422var vector g_hudres;
423
424var ncRadar g_overview;
425
Tasked with managing overview/radar type widgets.
Definition: NSRadar.h:30
nonvirtual float GetAFOV(void)
Returns the absolute field of view of the ncView.
Definition: NSView.qc:229
nonvirtual vector GetCameraOrigin(void)
Returns the 3D world coordinate of the ncView.
Definition: NSView.qc:180
nonvirtual vector GetCameraAngle(void)
Returns the 3D direction of the ncView.
Definition: NSView.qc:186
ncView g_view
the current seat run for each draw call, for each player.
Definition: NSView.h:156
void GameMessage_Setup(string strMessage, int iChannel)
Places a message within a specified channel.
Definition: text.qc:262
Representation of a font.
Definition: api_func.h:39