void CHudBenchmark::StartNextSection( int section ) { net_status_t status; switch ( section ) { case FIRST_STAGE: // Stage 2 requires that we tell the server to "drop" an item m_fSendTime = gHUD.m_flTime; m_fReceiveTime = 0.0; m_StoredLatency = 0.0; m_StoredPacketLoss = 0.0; m_nStoredHopCount = 0; m_nTraceDone = 0; ServerCmd( "ppdemo 1 start\n" ); break; case SECOND_STAGE: if ( m_nTraceDone ) { gEngfuncs.pNetAPI->Status( &status ); gEngfuncs.Con_Printf( "Hops == %i\n", m_nStoredHopCount ); m_StoredPacketLoss = status.packet_loss; gEngfuncs.Con_Printf( "PL == %i\n", (int)m_StoredPacketLoss ); } m_nSentFinish = 0; // added by minman ServerCmd( "ppdemo 2\n" ); break; case THIRD_STAGE: m_nSentFinish = 0; // added by minman ServerCmd( "ppdemo 3\n" ); break; //TODO: fourth stage undefined? default: break; } m_fStageStarted = gHUD.m_flTime; g_benchSwitchTime = gHUD.m_flTime + Bench_GetSwitchTime(); }
// // Think: // Used for selection of weapon menu item. // void CHudAmmo::Think() { if( m_bNeedsLocalUpdate ) { m_bNeedsLocalUpdate = false; if( m_pWeapon ) UpdateWeaponHUD( m_pWeapon, m_bOnTarget ); } if ( gHUD.m_bPlayerDead ) return; CBasePlayer* pPlayer = g_Prediction.GetLocalPlayer(); if ( gHUD.m_iWeaponBits != pPlayer->pev->weapons ) { pPlayer->pev->weapons = gHUD.m_iWeaponBits; for (int i = MAX_WEAPONS-1; i > 0; i-- ) { CBasePlayerWeapon *p = g_Prediction.GetWeapon(i); if ( p && p->GetWeaponInfo() ) { if ( gHUD.m_iWeaponBits & ( 1 << p->GetWeaponInfo()->GetID() ) ) pPlayer->AddPlayerItem( p ); else pPlayer->RemovePlayerItem( p ); } } } if( !m_pActiveSel ) return; // has the player selected one? if (gHUD.m_iKeyBits & IN_ATTACK) { if ( m_pActiveSel != (CBasePlayerWeapon *)1) { ServerCmd( m_pActiveSel->GetWeaponInfo()->GetWeaponName()); g_weaponselect = m_pActiveSel->GetWeaponInfo()->GetID(); } m_pLastSel = m_pActiveSel; m_pActiveSel = nullptr; gHUD.m_iKeyBits &= ~IN_ATTACK; PlaySound("common/wpn_select.wav", 1); } }
// // Think: // Used for selection of weapon menu item. // void CHudAmmo::Think(void) { if ( gHUD.m_fPlayerDead ) return; if ( gHUD.m_iWeaponBits != gWR.iOldWeaponBits ) { gWR.iOldWeaponBits = gHUD.m_iWeaponBits; for (int i = 0; i < MAX_WEAPONS-1; i++ ) { WEAPON *p = gWR.GetWeapon(i); if ( p ) { if ( gHUD.m_iWeaponBits & ( 1 << p->iId ) ) { gWR.PickupWeapon( p ); } else { gWR.DropWeapon( p ); } } } } if (!gpActiveSel) return; // has the player selected one? if (gHUD.m_iKeyBits & IN_ATTACK) { if (gpActiveSel != (WEAPON *)1) { ServerCmd(gpActiveSel->szName); g_weaponselect = gpActiveSel->iId; } gpLastSel = gpActiveSel; gpActiveSel = NULL; gHUD.m_iKeyBits &= ~IN_ATTACK; PlaySound("common/wpn_select.wav", 1); } }
// // Think: // Used for selection of weapon menu item. // void CHudAmmo::Think(void) { if ( gHUD.m_fPlayerDead ) return; if ( gHUD.m_iWeaponBits != gWR.iOldWeaponBits ) { gWR.iOldWeaponBits = gHUD.m_iWeaponBits; for (int i = MAX_WEAPONS-1; i > 0; i-- ) { WEAPON *p = gWR.GetWeapon(i); if ( p ) { if ( gHUD.m_iWeaponBits & ( 1 << p->iId ) ) gWR.PickupWeapon( p ); else gWR.DropWeapon( p ); } } } if (!gpActiveSel) return; // has the player selected one? if (gHUD.m_iKeyBits & IN_ATTACK) { if (gpActiveSel != (WEAPON *)1) { ServerCmd(gpActiveSel->szName); g_weaponselect = gpActiveSel->iId; } gpLastSel = gpActiveSel; gpActiveSel = NULL; gHUD.m_iKeyBits &= ~IN_ATTACK; // Fograin92: Replaced with new audio engine gSoundEngine.PlaySound("common/wpn_select.wav", g_vecZero, SND_2D, 0, CVAR_GET_FLOAT("sm_snd_sfx")); } }
void WeaponsResource::SelectSlot(int iSlot, int fAdvance, int iDirection) { // Discwar has no weapons to switch to return; if(gHUD.m_Menu.m_fMenuDisplayed && (fAdvance == FALSE) && (iDirection == 1)) { // menu is overriding slot use commands gHUD.m_Menu.SelectMenuItem(iSlot + 1); // slots are one off the key numbers return; } if(iSlot > MAX_WEAPON_SLOTS) return; if(gHUD.m_fPlayerDead || gHUD.m_iHideHUDDisplay & (HIDEHUD_WEAPONS | HIDEHUD_ALL)) return; if(!(gHUD.m_iWeaponBits & (1 << (WEAPON_SUIT)))) return; if(!(gHUD.m_iWeaponBits & ~(1 << (WEAPON_SUIT)))) return; WEAPON *p = NULL; bool fastSwitch = CVAR_GET_FLOAT("hud_fastswitch") != 0; if((gpActiveSel == NULL) || (gpActiveSel == (WEAPON *)1) || (iSlot != gpActiveSel->iSlot)) { PlaySound("common/wpn_hudon.wav", 1); p = GetFirstPos(iSlot); if(p && fastSwitch) // check for fast weapon switch mode { // if fast weapon switch is on, then weapons can be selected in a single keypress // but only if there is only one item in the bucket WEAPON *p2 = GetNextActivePos(p->iSlot, p->iSlotPos); if(!p2) { // only one active item in bucket, so change directly to weapon ServerCmd(p->szName); g_weaponselect = p->iId; return; } } } else { PlaySound("common/wpn_moveselect.wav", 1); if(gpActiveSel) p = GetNextActivePos(gpActiveSel->iSlot, gpActiveSel->iSlotPos); if(!p) p = GetFirstPos(iSlot); } if(!p) // no selection found { // just display the weapon list, unless fastswitch is on just ignore it if(!fastSwitch) gpActiveSel = (WEAPON *)1; else gpActiveSel = NULL; } else gpActiveSel = p; }
void CHudBenchmark::Think( void ) { if ( !Bench_Active() ) return; Trace_Think(); if ( started ) { started = 0; // Clear variable m_fReceiveTime = 0.0; m_nFPSCount = 0; m_fAverageFT = 0.0; m_nSentFinish = 0; m_StoredLatency = 0.0; m_StoredPacketLoss = 0.0; m_nStoredHopCount = 0; m_nTraceDone = 0; m_nObjects = 0; m_nScoreComputed = 0; m_nCompositeScore = 0; m_fAvgScore = 0; m_fDrawScore = 0.0; m_fAvgFrameRate = 0.0; } if ( gHUD.m_flTime > g_benchSwitchTime ) { Bench_SetStage( Bench_GetStage() + 1 ); StartNextSection( Bench_GetStage() ); } if ( Bench_InStage( FIRST_STAGE ) ) { // Assume 1000 ms lag is the max and that would take all but 2 seconds of this interval to traverse if ( m_fReceiveTime ) { float latency = 2.0 * m_StoredLatency; float switch_time; float total_time; latency = max( 0.0f, latency ); latency = min( 1.0f, latency ); total_time = Bench_GetSwitchTime(); total_time -= 2.0; switch_time = m_fStageStarted + latency * total_time; switch_time += 1.0; if ( gHUD.m_flTime >= switch_time ) { if ( !m_nSentFinish ) { g_benchSwitchTime = gHUD.m_flTime + 1.0 + SCORE_TIME_UP; ServerCmd( "ppdemo 1 finish\n" ); m_nSentFinish = 1; } } else { g_benchSwitchTime = gHUD.m_flTime + 10.0; } } } if ( Bench_InStage( SECOND_STAGE ) ) { // frametime static float lasttime; float elapsed; float total; float frac; float switch_time; // added by minman if ( lasttime ) { float dt; dt = gHUD.m_flTime - lasttime; if ( dt > 0 ) { CountFrame( dt ); } } lasttime = gHUD.m_flTime; elapsed = gHUD.m_flTime - m_fStageStarted; total = Bench_GetSwitchTime(); if ( total ) { frac = elapsed / total; // Only takes 1/2 time to get up to maximum speed frac *= 2.0; frac = max( 0.0f, frac ); frac = min( 1.0f, frac ); m_nObjects = (int)(NUM_BENCH_OBJ * frac); } switch_time = m_fStageStarted + total; /* BELOW ADDED BY minman */ if (gHUD.m_flTime >= switch_time) { if ( !m_nSentFinish) { g_benchSwitchTime = gHUD.m_flTime + SCORE_TIME_UP; m_nSentFinish = 1; } } else g_benchSwitchTime = gHUD.m_flTime + 10.0; } /* BELOW ADDED BY minman */ if ( Bench_InStage (THIRD_STAGE)) { float switch_time = m_fStageStarted + Bench_GetSwitchTime(); if (gHUD.m_flTime >= switch_time) { if ( !m_nSentFinish) { g_benchSwitchTime = gHUD.m_flTime + SCORE_TIME_UP; m_nSentFinish = 1; } } else g_benchSwitchTime = gHUD.m_flTime + 10.0; } if ( Bench_InStage( FOURTH_STAGE ) ) { if ( !m_nScoreComputed ) { m_nScoreComputed = 1; gHUD.m_Benchmark.SetCompositeScore(); } } if ( Bench_GetStage() > LAST_STAGE ) { m_iFlags &= ~HUD_ACTIVE; EngineClientCmd( "quit\n" ); } }
void CVoiceStatus::UpdateServerState(bool bForce) { // Can't do anything when we're not in a level. char const *pLevelName = gEngfuncs.pfnGetLevelName(); if( pLevelName[0] == 0 ) { if( gEngfuncs.pfnGetCvarFloat("voice_clientdebug") ) { gEngfuncs.pfnConsolePrint( "CVoiceStatus::UpdateServerState: pLevelName[0]==0\n" ); } return; } int bCVarModEnable = !!gEngfuncs.pfnGetCvarFloat("voice_modenable"); if(bForce || m_bServerModEnable != bCVarModEnable) { m_bServerModEnable = bCVarModEnable; char str[256]; _snprintf(str, sizeof(str), "VModEnable %d", m_bServerModEnable); ServerCmd(str); if(gEngfuncs.pfnGetCvarFloat("voice_clientdebug")) { char msg[256]; sprintf(msg, "CVoiceStatus::UpdateServerState: Sending '%s'\n", str); gEngfuncs.pfnConsolePrint(msg); } } char str[2048]; sprintf(str, "vban"); bool bChange = false; for(uint32 dw=0; dw < VOICE_MAX_PLAYERS_DW; dw++) { uint32 serverBanMask = 0; uint32 banMask = 0; for(uint32 i=0; i < 32; i++) { char playerID[16]; if(!gEngfuncs.GetPlayerUniqueID(i+1, playerID)) continue; if(m_BanMgr.GetPlayerBan(playerID)) banMask |= 1 << i; if(m_ServerBannedPlayers[dw*32 + i]) serverBanMask |= 1 << i; } if(serverBanMask != banMask) bChange = true; // Ok, the server needs to be updated. char numStr[512]; sprintf(numStr, " %x", banMask); strcat(str, numStr); } if(bChange || bForce) { if(gEngfuncs.pfnGetCvarFloat("voice_clientdebug")) { char msg[256]; sprintf(msg, "CVoiceStatus::UpdateServerState: Sending '%s'\n", str); gEngfuncs.pfnConsolePrint(msg); } gEngfuncs.pfnServerCmdUnreliable(str); // Tell the server.. } else { if (gEngfuncs.pfnGetCvarFloat("voice_clientdebug")) { gEngfuncs.pfnConsolePrint( "CVoiceStatus::UpdateServerState: no change\n" ); } } m_LastUpdateServerState = gEngfuncs.GetClientTime(); }
void CHudAmmo::SelectSlot( int iSlot, const bool fAdvance, int iDirection ) { if ( gHUD.m_Menu.m_fMenuDisplayed && !fAdvance && (iDirection == 1) ) { // menu is overriding slot use commands gHUD.m_Menu.SelectMenuItem( iSlot + 1 ); // slots are one off the key numbers return; } if ( iSlot > MAX_WEAPON_SLOTS ) return; if ( gHUD.m_bPlayerDead || gHUD.m_iHideHUDDisplay & ( HIDEHUD_WEAPONS | HIDEHUD_ALL ) ) return; if (!(gHUD.m_iWeaponBits & (1<<(WEAPON_SUIT)) )) return; if ( ! ( gHUD.m_iWeaponBits & ~(1<<(WEAPON_SUIT)) )) return; CBasePlayerWeapon *p = NULL; bool fastSwitch = CVAR_GET_FLOAT( "hud_fastswitch" ) != 0; CBasePlayer* pPlayer = g_Prediction.GetLocalPlayer(); if ( ( m_pActiveSel == NULL) || ( m_pActiveSel == ( CBasePlayerWeapon *)1) || (iSlot != m_pActiveSel->GetWeaponInfo()->GetBucket()) ) { PlaySound( "common/wpn_hudon.wav", 1 ); p = pPlayer->GetFirstPos( iSlot ); if ( p && fastSwitch ) // check for fast weapon switch mode { // if fast weapon switch is on, then weapons can be selected in a single keypress // but only if there is only one item in the bucket CBasePlayerWeapon *p2 = pPlayer->GetNextActivePos( p->GetWeaponInfo()->GetBucket(), p->GetWeaponInfo()->GetPosition() ); if ( !p2 ) { // only one active item in bucket, so change directly to weapon ServerCmd( p->GetWeaponInfo()->GetWeaponName() ); g_weaponselect = p->GetWeaponInfo()->GetID(); return; } } } else { PlaySound("common/wpn_moveselect.wav", 1); if ( m_pActiveSel ) p = pPlayer->GetNextActivePos( m_pActiveSel->GetWeaponInfo()->GetBucket(), m_pActiveSel->GetWeaponInfo()->GetPosition() ); if ( !p ) p = pPlayer->GetFirstPos( iSlot ); } if ( !p ) // no selection found { // just display the weapon list, unless fastswitch is on just ignore it if ( !fastSwitch ) m_pActiveSel = ( CBasePlayerWeapon *)1; else m_pActiveSel = nullptr; } else m_pActiveSel = p; }