/* ================== S_ClearLoopingSounds ================== */ void S_ClearLoopingSounds( qboolean killall ) { int i; for ( i = 0 ; i < MAX_GENTITIES ; i++) { if (killall || loopSounds[i].kill == qtrue || (loopSounds[i].sfx && loopSounds[i].sfx->soundLength == 0)) { loopSounds[i].kill = qfalse; S_StopLoopingSound(i); } } numLoopChannels = 0; }
/* ==================== CL_CgameSystemCalls The cgame module is making a system call ==================== */ intptr_t CL_CgameSystemCalls( intptr_t *args ) { switch( args[0] ) { case CG_PRINT: Com_Printf( "%s", (const char*)VMA(1) ); return 0; case CG_ERROR: Com_Error( ERR_DROP, "%s", (const char*)VMA(1) ); return 0; case CG_MILLISECONDS: return Sys_Milliseconds(); case CG_CVAR_REGISTER: Cvar_Register( VMA(1), VMA(2), VMA(3), args[4] ); return 0; case CG_CVAR_UPDATE: Cvar_Update( VMA(1) ); return 0; case CG_CVAR_SET: Cvar_Set( VMA(1), VMA(2) ); return 0; case CG_CVAR_VARIABLESTRINGBUFFER: Cvar_VariableStringBuffer( VMA(1), VMA(2), args[3] ); return 0; case CG_ARGC: return Cmd_Argc(); case CG_ARGV: Cmd_ArgvBuffer( args[1], VMA(2), args[3] ); return 0; case CG_ARGS: Cmd_ArgsBuffer( VMA(1), args[2] ); return 0; case CG_FS_FOPENFILE: return FS_FOpenFileByMode( VMA(1), VMA(2), args[3] ); case CG_FS_READ: FS_Read2( VMA(1), args[2], args[3] ); return 0; case CG_FS_WRITE: FS_Write( VMA(1), args[2], args[3] ); return 0; case CG_FS_FCLOSEFILE: FS_FCloseFile( args[1] ); return 0; case CG_FS_SEEK: return FS_Seek( args[1], args[2], args[3] ); case CG_SENDCONSOLECOMMAND: Cbuf_AddText( VMA(1) ); return 0; case CG_ADDCOMMAND: CL_AddCgameCommand( VMA(1) ); return 0; case CG_REMOVECOMMAND: Cmd_RemoveCommand( VMA(1) ); return 0; case CG_SENDCLIENTCOMMAND: CL_AddReliableCommand( VMA(1) ); return 0; case CG_UPDATESCREEN: // this is used during lengthy level loading, so pump message loop // Com_EventLoop(); // FIXME: if a server restarts here, BAD THINGS HAPPEN! // We can't call Com_EventLoop here, a restart will crash and this _does_ happen // if there is a map change while we are downloading at pk3. // ZOID SCR_UpdateScreen(); return 0; case CG_CM_LOADMAP: CL_CM_LoadMap( VMA(1) ); return 0; case CG_CM_NUMINLINEMODELS: return CM_NumInlineModels(); case CG_CM_INLINEMODEL: return CM_InlineModel( args[1] ); case CG_CM_TEMPBOXMODEL: return CM_TempBoxModel( VMA(1), VMA(2), /*int capsule*/ qfalse ); case CG_CM_TEMPCAPSULEMODEL: return CM_TempBoxModel( VMA(1), VMA(2), /*int capsule*/ qtrue ); case CG_CM_POINTCONTENTS: return CM_PointContents( VMA(1), args[2] ); case CG_CM_TRANSFORMEDPOINTCONTENTS: return CM_TransformedPointContents( VMA(1), args[2], VMA(3), VMA(4) ); case CG_CM_BOXTRACE: CM_BoxTrace( VMA(1), VMA(2), VMA(3), VMA(4), VMA(5), args[6], args[7], /*int capsule*/ qfalse ); return 0; case CG_CM_CAPSULETRACE: CM_BoxTrace( VMA(1), VMA(2), VMA(3), VMA(4), VMA(5), args[6], args[7], /*int capsule*/ qtrue ); return 0; case CG_CM_TRANSFORMEDBOXTRACE: CM_TransformedBoxTrace( VMA(1), VMA(2), VMA(3), VMA(4), VMA(5), args[6], args[7], VMA(8), VMA(9), /*int capsule*/ qfalse ); return 0; case CG_CM_TRANSFORMEDCAPSULETRACE: CM_TransformedBoxTrace( VMA(1), VMA(2), VMA(3), VMA(4), VMA(5), args[6], args[7], VMA(8), VMA(9), /*int capsule*/ qtrue ); return 0; case CG_CM_MARKFRAGMENTS: return re.MarkFragments( args[1], VMA(2), VMA(3), args[4], VMA(5), args[6], VMA(7) ); case CG_S_STARTSOUND: S_StartSound( VMA(1), args[2], args[3], args[4] ); return 0; case CG_S_STARTLOCALSOUND: S_StartLocalSound( args[1], args[2] ); return 0; case CG_S_CLEARLOOPINGSOUNDS: S_ClearLoopingSounds(args[1]); return 0; case CG_S_ADDLOOPINGSOUND: S_AddLoopingSound( args[1], VMA(2), VMA(3), args[4] ); return 0; case CG_S_ADDREALLOOPINGSOUND: S_AddRealLoopingSound( args[1], VMA(2), VMA(3), args[4] ); return 0; case CG_S_STOPLOOPINGSOUND: S_StopLoopingSound( args[1] ); return 0; case CG_S_UPDATEENTITYPOSITION: S_UpdateEntityPosition( args[1], VMA(2) ); return 0; case CG_S_RESPATIALIZE: S_Respatialize( args[1], VMA(2), VMA(3), args[4] ); return 0; case CG_S_REGISTERSOUND: return S_RegisterSound( VMA(1), args[2] ); case CG_S_STARTBACKGROUNDTRACK: S_StartBackgroundTrack( VMA(1), VMA(2) ); return 0; case CG_R_LOADWORLDMAP: re.LoadWorld( VMA(1) ); return 0; case CG_R_REGISTERMODEL: return re.RegisterModel( VMA(1) ); case CG_R_REGISTERSKIN: return re.RegisterSkin( VMA(1) ); case CG_R_REGISTERSHADER: return re.RegisterShader( VMA(1) ); case CG_R_REGISTERSHADERNOMIP: return re.RegisterShaderNoMip( VMA(1) ); case CG_R_REGISTERFONT: re.RegisterFont( VMA(1), args[2], VMA(3)); case CG_R_CLEARSCENE: re.ClearScene(); return 0; case CG_R_ADDREFENTITYTOSCENE: re.AddRefEntityToScene( VMA(1) ); return 0; case CG_R_ADDPOLYTOSCENE: re.AddPolyToScene( args[1], args[2], VMA(3), 1 ); return 0; case CG_R_ADDPOLYSTOSCENE: re.AddPolyToScene( args[1], args[2], VMA(3), args[4] ); return 0; case CG_R_LIGHTFORPOINT: return re.LightForPoint( VMA(1), VMA(2), VMA(3), VMA(4) ); case CG_R_ADDLIGHTTOSCENE: re.AddLightToScene( VMA(1), VMF(2), VMF(3), VMF(4), VMF(5) ); return 0; case CG_R_ADDADDITIVELIGHTTOSCENE: re.AddAdditiveLightToScene( VMA(1), VMF(2), VMF(3), VMF(4), VMF(5) ); return 0; case CG_R_RENDERSCENE: re.RenderScene( VMA(1) ); return 0; case CG_R_SETCOLOR: re.SetColor( VMA(1) ); return 0; case CG_R_DRAWSTRETCHPIC: re.DrawStretchPic( VMF(1), VMF(2), VMF(3), VMF(4), VMF(5), VMF(6), VMF(7), VMF(8), args[9] ); return 0; case CG_R_MODELBOUNDS: re.ModelBounds( args[1], VMA(2), VMA(3) ); return 0; case CG_R_LERPTAG: return re.LerpTag( VMA(1), args[2], args[3], args[4], VMF(5), VMA(6) ); case CG_GETGLCONFIG: CL_GetGlconfig( VMA(1) ); return 0; case CG_GETGAMESTATE: CL_GetGameState( VMA(1) ); return 0; case CG_GETCURRENTSNAPSHOTNUMBER: CL_GetCurrentSnapshotNumber( VMA(1), VMA(2) ); return 0; case CG_GETSNAPSHOT: return CL_GetSnapshot( args[1], VMA(2) ); case CG_GETSERVERCOMMAND: return CL_GetServerCommand( args[1] ); case CG_GETCURRENTCMDNUMBER: return CL_GetCurrentCmdNumber(); case CG_GETUSERCMD: return CL_GetUserCmd( args[1], VMA(2) ); case CG_SETUSERCMDVALUE: CL_SetUserCmdValue( args[1], VMF(2) ); return 0; case CG_MEMORY_REMAINING: return Hunk_MemoryRemaining(); case CG_KEY_ISDOWN: return Key_IsDown( args[1] ); case CG_KEY_GETCATCHER: return Key_GetCatcher(); case CG_KEY_SETCATCHER: // Don't allow the cgame module to close the console Key_SetCatcher( args[1] | ( Key_GetCatcher( ) & KEYCATCH_CONSOLE ) ); return 0; case CG_KEY_GETKEY: return Key_GetKey( VMA(1) ); case CG_MEMSET: Com_Memset( VMA(1), args[2], args[3] ); return 0; case CG_MEMCPY: Com_Memcpy( VMA(1), VMA(2), args[3] ); return 0; case CG_STRNCPY: strncpy( VMA(1), VMA(2), args[3] ); return args[1]; case CG_SIN: return FloatAsInt( sin( VMF(1) ) ); case CG_COS: return FloatAsInt( cos( VMF(1) ) ); case CG_ATAN2: return FloatAsInt( atan2( VMF(1), VMF(2) ) ); case CG_SQRT: return FloatAsInt( sqrt( VMF(1) ) ); case CG_FLOOR: return FloatAsInt( floor( VMF(1) ) ); case CG_CEIL: return FloatAsInt( ceil( VMF(1) ) ); case CG_ACOS: return FloatAsInt( Q_acos( VMF(1) ) ); case CG_PC_ADD_GLOBAL_DEFINE: return botlib_export->PC_AddGlobalDefine( VMA(1) ); case CG_PC_LOAD_SOURCE: return botlib_export->PC_LoadSourceHandle( VMA(1) ); case CG_PC_FREE_SOURCE: return botlib_export->PC_FreeSourceHandle( args[1] ); case CG_PC_READ_TOKEN: return botlib_export->PC_ReadTokenHandle( args[1], VMA(2) ); case CG_PC_SOURCE_FILE_AND_LINE: return botlib_export->PC_SourceFileAndLine( args[1], VMA(2), VMA(3) ); case CG_S_STOPBACKGROUNDTRACK: S_StopBackgroundTrack(); return 0; case CG_REAL_TIME: return Com_RealTime( VMA(1) ); case CG_SNAPVECTOR: Sys_SnapVector( VMA(1) ); return 0; case CG_CIN_PLAYCINEMATIC: return CIN_PlayCinematic(VMA(1), args[2], args[3], args[4], args[5], args[6]); case CG_CIN_STOPCINEMATIC: return CIN_StopCinematic(args[1]); case CG_CIN_RUNCINEMATIC: return CIN_RunCinematic(args[1]); case CG_CIN_DRAWCINEMATIC: CIN_DrawCinematic(args[1]); return 0; case CG_CIN_SETEXTENTS: CIN_SetExtents(args[1], args[2], args[3], args[4], args[5]); return 0; case CG_R_REMAP_SHADER: re.RemapShader( VMA(1), VMA(2), VMA(3) ); return 0; /* case CG_LOADCAMERA: return loadCamera(VMA(1)); case CG_STARTCAMERA: startCamera(args[1]); return 0; case CG_GETCAMERAINFO: return getCameraInfo(args[1], VMA(2), VMA(3)); */ case CG_GET_ENTITY_TOKEN: return re.GetEntityToken( VMA(1), args[2] ); case CG_R_INPVS: return re.inPVS( VMA(1), VMA(2) ); default: assert(0); Com_Error( ERR_DROP, "Bad cgame system trap: %ld", (long int) args[0] ); } return 0; }
intptr_t CL_CgameSystemCalls( intptr_t *args ) { if( cls.cgInterface == 2 && args[0] >= CG_R_SETCLIPREGION && args[0] < CG_MEMSET ) { if( args[0] < CG_S_STOPBACKGROUNDTRACK - 1 ) args[0] += 1; else if( args[0] < CG_S_STOPBACKGROUNDTRACK + 4 ) args[0] += CG_PARSE_ADD_GLOBAL_DEFINE - CG_S_STOPBACKGROUNDTRACK + 1; else if( args[0] < CG_PARSE_ADD_GLOBAL_DEFINE + 4 ) args[0] -= 4; else if( args[0] >= CG_PARSE_SOURCE_FILE_AND_LINE && args[0] <= CG_S_SOUNDDURATION ) args[0] = CG_PARSE_SOURCE_FILE_AND_LINE - 1337 - args[0] ; } switch( args[0] ) { case CG_PRINT: Com_Printf( "%s", (const char*)VMA(1) ); return 0; case CG_ERROR: if( probingCG ) { cls.cgInterface = 2; // this is a 1.1.0 cgame return 0; } Com_Error( ERR_DROP, "%s", (const char*)VMA(1) ); return 0; case CG_MILLISECONDS: return Sys_Milliseconds(); case CG_CVAR_REGISTER: Cvar_Register( (vmCvar_t*)VMA(1), (const char*)VMA(2), (const char*)VMA(3), args[4] ); return 0; case CG_CVAR_UPDATE: Cvar_Update( (vmCvar_t*)VMA(1) ); return 0; case CG_CVAR_SET: Cvar_SetSafe( (const char*)VMA(1), (const char*)VMA(2) ); return 0; case CG_CVAR_VARIABLESTRINGBUFFER: Cvar_VariableStringBuffer( (const char*)VMA(1), (char*)VMA(2), args[3] ); return 0; case CG_ARGC: return Cmd_Argc(); case CG_ARGV: Cmd_ArgvBuffer( args[1], (char*)VMA(2), args[3] ); return 0; case CG_ARGS: Cmd_ArgsBuffer( (char*)VMA(1), args[2] ); return 0; case CG_LITERAL_ARGS: Cmd_LiteralArgsBuffer( (char*)VMA(1), args[2] ); return 0; case CG_FS_FOPENFILE: return FS_FOpenFileByMode( (const char*)VMA(1), (fileHandle_t*)VMA(2), (FS_Mode)args[3] ); case CG_FS_READ: FS_Read( VMA(1), args[2], args[3] ); return 0; case CG_FS_WRITE: FS_Write( VMA(1), args[2], args[3] ); return 0; case CG_FS_FCLOSEFILE: FS_FCloseFile( args[1] ); return 0; case CG_FS_SEEK: return FS_Seek( (fileHandle_t)args[1], args[2], (FS_Origin)args[3] ); case CG_FS_GETFILELIST: return FS_GetFileList( (const char*)VMA(1), (const char*)VMA(2), (char*)VMA(3), args[4] ); case CG_SENDCONSOLECOMMAND: Cbuf_AddText( (const char*)VMA(1) ); return 0; case CG_ADDCOMMAND: Cmd_AddCommand( (const char*)VMA(1), NULL ); return 0; case CG_REMOVECOMMAND: Cmd_RemoveCommandSafe( (const char*)VMA(1) ); return 0; case CG_SENDCLIENTCOMMAND: CL_AddReliableCommand((const char*)VMA(1), false); return 0; case CG_UPDATESCREEN: // this is used during lengthy level loading, so pump message loop // Com_EventLoop(); // FIXME: if a server restarts here, BAD THINGS HAPPEN! // We can't call Com_EventLoop here, a restart will crash and this _does_ happen // if there is a map change while we are downloading at pk3. // ZOID SCR_UpdateScreen(); return 0; case CG_CM_LOADMAP: CL_CM_LoadMap( (const char*)VMA(1) ); return 0; case CG_CM_NUMINLINEMODELS: return CM_NumInlineModels(); case CG_CM_INLINEMODEL: return CM_InlineModel( args[1] ); case CG_CM_TEMPBOXMODEL: return CM_TempBoxModel( (const float*)VMA(1), (const float*)VMA(2), false ); case CG_CM_TEMPCAPSULEMODEL: return CM_TempBoxModel( (const float*)VMA(1), (const float*)VMA(2), true ); case CG_CM_POINTCONTENTS: return CM_PointContents( (const float*)VMA(1), args[2] ); case CG_CM_TRANSFORMEDPOINTCONTENTS: return CM_TransformedPointContents( (const float*)VMA(1), (clipHandle_t)args[2], (const float*)VMA(3), (const float*)VMA(4) ); case CG_CM_BOXTRACE: CM_BoxTrace( (trace_t*)VMA(1), (const float*)VMA(2), (const float*)VMA(3), (float*)VMA(4), (float*)VMA(5), (clipHandle_t)args[6], args[7], TT_AABB ); return 0; case CG_CM_CAPSULETRACE: CM_BoxTrace( (trace_t*)VMA(1), (const float*)VMA(2), (const float*)VMA(3), (float*)VMA(4), (float*)VMA(5), (clipHandle_t)args[6], args[7], TT_CAPSULE ); return 0; case CG_CM_TRANSFORMEDBOXTRACE: CM_TransformedBoxTrace( (trace_t*)VMA(1), (const float*)VMA(2), (const float*)VMA(3), (float*)VMA(4), (float*)VMA(5), (clipHandle_t)args[6], args[7], (const float*)VMA(8), (const float*)VMA(9), TT_AABB ); return 0; case CG_CM_TRANSFORMEDCAPSULETRACE: CM_TransformedBoxTrace( (trace_t*)VMA(1), (const float*)VMA(2), (const float*)VMA(3), (float*)VMA(4), (float*)VMA(5), (clipHandle_t)args[6], args[7], (const float*)VMA(8), (const float*)VMA(9), TT_CAPSULE ); return 0; case CG_CM_BISPHERETRACE: CM_BiSphereTrace( (trace_t*)VMA(1), (const float*)VMA(2), (const float*)VMA(3), VMF(4), VMF(5), (clipHandle_t)args[6], args[7] ); return 0; case CG_CM_TRANSFORMEDBISPHERETRACE: CM_TransformedBiSphereTrace( (trace_t*)VMA(1), (const float*)VMA(2), (const float*)VMA(3), VMF(4), VMF(5), (clipHandle_t)args[6], args[7], (const float*)VMA(8) ); return 0; case CG_CM_MARKFRAGMENTS: { float (&arg2)[3][3] = *reinterpret_cast<float (*)[3][3]>(VMA(2)); return re.MarkFragments( args[1], arg2, (const float*)VMA(3), args[4], (float*)VMA(5), args[6], (markFragment_t*)VMA(7) ); } case CG_S_STARTSOUND: S_StartSound( (float*)VMA(1), args[2], args[3], (sfxHandle_t)args[4] ); return 0; case CG_S_STARTLOCALSOUND: S_StartLocalSound( (sfxHandle_t)args[1], args[2] ); return 0; case CG_S_CLEARLOOPINGSOUNDS: S_ClearLoopingSounds( (bool)args[1] ); return 0; case CG_S_ADDLOOPINGSOUND: S_AddLoopingSound( args[1], (const float*)VMA(2), (const float*)VMA(3), (sfxHandle_t)args[4] ); return 0; case CG_S_ADDREALLOOPINGSOUND: S_AddRealLoopingSound( args[1], (const float*)VMA(2), (const float*)VMA(3), (sfxHandle_t)args[4] ); return 0; case CG_S_STOPLOOPINGSOUND: S_StopLoopingSound( args[1] ); return 0; case CG_S_UPDATEENTITYPOSITION: S_UpdateEntityPosition( args[1], (const float*)VMA(2) ); return 0; case CG_S_RESPATIALIZE: { float (&arg3)[3][3] = *reinterpret_cast<float (*)[3][3]>(VMA(3)); S_Respatialize( args[1], (const float*)VMA(2), arg3, args[4] ); return 0; } case CG_S_REGISTERSOUND: return S_RegisterSound( (const char*)VMA(1), (bool)args[2] ); case CG_S_SOUNDDURATION: return S_SoundDuration( args[1] ); case CG_S_STARTBACKGROUNDTRACK: S_StartBackgroundTrack( (const char*)VMA(1), (const char*)VMA(2) ); return 0; case CG_R_LOADWORLDMAP: re.LoadWorld( (const char*)VMA(1) ); return 0; case CG_R_REGISTERMODEL: return re.RegisterModel( (const char*)VMA(1) ); case CG_R_REGISTERSKIN: return re.RegisterSkin( (const char*)VMA(1) ); case CG_R_REGISTERSHADER: return re.RegisterShader( (const char*)VMA(1) ); case CG_R_REGISTERSHADERNOMIP: return re.RegisterShaderNoMip( (const char*)VMA(1) ); case CG_R_REGISTERFONT: re.RegisterFont( (const char*)VMA(1), args[2], (fontInfo_t*)VMA(3)); return 0; case CG_R_CLEARSCENE: re.ClearScene(); return 0; case CG_R_ADDREFENTITYTOSCENE: re.AddRefEntityToScene( (const refEntity_t*)VMA(1) ); return 0; case CG_R_ADDPOLYTOSCENE: re.AddPolyToScene( (qhandle_t)args[1], args[2], (const polyVert_t*)VMA(3), 1 ); return 0; case CG_R_ADDPOLYSTOSCENE: re.AddPolyToScene( (qhandle_t)args[1], args[2], (const polyVert_t*)VMA(3), args[4] ); return 0; case CG_R_LIGHTFORPOINT: return re.LightForPoint( (float*)VMA(1), (float*)VMA(2), (float*)VMA(3), (float*)VMA(4) ); case CG_R_ADDLIGHTTOSCENE: re.AddLightToScene( (const float*)VMA(1), VMF(2), VMF(3), VMF(4), VMF(5) ); return 0; case CG_R_ADDADDITIVELIGHTTOSCENE: re.AddAdditiveLightToScene( (const float*)VMA(1), VMF(2), VMF(3), VMF(4), VMF(5) ); return 0; case CG_R_RENDERSCENE: re.RenderScene( (const refdef_t*)VMA(1) ); return 0; case CG_R_SETCOLOR: re.SetColor( (const float*)VMA(1) ); return 0; case CG_R_SETCLIPREGION: re.SetClipRegion( (const float*)VMA(1) ); return 0; case CG_R_DRAWSTRETCHPIC: re.DrawStretchPic( VMF(1), VMF(2), VMF(3), VMF(4), VMF(5), VMF(6), VMF(7), VMF(8), (qhandle_t)args[9] ); return 0; case CG_R_MODELBOUNDS: re.ModelBounds( (qhandle_t)args[1], (float*)VMA(2), (float*)VMA(3) ); return 0; case CG_R_LERPTAG: return re.LerpTag( (orientation_t*)VMA(1), args[2], args[3], args[4], VMF(5), (const char*)VMA(6) ); case CG_GETGLCONFIG: CL_GetGlconfig( (glconfig_t*)VMA(1) ); return 0; case CG_GETGAMESTATE: CL_GetGameState( (gameState_t*)VMA(1) ); return 0; case CG_GETCURRENTSNAPSHOTNUMBER: CL_GetCurrentSnapshotNumber( (int*)VMA(1), (int*)VMA(2) ); return 0; case CG_GETSNAPSHOT: return CL_GetSnapshot( args[1], (snapshot_t*)VMA(2) ); case CG_GETSERVERCOMMAND: return CL_GetServerCommand( args[1] ); case CG_GETCURRENTCMDNUMBER: return CL_GetCurrentCmdNumber(); case CG_GETUSERCMD: return CL_GetUserCmd( args[1], (usercmd_t*)VMA(2) ); case CG_SETUSERCMDVALUE: CL_SetUserCmdValue( args[1], VMF(2) ); return 0; case CG_MEMORY_REMAINING: return Hunk_MemoryRemaining(); case CG_KEY_ISDOWN: return Key_IsDown( args[1] ); case CG_KEY_GETCATCHER: return Key_GetCatcher(); case CG_KEY_SETCATCHER: // don't allow the cgame module to toggle the console Key_SetCatcher( ( args[1] & ~KEYCATCH_CONSOLE ) | ( Key_GetCatcher() & KEYCATCH_CONSOLE ) ); return 0; case CG_KEY_GETKEY: return Key_GetKey( (const char*)VMA(1) ); case CG_GETDEMOSTATE: return CL_DemoState( ); case CG_GETDEMOPOS: return CL_DemoPos( ); case CG_GETDEMONAME: CL_DemoName( (char*)VMA(1), args[2] ); return 0; case CG_KEY_KEYNUMTOSTRINGBUF: Key_KeynumToStringBuf( args[1], (char*)VMA(2), args[3] ); return 0; case CG_KEY_GETBINDINGBUF: Key_GetBindingBuf( args[1], (char*)VMA(2), args[3] ); return 0; case CG_KEY_SETBINDING: Key_SetBinding( args[1], (const char*)VMA(2) ); return 0; case CG_PARSE_ADD_GLOBAL_DEFINE: return Parse_AddGlobalDefine( (char*)VMA(1) ); case CG_PARSE_LOAD_SOURCE: return Parse_LoadSourceHandle( (const char*)VMA(1) ); case CG_PARSE_FREE_SOURCE: return Parse_FreeSourceHandle( args[1] ); case CG_PARSE_READ_TOKEN: return Parse_ReadTokenHandle( args[1], (pc_token_t*)VMA(2) ); case CG_PARSE_SOURCE_FILE_AND_LINE: return Parse_SourceFileAndLine( args[1], (char*)VMA(2), (int*)VMA(3) ); case CG_KEY_SETOVERSTRIKEMODE: Key_SetOverstrikeMode( (bool)args[1] ); return 0; case CG_KEY_GETOVERSTRIKEMODE: return Key_GetOverstrikeMode( ); case CG_FIELD_COMPLETELIST: Field_CompleteList( (char*)VMA(1) ); return 0; case CG_MEMSET: ::memset( VMA(1), args[2], args[3] ); return 0; case CG_MEMCPY: ::memcpy( VMA(1), VMA(2), args[3] ); return 0; case CG_STRNCPY: safe_strncpy( (char*)VMA(1), (const char*)VMA(2), args[3] ); return args[1]; case CG_SIN: return FloatAsInt( sin( VMF(1) ) ); case CG_COS: return FloatAsInt( cos( VMF(1) ) ); case CG_ATAN2: return FloatAsInt( atan2( VMF(1), VMF(2) ) ); case CG_SQRT: return FloatAsInt( sqrt( VMF(1) ) ); case CG_FLOOR: return FloatAsInt( floor( VMF(1) ) ); case CG_CEIL: return FloatAsInt( ceil( VMF(1) ) ); case CG_ACOS: return FloatAsInt( Q_acos( VMF(1) ) ); case CG_S_STOPBACKGROUNDTRACK: S_StopBackgroundTrack(); return 0; case CG_REAL_TIME: return Com_RealTime( (qtime_t*)VMA(1) ); case CG_SNAPVECTOR: Q_SnapVector((float*)VMA(1)); return 0; case CG_CIN_PLAYCINEMATIC: return CIN_PlayCinematic((const char*)VMA(1), args[2], args[3], args[4], args[5], args[6]); case CG_CIN_STOPCINEMATIC: return CIN_StopCinematic(args[1]); case CG_CIN_RUNCINEMATIC: return CIN_RunCinematic(args[1]); case CG_CIN_DRAWCINEMATIC: CIN_DrawCinematic(args[1]); return 0; case CG_CIN_SETEXTENTS: CIN_SetExtents(args[1], args[2], args[3], args[4], args[5]); return 0; case CG_R_REMAP_SHADER: re.RemapShader( (const char*)VMA(1), (const char*)VMA(2), (const char*)VMA(3) ); return 0; case CG_GET_ENTITY_TOKEN: return re.GetEntityToken( (char*)VMA(1), args[2] ); case CG_R_INPVS: return re.inPVS( (const float*)VMA(1), (const float*)VMA(2) ); default: assert(0); Com_Error( ERR_DROP, "Bad cgame system trap: %ld", (long int) args[0] ); } return 0; }
/* ==================== CL_CgameSystemCalls The cgame module is making a system call ==================== */ intptr_t CL_CgameSystemCalls( intptr_t *args ) { switch ( args[ 0 ] ) { case CG_PRINT: Com_Printf( "%s", ( char * ) VMA( 1 ) ); return 0; case CG_ERROR: Com_Error( ERR_DROP, "%s", ( char * ) VMA( 1 ) ); case CG_MILLISECONDS: return Sys_Milliseconds(); case CG_CVAR_REGISTER: Cvar_Register( VMA( 1 ), VMA( 2 ), VMA( 3 ), args[ 4 ] ); return 0; case CG_CVAR_UPDATE: Cvar_Update( VMA( 1 ) ); return 0; case CG_CVAR_SET: Cvar_Set( VMA( 1 ), VMA( 2 ) ); return 0; case CG_CVAR_VARIABLESTRINGBUFFER: VM_CheckBlock( args[2], args[3], "CVARVSB" ); Cvar_VariableStringBuffer( VMA( 1 ), VMA( 2 ), args[ 3 ] ); return 0; case CG_CVAR_LATCHEDVARIABLESTRINGBUFFER: VM_CheckBlock( args[2], args[3], "CVARLVSB" ); Cvar_LatchedVariableStringBuffer( VMA( 1 ), VMA( 2 ), args[ 3 ] ); return 0; case CG_ARGC: return Cmd_Argc(); case CG_ARGV: VM_CheckBlock( args[2], args[3], "ARGV" ); Cmd_ArgvBuffer( args[ 1 ], VMA( 2 ), args[ 3 ] ); return 0; case CG_ARGS: VM_CheckBlock( args[1], args[2], "ARGS" ); Cmd_ArgsBuffer( VMA( 1 ), args[ 2 ] ); return 0; case CG_LITERAL_ARGS: // FIXME VM_CheckBlock( args[1], args[2], "LARGS" ); Cmd_LiteralArgsBuffer( VMA( 1 ), args[ 2 ] ); // Cmd_ArgsBuffer(VMA(1), args[2]); return 0; case CG_GETDEMOSTATE: return CL_DemoState(); case CG_GETDEMOPOS: return CL_DemoPos(); case CG_FS_FOPENFILE: return FS_FOpenFileByMode( VMA( 1 ), VMA( 2 ), args[ 3 ] ); case CG_FS_READ: VM_CheckBlock( args[1], args[2], "FSREAD" ); FS_Read2( VMA( 1 ), args[ 2 ], args[ 3 ] ); return 0; case CG_FS_WRITE: VM_CheckBlock( args[1], args[2], "FSWRITE" ); return FS_Write( VMA( 1 ), args[ 2 ], args[ 3 ] ); case CG_FS_FCLOSEFILE: FS_FCloseFile( args[ 1 ] ); return 0; case CG_FS_GETFILELIST: VM_CheckBlock( args[3], args[4], "FSGFL" ); return FS_GetFileList( VMA( 1 ), VMA( 2 ), VMA( 3 ), args[ 4 ] ); case CG_FS_DELETEFILE: return FS_Delete( VMA( 1 ) ); case CG_SENDCONSOLECOMMAND: Cbuf_AddText( VMA( 1 ) ); return 0; case CG_ADDCOMMAND: CL_AddCgameCommand( VMA( 1 ) ); return 0; case CG_REMOVECOMMAND: Cmd_RemoveCommand( VMA( 1 ) ); return 0; case CG_COMPLETE_CALLBACK: if ( completer ) { completer( VMA( 1 ) ); } return 0; case CG_SENDCLIENTCOMMAND: CL_AddReliableCommand( VMA( 1 ) ); return 0; case CG_UPDATESCREEN: SCR_UpdateScreen(); return 0; case CG_CM_LOADMAP: CL_CM_LoadMap( VMA( 1 ) ); return 0; case CG_CM_NUMINLINEMODELS: return CM_NumInlineModels(); case CG_CM_INLINEMODEL: return CM_InlineModel( args[ 1 ] ); case CG_CM_TEMPBOXMODEL: return CM_TempBoxModel( VMA( 1 ), VMA( 2 ), qfalse ); case CG_CM_TEMPCAPSULEMODEL: return CM_TempBoxModel( VMA( 1 ), VMA( 2 ), qtrue ); case CG_CM_POINTCONTENTS: return CM_PointContents( VMA( 1 ), args[ 2 ] ); case CG_CM_TRANSFORMEDPOINTCONTENTS: return CM_TransformedPointContents( VMA( 1 ), args[ 2 ], VMA( 3 ), VMA( 4 ) ); case CG_CM_BOXTRACE: CM_BoxTrace( VMA( 1 ), VMA( 2 ), VMA( 3 ), VMA( 4 ), VMA( 5 ), args[ 6 ], args[ 7 ], TT_AABB ); return 0; case CG_CM_TRANSFORMEDBOXTRACE: CM_TransformedBoxTrace( VMA( 1 ), VMA( 2 ), VMA( 3 ), VMA( 4 ), VMA( 5 ), args[ 6 ], args[ 7 ], VMA( 8 ), VMA( 9 ), TT_AABB ); return 0; case CG_CM_CAPSULETRACE: CM_BoxTrace( VMA( 1 ), VMA( 2 ), VMA( 3 ), VMA( 4 ), VMA( 5 ), args[ 6 ], args[ 7 ], TT_CAPSULE ); return 0; case CG_CM_TRANSFORMEDCAPSULETRACE: CM_TransformedBoxTrace( VMA( 1 ), VMA( 2 ), VMA( 3 ), VMA( 4 ), VMA( 5 ), args[ 6 ], args[ 7 ], VMA( 8 ), VMA( 9 ), TT_CAPSULE ); return 0; case CG_CM_BISPHERETRACE: CM_BiSphereTrace( VMA( 1 ), VMA( 2 ), VMA( 3 ), VMF( 4 ), VMF( 5 ), args[ 6 ], args[ 7 ] ); return 0; case CG_CM_TRANSFORMEDBISPHERETRACE: CM_TransformedBiSphereTrace( VMA( 1 ), VMA( 2 ), VMA( 3 ), VMF( 4 ), VMF( 5 ), args[ 6 ], args[ 7 ], VMA( 8 ) ); return 0; case CG_CM_MARKFRAGMENTS: return re.MarkFragments( args[ 1 ], VMA( 2 ), VMA( 3 ), args[ 4 ], VMA( 5 ), args[ 6 ], VMA( 7 ) ); case CG_R_PROJECTDECAL: re.ProjectDecal( args[ 1 ], args[ 2 ], VMA( 3 ), VMA( 4 ), VMA( 5 ), args[ 6 ], args[ 7 ] ); return 0; case CG_R_CLEARDECALS: re.ClearDecals(); return 0; case CG_S_STARTSOUND: S_StartSound( VMA( 1 ), args[ 2 ], args[ 3 ], args[ 4 ] ); return 0; case CG_S_STARTSOUNDEX: S_StartSoundEx( VMA( 1 ), args[ 2 ], args[ 3 ], args[ 4 ] ); return 0; case CG_S_STARTLOCALSOUND: S_StartLocalSound( args[ 1 ], args[ 2 ] ); return 0; case CG_S_CLEARLOOPINGSOUNDS: S_ClearLoopingSounds( args[ 1 ] ); return 0; case CG_S_CLEARSOUNDS: /*if(args[1] == 0) { S_ClearSounds(qtrue, qfalse); } else if(args[1] == 1) { S_ClearSounds(qtrue, qtrue); }*/ return 0; case CG_S_ADDLOOPINGSOUND: S_AddLoopingSound( args[ 1 ], VMA( 2 ), VMA( 3 ), args[ 4 ] ); return 0; case CG_S_ADDREALLOOPINGSOUND: S_AddRealLoopingSound( args[ 1 ], VMA( 2 ), VMA( 3 ), args[ 4 ] ); return 0; case CG_S_STOPLOOPINGSOUND: S_StopLoopingSound( args[ 1 ] ); return 0; case CG_S_STOPSTREAMINGSOUND: // FIXME //S_StopEntStreamingSound(args[1]); return 0; case CG_S_UPDATEENTITYPOSITION: S_UpdateEntityPosition( args[ 1 ], VMA( 2 ) ); return 0; case CG_S_GETVOICEAMPLITUDE: return S_GetVoiceAmplitude( args[ 1 ] ); case CG_S_GETSOUNDLENGTH: return S_GetSoundLength( args[ 1 ] ); // ydnar: for looped sound starts case CG_S_GETCURRENTSOUNDTIME: return S_GetCurrentSoundTime(); case CG_S_RESPATIALIZE: S_Respatialize( args[ 1 ], VMA( 2 ), VMA( 3 ), args[ 4 ] ); return 0; case CG_S_REGISTERSOUND: #ifdef DOOMSOUND ///// (SA) DOOMSOUND return S_RegisterSound( VMA( 1 ) ); #else return S_RegisterSound( VMA( 1 ), args[ 2 ] ); #endif ///// (SA) DOOMSOUND case CG_S_STARTBACKGROUNDTRACK: //S_StartBackgroundTrack(VMA(1), VMA(2), args[3]); //----(SA) added fadeup time S_StartBackgroundTrack( VMA( 1 ), VMA( 2 ) ); return 0; case CG_S_FADESTREAMINGSOUND: // FIXME //S_FadeStreamingSound(VMF(1), args[2], args[3]); //----(SA) added music/all-streaming options return 0; case CG_S_STARTSTREAMINGSOUND: // FIXME //return S_StartStreamingSound(VMA(1), VMA(2), args[3], args[4], args[5]); return 0; case CG_R_LOADWORLDMAP: re.LoadWorld( VMA( 1 ) ); return 0; case CG_R_REGISTERMODEL: #ifdef IPHONE GLimp_AcquireGL(); return re.RegisterModel( VMA( 1 ) ); GLimp_ReleaseGL(); #else return re.RegisterModel( VMA( 1 ) ); #endif // IPHONE case CG_R_REGISTERSKIN: return re.RegisterSkin( VMA( 1 ) ); //----(SA) added case CG_R_GETSKINMODEL: return re.GetSkinModel( args[ 1 ], VMA( 2 ), VMA( 3 ) ); case CG_R_GETMODELSHADER: return re.GetShaderFromModel( args[ 1 ], args[ 2 ], args[ 3 ] ); //----(SA) end case CG_R_REGISTERSHADER: #ifdef IPHONE_NOTYET GLimp_AcquireGL(); return re.RegisterShader( VMA( 1 ) ); GLimp_ReleaseGL(); #else return re.RegisterShader( VMA( 1 ) ); #endif // IPHONE case CG_R_REGISTERFONT: re.RegisterFontVM( VMA( 1 ), VMA( 2 ), args[ 3 ], VMA( 4 ) ); return 0; case CG_R_REGISTERSHADERNOMIP: #ifdef IPHONE_NOTYET GLimp_AcquireGL(); return re.RegisterShaderNoMip( VMA( 1 ) ); GLimp_ReleaseGL(); #else return re.RegisterShaderNoMip( VMA( 1 ) ); #endif // IPHONE #if defined( USE_REFLIGHT ) case CG_R_REGISTERSHADERLIGHTATTENUATION: return re.RegisterShaderLightAttenuation( VMA( 1 ) ); #endif case CG_R_CLEARSCENE: re.ClearScene(); return 0; case CG_R_ADDREFENTITYTOSCENE: re.AddRefEntityToScene( VMA( 1 ) ); return 0; #if defined( USE_REFLIGHT ) case CG_R_ADDREFLIGHTSTOSCENE: re.AddRefLightToScene( VMA( 1 ) ); return 0; #endif case CG_R_ADDPOLYTOSCENE: re.AddPolyToScene( args[ 1 ], args[ 2 ], VMA( 3 ) ); return 0; case CG_R_ADDPOLYSTOSCENE: re.AddPolysToScene( args[ 1 ], args[ 2 ], VMA( 3 ), args[ 4 ] ); return 0; case CG_R_ADDPOLYBUFFERTOSCENE: re.AddPolyBufferToScene( VMA( 1 ) ); return 0; case CG_R_ADDLIGHTTOSCENE: re.AddLightToScene( VMA( 1 ), VMF( 2 ), VMF( 3 ), VMF( 4 ), VMF( 5 ), VMF( 6 ), args[ 7 ], args[ 8 ] ); return 0; case CG_R_ADDADDITIVELIGHTTOSCENE: re.AddAdditiveLightToScene( VMA( 1 ), VMF( 2 ), VMF( 3 ), VMF( 4 ), VMF( 5 ) ); return 0; case CG_FS_SEEK: return FS_Seek( args[ 1 ], args[ 2 ], args[ 3 ] ); case CG_R_ADDCORONATOSCENE: re.AddCoronaToScene( VMA( 1 ), VMF( 2 ), VMF( 3 ), VMF( 4 ), VMF( 5 ), args[ 6 ], args[ 7 ] ); return 0; case CG_R_SETFOG: re.SetFog( args[ 1 ], args[ 2 ], args[ 3 ], VMF( 4 ), VMF( 5 ), VMF( 6 ), VMF( 7 ) ); return 0; case CG_R_SETGLOBALFOG: re.SetGlobalFog( args[ 1 ], args[ 2 ], VMF( 3 ), VMF( 4 ), VMF( 5 ), VMF( 6 ) ); return 0; case CG_R_RENDERSCENE: re.RenderScene( VMA( 1 ) ); return 0; case CG_R_SAVEVIEWPARMS: re.SaveViewParms(); return 0; case CG_R_RESTOREVIEWPARMS: re.RestoreViewParms(); return 0; case CG_R_SETCOLOR: re.SetColor( VMA( 1 ) ); return 0; // Tremulous case CG_R_SETCLIPREGION: re.SetClipRegion( VMA( 1 ) ); return 0; case CG_R_DRAWSTRETCHPIC: re.DrawStretchPic( VMF( 1 ), VMF( 2 ), VMF( 3 ), VMF( 4 ), VMF( 5 ), VMF( 6 ), VMF( 7 ), VMF( 8 ), args[ 9 ] ); return 0; case CG_R_DRAWROTATEDPIC: re.DrawRotatedPic( VMF( 1 ), VMF( 2 ), VMF( 3 ), VMF( 4 ), VMF( 5 ), VMF( 6 ), VMF( 7 ), VMF( 8 ), args[ 9 ], VMF( 10 ) ); return 0; case CG_R_DRAWSTRETCHPIC_GRADIENT: re.DrawStretchPicGradient( VMF( 1 ), VMF( 2 ), VMF( 3 ), VMF( 4 ), VMF( 5 ), VMF( 6 ), VMF( 7 ), VMF( 8 ), args[ 9 ], VMA( 10 ), args[ 11 ] ); return 0; case CG_R_DRAW2DPOLYS: re.Add2dPolys( VMA( 1 ), args[ 2 ], args[ 3 ] ); return 0; case CG_R_MODELBOUNDS: re.ModelBounds( args[ 1 ], VMA( 2 ), VMA( 3 ) ); return 0; case CG_R_LERPTAG: return re.LerpTag( VMA( 1 ), VMA( 2 ), VMA( 3 ), args[ 4 ] ); case CG_GETGLCONFIG: CL_GetGlconfig( VMA( 1 ) ); return 0; case CG_GETGAMESTATE: CL_GetGameState( VMA( 1 ) ); return 0; case CG_GETCURRENTSNAPSHOTNUMBER: CL_GetCurrentSnapshotNumber( VMA( 1 ), VMA( 2 ) ); return 0; case CG_GETSNAPSHOT: return CL_GetSnapshot( args[ 1 ], VMA( 2 ) ); case CG_GETSERVERCOMMAND: return CL_GetServerCommand( args[ 1 ] ); case CG_GETCURRENTCMDNUMBER: return CL_GetCurrentCmdNumber(); case CG_GETUSERCMD: return CL_GetUserCmd( args[ 1 ], VMA( 2 ) ); case CG_SETUSERCMDVALUE: CL_SetUserCmdValue( args[ 1 ], args[ 2 ], VMF( 3 ), args[ 4 ] ); return 0; case CG_SETCLIENTLERPORIGIN: CL_SetClientLerpOrigin( VMF( 1 ), VMF( 2 ), VMF( 3 ) ); return 0; case CG_MEMORY_REMAINING: return Hunk_MemoryRemaining(); case CG_KEY_ISDOWN: return Key_IsDown( args[ 1 ] ); case CG_KEY_GETCATCHER: return Key_GetCatcher(); case CG_KEY_SETCATCHER: Key_SetCatcher( args[ 1 ] ); return 0; case CG_KEY_GETKEY: return Key_GetKey( VMA( 1 ) ); case CG_KEY_GETOVERSTRIKEMODE: return Key_GetOverstrikeMode(); case CG_KEY_SETOVERSTRIKEMODE: Key_SetOverstrikeMode( args[ 1 ] ); return 0; case CG_S_STOPBACKGROUNDTRACK: S_StopBackgroundTrack(); return 0; case CG_REAL_TIME: return Com_RealTime( VMA( 1 ) ); case CG_SNAPVECTOR: Q_SnapVector( VMA( 1 ) ); return 0; case CG_CIN_PLAYCINEMATIC: return CIN_PlayCinematic( VMA( 1 ), args[ 2 ], args[ 3 ], args[ 4 ], args[ 5 ], args[ 6 ] ); case CG_CIN_STOPCINEMATIC: return CIN_StopCinematic( args[ 1 ] ); case CG_CIN_RUNCINEMATIC: return CIN_RunCinematic( args[ 1 ] ); case CG_CIN_DRAWCINEMATIC: CIN_DrawCinematic( args[ 1 ] ); return 0; case CG_CIN_SETEXTENTS: CIN_SetExtents( args[ 1 ], args[ 2 ], args[ 3 ], args[ 4 ], args[ 5 ] ); return 0; case CG_R_REMAP_SHADER: re.RemapShader( VMA( 1 ), VMA( 2 ), VMA( 3 ) ); return 0; case CG_LOADCAMERA: //return loadCamera(args[1], VMA(2)); return 0; case CG_STARTCAMERA: //if(args[1] == 0) //{ // CAM_PRIMARY // cl.cameraMode = qtrue; //} //startCamera(args[1], args[2]); return 0; case CG_STOPCAMERA: //if(args[1] == 0) //{ // CAM_PRIMARY // cl.cameraMode = qfalse; //} return 0; case CG_GETCAMERAINFO: //return getCameraInfo(args[1], args[2], VMA(3), VMA(4), VMA(5)); return 0; case CG_GET_ENTITY_TOKEN: VM_CheckBlock( args[1], args[2], "GETET" ); return re.GetEntityToken( VMA( 1 ), args[ 2 ] ); case CG_INGAME_POPUP: if ( cls.state == CA_ACTIVE && !clc.demoplaying ) { if ( uivm ) { // Gordon: can be called as the system is shutting down VM_Call( uivm, UI_SET_ACTIVE_MENU, args[ 1 ] ); } } return 0; case CG_INGAME_CLOSEPOPUP: return 0; case CG_KEY_GETBINDINGBUF: VM_CheckBlock( args[2], args[3], "KEYGBB" ); Key_GetBindingBuf( args[ 1 ], VMA( 2 ), args[ 3 ] ); return 0; case CG_KEY_SETBINDING: Key_SetBinding( args[ 1 ], VMA( 2 ) ); return 0; case CG_PARSE_ADD_GLOBAL_DEFINE: return Parse_AddGlobalDefine( VMA( 1 ) ); case CG_PARSE_LOAD_SOURCE: return Parse_LoadSourceHandle( VMA( 1 ) ); case CG_PARSE_FREE_SOURCE: return Parse_FreeSourceHandle( args[ 1 ] ); case CG_PARSE_READ_TOKEN: return Parse_ReadTokenHandle( args[ 1 ], VMA( 2 ) ); case CG_PARSE_SOURCE_FILE_AND_LINE: return Parse_SourceFileAndLine( args[ 1 ], VMA( 2 ), VMA( 3 ) ); case CG_KEY_KEYNUMTOSTRINGBUF: VM_CheckBlock( args[2], args[3], "KEYNTSB" ); Key_KeynumToStringBuf( args[ 1 ], VMA( 2 ), args[ 3 ] ); return 0; case CG_KEY_BINDINGTOKEYS: Key_GetBindingByString( VMA( 1 ), VMA( 2 ), VMA( 3 ) ); return 0; case CG_S_FADEALLSOUNDS: // FIXME //S_FadeAllSounds(VMF(1), args[2], args[3]); return 0; case CG_R_INPVS: return re.inPVS( VMA( 1 ), VMA( 2 ) ); case CG_GETHUNKDATA: Com_GetHunkInfo( VMA( 1 ), VMA( 2 ) ); return 0; case CG_PUMPEVENTLOOP: // Com_EventLoop(); // CL_WritePacket(); return 0; //zinx - binary channel case CG_SENDMESSAGE: VM_CheckBlock( args[1], args[2], "SENDM" ); CL_SendBinaryMessage( VMA( 1 ), args[ 2 ] ); return 0; case CG_MESSAGESTATUS: return CL_BinaryMessageStatus(); //bani - dynamic shaders case CG_R_LOADDYNAMICSHADER: return re.LoadDynamicShader( VMA( 1 ), VMA( 2 ) ); // fretn - render to texture case CG_R_RENDERTOTEXTURE: re.RenderToTexture( args[ 1 ], args[ 2 ], args[ 3 ], args[ 4 ], args[ 5 ] ); return 0; //bani case CG_R_GETTEXTUREID: return re.GetTextureId( VMA( 1 ) ); //bani - flush gl rendering buffers case CG_R_FINISH: re.Finish(); return 0; case CG_GETDEMONAME: VM_CheckBlock( args[1], args[2], "GETDM" ); CL_DemoName( VMA( 1 ), args[ 2 ] ); return 0; case CG_R_LIGHTFORPOINT: return re.LightForPoint( VMA( 1 ), VMA( 2 ), VMA( 3 ), VMA( 4 ) ); case CG_S_SOUNDDURATION: return S_SoundDuration( args[ 1 ] ); #if defined( USE_REFENTITY_ANIMATIONSYSTEM ) case CG_R_REGISTERANIMATION: return re.RegisterAnimation( VMA( 1 ) ); case CG_R_CHECKSKELETON: return re.CheckSkeleton( VMA( 1 ), args[ 2 ], args[ 3 ] ); case CG_R_BUILDSKELETON: return re.BuildSkeleton( VMA( 1 ), args[ 2 ], args[ 3 ], args[ 4 ], VMF( 5 ), args[ 6 ] ); case CG_R_BLENDSKELETON: return re.BlendSkeleton( VMA( 1 ), VMA( 2 ), VMF( 3 ) ); case CG_R_BONEINDEX: return re.BoneIndex( args[ 1 ], VMA( 2 ) ); case CG_R_ANIMNUMFRAMES: return re.AnimNumFrames( args[ 1 ] ); case CG_R_ANIMFRAMERATE: return re.AnimFrameRate( args[ 1 ] ); #endif case CG_REGISTER_BUTTON_COMMANDS: CL_RegisterButtonCommands( VMA( 1 ) ); return 0; case CG_GETCLIPBOARDDATA: VM_CheckBlock( args[1], args[2], "GETCLIP" ); if ( cl_allowPaste->integer ) { CL_GetClipboardData( VMA(1), args[2], args[3] ); } else { ( (char *) VMA( 1 ) )[0] = '\0'; } return 0; case CG_QUOTESTRING: Cmd_QuoteStringBuffer( VMA( 1 ), VMA( 2 ), args[ 3 ] ); return 0; case CG_GETTEXT: strncpy( VMA(1), __(VMA(2)), args[3] ); return 0; case CG_R_GLYPH: re.GlyphVM( args[1], VMA(2), VMA(3) ); return 0; case CG_R_GLYPHCHAR: re.GlyphCharVM( args[1], args[2], VMA(3) ); return 0; case CG_R_UREGISTERFONT: re.UnregisterFontVM( args[1] ); return 0; default: Com_Error( ERR_DROP, "Bad cgame system trap: %ld", ( long int ) args[ 0 ] ); } return 0; }
/* ==================== CL_CgameSystemCalls The cgame module is making a system call ==================== */ intptr_t CL_CgameSystemCalls( intptr_t *args ) { switch( args[0] ) { case CG_PRINT: Com_Printf( "%s", VMA(1) ); return 0; case CG_FATAL_ERROR: Com_Error( ERR_DROP, "%s", VMA(1) ); return 0; case CG_MILLISECONDS: return Sys_Milliseconds(); case CG_CVAR_REGISTER: Cvar_Register( VMA(1), VMA(2), VMA(3), args[4] ); return 0; case CG_CVAR_UPDATE: Cvar_Update( VMA(1) ); return 0; case CG_CVAR_SET: Cvar_Set( VMA(1), VMA(2) ); return 0; case CG_CVAR_VARIABLESTRINGBUFFER: Cvar_VariableStringBuffer( VMA(1), VMA(2), args[3] ); return 0; case CG_ARGC: return Cmd_Argc(); case CG_ARGV: Cmd_ArgvBuffer( args[1], VMA(2), args[3] ); return 0; case CG_ARGVI: return atoi( Cmd_Argv( args[1] ) ); case CG_ARGS: Cmd_ArgsBuffer( VMA(1), args[2] ); return 0; case CG_CMD_EXECUTETEXT: Cbuf_ExecuteText( args[1], VMA(2) ); return 0; case CG_FS_FOPENFILE: return FS_FOpenFileByMode( VMA(1), VMA(2), args[3] ); case CG_FS_READ: FS_Read( VMA(1), args[2], args[3] ); return 0; case CG_FS_WRITE: FS_Write( VMA(1), args[2], args[3] ); return 0; case CG_FS_FCLOSEFILE: FS_FCloseFile( args[1] ); return 0; case CG_SENDCONSOLECOMMAND: Cbuf_AddText( VMA(1) ); return 0; case CG_FORWARDCOMMAND: VM_Call( uivm, UI_CONSOLE_COMMAND, cls.realtime ); return 0; case CG_ADDCOMMAND: CL_AddCgameCommand( VMA(1) ); return 0; case CG_REMOVECOMMAND: Cmd_RemoveCommand( VMA(1) ); return 0; case CG_SENDCLIENTCOMMAND: CL_AddReliableCommand( VMA(1) ); return 0; case CG_UPDATESCREEN: // this is used during lengthy level loading, so pump message loop // Com_EventLoop(); // FIXME: if a server restarts here, BAD THINGS HAPPEN! // We can't call Com_EventLoop here, a restart will crash and this _does_ happen // if there is a map change while we are downloading at pk3. // ZOID SCR_UpdateScreen(); return 0; case CG_CM_LOADMAP: CL_CM_LoadMap( VMA(1) ); return 0; case CG_CM_NUMINLINEMODELS: return CM_NumInlineModels(); case CG_CM_INLINEMODEL: return CM_InlineModel( args[1] ); case CG_CM_TEMPBOXMODEL: return CM_TempBoxModel( VMA(1), VMA(2), /*int capsule*/ qfalse ); case CG_CM_TEMPCAPSULEMODEL: return CM_TempBoxModel( VMA(1), VMA(2), /*int capsule*/ qtrue ); case CG_CM_POINTCONTENTS: return CM_PointContents( VMA(1), args[2] ); case CG_CM_TRANSFORMEDPOINTCONTENTS: return CM_TransformedPointContents( VMA(1), args[2], VMA(3), VMA(4) ); case CG_CM_BOXTRACE: CM_BoxTrace( VMA(1), VMA(2), VMA(3), VMA(4), VMA(5), args[6], args[7], /*int capsule*/ qfalse ); return 0; case CG_CM_CAPSULETRACE: CM_BoxTrace( VMA(1), VMA(2), VMA(3), VMA(4), VMA(5), args[6], args[7], /*int capsule*/ qtrue ); return 0; case CG_CM_TRANSFORMEDBOXTRACE: CM_TransformedBoxTrace( VMA(1), VMA(2), VMA(3), VMA(4), VMA(5), args[6], args[7], VMA(8), VMA(9), /*int capsule*/ qfalse ); return 0; case CG_CM_TRANSFORMEDCAPSULETRACE: CM_TransformedBoxTrace( VMA(1), VMA(2), VMA(3), VMA(4), VMA(5), args[6], args[7], VMA(8), VMA(9), /*int capsule*/ qtrue ); return 0; case CG_CM_MARKFRAGMENTS: return re.MarkFragments( args[1], VMA(2), VMA(3), args[4], VMA(5), args[6], VMA(7) ); case CG_S_STARTSOUND: S_StartSound( VMA(1), args[2], args[3], args[4] ); return 0; case CG_S_STARTLOCALSOUND: S_StartLocalSound( args[1], args[2] ); return 0; case CG_S_CLEARLOOPINGSOUNDS: S_ClearLoopingSounds(args[1]); return 0; case CG_S_ADDLOOPINGSOUND: S_AddLoopingSound( args[1], VMA(2), VMA(3), args[4] ); return 0; case CG_S_ADDREALLOOPINGSOUND: S_AddRealLoopingSound( args[1], VMA(2), VMA(3), args[4] ); return 0; case CG_S_STOPLOOPINGSOUND: S_StopLoopingSound( args[1] ); return 0; case CG_S_UPDATEENTITYPOSITION: S_UpdateEntityPosition( args[1], VMA(2) ); return 0; case CG_S_RESPATIALIZE: S_Respatialize( args[1], VMA(2), VMA(3), args[4] ); return 0; case CG_S_REGISTERSOUND: return S_RegisterSound( VMA(1), args[2] ); case CG_S_STARTBACKGROUNDTRACK: S_StartBackgroundTrack( VMA(1), VMA(2) ); return 0; case CG_R_LOADWORLDMAP: CL_R_LoadWorld( VMA( 1 ) ); return 0; case CG_R_REGISTERMODEL: return re.RegisterModel( VMA(1) ); case CG_R_REGISTERSKIN: return re.RegisterSkin( VMA(1) ); case CG_R_REGISTERSHADER: return re.RegisterShader( VMA(1) ); case CG_R_REGISTERSHADERNOMIP: return re.RegisterShaderNoMip( VMA(1) ); case CG_R_REGISTERFONT: return re.RegisterFont( VMA(1) ); case CG_R_CLEARSCENE: re.ClearScene(); return 0; case CG_R_BUILDPOSE: { animGroupTransition_t trans; trans.animGroup = 0; trans.interp = 0; return re.BuildPose( args[1], VMA( 2 ), args[3], VMA( 4 ), args[5], NULL, 0, NULL, 0, &trans, 1 ); } case CG_R_BUILDPOSE2: return re.BuildPose( args[1], VMA( 2 ), 2, VMA( 3 ), 2, VMA( 4 ), 2, VMA( 5 ), 2, VMA( 6 ), 2 ); case CG_R_BUILDPOSE3: return re.BuildPose( args[1], VMA( 2 ), 1, 0, 0, VMA( 3 ), 1, 0, 0, VMA( 4 ), 1 ); case CG_R_LERPTAGFROMPOSE: return re.LerpTagFromPose( VMA( 1 ), args[2], args[3], VMA( 4 ) ); case CG_R_ADDREFENTITYTOSCENE: re.AddRefEntityToScene( VMA(1) ); return 0; case CG_R_ADDPOLYTOSCENE: re.AddPolyToScene( args[1], args[2], VMA(3), 1 ); return 0; case CG_R_ADDPOLYSTOSCENE: re.AddPolyToScene( args[1], args[2], VMA(3), args[4] ); return 0; case CG_R_MENUBEGINSURF: re.MenuBeginSurf( args[1] ); return 0; case CG_R_MENUENDSURF: re.MenuEndSurf(); return 0; case CG_R_LIGHTFORPOINT: return re.LightForPoint( VMA(1), VMA(2), VMA(3), VMA(4) ); case CG_R_ADDLIGHTTOSCENE: re.AddLightToScene( VMA(1), VMF(2), VMF(3), VMF(4), VMF(5) ); return 0; case CG_R_ADDADDITIVELIGHTTOSCENE: re.AddAdditiveLightToScene( VMA(1), VMF(2), VMF(3), VMF(4), VMF(5) ); return 0; case CG_R_RENDERSCENE: re.RenderScene( VMA(1) ); return 0; case CG_R_SETCOLOR: re.SetColor( VMA(1) ); return 0; case CG_R_DRAWSTRETCHPIC: re.DrawStretchPic( VMF(1), VMF(2), VMF(3), VMF(4), NULL, VMF(5), VMF(6), VMF(7), VMF(8), args[9] ); return 0; case CG_R_SHAPECREATE: { curve_t * c = VMA(1); int n = args[3]; int i; for ( i=0; i<n; i++ ) { c->pts = (vec2_t*)VM_ArgPtr((intptr_t)c->pts); c->uvs = (vec2_t*)VM_ArgPtr((intptr_t)c->uvs); c->colors = (vec4_t*)VM_ArgPtr((intptr_t)c->colors); c->indices = (short*)VM_ArgPtr((intptr_t)c->indices ); } return re.ShapeCreate( c, VMA( 2 ), n ); } case CG_R_SHAPEDRAW: re.ShapeDraw( args[1], args[2], VMA( 3 ) ); return 0; case CG_R_RENDERTEXT: CL_RenderText( VMA(1), VMF(2), VMA(3), VMA(4), args[5], (args[6])>>16, args[6]&0xFFFF, args[7], args[8], 0, args[9], VMA(10) ); return 0; case CG_R_GETFONT: memcpy( VMA(3), re.GetFontFromFontSet( args[1], VMF(2) ), sizeof(fontInfo_t) ); return 0; case CG_R_ROUNDRECT: SCR_FillRect( VMF(1), VMF(2), VMF(3), VMF(4), VMA(5), args[6] ); return 0; case CG_R_MODELBOUNDS: re.ModelBounds( args[1], VMA(2), VMA(3) ); return 0; case CG_R_LERPTAG: return re.LerpTag( VMA(1), args[2], args[3], args[4], VMF(5), VMA(6) ); case CG_GETGLCONFIG: CL_GetGlconfig( VMA(1) ); return 0; case CG_GETGAMESTATE: CL_GetGameState( VMA(1) ); return 0; case CG_GETCURRENTSNAPSHOTNUMBER: CL_GetCurrentSnapshotNumber( VMA(1), VMA(2) ); return 0; case CG_GETSNAPSHOT: return CL_GetSnapshot( args[1], VMA(2) ); case CG_GETSERVERCOMMAND: return CL_GetServerCommand( args[1] ); case CG_GETCURRENTCMDNUMBER: return CL_GetCurrentCmdNumber(); case CG_GETUSERCMD: return CL_GetUserCmd( args[1], VMA(2) ); case CG_SETUSERCMDVALUE: CL_SetUserCmdValue( args[1], VMF(2) ); return 0; case CG_MEMORY_REMAINING: return Hunk_MemoryRemaining(); case CG_KEY_ISDOWN: return Key_IsDown( args[1] ); case CG_KEY_GETCATCHER: return Key_GetCatcher(); case CG_KEY_SETCATCHER: Key_SetCatcher( args[1] ); return 0; case CG_KEY_GETKEY: return Key_GetKey( VMA(1) ); case CG_MEMSET: Com_Memset( VMA(1), args[2], args[3] ); return 0; case CG_MEMCPY: Com_Memcpy( VMA(1), VMA(2), args[3] ); return 0; case CG_STRNCPY: strncpy( VMA(1), VMA(2), args[3] ); return args[1]; case CG_SIN: return FloatAsInt( sin( VMF(1) ) ); case CG_COS: return FloatAsInt( cos( VMF(1) ) ); case CG_ATAN2: return FloatAsInt( atan2( VMF(1), VMF(2) ) ); case CG_SQRT: return FloatAsInt( sqrt( VMF(1) ) ); case CG_FLOOR: return FloatAsInt( floor( VMF(1) ) ); case CG_CEIL: return FloatAsInt( ceil( VMF(1) ) ); case CG_ACOS: return FloatAsInt( Q_acos( VMF(1) ) ); case CG_FMOD: return FloatAsInt( fmod( VMF(1),VMF(2) ) ); case CG_POW: return FloatAsInt( pow( VMF(1),VMF(2) ) ); case CG_ATAN: return FloatAsInt( atan( VMF(1) ) ); case CG_TAN: return FloatAsInt( tan( VMF(1)) ); case CG_PC_ADD_GLOBAL_DEFINE: return botlib_export->PC_AddGlobalDefine( VMA(1) ); case CG_PC_LOAD_SOURCE: return botlib_export->PC_LoadSourceHandle( VMA(1) ); case CG_PC_FREE_SOURCE: return botlib_export->PC_FreeSourceHandle( args[1] ); case CG_PC_READ_TOKEN: return botlib_export->PC_ReadTokenHandle( args[1], VMA(2) ); case CG_PC_SOURCE_FILE_AND_LINE: return botlib_export->PC_SourceFileAndLine( args[1], VMA(2), VMA(3) ); case CG_S_STOPBACKGROUNDTRACK: S_StopBackgroundTrack(); return 0; case CG_REAL_TIME: return Com_RealTime( VMA(1) ); case CG_SNAPVECTOR: Sys_SnapVector( VMA(1) ); return 0; case CG_UPDATEGAMESTATE: return CL_UpdateGameState( VMA(1) ); case CG_CIN_PLAYCINEMATIC: return CIN_PlayCinematic(VMA(1), args[2], args[3], args[4], args[5], args[6]); case CG_CIN_STOPCINEMATIC: return CIN_StopCinematic(args[1]); case CG_CIN_RUNCINEMATIC: return CIN_RunCinematic(args[1]); case CG_CIN_DRAWCINEMATIC: CIN_DrawCinematic(args[1]); return 0; case CG_CIN_SETEXTENTS: CIN_SetExtents(args[1], args[2], args[3], args[4], args[5]); return 0; case CG_R_REMAP_SHADER: //ToDo: remove this trap return 0; /* case CG_LOADCAMERA: return loadCamera(VMA(1)); case CG_STARTCAMERA: startCamera(args[1]); return 0; case CG_GETCAMERAINFO: return getCameraInfo(args[1], VMA(2), VMA(3)); */ case CG_GET_ENTITY_TOKEN: return re.GetEntityToken( VMA(1), args[2] ); case CG_R_INPVS: return re.inPVS( VMA(1), VMA(2) ); case CG_Q_rand: return Rand_NextUInt32( &cl.db.rand ); case CG_SQL_LOADDB: { char * buffer; int length; length = FS_ReadFile( VMA(1), &buffer ); if ( length > 0 ) { sql_exec( &cl.db, buffer ); FS_FreeFile(buffer); } return 0; } break; case CG_SQL_EXEC: return sql_exec( &cl.db, VMA(1) ); case CG_SQL_PREPARE: return sql_prepare( &cl.db, VMA(1) ) != 0; case CG_SQL_BIND: return sql_bind( &cl.db, args ); case CG_SQL_BINDTEXT: return sql_bindtext( &cl.db, args[1], VMA(2) ); case CG_SQL_BINDINT: return sql_bindint( &cl.db, args[1], args[2] ); case CG_SQL_BINDARGS: { int i,n = Cmd_Argc(); for ( i=1; i<n; i++ ) { if ( !sql_bindtext( &cl.db, i, Cmd_Argv( i ) ) ) return 0; } } return 1; case CG_SQL_STEP: return sql_step( &cl.db ); case CG_SQL_COLUMNCOUNT: return sql_columncount( &cl.db ); case CG_SQL_COLUMNASTEXT: Q_strncpyz( VMA(1), sql_columnastext( &cl.db, args[3] ), args[2] ); break; case CG_SQL_COLUMNASINT: return sql_columnasint( &cl.db, args[1] ); case CG_SQL_COLUMNNAME: Q_strncpyz( VMA(1), sql_columnname( &cl.db, args[3] ), args[2] ); break; case CG_SQL_DONE: return sql_done( &cl.db ); case CG_SQL_COMPILE: return sql_compile( &cl.db, VMA(1) ); case CG_SQL_RUN: { char * buffer = VMA(1); int size = args[2]; int id = args[3]; int i; formatInfo_t * stmt = (formatInfo_t*)cl.db.stmts_byindex[ id ]; if ( stmt ) { sqlData_t params[ 3 ]; const char * r; for ( i=0; i<3; i++ ) { params[ i ].format = INTEGER; params[ i ].payload.integer = args[ 4+i ]; } r = sql_eval( &cl.db, stmt->print, 0, 0, 0, 0, params, 0 ).string; Q_strncpyz( buffer, r, size ); } else { buffer[ 0 ] = '\0'; } } break; default: assert(0); // bk010102 Com_Error( ERR_DROP, "Bad cgame system trap: %i", args[0] ); } return 0; }