Nuclide
Software Development Kit for id Tech
defs.h
Go to the documentation of this file.
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 "../shared/entityDef.h"
18#include "text.h"
19#include "textmenu.h"
20#include "font.h"
21#include "fade.h"
22#include "cmd.h"
23#include "util.h"
24#include "NSView.h"
25#include "NSRadar.h"
26#include "crosshair.h"
27
28var bool g_net_debug = false;
29var bool g_cheats = false;
30
31#define PRINTFLAG(x) if (cvar("net_showUpdates") || g_net_debug) \
32 print(sprintf("%f %s read update %s\n", time, classname, #x));
33
34#define READENTITY_BYTE(field, changedflag) {\
35 if (flChanged & changedflag) {\
36 field = readbyte();\
37 PRINTFLAG(changedflag); \
38 }\
39}
40
41#define READENTITY_SHORT(field, changedflag) {\
42 if (flChanged & changedflag) {\
43 field = readshort();\
44 PRINTFLAG(changedflag); \
45 }\
46}
47
48#define READENTITY_FLOAT(field, changedflag) {\
49 if (flChanged & changedflag) {\
50 field = readfloat();\
51 PRINTFLAG(changedflag); \
52 }\
53}
54
55#define READENTITY_INT(field, changedflag) {\
56 if (flChanged & changedflag) {\
57 field = readint();\
58 PRINTFLAG(changedflag); \
59 }\
60}
61
62#define READENTITY_STRING(field, changedflag) {\
63 if (flChanged & changedflag) {\
64 field = readstring();\
65 PRINTFLAG(changedflag); \
66 }\
67}
68
69#define READENTITY_COORD(field, changedflag) {\
70 if (flChanged & changedflag) {\
71 field = readcoord();\
72 PRINTFLAG(changedflag); \
73 }\
74}
75
76#define READENTITY_ANGLE(field, changedflag) {\
77 if (flChanged & changedflag) {\
78 field = readangle();\
79 PRINTFLAG(changedflag); \
80 }\
81}
82
83#define READENTITY_ENTITY(field, changedflag) {\
84 if (flChanged & changedflag) {\
85 field = findentity(world, ::entnum, readentitynum());\
86 PRINTFLAG(changedflag); \
87 }\
88}
89
90#define READENTITY_ENTNUM(field, changedflag) {\
91 if (flChanged & changedflag) {\
92 field = readentitynum();\
93 PRINTFLAG(changedflag); \
94 }\
95}
96
97#define READENTITY_COLOR(field, changedflag) {\
98 if (flChanged & changedflag) {\
99 field = readbyte() / 255;\
100 PRINTFLAG(changedflag); \
101 }\
102}
103
104#define READENTITY_MODELINDEX(field, changedflag) {\
105 if (flChanged & changedflag) {\
106 field = readshort();\
107 PRINTFLAG(changedflag); \
108 }\
109}
110
111/* undocumented printcall types */
112#define PRINT_LOW 0
113#define PRINT_MEDIUM 1
114#define PRINT_HIGH 2
115#define PRINT_CHAT 3
116
117var bool g_dlight_cached = false;
118var bool g_client_world_loaded = false;
119
120const float MASK_GLOWS = 16;
121var bool g_focus;
122bool Util_IsFocused(void);
123
125int Util_GetMaxPlayers(void);
126
127/* fonts */
131
132//var string g_shellchrome;
135
136/* clientside cvars */
141var vector autocvar_con_color = [255,150,0];
142var vector autocvar_vgui_color = [255,170,0];
143var vector autocvar_cg_viewmodelOffset = [0,0,0];
145var float autocvar_cg_viewmodelFov = 90.0f;
147var float autocvar_cg_hudAspect = 0.0f;
149
150/* particle descriptors */
152var float PART_BURNING;
153
154/* misc globals */
159
160/* this actually belongs in builtins.h since its an undocumented global */
162
163string(string modelname, int frame, float frametime) spriteframe = #0;
164
165void CSQC_UpdateSeat(void);
166
168void
169drawstring_r(vector p, string t, vector s, vector c, float a, float f)
170{
171 p[0] -= stringwidth(t, TRUE, s);
172 drawstring(p, t, s, c, a, f);
173}
174
175void GameMessage_Setup(string, int);
176void View_SetMuzzleflash(int);
177
178void Event_Callback(float mtime, __inout float btime);
179void View_AddEvent(void(void) pCallback, float flTime);
180void View_PlayAnimation(int);
181void View_PlayAnimation(int);
182
183void View_EnableViewmodel(void);
184void View_DisableViewmodel(void);
185void View_SetViewmodelSkin(float);
186
188void drawrect(vector pos, vector sz, float thickness, vector rgb, float al, optional float dfl)
189{
190 /* top */
191 drawfill(pos, [sz[0], thickness], rgb, al, dfl);
192 /* bottom */
193 drawfill(pos + [0, sz[1] - thickness], [sz[0], thickness], rgb, al, dfl);
194 /* left */
195 drawfill(pos + [0, thickness], [thickness, sz[1] - (thickness * 2)], rgb, al, dfl);
196 /* right */
197 drawfill(pos + [sz[0] - thickness, thickness], [thickness, sz[1] - (thickness * 2)], rgb, al, dfl);
198}
199
200
204void
205drawpic3d(vector worldpos, string mat, vector sz, vector rgb, float alpha)
206{
207 static bool
208 drawpic3d_visible(vector p1) {
209 vector delta;
210 float fov;
211 vector p2 = g_view.GetCameraOrigin();
212 vector ang = g_view.GetCameraAngle();
213
214 makevectors(ang);
215 delta = normalize (p1 - p2);
216 fov = delta * v_forward;
217
218 if (fov > (g_view.GetAFOV()/180)) {
219 traceline(p2, p1, MOVE_WORLDONLY, self);
220 if (trace_fraction == 1.0) {
221 return (1);
222 }
223 }
224 return (0);
225 }
226
227 if (drawpic3d_visible(worldpos) == true) {
228 vector vecProj = project(worldpos) - (sz/2);
229 drawpic(vecProj, mat, sz, rgb, alpha);
230 }
231}
232
234void
235drawcone(vector vecOrigin, vector vecAngle, int iDivisions, float flLength, float flRadius, vector vecColor, float flAlpha)
236{
237 vector c;
238 vector e0;
239 vector e1;
240 float angDelta;
241
242 static vector
243 perpendicularCross(vector v)
244 {
245 float min = fabs(v[0]);
246 vector ca = [1, 0, 0];
247
248 if (fabs(v[1]) < min) {
249 min = fabs(v.y);
250 ca = [0, 1, 0];
251 }
252
253 if (fabs(v[2]) < min) {
254 ca = [0, 0, 1];
255 }
256
257 return crossproduct(v, ca);
258 }
259
260 makevectors(vecAngle + [0, 0, 0]);
261 vecAngle = v_forward * -1;
262 c = vecOrigin + (-vecAngle * flLength);
263 e0 = perpendicularCross(vecAngle);
264 e1 = crossproduct(e0, vecAngle);
265 angDelta = 360.0 / (iDivisions-1) * (M_PI / 180.0f);
266
267 R_BeginPolygon("debugcone");
268 R_PolygonVertex(vecOrigin, [0,0], vecColor, flAlpha);
269 for (int i = 0; i < iDivisions; ++i) {
270 vector vecPoint;
271 float rad = angDelta * i;
272 vecPoint = c + (((e0 * cos(rad)) + (e1 * sin(rad))) * flRadius);
273 R_PolygonVertex(vecPoint, [0,0], vecColor, flAlpha);
274 }
275 R_EndPolygon();
276}
277
279void
281{
282 precache_pic(strcat(path, "_bk"));
283 precache_pic(strcat(path, "_dn"));
284 precache_pic(strcat(path, "_ft"));
285 precache_pic(strcat(path, "_lf"));
286 precache_pic(strcat(path, "_rt"));
287 precache_pic(strcat(path, "_up"));
288}
289
290typedef enum
291{
296
297struct
298{
299 /* viewmodel stuff */
306
307 void(void) m_pEventCall;
312
315
316 /* damage overlay */
320
321 /* +zoomin cmd */
324
325 /* player fields */
326 entity m_ePlayer;
331
332 /* camera fields */
336
339
341
342 /* saturn controller */
344
345 /* centerprint related */
350
351 /* chat related */
355
366
367 /* fading */
377
378 /* shake */
383
384 vector m_vecLag;
385
386 /* vehicles */
389
390 /* new XR helpers */
392
395
399
402
403var vector g_vecMousePos;
404var vector g_hudmins;
405var vector g_hudres;
406
NSView handles camera and viewpoints.
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:162
nonvirtual vector GetCameraOrigin(void)
Returns the 3D world coordinate of the NSView.
Definition: NSView.qc:156
nonvirtual float GetAFOV(void)
Returns the absolute field of view of the NSView.
Definition: NSView.qc:205
entity m_eViewModel
Definition: defs.h:300
float m_flFadeDuration
Definition: defs.h:368
vector m_vecPredictedOrigin
Definition: defs.h:327
const float MASK_GLOWS
Definition: defs.h:120
float m_flFadeTime
Definition: defs.h:373
movementStance_t
Definition: defs.h:291
@ STANCE_PRONE
Definition: defs.h:294
@ STANCE_CROUCH
Definition: defs.h:293
@ STANCE_DEFAULT
Definition: defs.h:292
var bool g_net_debug
Definition: defs.h:28
float m_flEventMdl
Definition: defs.h:310
int m_iFadeActive
Definition: defs.h:376
int m_iOldWeapon
Definition: defs.h:314
void View_PlayAnimation(int)
Definition: view.qc:342
float m_flInputBlockTime
Definition: defs.h:365
var vector autocvar_cg_viewmodelOffset
Definition: defs.h:143
movementStance_t m_dForceStance
Definition: defs.h:364
int m_iSelectedWeapon
Definition: defs.h:400
float m_flVehTransition
Definition: defs.h:387
bool m_bInterfaceFocused
Definition: defs.h:393
string m_strCenterprintBuffer[18]
Definition: defs.h:349
string m_strPrintBuffer[5]
Definition: defs.h:353
void View_EnableViewmodel(void)
Definition: view.qc:365
int m_iSprinting
Definition: defs.h:398
bool m_iInputSprint
Definition: defs.h:361
void CSQC_UpdateSeat(void)
Updates our seat pointers.
Definition: entry.qc:26
var NSRadar g_overview
Definition: defs.h:407
var int autocvar_pm_thirdPerson
Definition: defs.h:139
float m_flZoomTime
Definition: defs.h:323
vector g_vidsize
Definition: defs.h:156
entity m_ePlayer
Definition: defs.h:326
float m_flSprintLerp
Definition: defs.h:374
float m_iCenterprintLines
Definition: defs.h:348
int m_iScoresVisible
Definition: defs.h:340
float m_flShakeFreq
Definition: defs.h:379
int m_iLastWeapon
Definition: defs.h:313
int m_iVMBonesL
Definition: defs.h:305
int m_iPrintLines
Definition: defs.h:354
vector m_vecVehEntry
Definition: defs.h:388
entity m_eViewModelL
Definition: defs.h:303
var float autocvar_in_zoomSensitivity
Definition: defs.h:137
int m_iLeanDir
Definition: defs.h:396
font_s FONT_20
Definition: defs.h:129
float m_flEventTime
Definition: defs.h:308
var float autocvar_cg_viewmodelScale
Definition: defs.h:146
var float PART_BURNING
Definition: defs.h:152
int Util_GetMaxPlayers(void)
Definition: util.qc:89
bool m_bSpecInput
Definition: defs.h:394
vector m_vecPredictedVelocity
Definition: defs.h:329
void drawcone(vector vecOrigin, vector vecAngle, int iDivisions, float flLength, float flRadius, vector vecColor, float flAlpha)
Draws a (debug) cone in 3D space.
Definition: defs.h:235
void drawrect(vector pos, vector sz, float thickness, vector rgb, float al, optional float dfl)
Draws a non-filled rectangle with a specified outline.
Definition: defs.h:188
var bool g_client_world_loaded
Definition: defs.h:118
var int g_numplayerslots
Definition: defs.h:124
float m_flPrintTime
Definition: defs.h:352
float m_flFadeHold
Definition: defs.h:369
float m_flFadeMaxAlpha
Definition: defs.h:370
bool m_iInputJump
Definition: defs.h:363
vector m_vecLag
Definition: defs.h:384
float m_flShakeAmp
Definition: defs.h:382
var float autocvar_cg_hudAspect
Definition: defs.h:147
void View_SetMuzzleflash(int)
Definition: view.qc:48
vector mouse_pos
Definition: defs.h:157
bool m_iInputUse
Definition: defs.h:359
var vector g_hudres
Definition: defs.h:405
float m_flShakeDuration
Definition: defs.h:380
vector video_mins
Definition: defs.h:155
entity m_eMuzzleflashL
Definition: defs.h:304
void Event_Callback(float mtime, __inout float btime)
Definition: modelevent.qc:27
float m_flEventFrame
Definition: defs.h:309
var vector autocvar_vgui_color
Definition: defs.h:142
var float g_shellchromeshader_cull
Definition: defs.h:134
vector m_vecDamagePos
Definition: defs.h:318
var int autocvar_cg_viewmodelFlip
Definition: defs.h:140
var float g_shellchromeshader
Definition: defs.h:133
bool m_iInputDuck
Definition: defs.h:360
font_s FONT_CON
Definition: defs.h:130
void drawstring_r(vector p, string t, vector s, vector c, float a, float f)
Like drawstring() but aligns text to the right from the specified screen coordinates.
Definition: defs.h:169
void View_SetViewmodelSkin(float)
Definition: view.qc:385
struct @9 * pSeat[4]
float m_flPredictedFlags
Definition: defs.h:330
var vector g_hudmins
Definition: defs.h:404
float m_flShakeTime
Definition: defs.h:381
float m_flDamageAlpha
Definition: defs.h:317
bool m_bMoveForward
Definition: defs.h:391
float m_flCenterprintTime
Definition: defs.h:347
int m_iEventWeapon
Definition: defs.h:311
var vector g_vecMousePos
Definition: defs.h:403
vector m_vecFadeColor
Definition: defs.h:375
bool m_iInputReload
Definition: defs.h:358
void View_AddEvent(void(void) pCallback, float flTime)
Definition: view.qc:57
font_s FONT_16
Definition: defs.h:128
var float autocvar_cg_viewmodelFov
Definition: defs.h:145
var bool g_dlight_cached
Definition: defs.h:117
var bool autocvar_pm_crouchToggle
Definition: defs.h:148
var int autocvar_cg_viewmodelPass
Definition: defs.h:144
bool m_iInputAttack
Definition: defs.h:356
int g_iIntermission
Definition: defs.h:158
float m_flLeaning
Definition: defs.h:397
float clframetime
Definition: defs.h:161
float m_flFadeStyle
Definition: defs.h:371
vector m_vecCameraOrigin
Definition: defs.h:333
float m_flCameraTime
Definition: defs.h:335
entity m_eMuzzleflash
Definition: defs.h:301
int m_iVMBones
Definition: defs.h:302
struct @9 g_seats[4]
var vector autocvar_con_color
Definition: defs.h:141
int m_iDamageFlags
Definition: defs.h:319
int m_iSaturnMenu
Definition: defs.h:343
float m_flFadeAlpha
Definition: defs.h:372
vector m_vecCameraAngle
Definition: defs.h:334
float m_flHUDWeaponSelectTime
Definition: defs.h:338
void View_DisableViewmodel(void)
Definition: view.qc:375
void GameMessage_Setup(string, int)
Definition: text.qc:262
var float PART_DUSTMOTE
Definition: defs.h:151
void drawpic3d(vector worldpos, string mat, vector sz, vector rgb, float alpha)
Like drawpic, but instead of screen coords, it will take world coords.
Definition: defs.h:205
bool m_iInputAttack2
Definition: defs.h:357
int m_iZoomed
Definition: defs.h:322
var bool g_cheats
Definition: defs.h:29
void precache_cubemap(string path)
Like precache_pic, but will precache sky/cube map images (_bk, _dn etc.)
Definition: defs.h:280
bool m_iInputProne
Definition: defs.h:362
vector m_vecPredictedOriginOld
Definition: defs.h:328
string(string modelname, int frame, float frametime) spriteframe
var int autocvar_pm_stairSmoothing
Definition: defs.h:138
var bool g_focus
Definition: defs.h:121
int m_iHUDWeaponSelected
Definition: defs.h:337
bool Util_IsFocused(void)
Definition: util.qc:83
float m_flCenterprintAlpha
Definition: defs.h:346
NSView g_view
the current seat run for each draw call, for each player.
Definition: NSView.h:156
vector v_forward
Definition: math.h:45
void makevectors(vector angles)
Definition: math.h:48
Console Commands.
void(void) PlayerUse
__wrap void traceline(vector v1, vector v2, float flags, entity ent)
Definition: defs.h:379
Representation of a font.
Definition: font.h:46
noref float frame
Definition: ui_3dview.qc:22