Пример #1
0
void R_CheckMP3s( const char *psDir )
{
//	Com_Printf(va("Scanning Dir: %s\n",psDir));
	Com_Printf(".");	// stops useful info scrolling off screen

	char	**sysFiles, **dirFiles;
	int		numSysFiles, i, numdirs;

	dirFiles = FS_ListFiles( psDir, "/", &numdirs);
	if (numdirs > 2)
	{
		for (i=2;i<numdirs;i++)
		{
			char	sDirName[MAX_QPATH];
			sprintf(sDirName, "%s\\%s", psDir, dirFiles[i]);
			R_CheckMP3s(sDirName);
		}
	}

	sysFiles = FS_ListFiles( psDir, ".mp3", &numSysFiles );
	for(i=0; i<numSysFiles; i++)
	{
		char	sFilename[MAX_QPATH];
		sprintf(sFilename,"%s\\%s", psDir, sysFiles[i]);		
			
		Com_Printf("%sFound file: %s",!i?"\n":"",sFilename);

		iFilesFound++;

		// read it in...
		//
		byte *pbData = NULL;
		int iSize = FS_ReadFile( sFilename, (void **)&pbData);

		if (pbData)
		{
			id3v1_1* pTAG;

			// do NOT check 'qbForceRescan' here as an opt, because we need to actually fill in 'pTAG' if there is one...
			//
			qboolean qbTagNeedsUpdating = (/* qbForceRescan || */ !MP3_ReadSpecialTagInfo(pbData, iSize, &pTAG))?qtrue:qfalse;

			if (pTAG == NULL || qbTagNeedsUpdating || qbForceRescan)
			{
				Com_Printf(" ( Updating )\n");

				// I need to scan this file to get the volume...
				//
				// For EF1 I used a temp sfx_t struct, but I can't do that now with this new alloc scheme,
				//	I have to ask for it legally, so I'll keep re-using one, and restoring it's name after use.
				//	(slightly dodgy, but works ok if no-one else changes stuff)
				//
				//sfx_t SFX = {0};
				extern sfx_t *S_FindName( const char *name );
				//
				static sfx_t *pSFX = NULL;
				const char sReservedSFXEntrynameForMP3[] = "reserved_for_mp3";	// ( strlen() < MAX_QPATH )

				if (pSFX == NULL)	// once only
				{
					pSFX = S_FindName(sReservedSFXEntrynameForMP3);	// always returns, else ERR_FATAL					
				}

				if (MP3_IsValid(sFilename,pbData, iSize, qbForceStereo))
				{
					wavinfo_t info;

					int iRawPCMDataSize = MP3_GetUnpackedSize(sFilename, pbData, iSize, qtrue, qbForceStereo);

					if (iRawPCMDataSize)	// should always be true, unless file is f****d, in which case, stop this conversion process
					{
						float fMaxVol = 128;	// any old default
						int iActualUnpackedSize = iRawPCMDataSize;	// default, override later if not doing music

						if (!qbForceStereo)	// no point for stereo files, which are for music and therefore no lip-sync
						{
							byte *pbUnpackBuffer = (byte *) Z_Malloc ( iRawPCMDataSize+10, TAG_TEMP_WORKSPACE );	// won't return if fails

							iActualUnpackedSize = MP3_UnpackRawPCM( sFilename, pbData, iSize, pbUnpackBuffer );
							if (iActualUnpackedSize != iRawPCMDataSize)
							{
								Com_Error(ERR_DROP, "******* Whoah! MP3 %s unpacked to %d bytes, but size calc said %d!\n",sFilename,iActualUnpackedSize,iRawPCMDataSize);
							}
						
							// fake up a WAV structure so I can use the other post-load sound code such as volume calc for lip-synching
							//
							MP3_FakeUpWAVInfo( sFilename, pbData, iSize, iActualUnpackedSize,
												// these params are all references...
												info.format, info.rate, info.width, info.channels, info.samples, info.dataofs
												);

							extern void S_LoadSound_Finalize(wavinfo_t	*info, sfx_t *sfx, byte *data);

							S_LoadSound_Finalize(&info, pSFX, pbUnpackBuffer);	// all this just for lipsynch. Oh well.

							fMaxVol = pSFX->fVolRange;

							// free sfx->data...
							//
							{
								// Hunk_FreeTempMemory( SFX.data );	// this will have been allocated inside S_LoadSound_Finalise()
								//
								// I want a big thankyou from the Mac guys for providing this define... :-) -ste
								//
								// #ifndef INT_MIN
								// #define INT_MIN     (-2147483647 - 1) /* minimum (signed) int value */
								// #endif
								//
								pSFX->iLastTimeUsed = INT_MIN;		// force this to be oldest sound file, therefore disposable...
								pSFX->bInMemory = qtrue;
								SND_FreeOldestSound();		// ... and do the disposal

								// now set our temp SFX struct back to default name so nothing else accidentally uses it...
								//
								strcpy(pSFX->sSoundName, sReservedSFXEntrynameForMP3);
								pSFX->bDefaultSound = qfalse;								
							}

							// other stuff...
							//
							Z_Free(pbUnpackBuffer);
						}

						// well, time to update the file now...
						//
						fileHandle_t f = FS_FOpenFileWrite( sFilename );
						if (f)
						{
							// write the file back out, but omitting the tag if there was one...
							//
							int iWritten = FS_Write(pbData, iSize-(pTAG?sizeof(*pTAG):0), f);

							if (iWritten)
							{
								// make up a new tag if we didn't find one in the original file...
								//
								id3v1_1 TAG;
								if (!pTAG)
								{
									pTAG = &TAG;
									memset(&TAG,0,sizeof(TAG));
									strncpy(pTAG->id,"TAG",3);
								}

								strncpy(pTAG->title,	Filename_WithoutPath(Filename_WithoutExt(sFilename)), sizeof(pTAG->title));
								strncpy(pTAG->artist,	"Raven Software",						sizeof(pTAG->artist)	);
								strncpy(pTAG->year,		"2001",									sizeof(pTAG->year)		);
								strncpy(pTAG->comment,	va("%s %g",sKEY_MAXVOL,fMaxVol),		sizeof(pTAG->comment)	);
								strncpy(pTAG->album,	va("%s %d",sKEY_UNCOMP,iActualUnpackedSize),sizeof(pTAG->album)	);
								
								if (FS_Write( pTAG, sizeof(*pTAG), f ))	// NZ = success
								{
									iFilesUpdated++;
								}
								else
								{
									Com_Printf("*********** Failed write to file!\n");
									iErrors++;
								}
							}
							else
							{
								Com_Printf("*********** Failed write to file!\n");
								iErrors++;
							}
							FS_FCloseFile( f );
						}
						else
						{
							Com_Printf("*********** Failed to re-open for write!\n");
							iErrors++;
						}					
					}
					else
					{
						Com_Error(ERR_DROP, "******* This MP3 should be deleted: %s\n",sFilename);
					}
				}
				else
				{
					Com_Printf("*********** File was not a valid MP3!\n");
					iErrors++;
				}
			}
			else
			{
				Com_Printf(" ( OK )\n");
			}

			FS_FreeFile( pbData );
		}
	}
	FS_FreeFileList( sysFiles );
	FS_FreeFileList( dirFiles );
}
Пример #2
0
int CL_CgameSystemCalls( int *args ) {
#ifndef __NO_JK2
    if( Cvar_VariableIntegerValue("com_jk2") )
    {
        args[0] = (int)CL_ConvertJK2SysCall((cgameJK2Import_t)args[0]);
    }
#endif
    switch( args[0] ) {
    case CG_PRINT:
        Com_Printf( "%s", VMA(1) );
        return 0;
    case CG_ERROR:
        Com_Error( ERR_DROP, S_COLOR_RED"%s", 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_Set( (const char *) VMA(1), (const char *) VMA(2) );
        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_FS_FOPENFILE:
        return FS_FOpenFileByMode( (const char *) VMA(1), (int *) VMA(2), (fsMode_t) 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( (const char *) VMA(1) );
        return 0;
    case CG_ADDCOMMAND:
        CL_AddCgameCommand( (const char *) VMA(1) );
        return 0;
    case CG_SENDCLIENTCOMMAND:
        CL_AddReliableCommand( (const char *) 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!
        SCR_UpdateScreen();
        return 0;

#ifdef _XBOX
    case CG_RMG_INIT:
    case CG_CM_REGISTER_TERRAIN:
    case CG_RE_INIT_RENDERER_TERRAIN:
        Com_Error( ERR_FATAL, "ERROR: Terrain unsupported on Xbox.\n" );
#else
    case CG_RMG_INIT:
        /*
        if (!com_sv_running->integer)
        {	// don't do this if we are connected locally
        	if (!TheRandomMissionManager)
        	{
        		TheRandomMissionManager = new CRMManager;
        	}
        	TheRandomMissionManager->SetLandScape( cmg.landScapes[args[1]] );
        	TheRandomMissionManager->LoadMission(qfalse);
        	TheRandomMissionManager->SpawnMission(qfalse);
        	cmg.landScapes[args[1]]->UpdatePatches();
        }
        */ //this is SP.. I guess we're always the client and server.
//		cl.mRMGChecksum = cm.landScapes[args[1]]->get_rand_seed();
        RM_CreateRandomModels(args[1], (const char *)VMA(2));
        //cmg.landScapes[args[1]]->rand_seed(cl.mRMGChecksum);		// restore it, in case we do a vid restart
        cmg.landScape->rand_seed(cmg.landScape->get_rand_seed());
//		TheRandomMissionManager->CreateMap();
        return 0;
    case CG_CM_REGISTER_TERRAIN:
        return CM_RegisterTerrain((const char *)VMA(1), false)->GetTerrainId();

    case CG_RE_INIT_RENDERER_TERRAIN:
        RE_InitRendererTerrain((const char *)VMA(1));
        return 0;
#endif	// _XBOX

    case CG_CM_LOADMAP:
#ifdef _XBOX
        CL_CM_LoadMap( (const char *) VMA(1) );
#else
        CL_CM_LoadMap( (const char *) VMA(1), args[2] );
#endif
        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) );//, (int) VMA(3) );
    case CG_CM_POINTCONTENTS:
        return CM_PointContents( (float *)VMA(1), args[2] );
    case CG_CM_TRANSFORMEDPOINTCONTENTS:
        return CM_TransformedPointContents( (const float *) VMA(1), 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), (const float *) VMA(4), (const float *) VMA(5), args[6], args[7] );
        return 0;
    case CG_CM_TRANSFORMEDBOXTRACE:
        CM_TransformedBoxTrace( (trace_t *) VMA(1), (const float *) VMA(2), (const float *) VMA(3), (const float *) VMA(4), (const float *) VMA(5), args[6], args[7], (const float *) VMA(8), (const float *) VMA(9) );
        return 0;
    case CG_CM_MARKFRAGMENTS:
        return re.MarkFragments( args[1], (float(*)[3]) VMA(2), (const float *) VMA(3), args[4], (float *) VMA(5), args[6], (markFragment_t *) VMA(7) );
    case CG_CM_SNAPPVS:
        CM_SnapPVS((float(*))VMA(1),(byte *) VMA(2));
        return 0;
    case CG_S_STOPSOUNDS:
        S_StopSounds( );
        return 0;

    case CG_S_STARTSOUND:
        // stops an ERR_DROP internally if called illegally from game side, but note that it also gets here
        //	legally during level start where normally the internal s_soundStarted check would return. So ok to hit this.
        if (!cls.cgameStarted) {
            return 0;
        }
        S_StartSound( (float *) VMA(1), args[2], (soundChannel_t)args[3], args[4] );
        return 0;
    case CG_S_UPDATEAMBIENTSET:
        // stops an ERR_DROP internally if called illegally from game side, but note that it also gets here
        //	legally during level start where normally the internal s_soundStarted check would return. So ok to hit this.
        if (!cls.cgameStarted) {
            return 0;
        }
        S_UpdateAmbientSet( (const char *) VMA(1), (float *) VMA(2) );
        return 0;
    case CG_S_ADDLOCALSET:
        return S_AddLocalSet( (const char *) VMA(1), (float *) VMA(2), (float *) VMA(3), args[4], args[5] );
    case CG_AS_PARSESETS:
        AS_ParseSets();
        return 0;
    case CG_AS_ADDENTRY:
        AS_AddPrecacheEntry( (const char *) VMA(1) );
        return 0;
    case CG_AS_GETBMODELSOUND:
        return AS_GetBModelSound( (const char *) VMA(1), args[2] );
    case CG_S_STARTLOCALSOUND:
        // stops an ERR_DROP internally if called illegally from game side, but note that it also gets here
        //	legally during level start where normally the internal s_soundStarted check would return. So ok to hit this.
        if (!cls.cgameStarted) {
            return 0;
        }
        S_StartLocalSound( args[1], args[2] );
        return 0;
    case CG_S_CLEARLOOPINGSOUNDS:
        S_ClearLoopingSounds();
        return 0;
    case CG_S_ADDLOOPINGSOUND:
        // stops an ERR_DROP internally if called illegally from game side, but note that it also gets here
        //	legally during level start where normally the internal s_soundStarted check would return. So ok to hit this.
        if (!cls.cgameStarted) {
            return 0;
        }
        S_AddLoopingSound( args[1], (const float *) VMA(2), (const float *) VMA(3), args[4], (soundChannel_t)args[5] );
        return 0;
    case CG_S_UPDATEENTITYPOSITION:
        S_UpdateEntityPosition( args[1], (const float *) VMA(2) );
        return 0;
    case CG_S_RESPATIALIZE:
        S_Respatialize( args[1], (const float *) VMA(2), (float(*)[3]) VMA(3), args[4] );
        return 0;
    case CG_S_REGISTERSOUND:
        return S_RegisterSound( (const char *) VMA(1) );
    case CG_S_STARTBACKGROUNDTRACK:
        S_StartBackgroundTrack( (const char *) VMA(1), (const char *) VMA(2), args[3]);
        return 0;
    case CG_S_GETSAMPLELENGTH:
        return S_GetSampleLengthInMilliSeconds(  args[1]);
    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:
        return re.RegisterFont( (const char *) VMA(1) );
    case CG_R_FONTSTRLENPIXELS:
        return re.Font_StrLenPixels( (const char *) VMA(1), args[2], VMF(3) );
    case CG_R_FONTSTRLENCHARS:
        return re.Font_StrLenChars( (const char *) VMA(1) );
    case CG_R_FONTHEIGHTPIXELS:
        return re.Font_HeightPixels( args[1], VMF(2) );
    case CG_R_FONTDRAWSTRING:
        re.Font_DrawString(args[1],args[2], (const char *) VMA(3), (float*)args[4], args[5], args[6], VMF(7));
        return 0;
    case CG_LANGUAGE_ISASIAN:
        return re.Language_IsAsian();
    case CG_LANGUAGE_USESSPACES:
        return re.Language_UsesSpaces();
    case CG_ANYLANGUAGE_READFROMSTRING:
        return re.AnyLanguage_ReadCharFromString( (char *) VMA(1), (int *) VMA(2), (qboolean *) VMA(3) );
    case CG_ANYLANGUAGE_READFROMSTRING2:
        return re.AnyLanguage_ReadCharFromString2( (char **) VMA(1), (qboolean *) VMA(3) );
    case CG_R_SETREFRACTIONPROP:
        tr_distortionAlpha = VMF(1);
        tr_distortionStretch = VMF(2);
        tr_distortionPrePost = (qboolean)args[3];
        tr_distortionNegate = (qboolean)args[4];
        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_INPVS:
        return R_inPVS((float *) VMA(1), (float *) VMA(2));

    case CG_R_GETLIGHTING:
        return re.GetLighting( (const float * ) VMA(1), (float *) VMA(2), (float *) VMA(3), (float *) VMA(4) );
    case CG_R_ADDPOLYTOSCENE:
        re.AddPolyToScene( args[1], args[2], (const polyVert_t *) VMA(3) );
        return 0;
    case CG_R_ADDLIGHTTOSCENE:
#ifdef VV_LIGHTING
        VVLightMan.RE_AddLightToScene ( (const float *) VMA(1), VMF(2), VMF(3), VMF(4), VMF(5) );
#else
        re.AddLightToScene( (const float *) VMA(1), VMF(2), VMF(3), VMF(4), VMF(5) );
#endif
        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_DRAWSTRETCHPIC:
        re.DrawStretchPic( VMF(1), VMF(2), VMF(3), VMF(4), VMF(5), VMF(6), VMF(7), VMF(8), args[9] );
        return 0;
    // The below was commented out for whatever reason... /me shrugs --eez
    case CG_R_DRAWSCREENSHOT:
        re.DrawStretchRaw( VMF(1), VMF(2), VMF(3), VMF(4), SG_SCR_WIDTH, SG_SCR_HEIGHT, SCR_GetScreenshot(0), 0, qtrue);
        return 0;
    case CG_R_MODELBOUNDS:
        re.ModelBounds( args[1], (float *) VMA(2), (float *) VMA(3) );
        return 0;
    case CG_R_LERPTAG:
        re.LerpTag( (orientation_t *) VMA(1), args[2], args[3], args[4], VMF(5), (const char *) VMA(6) );
        return 0;
    case CG_R_DRAWROTATEPIC:
        re.DrawRotatePic( VMF(1), VMF(2), VMF(3), VMF(4), VMF(5), VMF(6), VMF(7), VMF(8), VMF(9), args[10] );
        return 0;
    case CG_R_DRAWROTATEPIC2:
        re.DrawRotatePic2( VMF(1), VMF(2), VMF(3), VMF(4), VMF(5), VMF(6), VMF(7), VMF(8), VMF(9), args[10] );
        return 0;
    case CG_R_SETRANGEFOG:
        if (tr.rangedFog <= 0.0f)
        {
            g_oldRangedFog = tr.rangedFog;
        }
        tr.rangedFog = VMF(1);
        if (tr.rangedFog == 0.0f && g_oldRangedFog)
        {   //restore to previous state if applicable
            tr.rangedFog = g_oldRangedFog;
        }
        return 0;
    case CG_R_LA_GOGGLES:
        re.LAGoggles();
        return 0;
    case CG_R_SCISSOR:
        re.Scissor( VMF(1), VMF(2), VMF(3), VMF(4));
        return 0;
    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_GETDEFAULTSTATE:
        return CL_GetDefaultState(args[1], (entityState_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_s *) VMA(2) );
    case CG_SETUSERCMDVALUE:
        CL_SetUserCmdValue( args[1], VMF(2), VMF(3), VMF(4) );
        return 0;
    case CG_SETUSERCMDANGLES:
        CL_SetUserCmdAngles( VMF(1), VMF(2), VMF(3) );
        return 0;
    case COM_SETORGANGLES:
        Com_SetOrgAngles((float *)VMA(1),(float *)VMA(2));
        return 0;
    /*
    Ghoul2 Insert Start
    */

    case CG_G2_LISTSURFACES:
        G2API_ListSurfaces( (CGhoul2Info *) VMA(1) );
        return 0;

    case CG_G2_LISTBONES:
        G2API_ListBones( (CGhoul2Info *) VMA(1), args[2]);
        return 0;

    case CG_G2_HAVEWEGHOULMODELS:
        return G2API_HaveWeGhoul2Models( *((CGhoul2Info_v *)VMA(1)) );

    case CG_G2_SETMODELS:
        G2API_SetGhoul2ModelIndexes( *((CGhoul2Info_v *)VMA(1)),(qhandle_t *)VMA(2),(qhandle_t *)VMA(3));
        return 0;

    /*
    Ghoul2 Insert End
    */

    case CG_R_GET_LIGHT_STYLE:
        re.GetLightStyle(args[1], (byte*) VMA(2) );
        return 0;
    case CG_R_SET_LIGHT_STYLE:
        re.SetLightStyle(args[1], args[2] );
        return 0;

    case CG_R_GET_BMODEL_VERTS:
        re.GetBModelVerts( args[1], (float (*)[3])VMA(2), (float *)VMA(3) );
        return 0;

    case CG_R_WORLD_EFFECT_COMMAND:
        re.WorldEffectCommand( (const char *) 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], (const char *) VMA(7));

    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_Z_MALLOC:
        return (int)Z_Malloc(args[1], (memtag_t) args[2], qfalse);

    case CG_Z_FREE:
        Z_Free((void *) VMA(1));
        return 0;

    case CG_UI_SETACTIVE_MENU:
        UI_SetActiveMenu((const char *) VMA(1),NULL);
        return 0;

    case CG_UI_MENU_OPENBYNAME:
        Menus_OpenByName((const char *) VMA(1));
        return 0;

    case CG_UI_MENU_RESET:
        Menu_Reset();
        return 0;

    case CG_UI_MENU_NEW:
        Menu_New((char *) VMA(1));
        return 0;

    case CG_UI_PARSE_INT:
        PC_ParseInt((int *) VMA(1));
        return 0;

    case CG_UI_PARSE_STRING:
        PC_ParseString((const char **) VMA(1));
        return 0;

    case CG_UI_PARSE_FLOAT:
        PC_ParseFloat((float *) VMA(1));
        return 0;

    case CG_UI_STARTPARSESESSION:
        return(PC_StartParseSession((char *) VMA(1),(char **) VMA(2)));

    case CG_UI_ENDPARSESESSION:
        PC_EndParseSession((char *) VMA(1));
        return 0;

    case CG_UI_PARSEEXT:
        char **holdPtr;

        holdPtr = (char **) VMA(1);

        if(!holdPtr)
        {
            Com_Error(ERR_FATAL, "CG_UI_PARSEEXT: NULL holdPtr");
        }

        *holdPtr = PC_ParseExt();
        return 0;

    case CG_UI_MENUCLOSE_ALL:
        Menus_CloseAll();
        return 0;

    case CG_UI_MENUPAINT_ALL:
        Menu_PaintAll();
        return 0;

    case CG_UI_STRING_INIT:
        String_Init();
        return 0;

    case CG_UI_GETMENUINFO:
        menuDef_t *menu;
        int		*xPos,*yPos,*w,*h,result;
#ifndef __NO_JK2
        if(!Cvar_VariableIntegerValue("com_jk2"))
        {
#endif

            menu = Menus_FindByName((char *) VMA(1));	// Get menu
            if (menu)
            {
                xPos = (int *) VMA(2);
                *xPos = (int) menu->window.rect.x;
                yPos = (int *) VMA(3);
                *yPos = (int) menu->window.rect.y;
                w = (int *) VMA(4);
                *w = (int) menu->window.rect.w;
                h = (int *) VMA(5);
                *h = (int) menu->window.rect.h;
                result = qtrue;
            }
            else
            {
                result = qfalse;
            }

            return result;
#ifndef __NO_JK2
        }
        else
        {
            menu = Menus_FindByName((char *) VMA(1));	// Get menu
            if (menu)
            {
                xPos = (int *) VMA(2);
                *xPos = (int) menu->window.rect.x;
                yPos = (int *) VMA(3);
                *yPos = (int) menu->window.rect.y;
                result = qtrue;
            }
            else
            {
                result = qfalse;
            }

            return result;
        }
#endif
        break;

    case CG_UI_GETITEMTEXT:
        itemDef_t *item;
        menu = Menus_FindByName((char *) VMA(1));	// Get menu

        if (menu)
        {
            item = (itemDef_s *) Menu_FindItemByName((menuDef_t *) menu, (char *) VMA(2));
            if (item)
            {
                Q_strncpyz( (char *) VMA(3), item->text, 256 );
                result = qtrue;
            }
            else
            {
                result = qfalse;
            }
        }
        else
        {
            result = qfalse;
        }

        return result;

    case CG_UI_GETITEMINFO:
        menu = Menus_FindByName((char *) VMA(1));	// Get menu

        if (menu)
        {
            qhandle_t *background;

            item = (itemDef_s *) Menu_FindItemByName((menuDef_t *) menu, (char *) VMA(2));
            if (item)
            {
                xPos = (int *) VMA(3);
                *xPos = (int) item->window.rect.x;
                yPos = (int *) VMA(4);
                *yPos = (int) item->window.rect.y;
                w = (int *) VMA(5);
                *w = (int) item->window.rect.w;
                h = (int *) VMA(6);
                *h = (int) item->window.rect.h;

                vec4_t *color;

                color = (vec4_t *) VMA(7);
                if (!color)
                {
                    return qfalse;
                }

                (*color)[0] = (float) item->window.foreColor[0];
                (*color)[1] = (float) item->window.foreColor[1];
                (*color)[2] = (float) item->window.foreColor[2];
                (*color)[3] = (float) item->window.foreColor[3];
                background = (qhandle_t *) VMA(8);
                if (!background)
                {
                    return qfalse;
                }
                *background = item->window.background;

                result = qtrue;
            }
            else
            {
                result = qfalse;
            }
        }
        else
        {
            result = qfalse;
        }

        return result;

    case CG_SP_GETSTRINGTEXTSTRING:
#ifndef __NO_JK2
    case CG_SP_GETSTRINGTEXT:
        if(Cvar_VariableIntegerValue("com_jk2"))
        {
            const char* text;

            assert(VMA(1));
            //		assert(VMA(2));	// can now pass in NULL to just query the size

            if (args[0] == CG_SP_GETSTRINGTEXT)
            {
                text = JK2SP_GetStringText( args[1] );
            }
            else
            {
                text = JK2SP_GetStringTextString( (const char *) VMA(1) );
            }

            if (VMA(2))	// only if dest buffer supplied...
            {
                if ( text[0] )
                {
                    Q_strncpyz( (char *) VMA(2), text, args[3] );
                }
                else
                {
                    Q_strncpyz( (char *) VMA(2), "??", args[3] );
                }
            }
            return strlen(text);
        }
        else
        {
#endif
            const char* text;

            assert(VMA(1));
            text = SE_GetString( (const char *) VMA(1) );

            if (VMA(2))	// only if dest buffer supplied...
            {
                if ( text[0] )
                {
                    Q_strncpyz( (char *) VMA(2), text, args[3] );
                }
                else
                {
                    Com_sprintf( (char *) VMA(2), args[3], "??%s", VMA(1) );
                }
            }
            return strlen(text);
#ifndef __NO_JK2
        }
    //break;

    case CG_SP_REGISTER:
        return JK2SP_Register( (const char *) VMA(1), args[2]?(SP_REGISTER_MENU|SP_REGISTER_REQUIRED):SP_REGISTER_CLIENT );
#endif
    default:
        Com_Error( ERR_DROP, "Bad cgame system trap: %i", args[0] );
    }
    return 0;
}
Пример #3
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_SetSafe( 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_RemoveCommandSafe( VMA(1) );
        return 0;
    case CG_SENDCLIENTCOMMAND:
        CL_AddReliableCommand(VMA(1), qfalse);
        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));
        return 0;
    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:
        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(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;
}
Пример #4
0
static void SCR_CaptureVideo_Ogg_EndVideo(void)
{
	LOAD_FORMATSPECIFIC_OGG();
	ogg_page pg;
	ogg_packet pt;

	if(format->yuvi >= 0)
	{
		// send the previous (and last) frame
		while(format->lastnum-- > 0)
		{
			qtheora_encode_YUVin(&format->ts, &format->yuv[format->yuvi]);

			while(qtheora_encode_packetout(&format->ts, !format->lastnum, &pt))
				qogg_stream_packetin(&format->to, &pt);

			SCR_CaptureVideo_Ogg_Interleave();
		}
	}

	if(cls.capturevideo.soundrate)
	{
		qvorbis_analysis_wrote(&format->vd, 0);
		while(qvorbis_analysis_blockout(&format->vd, &format->vb) == 1)
		{
			qvorbis_analysis(&format->vb, NULL);
			qvorbis_bitrate_addblock(&format->vb);
			while(qvorbis_bitrate_flushpacket(&format->vd, &pt))
				qogg_stream_packetin(&format->vo, &pt);
			SCR_CaptureVideo_Ogg_Interleave();
		}
	}

	SCR_CaptureVideo_Ogg_FlushInterleaving();

	while(qogg_stream_pageout(&format->to, &pg) > 0)
	{
		FS_Write(cls.capturevideo.videofile, pg.header, pg.header_len);
		FS_Write(cls.capturevideo.videofile, pg.body, pg.body_len);
	}

	if(cls.capturevideo.soundrate)
	{
		while(qogg_stream_pageout(&format->vo, &pg) > 0)
		{
			FS_Write(cls.capturevideo.videofile, pg.header, pg.header_len);
			FS_Write(cls.capturevideo.videofile, pg.body, pg.body_len);
		}
	}
		
	while (1) {
		int result = qogg_stream_flush (&format->to, &pg);
		if (result < 0)
			fprintf (stderr, "Internal Ogg library error.\n"); // TODO Host_Error
		if (result <= 0)
			break;
		FS_Write(cls.capturevideo.videofile, pg.header, pg.header_len);
		FS_Write(cls.capturevideo.videofile, pg.body, pg.body_len);
	}

	if(cls.capturevideo.soundrate)
	{
		while (1) {
			int result = qogg_stream_flush (&format->vo, &pg);
			if (result < 0)
				fprintf (stderr, "Internal Ogg library error.\n"); // TODO Host_Error
			if (result <= 0)
				break;
			FS_Write(cls.capturevideo.videofile, pg.header, pg.header_len);
			FS_Write(cls.capturevideo.videofile, pg.body, pg.body_len);
		}

		qogg_stream_clear(&format->vo);
		qvorbis_block_clear(&format->vb);
		qvorbis_dsp_clear(&format->vd);
	}

	qogg_stream_clear(&format->to);
	qtheora_clear(&format->ts);
	qvorbis_info_clear(&format->vi);

	Mem_Free(format->yuv[0].y);
	Mem_Free(format->yuv[0].u);
	Mem_Free(format->yuv[0].v);
	Mem_Free(format->yuv[1].y);
	Mem_Free(format->yuv[1].u);
	Mem_Free(format->yuv[1].v);
	Mem_Free(format);

	FS_Close(cls.capturevideo.videofile);
	cls.capturevideo.videofile = NULL;
}
Пример #5
0
/*
============
Cvar_WriteVariables

Appends lines containing "set variable value" for all variables
with the archive flag set that are not in a transient state.
============
*/
void Cvar_WriteVariables( fileHandle_t f )
{
    std::string text = Cvar::GetCvarConfigText();
    FS_Write(text.c_str(), text.size(), f);
}
Пример #6
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_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_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_Read( VMA( 1 ), args[2], args[3] );
		return 0;
	case CG_FS_WRITE:
		return FS_Write( VMA( 1 ), args[2], args[3] );
	case CG_FS_FCLOSEFILE:
		FS_FCloseFile( args[1] );
		return 0;
	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 ), 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], /*int capsule*/ qfalse );
		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_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_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;
