From 14ac18de31e9dc36f0a26a93099a77847037d300 Mon Sep 17 00:00:00 2001 From: jeefo Date: Wed, 22 Jul 2015 23:04:43 +0300 Subject: [PATCH] added back frame skipping --- include/core.h | 8 ++++++++ source/basecode.cpp | 17 +++++++++++------ source/manager.cpp | 2 ++ source/navigate.cpp | 10 ++++++---- 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/include/core.h b/include/core.h index c9fd34f..1613faa 100644 --- a/include/core.h +++ b/include/core.h @@ -1177,6 +1177,7 @@ public: float m_fearLevel; // dynamic fear level (in game) float m_nextEmotionUpdate; // next time to sanitize emotions float m_thinkFps; // skip some frames in bot thinking + float m_thinkInterval; // interval between frames int m_actMessageIndex; // current processed message int m_pushMessageIndex; // offset for next pushed message @@ -1239,8 +1240,15 @@ public: inline Vector Center (void) { return (pev->absmax + pev->absmin) * 0.5; }; inline Vector EyePosition (void) { return pev->origin + pev->view_ofs; }; + // things that should be executed every frame + void ThinkFrame (void); + + // the main function that decides intervals of running bot ai void ThinkMain (void); + + /// the things that can be executed while skipping frames void Think (void); + void NewRound (void); void EquipInBuyzone (int buyCount); void PushMessageQueue (int message); diff --git a/source/basecode.cpp b/source/basecode.cpp index 64e6a36..1cc8480 100644 --- a/source/basecode.cpp +++ b/source/basecode.cpp @@ -733,7 +733,7 @@ void Bot::FindItem (void) { allowPickup = false; - if (!m_defendedBomb && m_personality != PERSONALITY_RUSHER && Random.Long (0, 100) < 80) + if (!m_defendedBomb) { m_defendedBomb = true; @@ -2869,19 +2869,24 @@ void Bot::ChooseAimDirection (void) m_lookAt = m_destOrigin; } -static float ThinkFps = 1.0f / 30.0f; - void Bot::ThinkMain (void) { - if (m_thinkFps < GetWorldTime ()) + if (m_thinkFps <= GetWorldTime ()) { + // execute delayed think Think (); // skip some frames - m_thinkFps = GetWorldTime () + ThinkFps * Random.Float (0.95f, 1.05f); + m_thinkFps = GetWorldTime () + m_thinkInterval; } else - UpdateLookAngles (); + ThinkFrame (); +} + +void Bot::ThinkFrame (void) +{ + UpdateLookAngles (); + RunPlayerMovement (); } void Bot::Think (void) diff --git a/source/manager.cpp b/source/manager.cpp index 88fe1a1..730a67c 100644 --- a/source/manager.cpp +++ b/source/manager.cpp @@ -1113,6 +1113,8 @@ void Bot::NewRound (void) if (Random.Long (0, 100) < 50) ChatterMessage (Chatter_NewRound); + + m_thinkInterval = (1.0f / 30.0f) * Random.Float (0.95f, 1.05f); } void Bot::Kill (void) diff --git a/source/navigate.cpp b/source/navigate.cpp index aa588b0..8eaa2ae 100644 --- a/source/navigate.cpp +++ b/source/navigate.cpp @@ -3189,6 +3189,8 @@ void Bot::UpdateLookAngles (void) float angleDiffYaw = AngleNormalize (direction.y - m_idealAngles.y); float angleDiffPitch = AngleNormalize (direction.x - m_idealAngles.x); + const float delta = m_frameInterval; + if (angleDiffYaw < 1.0f && angleDiffYaw > -1.0f) { m_lookYawVel = 0.0f; @@ -3203,8 +3205,8 @@ void Bot::UpdateLookAngles (void) else if (accel < -accelerate) accel = -accelerate; - m_lookYawVel += m_frameInterval * accel; - m_idealAngles.y += m_frameInterval * m_lookYawVel; + m_lookYawVel += delta * accel; + m_idealAngles.y += delta * m_lookYawVel; } float accel = 2.0f * stiffness * angleDiffPitch - damping * m_lookPitchVel; @@ -3213,8 +3215,8 @@ void Bot::UpdateLookAngles (void) else if (accel < -accelerate) accel = -accelerate; - m_lookPitchVel += m_frameInterval * accel; - m_idealAngles.x += m_frameInterval * m_lookPitchVel; + m_lookPitchVel += delta * accel; + m_idealAngles.x += delta * m_lookPitchVel; if (m_idealAngles.x < -89.0f) m_idealAngles.x = -89.0f;