Nuclide
Software Development Kit for id Technology
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
139var int g_numplayerslots;
140int Util_GetMaxPlayers(void);
141
142/* fonts */
143font_s FONT_16;
144font_s FONT_20;
145font_s FONT_CON;
146font_s FONT_CENTERPRINT;
147
148//var string g_shellchrome;
149var float g_shellchromeshader;
150var float g_shellchromeshader_cull;
151
152/* clientside cvars */
153var float autocvar_in_zoomSensitivity = 1.0f;
154var int autocvar_pm_stairSmoothing = TRUE;
155var int autocvar_pm_thirdPerson = FALSE;
156var int autocvar_cg_viewmodelFlip = FALSE;
157var vector autocvar_con_color = [255,150,0];
158var vector autocvar_vgui_color = [255,170,0];
159var vector autocvar_cg_viewmodelOffset = [0,0,0];
160var int autocvar_cg_viewmodelPass = 0;
161var float autocvar_cg_viewmodelFov = 90.0f;
162var float autocvar_cg_viewmodelScale = 1.0f;
163var float autocvar_cg_hudAspect = 0.0f;
164var bool autocvar_pm_crouchToggle = false;
165
166/* particle descriptors */
167var float PART_DUSTMOTE;
168var float PART_BURNING;
169
170/* misc globals */
171vector video_mins;
172vector g_vidsize;
173vector mouse_pos;
174int g_iIntermission;
175
176/* this actually belongs in builtins.h since its an undocumented global */
177float clframetime;
178
179string(string modelname, int frame, float frametime) spriteframe = #0;
180
181void CSQC_UpdateSeat(void);
182
184void
185drawstring_r(vector p, string t, vector s, vector c, float a, float f)
186{
187 p[0] -= stringwidth(t, TRUE, s);
188 drawstring(p, t, s, c, a, f);
189}
190
191void GameMessage_Setup(string, int);
192void View_SetMuzzleflash(int);
193
194void Event_Callback(float mtime, __inout float btime);
195void View_AddEvent(void(void) pCallback, float flTime);
196void View_PlayAnimation(int);
197void View_PlayAnimation(int);
198
199void View_EnableViewmodel(void);
200void View_DisableViewmodel(void);
201void View_SetViewmodelSkin(float);
202
204void drawrect(vector pos, vector sz, float thickness, vector rgb, float al, optional float dfl)
205{
206 /* top */
207 drawfill(pos, [sz[0], thickness], rgb, al, dfl);
208 /* bottom */
209 drawfill(pos + [0, sz[1] - thickness], [sz[0], thickness], rgb, al, dfl);
210 /* left */
211 drawfill(pos + [0, thickness], [thickness, sz[1] - (thickness * 2)], rgb, al, dfl);
212 /* right */
213 drawfill(pos + [sz[0] - thickness, thickness], [thickness, sz[1] - (thickness * 2)], rgb, al, dfl);
214}
215
219void
220drawpic3d(vector worldpos, string mat, vector sz, vector rgb, float alpha)
221{
222 static bool
223 drawpic3d_visible(vector p1) {
224 vector delta;
225 float fov;
226 vector p2 = g_view.GetCameraOrigin();
227 vector ang = g_view.GetCameraAngle();
228
229 makevectors(ang);
230 delta = normalize (p1 - p2);
231 fov = delta * v_forward;
232
233 if (fov > (g_view.GetAFOV()/180)) {
234 traceline(p2, p1, MOVE_WORLDONLY, self);
235 if (trace_fraction == 1.0) {
236 return (1);
237 }
238 }
239 return (0);
240 }
241
242 if (drawpic3d_visible(worldpos) == true) {
243 vector vecProj = project(worldpos) - (sz/2);
244 drawpic(vecProj, mat, sz, rgb, alpha);
245 }
246}
247
249void
250drawcone(vector vecOrigin, vector vecAngle, int iDivisions, float flLength, float flRadius, vector vecColor, float flAlpha)
251{
252 vector c;
253 vector e0;
254 vector e1;
255 float angDelta;
256
257 static vector
258 perpendicularCross(vector v)
259 {
260 float min = fabs(v[0]);
261 vector ca = [1, 0, 0];
262
263 if (fabs(v[1]) < min) {
264 min = fabs(v.y);
265 ca = [0, 1, 0];
266 }
267
268 if (fabs(v[2]) < min) {
269 ca = [0, 0, 1];
270 }
271
272 return crossproduct(v, ca);
273 }
274
275 makevectors(vecAngle + [0, 0, 0]);
276 vecAngle = v_forward * -1;
277 c = vecOrigin + (-vecAngle * flLength);
278 e0 = perpendicularCross(vecAngle);
279 e1 = crossproduct(e0, vecAngle);
280 angDelta = 360.0 / (iDivisions-1) * (M_PI / 180.0f);
281
282 R_BeginPolygon("debugcone");
283 R_PolygonVertex(vecOrigin, [0,0], vecColor, flAlpha);
284 for (int i = 0; i < iDivisions; ++i) {
285 vector vecPoint;
286 float rad = angDelta * i;
287 vecPoint = c + (((e0 * cos(rad)) + (e1 * sin(rad))) * flRadius);
288 R_PolygonVertex(vecPoint, [0,0], vecColor, flAlpha);
289 }
290 R_EndPolygon();
291}
292
294void
295precache_cubemap(string path)
296{
297 precache_pic(strcat(path, "_bk"));
298 precache_pic(strcat(path, "_dn"));
299 precache_pic(strcat(path, "_ft"));
300 precache_pic(strcat(path, "_lf"));
301 precache_pic(strcat(path, "_rt"));
302 precache_pic(strcat(path, "_up"));
303}
304
305typedef enum
306{
307 STANCE_DEFAULT = 0,
308 STANCE_CROUCH = 1,
309 STANCE_PRONE = 2,
310} movementStance_t;
311
312struct
313{
314 /* viewmodel stuff */
315 entity m_eViewModel;
316 entity m_eMuzzleflash;
317 int m_iVMBones;
318 entity m_eViewModelL;
319 entity m_eMuzzleflashL;
320 int m_iVMBonesL;
321
322 void(void) m_pEventCall;
323 float m_flEventTime;
324 float m_flEventFrame;
325 float m_flEventMdl;
326 entity m_iEventEntity;
327
328 int m_iLastWeapon;
329 int m_iOldWeapon;
330
331 /* damage overlay */
332 float m_flDamageAlpha;
333 vector m_vecDamagePos;
334 int m_iDamageFlags;
335
336 /* +zoomin cmd */
337 int m_iZoomed;
338 float m_flZoomTime;
339
340 /* player fields */
341 entity m_ePlayer;
342 vector m_vecPredictedOrigin;
343 vector m_vecPredictedOriginOld;
344 vector m_vecPredictedVelocity;
345 float m_flPredictedFlags;
346
347 /* camera fields */
348 vector m_vecCameraOrigin;
349 vector m_vecCameraAngle;
350 float m_flCameraTime;
351
352 int m_iHUDWeaponSelected;
353 float m_flHUDWeaponSelectTime;
354
355 int m_iScoresVisible;
356
357 /* saturn controller */
358 int m_iSaturnMenu;
359
360 /* centerprint related */
361 float m_flCenterprintAlpha;
362 float m_flCenterprintTime;
363 float m_iCenterprintLines;
364 string m_strCenterprintBuffer[18];
365
366 /* chat related */
367 float m_flPrintTime;
368 string m_strPrintBuffer[5];
369 int m_iPrintLines;
370
371 bool m_iInputAttack;
372 bool m_iInputAttack2;
373 bool m_iInputReload;
374 bool m_iInputUse;
375 bool m_iInputDuck;
376 bool m_iInputSprint;
377 bool m_iInputProne;
378 bool m_iInputJump;
379 movementStance_t m_dForceStance;
380 float m_flInputBlockTime;
381
382 /* fading */
383 float m_flFadeDuration;
384 float m_flFadeHold;
385 float m_flFadeMaxAlpha;
386 float m_flFadeStyle;
387 float m_flFadeAlpha;
388 float m_flFadeTime;
389 float m_flSprintLerp;
390 vector m_vecFadeColor;
391 int m_iFadeActive;
392
393 /* shake */
394 float m_flShakeFreq;
395 float m_flShakeDuration;
396 float m_flShakeTime;
397 float m_flShakeAmp;
398
399 vector m_vecLag;
400
401 /* vehicles */
402 float m_flVehTransition;
403 vector m_vecVehEntry;
404
405 /* new XR helpers */
406 bool m_bMoveForward;
407
408 bool m_bInterfaceFocused;
409 bool m_bSpecInput;
410
411 int m_iLeanDir;
412 float m_flLeaning;
413 int m_iSprinting;
414
415 int m_iSelectedWeapon;
416 bool m_bCommandMenu;
417} g_seats[4], *pSeat;
418
419.float modelindex2;
420.float modelindex3;
421.float modelindex4;
422
423var vector g_vecMousePos;
424var vector g_hudmins;
425var vector g_hudres;
426
427var NSRadar g_overview;
Tasked with managing overview/radar type widgets.
Definition: NSRadar.h:30
nonvirtual vector GetCameraAngle(void)
Returns the 3D direction of the NSView.
Definition: NSView.qc:186
nonvirtual vector GetCameraOrigin(void)
Returns the 3D world coordinate of the NSView.
Definition: NSView.qc:180
nonvirtual float GetAFOV(void)
Returns the absolute field of view of the NSView.
Definition: NSView.qc:229
NSView 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