//----(SA)	added
	case CG_S_STARTSOUNDEX:
		S_StartSoundEx( VMA( 1 ), args[2], args[3], args[4], args[5] );
		return 0;
//----(SA)	end
	case CG_S_STARTLOCALSOUND:
		S_StartLocalSound( args[1], args[2] );
		return 0;
	case CG_S_CLEARLOOPINGSOUNDS:
		S_ClearLoopingSounds(); // (SA) modified so no_pvs sounds can function
		// RF, if killall, then stop all sounds
		if ( args[1] == 1 ) {
			S_ClearSounds( qtrue, qfalse );
		} else if ( args[1] == 2 ) {
			S_ClearSounds( qtrue, qtrue );
		}
		return 0;
	case CG_S_ADDLOOPINGSOUND:
		// FIXME MrE: handling of looping sounds changed
		S_AddLoopingSound( args[1], VMA( 2 ), VMA( 3 ), args[4], args[5], args[6] );
		return 0;
// not in use
//	case CG_S_ADDREALLOOPINGSOUND:
//		S_AddLoopingSound( args[1], VMA(2), VMA(3), args[4], args[5], args[6] );
//		//S_AddRealLoopingSound( args[1], VMA(2), VMA(3), args[4], args[5] );
//		return 0;

//----(SA)	added
	case CG_S_STOPSTREAMINGSOUND:
		S_StopEntStreamingSound( args[1] );
		return 0;
//----(SA)	end

	case CG_S_STOPLOOPINGSOUND:
		// RF, not functional anymore, since we reverted to old looping code
		//S_StopLoopingSound( args[1] );
		return 0;
	case CG_S_UPDATEENTITYPOSITION:
		S_UpdateEntityPosition( args[1], VMA( 2 ) );
		return 0;
// Ridah, talking animations
	case CG_S_GETVOICEAMPLITUDE:
		return S_GetVoiceAmplitude( args[1] );
// done.
	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 ), qfalse );
#endif  ///// (SA) DOOMSOUND
	case CG_S_STARTBACKGROUNDTRACK:
		S_StartBackgroundTrack( VMA( 1 ), VMA( 2 ), args[3] );  //----(SA)	added fadeup time
		return 0;
	case CG_S_FADESTREAMINGSOUND:
		S_FadeStreamingSound( VMF( 1 ), args[2], args[3] ); //----(SA)	added music/all-streaming options
		return 0;
	case CG_S_STARTSTREAMINGSOUND:
		S_StartStreamingSound( VMA( 1 ), VMA( 2 ), args[3], args[4], args[5] );
		return 0;
	case CG_S_FADEALLSOUNDS:
		S_FadeAllSounds( VMF( 1 ), args[2] );   //----(SA)	added
		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 ) );

		//----(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:
		return re.RegisterShader( VMA( 1 ) );
	case CG_R_REGISTERFONT:
		re.RegisterFont( VMA( 1 ), args[2], VMA( 3 ) );
	case CG_R_REGISTERSHADERNOMIP:
		return re.RegisterShaderNoMip( VMA( 1 ) );
	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 ) );
		return 0;
		// Ridah
	case CG_R_ADDPOLYSTOSCENE:
		re.AddPolysToScene( args[1], args[2], VMA( 3 ), args[4] );
		return 0;
	case CG_RB_ZOMBIEFXADDNEWHIT:
		re.ZombieFXAddNewHit( args[1], VMA( 2 ), VMA( 3 ) );
		return 0;
		// done.
//	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 ), args[6] );
		return 0;
//	case CG_R_ADDADDITIVELIGHTTOSCENE:
//		re.AddAdditiveLightToScene( VMA(1), VMF(2), VMF(3), VMF(4), VMF(5) );
//		return 0;
	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_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_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_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] );    //----(SA)	modified	// NERVE - SMF - added fourth arg [cld]
		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:
		return (intptr_t)memset( VMA( 1 ), args[2], args[3] );
	case CG_MEMCPY:
		return (intptr_t)memcpy( VMA( 1 ), VMA( 2 ), args[3] );
	case CG_STRNCPY:
		return (intptr_t)strncpy( VMA( 1 ), VMA( 2 ), args[3] );
	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_SENDMOVESPEEDSTOGAME:
		SV_SendMoveSpeedsToGame( args[1], VMA( 2 ) );
		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_TESTPRINTINT:
		Com_Printf( "%s%i\n", VMA( 1 ), args[2] );
		return 0;
	case CG_TESTPRINTFLOAT:
		Com_Printf( "%s%f\n", VMA( 1 ), VMF( 2 ) );
		return 0;

	case CG_LOADCAMERA:
		return loadCamera( args[1], VMA( 2 ) );

	case CG_STARTCAMERA:
		if ( args[1] == 0 ) {  // CAM_PRIMARY
			cl.cameraMode = qtrue;  //----(SA)	added
		}
		startCamera( args[1], args[2] );
		return 0;

//----(SA)	added
	case CG_STOPCAMERA:
		if ( args[1] == 0 ) {  // CAM_PRIMARY
			cl.cameraMode = qfalse;
		}
//		stopCamera(args[1]);
		return 0;
//----(SA)	end

	case CG_GETCAMERAINFO:
		return getCameraInfo( args[1], args[2], VMA( 3 ), VMA( 4 ), VMA( 5 ) );

	case CG_GET_ENTITY_TOKEN:
		return re.GetEntityToken( VMA( 1 ), args[2] );

	case CG_INGAME_POPUP:
		if ( VMA( 1 ) && !Q_stricmp( VMA( 1 ), "briefing" ) ) {  //----(SA) added
			VM_Call( uivm, UI_SET_ACTIVE_MENU, UIMENU_BRIEFING );
			return 0;
		}

		if ( cls.state == CA_ACTIVE && !clc.demoplaying ) {
			// NERVE - SMF
			if ( VMA( 1 ) && !Q_stricmp( VMA( 1 ), "UIMENU_WM_PICKTEAM" ) ) {
				VM_Call( uivm, UI_SET_ACTIVE_MENU, UIMENU_WM_PICKTEAM );
			} else if ( VMA( 1 ) && !Q_stricmp( VMA( 1 ), "UIMENU_WM_PICKPLAYER" ) )    {
				VM_Call( uivm, UI_SET_ACTIVE_MENU, UIMENU_WM_PICKPLAYER );
			} else if ( VMA( 1 ) && !Q_stricmp( VMA( 1 ), "UIMENU_WM_QUICKMESSAGE" ) )    {
				VM_Call( uivm, UI_SET_ACTIVE_MENU, UIMENU_WM_QUICKMESSAGE );
			} else if ( VMA( 1 ) && !Q_stricmp( VMA( 1 ), "UIMENU_WM_LIMBO" ) )    {
				VM_Call( uivm, UI_SET_ACTIVE_MENU, UIMENU_WM_LIMBO );
			}
			// -NERVE - SMF
			else if ( VMA( 1 ) && !Q_stricmp( VMA( 1 ), "hbook1" ) ) {   //----(SA)
				VM_Call( uivm, UI_SET_ACTIVE_MENU, UIMENU_BOOK1 );
			} else if ( VMA( 1 ) && !Q_stricmp( VMA( 1 ), "hbook2" ) )    { //----(SA)
				VM_Call( uivm, UI_SET_ACTIVE_MENU, UIMENU_BOOK2 );
			} else if ( VMA( 1 ) && !Q_stricmp( VMA( 1 ), "hbook3" ) )    { //----(SA)
				VM_Call( uivm, UI_SET_ACTIVE_MENU, UIMENU_BOOK3 );
			} else if ( VMA( 1 ) && !Q_stricmp( VMA( 1 ), "pregame" ) )    { //----(SA) added
				VM_Call( uivm, UI_SET_ACTIVE_MENU, UIMENU_PREGAME );
			} else {
				VM_Call( uivm, UI_SET_ACTIVE_MENU, UIMENU_CLIPBOARD );
			}
		}
		return 0;

		// NERVE - SMF
	case CG_INGAME_CLOSEPOPUP:
		VM_Call( uivm, UI_KEY_EVENT, K_ESCAPE, qtrue );
		return 0;

	case CG_LIMBOCHAT:
		if ( VMA( 1 ) ) {
			CL_AddToLimboChat( VMA( 1 ) );
		}
		return 0;
		// - NERVE - SMF

	case CG_GETMODELINFO:
		return SV_GetModelInfo( args[1], VMA( 2 ), VMA( 3 ) );

	default:
		Com_Error( ERR_DROP, "Bad cgame system trap: %i", args[0] );
	}
	return 0;
}
Пример #7
0
/*********************************************************************
*
*       _WriteAt
*/
static int    _WriteAt (void * hFile, void *pBuffer, U32 Pos, U32 NumBytes) {
  _InitIfRequired();         // Perform automatic initialisation so that explicit call to FS_Init is not required
  FS_FSeek((FS_FILE*) hFile, Pos, FS_SEEK_SET);
  return FS_Write((FS_FILE*) hFile, pBuffer, NumBytes);
}
Пример #8
0
static size_t CL_cURL_CallbackWrite(void *buffer, size_t size, size_t nmemb,
	void *stream)
{
	FS_Write( buffer, size*nmemb, ((fileHandle_t*)stream)[0] );
	return size*nmemb;
}
Пример #9
0
void Cvar_WriteVariables( fileHandle_t f ) {
#if 0
	cvar_t	*var;
	char	buffer[1024];

	for (var = cvar_vars ; var ; var = var->next) {
		if( Q_stricmp( var->name, "cl_cdkey" ) == 0 ) {
			continue;
		}
		if( var->flags & CVAR_ARCHIVE ) {
			// write the latched value, even if it hasn't taken effect yet
			if ( var->latchedString ) {
				Com_sprintf (buffer, sizeof(buffer), "seta %s \"%s\"\n", var->name, var->latchedString);
			} else {
				Com_sprintf (buffer, sizeof(buffer), "seta %s \"%s\"\n", var->name, var->string);
			}
			FS_Printf (f, "%s", buffer);
		}
	}
#else
	cvar_t *var;
	char buffer[MAX_STRING_CHARS] = {0};
	int i=0, writeCount=0, totalCount=0, size=0;
	cvarSerialise_t *list = NULL, *listPtr = NULL;

	for ( var=cvar_vars; var; var=var->next ) {
		char *value = var->latchedString ? var->latchedString : var->string;
		if ( var->name && (var->flags & CVAR_ARCHIVE/*) && (Q_stricmp( var->resetString, value )*/ || (var->flags&CVAR_USER_CREATED)) ) {
			if ( strlen( var->name ) + strlen( var->latchedString ? var->latchedString : var->string ) + 9 >= sizeof( buffer ) )
				continue;
			writeCount++;
		}
		totalCount++;
	}

	// allocate the working space for sorting
	size = sizeof( cvarSerialise_t ) * writeCount;
	list = (cvarSerialise_t *)Z_Malloc( size );
	memset( list, 0, size );

	for ( var=cvar_vars, listPtr=list; var; var=var->next ) {
		char *value = var->latchedString ? var->latchedString : var->string;
		if ( var->name && (var->flags & CVAR_ARCHIVE/*) && (Q_stricmp( var->resetString, value )*/ || (var->flags&CVAR_USER_CREATED)) ) {
			if ( strlen( var->name ) + strlen( value ) + 9 >= sizeof( buffer ) ) {
				Com_Printf( S_COLOR_YELLOW "WARNING: value of variable \"%s\" too long to write to file\n", var->name );
				continue;
			}
			listPtr->name = var->name;
			listPtr->value = value;
			listPtr++;
		}
	}

	qsort( list, writeCount, sizeof( cvarSerialise_t ), cvarSort );

	for ( i=0, listPtr=list; i<writeCount; i++, listPtr++ ) {
		Com_sprintf( buffer, sizeof( buffer ), "seta %s \"%s\"\n", listPtr->name, listPtr->value );
		FS_Write( buffer, (int)strlen( buffer ), f );
	}

	Com_DPrintf( "Wrote %i/%i cvars to file\n", writeCount, totalCount );

	Z_Free( list );
	list = listPtr = NULL;
#endif
}
Пример #10
0
/*****************************************************************************
 * FUNCTION
 *  aud_trim_event_callback_hdlr
 * DESCRIPTION
 *  This function is used to handle the callback events from L1Audio.
 * PARAMETERS
 *
 * RETURNS
 *  void
 *****************************************************************************/
