/* * S_OpenBackgroundTrackProc */ static void *S_OpenBackgroundTrackProc( void *ptrack ) { bgTrack_t *track = ptrack; unsigned start; bool buffering; S_OpenMusicTrack( track, &buffering ); s_bgTrackBuffering = buffering; start = trap_Milliseconds(); while( s_bgTrackBuffering ) { if( trap_Milliseconds() > start + BACKGROUND_TRACK_BUFFERING_TIMEOUT ) { } else if( trap_FS_Eof( track->file ) ) { } else { if( trap_FS_Seek( track->file, BACKGROUND_TRACK_BUFFERING_SIZE, FS_SEEK_SET ) < 0 ) continue; trap_FS_Seek( track->file, 0, FS_SEEK_SET ); } // in case we delayed openening to let the stream cache for a while, // start actually reading from it now if( !track->open( track, NULL ) ) { track->ignore = true; } s_bgTrackBuffering = false; } s_bgTrack = track; s_bgTrackLoading = false; return NULL; }
/* ==================== CG_DrawInformation Draw all the status / pacifier stuff during level loading ==================== */ void CG_DrawInformation(qboolean forcerefresh) { static int lastcalled = 0; if (lastcalled && (trap_Milliseconds() - lastcalled < 500)) { return; } lastcalled = trap_Milliseconds(); if (cg.snap) { return; // we are in the world, no need to draw information } CG_DrawConnectScreen(qfalse, forcerefresh); }
// Remove the least recently used sound effect from memory static bool buffer_evict() { int i; int candinate = -1; int candinate_value = trap_Milliseconds(); for( i = 0; i < MAX_SFX; i++ ) { if( knownSfx[i].filename[0] == '\0' || !knownSfx[i].inMemory || knownSfx[i].isLocked ) continue; if( knownSfx[i].used < candinate_value ) { candinate = i; candinate_value = knownSfx[i].used; } } if( candinate != -1 ) { return S_UnloadBuffer( &knownSfx[candinate] ); } return false; }
// Free up a window reservation void CG_windowFree(cg_window_t *w) { int i, j; cg_windowHandler_t *wh = &cg.winHandler; if(w == NULL) return; if(w->effects >= WFX_FADEIN && w->state != WSTATE_OFF && w->inuse == qtrue) { w->state = WSTATE_SHUTDOWN; w->time = trap_Milliseconds(); return; } for(i=0; i<wh->numActiveWindows; i++) { if(w == &wh->window[wh->activeWindows[i]]) { for(j=i; j<wh->numActiveWindows; j++) { if(j+1 < wh->numActiveWindows) { wh->activeWindows[j] = wh->activeWindows[j+1]; } } w->id = WID_NONE; w->inuse = qfalse; w->state = WSTATE_OFF; CG_removeStrings(w); wh->numActiveWindows--; break; } } }
/* * source_setup */ static void source_setup( src_t *src, sfx_t *sfx, int priority, int entNum, int channel, float fvol, float attenuation ) { ALuint buffer; // Mark the SFX as used, and grab the raw AL buffer S_UseBuffer( sfx ); buffer = S_GetALBuffer( sfx ); clamp_low( attenuation, 0.0f ); src->lastUse = trap_Milliseconds(); src->sfx = sfx; src->priority = priority; src->entNum = entNum; src->channel = channel; src->fvol = fvol; src->attenuation = attenuation; src->isActive = qtrue; src->isLocked = qfalse; src->isLooping = qfalse; src->isTracking = qfalse; VectorClear( src->origin ); VectorClear( src->velocity ); qalSourcefv( src->source, AL_POSITION, vec3_origin ); qalSourcefv( src->source, AL_VELOCITY, vec3_origin ); qalSourcef( src->source, AL_GAIN, fvol * s_volume->value ); qalSourcei( src->source, AL_SOURCE_RELATIVE, AL_FALSE ); qalSourcei( src->source, AL_LOOPING, AL_FALSE ); qalSourcei( src->source, AL_BUFFER, buffer ); qalSourcef( src->source, AL_REFERENCE_DISTANCE, s_attenuation_refdistance ); qalSourcef( src->source, AL_MAX_DISTANCE, s_attenuation_maxdistance ); qalSourcef( src->source, AL_ROLLOFF_FACTOR, attenuation ); }
void G_Explodefragnade(gentity_t *ent, vec3_t origin) { vec3_t pos, dir; long i; //int damage; float mag; trace_t tr; gentity_t *target; srand(trap_Milliseconds()); for(i = 0;i < GRENADE_SHRAPNEL_COUNT;i++) { gentity_t *shrapnel; dir[0] = (int) (((double) rand() / ((double) (RAND_MAX) + (double) (1))) * GRENADE_SHRAPNEL_MAG) - (GRENADE_SHRAPNEL_MAG / 2); dir[1] = (int) (((double) rand() / ((double) (RAND_MAX) + (double) (1))) * GRENADE_SHRAPNEL_MAG) - (GRENADE_SHRAPNEL_MAG / 2); dir[2] = (int) (((double) rand() / ((double) (RAND_MAX) + (double) (1))) * GRENADE_SHRAPNEL_MAG) - (GRENADE_SHRAPNEL_MAG / 2); //VectorNormalize( dir ); mag = abs(dir[0]) + abs(dir[1]) + abs(dir[2]); dir[0] = dir[0] / mag; dir[1] = dir[1] / mag; dir[2] = dir[2] / mag; VectorMA(origin, GRENADE_SHRAPNEL_RANGE, dir, pos); //trap_Trace( &tr, origin, NULL, NULL, pos, ent->r.ownerNum, MASK_SHOT ); target = &g_entities[tr.entityNum]; //damage = Distance(tr.endpos,origin) / GRENADE_SHRAPNEL_RANGE * GRENADE_SHRAPNEL_DAMAGE; shrapnel = fire_shrapnel(ent, origin, dir); //if(target->health > 0 && target->takedamage) //{ // G_Damage( target, ent, ent, dir, tr.endpos, damage, 0, MOD_GRENADE ); //} } }
static JSBool sys_milliseconds(JSContext *cx, unsigned argc, jsval *vp) { jsval rval; JS_NewNumberValue(cx, trap_Milliseconds(), &rval); JS_SET_RVAL(cx, vp, rval); return JS_TRUE; }
void G_StoreClientPosition(gentity_t *ent) { int top, currentTime; if (!IS_ACTIVE(ent)) { return; } top = ent->client->topMarker; // new frame, mark the old marker's time as the end of the last frame if (ent->client->clientMarkers[top].time < level.time) { ent->client->clientMarkers[top].time = level.previousTime; top = ent->client->topMarker = ent->client->topMarker == MAX_CLIENT_MARKERS - 1 ? 0 : ent->client->topMarker + 1; } currentTime = level.previousTime + trap_Milliseconds() - level.frameTime; if (currentTime > level.time) { // owwie, we just went into the next frame... let's push them back currentTime = level.time; } VectorCopy(ent->r.mins, ent->client->clientMarkers[top].mins); VectorCopy(ent->r.maxs, ent->client->clientMarkers[top].maxs); VectorCopy(ent->r.currentOrigin, ent->client->clientMarkers[top].origin); // OSP - these timers appear to be questionable ent->client->clientMarkers[top].servertime = level.time; ent->client->clientMarkers[top].time = currentTime; }
/* =============== G_GenerateNewConnection Generates a new connection =============== */ connectionRecord_t *G_GenerateNewConnection( gclient_t *client ) { int code = 0; int i; // this should be really random srand( trap_Milliseconds( ) ); // there is a very very small possibility that this // will loop infinitely do { code = rand( ); } while( !G_CheckForUniquePTRC( code ) ); for( i = 0; i < MAX_CLIENTS; i++ ) { //found an unused slot if( !connections[ i ].ptrCode ) { connections[ i ].ptrCode = code; connections[ i ].clientNum = client->ps.clientNum; client->pers.connection = &connections[ i ]; G_UpdatePTRConnection( client ); return &connections[ i ]; } } return NULL; }
void G_StoreClientPosition( gentity_t* ent ) { int top, currentTime; if (!( ent->inuse && (ent->client->sess.sessionTeam == TEAM_AXIS || ent->client->sess.sessionTeam == TEAM_ALLIES) && ent->r.linked && (ent->health > 0) && !(ent->client->ps.pm_flags & PMF_LIMBO) && (ent->client->ps.pm_type == PM_NORMAL) )) { return; } top = ent->client->topMarker; // new frame, mark the old marker's time as the end of the last frame if( ent->client->clientMarkers[top].time < level.time) { ent->client->clientMarkers[top].time = level.previousTime; top = ent->client->topMarker = ent->client->topMarker == MAX_CLIENT_MARKERS - 1 ? 0 : ent->client->topMarker + 1; } currentTime = level.previousTime + trap_Milliseconds() - level.frameTime; if(currentTime > level.time) { // owwie, we just went into the next frame... let's push them back currentTime = level.time; } VectorCopy( ent->r.mins, ent->client->clientMarkers[top].mins ); VectorCopy( ent->r.maxs, ent->client->clientMarkers[top].maxs ); VectorCopy( ent->r.currentOrigin, ent->client->clientMarkers[top].origin ); ent->client->clientMarkers[top].servertime = level.time; ent->client->clientMarkers[top].time = currentTime; }
// from AS void G_SetRaceTime( edict_t *ent, int sector, unsigned int time ) { gclient_t *cl; raceRun_t *rr; cl = ent->r.client; if( ! ent->r.inuse || cl == NULL ) return; rr = &cl->level.stats.currentRun; if( sector < -1 || sector >= rr->numSectors ) return; // normal sector if( sector >= 0 ) rr->times[sector] = time; else if (rr->numSectors > 0) { raceRun_t *nrr; // new global racerun rr->times[rr->numSectors] = time; rr->timestamp = trap_Milliseconds(); // validate the client // no bots for race, at all if( ent->r.svflags & SVF_FAKECLIENT /* && mm_debug_reportbots->value == 0 */ ) { G_Printf("G_SetRaceTime: not reporting fakeclients\n"); return; } if( cl->mm_session <= 0 ) { G_Printf("G_SetRaceTime: not reporting non-registered clients\n"); return; } if( !game.raceruns ) game.raceruns = LinearAllocator( sizeof( raceRun_t ), 0, _G_LevelMalloc, _G_LevelFree ); // push new run nrr = ( raceRun_t * )LA_Alloc( game.raceruns ); memcpy( nrr, rr, sizeof( raceRun_t ) ); // reuse this one in nrr rr->times = 0; // see if we have to push intermediate result if( LA_Size( game.raceruns ) >= RACERUN_BATCH_SIZE ) { G_Match_SendReport(); // double-check this for memory-leaks if( game.raceruns != 0 ) LinearAllocator_Free( game.raceruns ); game.raceruns = 0; } } }
/* * G_ClearSnap * We just run G_SnapFrame, the server just sent the snap to the clients, * it's now time to clean up snap specific data to start the next snap from clean. */ void G_ClearSnap( void ) { edict_t *ent; game.realtime = trap_Milliseconds(); // level.time etc. might not be real time // clear gametype's clock override gs.gameState.longstats[GAMELONG_CLOCKOVERRIDE] = 0; // clear all events in the snap for( ent = &game.edicts[0]; ENTNUM( ent ) < game.numentities; ent++ ) { if( ISEVENTENTITY( &ent->s ) ) // events do not persist after a snapshot { G_FreeEdict( ent ); continue; } // events only last for a single message ent->s.events[0] = ent->s.events[1] = 0; ent->s.eventParms[0] = ent->s.eventParms[1] = 0; ent->numEvents = 0; ent->eventPriority[0] = ent->eventPriority[1] = false; ent->s.teleported = qfalse; // remove teleported bit. // remove effect bits that are (most likely) added from gametypes ent->s.effects = ( ent->s.effects & (EF_TAKEDAMAGE|EF_CARRIER|EF_FLAG_TRAIL|EF_ROTATE_AND_BOB|EF_STRONG_WEAPON|EF_GHOST) ); } // recover some info, let players respawn and finally clear the snap structures for( ent = &game.edicts[0]; ENTNUM( ent ) < game.numentities; ent++ ) { if( !GS_MatchPaused() ) { // copy origin to old origin ( this old_origin is for snaps ) if( !( ent->r.svflags & SVF_TRANSMITORIGIN2 ) ) VectorCopy( ent->s.origin, ent->s.old_origin ); G_CheckClientRespawnClick( ent ); } if( GS_MatchPaused() ) ent->s.sound = entity_sound_backup[ENTNUM( ent )]; // clear the snap temp info memset( &ent->snap, 0, sizeof( ent->snap ) ); if( ent->r.client && trap_GetClientState( PLAYERNUM( ent ) ) >= CS_SPAWNED ) { memset( &ent->r.client->resp.snap, 0, sizeof( ent->r.client->resp.snap ) ); // set race stats to invisible RS_clearHUDStats( ent->r.client ); // racesow - clear with our function } } g_snapStarted = false; }
/* ==================== CG_DrawInformation Draw all the status / pacifier stuff during level loading ==================== */ void CG_DrawInformation(qboolean forcerefresh) { static int lastcalled = 0; if (lastcalled && (trap_Milliseconds() - lastcalled < 500)) { return; } lastcalled = trap_Milliseconds(); if (cg.snap) { return; // we are in the world, no need to draw information } // loadpanel: erase the screen now, because otherwise the "awaiting challenge"-UI-screen is still visible behind the client-version of it (the one with the progressbar),.. // ..and we do not want a flickering screen (on widescreens). // debriefing screen: no need to erase the screen.. if (!cgs.dbShowing) { if (!cgs.media.backTileShader) { cgs.media.backTileShader = trap_R_RegisterShaderNoMip("gfx/2d/backtile"); } if (cgs.glconfig.windowAspect != RATIO43) { float xoffset = Ccg_WideXoffset() * cgs.screenXScale; trap_R_DrawStretchPic(0, 0, xoffset, cgs.glconfig.vidHeight, 0, 0, 1, 1, cgs.media.backTileShader); // left side trap_R_DrawStretchPic(cgs.glconfig.vidWidth - xoffset, 0, xoffset, cgs.glconfig.vidHeight, 0, 0, 1, 1, cgs.media.backTileShader); // right side } } CG_DrawConnectScreen(qfalse, forcerefresh); // TODO: dynamic game server MOTD window /* if(cg.motdWindow == NULL) { CG_createMOTDWindow(); } if(cg.motdWindow != NULL) { CG_windowDraw(); } */ }
int qasExecute( int contextHandle ) { contexthandle_t *ch = qasGetContextHandle( contextHandle ); if( !ch ) return QASINVALIDHANDLE; ch->timeOut = trap_Milliseconds() + 500; ch->timeOut = 0; return ch->ctx->Execute(); }
/////////////////////////// // Delete a view window // void CG_mvFree( int pID ) { cg_window_t *w = CG_mvClientLocate( pID ); if ( w != NULL ) { // Free it in mvDraw() w->targetTime = 100; w->time = trap_Milliseconds(); w->state = WSTATE_SHUTDOWN; } }
void S_UseBuffer( sfx_t *sfx ) { if( sfx->filename[0] == '\0' ) return; if( !sfx->inMemory ) S_LoadBuffer( sfx ); sfx->used = trap_Milliseconds(); }
qboolean BG_LoadWeapons ( weaponData_t *weaponDataTable, unsigned int *numLoadedWeapons, unsigned int *numWeapons ) { int i; char weaponFiles[8192]; int numFiles = strap_FS_GetFileList ("ext_data/weapons", ".wpn", weaponFiles, sizeof (weaponFiles)); const char *weaponFile = weaponFiles; int successful = 0; int failed = 0; int t = trap_Milliseconds(); Com_Printf ("------- Weapon Initialization -------\n"); //if ( !LoadWeaponCacheFile (weaponDataTable, numLoadedWeapons, numWeapons) ) { for ( i = 0; i < numFiles; i++ ) { if ( BG_ParseWeaponFile (va ("ext_data/weapons/%s", weaponFile)) ) { successful++; } else { failed++; } weaponFile += strlen (weaponFile) + 1; } //WriteWeaponCacheFile (weaponDataTable, numLoadedWeapons); } /*else { successful = *numLoadedWeapons; }*/ Com_Printf ("Successfully loaded %d weapons, failed to load %d weapons.\n", successful, failed); Com_Printf ("Took %d milliseconds.\n", trap_Milliseconds() - t); Com_Printf ("-------------------------------------\n"); return (qboolean)(successful > 0); }
static void CG_DrawFPS( float x, float y, float w, float h, int font, float textScale ) { char *s; static unsigned short previousTimes[FPS_FRAMES]; static unsigned short index; static int previous, lastupdate; int t, i, fps, total; unsigned short frameTime; #ifdef _XBOX const int xOffset = -40; #else //const int xOffset = 0; #endif vec4_t fpscolor; // don't use serverTime, because that will be drifting to // correct for internet lag changes, timescales, timedemos, etc t = trap_Milliseconds(); frameTime = t - previous; previous = t; if (t - lastupdate > 50) //don't sample faster than this { lastupdate = t; previousTimes[index % FPS_FRAMES] = frameTime; index++; } // average multiple frames together to smooth changes out a bit total = 0; for ( i = 0 ; i < FPS_FRAMES ; i++ ) { total += previousTimes[i]; } if ( !total ) { total = 1; } fps = 1000 * FPS_FRAMES / total; s = va( "%i fps", fps ); if (cg_drawFPS.integer == 2) { Q_strcat (s, 64, va ("\n%.3f mspf", (float)total / (float)FPS_FRAMES)); } if (fps < 10) { VectorSet(fpscolor, 1, 0, 0); } else if (fps > 50) { VectorSet(fpscolor, 0, 1, 0); } else { int hue = (fps - 10) * 3; //(0 to 120) HSL2RGB((float)hue/360, 1, 0.5f, &fpscolor[0], &fpscolor[1], &fpscolor[2]); } fpscolor[3] = 1; //w = CG_DrawStrlen( s ) * BIGCHAR_WIDTH; trap_R_Font_DrawString(x, y, s, fpscolor, font | STYLE_DROPSHADOW, -1, textScale); //CG_DrawBigString( 635 - w + xOffset, y + 2, s, 1.0F); }
void CG_ShowHelp_On(int *status) { int milli = trap_Milliseconds(); if (*status == SHOW_SHUTDOWN && milli < cg.fadeTime) { cg.fadeTime = 2 * milli + STATS_FADE_TIME - cg.fadeTime; } else if (*status != SHOW_ON) { cg.fadeTime = milli + STATS_FADE_TIME; } *status = SHOW_ON; }
/* * SF_RegisterSound */ sfx_t *SF_RegisterSound( const char *name ) { sfx_t *sfx; assert( name ); sfx = S_FindBuffer( name ); S_IssueLoadSfxCmd( s_cmdPipe, sfx->id ); sfx->used = trap_Milliseconds(); sfx->registration_sequence = s_registration_sequence; return sfx; }
static void qasGenericLineCallback( asIScriptContext *ctx, asDWORD *timeOut ) { // If the time out is reached we abort the script asDWORD curTicks = trap_Milliseconds(); if( *timeOut && ( *timeOut < curTicks ) ) ctx->Abort(); // It would also be possible to only suspend the script, // instead of aborting it. That would allow the application // to resume the execution where it left of at a later // time, by simply calling Execute() again. }
/* ==================== CG_DrawInformation Draw all the status / pacifier stuff during level loading ==================== */ void CG_DrawInformation( qboolean forcerefresh ) { static int lastcalled = 0; if( lastcalled && (trap_Milliseconds() - lastcalled < 500) ) { return; } lastcalled = trap_Milliseconds(); if( cg.snap ) { return; // we are in the world, no need to draw information } CG_DrawConnectScreen( qfalse, forcerefresh ); // OSP - Server MOTD window /* if(cg.motdWindow == NULL) { CG_createMOTDWindow(); } if(cg.motdWindow != NULL) { CG_windowDraw(); }*/ // OSP*/ }
/* * S_AllocSource */ src_t *S_AllocSource( int priority, int entNum, int channel ) { int i; int empty = -1; int weakest = -1; int weakest_time = trap_Milliseconds(); int weakest_priority = priority; for( i = 0; i < src_count; i++ ) { if( srclist[i].isLocked ) continue; if( !srclist[i].isActive && ( empty == -1 ) ) empty = i; if( srclist[i].priority < weakest_priority || ( srclist[i].priority == weakest_priority && srclist[i].lastUse < weakest_time ) ) { weakest_priority = srclist[i].priority; weakest_time = srclist[i].lastUse; weakest = i; } // Is it an exact match, and not on channel 0? if( ( srclist[i].entNum == entNum ) && ( srclist[i].channel == channel ) && ( channel != 0 ) ) { source_kill( &srclist[i] ); return &srclist[i]; } } if( empty != -1 ) { return &srclist[empty]; } if( weakest != -1 ) { source_kill( &srclist[weakest] ); return &srclist[weakest]; } return NULL; }
// Window stuct "constructor" with some common defaults void CG_windowReset( cg_window_t *w, int fx, int startupLength ) { vec4_t colorGeneralBorder = { 0.5f, 0.35f, 0.25f, 0.5f }; vec4_t colorGeneralFill = { 0.3f, 0.45f, 0.3f, 0.5f }; w->effects = fx; w->fontScaleX = 0.25; w->fontScaleY = 0.25; w->flashPeriod = 1000; w->flashMidpoint = w->flashPeriod / 2; w->id = WID_NONE; w->inuse = qtrue; w->lineCount = 0; w->state = ( fx >= WFX_FADEIN ) ? WSTATE_START : WSTATE_COMPLETE; w->targetTime = ( startupLength > 0 ) ? startupLength : 0; w->time = trap_Milliseconds(); w->x = 0; w->y = 0; memcpy( &w->colorBorder, &colorGeneralBorder, sizeof( vec4_t ) ); memcpy( &w->colorBackground, &colorGeneralFill, sizeof( vec4_t ) ); }
// Free up a window reservation void CG_windowFree(cg_window_t *w) { int i, j; cg_windowHandler_t *wh = &cg.winHandler; if (w == NULL) { return; } if (w->effects >= WFX_FADEIN && w->state != WSTATE_OFF && w->inuse == qtrue) { w->state = WSTATE_SHUTDOWN; w->time = trap_Milliseconds(); return; } for (i = 0; i < wh->numActiveWindows; ++i) { if (w == &wh->window[wh->activeWindows[i]]) { for (j = i; j < wh->numActiveWindows; ++j) { if (j + 1 < wh->numActiveWindows) { // Nico, #fixme: GCC 4.8.2 with optimization says // warning: array subscript is above array bounds wh->activeWindows[j] = wh->activeWindows[j + 1]; } } w->id = WID_NONE; w->inuse = qfalse; w->state = WSTATE_OFF; CG_removeStrings(w); wh->numActiveWindows--; break; } } }
// Main window-drawing handler void CG_windowDraw(void) { int h, x, y, i, j, milli, t_offset, tmp; cg_window_t *w; qboolean fCleanup = qfalse; // Gordon: FIXME, the limbomenu var no longer exists qboolean fAllowMV = (cg.snap != NULL && cg.snap->ps.pm_type != PM_INTERMISSION /*&& !cg.limboMenu*/); vec4_t *bg; vec4_t textColor, borderColor, bgColor; if(cg.winHandler.numActiveWindows == 0) { // Draw these for demoplayback no matter what CG_demoAviFPSDraw(); CG_demoTimescaleDraw(); return; } milli = trap_Milliseconds(); memcpy(textColor, colorWhite, sizeof(vec4_t)); // Mouse cursor position for MV highlighting (offset for cursor pointer position) // Also allow for swingcam toggling if(cg.mvTotalClients > 0 && fAllowMV) { CG_cursorUpdate(); } for(i=0; i<cg.winHandler.numActiveWindows; i++) { w = &cg.winHandler.window[cg.winHandler.activeWindows[i]]; if(!w->inuse || w->state == WSTATE_OFF) { fCleanup = qtrue; continue; } // Multiview rendering has its own handling if(w->effects & WFX_MULTIVIEW) { if(w != cg.mvCurrentMainview && fAllowMV) CG_mvDraw(w); continue; } if(w->effects & WFX_TEXTSIZING) { CG_windowNormalizeOnText(w); w->effects &= ~WFX_TEXTSIZING; } bg = ((w->effects & WFX_FLASH) && (milli % w->flashPeriod) > w->flashMidpoint) ? &w->colorBackground2 : &w->colorBackground; h = w->h; x = w->x; y = w->y; t_offset = milli - w->time; textColor[3] = 1.0f; memcpy(&borderColor, w->colorBorder, sizeof(vec4_t)); memcpy(&bgColor, bg, sizeof(vec4_t)); // TODO: Add in support for ALL scrolling effects if(w->state == WSTATE_START) { tmp = w->targetTime - t_offset; if(w->effects & WFX_SCROLLUP) { if(tmp > 0) { y += (480 - y) * tmp / w->targetTime;//(100 * tmp / w->targetTime) / 100; } else { w->state = WSTATE_COMPLETE; } w->curY = y; } if(w->effects & WFX_FADEIN) { if(tmp > 0) textColor[3] = (float)((float)t_offset / (float)w->targetTime); else w->state = WSTATE_COMPLETE; } } else if(w->state == WSTATE_SHUTDOWN) { tmp = w->targetTime - t_offset; if(w->effects & WFX_SCROLLUP) { if(tmp > 0) y = w->curY + (480 - w->y) * t_offset / w->targetTime;//(100 * t_offset / w->targetTime) / 100; if(tmp < 0 || y >= 480) { w->state = WSTATE_OFF; fCleanup = qtrue; continue; } } if(w->effects & WFX_FADEIN) { if(tmp > 0) { textColor[3] -= (float)((float)t_offset / (float)w->targetTime); } else { textColor[3] = 0.0f; w->state = WSTATE_OFF; } } } borderColor[3] *= textColor[3]; bgColor[3] *= textColor[3]; CG_FillRect(x, y, w->w, h, bgColor); CG_DrawRect(x, y, w->w, h, 1, borderColor); x += 5; y -= (w->effects & WFX_TRUETYPE) ? 3 : 0; for(j=w->lineCount-1; j>=0; j--) { if(w->effects & WFX_TRUETYPE) { // CG_Text_Paint(x, y + h, w->fontScale, textColor, (char*)w->lineText[j], 0.0f, 0, 0); CG_Text_Paint_Ext(x, y + h, w->fontScaleX, w->fontScaleY, textColor, (char*)w->lineText[j], 0.0f, 0, 0, &cgs.media.limboFont2); } h -= (w->lineHeight[j] + 3); if(!(w->effects & WFX_TRUETYPE)) { CG_DrawStringExt2(x, y + h, (char*)w->lineText[j], textColor, qfalse, qtrue, w->fontWidth, w->fontHeight, 0); } } } // Wedge in MV info overlay if(cg.mvTotalClients > 0 && fAllowMV) CG_mvOverlayDisplay(); // Extra rate info CG_demoAviFPSDraw(); CG_demoTimescaleDraw(); // Mouse cursor lays on top of everything if(cg.mvTotalClients > 0 && cg.time < cgs.cursorUpdate && fAllowMV) { //CG_DrawPic(cgs.cursorX - CURSOR_OFFSETX, cgs.cursorY - CURSOR_OFFSETY, 32, 32, cgs.media.cursor); CG_DrawPic( cgDC.cursorx, cgDC.cursory, 32, 32, cgs.media.cursorIcon ); } if(fCleanup) { CG_windowCleanup(); } }
//=========================================================================== // // Parameter: - // Returns: - // Changes Globals: - //=========================================================================== weightconfig_t *ReadWeightConfig(char *filename) { int newindent, avail = 0, n; pc_token_t token; int source; fuzzyseperator_t *fs; weightconfig_t *config = NULL; int starttime; starttime = trap_Milliseconds(); if (!bot_reloadcharacters.integer) { avail = -1; for( n = 0; n < MAX_WEIGHT_FILES; n++ ) { config = weightFileList[n]; if( !config ) { if( avail == -1 ) { avail = n; } //end if continue; } //end if if( strcmp( filename, config->filename ) == 0 ) { //BotAI_Print( PRT_MESSAGE, "retained %s\n", filename ); return config; } //end if } //end for if( avail == -1 ) { BotAI_Print( PRT_ERROR, "weightFileList was full trying to load %s\n", filename ); return NULL; } //end if } //end if source = trap_PC_LoadSource(filename, BOTFILESBASEFOLDER); if (!source) { BotAI_Print(PRT_ERROR, "counldn't load %s\n", filename); return NULL; } //end if // config = (weightconfig_t *) trap_HeapMalloc(sizeof(weightconfig_t)); config->numweights = 0; Q_strncpyz( config->filename, filename, sizeof(config->filename) ); //parse the item config file while(trap_PC_ReadToken(source, &token)) { if (!strcmp(token.string, "weight")) { if (config->numweights >= MAX_WEIGHTS) { PC_SourceWarning(source, "too many fuzzy weights"); break; } //end if if (!PC_ExpectTokenType(source, TT_STRING, 0, &token)) { FreeWeightConfig(config); trap_PC_FreeSource(source); return NULL; } //end if config->weights[config->numweights].name = (char *) trap_HeapMalloc(strlen(token.string) + 1); strcpy(config->weights[config->numweights].name, token.string); if (!PC_ExpectAnyToken(source, &token)) { FreeWeightConfig(config); trap_PC_FreeSource(source); return NULL; } //end if newindent = qfalse; if (!strcmp(token.string, "{")) { newindent = qtrue; if (!PC_ExpectAnyToken(source, &token)) { FreeWeightConfig(config); trap_PC_FreeSource(source); return NULL; } //end if } //end if if (!strcmp(token.string, "switch")) { fs = ReadFuzzySeperators_r(source); if (!fs) { FreeWeightConfig(config); trap_PC_FreeSource(source); return NULL; } //end if config->weights[config->numweights].firstseperator = fs; } //end if else if (!strcmp(token.string, "return")) { fs = (fuzzyseperator_t *) trap_HeapMalloc(sizeof(fuzzyseperator_t)); fs->index = 0; fs->value = MAX_INVENTORYVALUE; fs->next = NULL; fs->child = NULL; if (!ReadFuzzyWeight(source, fs)) { trap_HeapFree(fs); FreeWeightConfig(config); trap_PC_FreeSource(source); return NULL; } //end if config->weights[config->numweights].firstseperator = fs; } //end else if else { PC_SourceError(source, "invalid name %s", token.string); FreeWeightConfig(config); trap_PC_FreeSource(source); return NULL; } //end else if (newindent) { if (!PC_ExpectTokenString(source, "}")) { FreeWeightConfig(config); trap_PC_FreeSource(source); return NULL; } //end if } //end if config->numweights++; } //end if else { PC_SourceError(source, "invalid name %s", token.string); FreeWeightConfig(config); trap_PC_FreeSource(source); return NULL; } //end else } //end while //free the source at the end of a pass trap_PC_FreeSource(source); //if the file was located in a pak file BotAI_Print(PRT_DEVELOPER, "loaded %s\n", filename); BotAI_Print(PRT_DEVELOPER, "weights loaded in %d msec\n", trap_Milliseconds() - starttime); // if (!bot_reloadcharacters.integer) { weightFileList[avail] = config; } //end if // return config; } //end of the function ReadWeightConfig
// Demo playback key catcher support void CG_DemoClick(int key, qboolean down) { int milli = trap_Milliseconds(); // Avoid active console keypress issues if (!down && !cgs.fKeyPressed[key]) { return; } cgs.fKeyPressed[key] = down; switch (key) { case K_ESCAPE: CG_ShowHelp_Off(&cg.demohelpWindow); CG_keyOff_f(); return; case K_TAB: if (down) { CG_ScoresDown_f(); } else { CG_ScoresUp_f(); } return; // Help info case K_BACKSPACE: if (!down) { if (cg.demohelpWindow != SHOW_ON) { CG_ShowHelp_On(&cg.demohelpWindow); } else { CG_ShowHelp_Off(&cg.demohelpWindow); } } return; // Screenshot keys case K_F11: if (!down) { trap_SendConsoleCommand(va("screenshot%s\n", ((cg_useScreenshotJPEG.integer) ? "JPEG" : ""))); } return; case K_F12: if (!down) { CG_autoScreenShot_f(); } return; // Window controls case K_SHIFT: case K_CTRL: case K_MOUSE4: cgs.fResize = down; return; case K_MOUSE1: cgs.fSelect = down; return; case K_MOUSE2: case K_INS: case K_KP_PGUP: case K_DEL: case K_KP_PGDN: case K_MOUSE3: return; // Third-person controls case K_ENTER: if (!down) { trap_Cvar_Set("cg_thirdperson", ((cg_thirdPerson.integer == 0) ? "1" : "0")); } return; case K_UPARROW: if (milli > cgs.thirdpersonUpdate) { float range = cg_thirdPersonRange.value; cgs.thirdpersonUpdate = milli + DEMO_THIRDPERSONUPDATE; range -= ((range >= 4 * DEMO_RANGEDELTA) ? DEMO_RANGEDELTA : (range - DEMO_RANGEDELTA)); trap_Cvar_Set("cg_thirdPersonRange", va("%f", range)); } return; case K_DOWNARROW: if (milli > cgs.thirdpersonUpdate) { float range = cg_thirdPersonRange.value; cgs.thirdpersonUpdate = milli + DEMO_THIRDPERSONUPDATE; range += ((range >= 120 * DEMO_RANGEDELTA) ? 0 : DEMO_RANGEDELTA); trap_Cvar_Set("cg_thirdPersonRange", va("%f", range)); } return; case K_RIGHTARROW: if (milli > cgs.thirdpersonUpdate) { float angle = cg_thirdPersonAngle.value - DEMO_ANGLEDELTA; cgs.thirdpersonUpdate = milli + DEMO_THIRDPERSONUPDATE; if (angle < 0) { angle += 360.0f; } trap_Cvar_Set("cg_thirdPersonAngle", va("%f", angle)); } return; case K_LEFTARROW: if (milli > cgs.thirdpersonUpdate) { float angle = cg_thirdPersonAngle.value + DEMO_ANGLEDELTA; cgs.thirdpersonUpdate = milli + DEMO_THIRDPERSONUPDATE; if (angle >= 360.0f) { angle -= 360.0f; } trap_Cvar_Set("cg_thirdPersonAngle", va("%f", angle)); } return; // Timescale controls case K_KP_5: case K_KP_INS: case K_SPACE: if (!down) { trap_Cvar_Set("timescale", "1"); cgs.timescaleUpdate = cg.time + 1000; } return; case K_KP_DOWNARROW: if (!down) { float tscale = cg_timescale.value; if (tscale <= 1.1f) { if (tscale > 0.1f) { tscale -= 0.1f; } } else { tscale -= 1.0; } trap_Cvar_Set("timescale", va("%f", tscale)); cgs.timescaleUpdate = cg.time + (int)(1000.0f * tscale); } return; case K_MWHEELDOWN: if (!cgs.fKeyPressed[K_SHIFT]) { if (!down) { CG_ZoomOut_f(); } return; } // Roll over into timescale changes case K_KP_LEFTARROW: if (!down && cg_timescale.value > 0.1f) { trap_Cvar_Set("timescale", va("%f", cg_timescale.value - 0.1f)); cgs.timescaleUpdate = cg.time + (int)(1000.0f * cg_timescale.value - 0.1f); } return; case K_KP_UPARROW: if (!down) { trap_Cvar_Set("timescale", va("%f", cg_timescale.value + 1.0f)); cgs.timescaleUpdate = cg.time + (int)(1000.0f * cg_timescale.value + 1.0f); } return; case K_MWHEELUP: if (!cgs.fKeyPressed[K_SHIFT]) { if (!down) { CG_ZoomIn_f(); } return; } // Roll over into timescale changes case K_KP_RIGHTARROW: if (!down) { trap_Cvar_Set("timescale", va("%f", cg_timescale.value + 0.1f)); cgs.timescaleUpdate = cg.time + (int)(1000.0f * cg_timescale.value + 0.1f); } return; // AVI recording controls case K_F1: if (down) { cgs.aviDemoRate = demo_avifpsF1.integer; } else { trap_Cvar_Set("cl_avidemo", demo_avifpsF1.string); } return; case K_F2: if (down) { cgs.aviDemoRate = demo_avifpsF2.integer; } else { trap_Cvar_Set("cl_avidemo", demo_avifpsF2.string); } return; case K_F3: if (down) { cgs.aviDemoRate = demo_avifpsF3.integer; } else { trap_Cvar_Set("cl_avidemo", demo_avifpsF3.string); } return; case K_F4: if (down) { cgs.aviDemoRate = demo_avifpsF4.integer; } else { trap_Cvar_Set("cl_avidemo", demo_avifpsF4.string); } return; case K_F5: if (down) { cgs.aviDemoRate = demo_avifpsF5.integer; } else { trap_Cvar_Set("cl_avidemo", demo_avifpsF5.string); } return; } }
/* ================ G_RunFrame Advances the non-player objects in the world ================ */ void G_RunFrame( int levelTime ) { int i; gentity_t *ent; int msec; int start, end; // if we are waiting for the level to restart, do nothing if ( level.restarted ) { return; } level.framenum++; level.previousTime = level.time; level.time = levelTime; msec = level.time - level.previousTime; // get any cvar changes G_UpdateCvars(); // // go through all allocated objects // start = trap_Milliseconds(); ent = &g_entities[0]; for (i=0 ; i<level.num_entities ; i++, ent++) { if ( !ent->inuse ) { continue; } // clear events that are too old if ( level.time - ent->eventTime > EVENT_VALID_MSEC ) { if ( ent->s.event ) { ent->s.event = 0; // &= EV_EVENT_BITS; if ( ent->client ) { ent->client->ps.externalEvent = 0; // predicted events should never be set to zero //ent->client->ps.events[0] = 0; //ent->client->ps.events[1] = 0; } } if ( ent->freeAfterEvent ) { // tempEntities or dropped items completely go away after their event G_FreeEntity( ent ); continue; } else if ( ent->unlinkAfterEvent ) { // items that will respawn will hide themselves after their pickup event ent->unlinkAfterEvent = qfalse; trap_UnlinkEntity( ent ); } } // temporary entities don't think if ( ent->freeAfterEvent ) { continue; } if ( !ent->r.linked && ent->neverFree ) { continue; } if ( ent->s.eType == ET_MISSILE ) { G_RunMissile( ent ); continue; } if ( ent->s.eType == ET_ITEM || ent->physicsObject ) { G_RunItem( ent ); continue; } if ( ent->s.eType == ET_MOVER ) { G_RunMover( ent ); continue; } if ( i < MAX_CLIENTS ) { G_RunClient( ent ); continue; } G_RunThink( ent ); } end = trap_Milliseconds(); start = trap_Milliseconds(); // perform final fixups on the players ent = &g_entities[0]; for (i=0 ; i < level.maxclients ; i++, ent++ ) { if ( ent->inuse ) { ClientEndFrame( ent ); } } end = trap_Milliseconds(); // see if it is time to do a tournement restart CheckTournament(); // see if it is time to end the level CheckExitRules(); // update to team status? CheckTeamStatus(); // cancel vote if timed out CheckVote(); // check team votes CheckTeamVote( TEAM_RED ); CheckTeamVote( TEAM_BLUE ); // for tracking changes CheckCvars(); if (g_listEntity.integer) { for (i = 0; i < MAX_GENTITIES; i++) { G_Printf("%4i: %s\n", i, g_entities[i].classname); } trap_Cvar_Set("g_listEntity", "0"); } }
void CG_DemoHelpDraw() { const char *help[] = { "^nTAB ^mscores", "^nF1-F5 ^mavidemo record", "^nF11-F12 ^mscreenshot", NULL, "^nKP_DOWN ^mslow down (--)", "^nKP_LEFT ^mslow down (-)", "^nKP_UP ^mspeed up (++)", "^nKP_RIGHT ^mspeed up (+)", "^nSPACE ^mnormal speed", NULL, "^nENTER ^mExternal view", "^nLFT/RGHT ^mChange angle", "^nUP/DOWN ^mMove in/out" }; int i, x, y = 480, w, h; vec4_t bgColor = COLOR_BG; // window vec4_t borderColor = COLOR_BORDER; // window vec4_t bgColorTitle = COLOR_BG_TITLE; // titlebar vec4_t borderColorTitle = COLOR_BORDER_TITLE; // titlebar // Main header int hStyle = ITEM_TEXTSTYLE_SHADOWED; float hScale = 0.16f; float hScaleY = 0.21f; fontInfo_t *hFont = FONT_HEADER; vec4_t hdrColor2 = COLOR_HDR2; // text // Text settings int tStyle = ITEM_TEXTSTYLE_SHADOWED; int tSpacing = 9; // Should derive from CG_Text_Height_Ext float tScale = 0.19f; fontInfo_t *tFont = FONT_TEXT; vec4_t tColor = COLOR_TEXT; // text float diff = cg.fadeTime - trap_Milliseconds(); if (cg.demohelpWindow == SHOW_OFF) { return; } // FIXME: Should compute this beforehand w = DH_W; x = 640 + DH_X - w; h = 2 + tSpacing + 2 + // Header 2 + 1 + tSpacing * (2 + (sizeof (help)) / sizeof (char *)) + 2; // Fade-in effects if (diff > 0.0f) { float scale = diff / STATS_FADE_TIME; if (cg.demohelpWindow == SHOW_ON) { scale = 1.0f - scale; } bgColor[3] *= scale; bgColorTitle[3] *= scale; borderColor[3] *= scale; borderColorTitle[3] *= scale; hdrColor2[3] *= scale; tColor[3] *= scale; y += (DH_Y - h) * scale; } else if (cg.demohelpWindow == SHOW_SHUTDOWN) { cg.demohelpWindow = SHOW_OFF; return; } else { y += DH_Y - h; } CG_DrawRect(x, y, w, h, 1, borderColor); CG_FillRect(x, y, w, h, bgColor); // Header CG_FillRect(x, y, w, tSpacing + 4, bgColorTitle); CG_DrawRect(x, y, w, tSpacing + 4, 1, borderColorTitle); x += 4; y += 1; y += tSpacing; CG_Text_Paint_Ext(x, y, hScale, hScaleY, hdrColor2, "DEMO CONTROLS", 0.0f, 0, hStyle, hFont); y += 3; // Control info for (i = 0; i < (int)(sizeof (help) / sizeof (char *)); ++i) { y += tSpacing; if (help[i] != NULL) { CG_Text_Paint_Ext(x, y, tScale, tScale, tColor, (char *)help[i], 0.0f, 0, tStyle, tFont); } } y += tSpacing * 2; CG_Text_Paint_Ext(x, y, tScale, tScale, tColor, "^nBACKSPACE ^mhelp on/off", 0.0f, 0, tStyle, tFont); }