OpenMoHAA 0.83.0
Loading...
Searching...
No Matches
cg_public.h
1/*
2===========================================================================
3Copyright (C) 2023 the OpenMoHAA team
4
5This file is part of OpenMoHAA source code.
6
7OpenMoHAA source code is free software; you can redistribute it
8and/or modify it under the terms of the GNU General Public License as
9published by the Free Software Foundation; either version 2 of the License,
10or (at your option) any later version.
11
12OpenMoHAA source code is distributed in the hope that it will be
13useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with OpenMoHAA source code; if not, write to the Free Software
19Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20===========================================================================
21*/
22
23// DESCRIPTION:
24// client game public interfaces
25
26#pragma once
27
28#include "../renderercommon/tr_types.h"
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
34#define MAGIC_UNUSED_NUMBER 7777
35#define CMD_BACKUP 128
36#define CMD_MASK (CMD_BACKUP - 1)
37 // allow a lot of command backups for very fast systems
38 // multiple commands may be combined into a single packet, so this
39 // needs to be larger than PACKET_BACKUP
40
41#define MAX_ENTITIES_IN_SNAPSHOT 1024
42
43 // snapshots are a view of the server at a given time
44
45 // Snapshots are generated at regular time intervals by the server,
46 // but they may not be sent if a client's rate level is exceeded, or
47 // they may be dropped by the network.
48 typedef struct {
49 int snapFlags; // SNAPFLAG_RATE_DELAYED, etc
50 int ping;
51
52 int serverTime; // server time the message is valid for (in msec)
53
54 byte areamask[MAX_MAP_AREA_BYTES]; // portalarea visibility bits
55
56 playerState_t ps; // complete information about the current player at this time
57
58 int numEntities; // all of the entities that need to be presented
59 entityState_t entities[MAX_ENTITIES_IN_SNAPSHOT]; // at the time of this snapshot
60
61 int numServerCommands; // text based server commands to execute when this
62 int serverCommandSequence; // snapshot becomes current
63
64 int number_of_sounds;
65 server_sound_t sounds[MAX_SERVER_SOUNDS];
66 } snapshot_t;
67
68 typedef struct stopWatch_s {
69 int iStartTime;
70 int iEndTime;
71 int eType;
72 } stopWatch_t;
73
74 typedef struct AliasList_s AliasList_t;
75 typedef struct AliasListNode_s AliasListNode_t;
76 typedef struct dtiki_s dtiki_t;
77 typedef struct tiki_cmd_s tiki_cmd_t;
78
79 /*
80==================================================================
81
82functions imported from the main executable
83
84==================================================================
85*/
86
87#define CGAME_IMPORT_API_VERSION 3
88
89 /*
90==================================================================
91
92functions exported to the main executable
93
94==================================================================
95*/
96
97 typedef struct {
98 int apiversion;
99
100 //============== general services ==================
101
102 // print message on the local console
103 void (*Printf)(const char *fmt, ...);
104 void (*DPrintf)(const char *fmt, ...);
105 void (*DebugPrintf)(const char *fmt, ...);
106
107 // managed memory allocation
108 void *(*Malloc)(int size);
109 void (*Free)(void *block);
110
111 // abort the game
112 void (*Error)(int errorLevel, const char *fmt, ...);
113
114 // milliseconds should only be used for profiling, never
115 // for anything game related. Get time from CG_ReadyToBuildScene.
116 int (*Milliseconds)(void);
117
118 // localization
119 const char *(*LV_ConvertString)(const char *string);
120
121 // console variable interaction
122 cvar_t *(*Cvar_Get)(const char *var_name, const char *value, int flags);
123 cvar_t *(*Cvar_Find)(const char *var_name);
124 void (*Cvar_Set)(const char *var_name, const char *value);
125 void (*Cvar_CheckRange)(cvar_t* var, float min, float max, qboolean integral);
126
127 // ClientCommand and ConsoleCommand parameter access
128 int (*Argc)(void);
129 char *(*Argv)(int n);
130 char *(*Args)(void); // concatenation of all argv >= 1
131 void (*AddCommand)(const char *cmd);
132 void (*Cmd_Stuff)(const char *text);
133 void (*Cmd_Execute)(int execWhen, const char *text);
134 void (*Cmd_TokenizeString)(const char *textIn);
135
136 // a -1 return means the file does not exist
137 // NULL can be passed for buf to just determine existance
138 long (*FS_ReadFile)(const char *name, void **buf, qboolean quiet);
139 void (*FS_FreeFile)(void *buf);
140 int (*FS_WriteFile)(const char *qpath, const void *buffer, int size);
141 void (*FS_WriteTextFile)(const char *qpath, const void *buffer, int size);
142 char** (*FS_ListFilteredFiles)(const char* path, const char* extension, const char* filter, qboolean wantSubs, int* numfiles, qboolean allowNonPureFilesOnDisk);
143 void (*FS_FreeFileList)(char **list);
144 fileHandle_t (*FS_FOpenFileWrite)(const char *fileName);
145 size_t (*FS_Write)(const void *buffer, size_t size, fileHandle_t fileHandle);
146 void (*FS_FCloseFile)(fileHandle_t fileHandle);
147 // add commands to the local console as if they were typed in
148 // for map changing, etc. The command is not executed immediately,
149 // but will be executed in order the next time console commands
150 // are processed
151 void (*SendConsoleCommand)(const char *text);
152
153 // =========== client specific functions ===============
154
155 // send a string to the server over the network
156 int (*MSG_ReadBits)(int bits);
157 int (*MSG_ReadChar)();
158 int (*MSG_ReadByte)();
159 int (*MSG_ReadSVC)();
160 int (*MSG_ReadShort)();
161 int (*MSG_ReadLong)();
162 float (*MSG_ReadFloat)();
163 char *(*MSG_ReadString)();
164 char *(*MSG_ReadStringLine)();
165 float (*MSG_ReadAngle8)();
166 float (*MSG_ReadAngle16)();
167 void (*MSG_ReadData)(void *data, int len);
168 float (*MSG_ReadCoord)();
169 void (*MSG_ReadDir)(vec3_t dir);
170 void (*SendClientCommand)(const char *s);
171
172 // CM functions
173 void (*CM_LoadMap)(const char *name, int* checksum);
174 clipHandle_t (*CM_InlineModel)(int index); // 0 = world, 1+ = bmodels
175 int (*CM_NumInlineModels)(void);
176 int (*CM_PointContents)(const vec3_t p, int headnode);
177 int (*CM_TransformedPointContents)(
178 const vec3_t p, clipHandle_t model, const vec3_t origin, const vec3_t angles
179 );
180 void (*CM_BoxTrace)(
181 trace_t *results,
182 const vec3_t start,
183 const vec3_t end,
184 const vec3_t mins,
185 const vec3_t maxs,
186 int headnode,
187 int brushmask,
188 qboolean cylinder
189 );
190 void (*CM_TransformedBoxTrace)(
191 trace_t *results,
192 const vec3_t start,
193 const vec3_t end,
194 const vec3_t mins,
195 const vec3_t maxs,
196 int headnode,
197 int brushmask,
198 const vec3_t origin,
199 const vec3_t angles,
200 qboolean cylinder
201 );
202 clipHandle_t (*CM_TempBoxModel)(const vec3_t mins, const vec3_t maxs, int contents);
203 void (*CM_PrintBSPFileSizes)();
204 qboolean (*CM_LeafInPVS)(int leaf1, int leaf2);
205 int (*CM_PointLeafnum)(const vec3_t p);
206 int (*R_MarkFragments)(
207 int numPoints,
208 const vec3_t *points,
209 const vec3_t projection,
210 int maxPoints,
211 vec3_t pointBuffer,
212 int maxFragments,
213 markFragment_t *fragmentBuffer,
214 float fRadiusSquared
215 );
216 int (*R_MarkFragmentsForInlineModel)(
217 clipHandle_t bmodel,
218 const vec3_t vAngles,
219 const vec3_t vOrigin,
220 int numPoints,
221 const vec3_t *points,
222 const vec3_t projection,
223 int maxPoints,
224 vec3_t pointBuffer,
225 int maxFragments,
226 markFragment_t *fragmentBuffer,
227 float fRadiusSquared
228 );
229
230 void (*R_GetInlineModelBounds)(int index, vec3_t mins, vec3_t maxs);
231 void (*R_GetLightingForDecal)(vec3_t light, const vec3_t facing, const vec3_t origin);
232 void (*R_GetLightingForSmoke)(vec3_t light, const vec3_t origin);
233 int (*R_GatherLightSources)(const vec3_t pos, vec3_t *lightPos, vec3_t *lightIntensity, int maxLights);
234
235 // =========== sound function calls ===============
236
237 void (*S_StartSound)(
238 const vec3_t origin,
239 int entNum,
240 int entChannel,
241 sfxHandle_t sfxHandle,
242 float volume,
243 float minDist,
244 float pitch,
245 float maxDist,
246 int streamed
247 );
248 void (*S_StartLocalSound)(const char *soundName, qboolean forceLoad);
249 void (*S_StopSound)(int entnum, int channel);
250 void (*S_ClearLoopingSounds)(void);
251 void (*S_AddLoopingSound)(
252 const vec3_t origin,
253 const vec3_t velocity,
254 sfxHandle_t sfxHandle,
255 float volume,
256 float minDist,
257 float maxDist,
258 float pitch,
259 int flags
260 );
261 void (*S_Respatialize)(int entityNum, const vec3_t origin, vec3_t axis[3]);
262 void (*S_BeginRegistration)(void);
263 sfxHandle_t (*S_RegisterSound)(const char *sample, int streamed);
264 void (*S_EndRegistration)(void);
265 void (*S_UpdateEntity)(int entityNum, const vec3_t origin, const vec3_t velocity, qboolean use_listener);
266 void (*S_SetReverb)(int reverb_type, float reverb_level);
267 void (*S_SetGlobalAmbientVolumeLevel)(float volume);
268 float (*S_GetSoundTime)(sfxHandle_t handle);
269 int (*S_ChannelNameToNum)(const char *name);
270 const char *(*S_ChannelNumToName)(int channel);
271 int (*S_IsSoundPlaying)(int channelNumber, const char *name);
272
273 // =========== music function calls ===============
274
275 void (*MUSIC_NewSoundtrack)(const char *name);
276 void (*MUSIC_UpdateMood)(int current_mood, int fallback_mood);
277 void (*MUSIC_UpdateVolume)(float volume, float fade_time);
278
279 // =========== camera function calls ===============
280
281 float *(*get_camera_offset)(qboolean *lookactive, qboolean *resetview);
282
283 // =========== renderer function calls ================
284 void (*R_ClearScene)(void);
285 void (*R_RenderScene)(const refdef_t *fd);
286 void (*R_LoadWorldMap)(const char *mapname);
287 void (*R_PrintBSPFileSizes)();
288 int (*MapVersion)();
289 int (*R_MapVersion)();
290 qhandle_t (*R_RegisterModel)(const char *name);
291 qhandle_t (*R_SpawnEffectModel)(const char *name, vec3_t pos, vec3_t axis[3]);
292 qhandle_t (*R_RegisterServerModel)(const char *name);
293 const char * (*R_GetModelName)(qhandle_t hModel);
294 void (*R_UnregisterServerModel)(qhandle_t hModel);
295 qhandle_t (*R_RegisterShader)(const char *name);
296 qhandle_t (*R_RegisterShaderNoMip)(const char *name);
297 const char* (*R_GetShaderName)(qhandle_t hShader);
298 void (*R_AddRefEntityToScene)(const refEntity_t *ent, int parentEntityNumber);
299 void (*R_AddRefSpriteToScene)(const refEntity_t *ent);
300 void (*R_AddLightToScene)(const vec3_t origin, float intensity, float r, float g, float b, int type);
301 qboolean (*R_AddPolyToScene)(qhandle_t hShader, int numVerts, const polyVert_t *verts, int renderfx);
302 void (*R_AddTerrainMarkToScene)(
303 int terrainIndex, qhandle_t hShader, int numVerts, const polyVert_t *verts, int renderFx
304 );
305 void (*R_SetColor)(const vec4_t rgba); // NULL = 1,1,1,1
306 void (*R_DrawStretchPic)(
307 float x,
308 float y,
309 float w,
310 float h,
311 float s1,
312 float t1,
313 float s2,
314 float t2,
315 qhandle_t hShader
316 ); // 0 = white
317 fontheader_t *(*R_LoadFont)(const char *name);
318 void (*R_DrawString)(
319 fontheader_t *font, const char *text, float x, float y, int maxLen, const float *pvVirtualScreen
320 );
321 refEntity_t *(*R_GetRenderEntity)(int entityNumber);
322 void (*R_ModelBounds)(clipHandle_t model, vec3_t mins, vec3_t maxs);
323 float (*R_ModelRadius)(clipHandle_t model);
324 float (*R_Noise)(float x, float y, float z, double t);
325 void (*R_DebugLine)(const vec3_t start, const vec3_t end, float r, float g, float b, float alpha);
326 baseshader_t *(*GetShader)(int shaderNum);
327 // =========== Swipes =============
328 void (*R_SwipeBegin)(float thistime, float life, qhandle_t shader);
329 void (*R_SwipePoint)(vec3_t p1, vec3_t p2, float time);
330 void (*R_SwipeEnd)(void);
331 int (*R_GetShaderWidth)(qhandle_t shader);
332 int (*R_GetShaderHeight)(qhandle_t shader);
333 void (*R_DrawBox)(float x, float y, float w, float h);
334
335 // =========== data shared with the client =============
336 void (*GetGameState)(gameState_t *gamestate);
337 int (*GetSnapshot)(int snapshotNumber, snapshot_t *snapshot);
338 int (*GetServerStartTime)();
339 void (*SetTime)(int time);
340 void (*GetCurrentSnapshotNumber)(int *snapshotNumber, int *serverTime);
341 void (*GetGlconfig)(glconfig_t *glconfig);
342
343 // will return false if the number is so old that it doesn't exist in the buffer anymore
344 qboolean (*GetParseEntityState)(int parseEntityNumber, entityState_t *state);
345 int (*GetCurrentCmdNumber)(void); // returns the most recent command number
346 // which is the local predicted command for
347 // the following frame
348 qboolean (*GetUserCmd)(int cmdNumber, usercmd_t *ucmd);
349 qboolean (*GetServerCommand)(int serverCommandNumber, qboolean differentServer);
350
351 // ALIAS STUFF
352 qboolean (*Alias_Add)(const char *alias, const char *name, const char *parameters);
353 qboolean (*Alias_ListAdd)(AliasList_t *list, const char *alias, const char *name, const char *parameters);
354 const char *(*Alias_FindRandom)(const char *alias, AliasListNode_t **ret);
355 const char *(*Alias_ListFindRandom)(AliasList_t *list, const char *alias, AliasListNode_t **ret);
356 void (*Alias_Dump)(void);
357 void (*Alias_Clear)(void);
358 AliasList_t *(*AliasList_New)(const char *name);
359 void (*Alias_ListFindRandomRange)(
360 AliasList_t *list, const char *alias, int *minIndex, int *maxIndex, float *totalWeight
361 );
362 AliasList_t *(*Alias_GetGlobalList)();
363
364 // ==================== UI STUFF ==========================
365 void (*UI_ShowMenu)(const char *name, qboolean bForce);
366 void (*UI_HideMenu)(const char *name, qboolean bForce);
367 int (*UI_FontStringWidth)(fontheader_t *font, const char *string, int maxLen);
368 // Added in 2.0
369 float (*UI_GetObjectivesTop)(void);
370 void (*UI_GetHighResolutionScale)(vec2_t scale);
371
372 int (*Key_StringToKeynum)(const char *str);
373 const char *(*Key_KeynumToBindString)(int keyNum);
374 void (*Key_GetKeysForCommand)(const char *command, int *key1, int *key2);
375
376 // ==================== TIKI STUFF ==========================
377 // TIKI SPECIFIC STUFF
378 dtiki_t *(*R_Model_GetHandle)(qhandle_t handle);
379 int (*TIKI_NumAnims)(dtiki_t *pmdl);
380 void (*TIKI_CalculateBounds)(dtiki_t *pmdl, float scale, vec3_t mins, vec3_t maxs);
381 const char *(*TIKI_Name)(dtiki_t *tiki);
382 void *(*TIKI_GetSkeletor)(dtiki_t *tiki, int entNum);
383 void (*TIKI_SetEyeTargetPos)(dtiki_t *tiki, int entNum, vec3_t pos);
384
385 // ANIM SPECIFIC STUFF
386 const char *(*Anim_NameForNum)(dtiki_t *tiki, int animnum);
387 int (*Anim_NumForName)(dtiki_t *tiki, const char *name);
388 int (*Anim_Random)(dtiki_t *tiki, const char *name);
389 int (*Anim_NumFrames)(dtiki_t *tiki, int animnum);
390 float (*Anim_Time)(dtiki_t *tiki, int animnum);
391 float (*Anim_Frametime)(dtiki_t *tiki, int animnum);
392 void (*Anim_Delta)(dtiki_t *tiki, int animnum, vec3_t delta);
393 int (*Anim_Flags)(dtiki_t *tiki, int animnum);
394 int (*Anim_FlagsSkel)(dtiki_t *tiki, int animnum);
395 float (*Anim_CrossblendTime)(dtiki_t *tiki, int animnum);
396 qboolean (*Anim_HasCommands)(dtiki_t *tiki, int animnum);
397
398 // FRAME SPECIFIC STUFF
399 qboolean (*Frame_Commands)(dtiki_t *tiki, int animnum, int framenum, tiki_cmd_t *tiki_cmd);
400 qboolean (*Frame_CommandsTime)(dtiki_t *tiki, int animnum, float start, float end, tiki_cmd_t *tiki_cmd);
401
402 // SURFACE SPECIFIC STUFF
403 int (*Surface_NameToNum)(dtiki_t *tiki, const char *name);
404 //const char * (*Surface_NumToName) (dtiki_t* tiki, int num );
405 //int (*Surface_Flags) (dtiki_t* tiki, int num );
406 //int (*Surface_NumSkins) (dtiki_t* tiki, int num );
407
408 // TAG SPECIFIC STUFF
409 int (*Tag_NumForName)(dtiki_t *tiki, const char *name);
410 const char *(*Tag_NameForNum)(dtiki_t *tiki, int num);
411 void (*ForceUpdatePose)(refEntity_t *model);
412 orientation_t (*TIKI_Orientation)(refEntity_t *model, int tagNum);
413 qboolean (*TIKI_IsOnGround)(refEntity_t *model, int tagNum, float threshold);
414
415 // MISCELLANEOUS SPECIFIC STUFF
416 void (*UI_ShowScoreBoard)(const char *menuName);
417 void (*UI_HideScoreBoard)();
418 void (*UI_SetScoreBoardItem)(
419 int itemNumber,
420 const char *data1,
421 const char *data2,
422 const char *data3,
423 const char *data4,
424 const char *data5,
425 const char *data6,
426 const char *data7,
427 const char *data8,
428 const vec4_t textColor,
429 const vec4_t backColor,
430 qboolean isHeader
431 );
432 void (*UI_DeleteScoreBoardItems)(int maxIndex);
433 void (*UI_ToggleDMMessageConsole)(int consoleMode);
434 void (*CL_InitRadar)(radarClient_t* radars, qhandle_t* shaders, int clientNum); // Added in 2.0
435 dtiki_t *(*TIKI_FindTiki)(const char *path);
436 void (*LoadResource)(const char *name);
437 void (*FS_CanonicalFilename)(char *name);
438 void (*CL_RestoreSavedCgameState)();
439 void (*CL_ClearSavedCgameState)();
440
441 size_t (*getConfigStringIdNormalized)(size_t num);
442
443 cvar_t *fsDebug;
444 hdelement_t *HudDrawElements;
445 clientAnim_t *anim;
446 stopWatch_t *stopWatch;
447
449
450 /*
451==================================================================
452
453functions exported to the main executable
454
455==================================================================
456*/
457
458 typedef struct {
459 void (*CG_Init)(clientGameImport_t *imported, int serverMessageNum, int serverCommandSequence, int clientNum);
460 void (*CG_Shutdown)(void);
461 void (*CG_DrawActiveFrame)(int serverTime, int frameTime, stereoFrame_t stereoView, qboolean demoPlayback);
462 qboolean (*CG_ConsoleCommand)(void);
463 void (*CG_GetRendererConfig)(void);
464 void (*CG_Draw2D)(void);
465 void (*CG_EyePosition)(vec3_t *eyePos);
466 void (*CG_EyeOffset)(vec3_t *eyeOffset);
467 void (*CG_EyeAngles)(vec3_t *eyeAngles);
468 float (*CG_SensitivityScale)();
469 void (*CG_ParseCGMessage)();
470 void (*CG_RefreshHudDrawElements)();
471 void (*CG_HudDrawShader)(int info);
472 void (*CG_HudDrawFont)(int info);
473 int (*CG_GetParent)(int entNum);
474 float (*CG_GetObjectiveAlpha)();
475 int (*CG_PermanentMark)(
476 vec3_t origin,
477 vec3_t dir,
478 float orientation,
479 float sScale,
480 float tScale,
481 float red,
482 float green,
483 float blue,
484 float alpha,
485 qboolean doLighting,
486 float sCenter,
487 float tCenter,
488 markFragment_t *markFragments,
489 void *polyVerts
490 );
491 int (*CG_PermanentTreadMarkDecal)(
492 treadMark_t *treadMark,
493 qboolean startSegment,
494 qboolean doLighting,
495 markFragment_t *markFragments,
496 void *polyVerts
497 );
498 int (*CG_PermanentUpdateTreadMark)(
499 treadMark_t *treadMark, float alpha, float minSegment, float maxSegment, float maxOffset, float texScale
500 );
501 void (*CG_ProcessInitCommands)(dtiki_t *tiki, refEntity_t *ent);
502 void (*CG_EndTiki)(dtiki_t *tiki);
503 const char *(*CG_GetColumnName)(int columnNum, int *columnWidth);
504 void (*CG_GetScoreBoardColor)(float *red, float *green, float *blue, float *alpha);
505 void (*CG_GetScoreBoardFontColor)(float *red, float *green, float *blue, float *alpha);
506 int (*CG_GetScoreBoardDrawHeader)();
507 void (*CG_GetScoreBoardPosition)(float *x, float *y, float *width, float *height);
508 int (*CG_WeaponCommandButtonBits)();
509 int (*CG_CheckCaptureKey)(int key, qboolean down, unsigned int time);
510
511 //
512 // Added in 2.0
513 //
514 void (*CG_ReadNonPVSClient)(radarUnpacked_t* radarUnpacked);
515 void (*CG_UpdateRadar)();
516 size_t (*CG_SaveStateToBuffer)(void** out, int svsTime);
517 qboolean (*CG_LoadStateToBuffer)(void* state, size_t size, int svsTime);
518 void (*CG_CleanUpTempModels)();
519
520 // FIXME
521 //prof_cgame_t* profStruct;
522
523 qboolean (*CG_Command_ProcessFile)(const char *name, qboolean quiet, dtiki_t *curTiki);
524
526
527#ifdef CGAME_DLL
528# ifdef WIN32
529 __declspec(dllexport)
530# else
531 __attribute__((visibility("default")))
532# endif
533#endif
534 clientGameExport_t *GetCGameAPI(void);
535
536#ifdef __cplusplus
537}
538#endif
Definition alias.h:39
Definition alias.h:61
Definition q_shared.h:2140
Definition cg_public.h:458
Definition cg_public.h:97
Definition tiki_shared.h:176
Definition q_shared.h:1691
Definition tr_types.h:244
Definition q_shared.h:1491
Definition q_shared.h:1522
Definition tr_types.h:67
Definition q_shared.h:2220
Definition q_shared.h:2228
Definition tr_types.h:95
Definition tr_types.h:162
Definition cg_public.h:48
Definition puff.c:88
Definition cg_public.h:68
Definition tiki_shared.h:112
Definition q_shared.h:1450