bot: done some experiments with think timers
This commit is contained in:
parent
34772be5ca
commit
90dde6690b
4 changed files with 32 additions and 26 deletions
|
|
@ -519,6 +519,7 @@ private:
|
|||
void findValidNode ();
|
||||
void setPathOrigin ();
|
||||
void fireWeapons ();
|
||||
void doFireWeapons ();
|
||||
void selectWeapons (float distance, int index, int id, int choosen);
|
||||
void focusEnemy ();
|
||||
void selectBestWeapon ();
|
||||
|
|
@ -727,8 +728,8 @@ public:
|
|||
Deque <int32_t> m_msgQueue {};
|
||||
Array <int32_t> m_goalHist {};
|
||||
|
||||
FrameDelay m_thinkDelay {};
|
||||
FrameDelay m_commandDelay {};
|
||||
FrameDelay m_thinkTimer {};
|
||||
FrameDelay m_fullThinkTimer {};
|
||||
|
||||
public:
|
||||
Bot (edict_t *bot, int difficulty, int personality, int team, int skin);
|
||||
|
|
|
|||
|
|
@ -3007,24 +3007,26 @@ void Bot::checkParachute () {
|
|||
}
|
||||
|
||||
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) {
|
||||
update ();
|
||||
pev->flags |= FL_CLIENT | FL_FAKECLIENT; // restore fake client bit, just in case
|
||||
|
||||
// delay next execution for thinking
|
||||
m_thinkDelay.time = timestamp + m_thinkDelay.interval;
|
||||
}
|
||||
if (m_fullThinkTimer.time < game.time ()) {
|
||||
m_fullThinkTimer.time = game.time () + m_fullThinkTimer.interval;
|
||||
|
||||
// run bot command on twice speed
|
||||
if (m_commandDelay.time <= timestamp) {
|
||||
update ();
|
||||
}
|
||||
runMovement ();
|
||||
m_commandDelay.time = timestamp + m_commandDelay.interval;
|
||||
}
|
||||
|
||||
if (m_slowFrameTimestamp > timestamp) {
|
||||
if (m_slowFrameTimestamp > game.time ()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -3390,11 +3392,7 @@ void Bot::logic () {
|
|||
executeTasks (); // execute current task
|
||||
setAimDirection (); // choose aim direction
|
||||
updateLookAngles (); // and turn to chosen aim direction
|
||||
|
||||
// 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
|
||||
}
|
||||
doFireWeapons (); // do weapon firing
|
||||
|
||||
// check for reloading
|
||||
if (m_reloadCheckTime <= game.time ()) {
|
||||
|
|
|
|||
|
|
@ -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 () {
|
||||
// this function will return true if weapon was fired, false otherwise
|
||||
|
||||
|
|
|
|||
|
|
@ -1732,23 +1732,22 @@ void Bot::newRound () {
|
|||
pushChatterMessage (Chatter::NewRound);
|
||||
}
|
||||
auto thinkFps = cr::clamp (cv_think_fps.as <float> (), 30.0f, 90.0f);
|
||||
|
||||
auto updateInterval = 1.0f / thinkFps;
|
||||
auto commandInterval = 1.0f / 60.0f;
|
||||
auto thinkInterval = 1.0f / thinkFps;
|
||||
|
||||
if (game.is (GameFlags::Xash3D)) {
|
||||
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
|
||||
if (bots.isFrameSkipDisabled ()) {
|
||||
updateInterval = 0.0f;
|
||||
commandInterval = 0.0f;
|
||||
thinkInterval = 0.0f;
|
||||
fullThinkInterval = 0.0f;
|
||||
}
|
||||
m_thinkDelay.interval = updateInterval;
|
||||
m_commandDelay.interval = commandInterval;
|
||||
m_thinkTimer.interval = thinkInterval;
|
||||
m_fullThinkTimer.interval = fullThinkInterval;
|
||||
}
|
||||
|
||||
void Bot::resetPathSearchType () {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue