From b8cb81f97a47a5a175a48ff3903a748752d4e2f4 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Tue, 9 Jun 2015 23:31:46 +0300 Subject: [PATCH] continue to play with msec ;) --- include/core.h | 6 +++++- source/basecode.cpp | 22 +++++++++++++++++++--- source/manager.cpp | 5 +++++ 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/include/core.h b/include/core.h index b60f49b..390fd9f 100644 --- a/include/core.h +++ b/include/core.h @@ -910,6 +910,10 @@ private: float m_frameInterval; // bot's frame interval float m_lastCommandTime; // time bot last thinked + float m_msecDel; + float m_msecVal; + float m_msecNum; + float m_reloadCheckTime; // time to check reloading float m_zoomCheckTime; // time to check zoom again float m_shieldCheckTime; // time to check shiled drawing again @@ -1041,7 +1045,7 @@ private: int GetBestSecondaryWeaponCarried (void); void RunPlayerMovement (void); - byte ThrottledMsec (float input); + byte ThrottledMsec (void); void GetValidWaypoint (void); void ChangeWptIndex (int waypointIndex); bool IsDeadlyDrop (Vector targetOriginPos); diff --git a/source/basecode.cpp b/source/basecode.cpp index 56c2877..5f5aeb8 100644 --- a/source/basecode.cpp +++ b/source/basecode.cpp @@ -5771,14 +5771,30 @@ void Bot::MoveToVector (Vector to) FindPath (m_currentWaypointIndex, g_waypoint->FindNearest (to), 0); } -byte Bot::ThrottledMsec (float input) +byte Bot::ThrottledMsec (void) { // estimate msec to use for this command based on time passed from the previous command - int newMsec = static_cast (input * 1000); + if (m_msecDel + m_msecNum / 1000 < GetWorldTime () - 0.5f || m_msecDel > GetWorldTime ()) + { + m_msecDel = GetWorldTime () - 0.05f; + m_msecNum = 0; + } + + byte newMsec = (GetWorldTime () - m_msecDel) * 1000 - m_msecNum; // optimal msec value since start of 1 sec period + m_msecNum = (GetWorldTime () - m_msecDel) * 1000; // value we have to add to reach optimum + + // do we have to start a new 1 sec period? + if (m_msecNum > 1000) + { + m_msecDel += m_msecNum / 1000; + m_msecNum = 0; + } // bots are going to be slower than they should if this happens. if (newMsec > 255) newMsec = 255; + else if (newMsec < 1) + newMsec = 1; return static_cast (newMsec); } @@ -5801,7 +5817,7 @@ void Bot::RunPlayerMovement (void) m_frameInterval = GetWorldTime () - m_lastCommandTime; - byte msecVal = ThrottledMsec (m_frameInterval); + byte msecVal = ThrottledMsec (); m_lastCommandTime = GetWorldTime (); (*g_engfuncs.pfnRunPlayerMove) (pev->pContainingEntity, m_moveAngles, m_moveSpeed, m_strafeSpeed, 0.0, pev->button, pev->impulse, msecVal); diff --git a/source/manager.cpp b/source/manager.cpp index a860116..8d680dd 100644 --- a/source/manager.cpp +++ b/source/manager.cpp @@ -793,6 +793,11 @@ Bot::Bot (edict_t *bot, int difficulty, int personality, int team, int member) m_lastCommandTime = GetWorldTime () - 0.1f; m_frameInterval = GetWorldTime (); + + m_msecDel = 0.0f; + m_msecVal = 0.0f; + m_msecNum = 0.0f; + m_timePeriodicUpdate = 0.0f; bot->v.idealpitch = bot->v.v_angle.x;