void aud_trim_event_callback_hdlr(ilm_struct *ilm_ptr)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    kal_uint8*                   buf_p = NULL;
    kal_uint32                   buf_len; /* 2 bytes per unit */
    kal_uint32                   len;     /* 1 byte per unit */
    kal_int32                    fs_result = FS_NO_ERROR;
    kal_int32                    med_result = MED_RES_OK;
    l4aud_trim_event_ind_struct* ind_p = (l4aud_trim_event_ind_struct*) ilm_ptr->local_para_ptr;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/

    /* Validate event */
    if ((ind_p->handle != (kal_uint32)g_trim_ctx.mhdl_handle_p) ||
        (g_trim_ctx.state != AUD_TRIM_STATE_TRIM))
    {
        _AUD_TRIM_TRACE(ind_p->handle, g_trim_ctx.mhdl_handle_p, g_trim_ctx.state);
        return;
    }

    _AUD_TRIM_TRACE(ind_p->handle, ind_p->event, -1);

    switch (ind_p->event)
    {
        case MEDIA_DATA_NOTIFICATION:
        {
            /* Get read buffer from L1Audio */
            g_trim_ctx.mhdl_handle_p->GetReadBuffer(g_trim_ctx.mhdl_handle_p, &buf_p, &buf_len);
            
            if (buf_len > 0)
            {
                ASSERT(buf_p != NULL);
                
                /* Write to file system */
                fs_result = FS_Write(g_trim_ctx.file_output,
                                     buf_p,
                                     buf_len,
                                     &len);
                _AUD_TRIM_TRACE(fs_result, buf_len, len);

                if (fs_result == FS_NO_ERROR)
                {
                    /* Update file offset */
                    g_trim_ctx.file_length += len;
                    
                    _AUD_TRIM_TRACE(g_trim_ctx.file_output, g_trim_ctx.file_length, -1);

                    /* Sleep MED for a moment such that MMI may have chance to cancel the trimming */
                    kal_sleep_task(2);
                    
                    /* Notify L1Audio how many bytes are read. L1audio will fire another MEDIA_DATA_NOTIFICATION
                     * event if there is more data to be trimmed.
                     */
                    g_trim_ctx.mhdl_handle_p->ReadDataDone(g_trim_ctx.mhdl_handle_p, buf_len);
                }
                else
                {
                    /* Stop the trimming */
                    _aud_trim_stop();

                    /* Notify MMI with failure reason */
                    switch (fs_result)
                    {
                        case FS_DISK_FULL:
                            med_result = MED_RES_DISC_FULL;
                            break;
                        case FS_MSDC_WRITE_SECTOR_ERROR:
                        case FS_MEDIA_CHANGED:
                            med_result = MED_RES_NO_DISC;
                            break;
                        default:
                            med_result = MED_RES_ERROR;
                            break;
                    }

                    _aud_trim_send_result( med_result);
                }
            }
            
            break;
        }
        case MEDIA_END:
            /* End of trimming */
            _aud_trim_send_result(MED_RES_END_OF_FILE);
            break;
        default:
            /* Something wrong? */
            _aud_trim_send_result(MED_RES_ERROR);
            break;
    }
}
Пример #11
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;
}
Пример #12
0
/*
====================
SV_GameSystemCalls

The module is making a system call
====================
*/
intptr_t SV_GameSystemCalls(intptr_t * args) {
	switch (args[0]) {
		case G_PRINT:
			Com_Printf("%s", (char *)VMA(1));
			return 0;
		case G_ERROR:
			Com_Error(ERR_DROP, "%s", (char *)VMA(1));
			return 0;
		case G_MILLISECONDS:
			return Sys_Milliseconds();
		case G_CVAR_REGISTER:
			Cvar_Register((vmCvar_t*)VMA(1), (char*)VMA(2), (char*)VMA(3), args[4]);
			return 0;
		case G_CVAR_UPDATE:
			Cvar_Update((vmCvar_t*)VMA(1));
			return 0;
		case G_CVAR_SET:
			Cvar_Set((const char *)VMA(1), (const char *)VMA(2));
			return 0;
		case G_CVAR_VARIABLE_INTEGER_VALUE:
			return Cvar_VariableIntegerValue((const char *)VMA(1));
		case G_CVAR_VARIABLE_STRING_BUFFER:
			Cvar_VariableStringBuffer((char *)VMA(1), (char*)VMA(2), args[3]);
			return 0;
		case G_CVAR_LATCHEDVARIABLESTRINGBUFFER:
			Cvar_LatchedVariableStringBuffer((char *)VMA(1), (char*)VMA(2), args[3]);
			return 0;
		case G_ARGC:
			return Cmd_Argc();
		case G_ARGV:
			Cmd_ArgvBuffer(args[1], (char*)VMA(2), args[3]);
			return 0;
		case G_SEND_CONSOLE_COMMAND:
			Cbuf_ExecuteText(args[1], (char *)VMA(2));
			return 0;
		case G_FS_FOPEN_FILE:
			return FS_FOpenFileByMode((char *)VMA(1), (fileHandle_t*)VMA(2), (fsMode_t)args[3]);
		case G_FS_READ:
			FS_Read2(VMA(1), args[2], args[3]);
			return 0;
		case G_FS_WRITE:
			return FS_Write(VMA(1), args[2], args[3]);
		case G_FS_RENAME:
			FS_Rename((char *)VMA(1), (char *)VMA(2));
			return 0;
		case G_FS_FCLOSE_FILE:
			FS_FCloseFile(args[1]);
			return 0;
		case G_FS_GETFILELIST:
			return FS_GetFileList((char *)VMA(1), (char *)VMA(2), (char*)VMA(3), args[4]);
		case G_LOCATE_GAME_DATA:
			SV_LocateGameData((sharedEntity_t*)VMA(1), args[2], args[3], (playerState_t*)VMA(4), args[5]);
			return 0;
		case G_DROP_CLIENT:
			SV_GameDropClient(args[1], (char*)VMA(2), args[3]);
			return 0;
		case G_SEND_SERVER_COMMAND:
			SV_GameSendServerCommand(args[1], (char*)VMA(2));
			return 0;
		case G_LINKENTITY:
			SV_LinkEntity((sharedEntity_t*)VMA(1));
			return 0;
		case G_UNLINKENTITY:
			SV_UnlinkEntity((sharedEntity_t*)VMA(1));
			return 0;
		case G_ENTITIES_IN_BOX:
			return SV_AreaEntities((float*)VMA(1), (float*)VMA(2), (int*)VMA(3), args[4]);
		case G_ENTITY_CONTACT:
			return SV_EntityContact((float*)VMA(1), (float*)VMA(2), (sharedEntity_t*)VMA(3), TT_AABB);
		case G_ENTITY_CONTACTCAPSULE:
			return SV_EntityContact((float*)VMA(1), (float*)VMA(2), (sharedEntity_t*)VMA(3), TT_CAPSULE);
		case G_TRACE:
			SV_Trace((trace_t*)VMA(1), (float*)VMA(2), (float*)VMA(3), (float*)VMA(4), (float*)VMA(5), args[6], args[7], TT_AABB);
			return 0;
		case G_TRACECAPSULE:
			SV_Trace((trace_t*)VMA(1), (float*)VMA(2), (float*)VMA(3), (float*)VMA(4), (float*)VMA(5), args[6], args[7], TT_CAPSULE);
			return 0;
		case G_POINT_CONTENTS:
			return SV_PointContents((float*)VMA(1), args[2]);
		case G_SET_BRUSH_MODEL:
			SV_SetBrushModel((sharedEntity_t*)VMA(1), (char*)VMA(2));
			return 0;
		case G_IN_PVS:
			return SV_inPVS((float*)VMA(1), (float*)VMA(2));
		case G_IN_PVS_IGNORE_PORTALS:
			return SV_inPVSIgnorePortals((float*)VMA(1), (float*)VMA(2));
		case G_SET_CONFIGSTRING:
			SV_SetConfigstring(args[1], (char*)VMA(2));
			return 0;
		case G_GET_CONFIGSTRING:
			SV_GetConfigstring(args[1], (char*)VMA(2), args[3]);
			return 0;
		case G_SET_CONFIGSTRING_RESTRICTIONS:
			SV_SetConfigstringRestrictions( args[1], (clientList_t*)VMA(2) );
			return 0;
		case G_SET_USERINFO:
			SV_SetUserinfo(args[1], (char*)VMA(2));
			return 0;
		case G_GET_USERINFO:
			SV_GetUserinfo(args[1], (char*)VMA(2), args[3]);
			return 0;
		case G_GET_SERVERINFO:
			SV_GetServerinfo((char*)VMA(1), args[2]);
			return 0;
		case G_ADJUST_AREA_PORTAL_STATE:
			SV_AdjustAreaPortalState((sharedEntity_t*)VMA(1),(qboolean)args[2]);
			return 0;
		case G_AREAS_CONNECTED:
			return CM_AreasConnected(args[1], args[2]);
		case G_UPDATE_SHARED_CONFIG:
			SV_UpdateSharedConfig( args[1], (char*)VMA(2) );
			return 0;
		case G_BOT_ALLOCATE_CLIENT:
			return SV_BotAllocateClient(args[1]);
		case G_BOT_FREE_CLIENT:
			SV_BotFreeClient(args[1]);
			return 0;
		case G_GET_USERCMD:
			SV_GetUsercmd(args[1], (usercmd_t*)VMA(2));
			return 0;
		case G_GET_ENTITY_TOKEN: {
			const char     *s;

			s = COM_Parse(&sv.entityParsePoint);
			Q_strncpyz((char*)VMA(1), s, args[2]);
			if(!sv.entityParsePoint && !s[0]) {
				return qfalse;
			} else {
				return qtrue;
			}
		}
		case G_DEBUG_POLYGON_CREATE:
			return BotImport_DebugPolygonCreate(args[1], args[2], (vec3_t*)VMA(3));
		case G_DEBUG_POLYGON_DELETE:
			BotImport_DebugPolygonDelete(args[1]);
			return 0;
		case G_REAL_TIME:
			return Com_RealTime((qtime_t*)VMA(1));
		case G_SNAPVECTOR:
			Q_SnapVector((float*)VMA(1));
			return 0;
		case G_SEND_GAMESTAT:
			SV_MasterGameStat( (char*)VMA(1) );
			return 0;
		case G_ADDCOMMAND:
			Cmd_AddCommand( (char*)VMA(1), NULL, (char*)VMA(3) );
			return 0;
		case G_REMOVECOMMAND:
			Cmd_RemoveCommand( (char*)VMA(1) );
			return 0;
		case G_GETTAG:
			return SV_GetTag(args[1], args[2], (char*)VMA(3), (orientation_t*)VMA(4));
		case G_REGISTERTAG:
			return SV_LoadTag((char*)VMA(1));
		case G_REGISTERSOUND:
			return S_RegisterSound((char*)VMA(1), (qboolean)args[2]);
		case G_GET_SOUND_LENGTH:
			return S_GetSoundLength(args[1]);
		case G_PARSE_ADD_GLOBAL_DEFINE:
			return Parse_AddGlobalDefine( (char*)VMA(1) );
		case G_PARSE_LOAD_SOURCE:
			return Parse_LoadSourceHandle( (char*)VMA(1) );
		case G_PARSE_FREE_SOURCE:
			return Parse_FreeSourceHandle( args[1] );
		case G_PARSE_READ_TOKEN:
			return Parse_ReadTokenHandle( args[1], (pc_token_t*)VMA(2) );
		case G_PARSE_SOURCE_FILE_AND_LINE:
			return Parse_SourceFileAndLine( args[1], (char*)VMA(2), (int*)VMA(3) );
		case BOTLIB_SETUP:
			return SV_BotLibSetup();
		case BOTLIB_SHUTDOWN:
			return SV_BotLibShutdown();
		case BOTLIB_LIBVAR_SET:
			return botlib_export->BotLibVarSet((char*)VMA(1), (char*)VMA(2));
		case BOTLIB_LIBVAR_GET:
			return botlib_export->BotLibVarGet((char*)VMA(1), (char*)VMA(2), args[3]);
		case BOTLIB_PC_ADD_GLOBAL_DEFINE:
			return Parse_AddGlobalDefine( (char*)VMA(1) );
		case BOTLIB_PC_LOAD_SOURCE:
			return Parse_LoadSourceHandle((char*)VMA(1));
		case BOTLIB_PC_FREE_SOURCE:
			return Parse_FreeSourceHandle(args[1]);
		case BOTLIB_PC_READ_TOKEN:
			return Parse_ReadTokenHandle(args[1], (pc_token_t*)VMA(2));
		case BOTLIB_PC_SOURCE_FILE_AND_LINE:
			return Parse_SourceFileAndLine(args[1], (char*)VMA(2), (int*)VMA(3));
		case BOTLIB_PC_UNREAD_TOKEN:
			Parse_UnreadLastTokenHandle(args[1]);
			return 0;
		case BOTLIB_START_FRAME:
			return botlib_export->BotLibStartFrame(VMF(1));
		case BOTLIB_LOAD_MAP:
			return botlib_export->BotLibLoadMap((char*)VMA(1));
		case BOTLIB_UPDATENTITY:
			return botlib_export->BotLibUpdateEntity(args[1], (bot_entitystate_t*)VMA(2));
		case BOTLIB_TEST:
			return botlib_export->Test( args[1], (char*)VMA(2), (float*)VMA(3), (float*)VMA(4) );
		case BOTLIB_GET_SNAPSHOT_ENTITY:
			return SV_BotGetSnapshotEntity(args[1], args[2]);
		case BOTLIB_GET_CONSOLE_MESSAGE:
			return SV_BotGetConsoleMessage(args[1], (char*)VMA(2), args[3]);
		case BOTLIB_USER_COMMAND:
			SV_ClientThink(&svs.clients[args[1]], (usercmd_t*)VMA(2));
			return 0;
		case BOTLIB_AAS_ENTITY_INFO:
			botlib_export->aas.AAS_EntityInfo(args[1], (aas_entityinfo_s*)VMA(2));
			return 0;
		case BOTLIB_AAS_INITIALIZED:
			return botlib_export->aas.AAS_Initialized();
		case BOTLIB_AAS_PRESENCE_TYPE_BOUNDING_BOX:
			botlib_export->aas.AAS_PresenceTypeBoundingBox( args[1], (float*)VMA(2), (float*)VMA(3) );
			return 0;
		case BOTLIB_AAS_TIME:
			return FloatAsInt(botlib_export->aas.AAS_Time());
		case BOTLIB_AAS_SETCURRENTWORLD:
			botlib_export->aas.AAS_SetCurrentWorld(args[1]);
			return 0;
		case BOTLIB_AAS_POINT_AREA_NUM:
			return botlib_export->aas.AAS_PointAreaNum( (float*)VMA(1) );
		case BOTLIB_AAS_TRACE_AREAS:
			return botlib_export->aas.AAS_TraceAreas( (float*)VMA(1), (float*)VMA(2), (int*)VMA(3), (vec3_t*)VMA(4), args[5] );
		case BOTLIB_AAS_BBOX_AREAS:
			return botlib_export->aas.AAS_BBoxAreas( (float*)VMA(1), (float*)VMA(2), (int*)VMA(3), args[4] );
		case BOTLIB_AAS_AREA_CENTER:
			botlib_export->aas.AAS_AreaCenter(args[1], (float*)VMA(2));
			return 0;
		case BOTLIB_AAS_AREA_WAYPOINT:
			return botlib_export->aas.AAS_AreaWaypoint(args[1], (float*)VMA(2));
		case BOTLIB_AAS_POINT_CONTENTS:
			return botlib_export->aas.AAS_PointContents((float*)VMA(1));
		case BOTLIB_AAS_NEXT_BSP_ENTITY:
			return botlib_export->aas.AAS_NextBSPEntity(args[1]);
		case BOTLIB_AAS_VALUE_FOR_BSP_EPAIR_KEY:
			return botlib_export->aas.AAS_ValueForBSPEpairKey(args[1], (char*)VMA(2), (char*)VMA(3), args[4]);
		case BOTLIB_AAS_VECTOR_FOR_BSP_EPAIR_KEY:
			return botlib_export->aas.AAS_VectorForBSPEpairKey(args[1], (char*)VMA(2), (float*)VMA(3));
		case BOTLIB_AAS_FLOAT_FOR_BSP_EPAIR_KEY:
			return botlib_export->aas.AAS_FloatForBSPEpairKey(args[1], (char*)VMA(2), (float*)VMA(3));
		case BOTLIB_AAS_INT_FOR_BSP_EPAIR_KEY:
			return botlib_export->aas.AAS_IntForBSPEpairKey(args[1], (char*)VMA(2), (int*)VMA(3));
		case BOTLIB_AAS_AREA_REACHABILITY:
			return botlib_export->aas.AAS_AreaReachability(args[1]);
		case BOTLIB_AAS_AREA_LADDER:
			return botlib_export->aas.AAS_AreaLadder(args[1]);
		case BOTLIB_AAS_AREA_TRAVEL_TIME_TO_GOAL_AREA:
			return botlib_export->aas.AAS_AreaTravelTimeToGoalArea(args[1], (float*)VMA(2), args[3], args[4]);
		case BOTLIB_AAS_SWIMMING:
			return botlib_export->aas.AAS_Swimming((float*)VMA(1));
		case BOTLIB_AAS_PREDICT_CLIENT_MOVEMENT:
			return botlib_export->aas.AAS_PredictClientMovement((aas_clientmove_s*)VMA(1), args[2], (float*)VMA(3), args[4], args[5], (float*)VMA(6), (float*)VMA(7), args[8], args[9], VMF(10), args[11], args[12], args[13]);
		case BOTLIB_AAS_RT_SHOWROUTE:
			botlib_export->aas.AAS_RT_ShowRoute((float*)VMA(1), args[2], args[3]);
			return 0;
		case BOTLIB_AAS_NEARESTHIDEAREA:
			return botlib_export->aas.AAS_NearestHideArea(args[1], (float*)VMA(2), args[3], args[4], (float*)VMA(5), args[6], args[7], VMF(8), (float*)VMA(9));
		case BOTLIB_AAS_LISTAREASINRANGE:
			return botlib_export->aas.AAS_ListAreasInRange((float*)VMA(1), args[2], VMF(3), args[4], (vec3_t*)VMA(5), args[6]);
		case BOTLIB_AAS_AVOIDDANGERAREA:
			return botlib_export->aas.AAS_AvoidDangerArea((float*)VMA(1), args[2], (float*)VMA(3), args[4], VMF(5), args[6]);
		case BOTLIB_AAS_RETREAT:
			return botlib_export->aas.AAS_Retreat((int*)VMA(1), args[2], (float*)VMA(3), args[4], (float*)VMA(5), args[6], VMF(7), VMF(8), args[9]);
		case BOTLIB_AAS_ALTROUTEGOALS:
			return botlib_export->aas.AAS_AlternativeRouteGoals((float*)VMA(1), (float*)VMA(2), args[3], (aas_altroutegoal_t*)VMA(4), args[5], args[6]);
		case BOTLIB_AAS_SETAASBLOCKINGENTITY:
			botlib_export->aas.AAS_SetAASBlockingEntity((float*)VMA(1), (float*)VMA(2), args[3]);
			return 0;
		case BOTLIB_AAS_RECORDTEAMDEATHAREA:
			botlib_export->aas.AAS_RecordTeamDeathArea((float*)VMA(1), args[2], args[3], args[4], args[5]);
			return 0;
		case BOTLIB_EA_SAY:
			botlib_export->ea.EA_Say(args[1], (char*)VMA(2));
			return 0;
		case BOTLIB_EA_SAY_TEAM:
			botlib_export->ea.EA_SayTeam(args[1], (char*)VMA(2));
			return 0;
		case BOTLIB_EA_USE_ITEM:
			botlib_export->ea.EA_UseItem(args[1], (char*)VMA(2));
			return 0;
		case BOTLIB_EA_DROP_ITEM:
			botlib_export->ea.EA_DropItem(args[1], (char*)VMA(2));
			return 0;
		case BOTLIB_EA_USE_INV:
			botlib_export->ea.EA_UseInv(args[1], (char*)VMA(2));
			return 0;
		case BOTLIB_EA_DROP_INV:
			botlib_export->ea.EA_DropInv(args[1], (char*)VMA(2));
			return 0;
		case BOTLIB_EA_GESTURE:
			botlib_export->ea.EA_Gesture(args[1]);
			return 0;
		case BOTLIB_EA_COMMAND:
			botlib_export->ea.EA_Command(args[1], (char*)VMA(2));
			return 0;
		case BOTLIB_EA_SELECT_WEAPON:
			botlib_export->ea.EA_SelectWeapon(args[1], args[2]);
			return 0;
		case BOTLIB_EA_TALK:
			botlib_export->ea.EA_Talk(args[1]);
			return 0;
		case BOTLIB_EA_ATTACK:
			botlib_export->ea.EA_Attack(args[1]);
			return 0;
		case BOTLIB_EA_RELOAD:
			botlib_export->ea.EA_Reload(args[1]);
			return 0;
		case BOTLIB_EA_USE:
			botlib_export->ea.EA_Use(args[1]);
			return 0;
		case BOTLIB_EA_RESPAWN:
			botlib_export->ea.EA_Respawn(args[1]);
			return 0;
		case BOTLIB_EA_JUMP:
			botlib_export->ea.EA_Jump(args[1]);
			return 0;
		case BOTLIB_EA_DELAYED_JUMP:
			botlib_export->ea.EA_DelayedJump(args[1]);
			return 0;
		case BOTLIB_EA_CROUCH:
			botlib_export->ea.EA_Crouch(args[1]);
			return 0;
		case BOTLIB_EA_WALK:
			botlib_export->ea.EA_Walk(args[1]);
			return 0;
		case BOTLIB_EA_MOVE_UP:
			botlib_export->ea.EA_MoveUp(args[1]);
			return 0;
		case BOTLIB_EA_MOVE_DOWN:
			botlib_export->ea.EA_MoveDown(args[1]);
			return 0;
		case BOTLIB_EA_MOVE_FORWARD:
			botlib_export->ea.EA_MoveForward(args[1]);
			return 0;
		case BOTLIB_EA_MOVE_BACK:
			botlib_export->ea.EA_MoveBack(args[1]);
			return 0;
		case BOTLIB_EA_MOVE_LEFT:
			botlib_export->ea.EA_MoveLeft(args[1]);
			return 0;
		case BOTLIB_EA_MOVE_RIGHT:
			botlib_export->ea.EA_MoveRight(args[1]);
			return 0;
		case BOTLIB_EA_MOVE:
			botlib_export->ea.EA_Move(args[1], (float*)VMA(2), VMF(3));
			return 0;
		case BOTLIB_EA_VIEW:
			botlib_export->ea.EA_View(args[1], (float*)VMA(2));
			return 0;
		case BOTLIB_EA_PRONE:
			botlib_export->ea.EA_Prone(args[1]);
			return 0;
		case BOTLIB_EA_END_REGULAR:
			botlib_export->ea.EA_EndRegular(args[1], VMF(2));
			return 0;
		case BOTLIB_EA_GET_INPUT:
			botlib_export->ea.EA_GetInput(args[1], VMF(2), (bot_input_t*)VMA(3));
			return 0;
		case BOTLIB_EA_RESET_INPUT:
			botlib_export->ea.EA_ResetInput(args[1], (bot_input_t*)VMA(2));
			return 0;
		case BOTLIB_AI_LOAD_CHARACTER:
			return botlib_export->ai.BotLoadCharacter((char*)VMA(1), args[2]);
		case BOTLIB_AI_FREE_CHARACTER:
			botlib_export->ai.BotFreeCharacter(args[1]);
			return 0;
		case BOTLIB_AI_CHARACTERISTIC_FLOAT:
			return FloatAsInt(botlib_export->ai.Characteristic_Float(args[1], args[2]));
		case BOTLIB_AI_CHARACTERISTIC_BFLOAT:
			return FloatAsInt(botlib_export->ai.Characteristic_BFloat(args[1], args[2], VMF(3), VMF(4)));
		case BOTLIB_AI_CHARACTERISTIC_INTEGER:
			return botlib_export->ai.Characteristic_Integer(args[1], args[2]);
		case BOTLIB_AI_CHARACTERISTIC_BINTEGER:
			return botlib_export->ai.Characteristic_BInteger(args[1], args[2], args[3], args[4]);
		case BOTLIB_AI_CHARACTERISTIC_STRING:
			botlib_export->ai.Characteristic_String(args[1], args[2], (char*)VMA(3), args[4]);
			return 0;
		case BOTLIB_AI_ALLOC_CHAT_STATE:
			return botlib_export->ai.BotAllocChatState();
		case BOTLIB_AI_FREE_CHAT_STATE:
			botlib_export->ai.BotFreeChatState(args[1]);
			return 0;
		case BOTLIB_AI_QUEUE_CONSOLE_MESSAGE:
			botlib_export->ai.BotQueueConsoleMessage(args[1], args[2], (char*)VMA(3));
			return 0;
		case BOTLIB_AI_REMOVE_CONSOLE_MESSAGE:
			botlib_export->ai.BotRemoveConsoleMessage(args[1], args[2]);
			return 0;
		case BOTLIB_AI_NEXT_CONSOLE_MESSAGE:
			return botlib_export->ai.BotNextConsoleMessage(args[1], (bot_consolemessage_s*)VMA(2));
		case BOTLIB_AI_NUM_CONSOLE_MESSAGE:
			return botlib_export->ai.BotNumConsoleMessages(args[1]);
		case BOTLIB_AI_INITIAL_CHAT:
			botlib_export->ai.BotInitialChat(args[1], (char*)VMA(2), args[3], (char*)VMA(4), (char*)VMA(5), (char*)VMA(6), (char*)VMA(7), (char*)VMA(8), (char*)VMA(9), (char*)VMA(10), (char*)VMA(11));
			return 0;
		case BOTLIB_AI_NUM_INITIAL_CHATS:
			return botlib_export->ai.BotNumInitialChats(args[1], (char*)VMA(2));
		case BOTLIB_AI_REPLY_CHAT:
			return botlib_export->ai.BotReplyChat(args[1], (char*)VMA(2), args[3], args[4], (char*)VMA(5), (char*)VMA(6), (char*)VMA(7), (char*)VMA(8), (char*)VMA(9), (char*)VMA(10), (char*)VMA(11), (char*)VMA(12));
		case BOTLIB_AI_CHAT_LENGTH:
			return botlib_export->ai.BotChatLength(args[1]);
		case BOTLIB_AI_ENTER_CHAT:
			botlib_export->ai.BotEnterChat(args[1], args[2], args[3]);
			return 0;
		case BOTLIB_AI_GET_CHAT_MESSAGE:
			botlib_export->ai.BotGetChatMessage(args[1], (char*)VMA(2), args[3]);
			return 0;
		case BOTLIB_AI_STRING_CONTAINS:
			return botlib_export->ai.StringContains((char*)VMA(1), (char*)VMA(2), args[3]);
		case BOTLIB_AI_FIND_MATCH:
			return botlib_export->ai.BotFindMatch((char*)VMA(1), (bot_match_s*)VMA(2), args[3]);
		case BOTLIB_AI_MATCH_VARIABLE:
			botlib_export->ai.BotMatchVariable((bot_match_s*)VMA(1), args[2], (char*)VMA(3), args[4]);
			return 0;
		case BOTLIB_AI_UNIFY_WHITE_SPACES:
			botlib_export->ai.UnifyWhiteSpaces((char*)VMA(1));
			return 0;
		case BOTLIB_AI_REPLACE_SYNONYMS:
			botlib_export->ai.BotReplaceSynonyms((char*)VMA(1), args[2]);
			return 0;
		case BOTLIB_AI_LOAD_CHAT_FILE:
			return botlib_export->ai.BotLoadChatFile(args[1], (char*)VMA(2), (char*)VMA(3));
		case BOTLIB_AI_SET_CHAT_GENDER:
			botlib_export->ai.BotSetChatGender(args[1], args[2]);
			return 0;
		case BOTLIB_AI_SET_CHAT_NAME:
			botlib_export->ai.BotSetChatName(args[1], (char*)VMA(2));
			return 0;
		case BOTLIB_AI_RESET_GOAL_STATE:
			botlib_export->ai.BotResetGoalState(args[1]);
			return 0;
		case BOTLIB_AI_RESET_AVOID_GOALS:
			botlib_export->ai.BotResetAvoidGoals(args[1]);
			return 0;
		case BOTLIB_AI_REMOVE_FROM_AVOID_GOALS:
			botlib_export->ai.BotRemoveFromAvoidGoals(args[1], args[2]);
			return 0;
		case BOTLIB_AI_PUSH_GOAL:
			botlib_export->ai.BotPushGoal(args[1], (bot_goal_s*)VMA(2));
			return 0;
		case BOTLIB_AI_POP_GOAL:
			botlib_export->ai.BotPopGoal(args[1]);
			return 0;
		case BOTLIB_AI_EMPTY_GOAL_STACK:
			botlib_export->ai.BotEmptyGoalStack(args[1]);
			return 0;
		case BOTLIB_AI_DUMP_AVOID_GOALS:
			botlib_export->ai.BotDumpAvoidGoals(args[1]);
			return 0;
		case BOTLIB_AI_DUMP_GOAL_STACK:
			botlib_export->ai.BotDumpGoalStack(args[1]);
			return 0;
		case BOTLIB_AI_GOAL_NAME:
			botlib_export->ai.BotGoalName(args[1], (char*)VMA(2), args[3]);
			return 0;
		case BOTLIB_AI_GET_TOP_GOAL:
			return botlib_export->ai.BotGetTopGoal(args[1], (bot_goal_s*)VMA(2));
		case BOTLIB_AI_GET_SECOND_GOAL:
			return botlib_export->ai.BotGetSecondGoal(args[1], (bot_goal_s*)VMA(2));
		case BOTLIB_AI_CHOOSE_LTG_ITEM:
			return botlib_export->ai.BotChooseLTGItem(args[1], (float*)VMA(2), (int*)VMA(3), args[4]);
		case BOTLIB_AI_CHOOSE_NBG_ITEM:
			return botlib_export->ai.BotChooseNBGItem(args[1], (float*)VMA(2), (int*)VMA(3), args[4], (bot_goal_s*)VMA(5), VMF(6));
		case BOTLIB_AI_TOUCHING_GOAL:
			return botlib_export->ai.BotTouchingGoal((float*)VMA(1), (bot_goal_s*)VMA(2));
		case BOTLIB_AI_ITEM_GOAL_IN_VIS_BUT_NOT_VISIBLE:
			return botlib_export->ai.BotItemGoalInVisButNotVisible(args[1], (float*)VMA(2), (float*)VMA(3), (bot_goal_s*)VMA(4));
		case BOTLIB_AI_GET_LEVEL_ITEM_GOAL:
			return botlib_export->ai.BotGetLevelItemGoal(args[1], (char*)VMA(2), (bot_goal_s*)VMA(3));
		case BOTLIB_AI_GET_NEXT_CAMP_SPOT_GOAL:
			return botlib_export->ai.BotGetNextCampSpotGoal(args[1], (bot_goal_s*)VMA(2));
		case BOTLIB_AI_GET_MAP_LOCATION_GOAL:
			return botlib_export->ai.BotGetMapLocationGoal((char*)VMA(1), (bot_goal_s*)VMA(2));
		case BOTLIB_AI_AVOID_GOAL_TIME:
			return FloatAsInt(botlib_export->ai.BotAvoidGoalTime(args[1], args[2]));
		case BOTLIB_AI_INIT_LEVEL_ITEMS:
			botlib_export->ai.BotInitLevelItems();
			return 0;
		case BOTLIB_AI_UPDATE_ENTITY_ITEMS:
			botlib_export->ai.BotUpdateEntityItems();
			return 0;
		case BOTLIB_AI_LOAD_ITEM_WEIGHTS:
			return botlib_export->ai.BotLoadItemWeights(args[1], (char*)VMA(2));
		case BOTLIB_AI_FREE_ITEM_WEIGHTS:
			botlib_export->ai.BotFreeItemWeights(args[1]);
			return 0;
		case BOTLIB_AI_INTERBREED_GOAL_FUZZY_LOGIC:
			botlib_export->ai.BotInterbreedGoalFuzzyLogic(args[1], args[2], args[3]);
			return 0;
		case BOTLIB_AI_SAVE_GOAL_FUZZY_LOGIC:
			botlib_export->ai.BotSaveGoalFuzzyLogic(args[1], (char*)VMA(2));
			return 0;
		case BOTLIB_AI_MUTATE_GOAL_FUZZY_LOGIC:
			botlib_export->ai.BotMutateGoalFuzzyLogic(args[1], VMF(2));
			return 0;
		case BOTLIB_AI_ALLOC_GOAL_STATE:
			return botlib_export->ai.BotAllocGoalState(args[1]);
		case BOTLIB_AI_FREE_GOAL_STATE:
			botlib_export->ai.BotFreeGoalState(args[1]);
			return 0;
		case BOTLIB_AI_RESET_MOVE_STATE:
			botlib_export->ai.BotResetMoveState(args[1]);
			return 0;
		case BOTLIB_AI_MOVE_TO_GOAL:
			botlib_export->ai.BotMoveToGoal((bot_moveresult_s*)VMA(1), args[2], (bot_goal_s*)VMA(3), args[4]);
			return 0;
		case BOTLIB_AI_MOVE_IN_DIRECTION:
			return botlib_export->ai.BotMoveInDirection(args[1], (float*)VMA(2), VMF(3), args[4]);
		case BOTLIB_AI_RESET_AVOID_REACH:
			botlib_export->ai.BotResetAvoidReach(args[1]);
			return 0;
		case BOTLIB_AI_RESET_LAST_AVOID_REACH:
			botlib_export->ai.BotResetLastAvoidReach(args[1]);
			return 0;
		case BOTLIB_AI_REACHABILITY_AREA:
			return botlib_export->ai.BotReachabilityArea((float*)VMA(1), args[2]);
		case BOTLIB_AI_MOVEMENT_VIEW_TARGET:
			return botlib_export->ai.BotMovementViewTarget(args[1], (bot_goal_s*)VMA(2), args[3], VMF(4), (float*)VMA(5));
		case BOTLIB_AI_PREDICT_VISIBLE_POSITION:
			return botlib_export->ai.BotPredictVisiblePosition((float*)VMA(1), args[2], (bot_goal_s*)VMA(3), args[4], (vec_t*)VMA(5));
		case BOTLIB_AI_ALLOC_MOVE_STATE:
			return botlib_export->ai.BotAllocMoveState();
		case BOTLIB_AI_FREE_MOVE_STATE:
			botlib_export->ai.BotFreeMoveState(args[1]);
			return 0;
		case BOTLIB_AI_INIT_MOVE_STATE:
			botlib_export->ai.BotInitMoveState(args[1], (bot_initmove_s*)VMA(2));
			return 0;
		case BOTLIB_AI_INIT_AVOID_REACH:
			botlib_export->ai.BotInitAvoidReach(args[1]);
			return 0;
		case BOTLIB_AI_CHOOSE_BEST_FIGHT_WEAPON:
			return botlib_export->ai.BotChooseBestFightWeapon(args[1], (int*)VMA(2));
		case BOTLIB_AI_GET_WEAPON_INFO:
			botlib_export->ai.BotGetWeaponInfo(args[1], args[2], (weaponinfo_s*)VMA(3));
			return 0;
		case BOTLIB_AI_LOAD_WEAPON_WEIGHTS:
			return botlib_export->ai.BotLoadWeaponWeights(args[1], (char*)VMA(2));
		case BOTLIB_AI_ALLOC_WEAPON_STATE:
			return botlib_export->ai.BotAllocWeaponState();
		case BOTLIB_AI_FREE_WEAPON_STATE:
			botlib_export->ai.BotFreeWeaponState(args[1]);
			return 0;
		case BOTLIB_AI_RESET_WEAPON_STATE:
			botlib_export->ai.BotResetWeaponState(args[1]);
			return 0;
		case BOTLIB_AI_GENETIC_PARENTS_AND_CHILD_SELECTION:
			return botlib_export->ai.GeneticParentsAndChildSelection(args[1], (float*)VMA(2), (int*)VMA(3), (int*)VMA(4), (int*)VMA(5));
		case G_ADD_PHYSICS_ENTITY:
#ifdef USE_PHYSICS
			CMod_PhysicsAddEntity((sharedEntity_t*)VMA(1));
#endif
			return 0;
		case G_ADD_PHYSICS_STATIC:
#ifdef USE_PHYSICS
			CMod_PhysicsAddStatic((sharedEntity_t*)VMA(1));
#endif
			return 0;
		case TRAP_MEMSET:
			memset(VMA(1), args[2], args[3]);
			return 0;
		case TRAP_MEMCPY:
			memcpy(VMA(1), VMA(2), args[3]);
			return 0;
		case TRAP_STRNCPY:
			return (intptr_t)strncpy( (char*)VMA( 1 ), (char*)VMA( 2 ), args[3] );
		case TRAP_SIN:
			return FloatAsInt(sin(VMF(1)));
		case TRAP_COS:
			return FloatAsInt(cos(VMF(1)));
		case TRAP_ATAN2:
			return FloatAsInt(atan2(VMF(1), VMF(2)));
		case TRAP_SQRT:
			return FloatAsInt(sqrt(VMF(1)));
		case TRAP_MATRIXMULTIPLY:
			AxisMultiply((vec3_t*)VMA(1), (vec3_t*)VMA(2), (vec3_t*)VMA(3));
			return 0;
		case TRAP_ANGLEVECTORS:
			AngleVectors((vec_t*)VMA(1), (vec_t*)VMA(2), (vec_t*)VMA(3), (vec_t*)VMA(4));
			return 0;
		case TRAP_PERPENDICULARVECTOR:
			PerpendicularVector((vec_t*)VMA(1), (vec_t*)VMA(2));
			return 0;
		case TRAP_FLOOR:
			return FloatAsInt(floor(VMF(1)));
		case TRAP_CEIL:
			return FloatAsInt(ceil(VMF(1)));
		case G_SENDMESSAGE:
			SV_SendBinaryMessage(args[1], (char*)VMA(2), args[3]);
			return 0;
		case G_MESSAGESTATUS:
			return SV_BinaryMessageStatus(args[1]);
#if defined(ET_MYSQL)
        case G_SQL_RUNQUERY:
                return OW_RunQuery( (char*)VMA(1) );
        case G_SQL_FINISHQUERY:
                OW_FinishQuery( args[1] );
                return 0;
        case G_SQL_NEXTROW:
                return OW_NextRow( args[1] );
        case G_SQL_ROWCOUNT:
                return OW_RowCount( args[1] );
        case G_SQL_GETFIELDBYID:
                OW_GetFieldByID( args[1], args[2], (char*)VMA(3), args[4]  );
                return 0;
        case G_SQL_GETFIELDBYNAME:
                OW_GetFieldByName( args[1], (char*)VMA(2), (char*)VMA(3), args[4] );
                return 0;
        case G_SQL_GETFIELDBYID_INT:
                return OW_GetFieldByID_int( args[1], args[2] );
        case G_SQL_GETFIELDBYNAME_INT:
                return OW_GetFieldByName_int( args[1], (char*)VMA(2) );
        case G_SQL_FIELDCOUNT:
                return OW_FieldCount( args[1] );
        case G_SQL_CLEANSTRING:
                OW_CleanString( (char*)VMA(1), (char*)VMA(2), args[3] );
                return 0;
#endif
		case G_RSA_GENMSG:
			return SV_RSAGenMsg( (char*)VMA(1), (char*)VMA(2), (char*)VMA(3) );
		default:
			Com_Error( ERR_DROP, "Bad game system trap: %ld", (long int) args[0] );
	}
	return -1;
}
Пример #13
0
void Com_Frame( void ) {
	try 
	{
		int		timeBeforeFirstEvents, timeBeforeServer, timeBeforeEvents, timeBeforeClient, timeAfter;
		int		msec, minMsec;
		static int	lastTime = 0;

		// write config file if anything changed
		Com_WriteConfiguration(); 

		// if "viewlog" has been modified, show or hide the log console
		if ( com_viewlog->modified ) {
			Sys_ShowConsole( com_viewlog->integer, qfalse );
			com_viewlog->modified = qfalse;
		}

		//
		// main event loop
		//
		if ( com_speeds->integer ) {
			timeBeforeFirstEvents = Sys_Milliseconds ();
		}

		// we may want to spin here if things are going too fast
		if ( com_maxfps->integer > 0 ) {
			minMsec = 1000 / com_maxfps->integer;
		} else {
			minMsec = 1;
		}
		do {
			com_frameTime = Com_EventLoop();
			if ( lastTime > com_frameTime ) {
				lastTime = com_frameTime;		// possible on first frame
			}
			msec = com_frameTime - lastTime;
		} while ( msec < minMsec );
		Cbuf_Execute ();

		lastTime = com_frameTime;

		// mess with msec if needed
		com_frameMsec = msec;
		float fractionMsec=0.0f;
		msec = Com_ModifyMsec( msec, fractionMsec);
	
		//
		// server side
		//
		if ( com_speeds->integer ) {
			timeBeforeServer = Sys_Milliseconds ();
		}

		SV_Frame (msec, fractionMsec);


		//
		// client system
		//


	//	if ( !com_dedicated->integer ) 
		{
			//
			// run event loop a second time to get server to client packets
			// without a frame of latency
			//
			if ( com_speeds->integer ) {
				timeBeforeEvents = Sys_Milliseconds ();
			}
			Com_EventLoop();
			Cbuf_Execute ();


			//
			// client side
			//
			if ( com_speeds->integer ) {
				timeBeforeClient = Sys_Milliseconds ();
			}

			CL_Frame (msec, fractionMsec);

			if ( com_speeds->integer ) {
				timeAfter = Sys_Milliseconds ();
			}
		}


		//
		// report timing information
		//
		if ( com_speeds->integer ) {
			int			all, sv, ev, cl;

			all = timeAfter - timeBeforeServer;
			sv = timeBeforeEvents - timeBeforeServer;
			ev = timeBeforeServer - timeBeforeFirstEvents + timeBeforeClient - timeBeforeEvents;
			cl = timeAfter - timeBeforeClient;
			sv -= time_game;
			cl -= time_frontend + time_backend;

			Com_Printf("fr:%i all:%3i sv:%3i ev:%3i cl:%3i gm:%3i tr:%3i pvs:%3i rf:%3i bk:%3i\n", 
						com_frameNumber, all, sv, ev, cl, time_game, timeInTrace, timeInPVSCheck, time_frontend, time_backend);

			// speedslog
			if ( com_speedslog && com_speedslog->integer )
			{
				if(!speedslog)
				{
					speedslog = FS_FOpenFileWrite("speeds.log");
					FS_Write("data={\n", strlen("data={\n"), speedslog);
					bComma=false;
					if ( com_speedslog->integer > 1 ) 
					{
						// force it to not buffer so we get valid
						// data even if we are crashing
						FS_ForceFlush(logfile);
					}
				}
				if (speedslog)
				{
					char		msg[MAXPRINTMSG];

					if(bComma)
					{
						FS_Write(",\n", strlen(",\n"), speedslog);
						bComma=false;
					}
					FS_Write("{", strlen("{"), speedslog);
					Com_sprintf(msg,sizeof(msg),
								"%8.4f,%8.4f,%8.4f,%8.4f,%8.4f,%8.4f,",corg[0],corg[1],corg[2],cangles[0],cangles[1],cangles[2]);
					FS_Write(msg, strlen(msg), speedslog);
					Com_sprintf(msg,sizeof(msg),
						"%i,%3i,%3i,%3i,%3i,%3i,%3i,%3i,%3i,%3i}", 
						com_frameNumber, all, sv, ev, cl, time_game, timeInTrace, timeInPVSCheck, time_frontend, time_backend);
					FS_Write(msg, strlen(msg), speedslog);
					bComma=true;
				}
			}

			timeInTrace = timeInPVSCheck = 0;
		}

		//
		// trace optimization tracking
		//
		if ( com_showtrace->integer ) {
			extern	int c_traces, c_brush_traces, c_patch_traces;
			extern	int	c_pointcontents;

			/*
			Com_Printf( "%4i non-sv_traces, %4i sv_traces, %4i ms, ave %4.2f ms\n", c_traces - numTraces, numTraces, timeInTrace, (float)timeInTrace/(float)numTraces );
			timeInTrace = numTraces = 0;
			c_traces = 0;
			*/
		
			Com_Printf ("%4i traces  (%ib %ip) %4i points\n", c_traces,
				c_brush_traces, c_patch_traces, c_pointcontents);
			c_traces = 0;
			c_brush_traces = 0;
			c_patch_traces = 0;
			c_pointcontents = 0;
		}

		com_frameNumber++;
	}
	catch ( int code )
	{
		Com_CatchError (code);
		Com_Printf ("%s\n", Com_ErrorString (code));
		return;
	}

#ifdef G2_PERFORMANCE_ANALYSIS
	if (com_G2Report && com_G2Report->integer)
	{
		re.G2Time_ReportTimers();
	}

	re.G2Time_ResetTimers();
#endif
}
Пример #14
0
void demoConvert( const char *oldName, const char *newBaseName, qboolean smoothen ) {
	fileHandle_t	oldHandle = 0;
	fileHandle_t	newHandle = 0;
	int				temp;
	int				oldSize;
	int				msgSequence;
	msg_t			oldMsg;
	byte			oldData[ MAX_MSGLEN ];
	int				oldTime, nextTime, fullTime;
	int				clientNum;
	demoFrame_t		*workFrame;
	int				parseEntitiesNum = 0;
	demoConvert_t	*convert;
	char			bigConfigString[BIG_INFO_STRING];
	int				bigConfigNumber;
	const char		*s;
	clSnapshot_t	*oldSnap = 0;
	clSnapshot_t	*newSnap;
	int				levelCount = 0;
	char			newName[MAX_OSPATH];

	oldSize = FS_FOpenFileRead( oldName, &oldHandle, qtrue );
	if (!oldHandle) {
		Com_Printf("Failed to open %s for conversion.", oldName);
		return;
	}
	/* Alloc some memory */
	convert = Z_Malloc( sizeof( demoConvert_t) );
	/* Initialize the first workframe's strings */
	while (oldSize > 0) {
		MSG_Init( &oldMsg, oldData, sizeof( oldData ) );
		/* Read the sequence number */
		if (FS_Read( &convert->messageNum, 4, oldHandle) != 4)
			goto conversionerror;
		convert->messageNum = LittleLong( convert->messageNum );
		oldSize -= 4;
		/* Read the message size */
		if (FS_Read( &oldMsg.cursize,4, oldHandle) != 4)
			goto conversionerror;
		oldSize -= 4;
		oldMsg.cursize = LittleLong( oldMsg.cursize );
		/* Negative size signals end of demo */
		if (oldMsg.cursize < 0)
			break;
		if ( oldMsg.cursize > oldMsg.maxsize ) 
			goto conversionerror;
		/* Read the actual message */
		if (FS_Read( oldMsg.data, oldMsg.cursize, oldHandle ) != oldMsg.cursize)
			goto conversionerror;
		oldSize -= oldMsg.cursize;
		// init the bitstream
		MSG_BeginReading( &oldMsg );
		// Skip the reliable sequence acknowledge number
		MSG_ReadLong( &oldMsg );
		//
		// parse the message
		//
		while ( 1 ) {
			byte cmd;
			if ( oldMsg.readcount > oldMsg.cursize ) {
				Com_Printf ("Demo conversion, read past end of server message.\n");
				goto conversionerror;
			}
            cmd = MSG_ReadByte( &oldMsg );
			if ( cmd == svc_EOF) {
                break;
			}
			workFrame = &convert->frames[ convert->frameIndex % DEMOCONVERTFRAMES ];
			// other commands
			switch ( cmd ) {
			default:
				Com_Error (ERR_DROP,"CL_ParseServerMessage: Illegible server message\n");
				break;			
			case svc_nop:
				break;
			case svc_serverCommand:
				temp = MSG_ReadLong( &oldMsg );
				s = MSG_ReadString( &oldMsg );
				if (temp<=msgSequence)
					break;
//				Com_Printf( " server command %s\n", s );
				msgSequence = temp;
				Cmd_TokenizeString( s );
	
				if ( !Q_stricmp( Cmd_Argv(0), "bcs0" ) ) {
					bigConfigNumber = atoi( Cmd_Argv(1) );
					Q_strncpyz( bigConfigString, Cmd_Argv(2), sizeof( bigConfigString ));
					break;
				}
				if ( !Q_stricmp( Cmd_Argv(0), "bcs1" ) ) {
					Q_strcat( bigConfigString, sizeof( bigConfigString ), Cmd_Argv(2));
					break;
				}
				if ( !Q_stricmp( Cmd_Argv(0), "bcs2" ) ) {
					Q_strcat( bigConfigString, sizeof( bigConfigString ), Cmd_Argv(2));
					demoFrameAddString( &workFrame->string, bigConfigNumber, bigConfigString );
					break;
				}
				if ( !Q_stricmp( Cmd_Argv(0), "cs" ) ) {
					int num = atoi( Cmd_Argv(1) );
					s = Cmd_ArgsFrom( 2 );
					demoFrameAddString( &workFrame->string, num, Cmd_ArgsFrom( 2 ) );
					break;
				}
				if ( clientNum >= 0 && clientNum < MAX_CLIENTS ) {
					int len = strlen( s ) + 1;
					char *dst;
					if (workFrame->commandUsed + len + 1 > sizeof( workFrame->commandData)) {
						Com_Printf("Overflowed state command data.\n");
						goto conversionerror;
					}
					dst = workFrame->commandData + workFrame->commandUsed;
					*dst = clientNum;
					Com_Memcpy( dst+1, s, len );
					workFrame->commandUsed += len + 1;
				}
				break;
			case svc_gamestate:
				if (newHandle) {
					FS_FCloseFile( newHandle );
					newHandle = 0;
				}
				if (levelCount) {
					Com_sprintf( newName, sizeof( newName ), "%s.%d.mme", newBaseName, levelCount );
				} else {
					Com_sprintf( newName, sizeof( newName ), "%s.mme", newBaseName );
				}
				fullTime = -1;
				clientNum = -1;
				oldTime = -1;
				Com_Memset( convert, 0, sizeof( *convert ));
				convert->frames[0].string.used = 1;
				levelCount++;
				newHandle = FS_FOpenFileWrite( newName );
				if (!newHandle) {
					Com_Printf("Failed to open %s for target conversion target.\n", newName);
					goto conversionerror;
					return;
				} else {
					FS_Write ( demoHeader, strlen( demoHeader ), newHandle );
				}
				Com_sprintf( newName, sizeof( newName ), "%s.txt", newBaseName );
				workFrame = &convert->frames[ convert->frameIndex % DEMOCONVERTFRAMES ];
				msgSequence = MSG_ReadLong( &oldMsg );
				while( 1 ) {
					cmd = MSG_ReadByte( &oldMsg );
					if (cmd == svc_EOF)
						break;
					if ( cmd == svc_configstring) {
						int		num;
						const char *s;
						num = MSG_ReadShort( &oldMsg );
						s = MSG_ReadBigString( &oldMsg );
						demoFrameAddString( &workFrame->string, num, s );
					} else if ( cmd == svc_baseline ) {
						int num = MSG_ReadBits( &oldMsg, GENTITYNUM_BITS );
						if ( num < 0 || num >= MAX_GENTITIES ) {
							Com_Printf( "Baseline number out of range: %i.\n", num );
							goto conversionerror;
						}
						MSG_ReadDeltaEntity( &oldMsg, &demoNullEntityState, &convert->entityBaselines[num], num );
					} else {
						Com_Printf( "Unknown block while converting demo gamestate.\n" );
						goto conversionerror;
					}
				}
				clientNum = MSG_ReadLong( &oldMsg );
				/* Skip the checksum feed */
				MSG_ReadLong( &oldMsg );
				break;
			case svc_snapshot:
				nextTime = MSG_ReadLong( &oldMsg );
				/* Delta number, not needed */
				newSnap = &convert->snapshots[convert->messageNum & PACKET_MASK];
				Com_Memset (newSnap, 0, sizeof(*newSnap));
				newSnap->deltaNum = MSG_ReadByte( &oldMsg );
				newSnap->messageNum = convert->messageNum;
				if (!newSnap->deltaNum) {
					newSnap->deltaNum = -1;
					newSnap->valid = qtrue;		// uncompressed frame
					oldSnap  = NULL;
				} else {
					newSnap->deltaNum = newSnap->messageNum - newSnap->deltaNum;
					oldSnap = &convert->snapshots[newSnap->deltaNum & PACKET_MASK];
					if (!oldSnap->valid) {
						Com_Printf( "Delta snapshot without base.\n" );
						goto conversionerror;
					} else if (oldSnap->messageNum != newSnap->deltaNum) {
						// The frame that the server did the delta from
						// is too old, so we can't reconstruct it properly.
						Com_Printf ("Delta frame too old.\n");
					} else if ( parseEntitiesNum - oldSnap->parseEntitiesNum > MAX_PARSE_ENTITIES-128 ) {
						Com_Printf ("Delta parseEntitiesNum too old.\n");
					} else {
						newSnap->valid = qtrue;	// valid delta parse
					}
				}

				/* Snapflags, not needed */
				newSnap->snapFlags = MSG_ReadByte( &oldMsg );
				// read areamask
				workFrame->areaUsed = MSG_ReadByte( &oldMsg );
				MSG_ReadData( &oldMsg, workFrame->areamask, workFrame->areaUsed );
				if (clientNum <0 || clientNum >= MAX_CLIENTS) {
					Com_Printf("Got snapshot with invalid client.\n");
					goto conversionerror;
				}
				MSG_ReadDeltaPlayerstate( &oldMsg, oldSnap ? &oldSnap->ps : &demoNullPlayerState, &newSnap->ps );
				/* Read the individual entities */
				newSnap->parseEntitiesNum = parseEntitiesNum;
				newSnap->numEntities = 0;
				Com_Memset( workFrame->entityData, 0, sizeof( workFrame->entityData ));

				/* The beast that is entity parsing */
				{
				int			newnum;
				entityState_t	*oldstate, *newstate;
				int			oldindex = 0;
				int			oldnum;
				newnum = MSG_ReadBits( &oldMsg, GENTITYNUM_BITS );
				while ( 1 ) {
					// read the entity index number
					if (oldSnap && oldindex < oldSnap->numEntities) {
						oldstate = &convert->parseEntities[(oldSnap->parseEntitiesNum + oldindex) & (MAX_PARSE_ENTITIES-1)];
						oldnum = oldstate->number;
					} else {
						oldstate = 0;
						oldnum = 99999;
					}
					newstate = &convert->parseEntities[parseEntitiesNum];
					if ( !oldstate && (newnum == (MAX_GENTITIES-1))) {
						break;
					} else if ( oldnum < newnum ) {
						*newstate = *oldstate;
						oldindex++;
					} else if (oldnum == newnum) {
						oldindex++;
						MSG_ReadDeltaEntity( &oldMsg, oldstate, newstate, newnum );
						if ( newstate->number != MAX_GENTITIES-1)
							workFrame->entityData[ newstate->number ] = 1;
						newnum = MSG_ReadBits( &oldMsg, GENTITYNUM_BITS );
					} else if (oldnum > newnum) {
						MSG_ReadDeltaEntity( &oldMsg, &convert->entityBaselines[newnum], newstate , newnum );
						if ( newstate->number != MAX_GENTITIES-1)
							workFrame->entityData[ newstate->number ] = 1;
						newnum = MSG_ReadBits( &oldMsg, GENTITYNUM_BITS );
					}
					if (newstate->number == MAX_GENTITIES-1)
						continue;
					parseEntitiesNum++;
					parseEntitiesNum &= (MAX_PARSE_ENTITIES-1);
					newSnap->numEntities++;
				}}
				/* Stop processing this further since it's an invalid snap due to lack of delta data */
				if (!newSnap->valid)
					break;

				/* Skipped snapshots will be set invalid in the circular buffer */
				if ( newSnap->messageNum - convert->lastMessageNum >= PACKET_BACKUP ) {
					convert->lastMessageNum = newSnap->messageNum - ( PACKET_BACKUP - 1 );
				}
				for ( ; convert->lastMessageNum < newSnap->messageNum ; convert->lastMessageNum++ ) {
					convert->snapshots[convert->lastMessageNum & PACKET_MASK].valid = qfalse;
				}
				convert->lastMessageNum = newSnap->messageNum + 1;

				/* compress the frame into the new format */
				if (nextTime > oldTime) {
					demoFrame_t *cleanFrame;
					int writeIndex;
					for (temp = 0;temp<newSnap->numEntities;temp++) {
						int p = (newSnap->parseEntitiesNum+temp) & (MAX_PARSE_ENTITIES-1);
						entityState_t *newState = &convert->parseEntities[p];
						workFrame->entities[newState->number] = *newState;
					}
					workFrame->clientData[clientNum] = 1;
					workFrame->clients[clientNum] = newSnap->ps;
					workFrame->serverTime = nextTime;

					/* Which frame from the cache to save */
					writeIndex = convert->frameIndex - (DEMOCONVERTFRAMES/2);
					if (writeIndex >= 0) {
						const demoFrame_t *newFrame;
						msg_t writeMsg;
						// init the message
						MSG_Init( &writeMsg, demoBuffer, sizeof (demoBuffer));
						MSG_Clear( &writeMsg );
						MSG_Bitstream( &writeMsg );
						newFrame = &convert->frames[ writeIndex  % DEMOCONVERTFRAMES];
						if ( smoothen )
							demoFrameInterpolate( convert->frames, DEMOCONVERTFRAMES, writeIndex );
						if ( nextTime > fullTime || writeIndex <= 0 ) {
							/* Plan the next time for a full write */
							fullTime = nextTime + 2000;
							demoFramePack( &writeMsg, newFrame, 0 );
						} else {
							const demoFrame_t *oldFrame = &convert->frames[ ( writeIndex -1 ) % DEMOCONVERTFRAMES];
							demoFramePack( &writeMsg, newFrame, oldFrame );
						}
						/* Write away the new data in the msg queue */
						temp = LittleLong( writeMsg.cursize );
						FS_Write (&temp, 4, newHandle );
						FS_Write ( writeMsg.data , writeMsg.cursize, newHandle );
					}

					/* Clean up the upcoming frame for all new changes */
					convert->frameIndex++;
					cleanFrame = &convert->frames[ convert->frameIndex % DEMOCONVERTFRAMES];
					cleanFrame->serverTime = 0;
					for (temp = 0;temp<MAX_GENTITIES;temp++)
						cleanFrame->entities[temp].number = MAX_GENTITIES-1;
					Com_Memset( cleanFrame->clientData, 0, sizeof ( cleanFrame->clientData ));
					Com_Memcpy( cleanFrame->string.data, workFrame->string.data, workFrame->string.used );
					Com_Memcpy( cleanFrame->string.offsets, workFrame->string.offsets, sizeof( workFrame->string.offsets ));
					cleanFrame->string.used = workFrame->string.used;
					cleanFrame->commandUsed = 0;
					/* keep track of this last frame's time */
					oldTime = nextTime;
				}
				break;
			case svc_download:
				// read block number
				temp = MSG_ReadShort ( &oldMsg );
				if (!temp)	//0 block, read file size
					MSG_ReadLong( &oldMsg );
				// read block size
				temp = MSG_ReadShort ( &oldMsg );
				// read the data block
				for ( ;temp>0;temp--)
					MSG_ReadByte( &oldMsg );
				break;
			}
		}
	}
conversionerror:
	FS_FCloseFile( oldHandle );
	FS_FCloseFile( newHandle );
	Z_Free( convert );
	return;
}
Пример #15
0
/*
=====================
CL_ParseDownload

A download message has been received from the server
=====================
*/
void CL_ParseDownload(msg_t *msg)
{
    int           size;
    unsigned char data[MAX_MSGLEN];
    int           block;

    if (!*cls.downloadTempName)
    {
        Com_Printf("Server sending download, but no download was requested\n");
        CL_AddReliableCommand("stopdl");
        return;
    }

    // read the data
    block = MSG_ReadShort(msg);

    // www dl
    // if we haven't acked the download redirect yet
    if (block == -1)
    {
        if (!clc.bWWWDl)
        {
            // server is sending us a www download
            Q_strncpyz(cls.originalDownloadName, cls.downloadName, sizeof(cls.originalDownloadName));
            Q_strncpyz(cls.downloadName, MSG_ReadString(msg), sizeof(cls.downloadName));
            clc.downloadSize  = MSG_ReadLong(msg);
            clc.downloadFlags = MSG_ReadLong(msg);
            if (clc.downloadFlags & (1 << DL_FLAG_URL))
            {
                Sys_OpenURL(cls.downloadName, qtrue);
                Cbuf_ExecuteText(EXEC_APPEND, "quit\n");
                CL_AddReliableCommand("wwwdl bbl8r");   // not sure if that's the right msg
                clc.bWWWDlAborting = qtrue;
                return;
            }
            Cvar_SetValue("cl_downloadSize", clc.downloadSize);
            Com_DPrintf("Server redirected download: %s\n", cls.downloadName);
            clc.bWWWDl = qtrue; // activate wwwdl client loop
            CL_AddReliableCommand("wwwdl ack");
            // make sure the server is not trying to redirect us again on a bad checksum
            if (strstr(clc.badChecksumList, va("@%s", cls.originalDownloadName)))
            {
                Com_Printf("refusing redirect to %s by server (bad checksum)\n", cls.downloadName);
                CL_AddReliableCommand("wwwdl fail");
                clc.bWWWDlAborting = qtrue;
                return;
            }
            // make downloadTempName an OS path
            Q_strncpyz(cls.downloadTempName, FS_BuildOSPath(Cvar_VariableString("fs_homepath"), cls.downloadTempName, ""), sizeof(cls.downloadTempName));
            cls.downloadTempName[strlen(cls.downloadTempName) - 1] = '\0';
            if (!DL_BeginDownload(cls.downloadTempName, cls.downloadName))
            {
                // setting bWWWDl to false after sending the wwwdl fail doesn't work
                // not sure why, but I suspect we have to eat all remaining block -1 that the server has sent us
                // still leave a flag so that CL_WWWDownload is inactive
                // we count on server sending us a gamestate to start up clean again
                CL_AddReliableCommand("wwwdl fail");
                clc.bWWWDlAborting = qtrue;
                Com_Printf("Failed to initialize download for '%s'\n", cls.downloadName);
            }
            // Check for a disconnected download
            // we'll let the server disconnect us when it gets the bbl8r message
            if (clc.downloadFlags & (1 << DL_FLAG_DISCON))
            {
                CL_AddReliableCommand("wwwdl bbl8r");
                cls.bWWWDlDisconnected = qtrue;
            }
            return;
        }
        else
        {
            // server keeps sending that message till we ack it, eat and ignore
            //MSG_ReadLong( msg );
            MSG_ReadString(msg);
            MSG_ReadLong(msg);
            MSG_ReadLong(msg);
            return;
        }
    }

    if (!block)
    {
        // block zero is special, contains file size
        clc.downloadSize = MSG_ReadLong(msg);

        Cvar_SetValue("cl_downloadSize", clc.downloadSize);

        if (clc.downloadSize < 0)
        {
            Com_Error(ERR_DROP, "%s", MSG_ReadString(msg));
            return;
        }
    }

    size = MSG_ReadShort(msg);
    if (size < 0 || size > sizeof(data))
    {
        Com_Error(ERR_DROP, "CL_ParseDownload: Invalid size %d for download chunk.", size);
        return;
    }

    MSG_ReadData(msg, data, size);

    if (clc.downloadBlock != block)
    {
        Com_DPrintf("CL_ParseDownload: Expected block %d, got %d\n", clc.downloadBlock, block);
        return;
    }

    // open the file if not opened yet
    if (!clc.download)
    {
        clc.download = FS_SV_FOpenFileWrite(cls.downloadTempName);

        if (!clc.download)
        {
            Com_Printf("Could not create %s\n", cls.downloadTempName);
            CL_AddReliableCommand("stopdl");
            CL_NextDownload();
            return;
        }
    }

    if (size)
    {
        FS_Write(data, size, clc.download);
    }

    CL_AddReliableCommand(va("nextdl %d", clc.downloadBlock));
    clc.downloadBlock++;

    clc.downloadCount += size;

    // So UI gets access to it
    Cvar_SetValue("cl_downloadCount", clc.downloadCount);

    if (!size)     // A zero length block means EOF
    {
        if (clc.download)
        {
            FS_FCloseFile(clc.download);
            clc.download = 0;

            // rename the file
            FS_SV_Rename(cls.downloadTempName, cls.downloadName);
        }
        *cls.downloadTempName = *cls.downloadName = 0;
        Cvar_Set("cl_downloadName", "");

        // send intentions now
        // We need this because without it, we would hold the last nextdl and then start
        // loading right away.  If we take a while to load, the server is happily trying
        // to send us that last block over and over.
        // Write it twice to help make sure we acknowledge the download
        CL_WritePacket();
        CL_WritePacket();

        // get another file if needed
        CL_NextDownload();
    }
}
Пример #16
0
static kal_int32 xml_generate_flash_text(kal_int8 hd, kal_char *text, kal_uint32 textlen)
{
    kal_uint32 length, len;
    kal_int32 ret;
    FS_HANDLE fhandle = -1;
    xml_generator_struct *p = NULL;


/* first to get xml text length */
    if(textlen == 0)/* text is in file */
    {
        fhandle = FS_Open((WCHAR*)text, FS_READ_ONLY);
        if (fhandle < 0)
        {
            return XG_E_FAIL;
        }
        ret = FS_GetFileSize(fhandle, &length);
	if (ret == FS_FILE_NOT_FOUND)
	{
	    return XG_E_FILE_NOT_FOUND;
	}
        if (ret < 0)
        {
            FS_Close(fhandle);
            return XG_E_FAIL;
        }       
    }
    else /* text is in buffer */
    {
        length = textlen;
    }

    p = &(xg_array[hd]);

        
/* then write xml text to dest */
    if(p->buf != NULL)     /* write xml text to buffer */    
    {
        /* verify if over-buffer */
        if(p->curlen+length > p->buflen)
        {
            if(fhandle != -1)
            {
                FS_Close(fhandle);
            }
            ASSERT(0);
            kal_printf("buffer to save will be overflow!!!!\r\n");
            return XG_E_OVER_BUFFER;            
        }
        if (textlen != 0) /* text is in buffer, write xml text from buffer to buffer */
        {
            memcpy(p->buf+p->curlen, text, textlen);
            len = textlen;
            ret = 0;
        }
        else /* text is in file, write xml text from file to buffer */
        {
            ret = xml_generate_write_filetobuf(p->buf+p->curlen, fhandle, &len);
            FS_Close(fhandle);
        }
    }
    else /* write xml text to file */
    {
        
        if (textlen != 0) /* text is in buffer, write xml text from buffer to file */
        {
            
              ret = FS_Write(p->file, text, textlen, &len);
              if(ret == FS_DISK_FULL)
        {
        	return XG_E_LACK_DISK;
        }
           
            
        }
        else    /* text is in file, write xml text from file to file */
        {
            ret = xml_generate_write_filetofile(p->file, fhandle, &len);
            FS_Close(fhandle);     
        }
    }
    if (ret < 0)
    {
        return ret;
    }  
    else
    {
        
        p->curlen += len;
        return len; 
    }      
}
Пример #17
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_CVAR_VARIABLEINTEGERVALUE:
			return Cvar_VariableIntegerValue( VMA( 1 ) );

		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.SetWorldVisData( CM_ClusterPVS( -1 ) );
			re.LoadWorld( VMA( 1 ) );
			return 0;

		case CG_R_REGISTERMODEL:
			return re.RegisterModel( VMA( 1 ) );

		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:
			return re.RegisterShader( VMA( 1 ) );

		case CG_R_REGISTERFONT:
			re.RegisterFontVM( VMA( 1 ), VMA( 2 ), args[ 3 ], VMA( 4 ) );
			return 0;

		case CG_R_REGISTERSHADERNOMIP:
			return re.RegisterShaderNoMip( VMA( 1 ) );

