OpenMoHAA 0.82.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 // add commands to the local console as if they were typed in
145 // for map changing, etc. The command is not executed immediately,
146 // but will be executed in order the next time console commands
147 // are processed
148 void (*SendConsoleCommand)(const char *text);
149
150 // =========== client specific functions ===============
151
152 // send a string to the server over the network
153 int (*MSG_ReadBits)(int bits);
154 int (*MSG_ReadChar)();
155 int (*MSG_ReadByte)();
156 int (*MSG_ReadSVC)();
157 int (*MSG_ReadShort)();
158 int (*MSG_ReadLong)();
159 float (*MSG_ReadFloat)();
160 char *(*MSG_ReadString)();
161 char *(*MSG_ReadStringLine)();
162 float (*MSG_ReadAngle8)();
163 float (*MSG_ReadAngle16)();
164 void (*MSG_ReadData)(void *data, int len);
165 float (*MSG_ReadCoord)();
166 void (*MSG_ReadDir)(vec3_t dir);
167 void (*SendClientCommand)(const char *s);
168
169 // CM functions
170 void (*CM_LoadMap)(const char *name, int* checksum);
171 clipHandle_t (*CM_InlineModel)(int index); // 0 = world, 1+ = bmodels
172 int (*CM_NumInlineModels)(void);
173 int (*CM_PointContents)(const vec3_t p, int headnode);
174 int (*CM_TransformedPointContents)(
175 const vec3_t p, clipHandle_t model, const vec3_t origin, const vec3_t angles
176 );
177 void (*CM_BoxTrace)(
178 trace_t *results,
179 const vec3_t start,
180 const vec3_t end,
181 const vec3_t mins,
182 const vec3_t maxs,
183 int headnode,
184 int brushmask,
185 qboolean cylinder
186 );
187 void (*CM_TransformedBoxTrace)(
188 trace_t *results,
189 const vec3_t start,
190 const vec3_t end,
191 const vec3_t mins,
192 const vec3_t maxs,
193 int headnode,
194 int brushmask,
195 const vec3_t origin,
196 const vec3_t angles,
197 qboolean cylinder
198 );
199 clipHandle_t (*CM_TempBoxModel)(const vec3_t mins, const vec3_t maxs, int contents);
200 void (*CM_PrintBSPFileSizes)();
201 qboolean (*CM_LeafInPVS)(int leaf1, int leaf2);
202 int (*CM_PointLeafnum)(const vec3_t p);
203 int (*R_MarkFragments)(
204 int numPoints,
205 const vec3_t *points,
206 const vec3_t projection,
207 int maxPoints,
208 vec3_t pointBuffer,
209 int maxFragments,
210 markFragment_t *fragmentBuffer,
211 float fRadiusSquared
212 );
213 int (*R_MarkFragmentsForInlineModel)(
214 clipHandle_t bmodel,
215 const vec3_t vAngles,
216 const vec3_t vOrigin,
217 int numPoints,
218 const vec3_t *points,
219 const vec3_t projection,
220 int maxPoints,
221 vec3_t pointBuffer,
222 int maxFragments,
223 markFragment_t *fragmentBuffer,
224 float fRadiusSquared
225 );
226
227 void (*R_GetInlineModelBounds)(int index, vec3_t mins, vec3_t maxs);
228 void (*R_GetLightingForDecal)(vec3_t light, const vec3_t facing, const vec3_t origin);
229 void (*R_GetLightingForSmoke)(vec3_t light, const vec3_t origin);
230 int (*R_GatherLightSources)(const vec3_t pos, vec3_t *lightPos, vec3_t *lightIntensity, int maxLights);
231
232 // =========== sound function calls ===============
233
234 void (*S_StartSound)(
235 const vec3_t origin,
236 int entNum,
237 int entChannel,
238 sfxHandle_t sfxHandle,
239 float volume,
240 float minDist,
241 float pitch,
242 float maxDist,
243 int streamed
244 );
245 void (*S_StartLocalSound)(const char *soundName, qboolean forceLoad);
246 void (*S_StopSound)(int entnum, int channel);
247 void (*S_ClearLoopingSounds)(void);
248 void (*S_AddLoopingSound)(
249 const vec3_t origin,
250 const vec3_t velocity,
251 sfxHandle_t sfxHandle,
252 float volume,
253 float minDist,
254 float maxDist,
255 float pitch,
256 int flags
257 );
258 void (*S_Respatialize)(int entityNum, const vec3_t origin, vec3_t axis[3]);
259 void (*S_BeginRegistration)(void);
260 sfxHandle_t (*S_RegisterSound)(const char *sample, int streamed);
261 void (*S_EndRegistration)(void);
262 void (*S_UpdateEntity)(int entityNum, const vec3_t origin, const vec3_t velocity, qboolean use_listener);
263 void (*S_SetReverb)(int reverb_type, float reverb_level);
264 void (*S_SetGlobalAmbientVolumeLevel)(float volume);
265 float (*S_GetSoundTime)(sfxHandle_t handle);
266 int (*S_ChannelNameToNum)(const char *name);
267 const char *(*S_ChannelNumToName)(int channel);
268 int (*S_IsSoundPlaying)(int channelNumber, const char *name);
269
270 // =========== music function calls ===============
271
272 void (*MUSIC_NewSoundtrack)(const char *name);
273 void (*MUSIC_UpdateMood)(int current_mood, int fallback_mood);
274 void (*MUSIC_UpdateVolume)(float volume, float fade_time);
275
276 // =========== camera function calls ===============
277
278 float *(*get_camera_offset)(qboolean *lookactive, qboolean *resetview);
279
280 // =========== renderer function calls ================
281 void (*R_ClearScene)(void);
282 void (*R_RenderScene)(const refdef_t *fd);
283 void (*R_LoadWorldMap)(const char *mapname);
284 void (*R_PrintBSPFileSizes)();
285 int (*MapVersion)();
286 int (*R_MapVersion)();
287 qhandle_t (*R_RegisterModel)(const char *name);
288 qhandle_t (*R_SpawnEffectModel)(const char *name, vec3_t pos, vec3_t axis[3]);
289 qhandle_t (*R_RegisterServerModel)(const char *name);
290 const char * (*R_GetModelName)(qhandle_t hModel);
291 void (*R_UnregisterServerModel)(qhandle_t hModel);
292 qhandle_t (*R_RegisterShader)(const char *name);
293 qhandle_t (*R_RegisterShaderNoMip)(const char *name);
294 const char* (*R_GetShaderName)(qhandle_t hShader);
295 void (*R_AddRefEntityToScene)(const refEntity_t *ent, int parentEntityNumber);
296 void (*R_AddRefSpriteToScene)(const refEntity_t *ent);
297 void (*R_AddLightToScene)(const vec3_t origin, float intensity, float r, float g, float b, int type);
298 qboolean (*R_AddPolyToScene)(qhandle_t hShader, int numVerts, const polyVert_t *verts, int renderfx);
299 void (*R_AddTerrainMarkToScene)(
300 int terrainIndex, qhandle_t hShader, int numVerts, const polyVert_t *verts, int renderFx
301 );
302 void (*R_SetColor)(const vec4_t rgba); // NULL = 1,1,1,1
303 void (*R_DrawStretchPic)(
304 float x,
305 float y,
306 float w,
307 float h,
308 float s1,
309 float t1,
310 float s2,
311 float t2,
312 qhandle_t hShader
313 ); // 0 = white
314 fontheader_t *(*R_LoadFont)(const char *name);
315 void (*R_DrawString)(
316 fontheader_t *font, const char *text, float x, float y, int maxLen, const float *pvVirtualScreen
317 );
318 refEntity_t *(*R_GetRenderEntity)(int entityNumber);
319 void (*R_ModelBounds)(clipHandle_t model, vec3_t mins, vec3_t maxs);
320 float (*R_ModelRadius)(clipHandle_t model);
321 float (*R_Noise)(float x, float y, float z, double t);
322 void (*R_DebugLine)(const vec3_t start, const vec3_t end, float r, float g, float b, float alpha);
323 baseshader_t *(*GetShader)(int shaderNum);
324 // =========== Swipes =============
325 void (*R_SwipeBegin)(float thistime, float life, qhandle_t shader);
326 void (*R_SwipePoint)(vec3_t p1, vec3_t p2, float time);
327 void (*R_SwipeEnd)(void);
328 int (*R_GetShaderWidth)(qhandle_t shader);
329 int (*R_GetShaderHeight)(qhandle_t shader);
330 void (*R_DrawBox)(float x, float y, float w, float h);
331
332 // =========== data shared with the client =============
333 void (*GetGameState)(gameState_t *gamestate);
334 int (*GetSnapshot)(int snapshotNumber, snapshot_t *snapshot);
335 int (*GetServerStartTime)();
336 void (*SetTime)(int time);
337 void (*GetCurrentSnapshotNumber)(int *snapshotNumber, int *serverTime);
338 void (*GetGlconfig)(glconfig_t *glconfig);
339
340 // will return false if the number is so old that it doesn't exist in the buffer anymore
341 qboolean (*GetParseEntityState)(int parseEntityNumber, entityState_t *state);
342 int (*GetCurrentCmdNumber)(void); // returns the most recent command number
343 // which is the local predicted command for
344 // the following frame
345 qboolean (*GetUserCmd)(int cmdNumber, usercmd_t *ucmd);
346 qboolean (*GetServerCommand)(int serverCommandNumber, qboolean differentServer);
347
348 // ALIAS STUFF
349 qboolean (*Alias_Add)(const char *alias, const char *name, const char *parameters);
350 qboolean (*Alias_ListAdd)(AliasList_t *list, const char *alias, const char *name, const char *parameters);
351 const char *(*Alias_FindRandom)(const char *alias, AliasListNode_t **ret);
352 const char *(*Alias_ListFindRandom)(AliasList_t *list, const char *alias, AliasListNode_t **ret);
353 void (*Alias_Dump)(void);
354 void (*Alias_Clear)(void);
355 AliasList_t *(*AliasList_New)(const char *name);
356 void (*Alias_ListFindRandomRange)(
357 AliasList_t *list, const char *alias, int *minIndex, int *maxIndex, float *totalWeight
358 );
359 AliasList_t *(*Alias_GetGlobalList)();
360
361 // ==================== UI STUFF ==========================
362 void (*UI_ShowMenu)(const char *name, qboolean bForce);
363 void (*UI_HideMenu)(const char *name, qboolean bForce);
364 int (*UI_FontStringWidth)(fontheader_t *font, const char *string, int maxLen);
365 // Added in 2.0
366 float (*UI_GetObjectivesTop)(void);
367 void (*UI_GetHighResolutionScale)(vec2_t scale);
368
369 int (*Key_StringToKeynum)(const char *str);
370 const char *(*Key_KeynumToBindString)(int keyNum);
371 void (*Key_GetKeysForCommand)(const char *command, int *key1, int *key2);
372
373 // ==================== TIKI STUFF ==========================
374 // TIKI SPECIFIC STUFF
375 dtiki_t *(*R_Model_GetHandle)(qhandle_t handle);
376 int (*TIKI_NumAnims)(dtiki_t *pmdl);
377 void (*TIKI_CalculateBounds)(dtiki_t *pmdl, float scale, vec3_t mins, vec3_t maxs);
378 const char *(*TIKI_Name)(dtiki_t *tiki);
379 void *(*TIKI_GetSkeletor)(dtiki_t *tiki, int entNum);
380 void (*TIKI_SetEyeTargetPos)(dtiki_t *tiki, int entNum, vec3_t pos);
381
382 // ANIM SPECIFIC STUFF
383 const char *(*Anim_NameForNum)(dtiki_t *tiki, int animnum);
384 int (*Anim_NumForName)(dtiki_t *tiki, const char *name);
385 int (*Anim_Random)(dtiki_t *tiki, const char *name);
386 int (*Anim_NumFrames)(dtiki_t *tiki, int animnum);
387 float (*Anim_Time)(dtiki_t *tiki, int animnum);
388 float (*Anim_Frametime)(dtiki_t *tiki, int animnum);
389 void (*Anim_Delta)(dtiki_t *tiki, int animnum, vec3_t delta);
390 int (*Anim_Flags)(dtiki_t *tiki, int animnum);
391 int (*Anim_FlagsSkel)(dtiki_t *tiki, int animnum);
392 float (*Anim_CrossblendTime)(dtiki_t *tiki, int animnum);
393 qboolean (*Anim_HasCommands)(dtiki_t *tiki, int animnum);
394
395 // FRAME SPECIFIC STUFF
396 qboolean (*Frame_Commands)(dtiki_t *tiki, int animnum, int framenum, tiki_cmd_t *tiki_cmd);
397 qboolean (*Frame_CommandsTime)(dtiki_t *tiki, int animnum, float start, float end, tiki_cmd_t *tiki_cmd);
398
399 // SURFACE SPECIFIC STUFF
400 int (*Surface_NameToNum)(dtiki_t *tiki, const char *name);
401 //const char * (*Surface_NumToName) (dtiki_t* tiki, int num );
402 //int (*Surface_Flags) (dtiki_t* tiki, int num );
403 //int (*Surface_NumSkins) (dtiki_t* tiki, int num );
404
405 // TAG SPECIFIC STUFF
406 int (*Tag_NumForName)(dtiki_t *tiki, const char *name);
407 const char *(*Tag_NameForNum)(dtiki_t *tiki, int num);
408 void (*ForceUpdatePose)(refEntity_t *model);
409 orientation_t (*TIKI_Orientation)(refEntity_t *model, int tagNum);
410 qboolean (*TIKI_IsOnGround)(refEntity_t *model, int tagNum, float threshold);
411
412 // MISCELLANEOUS SPECIFIC STUFF
413 void (*UI_ShowScoreBoard)(const char *menuName);
414 void (*UI_HideScoreBoard)();
415 void (*UI_SetScoreBoardItem)(
416 int itemNumber,
417 const char *data1,
418 const char *data2,
419 const char *data3,
420 const char *data4,
421 const char *data5,
422 const char *data6,
423 const char *data7,
424 const char *data8,
425 const vec4_t textColor,
426 const vec4_t backColor,
427 qboolean isHeader
428 );
429 void (*UI_DeleteScoreBoardItems)(int maxIndex);
430 void (*UI_ToggleDMMessageConsole)(int consoleMode);
431 void (*CL_InitRadar)(radarClient_t* radars, qhandle_t* shaders, int clientNum); // Added in 2.0
432 dtiki_t *(*TIKI_FindTiki)(const char *path);
433 void (*LoadResource)(const char *name);
434 void (*FS_CanonicalFilename)(char *name);
435 void (*CL_RestoreSavedCgameState)();
436 void (*CL_ClearSavedCgameState)();
437
438 size_t (*getConfigStringIdNormalized)(size_t num);
439
440 cvar_t *fsDebug;
441 hdelement_t *HudDrawElements;
442 clientAnim_t *anim;
443 stopWatch_t *stopWatch;
444
446
447 /*
448==================================================================
449
450functions exported to the main executable
451
452==================================================================
453*/
454
455 typedef struct {
456 void (*CG_Init)(clientGameImport_t *imported, int serverMessageNum, int serverCommandSequence, int clientNum);
457 void (*CG_Shutdown)(void);
458 void (*CG_DrawActiveFrame)(int serverTime, int frameTime, stereoFrame_t stereoView, qboolean demoPlayback);
459 qboolean (*CG_ConsoleCommand)(void);
460 void (*CG_GetRendererConfig)(void);
461 void (*CG_Draw2D)(void);
462 void (*CG_EyePosition)(vec3_t *eyePos);
463 void (*CG_EyeOffset)(vec3_t *eyeOffset);
464 void (*CG_EyeAngles)(vec3_t *eyeAngles);
465 float (*CG_SensitivityScale)();
466 void (*CG_ParseCGMessage)();
467 void (*CG_RefreshHudDrawElements)();
468 void (*CG_HudDrawShader)(int info);
469 void (*CG_HudDrawFont)(int info);
470 int (*CG_GetParent)(int entNum);
471 float (*CG_GetObjectiveAlpha)();
472 int (*CG_PermanentMark)(
473 vec3_t origin,
474 vec3_t dir,
475 float orientation,
476 float sScale,
477 float tScale,
478 float red,
479 float green,
480 float blue,
481 float alpha,
482 qboolean doLighting,
483 float sCenter,
484 float tCenter,
485 markFragment_t *markFragments,
486 void *polyVerts
487 );
488 int (*CG_PermanentTreadMarkDecal)(
489 treadMark_t *treadMark,
490 qboolean startSegment,
491 qboolean doLighting,
492 markFragment_t *markFragments,
493 void *polyVerts
494 );
495 int (*CG_PermanentUpdateTreadMark)(
496 treadMark_t *treadMark, float alpha, float minSegment, float maxSegment, float maxOffset, float texScale
497 );
498 void (*CG_ProcessInitCommands)(dtiki_t *tiki, refEntity_t *ent);
499 void (*CG_EndTiki)(dtiki_t *tiki);
500 const char *(*CG_GetColumnName)(int columnNum, int *columnWidth);
501 void (*CG_GetScoreBoardColor)(float *red, float *green, float *blue, float *alpha);
502 void (*CG_GetScoreBoardFontColor)(float *red, float *green, float *blue, float *alpha);
503 int (*CG_GetScoreBoardDrawHeader)();
504 void (*CG_GetScoreBoardPosition)(float *x, float *y, float *width, float *height);
505 int (*CG_WeaponCommandButtonBits)();
506 int (*CG_CheckCaptureKey)(int key, qboolean down, unsigned int time);
507
508 //
509 // Added in 2.0
510 //
511 void (*CG_ReadNonPVSClient)(radarUnpacked_t* radarUnpacked);
512 void (*CG_UpdateRadar)();
513 size_t (*CG_SaveStateToBuffer)(void** out, int svsTime);
514 qboolean (*CG_LoadStateToBuffer)(void* state, size_t size, int svsTime);
515 void (*CG_CleanUpTempModels)();
516
517 // FIXME
518 //prof_cgame_t* profStruct;
519
520 qboolean (*CG_Command_ProcessFile)(const char *name, qboolean quiet, dtiki_t *curTiki);
521
523
524#ifdef CGAME_DLL
525# ifdef WIN32
526 __declspec(dllexport)
527# else
528 __attribute__((visibility("default")))
529# endif
530#endif
531 clientGameExport_t *GetCGameAPI(void);
532
533#ifdef __cplusplus
534}
535#endif
Definition str.h:77
Definition alias.h:40
Definition alias.h:63
Definition q_shared.h:2143
Definition cg_public.h:455
Definition cg_public.h:97
Definition tiki_shared.h:176
Definition q_shared.h:1693
Definition tr_types.h:244
Definition q_shared.h:1493
Definition q_shared.h:1524
Definition tr_types.h:67
Definition q_shared.h:2223
Definition q_shared.h:2231
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:1452