bot: done some experiments with think timers

This commit is contained in:
jeefo 2025-08-23 16:24:13 +03:00
commit 90dde6690b
No known key found for this signature in database
GPG key ID: D696786B81B667C8
4 changed files with 32 additions and 26 deletions

View file

@ -519,6 +519,7 @@ private:
void findValidNode (); void findValidNode ();
void setPathOrigin (); void setPathOrigin ();
void fireWeapons (); void fireWeapons ();
void doFireWeapons ();
void selectWeapons (float distance, int index, int id, int choosen); void selectWeapons (float distance, int index, int id, int choosen);
void focusEnemy (); void focusEnemy ();
void selectBestWeapon (); void selectBestWeapon ();
@ -727,8 +728,8 @@ public:
Deque <int32_t> m_msgQueue {}; Deque <int32_t> m_msgQueue {};
Array <int32_t> m_goalHist {}; Array <int32_t> m_goalHist {};
FrameDelay m_thinkDelay {}; FrameDelay m_thinkTimer {};
FrameDelay m_commandDelay {}; FrameDelay m_fullThinkTimer {};
public: public:
Bot (edict_t *bot, int difficulty, int personality, int team, int skin); Bot (edict_t *bot, int difficulty, int personality, int team, int skin);

View file

@ -3007,24 +3007,26 @@ void Bot::checkParachute () {
} }
void Bot::frame () { void Bot::frame () {
pev->flags |= FL_CLIENT | FL_FAKECLIENT; // restore fake client bit, just in case if (m_thinkTimer.time < game.time ()) {
m_thinkTimer.time = game.time () + m_thinkTimer.interval;
const auto timestamp = game.time (); if (m_aimFlags && AimFlags::Enemy) {
focusEnemy ();
}
doFireWeapons ();
updateLookAngles ();
if (m_thinkDelay.time <= timestamp) { pev->flags |= FL_CLIENT | FL_FAKECLIENT; // restore fake client bit, just in case
update ();
// delay next execution for thinking if (m_fullThinkTimer.time < game.time ()) {
m_thinkDelay.time = timestamp + m_thinkDelay.interval; m_fullThinkTimer.time = game.time () + m_fullThinkTimer.interval;
}
// run bot command on twice speed update ();
if (m_commandDelay.time <= timestamp) { }
runMovement (); runMovement ();
m_commandDelay.time = timestamp + m_commandDelay.interval;
} }
if (m_slowFrameTimestamp > timestamp) { if (m_slowFrameTimestamp > game.time ()) {
return; return;
} }
@ -3390,11 +3392,7 @@ void Bot::logic () {
executeTasks (); // execute current task executeTasks (); // execute current task
setAimDirection (); // choose aim direction setAimDirection (); // choose aim direction
updateLookAngles (); // and turn to chosen aim direction updateLookAngles (); // and turn to chosen aim direction
doFireWeapons (); // do weapon firing
// the bots wants to fire at something?
if (m_shootAtDeadTime > game.time () || (m_wantsToFire && !m_isUsingGrenade && m_shootTime <= game.time ())) {
fireWeapons (); // if bot didn't fire a bullet try again next frame
}
// check for reloading // check for reloading
if (m_reloadCheckTime <= game.time ()) { if (m_reloadCheckTime <= game.time ()) {

View file

@ -1217,6 +1217,14 @@ void Bot::selectWeapons (float distance, int, int id, int choosen) {
} }
} }
void Bot::doFireWeapons () {
// the bots wants to fire at something?
if (m_shootAtDeadTime > game.time () || (m_wantsToFire && !m_isUsingGrenade && m_shootTime <= game.time ())) {
fireWeapons (); // if bot didn't fire a bullet try again next frame
}
}
void Bot::fireWeapons () { void Bot::fireWeapons () {
// this function will return true if weapon was fired, false otherwise // this function will return true if weapon was fired, false otherwise

View file

@ -1732,23 +1732,22 @@ void Bot::newRound () {
pushChatterMessage (Chatter::NewRound); pushChatterMessage (Chatter::NewRound);
} }
auto thinkFps = cr::clamp (cv_think_fps.as <float> (), 30.0f, 90.0f); auto thinkFps = cr::clamp (cv_think_fps.as <float> (), 30.0f, 90.0f);
auto thinkInterval = 1.0f / thinkFps;
auto updateInterval = 1.0f / thinkFps;
auto commandInterval = 1.0f / 60.0f;
if (game.is (GameFlags::Xash3D)) { if (game.is (GameFlags::Xash3D)) {
if (thinkFps < 50) { if (thinkFps < 50) {
updateInterval = 1.0f / 50.0f; // xash3d works acceptable at 50fps thinkInterval = 1.0f / 50.0f; // xash3d works acceptable at 50fps
} }
} }
auto fullThinkInterval = 1.0f / 10.0f;
// legacy games behaves strange, when this enabled, disable for xash3d as well if requested // legacy games behaves strange, when this enabled, disable for xash3d as well if requested
if (bots.isFrameSkipDisabled ()) { if (bots.isFrameSkipDisabled ()) {
updateInterval = 0.0f; thinkInterval = 0.0f;
commandInterval = 0.0f; fullThinkInterval = 0.0f;
} }
m_thinkDelay.interval = updateInterval; m_thinkTimer.interval = thinkInterval;
m_commandDelay.interval = commandInterval; m_fullThinkTimer.interval = fullThinkInterval;
} }
void Bot::resetPathSearchType () { void Bot::resetPathSearchType () {