#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_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;

			//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_PGETTEXT:
			strncpy( VMA( 1 ), C__( VMA( 2 ), VMA( 3 ) ), args[ 4 ] );
			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;
}
void ME_ExportToScript( const char* scriptname )
{
	char			scriptfile[256];
	char			outstring[1024];
	const char		*info, *mapname;
	fileHandle_t	f;
	static char		buf[MAX_MENUDEFFILE];
	int				i, j;
	IGME_vehicle_t* veh;

	if( !scriptname )
	{
		CG_Printf("Invalid scriptname!\n");
		return;
	}

	// set up mission filename
	info = CG_ConfigString( CS_SERVERINFO );
	mapname = Info_ValueForKey( info, "mapname" );
	Com_sprintf(scriptfile, 255, "missions/%s/%s.mis", mapname, scriptname);

	if( FS_FOpenFileByMode(scriptfile, &f, FS_WRITE) < 0 ) {
		CG_Printf("Unable to write to file %s. Exporting to script cancelled.", scriptfile);
		return;
	}
	
	CG_Printf("Saving to script: %s\n", scriptfile);

	// first line comment
	Com_sprintf( outstring, sizeof(outstring), "//Missionscript for map %s\n\n",mapname );
	FS_Write( outstring, strlen(outstring), f );

	// header
	Com_sprintf( outstring, sizeof(outstring), "Overview\n{\n\tmap\t%s\n", mapname );
	FS_Write( outstring, strlen(outstring), f );

	Com_sprintf( outstring, sizeof(outstring), "\tgameset\t%d\n", cgs.gameset );
	FS_Write( outstring, strlen(outstring), f );

	Com_sprintf( outstring, sizeof(outstring), "\tgametype\t%d\n", cgs.gametype );
	FS_Write( outstring, strlen(outstring), f );

	Com_sprintf( outstring, sizeof(outstring), "\tmission\t%s\n", scriptname );
	FS_Write( outstring, strlen(outstring), f );

	Com_sprintf( outstring, sizeof(outstring), "\tgoal\tSearchAndDestroy\n}\n\n" );
	FS_Write( outstring, strlen(outstring), f );

	// entities and groundinstallations
	Com_sprintf( outstring, sizeof(outstring), "Entities\n{\n", mapname );
	FS_Write( outstring, strlen(outstring), f );
	for( i = 0; i < IGME_MAX_VEHICLES; ++i ) {
		veh = &cgs.IGME.vehicles[i]; 
		if( !veh->active ) continue;
		if( veh->groundInstallation	)
		{
			Com_sprintf( outstring, sizeof(outstring), "\tGroundInstallation\n\t{\n", mapname );
			FS_Write( outstring, strlen(outstring), f );

			Com_sprintf( outstring, sizeof(outstring), "\t\tIndex\t%d\n", veh->vehidx );
			FS_Write( outstring, strlen(outstring), f );

			Com_sprintf( outstring, sizeof(outstring), "\t\tName\tSAM Turret\n" );
			FS_Write( outstring, strlen(outstring), f );

			Com_sprintf( outstring, sizeof(outstring), "\t\tTeam\t?\n" ); // ADD TEAM HERE!
			FS_Write( outstring, strlen(outstring), f );

			Com_sprintf( outstring, sizeof(outstring), "\t\tOrigin\t%f;%f;%f\n", veh->origin[0],
				veh->origin[1], veh->origin[2]);
			FS_Write( outstring, strlen(outstring), f );

			Com_sprintf( outstring, sizeof(outstring), "\t\tAngles\t%f;%f;%f\n", veh->angles[0],
				veh->angles[1], veh->angles[2]);
			FS_Write( outstring, strlen(outstring), f );

			Com_sprintf( outstring, sizeof(outstring), "\t}\n\n", mapname );
			FS_Write( outstring, strlen(outstring), f );
		}
		else
		{
			Com_sprintf( outstring, sizeof(outstring), "\tVehicle\n\t{\n", mapname );
			FS_Write( outstring, strlen(outstring), f );

			Com_sprintf( outstring, sizeof(outstring), "\t\tIndex\t%d\n", veh->vehidx );
			FS_Write( outstring, strlen(outstring), f );

			Com_sprintf( outstring, sizeof(outstring), "\t\tName\t%s\n", availableVehicles[veh->vehidx].modelName );
			FS_Write( outstring, strlen(outstring), f );

			Com_sprintf( outstring, sizeof(outstring), "\t\tTeam\t%d\n", availableVehicles[veh->vehidx].team ); 
			FS_Write( outstring, strlen(outstring), f );

			Com_sprintf( outstring, sizeof(outstring), "\t\tOrigin\t%f;%f;%f\n", veh->origin[0],
				veh->origin[1], veh->origin[2]);
			FS_Write( outstring, strlen(outstring), f );

			Com_sprintf( outstring, sizeof(outstring), "\t\tAngles\t%f;%f;%f\n", veh->angles[0],
				veh->angles[1], veh->angles[2]);
			FS_Write( outstring, strlen(outstring), f );

			Com_sprintf( outstring, sizeof(outstring), "\t\tWaypoints\n\t\t{\n" );
			FS_Write( outstring, strlen(outstring), f );

			for( j = 0; j < IGME_MAX_WAYPOINTS; ++j ) 
			{
				if( !veh->waypoints[j].active ) break;//as they are in a row
				Com_sprintf( outstring, sizeof(outstring), "\t\t\tOrigin\t%f;%f;%f\n", veh->waypoints[j].origin[0],
					veh->waypoints[j].origin[1], veh->waypoints[j].origin[2]);
				FS_Write( outstring, strlen(outstring), f );

			}

			Com_sprintf( outstring, sizeof(outstring), "\t\t}\n\t}\n\n", mapname );
			FS_Write( outstring, strlen(outstring), f );
		}
	}
	Com_sprintf( outstring, sizeof(outstring), "}\n", mapname );
	FS_Write( outstring, strlen(outstring), f );



	CG_Printf("Successfully saved to script\n");

	FS_FCloseFile(f);




}
Пример #19
0
/*
====================
CL_UpdateLevelHunkUsage

  This updates the "hunkusage.dat" file with the current map and it's hunk usage count

  This is used for level loading, so we can show a percentage bar dependant on the amount
  of hunk memory allocated so far

  This will be slightly inaccurate if some settings like sound quality are changed, but these
  things should only account for a small variation (hopefully)
====================
*/
void CL_UpdateLevelHunkUsage( void ) {
	int handle;
	char *memlistfile = "hunkusage.dat";
	char *buf, *outbuf;
	char *buftrav, *outbuftrav;
	char *token;
	char outstr[256];
	int len, memusage;

	memusage = Cvar_VariableIntegerValue( "com_hunkused" ) + Cvar_VariableIntegerValue( "hunk_soundadjust" );

	len = FS_FOpenFileByMode( memlistfile, &handle, FS_READ );
	if ( len >= 0 ) { // the file exists, so read it in, strip out the current entry for this map, and save it out, so we can append the new value

		buf = (char *)Z_Malloc( len + 1 );
		memset( buf, 0, len + 1 );
		outbuf = (char *)Z_Malloc( len + 1 );
		memset( outbuf, 0, len + 1 );

		FS_Read( (void *)buf, len, handle );
		FS_FCloseFile( handle );

		// now parse the file, filtering out the current map
		buftrav = buf;
		outbuftrav = outbuf;
		outbuftrav[0] = '\0';
		while ( ( token = COM_Parse( &buftrav ) ) && token[0] ) {
			if ( !Q_strcasecmp( token, cl.mapname ) ) {
				// found a match
				token = COM_Parse( &buftrav );  // read the size
				if ( token && token[0] ) {
					if ( atoi( token ) == memusage ) {  // if it is the same, abort this process
						Z_Free( buf );
						Z_Free( outbuf );
						return;
					}
				}
			} else {    // send it to the outbuf
				Q_strcat( outbuftrav, len + 1, token );
				Q_strcat( outbuftrav, len + 1, " " );
				token = COM_Parse( &buftrav );  // read the size
				if ( token && token[0] ) {
					Q_strcat( outbuftrav, len + 1, token );
					Q_strcat( outbuftrav, len + 1, "\n" );
				} else {
					Com_Error( ERR_DROP, "hunkusage.dat file is corrupt\n" );
				}
			}
		}

#ifdef __MACOS__    //DAJ MacOS file typing
		{
			extern _MSL_IMP_EXP_C long _fcreator, _ftype;
			_ftype = 'WlfB';
			_fcreator = 'WlfS';
		}
#endif
		handle = FS_FOpenFileWrite( memlistfile );
		if ( handle < 0 ) {
			Com_Error( ERR_DROP, "cannot create %s\n", memlistfile );
		}
		// input file is parsed, now output to the new file
		len = strlen( outbuf );
		if ( FS_Write( (void *)outbuf, len, handle ) != len ) {
			Com_Error( ERR_DROP, "cannot write to %s\n", memlistfile );
		}
		FS_FCloseFile( handle );

		Z_Free( buf );
		Z_Free( outbuf );
	}
	// now append the current map to the current file
	FS_FOpenFileByMode( memlistfile, &handle, FS_APPEND );
	if ( handle < 0 ) {
		Com_Error( ERR_DROP, "cannot write to hunkusage.dat, check disk full\n" );
	}
	Com_sprintf( outstr, sizeof( outstr ), "%s %i\n", cl.mapname, memusage );
	FS_Write( outstr, strlen( outstr ), handle );
	FS_FCloseFile( handle );

	// now just open it and close it, so it gets copied to the pak dir
	len = FS_FOpenFileByMode( memlistfile, &handle, FS_READ );
	if ( len >= 0 ) {
		FS_FCloseFile( handle );
	}
}
Пример #20
0
void CL_Record(const char *name)
{
	int           i;
	msg_t         buf;
	byte          bufData[MAX_MSGLEN];
	entityState_t *ent;
	entityState_t nullstate;
	char          *s;
	int           len;

	// open the demo file
	Com_FuncPrinf("Recording to %s.\n", name);
	clc.demofile = FS_FOpenFileWrite(name);
	if (!clc.demofile)
	{
		Com_FuncPrinf("ERROR: couldn't open.\n");
		return;
	}

	clc.demorecording = qtrue;
	Cvar_Set("cl_demorecording", "1");    // fretn
	Q_strncpyz(clc.demoName, demoName, sizeof(clc.demoName));
	Cvar_Set("cl_demofilename", clc.demoName);    // bani
	Cvar_Set("cl_demooffset", "0");    // bani

	// don't start saving messages until a non-delta compressed message is received
	clc.demowaiting = qtrue;

	// write out the gamestate message
	MSG_Init(&buf, bufData, sizeof(bufData));
	MSG_Bitstream(&buf);

	// NOTE: all server->client messages now acknowledge
	MSG_WriteLong(&buf, clc.reliableSequence);

	MSG_WriteByte(&buf, svc_gamestate);
	MSG_WriteLong(&buf, clc.serverCommandSequence);

	// configstrings
	for (i = 0; i < MAX_CONFIGSTRINGS; i++)
	{
		if (!cl.gameState.stringOffsets[i])
		{
			continue;
		}
		s = cl.gameState.stringData + cl.gameState.stringOffsets[i];
		MSG_WriteByte(&buf, svc_configstring);
		MSG_WriteShort(&buf, i);
		MSG_WriteBigString(&buf, s);
	}

	// baselines
	memset(&nullstate, 0, sizeof(nullstate));
	for (i = 0; i < MAX_GENTITIES; i++)
	{
		ent = &cl.entityBaselines[i];
		if (!ent->number)
		{
			continue;
		}
		MSG_WriteByte(&buf, svc_baseline);
		MSG_WriteDeltaEntity(&buf, &nullstate, ent, qtrue);
	}

	MSG_WriteByte(&buf, svc_EOF);

	// finished writing the gamestate stuff

	// write the client num
	MSG_WriteLong(&buf, clc.clientNum);
	// write the checksum feed
	MSG_WriteLong(&buf, clc.checksumFeed);

	// finished writing the client packet
	MSG_WriteByte(&buf, svc_EOF);

	// write it to the demo file
	len = LittleLong(clc.serverMessageSequence - 1);
	FS_Write(&len, 4, clc.demofile);

	len = LittleLong(buf.cursize);
	FS_Write(&len, 4, clc.demofile);
	FS_Write(buf.data, buf.cursize, clc.demofile);

	// the rest of the demo file will be copied from net messages
}
Пример #21
0
/*
=====================
CL_ParseDownload

A download message has been received from the server
=====================
*/
void CL_ParseDownload ( msg_t *msg ) {
	int		size;
	unsigned char data[MAX_MSGLEN];
	uint16_t block;

	if (!*clc.downloadTempName) {
		Com_Printf("Server sending download, but no download was requested\n");
		CL_AddReliableCommand("stopdl", qfalse);
		return;
	}

	// read the data
	block = MSG_ReadShort ( msg );

	if(!block && !clc.downloadBlock)
	{
		// block zero is special, contains file size
		clc.downloadSize = MSG_ReadLong ( msg );

		Cvar_SetValue( "cl_downloadSize", clc.downloadSize );

		if (clc.downloadSize < 0)
		{
			Com_Error( ERR_DROP, "%s", MSG_ReadString( msg ) );
			return;
		}
	}

	size = MSG_ReadShort ( msg );
	if (size < 0 || size > sizeof(data))
	{
		Com_Error(ERR_DROP, "CL_ParseDownload: Invalid size %d for download chunk", size);
		return;
	}
	
	MSG_ReadData(msg, data, size);

	if((clc.downloadBlock & 0xFFFF) != block)
	{
		Com_DPrintf( "CL_ParseDownload: Expected block %d, got %d\n", (clc.downloadBlock & 0xFFFF), block);
		return;
	}

	// open the file if not opened yet
	if (!clc.download)
	{
		clc.download = FS_SV_FOpenFileWrite( clc.downloadTempName );

		if (!clc.download) {
			Com_Printf( "Could not create %s\n", clc.downloadTempName );
			CL_AddReliableCommand("stopdl", qfalse);
			CL_NextDownload();
			return;
		}
	}

	if (size)
		FS_Write( data, size, clc.download );

	CL_AddReliableCommand(va("nextdl %d", clc.downloadBlock), qfalse);
	clc.downloadBlock++;

	clc.downloadCount += size;

	// So UI gets access to it
	Cvar_SetValue( "cl_downloadCount", clc.downloadCount );

	if (!size) { // A zero length block means EOF
		if (clc.download) {
			FS_FCloseFile( clc.download );
			clc.download = 0;

			// rename the file
			FS_SV_Rename ( clc.downloadTempName, clc.downloadName, qfalse );
		}

		// send intentions now
		// We need this because without it, we would hold the last nextdl and then start
		// loading right away.  If we take a while to load, the server is happily trying
		// to send us that last block over and over.
		// Write it twice to help make sure we acknowledge the download
		CL_WritePacket();
		CL_WritePacket();

		// get another file if needed
		CL_NextDownload ();
	}
}
Пример #22
0
static void logfile_write(print_type_t type, const char *s)
{
    char text[MAXPRINTMSG];
    char buf[MAX_QPATH];
    char *p, *maxp;
    size_t len;
    ssize_t ret;
    int c;

    if (logfile_prefix->string[0]) {
        p = strchr(logfile_prefix->string, '@');
        if (p) {
            // expand it in place, hacky
            switch (type) {
            case PRINT_TALK:      *p = 'T'; break;
            case PRINT_DEVELOPER: *p = 'D'; break;
            case PRINT_WARNING:   *p = 'W'; break;
            case PRINT_ERROR:     *p = 'E'; break;
            case PRINT_NOTICE:    *p = 'N'; break;
            default:              *p = 'A'; break;
            }
        }
        len = format_local_time(buf, sizeof(buf), logfile_prefix->string);
        if (p) {
            *p = '@';
        }
    } else {
        len = 0;
    }

    p = text;
    maxp = text + sizeof(text) - 1;
    while (*s) {
        if (com_logNewline) {
            if (len > 0 && p + len < maxp) {
                memcpy(p, buf, len);
                p += len;
            }
            com_logNewline = qfalse;
        }

        if (p == maxp) {
            break;
        }

        c = *s++;
        if (c == '\n') {
            com_logNewline = qtrue;
        } else {
            c = Q_charascii(c);
        }

        *p++ = c;
    }
    *p = 0;

    len = p - text;
    ret = FS_Write(text, len, com_logFile);
    if (ret != len) {
        // zero handle BEFORE doing anything else to avoid recursion
        qhandle_t tmp = com_logFile;
        com_logFile = 0;
        FS_FCloseFile(tmp);
        Com_EPrintf("Couldn't write console log: %s\n", Q_ErrorString(ret));
        Cvar_Set("logfile", "0");
    }
}
Пример #23
0
void SCR_CaptureVideo_Ogg_BeginVideo(void)
{
	cls.capturevideo.format = CAPTUREVIDEOFORMAT_OGG_VORBIS_THEORA;
	cls.capturevideo.formatextension = "ogv";
	cls.capturevideo.videofile = FS_OpenRealFile(va("%s.%s", cls.capturevideo.basename, cls.capturevideo.formatextension), "wb", false);
	cls.capturevideo.endvideo = SCR_CaptureVideo_Ogg_EndVideo;
	cls.capturevideo.videoframes = SCR_CaptureVideo_Ogg_VideoFrames;
	cls.capturevideo.soundframe = SCR_CaptureVideo_Ogg_SoundFrame;
	cls.capturevideo.formatspecific = Mem_Alloc(tempmempool, sizeof(capturevideostate_ogg_formatspecific_t));
	{
		LOAD_FORMATSPECIFIC_OGG();
		int num, denom, i;
		ogg_page pg;
		ogg_packet pt, pt2, pt3;
		theora_comment tc;
		vorbis_comment vc;
		theora_info ti;

		format->serial1 = rand();
		qogg_stream_init(&format->to, format->serial1);

		if(cls.capturevideo.soundrate)
		{
			do
			{
				format->serial2 = rand();
			}
			while(format->serial1 == format->serial2);
			qogg_stream_init(&format->vo, format->serial2);
		}

		format->videopage.len = format->audiopage.len = 0;

		qtheora_info_init(&ti);
		ti.frame_width = cls.capturevideo.width;
		ti.frame_height = cls.capturevideo.height;
		ti.width = (ti.frame_width + 15) & ~15;
		ti.height = (ti.frame_height + 15) & ~15;
		//ti.offset_x = ((ti.width - ti.frame_width) / 2) & ~1;
		//ti.offset_y = ((ti.height - ti.frame_height) / 2) & ~1;

		for(i = 0; i < 2; ++i)
		{
			format->yuv[i].y_width = ti.width;
			format->yuv[i].y_height = ti.height;
			format->yuv[i].y_stride = ti.width;
			format->yuv[i].uv_width = ti.width / 2;
			format->yuv[i].uv_height = ti.height / 2;
			format->yuv[i].uv_stride = ti.width / 2;
			format->yuv[i].y = (unsigned char *) Mem_Alloc(tempmempool, format->yuv[i].y_stride * format->yuv[i].y_height);
			format->yuv[i].u = (unsigned char *) Mem_Alloc(tempmempool, format->yuv[i].uv_stride * format->yuv[i].uv_height);
			format->yuv[i].v = (unsigned char *) Mem_Alloc(tempmempool, format->yuv[i].uv_stride * format->yuv[i].uv_height);
		}
		format->yuvi = -1; // -1: no frame valid yet, write into 0

		FindFraction(cls.capturevideo.framerate / cls.capturevideo.framestep, &num, &denom, 1001);
		ti.fps_numerator = num;
		ti.fps_denominator = denom;

		FindFraction(1 / vid_pixelheight.value, &num, &denom, 1000);
		ti.aspect_numerator = num;
		ti.aspect_denominator = denom;

		ti.colorspace = OC_CS_UNSPECIFIED;
		ti.pixelformat = OC_PF_420;

		ti.quick_p = true; // http://mlblog.osdir.com/multimedia.ogg.theora.general/2004-07/index.shtml
		ti.dropframes_p = false;

		ti.target_bitrate = cl_capturevideo_ogg_theora_bitrate.integer * 1000;
		ti.quality = cl_capturevideo_ogg_theora_quality.integer;

		if(ti.target_bitrate <= 0)
		{
			if(ti.quality < 0)
			{
				ti.target_bitrate = -1;
				ti.keyframe_data_target_bitrate = (unsigned int)-1;
				ti.quality = 63;
			}
			else
			{
				ti.target_bitrate = -1;
				ti.keyframe_data_target_bitrate = (unsigned int)-1;
				ti.quality = bound(0, ti.quality, 63);
			}
		}
		else
		{
			if(ti.quality < 0)
			{
				ti.target_bitrate = bound(45000, ti.target_bitrate, 2000000);
				ti.keyframe_data_target_bitrate = (int) (ti.target_bitrate * max(1, cl_capturevideo_ogg_theora_keyframe_bitrate_multiplier.value));
				ti.quality = -1;
			}
			else
			{
				ti.target_bitrate = bound(45000, ti.target_bitrate, 2000000);
				ti.keyframe_data_target_bitrate = (int) (ti.target_bitrate * max(1, cl_capturevideo_ogg_theora_keyframe_bitrate_multiplier.value));
				ti.quality = -1;
			}
		}

		// this -1 magic is because ti.keyframe_frequency and ti.keyframe_mindistance use different metrics
		ti.keyframe_frequency = bound(1, cl_capturevideo_ogg_theora_keyframe_maxinterval.integer, 1000);
		ti.keyframe_mindistance = bound(1, cl_capturevideo_ogg_theora_keyframe_mininterval.integer, (int) ti.keyframe_frequency) - 1;
		ti.noise_sensitivity = bound(0, cl_capturevideo_ogg_theora_noise_sensitivity.integer, 6);
		ti.sharpness = bound(0, cl_capturevideo_ogg_theora_sharpness.integer, 2);
		ti.keyframe_auto_threshold = bound(0, cl_capturevideo_ogg_theora_keyframe_auto_threshold.integer, 100);

		ti.keyframe_frequency_force = ti.keyframe_frequency;
		ti.keyframe_auto_p = (ti.keyframe_frequency != ti.keyframe_mindistance + 1);

		qtheora_encode_init(&format->ts, &ti);
		qtheora_info_clear(&ti);

		// vorbis?
		if(cls.capturevideo.soundrate)
		{
			qvorbis_info_init(&format->vi);
			qvorbis_encode_init_vbr(&format->vi, cls.capturevideo.soundchannels, cls.capturevideo.soundrate, bound(-1, cl_capturevideo_ogg_vorbis_quality.value, 10) * 0.099);
			qvorbis_comment_init(&vc);
			qvorbis_analysis_init(&format->vd, &format->vi);
			qvorbis_block_init(&format->vd, &format->vb);
		}

		qtheora_comment_init(&tc);

		/* create the remaining theora headers */
		qtheora_encode_header(&format->ts, &pt);
		qogg_stream_packetin(&format->to, &pt);
		if (qogg_stream_pageout (&format->to, &pg) != 1)
			fprintf (stderr, "Internal Ogg library error.\n");
		FS_Write(cls.capturevideo.videofile, pg.header, pg.header_len);
		FS_Write(cls.capturevideo.videofile, pg.body, pg.body_len);

		qtheora_encode_comment(&tc, &pt);
		qogg_stream_packetin(&format->to, &pt);
		qtheora_encode_tables(&format->ts, &pt);
		qogg_stream_packetin (&format->to, &pt);

		qtheora_comment_clear(&tc);

		if(cls.capturevideo.soundrate)
		{
			qvorbis_analysis_headerout(&format->vd, &vc, &pt, &pt2, &pt3);
			qogg_stream_packetin(&format->vo, &pt);
			if (qogg_stream_pageout (&format->vo, &pg) != 1)
				fprintf (stderr, "Internal Ogg library error.\n");
			FS_Write(cls.capturevideo.videofile, pg.header, pg.header_len);
			FS_Write(cls.capturevideo.videofile, pg.body, pg.body_len);

			qogg_stream_packetin(&format->vo, &pt2);
			qogg_stream_packetin(&format->vo, &pt3);

			qvorbis_comment_clear(&vc);
		}

		for(;;)
		{
			int result = qogg_stream_flush (&format->to, &pg);
			if (result < 0)
				fprintf (stderr, "Internal Ogg library error.\n"); // TODO Host_Error
			if (result <= 0)
				break;
			FS_Write(cls.capturevideo.videofile, pg.header, pg.header_len);
			FS_Write(cls.capturevideo.videofile, pg.body, pg.body_len);
		}

		if(cls.capturevideo.soundrate)
		for(;;)
		{
			int result = qogg_stream_flush (&format->vo, &pg);
			if (result < 0)
				fprintf (stderr, "Internal Ogg library error.\n"); // TODO Host_Error
			if (result <= 0)
				break;
			FS_Write(cls.capturevideo.videofile, pg.header, pg.header_len);
			FS_Write(cls.capturevideo.videofile, pg.body, pg.body_len);
		}
	}
}
Пример #24
0
/*
====================
CL_UISystemCalls

The ui module is making a system call
====================
*/
int CL_UISystemCalls( int *args ) {
	switch( args[0] ) {
	case UI_ERROR:
		Com_Error( ERR_DROP, "%s", VMA(1) );
		return 0;

	case UI_PRINT:
		Com_Printf( "%s", VMA(1) );
		return 0;

	case UI_MILLISECONDS:
		return Sys_Milliseconds();

	case UI_CVAR_REGISTER:
		Cvar_Register( VMA(1), VMA(2), VMA(3), args[4] ); 
		return 0;

	case UI_CVAR_UPDATE:
		Cvar_Update( VMA(1) );
		return 0;

	case UI_CVAR_SET:
		Cvar_Set( VMA(1), VMA(2) );
		return 0;

	case UI_CVAR_VARIABLEVALUE:
		return FloatAsInt( Cvar_VariableValue( VMA(1) ) );

	case UI_CVAR_VARIABLESTRINGBUFFER:
		Cvar_VariableStringBuffer( VMA(1), VMA(2), args[3] );
		return 0;

	case UI_CVAR_SETVALUE:
		Cvar_SetValue( VMA(1), VMF(2) );
		return 0;

	case UI_CVAR_RESET:
		Cvar_Reset( VMA(1) );
		return 0;

	case UI_CVAR_CREATE:
		Cvar_Get( VMA(1), VMA(2), args[3] );
		return 0;

	case UI_CVAR_INFOSTRINGBUFFER:
		Cvar_InfoStringBuffer( args[1], VMA(2), args[3] );
		return 0;

	case UI_ARGC:
		return Cmd_Argc();

	case UI_ARGV:
		Cmd_ArgvBuffer( args[1], VMA(2), args[3] );
		return 0;

	case UI_CMD_EXECUTETEXT:
		Cbuf_ExecuteText( args[1], VMA(2) );
		return 0;

	case UI_FS_FOPENFILE:
		return FS_FOpenFileByMode( VMA(1), VMA(2), args[3] );

	case UI_FS_READ:
		FS_Read2( VMA(1), args[2], args[3] );
		return 0;

	case UI_FS_WRITE:
		FS_Write( VMA(1), args[2], args[3] );
		return 0;

	case UI_FS_FCLOSEFILE:
		FS_FCloseFile( args[1] );
		return 0;

	case UI_FS_GETFILELIST:
		return FS_GetFileList( VMA(1), VMA(2), VMA(3), args[4] );

	case UI_FS_SEEK:
		return FS_Seek( args[1], args[2], args[3] );
	
	case UI_R_REGISTERMODEL:
		return re.RegisterModel( VMA(1) );

	case UI_R_REGISTERSKIN:
		return re.RegisterSkin( VMA(1) );

	case UI_R_REGISTERSHADERNOMIP:
		return re.RegisterShaderNoMip( VMA(1) );

	case UI_R_CLEARSCENE:
		re.ClearScene();
		return 0;

	case UI_R_ADDREFENTITYTOSCENE:
		re.AddRefEntityToScene( VMA(1) );
		return 0;

	case UI_R_ADDPOLYTOSCENE:
		re.AddPolyToScene( args[1], args[2], VMA(3), 1 );
		return 0;

	case UI_R_ADDLIGHTTOSCENE:
		re.AddLightToScene( VMA(1), VMF(2), VMF(3), VMF(4), VMF(5) );
		return 0;

	case UI_R_RENDERSCENE:
		re.RenderScene( VMA(1) );
		return 0;

	case UI_R_SETCOLOR:
		re.SetColor( VMA(1) );
		return 0;

	case UI_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 UI_R_MODELBOUNDS:
		re.ModelBounds( args[1], VMA(2), VMA(3) );
		return 0;

	case UI_UPDATESCREEN:
		SCR_UpdateScreen();
		return 0;

	case UI_CM_LERPTAG:
		re.LerpTag( VMA(1), args[2], args[3], args[4], VMF(5), VMA(6) );
		return 0;

	case UI_S_REGISTERSOUND:
		return S_RegisterSound( VMA(1), args[2] );

	case UI_S_STARTLOCALSOUND:
		S_StartLocalSound( args[1], args[2] );
		return 0;

	case UI_KEY_KEYNUMTOSTRINGBUF:
		Key_KeynumToStringBuf( args[1], VMA(2), args[3] );
		return 0;

	case UI_KEY_GETBINDINGBUF:
		Key_GetBindingBuf( args[1], VMA(2), args[3] );
		return 0;

	case UI_KEY_SETBINDING:
		Key_SetBinding( args[1], VMA(2) );
		return 0;

	case UI_KEY_ISDOWN:
		return Key_IsDown( args[1] );

	case UI_KEY_GETOVERSTRIKEMODE:
		return Key_GetOverstrikeMode();

	case UI_KEY_SETOVERSTRIKEMODE:
		Key_SetOverstrikeMode( args[1] );
		return 0;

	case UI_KEY_CLEARSTATES:
		Key_ClearStates();
		return 0;

	case UI_KEY_GETCATCHER:
		return Key_GetCatcher();

	case UI_KEY_SETCATCHER:
		Key_SetCatcher( args[1] );
		return 0;

	case UI_GETCLIPBOARDDATA:
		GetClipboardData( VMA(1), args[2] );
		return 0;

	case UI_GETCLIENTSTATE:
		GetClientState( VMA(1) );
		return 0;		

	case UI_GETGLCONFIG:
		CL_GetGlconfig( VMA(1) );
		return 0;

	case UI_GETCONFIGSTRING:
		return GetConfigString( args[1], VMA(2), args[3] );

	case UI_LAN_LOADCACHEDSERVERS:
		LAN_LoadCachedServers();
		return 0;

	case UI_LAN_SAVECACHEDSERVERS:
		LAN_SaveServersToCache();
		return 0;

	case UI_LAN_ADDSERVER:
		return LAN_AddServer(args[1], VMA(2), VMA(3));

	case UI_LAN_REMOVESERVER:
		LAN_RemoveServer(args[1], VMA(2));
		return 0;

	case UI_LAN_GETPINGQUEUECOUNT:
		return LAN_GetPingQueueCount();

	case UI_LAN_CLEARPING:
		LAN_ClearPing( args[1] );
		return 0;

	case UI_LAN_GETPING:
		LAN_GetPing( args[1], VMA(2), args[3], VMA(4) );
		return 0;

	case UI_LAN_GETPINGINFO:
		LAN_GetPingInfo( args[1], VMA(2), args[3] );
		return 0;

	case UI_LAN_GETSERVERCOUNT:
		return LAN_GetServerCount(args[1]);

	case UI_LAN_GETSERVERADDRESSSTRING:
		LAN_GetServerAddressString( args[1], args[2], VMA(3), args[4] );
		return 0;

	case UI_LAN_GETSERVERINFO:
		LAN_GetServerInfo( args[1], args[2], VMA(3), args[4] );
		return 0;

	case UI_LAN_GETSERVERPING:
		return LAN_GetServerPing( args[1], args[2] );

	case UI_LAN_MARKSERVERVISIBLE:
		LAN_MarkServerVisible( args[1], args[2], args[3] );
		return 0;

	case UI_LAN_SERVERISVISIBLE:
		return LAN_ServerIsVisible( args[1], args[2] );

	case UI_LAN_UPDATEVISIBLEPINGS:
		return LAN_UpdateVisiblePings( args[1] );

	case UI_LAN_RESETPINGS:
		LAN_ResetPings( args[1] );
		return 0;

	case UI_LAN_SERVERSTATUS:
		return LAN_GetServerStatus( VMA(1), VMA(2), args[3] );

	case UI_LAN_COMPARESERVERS:
		return LAN_CompareServers( args[1], args[2], args[3], args[4], args[5] );

	case UI_MEMORY_REMAINING:
		return Hunk_MemoryRemaining();

	case UI_GET_CDKEY:
		CLUI_GetCDKey( VMA(1), args[2] );
		return 0;

	case UI_SET_CDKEY:
		CLUI_SetCDKey( VMA(1) );
		return 0;
	
	case UI_SET_PBCLSTATUS:
		return 0;	

	case UI_R_REGISTERFONT:
		re.RegisterFont( VMA(1), args[2], VMA(3));
		return 0;

	case UI_MEMSET:
		Com_Memset( VMA(1), args[2], args[3] );
		return 0;

	case UI_MEMCPY:
		Com_Memcpy( VMA(1), VMA(2), args[3] );
		return 0;

	case UI_STRNCPY:
		return (int)strncpy( VMA(1), VMA(2), args[3] );

	case UI_SIN:
		return FloatAsInt( sin( VMF(1) ) );

	case UI_COS:
		return FloatAsInt( cos( VMF(1) ) );

	case UI_ATAN2:
		return FloatAsInt( atan2( VMF(1), VMF(2) ) );

	case UI_SQRT:
		return FloatAsInt( sqrt( VMF(1) ) );

	case UI_FLOOR:
		return FloatAsInt( floor( VMF(1) ) );

	case UI_CEIL:
		return FloatAsInt( ceil( VMF(1) ) );

	case UI_PC_ADD_GLOBAL_DEFINE:
		return botlib_export->PC_AddGlobalDefine( VMA(1) );
	case UI_PC_LOAD_SOURCE:
		return botlib_export->PC_LoadSourceHandle( VMA(1) );
	case UI_PC_FREE_SOURCE:
		return botlib_export->PC_FreeSourceHandle( args[1] );
	case UI_PC_READ_TOKEN:
		return botlib_export->PC_ReadTokenHandle( args[1], VMA(2) );
	case UI_PC_SOURCE_FILE_AND_LINE:
		return botlib_export->PC_SourceFileAndLine( args[1], VMA(2), VMA(3) );

	case UI_S_STOPBACKGROUNDTRACK:
		S_StopBackgroundTrack();
		return 0;
	case UI_S_STARTBACKGROUNDTRACK:
		S_StartBackgroundTrack( VMA(1), VMA(2));
		return 0;

	case UI_REAL_TIME:
		return Com_RealTime( VMA(1) );

	case UI_CIN_PLAYCINEMATIC:
	  Com_DPrintf("UI_CIN_PlayCinematic\n");
	  return CIN_PlayCinematic(VMA(1), args[2], args[3], args[4], args[5], args[6]);

	case UI_CIN_STOPCINEMATIC:
	  return CIN_StopCinematic(args[1]);

	case UI_CIN_RUNCINEMATIC:
	  return CIN_RunCinematic(args[1]);

	case UI_CIN_DRAWCINEMATIC:
	  CIN_DrawCinematic(args[1]);
	  return 0;

	case UI_CIN_SETEXTENTS:
	  CIN_SetExtents(args[1], args[2], args[3], args[4], args[5]);
	  return 0;

	case UI_R_REMAP_SHADER:
		re.RemapShader( VMA(1), VMA(2), VMA(3) );
		return 0;

	case UI_VERIFY_CDKEY:
		return CL_CDKeyValidate(VMA(1), VMA(2));


		
	default:
		Com_Error( ERR_DROP, "Bad UI system trap: %i", args[0] );

	}

	return 0;
}
Пример #25
0
intptr_t CL_UISystemCalls( intptr_t *args ) {
	switch ( args[0] ) {
		//rww - alright, DO NOT EVER add a GAME/CGAME/UI generic call without adding a trap to match, and
		//all of these traps must be shared and have cases in sv_game, cl_cgame, and cl_ui. They must also
		//all be in the same order, and start at 100.
	case TRAP_MEMSET:
		Com_Memset( VMA(1), args[2], args[3] );
		return 0;

	case TRAP_MEMCPY:
		Com_Memcpy( VMA(1), VMA(2), args[3] );
		return 0;

	case TRAP_STRNCPY:
		strncpy( (char *)VMA(1), (const char *)VMA(2), args[3] );
		return args[1];

	case TRAP_SIN:
		return FloatAsInt( sin( VMF(1) ) );

	case TRAP_COS:
		return FloatAsInt( cos( VMF(1) ) );

	case TRAP_ATAN2:
		return FloatAsInt( atan2( VMF(1), VMF(2) ) );

	case TRAP_SQRT:
		return FloatAsInt( sqrt( VMF(1) ) );

	case TRAP_MATRIXMULTIPLY:
		MatrixMultiply( (vec3_t *)VMA(1), (vec3_t *)VMA(2), (vec3_t *)VMA(3) );
		return 0;

	case TRAP_ANGLEVECTORS:
		AngleVectors( (const float *)VMA(1), (float *)VMA(2), (float *)VMA(3), (float *)VMA(4) );
		return 0;

	case TRAP_PERPENDICULARVECTOR:
		PerpendicularVector( (float *)VMA(1), (const float *)VMA(2) );
		return 0;

	case TRAP_FLOOR:
		return FloatAsInt( floor( VMF(1) ) );

	case TRAP_CEIL:
		return FloatAsInt( ceil( VMF(1) ) );

	case TRAP_TESTPRINTINT:
		return 0;

	case TRAP_TESTPRINTFLOAT:
		return 0;

	case TRAP_ACOS:
		return FloatAsInt( Q_acos( VMF(1) ) );

	case TRAP_ASIN:
		return FloatAsInt( Q_asin( VMF(1) ) );

	case UI_ERROR:
		Com_Error( ERR_DROP, "%s", VMA(1) );
		return 0;

	case UI_PRINT:
		Com_Printf( "%s", VMA(1) );
		return 0;

	case UI_MILLISECONDS:
		return Sys_Milliseconds();

	case UI_CVAR_REGISTER:
		Cvar_Register( (vmCvar_t *)VMA(1), (const char *)VMA(2), (const char *)VMA(3), args[4] );
		return 0;

	case UI_CVAR_UPDATE:
		Cvar_Update( (vmCvar_t *)VMA(1) );
		return 0;

	case UI_CVAR_SET:
		Cvar_VM_Set( (const char *)VMA(1), (const char *)VMA(2), VM_UI );
		return 0;

	case UI_CVAR_VARIABLEVALUE:
		return FloatAsInt( Cvar_VariableValue( (const char *)VMA(1) ) );

	case UI_CVAR_VARIABLESTRINGBUFFER:
		Cvar_VariableStringBuffer( (const char *)VMA(1), (char *)VMA(2), args[3] );
		return 0;

	case UI_CVAR_SETVALUE:
		Cvar_VM_SetValue( (const char *)VMA(1), VMF(2), VM_UI );
		return 0;

	case UI_CVAR_RESET:
		Cvar_Reset( (const char *)VMA(1) );
		return 0;

	case UI_CVAR_CREATE:
		Cvar_Get( (const char *)VMA(1), (const char *)VMA(2), args[3] );
		return 0;

	case UI_CVAR_INFOSTRINGBUFFER:
		Cvar_InfoStringBuffer( args[1], (char *)VMA(2), args[3] );
		return 0;

	case UI_ARGC:
		return Cmd_Argc();

	case UI_ARGV:
		Cmd_ArgvBuffer( args[1], (char *)VMA(2), args[3] );
		return 0;

	case UI_CMD_EXECUTETEXT:
		Cbuf_ExecuteText( args[1], (const char *)VMA(2) );
		return 0;

	case UI_FS_FOPENFILE:
		return FS_FOpenFileByMode( (const char *)VMA(1), (int *)VMA(2), (fsMode_t)args[3] );

	case UI_FS_READ:
		FS_Read( VMA(1), args[2], args[3] );
		return 0;

	case UI_FS_WRITE:
		FS_Write( VMA(1), args[2], args[3] );
		return 0;

	case UI_FS_FCLOSEFILE:
		FS_FCloseFile( args[1] );
		return 0;

	case UI_FS_GETFILELIST:
		return FS_GetFileList( (const char *)VMA(1), (const char *)VMA(2), (char *)VMA(3), args[4] );

	case UI_R_REGISTERMODEL:
		return re->RegisterModel( (const char *)VMA(1) );

	case UI_R_REGISTERSKIN:
		return re->RegisterSkin( (const char *)VMA(1) );

	case UI_R_REGISTERSHADERNOMIP:
		return re->RegisterShaderNoMip( (const char *)VMA(1) );

	case UI_R_SHADERNAMEFROMINDEX:
		CL_R_ShaderNameFromIndex( (char *)VMA(1), args[2] );
		return 0;

	case UI_R_CLEARSCENE:
		re->ClearScene();
		return 0;

	case UI_R_ADDREFENTITYTOSCENE:
		re->AddRefEntityToScene( (const refEntity_t *)VMA(1) );
		return 0;

	case UI_R_ADDPOLYTOSCENE:
		re->AddPolyToScene( args[1], args[2], (const polyVert_t *)VMA(3), 1 );
		return 0;

	case UI_R_ADDLIGHTTOSCENE:
		re->AddLightToScene( (const float *)VMA(1), VMF(2), VMF(3), VMF(4), VMF(5) );
		return 0;

	case UI_R_RENDERSCENE:
		re->RenderScene( (const refdef_t *)VMA(1) );
		return 0;

	case UI_R_SETCOLOR:
		re->SetColor( (const float *)VMA(1) );
		return 0;

	case UI_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 UI_R_MODELBOUNDS:
		re->ModelBounds( args[1], (float *)VMA(2), (float *)VMA(3) );
		return 0;

	case UI_UPDATESCREEN:
		SCR_UpdateScreen();
		return 0;

	case UI_CM_LERPTAG:
		re->LerpTag( (orientation_t *)VMA(1), args[2], args[3], args[4], VMF(5), (const char *)VMA(6) );
		return 0;

	case UI_S_REGISTERSOUND:
		return S_RegisterSound( (const char *)VMA(1) );

	case UI_S_STARTLOCALSOUND:
		S_StartLocalSound( args[1], args[2] );
		return 0;

	case UI_KEY_KEYNUMTOSTRINGBUF:
		Key_KeynumToStringBuf( args[1], (char *)VMA(2), args[3] );
		return 0;

	case UI_KEY_GETBINDINGBUF:
		Key_GetBindingBuf( args[1], (char *)VMA(2), args[3] );
		return 0;

	case UI_KEY_SETBINDING:
		Key_SetBinding( args[1], (const char *)VMA(2) );
		return 0;

	case UI_KEY_ISDOWN:
		return Key_IsDown( args[1] );

	case UI_KEY_GETOVERSTRIKEMODE:
		return Key_GetOverstrikeMode();

	case UI_KEY_SETOVERSTRIKEMODE:
		Key_SetOverstrikeMode( (qboolean)args[1] );
		return 0;

	case UI_KEY_CLEARSTATES:
		Key_ClearStates();
		return 0;

	case UI_KEY_GETCATCHER:
		return Key_GetCatcher();

	case UI_KEY_SETCATCHER:
		CL_Key_SetCatcher( args[1] );
		return 0;

	case UI_GETCLIPBOARDDATA:
		GetClipboardData( (char *)VMA(1), args[2] );
		return 0;

	case UI_GETCLIENTSTATE:
		CL_GetClientState( (uiClientState_t *)VMA(1) );
		return 0;

	case UI_GETGLCONFIG:
		CL_GetGlconfig( (glconfig_t *)VMA(1) );
		return 0;

	case UI_GETCONFIGSTRING:
		return GetConfigString( args[1], (char *)VMA(2), args[3] );

	case UI_LAN_LOADCACHEDSERVERS:
		LAN_LoadCachedServers();
		return 0;

	case UI_LAN_SAVECACHEDSERVERS:
		LAN_SaveServersToCache();
		return 0;

	case UI_LAN_ADDSERVER:
		return LAN_AddServer(args[1], (const char *)VMA(2), (const char *)VMA(3));

	case UI_LAN_REMOVESERVER:
		LAN_RemoveServer(args[1], (const char *)VMA(2));
		return 0;

	case UI_LAN_GETPINGQUEUECOUNT:
		return LAN_GetPingQueueCount();

	case UI_LAN_CLEARPING:
		LAN_ClearPing( args[1] );
		return 0;

	case UI_LAN_GETPING:
		LAN_GetPing( args[1], (char *)VMA(2), args[3], (int *)VMA(4) );
		return 0;

	case UI_LAN_GETPINGINFO:
		LAN_GetPingInfo( args[1], (char *)VMA(2), args[3] );
		return 0;

	case UI_LAN_GETSERVERCOUNT:
		return LAN_GetServerCount(args[1]);

	case UI_LAN_GETSERVERADDRESSSTRING:
		LAN_GetServerAddressString( args[1], args[2], (char *)VMA(3), args[4] );
		return 0;

	case UI_LAN_GETSERVERINFO:
		LAN_GetServerInfo( args[1], args[2], (char *)VMA(3), args[4] );
		return 0;

	case UI_LAN_GETSERVERPING:
		return LAN_GetServerPing( args[1], args[2] );

	case UI_LAN_MARKSERVERVISIBLE:
		LAN_MarkServerVisible( args[1], args[2], (qboolean)args[3] );
		return 0;

	case UI_LAN_SERVERISVISIBLE:
		return LAN_ServerIsVisible( args[1], args[2] );

	case UI_LAN_UPDATEVISIBLEPINGS:
		return LAN_UpdateVisiblePings( args[1] );

	case UI_LAN_RESETPINGS:
		LAN_ResetPings( args[1] );
		return 0;

	case UI_LAN_SERVERSTATUS:
		return LAN_GetServerStatus( (char *)VMA(1), (char *)VMA(2), args[3] );

	case UI_LAN_COMPARESERVERS:
		return LAN_CompareServers( args[1], args[2], args[3], args[4], args[5] );

	case UI_MEMORY_REMAINING:
		return Hunk_MemoryRemaining();

	case UI_R_REGISTERFONT:
		return re->RegisterFont( (const char *)VMA(1) );

	case UI_R_FONT_STRLENPIXELS:
		return re->Font_StrLenPixels( (const char *)VMA(1), args[2], VMF(3) );

	case UI_R_FONT_STRLENCHARS:
		return re->Font_StrLenChars( (const char *)VMA(1) );

	case UI_R_FONT_STRHEIGHTPIXELS:
		return re->Font_HeightPixels( args[1], VMF(2) );

	case UI_R_FONT_DRAWSTRING:
		re->Font_DrawString( args[1], args[2], (const char *)VMA(3), (const float *) VMA(4), args[5], args[6], VMF(7) );
		return 0;

	case UI_LANGUAGE_ISASIAN:
		return re->Language_IsAsian();

	case UI_LANGUAGE_USESSPACES:
		return re->Language_UsesSpaces();

	case UI_ANYLANGUAGE_READCHARFROMSTRING:
		return re->AnyLanguage_ReadCharFromString( (const char *)VMA(1), (int *) VMA(2), (qboolean *) VMA(3) );

	case UI_PC_ADD_GLOBAL_DEFINE:
		return botlib_export->PC_AddGlobalDefine( (char *)VMA(1) );

	case UI_PC_LOAD_SOURCE:
		return botlib_export->PC_LoadSourceHandle( (const char *)VMA(1) );

	case UI_PC_FREE_SOURCE:
		return botlib_export->PC_FreeSourceHandle( args[1] );

	case UI_PC_READ_TOKEN:
		return botlib_export->PC_ReadTokenHandle( args[1], (struct pc_token_s *)VMA(2) );

	case UI_PC_SOURCE_FILE_AND_LINE:
		return botlib_export->PC_SourceFileAndLine( args[1], (char *)VMA(2), (int *)VMA(3) );

	case UI_PC_LOAD_GLOBAL_DEFINES:
		return botlib_export->PC_LoadGlobalDefines ( (char *)VMA(1) );

	case UI_PC_REMOVE_ALL_GLOBAL_DEFINES:
		botlib_export->PC_RemoveAllGlobalDefines ( );
		return 0;

	case UI_S_STOPBACKGROUNDTRACK:
		S_StopBackgroundTrack();
		return 0;

	case UI_S_STARTBACKGROUNDTRACK:
		S_StartBackgroundTrack( (const char *)VMA(1), (const char *)VMA(2), qfalse );
		return 0;

	case UI_REAL_TIME:
		return Com_RealTime( (struct qtime_s *)VMA(1) );

	case UI_CIN_PLAYCINEMATIC:
		Com_DPrintf("UI_CIN_PlayCinematic\n");
		return CIN_PlayCinematic((const char *)VMA(1), args[2], args[3], args[4], args[5], args[6]);

	case UI_CIN_STOPCINEMATIC:
		return CIN_StopCinematic(args[1]);

	case UI_CIN_RUNCINEMATIC:
		return CIN_RunCinematic(args[1]);

	case UI_CIN_DRAWCINEMATIC:
		CIN_DrawCinematic(args[1]);
		return 0;

	case UI_CIN_SETEXTENTS:
		CIN_SetExtents(args[1], args[2], args[3], args[4], args[5]);
		return 0;

	case UI_R_REMAP_SHADER:
		re->RemapShader( (const char *)VMA(1), (const char *)VMA(2), (const char *)VMA(3) );
		return 0;

	case UI_SP_GETNUMLANGUAGES:
		return SE_GetNumLanguages();

	case UI_SP_GETLANGUAGENAME:
		CL_SE_GetLanguageName( args[1], (char *)VMA(2) );
		return 0;

	case UI_SP_GETSTRINGTEXTSTRING:
		return CL_SE_GetStringTextString( (const char *)VMA(1), (char *)VMA(2), args[3] );

	case UI_G2_LISTSURFACES:
		re->G2API_ListSurfaces( (CGhoul2Info *) args[1] );
		return 0;

	case UI_G2_LISTBONES:
		re->G2API_ListBones( (CGhoul2Info *) args[1], args[2]);
		return 0;

	case UI_G2_HAVEWEGHOULMODELS:
		return re->G2API_HaveWeGhoul2Models( *((CGhoul2Info_v *)args[1]) );

	case UI_G2_SETMODELS:
		re->G2API_SetGhoul2ModelIndexes( *((CGhoul2Info_v *)args[1]),(qhandle_t *)VMA(2),(qhandle_t *)VMA(3));
		return 0;

	case UI_G2_GETBOLT:
		return re->G2API_GetBoltMatrix(*((CGhoul2Info_v *)args[1]), args[2], args[3], (mdxaBone_t *)VMA(4), (const float *)VMA(5),(const float *)VMA(6), args[7], (qhandle_t *)VMA(8), (float *)VMA(9));

	case UI_G2_GETBOLT_NOREC:
		re->G2API_BoltMatrixReconstruction( qfalse );//gG2_GBMNoReconstruct = qtrue;
		return re->G2API_GetBoltMatrix(*((CGhoul2Info_v *)args[1]), args[2], args[3], (mdxaBone_t *)VMA(4), (const float *)VMA(5),(const float *)VMA(6), args[7], (qhandle_t *)VMA(8), (float *)VMA(9));

	case UI_G2_GETBOLT_NOREC_NOROT:
		// cgame reconstructs bolt matrix, why is this different?
		re->G2API_BoltMatrixReconstruction( qfalse );//gG2_GBMNoReconstruct = qtrue;
		re->G2API_BoltMatrixSPMethod( qtrue );//gG2_GBMUseSPMethod = qtrue;
		return re->G2API_GetBoltMatrix(*((CGhoul2Info_v *)args[1]), args[2], args[3], (mdxaBone_t *)VMA(4), (const float *)VMA(5),(const float *)VMA(6), args[7], (qhandle_t *)VMA(8), (float *)VMA(9));

	case UI_G2_INITGHOUL2MODEL:
#ifdef _FULL_G2_LEAK_CHECKING
		g_G2AllocServer = 0;
#endif
		return	re->G2API_InitGhoul2Model((CGhoul2Info_v **)VMA(1), (const char *)VMA(2), args[3], (qhandle_t) args[4], (qhandle_t) args[5], args[6], args[7]);

	case UI_G2_COLLISIONDETECT:
	case UI_G2_COLLISIONDETECTCACHE:
		return 0; //not supported for ui

	case UI_G2_ANGLEOVERRIDE:
		return re->G2API_SetBoneAngles(*((CGhoul2Info_v *)args[1]), args[2], (const char *)VMA(3), (float *)VMA(4), args[5], (const Eorientations) args[6], (const Eorientations) args[7], (const Eorientations) args[8], (qhandle_t *)VMA(9), args[10], args[11] );

	case UI_G2_CLEANMODELS:
#ifdef _FULL_G2_LEAK_CHECKING
		g_G2AllocServer = 0;
#endif
		re->G2API_CleanGhoul2Models((CGhoul2Info_v **)VMA(1));
		//	re->G2API_CleanGhoul2Models((CGhoul2Info_v **)args[1]);
		return 0;

	case UI_G2_PLAYANIM:
		return re->G2API_SetBoneAnim(*((CGhoul2Info_v *)args[1]), args[2], (const char *)VMA(3), args[4], args[5], args[6], VMF(7), args[8], VMF(9), args[10]);

	case UI_G2_GETBONEANIM:
		{
			CGhoul2Info_v &g2 = *((CGhoul2Info_v *)args[1]);
			int modelIndex = args[10];

			return re->G2API_GetBoneAnim(g2, modelIndex, (const char*)VMA(2), args[3], (float *)VMA(4), (int *)VMA(5), (int *)VMA(6), (int *)VMA(7), (float *)VMA(8), (int *)VMA(9));
		}

	case UI_G2_GETBONEFRAME:
		{ //rwwFIXMEFIXME: Just make a G2API_GetBoneFrame func too. This is dirty.
			CGhoul2Info_v &g2 = *((CGhoul2Info_v *)args[1]);
			int modelIndex = args[6];
			int iDontCare1 = 0, iDontCare2 = 0, iDontCare3 = 0;
			float fDontCare1 = 0;

			return re->G2API_GetBoneAnim(g2, modelIndex, (const char*)VMA(2), args[3], (float *)VMA(4), &iDontCare1, &iDontCare2, &iDontCare3, &fDontCare1, (int *)VMA(5));
		}

	case UI_G2_GETGLANAME:
		//	return (int)G2API_GetGLAName(*((CGhoul2Info_v *)VMA(1)), args[2]);
		{
			char *point = ((char *)VMA(3));
			char *local;
			local = re->G2API_GetGLAName(*((CGhoul2Info_v *)args[1]), args[2]);
			if (local)
			{
				strcpy(point, local);
			}
		}
		return 0;

	case UI_G2_COPYGHOUL2INSTANCE:
		return (int)re->G2API_CopyGhoul2Instance(*((CGhoul2Info_v *)args[1]), *((CGhoul2Info_v *)args[2]), args[3]);

	case UI_G2_COPYSPECIFICGHOUL2MODEL:
		re->G2API_CopySpecificG2Model(*((CGhoul2Info_v *)args[1]), args[2], *((CGhoul2Info_v *)args[3]), args[4]);
		return 0;

	case UI_G2_DUPLICATEGHOUL2INSTANCE:
#ifdef _FULL_G2_LEAK_CHECKING
		g_G2AllocServer = 0;
#endif
		re->G2API_DuplicateGhoul2Instance(*((CGhoul2Info_v *)args[1]), (CGhoul2Info_v **)VMA(2));
		return 0;

	case UI_G2_HASGHOUL2MODELONINDEX:
		return (int)re->G2API_HasGhoul2ModelOnIndex((CGhoul2Info_v **)VMA(1), args[2]);
		//return (int)G2API_HasGhoul2ModelOnIndex((CGhoul2Info_v **)args[1], args[2]);

	case UI_G2_REMOVEGHOUL2MODEL:
#ifdef _FULL_G2_LEAK_CHECKING
		g_G2AllocServer = 0;
#endif
		return (int)re->G2API_RemoveGhoul2Model((CGhoul2Info_v **)VMA(1), args[2]);
		//return (int)G2API_RemoveGhoul2Model((CGhoul2Info_v **)args[1], args[2]);

	case UI_G2_ADDBOLT:
		return re->G2API_AddBolt(*((CGhoul2Info_v *)args[1]), args[2], (const char *)VMA(3));

	case UI_G2_SETBOLTON:
		re->G2API_SetBoltInfo(*((CGhoul2Info_v *)args[1]), args[2], args[3]);
		return 0;

	case UI_G2_SETROOTSURFACE:
		return re->G2API_SetRootSurface(*((CGhoul2Info_v *)args[1]), args[2], (const char *)VMA(3));

	case UI_G2_SETSURFACEONOFF:
		return re->G2API_SetSurfaceOnOff(*((CGhoul2Info_v *)args[1]), (const char *)VMA(2), /*(const int)VMA(3)*/args[3]);

	case UI_G2_SETNEWORIGIN:
		return re->G2API_SetNewOrigin(*((CGhoul2Info_v *)args[1]), /*(const int)VMA(2)*/args[2]);

	case UI_G2_GETTIME:
		return re->G2API_GetTime(0);

	case UI_G2_SETTIME:
		re->G2API_SetTime(args[1], args[2]);
		return 0;

	case UI_G2_SETRAGDOLL:
		return 0; //not supported for ui
		break;

	case UI_G2_ANIMATEG2MODELS:
		return 0; //not supported for ui
		break;

	case UI_G2_SETBONEIKSTATE:
		return re->G2API_SetBoneIKState(*((CGhoul2Info_v *)args[1]), args[2], (const char *)VMA(3), args[4], (sharedSetBoneIKStateParams_t *)VMA(5));

	case UI_G2_IKMOVE:
		return re->G2API_IKMove(*((CGhoul2Info_v *)args[1]), args[2], (sharedIKMoveParams_t *)VMA(3));

	case UI_G2_GETSURFACENAME:
		{ //Since returning a pointer in such a way to a VM seems to cause MASSIVE FAILURE<tm>, we will shove data into the pointer the vm passes instead
			char *point = ((char *)VMA(4));
			char *local;
			int modelindex = args[3];

			CGhoul2Info_v &g2 = *((CGhoul2Info_v *)args[1]);

			local = re->G2API_GetSurfaceName(g2, modelindex, args[2]);
			if (local)
			{
				strcpy(point, local);
			}
		}

		return 0;
	case UI_G2_SETSKIN:
		{
			CGhoul2Info_v &g2 = *((CGhoul2Info_v *)args[1]);
			int modelIndex = args[2];

			return re->G2API_SetSkin(g2, modelIndex, args[3], args[4]);
		}

	case UI_G2_ATTACHG2MODEL:
		{
			CGhoul2Info_v *g2From = ((CGhoul2Info_v *)args[1]);
			CGhoul2Info_v *g2To = ((CGhoul2Info_v *)args[3]);

			return re->G2API_AttachG2Model(*g2From, args[2], *g2To, args[4], args[5]);
		}

	default:
		Com_Error( ERR_DROP, "Bad UI system trap: %ld", (long int) args[0] );

	}

	return 0;
}
Пример #26
0
/*
* CL_ParseDownload
* Handles download message from the server.
* Writes data to the file and requests next download block.
*/
static void CL_ParseDownload( msg_t *msg )
{
	size_t size, offset;
	char *svFilename;

	// read the data
	svFilename = MSG_ReadString( msg );
	offset = MSG_ReadLong( msg );
	size = MSG_ReadLong( msg );

	if( msg->readcount + size > msg->cursize )
	{
		Com_Printf( "Error: Download message didn't have as much data as it promised\n" );
		CL_RetryDownload();
		return;
	}

	if( !cls.download.filenum )
	{
		Com_Printf( "Error: Download message while not dowloading\n" );
		msg->readcount += size;
		return;
	}

	if( Q_stricmp( cls.download.name, svFilename ) )
	{
		Com_Printf( "Error: Download message for wrong file\n" );
		msg->readcount += size;
		return;
	}

	if( offset+size > cls.download.size )
	{
		Com_Printf( "Error: Invalid download message\n" );
		msg->readcount += size;
		CL_RetryDownload();
		return;
	}

	if( cls.download.offset != offset )
	{
		Com_Printf( "Error: Download message for wrong position\n" );
		msg->readcount += size;
		CL_RetryDownload();
		return;
	}

	FS_Write( msg->data + msg->readcount, size, cls.download.filenum );
	msg->readcount += size;
	cls.download.offset += size;
	cls.download.percent = (double)cls.download.offset / (double)cls.download.size;
	clamp( cls.download.percent, 0, 1 );

	Cvar_ForceSet( "cl_download_percent", va( "%.1f", cls.download.percent * 100 ) );

	if( cls.download.offset < cls.download.size )
	{
		cls.download.timeout = Sys_Milliseconds() + 3000;
		cls.download.retries = 0;

		CL_AddReliableCommand( va( "nextdl \"%s\" %i", cls.download.name, cls.download.offset ) );
	}
	else
	{
		Com_Printf( "Download complete: %s\n", cls.download.name );

		CL_DownloadComplete();

		// let the server know we're done
		CL_AddReliableCommand( va( "nextdl \"%s\" %i", cls.download.name, -1 ) );

		CL_StopServerDownload();

		CL_DownloadDone();
	}
}
Пример #27
0
static void CLQW_ParseDownload( QMsg& message ) {
	// read the data
	int size = message.ReadShort();
	int percent = message.ReadByte();

	if ( clc.demoplaying ) {
		if ( size > 0 ) {
			message.readcount += size;
		}
		return;	// not in demo playback
	}

	if ( size == -1 ) {
		common->Printf( "File not found.\n" );
		if ( clc.download ) {
			common->Printf( "cls.download shouldn't have been set\n" );
			FS_FCloseFile( clc.download );
			clc.download = 0;
		}
		CLQW_RequestNextDownload();
		return;
	}

	// open the file if not opened yet
	if ( !clc.download ) {
		if ( String::NCmp( clc.downloadTempName, "skins/", 6 ) ) {
			clc.download = FS_FOpenFileWrite( clc.downloadTempName );
		} else {
			char name[ 1024 ];
			sprintf( name, "qw/%s", clc.downloadTempName );
			clc.download = FS_SV_FOpenFileWrite( name );
		}

		if ( !clc.download ) {
			message.readcount += size;
			common->Printf( "Failed to open %s\n", clc.downloadTempName );
			CLQW_RequestNextDownload();
			return;
		}
	}

	FS_Write( message._data + message.readcount, size, clc.download );
	message.readcount += size;

	if ( percent != 100 ) {
		// change display routines by zoid
		// request next block
		clc.downloadPercent = percent;

		CL_AddReliableCommand( "nextdl" );
	} else {
		FS_FCloseFile( clc.download );

		// rename the temp file to it's final name
		if ( String::Cmp( clc.downloadTempName, clc.downloadName ) ) {
			if ( String::NCmp( clc.downloadTempName,"skins/",6 ) ) {
				FS_Rename( clc.downloadTempName, clc.downloadName );
			} else {
				char oldn[ MAX_OSPATH ];
				sprintf( oldn, "qw/%s", clc.downloadTempName );
				char newn[ MAX_OSPATH ];
				sprintf( newn, "qw/%s", clc.downloadName );
				FS_SV_Rename( oldn, newn );
			}
		}

		clc.download = 0;
		clc.downloadPercent = 0;

		// get another file if needed

		CLQW_RequestNextDownload();
	}
}
Пример #28
0
/*
====================
CL_UISystemCalls

The ui module is making a system call
====================
*/
intptr_t CL_UISystemCalls( intptr_t *args ) {
	switch( args[0] ) {
	case UI_ERROR:
		Com_Error( ERR_DROP, "%s", (const char*)VMA(1) );
		return 0;

	case UI_PRINT:
		Com_Printf( "%s", (const char*)VMA(1) );
		return 0;

	case UI_MILLISECONDS:
		return Sys_Milliseconds();

	case UI_CVAR_REGISTER:
		Cvar_Register( VMA(1), VMA(2), VMA(3), args[4] ); 
		return 0;

	case UI_CVAR_UPDATE:
		Cvar_Update( VMA(1) );
		return 0;

	case UI_CVAR_SET:
		Cvar_SetSafe( VMA(1), VMA(2) );
		return 0;

	case UI_CVAR_VARIABLEVALUE:
		return FloatAsInt( Cvar_VariableValue( VMA(1) ) );

	case UI_CVAR_VARIABLESTRINGBUFFER:
		Cvar_VariableStringBuffer( VMA(1), VMA(2), args[3] );
		return 0;

	case UI_CVAR_SETVALUE:
		Cvar_SetValueSafe( VMA(1), VMF(2) );
		return 0;

	case UI_CVAR_RESET:
		Cvar_Reset( VMA(1) );
		return 0;

	case UI_CVAR_CREATE:
		Cvar_Get( VMA(1), VMA(2), args[3] );
		return 0;

	case UI_CVAR_INFOSTRINGBUFFER:
		Cvar_InfoStringBuffer( args[1], VMA(2), args[3] );
		return 0;

	case UI_ARGC:
		return Cmd_Argc();

	case UI_ARGV:
		Cmd_ArgvBuffer( args[1], VMA(2), args[3] );
		return 0;

	case UI_CMD_EXECUTETEXT:
		if(args[1] == EXEC_NOW
		&& (!strncmp(VMA(2), "snd_restart", 11)
		|| !strncmp(VMA(2), "vid_restart", 11)
		|| !strncmp(VMA(2), "quit", 5)))
		{
			Com_Printf (S_COLOR_YELLOW "turning EXEC_NOW '%.11s' into EXEC_INSERT\n", (const char*)VMA(2));
			args[1] = EXEC_INSERT;
		}
		Cbuf_ExecuteText( args[1], VMA(2) );
		return 0;

	case UI_FS_FOPENFILE:
		return FS_FOpenFileByMode( VMA(1), VMA(2), args[3] );

	case UI_FS_READ:
		FS_Read2( VMA(1), args[2], args[3] );
		return 0;

	case UI_FS_WRITE:
		FS_Write( VMA(1), args[2], args[3] );
		return 0;

	case UI_FS_FCLOSEFILE:
		FS_FCloseFile( args[1] );
		return 0;

	case UI_FS_GETFILELIST:
		return FS_GetFileList( VMA(1), VMA(2), VMA(3), args[4] );
	
	case UI_R_REGISTERMODEL:
		return re.RegisterModel( VMA(1) );

	case UI_R_REGISTERSKIN:
		return re.RegisterSkin( VMA(1) );

	case UI_R_REGISTERSHADERNOMIP:
		return re.RegisterShaderNoMip( VMA(1) );

	case UI_R_CLEARSCENE:
		re.ClearScene();
		return 0;

	case UI_R_ADDREFENTITYTOSCENE:
		re.AddRefEntityToScene( VMA(1) );
		return 0;

	case UI_R_ADDPOLYTOSCENE:
		re.AddPolyToScene( args[1], args[2], VMA(3), 1 );
		return 0;

	case UI_R_ADDLIGHTTOSCENE:
		re.AddLightToScene( VMA(1), VMF(2), VMF(3), VMF(4), VMF(5) );
		return 0;

	case UI_R_RENDERSCENE:
		re.RenderScene( VMA(1) );
		return 0;

	case UI_R_SETCOLOR:
		re.SetColor( VMA(1) );
		return 0;

	case UI_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 UI_R_MODELBOUNDS:
		re.ModelBounds( args[1], VMA(2), VMA(3) );
		return 0;

	case UI_UPDATESCREEN:
		SCR_UpdateScreen();
		return 0;

	case UI_CM_LERPTAG:
		re.LerpTag( VMA(1), args[2], args[3], args[4], VMF(5), VMA(6) );
		return 0;

	case UI_S_REGISTERSOUND:
		return S_RegisterSound( VMA(1), args[2] );

	case UI_S_STARTLOCALSOUND:
		S_StartLocalSound( args[1], args[2] );
		return 0;

	case UI_KEY_KEYNUMTOSTRINGBUF:
		Key_KeynumToStringBuf( args[1], VMA(2), args[3] );
		return 0;

	case UI_KEY_GETBINDINGBUF:
		Key_GetBindingBuf( args[1], VMA(2), args[3] );
		return 0;

	case UI_KEY_SETBINDING:
		Key_SetBinding( args[1], VMA(2) );
		return 0;

	case UI_KEY_ISDOWN:
		return Key_IsDown( args[1] );

	case UI_KEY_GETOVERSTRIKEMODE:
		return Key_GetOverstrikeMode();

	case UI_KEY_SETOVERSTRIKEMODE:
		Key_SetOverstrikeMode( args[1] );
		return 0;

	case UI_KEY_CLEARSTATES:
		Key_ClearStates();
		return 0;

	case UI_KEY_GETCATCHER:
		return Key_GetCatcher();

	case UI_KEY_SETCATCHER:
		// Don't allow the ui module to close the console
		Key_SetCatcher( args[1] | ( Key_GetCatcher( ) & KEYCATCH_CONSOLE ) );
		return 0;

	case UI_GETCLIPBOARDDATA:
		CL_GetClipboardData( VMA(1), args[2] );
		return 0;

	case UI_GETCLIENTSTATE:
		GetClientState( VMA(1) );
		return 0;		

	case UI_GETGLCONFIG:
		CL_GetGlconfig( VMA(1) );
		return 0;

	case UI_GETCONFIGSTRING:
		return GetConfigString( args[1], VMA(2), args[3] );

	case UI_LAN_LOADCACHEDSERVERS:
		LAN_LoadCachedServers();
		return 0;

	case UI_LAN_SAVECACHEDSERVERS:
		LAN_SaveServersToCache();
		return 0;

	case UI_LAN_ADDSERVER:
		return LAN_AddServer(args[1], VMA(2), VMA(3));

	case UI_LAN_REMOVESERVER:
		LAN_RemoveServer(args[1], VMA(2));
		return 0;

	case UI_LAN_GETPINGQUEUECOUNT:
		return LAN_GetPingQueueCount();

	case UI_LAN_CLEARPING:
		LAN_ClearPing( args[1] );
		return 0;

	case UI_LAN_GETPING:
		LAN_GetPing( args[1], VMA(2), args[3], VMA(4) );
		return 0;

	case UI_LAN_GETPINGINFO:
		LAN_GetPingInfo( args[1], VMA(2), args[3] );
		return 0;

	case UI_LAN_GETSERVERCOUNT:
		return LAN_GetServerCount(args[1]);

	case UI_LAN_GETSERVERADDRESSSTRING:
		LAN_GetServerAddressString( args[1], args[2], VMA(3), args[4] );
		return 0;

	case UI_LAN_GETSERVERINFO:
		LAN_GetServerInfo( args[1], args[2], VMA(3), args[4] );
		return 0;

	case UI_LAN_GETSERVERPING:
		return LAN_GetServerPing( args[1], args[2] );

	case UI_LAN_MARKSERVERVISIBLE:
		LAN_MarkServerVisible( args[1], args[2], args[3] );
		return 0;

	case UI_LAN_SERVERISVISIBLE:
		return LAN_ServerIsVisible( args[1], args[2] );

	case UI_LAN_UPDATEVISIBLEPINGS:
		return LAN_UpdateVisiblePings( args[1] );

	case UI_LAN_RESETPINGS:
		LAN_ResetPings( args[1] );
		return 0;

	case UI_LAN_SERVERSTATUS:
		return LAN_GetServerStatus( VMA(1), VMA(2), args[3] );

	case UI_LAN_COMPARESERVERS:
		return LAN_CompareServers( args[1], args[2], args[3], args[4], args[5] );

	case UI_MEMORY_REMAINING:
		return Hunk_MemoryRemaining();

	case UI_R_REGISTERFONT:
		re.RegisterFont( VMA(1), args[2], VMA(3));
		return 0;

	case UI_MEMSET:
		Com_Memset( VMA(1), args[2], args[3] );
		return 0;

	case UI_MEMCPY:
		Com_Memcpy( VMA(1), VMA(2), args[3] );
		return 0;

	case UI_STRNCPY:
		strncpy( VMA(1), VMA(2), args[3] );
		return args[1];

	case UI_SIN:
		return FloatAsInt( sin( VMF(1) ) );

	case UI_COS:
		return FloatAsInt( cos( VMF(1) ) );

	case UI_ATAN2:
		return FloatAsInt( atan2( VMF(1), VMF(2) ) );

	case UI_SQRT:
		return FloatAsInt( sqrt( VMF(1) ) );

	case UI_FLOOR:
		return FloatAsInt( floor( VMF(1) ) );

	case UI_CEIL:
		return FloatAsInt( ceil( VMF(1) ) );

	case UI_S_STOPBACKGROUNDTRACK:
		S_StopBackgroundTrack();
		return 0;
	case UI_S_STARTBACKGROUNDTRACK:
		S_StartBackgroundTrack( VMA(1), VMA(2));
		return 0;

	case UI_REAL_TIME:
		return Com_RealTime( VMA(1) );

	case UI_CIN_PLAYCINEMATIC:
	  Com_DPrintf("UI_CIN_PlayCinematic\n");
	  return CIN_PlayCinematic(VMA(1), args[2], args[3], args[4], args[5], args[6]);

	case UI_CIN_STOPCINEMATIC:
	  return CIN_StopCinematic(args[1]);

	case UI_CIN_RUNCINEMATIC:
	  return CIN_RunCinematic(args[1]);

	case UI_CIN_DRAWCINEMATIC:
	  CIN_DrawCinematic(args[1]);
	  return 0;

	case UI_CIN_SETEXTENTS:
	  CIN_SetExtents(args[1], args[2], args[3], args[4], args[5]);
	  return 0;

	case UI_R_REMAP_SHADER:
		re.RemapShader( VMA(1), VMA(2), VMA(3) );
		return 0;
		
	default:
		Com_Error( ERR_DROP, "Bad UI system trap: %ld", (long int) args[0] );

	}

	return 0;
}
Пример #29
0
/*
===============
SafeFS_Write
===============
*/
static ID_INLINE void SafeFS_Write( const void *buffer, int len, fileHandle_t f )
{
  if( FS_Write( buffer, len, f ) < len )
    Com_Error( ERR_DROP, "Failed to write avi file" );
}
Пример #30
0
kal_bool BT_PcmLoopbackTest(void)
{
   kal_int16 i, count = 0;
   kal_uint16 *buf;
   kal_uint32 len = 0, acmLen = 0;
   kal_int32 magDB = 0;
   TD_Handle hdl;
   kal_uint16 *rb_base;
   
   AM_BluetoothOn(2);//2:open earphone mode, 1: open cordless mode
   AM_FlushQFunction();
   
   kal_prompt_trace(MOD_L1SP, "after set,DP_VOL_OUT_PCM= %d",*DP_VOL_OUT_PCM);
   
   /*initialize*/
   rb_base = (kal_uint16 *)get_ctrl_buffer(BTLB_BUF_LEN << 1);
   Media_SetBuffer( rb_base, BTLB_BUF_LEN );
   TD_Init( &hdl, TARGET_TONE, BLOCK_SIZE);

#ifdef BTLB_DEBUG
   pcmDebugCnt = 0;
   pcmDebugPtr = btlbPcmDebugBuf;
#endif
   /*start tone_play and record*/
   
   KT_Play(TARGET_TONE, 0, 0); /*play single tone , continuous play*/
   Media_Record(MEDIA_FORMAT_PCM_8K, BTLB_Handler, (void *)0);

   for (i = 0 ; i < 100 ; i++)/*if delay is large, we should enlarge this waiting*/
   {
      Media_GetReadBuffer(&buf ,&len);
      if ( len==0 )
         kal_sleep_task(1);
      else{
         if ( (len + acmLen) >= BLOCK_SIZE ){/*acumulated length >= BLOCK_SIZE*/
            len = BLOCK_SIZE - acmLen;/*recount samples to fit block*/
         }
         TD_ProcessBlock(&hdl, (kal_int16 *)buf, len);
#ifdef BTLB_DEBUG
{
         int j;
         for(j = 0 ; j < len ; j++ )
            if( pcmDebugCnt < 80000 )
            {
               *pcmDebugPtr++ = buf[j];
               pcmDebugCnt ++;
            }
}
#endif
         Media_ReadDataDone( len );
         acmLen += len;
         if ( acmLen >= BLOCK_SIZE){
            magDB = TD_GetMagnitudeDB( &hdl );
            kal_prompt_trace( MOD_L1SP, "magDB = %d", magDB);
            if( magDB > BTLB_TONE_MAG_DB_THRESHOLD )
              count ++;
            TD_Reset( &hdl );
            acmLen=0;//reset
         
            if ( count > 2)
               break;
         }
      }
   }

#ifdef BTLB_DEBUG
{
      int file_handle;
      kal_prompt_trace(MOD_L1SP, "prepare to dump pcm file");
      kal_wsprintf(debugFile, "d:\\BTLBdebug.pcm");
      file_handle = FS_Open(debugFile, FS_CREATE);
      if(file_handle > 0) 
      { 
         FS_Write( file_handle, (void *)btlbPcmDebugBuf, pcmDebugCnt << 1, NULL );
         FS_Close(file_handle);
         kal_prompt_trace(MOD_L1SP, "finish dump pcm file BTLBdebug.pcm");
      }
      else{
      	kal_prompt_trace(MOD_L1SP, "unable to dump file");
      }
      
}
#endif
   KT_StopAndWait();
   Media_Stop();
   AM_BluetoothOff();//close earphone mode
   /*close loopback path, should be removed in the future*/
   //*AFE_VAC_CON1 &= ~0x02;
   
   free_ctrl_buffer( rb_base );
   
   if ( count > 2){
      return true;
   }else
      return false;
}