1 /* 2 Copyright (C) 1997-2001 Id Software, Inc. 3 4 This program is free software; you can redistribute it and/or 5 modify it under the terms of the GNU General Public License 6 as published by the Free Software Foundation; either version 2 7 of the License, or (at your option) any later version. 8 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 13 See the GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program; if not, write to the Free Software 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 */ 19 20 // 21 // cg_api.h 22 // 23 24 #ifndef __CGAMEAPI_H__ 25 #define __CGAMEAPI_H__ 26 27 #define CGAME_APIVERSION 031 // Just the engine version number 28 29 typedef struct cgExport_s { 30 int apiVersion; 31 32 void (*Init) (void); 33 void (*Shutdown) (void); 34 35 void (*UpdateConnectInfo) (char *serverName, char *serverMessage, int connectCount, char *dlFileName, int dlPercent, float bytesDownloaded); 36 void (*LoadMap) (int playerNum, int serverProtocol, qBool attractLoop, qBool strafeHack, refConfig_t *inConfig); 37 38 void (*DebugGraph) (float value, int color); 39 40 void (*BeginFrameSequence) (frame_t frame); 41 void (*EndFrameSequence) (int numEntities); 42 void (*NewPacketEntityState) (int entNum, entityState_t state); 43 // the sound code makes callbacks to the client for entitiy position 44 // information, so entities can be dynamically re-spatialized 45 void (*GetEntitySoundOrigin) (int entNum, vec3_t origin, vec3_t velocity); 46 47 void (*ParseConfigString) (int num, char *str); 48 49 void (*StartServerMessage) (void); 50 qBool (*ParseServerMessage) (int command); 51 void (*EndServerMessage) (int realTime); 52 53 void (*StartSound) (vec3_t origin, int entNum, entChannel_t entChannel, int soundNum, float volume, float attenuation, float timeOffset); 54 55 void (*Pmove) (pMoveNew_t *pmove, float airAcceleration); 56 57 void (*RegisterSounds) (void); 58 59 void (*RenderView) (int realTime, float netFrameTime, float refreshFrameTime, float stereoSeparation, qBool refreshPrepped); 60 61 void (*SetRefConfig) (refConfig_t *inConfig); 62 63 void (*MainMenu) (void); 64 void (*ForceMenuOff) (void); 65 66 void (*MoveMouse) (float x, float y); 67 void (*KeyEvent) (keyNum_t keyNum, qBool isDown); 68 69 qBool (*ParseServerInfo) (char *adr, char *info); 70 qBool (*ParseServerStatus) (char *adr, char *info); 71 } cgExport_t; 72 73 typedef struct cgImport_s { 74 void (*Cbuf_AddText) (char *text); 75 void (*Cbuf_Execute) (void); 76 void (*Cbuf_ExecuteString) (char *text); 77 void (*Cbuf_InsertText) (char *text); 78 79 qBool (*CL_ForwardCmdToServer) (void); 80 void (*CL_ResetServerCount) (void); 81 82 trace_t (*CM_BoxTrace) (vec3_t start, vec3_t end, vec3_t mins, vec3_t maxs, int headNode, int brushMask); 83 int (*CM_HeadnodeForBox) (vec3_t mins, vec3_t maxs); 84 struct cBspModel_s *(*CM_InlineModel) (char *name); 85 void (*CM_InlineModelBounds) (struct cBspModel_s *model, vec3_t mins, vec3_t maxs); 86 int (*CM_InlineModelHeadNode) (struct cBspModel_s *model); 87 int (*CM_PointContents) (vec3_t point, int headNode); 88 trace_t (*CM_Trace) (vec3_t start, vec3_t end, float size, int contentMask); 89 void (*CM_TransformedBoxTrace) (trace_t *out, vec3_t start, vec3_t end, vec3_t mins, vec3_t maxs, int headNode, int brushMask, vec3_t origin, vec3_t angles); 90 int (*CM_TransformedPointContents) (vec3_t point, int headNode, vec3_t origin, vec3_t angles); 91 92 void *(*Cmd_AddCommand) (char *name, void (*function) (void), const char *description); 93 void (*Cmd_RemoveCommand) (char *name, void *command); 94 95 void (*Cmd_TokenizeString) (char *text, qBool macroExpand); 96 int (*Cmd_Argc) (void); 97 char *(*Cmd_Args) (void); 98 char *(*Cmd_Argv) (int arg); 99 100 void (*Com_Error) (comError_t code, char *text); 101 void (*Com_Printf) (comPrint_t flags, char *text); 102 void (*Com_DevPrintf) (comPrint_t flags, char *text); 103 caState_t (*Com_ClientState) (void); 104 ssState_t (*Com_ServerState) (void); 105 106 cVar_t *(*Cvar_Register) (char *name, char *value, int flags); 107 cVar_t *(*Cvar_Exists) (char *varName); 108 109 int (*Cvar_GetIntegerValue) (char *varName); 110 char *(*Cvar_GetStringValue) (char *varName); 111 float (*Cvar_GetFloatValue) (char *varName); 112 113 cVar_t *(*Cvar_VariableSet) (cVar_t *var, char *value, qBool force); 114 cVar_t *(*Cvar_VariableSetValue) (cVar_t *var, float value, qBool force); 115 cVar_t *(*Cvar_VariableReset) (cVar_t *var, qBool force); 116 117 cVar_t *(*Cvar_Set) (char *name, char *value, qBool force); 118 cVar_t *(*Cvar_SetValue) (char *name, float value, qBool force); 119 cVar_t *(*Cvar_Reset) (char *varName, qBool force); 120 121 void (*FS_CreatePath) (char *path); 122 char *(*FS_Gamedir) (void); 123 int (*FS_FileExists) (char *path); 124 int (*FS_FindFiles) (char *path, char *filter, char *extension, char **fileList, int maxFiles, qBool addGameDir, qBool recurse); 125 void (*FS_FreeFileList) (char **list, int num, const char *fileName, const int fileLine); 126 int (*FS_LoadFile) (char *path, void **buffer, char *terminate); 127 void (*FS_FreeFile) (void *buffer, const char *fileName, const int fileLine); 128 char *(*FS_NextPath) (char *prevPath); 129 int (*FS_Read) (void *buffer, int len, fileHandle_t fileNum); 130 int (*FS_Write) (void *buffer, int size, fileHandle_t fileNum); 131 void (*FS_Seek) (fileHandle_t fileNum, int offset, fsSeekOrigin_t seekOrigin); 132 int (*FS_OpenFile) (char *fileName, fileHandle_t *fileNum, fsOpenMode_t openMode); 133 void (*FS_CloseFile) (fileHandle_t fileNum); 134 135 void (*GetConfigString) (int i, char *str, int size); 136 137 struct gui_s *(*GUI_RegisterGUI) (char *name); 138 void (*GUI_OpenGUI) (struct gui_s *gui); 139 void (*GUI_CloseGUI) (struct gui_s *gui); 140 void (*GUI_CloseAllGUIs) (void); 141 void (*GUI_NamedGlobalEvent) (char *name); 142 void (*GUI_NamedGUIEvent) (struct gui_s *gui, char *name); 143 144 struct guiVar_s *(*GUIVar_Register) (char *name, guiVarType_t type); 145 qBool (*GUIVar_GetFloatValue) (struct guiVar_s *var, float *dest); 146 qBool (*GUIVar_GetStrValue) (struct guiVar_s *var, char *dest, size_t size); 147 qBool (*GUIVar_GetVecValue) (struct guiVar_s *var, vec4_t dest); 148 void (*GUIVar_SetFloatValue) (struct guiVar_s *var, float value); 149 void (*GUIVar_SetStrValue) (struct guiVar_s *var, char *value); 150 void (*GUIVar_SetVecValue) (struct guiVar_s *var, vec4_t value); 151 152 void (*Key_ClearStates) (void); 153 char *(*Key_GetBindingBuf) (keyNum_t keyNum); 154 keyDest_t (*Key_GetDest) (void); 155 qBool (*Key_IsDown) (keyNum_t keyNum); 156 char *(*Key_KeynumToString) (keyNum_t keyNum); 157 void (*Key_SetBinding) (keyNum_t keyNum, char *binding); 158 void (*Key_SetDest) (keyDest_t keyDest); 159 qBool (*Key_InsertOn) (void); 160 qBool (*Key_CapslockOn) (void); 161 qBool (*Key_ShiftDown) (void); 162 163 void *(*Mem_Alloc) (size_t size, qBool zeroFill, const int tagNum, const char *fileName, const int fileLine); 164 uint32 (*Mem_Free) (const void *ptr, const char *fileName, const int fileLine); 165 uint32 (*Mem_FreeTag) (const int tagNum, const char *fileName, const int fileLine); 166 char *(*Mem_StrDup) (const char *in, const int tagNum, const char *fileName, const int fileLine); 167 uint32 (*Mem_TagSize) (const int tagNum); 168 uint32 (*Mem_ChangeTag) (const int tagFrom, const int tagTo); 169 170 int (*MSG_ReadChar) (void); 171 int (*MSG_ReadByte) (void); 172 int (*MSG_ReadShort) (void); 173 int (*MSG_ReadLong) (void); 174 float (*MSG_ReadFloat) (void); 175 void (*MSG_ReadDir) (vec3_t dir); 176 void (*MSG_ReadPos) (vec3_t pos); 177 char *(*MSG_ReadString) (void); 178 179 int (*NET_GetCurrentUserCmdNum) (void); 180 int (*NET_GetPacketDropCount) (void); 181 int (*NET_GetRateDropCount) (void); 182 void (*NET_GetSequenceState) (int *outgoingSequence, int *incomingAcknowledged); 183 void (*NET_GetUserCmd) (int frame, userCmd_t *cmd); 184 int (*NET_GetUserCmdTime) (int frame); 185 186 void (*R_AddDecal) (refDecal_t *decal, bvec4_t color, struct shader_s *material, float materialTime); 187 void (*R_AddEntity) (refEntity_t *ent); 188 void (*R_AddPoly) (refPoly_t *poly); 189 void (*R_AddLight) (vec3_t org, float intensity, float r, float g, float b); 190 void (*R_AddLightStyle) (int style, float r, float g, float b); 191 192 void (*R_ClearScene) (void); 193 194 qBool (*R_CullBox) (vec3_t mins, vec3_t maxs, int clipFlags); 195 qBool (*R_CullSphere) (const vec3_t origin, const float radius, int clipFlags); 196 197 struct font_s *(*R_RegisterFont) (char *name); 198 void (*R_GetFontDimensions) (struct font_s *font, float xScale, float yScale, uint32 flags, vec2_t dest); 199 void (*R_DrawChar) (struct font_s *font, float x, float y, float xScale, float yScale, uint32 flags, int num, vec4_t color); 200 int (*R_DrawString) (struct font_s *font, float x, float y, float xScale, float yScale, uint32 flags, char *string, vec4_t color); 201 int (*R_DrawStringLen) (struct font_s *font, float x, float y, float xScale, float yScale, uint32 flags, char *string, int len, vec4_t color); 202 203 void (*R_DrawPic) (struct shader_s *shader, float shaderTime, float x, float y, int w, int h, float s1, float t1, float s2, float t2, vec4_t color); 204 void (*R_DrawRectangle) (struct shader_s *shader, float shaderTime, vec2_t tl, vec2_t tr, vec2_t br, vec2_t bl, float s1, float t1, float s2, float t2, vec4_t color); 205 206 void (*R_GetRefConfig) (refConfig_t *outConfig); 207 void (*R_GetImageSize) (struct shader_s *shader, int *width, int *height); 208 209 qBool (*R_CreateDecal) (refDecal_t *d, vec3_t origin, vec3_t direction, float angle, float size); 210 qBool (*R_FreeDecal) (refDecal_t *d); 211 212 void (*R_RegisterMap) (char *mapName); 213 struct refModel_s *(*R_RegisterModel) (char *name); 214 void (*R_ModelBounds) (struct refModel_s *model, vec3_t mins, vec3_t maxs); 215 216 void (*R_UpdateScreen) (void); 217 void (*R_RenderScene) (refDef_t *rd); 218 void (*R_BeginFrame) (float cameraSeparation); 219 void (*R_EndFrame) (void); 220 221 struct shader_s *(*R_RegisterPic) (char *name); 222 struct shader_s *(*R_RegisterPoly) (char *name); 223 struct shader_s *(*R_RegisterSkin) (char *name); 224 225 void (*R_LightPoint) (vec3_t point, vec3_t light); 226 void (*R_TransformVectorToScreen) (refDef_t *rd, vec3_t in, vec2_t out); 227 void (*R_SetSky) (char *name, float rotate, vec3_t axis); 228 229 struct sfx_s *(*Snd_RegisterSound) (char *sample); 230 void (*Snd_StartSound) (vec3_t origin, int entNum, entChannel_t entChannel, struct sfx_s *sfx, float volume, float attenuation, float timeOffset); 231 void (*Snd_StartLocalSound) (struct sfx_s *sfx, float volume); 232 void (*Snd_Update) (refDef_t *rd); 233 234 void (*Sys_FindClose) (void); 235 char *(*Sys_FindFirst) (char *path, uint32 mustHave, uint32 cantHave); 236 char *(*Sys_GetClipboardData) (void); 237 int (*Sys_Milliseconds) (void); 238 void (*Sys_SendKeyEvents) (void); 239 } cgImport_t; 240 241 typedef cgExport_t (*GetCGameAPI_t) (cgImport_t); 242 243 #endif // __CGAMEAPI_H__ 244