Quake-III-Arena

Quake III Arena GPL Source Release
Log | Files | Refs

cg_syscalls.c (13829B)


      1 /*
      2 ===========================================================================
      3 Copyright (C) 1999-2005 Id Software, Inc.
      4 
      5 This file is part of Quake III Arena source code.
      6 
      7 Quake III Arena source code is free software; you can redistribute it
      8 and/or modify it under the terms of the GNU General Public License as
      9 published by the Free Software Foundation; either version 2 of the License,
     10 or (at your option) any later version.
     11 
     12 Quake III Arena source code is distributed in the hope that it will be
     13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 GNU General Public License for more details.
     16 
     17 You should have received a copy of the GNU General Public License
     18 along with Foobar; if not, write to the Free Software
     19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
     20 ===========================================================================
     21 */
     22 //
     23 // cg_syscalls.c -- this file is only included when building a dll
     24 // cg_syscalls.asm is included instead when building a qvm
     25 #ifdef Q3_VM
     26 #error "Do not use in VM build"
     27 #endif
     28 
     29 #include "cg_local.h"
     30 
     31 static int (QDECL *syscall)( int arg, ... ) = (int (QDECL *)( int, ...))-1;
     32 
     33 
     34 void dllEntry( int (QDECL  *syscallptr)( int arg,... ) ) {
     35 	syscall = syscallptr;
     36 }
     37 
     38 
     39 int PASSFLOAT( float x ) {
     40 	float	floatTemp;
     41 	floatTemp = x;
     42 	return *(int *)&floatTemp;
     43 }
     44 
     45 void	trap_Print( const char *fmt ) {
     46 	syscall( CG_PRINT, fmt );
     47 }
     48 
     49 void	trap_Error( const char *fmt ) {
     50 	syscall( CG_ERROR, fmt );
     51 }
     52 
     53 int		trap_Milliseconds( void ) {
     54 	return syscall( CG_MILLISECONDS ); 
     55 }
     56 
     57 void	trap_Cvar_Register( vmCvar_t *vmCvar, const char *varName, const char *defaultValue, int flags ) {
     58 	syscall( CG_CVAR_REGISTER, vmCvar, varName, defaultValue, flags );
     59 }
     60 
     61 void	trap_Cvar_Update( vmCvar_t *vmCvar ) {
     62 	syscall( CG_CVAR_UPDATE, vmCvar );
     63 }
     64 
     65 void	trap_Cvar_Set( const char *var_name, const char *value ) {
     66 	syscall( CG_CVAR_SET, var_name, value );
     67 }
     68 
     69 void trap_Cvar_VariableStringBuffer( const char *var_name, char *buffer, int bufsize ) {
     70 	syscall( CG_CVAR_VARIABLESTRINGBUFFER, var_name, buffer, bufsize );
     71 }
     72 
     73 int		trap_Argc( void ) {
     74 	return syscall( CG_ARGC );
     75 }
     76 
     77 void	trap_Argv( int n, char *buffer, int bufferLength ) {
     78 	syscall( CG_ARGV, n, buffer, bufferLength );
     79 }
     80 
     81 void	trap_Args( char *buffer, int bufferLength ) {
     82 	syscall( CG_ARGS, buffer, bufferLength );
     83 }
     84 
     85 int		trap_FS_FOpenFile( const char *qpath, fileHandle_t *f, fsMode_t mode ) {
     86 	return syscall( CG_FS_FOPENFILE, qpath, f, mode );
     87 }
     88 
     89 void	trap_FS_Read( void *buffer, int len, fileHandle_t f ) {
     90 	syscall( CG_FS_READ, buffer, len, f );
     91 }
     92 
     93 void	trap_FS_Write( const void *buffer, int len, fileHandle_t f ) {
     94 	syscall( CG_FS_WRITE, buffer, len, f );
     95 }
     96 
     97 void	trap_FS_FCloseFile( fileHandle_t f ) {
     98 	syscall( CG_FS_FCLOSEFILE, f );
     99 }
    100 
    101 int trap_FS_Seek( fileHandle_t f, long offset, int origin ) {
    102 	return syscall( CG_FS_SEEK, f, offset, origin );
    103 }
    104 
    105 void	trap_SendConsoleCommand( const char *text ) {
    106 	syscall( CG_SENDCONSOLECOMMAND, text );
    107 }
    108 
    109 void	trap_AddCommand( const char *cmdName ) {
    110 	syscall( CG_ADDCOMMAND, cmdName );
    111 }
    112 
    113 void	trap_RemoveCommand( const char *cmdName ) {
    114 	syscall( CG_REMOVECOMMAND, cmdName );
    115 }
    116 
    117 void	trap_SendClientCommand( const char *s ) {
    118 	syscall( CG_SENDCLIENTCOMMAND, s );
    119 }
    120 
    121 void	trap_UpdateScreen( void ) {
    122 	syscall( CG_UPDATESCREEN );
    123 }
    124 
    125 void	trap_CM_LoadMap( const char *mapname ) {
    126 	syscall( CG_CM_LOADMAP, mapname );
    127 }
    128 
    129 int		trap_CM_NumInlineModels( void ) {
    130 	return syscall( CG_CM_NUMINLINEMODELS );
    131 }
    132 
    133 clipHandle_t trap_CM_InlineModel( int index ) {
    134 	return syscall( CG_CM_INLINEMODEL, index );
    135 }
    136 
    137 clipHandle_t trap_CM_TempBoxModel( const vec3_t mins, const vec3_t maxs ) {
    138 	return syscall( CG_CM_TEMPBOXMODEL, mins, maxs );
    139 }
    140 
    141 clipHandle_t trap_CM_TempCapsuleModel( const vec3_t mins, const vec3_t maxs ) {
    142 	return syscall( CG_CM_TEMPCAPSULEMODEL, mins, maxs );
    143 }
    144 
    145 int		trap_CM_PointContents( const vec3_t p, clipHandle_t model ) {
    146 	return syscall( CG_CM_POINTCONTENTS, p, model );
    147 }
    148 
    149 int		trap_CM_TransformedPointContents( const vec3_t p, clipHandle_t model, const vec3_t origin, const vec3_t angles ) {
    150 	return syscall( CG_CM_TRANSFORMEDPOINTCONTENTS, p, model, origin, angles );
    151 }
    152 
    153 void	trap_CM_BoxTrace( trace_t *results, const vec3_t start, const vec3_t end,
    154 						  const vec3_t mins, const vec3_t maxs,
    155 						  clipHandle_t model, int brushmask ) {
    156 	syscall( CG_CM_BOXTRACE, results, start, end, mins, maxs, model, brushmask );
    157 }
    158 
    159 void	trap_CM_CapsuleTrace( trace_t *results, const vec3_t start, const vec3_t end,
    160 						  const vec3_t mins, const vec3_t maxs,
    161 						  clipHandle_t model, int brushmask ) {
    162 	syscall( CG_CM_CAPSULETRACE, results, start, end, mins, maxs, model, brushmask );
    163 }
    164 
    165 void	trap_CM_TransformedBoxTrace( trace_t *results, const vec3_t start, const vec3_t end,
    166 						  const vec3_t mins, const vec3_t maxs,
    167 						  clipHandle_t model, int brushmask,
    168 						  const vec3_t origin, const vec3_t angles ) {
    169 	syscall( CG_CM_TRANSFORMEDBOXTRACE, results, start, end, mins, maxs, model, brushmask, origin, angles );
    170 }
    171 
    172 void	trap_CM_TransformedCapsuleTrace( trace_t *results, const vec3_t start, const vec3_t end,
    173 						  const vec3_t mins, const vec3_t maxs,
    174 						  clipHandle_t model, int brushmask,
    175 						  const vec3_t origin, const vec3_t angles ) {
    176 	syscall( CG_CM_TRANSFORMEDCAPSULETRACE, results, start, end, mins, maxs, model, brushmask, origin, angles );
    177 }
    178 
    179 int		trap_CM_MarkFragments( int numPoints, const vec3_t *points, 
    180 				const vec3_t projection,
    181 				int maxPoints, vec3_t pointBuffer,
    182 				int maxFragments, markFragment_t *fragmentBuffer ) {
    183 	return syscall( CG_CM_MARKFRAGMENTS, numPoints, points, projection, maxPoints, pointBuffer, maxFragments, fragmentBuffer );
    184 }
    185 
    186 void	trap_S_StartSound( vec3_t origin, int entityNum, int entchannel, sfxHandle_t sfx ) {
    187 	syscall( CG_S_STARTSOUND, origin, entityNum, entchannel, sfx );
    188 }
    189 
    190 void	trap_S_StartLocalSound( sfxHandle_t sfx, int channelNum ) {
    191 	syscall( CG_S_STARTLOCALSOUND, sfx, channelNum );
    192 }
    193 
    194 void	trap_S_ClearLoopingSounds( qboolean killall ) {
    195 	syscall( CG_S_CLEARLOOPINGSOUNDS, killall );
    196 }
    197 
    198 void	trap_S_AddLoopingSound( int entityNum, const vec3_t origin, const vec3_t velocity, sfxHandle_t sfx ) {
    199 	syscall( CG_S_ADDLOOPINGSOUND, entityNum, origin, velocity, sfx );
    200 }
    201 
    202 void	trap_S_AddRealLoopingSound( int entityNum, const vec3_t origin, const vec3_t velocity, sfxHandle_t sfx ) {
    203 	syscall( CG_S_ADDREALLOOPINGSOUND, entityNum, origin, velocity, sfx );
    204 }
    205 
    206 void	trap_S_StopLoopingSound( int entityNum ) {
    207 	syscall( CG_S_STOPLOOPINGSOUND, entityNum );
    208 }
    209 
    210 void	trap_S_UpdateEntityPosition( int entityNum, const vec3_t origin ) {
    211 	syscall( CG_S_UPDATEENTITYPOSITION, entityNum, origin );
    212 }
    213 
    214 void	trap_S_Respatialize( int entityNum, const vec3_t origin, vec3_t axis[3], int inwater ) {
    215 	syscall( CG_S_RESPATIALIZE, entityNum, origin, axis, inwater );
    216 }
    217 
    218 sfxHandle_t	trap_S_RegisterSound( const char *sample, qboolean compressed ) {
    219 	return syscall( CG_S_REGISTERSOUND, sample, compressed );
    220 }
    221 
    222 void	trap_S_StartBackgroundTrack( const char *intro, const char *loop ) {
    223 	syscall( CG_S_STARTBACKGROUNDTRACK, intro, loop );
    224 }
    225 
    226 void	trap_R_LoadWorldMap( const char *mapname ) {
    227 	syscall( CG_R_LOADWORLDMAP, mapname );
    228 }
    229 
    230 qhandle_t trap_R_RegisterModel( const char *name ) {
    231 	return syscall( CG_R_REGISTERMODEL, name );
    232 }
    233 
    234 qhandle_t trap_R_RegisterSkin( const char *name ) {
    235 	return syscall( CG_R_REGISTERSKIN, name );
    236 }
    237 
    238 qhandle_t trap_R_RegisterShader( const char *name ) {
    239 	return syscall( CG_R_REGISTERSHADER, name );
    240 }
    241 
    242 qhandle_t trap_R_RegisterShaderNoMip( const char *name ) {
    243 	return syscall( CG_R_REGISTERSHADERNOMIP, name );
    244 }
    245 
    246 void trap_R_RegisterFont(const char *fontName, int pointSize, fontInfo_t *font) {
    247 	syscall(CG_R_REGISTERFONT, fontName, pointSize, font );
    248 }
    249 
    250 void	trap_R_ClearScene( void ) {
    251 	syscall( CG_R_CLEARSCENE );
    252 }
    253 
    254 void	trap_R_AddRefEntityToScene( const refEntity_t *re ) {
    255 	syscall( CG_R_ADDREFENTITYTOSCENE, re );
    256 }
    257 
    258 void	trap_R_AddPolyToScene( qhandle_t hShader , int numVerts, const polyVert_t *verts ) {
    259 	syscall( CG_R_ADDPOLYTOSCENE, hShader, numVerts, verts );
    260 }
    261 
    262 void	trap_R_AddPolysToScene( qhandle_t hShader , int numVerts, const polyVert_t *verts, int num ) {
    263 	syscall( CG_R_ADDPOLYSTOSCENE, hShader, numVerts, verts, num );
    264 }
    265 
    266 int		trap_R_LightForPoint( vec3_t point, vec3_t ambientLight, vec3_t directedLight, vec3_t lightDir ) {
    267 	return syscall( CG_R_LIGHTFORPOINT, point, ambientLight, directedLight, lightDir );
    268 }
    269 
    270 void	trap_R_AddLightToScene( const vec3_t org, float intensity, float r, float g, float b ) {
    271 	syscall( CG_R_ADDLIGHTTOSCENE, org, PASSFLOAT(intensity), PASSFLOAT(r), PASSFLOAT(g), PASSFLOAT(b) );
    272 }
    273 
    274 void	trap_R_AddAdditiveLightToScene( const vec3_t org, float intensity, float r, float g, float b ) {
    275 	syscall( CG_R_ADDADDITIVELIGHTTOSCENE, org, PASSFLOAT(intensity), PASSFLOAT(r), PASSFLOAT(g), PASSFLOAT(b) );
    276 }
    277 
    278 void	trap_R_RenderScene( const refdef_t *fd ) {
    279 	syscall( CG_R_RENDERSCENE, fd );
    280 }
    281 
    282 void	trap_R_SetColor( const float *rgba ) {
    283 	syscall( CG_R_SETCOLOR, rgba );
    284 }
    285 
    286 void	trap_R_DrawStretchPic( float x, float y, float w, float h, 
    287 							   float s1, float t1, float s2, float t2, qhandle_t hShader ) {
    288 	syscall( CG_R_DRAWSTRETCHPIC, PASSFLOAT(x), PASSFLOAT(y), PASSFLOAT(w), PASSFLOAT(h), PASSFLOAT(s1), PASSFLOAT(t1), PASSFLOAT(s2), PASSFLOAT(t2), hShader );
    289 }
    290 
    291 void	trap_R_ModelBounds( clipHandle_t model, vec3_t mins, vec3_t maxs ) {
    292 	syscall( CG_R_MODELBOUNDS, model, mins, maxs );
    293 }
    294 
    295 int		trap_R_LerpTag( orientation_t *tag, clipHandle_t mod, int startFrame, int endFrame, 
    296 					   float frac, const char *tagName ) {
    297 	return syscall( CG_R_LERPTAG, tag, mod, startFrame, endFrame, PASSFLOAT(frac), tagName );
    298 }
    299 
    300 void	trap_R_RemapShader( const char *oldShader, const char *newShader, const char *timeOffset ) {
    301 	syscall( CG_R_REMAP_SHADER, oldShader, newShader, timeOffset );
    302 }
    303 
    304 void		trap_GetGlconfig( glconfig_t *glconfig ) {
    305 	syscall( CG_GETGLCONFIG, glconfig );
    306 }
    307 
    308 void		trap_GetGameState( gameState_t *gamestate ) {
    309 	syscall( CG_GETGAMESTATE, gamestate );
    310 }
    311 
    312 void		trap_GetCurrentSnapshotNumber( int *snapshotNumber, int *serverTime ) {
    313 	syscall( CG_GETCURRENTSNAPSHOTNUMBER, snapshotNumber, serverTime );
    314 }
    315 
    316 qboolean	trap_GetSnapshot( int snapshotNumber, snapshot_t *snapshot ) {
    317 	return syscall( CG_GETSNAPSHOT, snapshotNumber, snapshot );
    318 }
    319 
    320 qboolean	trap_GetServerCommand( int serverCommandNumber ) {
    321 	return syscall( CG_GETSERVERCOMMAND, serverCommandNumber );
    322 }
    323 
    324 int			trap_GetCurrentCmdNumber( void ) {
    325 	return syscall( CG_GETCURRENTCMDNUMBER );
    326 }
    327 
    328 qboolean	trap_GetUserCmd( int cmdNumber, usercmd_t *ucmd ) {
    329 	return syscall( CG_GETUSERCMD, cmdNumber, ucmd );
    330 }
    331 
    332 void		trap_SetUserCmdValue( int stateValue, float sensitivityScale ) {
    333 	syscall( CG_SETUSERCMDVALUE, stateValue, PASSFLOAT(sensitivityScale) );
    334 }
    335 
    336 void		testPrintInt( char *string, int i ) {
    337 	syscall( CG_TESTPRINTINT, string, i );
    338 }
    339 
    340 void		testPrintFloat( char *string, float f ) {
    341 	syscall( CG_TESTPRINTFLOAT, string, PASSFLOAT(f) );
    342 }
    343 
    344 int trap_MemoryRemaining( void ) {
    345 	return syscall( CG_MEMORY_REMAINING );
    346 }
    347 
    348 qboolean trap_Key_IsDown( int keynum ) {
    349 	return syscall( CG_KEY_ISDOWN, keynum );
    350 }
    351 
    352 int trap_Key_GetCatcher( void ) {
    353 	return syscall( CG_KEY_GETCATCHER );
    354 }
    355 
    356 void trap_Key_SetCatcher( int catcher ) {
    357 	syscall( CG_KEY_SETCATCHER, catcher );
    358 }
    359 
    360 int trap_Key_GetKey( const char *binding ) {
    361 	return syscall( CG_KEY_GETKEY, binding );
    362 }
    363 
    364 int trap_PC_AddGlobalDefine( char *define ) {
    365 	return syscall( CG_PC_ADD_GLOBAL_DEFINE, define );
    366 }
    367 
    368 int trap_PC_LoadSource( const char *filename ) {
    369 	return syscall( CG_PC_LOAD_SOURCE, filename );
    370 }
    371 
    372 int trap_PC_FreeSource( int handle ) {
    373 	return syscall( CG_PC_FREE_SOURCE, handle );
    374 }
    375 
    376 int trap_PC_ReadToken( int handle, pc_token_t *pc_token ) {
    377 	return syscall( CG_PC_READ_TOKEN, handle, pc_token );
    378 }
    379 
    380 int trap_PC_SourceFileAndLine( int handle, char *filename, int *line ) {
    381 	return syscall( CG_PC_SOURCE_FILE_AND_LINE, handle, filename, line );
    382 }
    383 
    384 void	trap_S_StopBackgroundTrack( void ) {
    385 	syscall( CG_S_STOPBACKGROUNDTRACK );
    386 }
    387 
    388 int trap_RealTime(qtime_t *qtime) {
    389 	return syscall( CG_REAL_TIME, qtime );
    390 }
    391 
    392 void trap_SnapVector( float *v ) {
    393 	syscall( CG_SNAPVECTOR, v );
    394 }
    395 
    396 // this returns a handle.  arg0 is the name in the format "idlogo.roq", set arg1 to NULL, alteredstates to qfalse (do not alter gamestate)
    397 int trap_CIN_PlayCinematic( const char *arg0, int xpos, int ypos, int width, int height, int bits) {
    398   return syscall(CG_CIN_PLAYCINEMATIC, arg0, xpos, ypos, width, height, bits);
    399 }
    400  
    401 // stops playing the cinematic and ends it.  should always return FMV_EOF
    402 // cinematics must be stopped in reverse order of when they are started
    403 e_status trap_CIN_StopCinematic(int handle) {
    404   return syscall(CG_CIN_STOPCINEMATIC, handle);
    405 }
    406 
    407 
    408 // will run a frame of the cinematic but will not draw it.  Will return FMV_EOF if the end of the cinematic has been reached.
    409 e_status trap_CIN_RunCinematic (int handle) {
    410   return syscall(CG_CIN_RUNCINEMATIC, handle);
    411 }
    412  
    413 
    414 // draws the current frame
    415 void trap_CIN_DrawCinematic (int handle) {
    416   syscall(CG_CIN_DRAWCINEMATIC, handle);
    417 }
    418  
    419 
    420 // allows you to resize the animation dynamically
    421 void trap_CIN_SetExtents (int handle, int x, int y, int w, int h) {
    422   syscall(CG_CIN_SETEXTENTS, handle, x, y, w, h);
    423 }
    424 
    425 /*
    426 qboolean trap_loadCamera( const char *name ) {
    427 	return syscall( CG_LOADCAMERA, name );
    428 }
    429 
    430 void trap_startCamera(int time) {
    431 	syscall(CG_STARTCAMERA, time);
    432 }
    433 
    434 qboolean trap_getCameraInfo( int time, vec3_t *origin, vec3_t *angles) {
    435 	return syscall( CG_GETCAMERAINFO, time, origin, angles );
    436 }
    437 */
    438 
    439 qboolean trap_GetEntityToken( char *buffer, int bufferSize ) {
    440 	return syscall( CG_GET_ENTITY_TOKEN, buffer, bufferSize );
    441 }
    442 
    443 qboolean trap_R_inPVS( const vec3_t p1, const vec3_t p2 ) {
    444 	return syscall( CG_R_INPVS, p1, p2 );
    445 }