2019-08-12 14:16:28 +03:00
|
|
|
//
|
2020-06-12 18:52:38 +03:00
|
|
|
// YaPB - Counter-Strike Bot based on PODBot by Markus Klinge.
|
2023-01-22 19:12:03 +06:00
|
|
|
// Copyright © 2004-2023 YaPB Project <yapb@jeefo.net>.
|
2019-08-12 14:16:28 +03:00
|
|
|
//
|
2020-11-03 08:57:12 +03:00
|
|
|
// SPDX-License-Identifier: MIT
|
2019-08-12 14:16:28 +03:00
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
// bot creation tab
|
2019-09-22 00:39:24 +03:00
|
|
|
struct BotRequest {
|
2019-08-12 14:16:28 +03:00
|
|
|
bool manual;
|
|
|
|
|
int difficulty;
|
|
|
|
|
int team;
|
2020-10-01 11:42:51 +03:00
|
|
|
int skin;
|
2019-08-12 14:16:28 +03:00
|
|
|
int personality;
|
|
|
|
|
String name;
|
|
|
|
|
};
|
|
|
|
|
|
2020-06-12 18:52:38 +03:00
|
|
|
// initial frustum data
|
|
|
|
|
struct FrustumData : public Singleton <FrustumData> {
|
|
|
|
|
private:
|
|
|
|
|
float Fov = 75.0f;
|
|
|
|
|
float AspectRatio = 1.33333f;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
float MaxView = 4096.0f;
|
aim: verify camp angles from nav data before using them
aim: tweaked a bit grenade handling, so bots should use them more
aim: reduce time between selecting grenade and throwing it away
aim: removed hacks in look angles code, due to removing yb_whoose_your_daddy cvar
aim: use direct enemy origin from visibility check, and not re-calculate it
aim: update enemy prediction, so it now depends on frame interval for a bot
aim: additional height offset are tweaked, and now used only for difficulty 4
nav: tweaked a bit player avoidance code, and it's not preventing bot from checking terrain
nav: do not check banned nodes, when bucket sizes re too low
nav: cover nodes are now selected depending on total bots on server
nav: let bot enter pause task after long jump
nav: extend velocity by a little for a jump, like it was in first versions of bot
nav: stuck checking is now taken in account lower minimal speed if bot is ducking
fix: navigation reachability timers, so bots will have correct current node index while camping
fix: bots are unable to finish pickup or destroy breakable task, if target is not reachable
fix: cover nodes are now calculated as they should
fix: manual calling bots add_[t/ct] now ignores yb_join_team cvar
bot: tweaked a little difficulty levels, so level 4 is now nightmare level, and 3 is very heard
bot: minor refactoring and moving functions to correct source file
bot: add yb_economics_disrespect_percent, so bots can ignore economics and buy more different guns
bot: add yb_check_darkness that allows to disable darkness checks for bot, thus disallowing usage of flashlight
bot: camp buttons are now lightly depends on bot health
chat: welcome chat message from bots is now sent during first freeze time period
crlib: switch over to stdint.h and remove crlib-own types
crlib: fixed alignment in sse code
2023-04-07 14:46:49 +03:00
|
|
|
float MinView = 2.0f;
|
2020-06-12 18:52:38 +03:00
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
float farHeight; // height of the far frustum
|
|
|
|
|
float farWidth; // width of the far frustum
|
|
|
|
|
|
|
|
|
|
float nearHeight; // height of the near frustum
|
|
|
|
|
float nearWidth; // width of the near frustum
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
FrustumData () {
|
|
|
|
|
nearHeight = 2.0f * cr::tanf (Fov * 0.0174532925f * 0.5f) * MinView;
|
|
|
|
|
nearWidth = nearHeight * AspectRatio;
|
|
|
|
|
|
|
|
|
|
farHeight = 2.0f * cr::tanf (Fov * 0.0174532925f * 0.5f) * MaxView;
|
|
|
|
|
farWidth = farHeight * AspectRatio;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// declare global frustum data
|
|
|
|
|
CR_EXPOSE_GLOBAL_SINGLETON (FrustumData, frustum);
|
|
|
|
|
|
2019-08-12 14:16:28 +03:00
|
|
|
// manager class
|
|
|
|
|
class BotManager final : public Singleton <BotManager> {
|
|
|
|
|
public:
|
|
|
|
|
using ForEachBot = Lambda <bool (Bot *)>;
|
|
|
|
|
using UniqueBot = UniquePtr <Bot>;
|
|
|
|
|
|
|
|
|
|
private:
|
2023-04-02 12:17:12 +03:00
|
|
|
float m_timeRoundStart {};
|
|
|
|
|
float m_timeRoundEnd {};
|
|
|
|
|
float m_timeRoundMid {};
|
2019-08-12 14:16:28 +03:00
|
|
|
|
2023-04-12 23:03:36 +03:00
|
|
|
float m_difficultyBalanceTime {}; // time to balance difficulties ?
|
2023-04-02 12:17:12 +03:00
|
|
|
float m_autoKillCheckTime {}; // time to kill all the bots ?
|
|
|
|
|
float m_maintainTime {}; // time to maintain bot creation
|
|
|
|
|
float m_quotaMaintainTime {}; // time to maintain bot quota
|
2020-11-23 13:11:28 +03:00
|
|
|
float m_grenadeUpdateTime {}; // time to update active grenades
|
2023-05-06 20:14:03 +03:00
|
|
|
float m_entityUpdateTime {}; // time to update interesting entities
|
2020-11-23 13:11:28 +03:00
|
|
|
float m_plantSearchUpdateTime {}; // time to update for searching planted bomb
|
|
|
|
|
float m_lastChatTime {}; // global chat time timestamp
|
|
|
|
|
float m_timeBombPlanted {}; // time the bomb were planted
|
|
|
|
|
float m_lastRadioTime[kGameTeamNum] {}; // global radio time
|
2019-08-12 14:16:28 +03:00
|
|
|
|
2023-04-02 12:17:12 +03:00
|
|
|
int m_lastWinner {}; // the team who won previous round
|
|
|
|
|
int m_lastDifficulty {}; // last bots difficulty
|
|
|
|
|
int m_bombSayStatus {}; // some bot is issued whine about bomb
|
2020-11-23 13:11:28 +03:00
|
|
|
int m_lastRadio[kGameTeamNum] {}; // last radio message for team
|
2019-08-12 14:16:28 +03:00
|
|
|
|
2023-05-12 22:12:22 +03:00
|
|
|
bool m_leaderChoosen[kGameTeamNum] {}; // is team leader choose thees round
|
2020-11-23 13:11:28 +03:00
|
|
|
bool m_economicsGood[kGameTeamNum] {}; // is team able to buy anything
|
2023-04-02 12:17:12 +03:00
|
|
|
bool m_bombPlanted {};
|
|
|
|
|
bool m_botsCanPause {};
|
|
|
|
|
bool m_roundOver {};
|
2019-08-12 14:16:28 +03:00
|
|
|
|
2023-04-02 12:17:12 +03:00
|
|
|
Array <edict_t *> m_activeGrenades {}; // holds currently active grenades on the map
|
2023-05-06 20:14:03 +03:00
|
|
|
Array <edict_t *> m_interestingEntities {}; // holds currently interesting entities on the map
|
2019-08-12 14:16:28 +03:00
|
|
|
|
2023-04-02 12:17:12 +03:00
|
|
|
Deque <String> m_saveBotNames {}; // bots names that persist upon changelevel
|
|
|
|
|
Deque <BotRequest> m_addRequests {}; // bot creation tab
|
|
|
|
|
SmallArray <BotTask> m_filters {}; // task filters
|
|
|
|
|
SmallArray <UniqueBot> m_bots {}; // all available bots
|
2019-08-12 14:16:28 +03:00
|
|
|
|
2023-04-02 12:17:12 +03:00
|
|
|
edict_t *m_killerEntity {}; // killer entity for bots
|
2020-06-12 18:52:38 +03:00
|
|
|
FrustumData m_frustumData {};
|
2019-08-12 14:16:28 +03:00
|
|
|
|
|
|
|
|
protected:
|
2020-10-01 11:42:51 +03:00
|
|
|
BotCreateResult create (StringRef name, int difficulty, int personality, int team, int skin);
|
2019-08-12 14:16:28 +03:00
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
BotManager ();
|
|
|
|
|
~BotManager () = default;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
Twin <int, int> countTeamPlayers ();
|
|
|
|
|
|
|
|
|
|
Bot *findBotByIndex (int index);
|
|
|
|
|
Bot *findBotByEntity (edict_t *ent);
|
|
|
|
|
|
|
|
|
|
Bot *findAliveBot ();
|
|
|
|
|
Bot *findHighestFragBot (int team);
|
|
|
|
|
|
|
|
|
|
int getHumansCount (bool ignoreSpectators = false);
|
|
|
|
|
int getAliveHumansCount ();
|
aim: verify camp angles from nav data before using them
aim: tweaked a bit grenade handling, so bots should use them more
aim: reduce time between selecting grenade and throwing it away
aim: removed hacks in look angles code, due to removing yb_whoose_your_daddy cvar
aim: use direct enemy origin from visibility check, and not re-calculate it
aim: update enemy prediction, so it now depends on frame interval for a bot
aim: additional height offset are tweaked, and now used only for difficulty 4
nav: tweaked a bit player avoidance code, and it's not preventing bot from checking terrain
nav: do not check banned nodes, when bucket sizes re too low
nav: cover nodes are now selected depending on total bots on server
nav: let bot enter pause task after long jump
nav: extend velocity by a little for a jump, like it was in first versions of bot
nav: stuck checking is now taken in account lower minimal speed if bot is ducking
fix: navigation reachability timers, so bots will have correct current node index while camping
fix: bots are unable to finish pickup or destroy breakable task, if target is not reachable
fix: cover nodes are now calculated as they should
fix: manual calling bots add_[t/ct] now ignores yb_join_team cvar
bot: tweaked a little difficulty levels, so level 4 is now nightmare level, and 3 is very heard
bot: minor refactoring and moving functions to correct source file
bot: add yb_economics_disrespect_percent, so bots can ignore economics and buy more different guns
bot: add yb_check_darkness that allows to disable darkness checks for bot, thus disallowing usage of flashlight
bot: camp buttons are now lightly depends on bot health
chat: welcome chat message from bots is now sent during first freeze time period
crlib: switch over to stdint.h and remove crlib-own types
crlib: fixed alignment in sse code
2023-04-07 14:46:49 +03:00
|
|
|
int getPlayerPriority (edict_t *ent);
|
2020-06-12 18:52:38 +03:00
|
|
|
|
2020-10-03 16:39:09 +03:00
|
|
|
float getConnectTime (StringRef name, float original);
|
2020-09-16 13:07:47 +03:00
|
|
|
float getAverageTeamKPD (bool calcForBots);
|
2019-08-12 14:16:28 +03:00
|
|
|
|
|
|
|
|
void setBombPlanted (bool isPlanted);
|
|
|
|
|
void frame ();
|
|
|
|
|
void createKillerEntity ();
|
|
|
|
|
void destroyKillerEntity ();
|
|
|
|
|
void touchKillerEntity (Bot *bot);
|
|
|
|
|
void destroy ();
|
2020-10-01 11:42:51 +03:00
|
|
|
void addbot (StringRef name, int difficulty, int personality, int team, int skin, bool manual);
|
|
|
|
|
void addbot (StringRef name, StringRef difficulty, StringRef personality, StringRef team, StringRef skin, bool manual);
|
2019-08-12 14:16:28 +03:00
|
|
|
void serverFill (int selection, int personality = Personality::Normal, int difficulty = -1, int numToAdd = -1);
|
|
|
|
|
void kickEveryone (bool instant = false, bool zeroQuota = true);
|
|
|
|
|
void kickBot (int index);
|
|
|
|
|
void kickFromTeam (Team team, bool removeAll = false);
|
|
|
|
|
void killAllBots (int team = -1);
|
|
|
|
|
void maintainQuota ();
|
2020-02-08 00:03:52 +03:00
|
|
|
void maintainAutoKill ();
|
2020-06-12 18:52:38 +03:00
|
|
|
void maintainLeaders ();
|
2019-08-12 14:16:28 +03:00
|
|
|
void initQuota ();
|
|
|
|
|
void initRound ();
|
|
|
|
|
void decrementQuota (int by = 1);
|
|
|
|
|
void selectLeaders (int team, bool reset);
|
|
|
|
|
void listBots ();
|
|
|
|
|
void setWeaponMode (int selection);
|
|
|
|
|
void updateTeamEconomics (int team, bool setTrue = false);
|
|
|
|
|
void updateBotDifficulties ();
|
2020-09-16 13:07:47 +03:00
|
|
|
void balanceBotDifficulties ();
|
2019-08-12 14:16:28 +03:00
|
|
|
void reset ();
|
|
|
|
|
void initFilters ();
|
|
|
|
|
void resetFilters ();
|
|
|
|
|
void updateActiveGrenade ();
|
2023-05-06 20:14:03 +03:00
|
|
|
void updateInterestingEntities ();
|
2019-08-12 14:16:28 +03:00
|
|
|
void captureChatRadio (const char *cmd, const char *arg, edict_t *ent);
|
|
|
|
|
void notifyBombDefuse ();
|
2020-06-12 18:52:38 +03:00
|
|
|
void execGameEntity (edict_t *ent);
|
2019-08-12 14:16:28 +03:00
|
|
|
void forEach (ForEachBot handler);
|
|
|
|
|
void erase (Bot *bot);
|
|
|
|
|
void handleDeath (edict_t *killer, edict_t *victim);
|
2019-09-21 23:20:33 +03:00
|
|
|
void setLastWinner (int winner);
|
2023-05-08 00:44:14 +03:00
|
|
|
void checkBotModel (edict_t *ent, char *infobuffer);
|
2019-08-12 14:16:28 +03:00
|
|
|
|
|
|
|
|
bool isTeamStacked (int team);
|
2019-08-18 21:00:00 +03:00
|
|
|
bool kickRandom (bool decQuota = true, Team fromTeam = Team::Unassigned);
|
2019-08-12 14:16:28 +03:00
|
|
|
|
|
|
|
|
public:
|
2020-06-12 18:52:38 +03:00
|
|
|
const Array <edict_t *> &getActiveGrenades () {
|
2019-08-12 14:16:28 +03:00
|
|
|
return m_activeGrenades;
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-06 20:14:03 +03:00
|
|
|
const Array <edict_t *> &getInterestingEntities () {
|
|
|
|
|
return m_interestingEntities;
|
2019-08-12 14:16:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool hasActiveGrenades () const {
|
|
|
|
|
return !m_activeGrenades.empty ();
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-06 20:14:03 +03:00
|
|
|
bool hasInterestingEntities () const {
|
|
|
|
|
return !m_interestingEntities.empty ();
|
2019-08-12 14:16:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool checkTeamEco (int team) const {
|
|
|
|
|
return m_economicsGood[team];
|
|
|
|
|
}
|
|
|
|
|
|
aim: verify camp angles from nav data before using them
aim: tweaked a bit grenade handling, so bots should use them more
aim: reduce time between selecting grenade and throwing it away
aim: removed hacks in look angles code, due to removing yb_whoose_your_daddy cvar
aim: use direct enemy origin from visibility check, and not re-calculate it
aim: update enemy prediction, so it now depends on frame interval for a bot
aim: additional height offset are tweaked, and now used only for difficulty 4
nav: tweaked a bit player avoidance code, and it's not preventing bot from checking terrain
nav: do not check banned nodes, when bucket sizes re too low
nav: cover nodes are now selected depending on total bots on server
nav: let bot enter pause task after long jump
nav: extend velocity by a little for a jump, like it was in first versions of bot
nav: stuck checking is now taken in account lower minimal speed if bot is ducking
fix: navigation reachability timers, so bots will have correct current node index while camping
fix: bots are unable to finish pickup or destroy breakable task, if target is not reachable
fix: cover nodes are now calculated as they should
fix: manual calling bots add_[t/ct] now ignores yb_join_team cvar
bot: tweaked a little difficulty levels, so level 4 is now nightmare level, and 3 is very heard
bot: minor refactoring and moving functions to correct source file
bot: add yb_economics_disrespect_percent, so bots can ignore economics and buy more different guns
bot: add yb_check_darkness that allows to disable darkness checks for bot, thus disallowing usage of flashlight
bot: camp buttons are now lightly depends on bot health
chat: welcome chat message from bots is now sent during first freeze time period
crlib: switch over to stdint.h and remove crlib-own types
crlib: fixed alignment in sse code
2023-04-07 14:46:49 +03:00
|
|
|
int32_t getLastWinner () const {
|
2019-08-12 14:16:28 +03:00
|
|
|
return m_lastWinner;
|
|
|
|
|
}
|
|
|
|
|
|
aim: verify camp angles from nav data before using them
aim: tweaked a bit grenade handling, so bots should use them more
aim: reduce time between selecting grenade and throwing it away
aim: removed hacks in look angles code, due to removing yb_whoose_your_daddy cvar
aim: use direct enemy origin from visibility check, and not re-calculate it
aim: update enemy prediction, so it now depends on frame interval for a bot
aim: additional height offset are tweaked, and now used only for difficulty 4
nav: tweaked a bit player avoidance code, and it's not preventing bot from checking terrain
nav: do not check banned nodes, when bucket sizes re too low
nav: cover nodes are now selected depending on total bots on server
nav: let bot enter pause task after long jump
nav: extend velocity by a little for a jump, like it was in first versions of bot
nav: stuck checking is now taken in account lower minimal speed if bot is ducking
fix: navigation reachability timers, so bots will have correct current node index while camping
fix: bots are unable to finish pickup or destroy breakable task, if target is not reachable
fix: cover nodes are now calculated as they should
fix: manual calling bots add_[t/ct] now ignores yb_join_team cvar
bot: tweaked a little difficulty levels, so level 4 is now nightmare level, and 3 is very heard
bot: minor refactoring and moving functions to correct source file
bot: add yb_economics_disrespect_percent, so bots can ignore economics and buy more different guns
bot: add yb_check_darkness that allows to disable darkness checks for bot, thus disallowing usage of flashlight
bot: camp buttons are now lightly depends on bot health
chat: welcome chat message from bots is now sent during first freeze time period
crlib: switch over to stdint.h and remove crlib-own types
crlib: fixed alignment in sse code
2023-04-07 14:46:49 +03:00
|
|
|
int32_t getBotCount () {
|
|
|
|
|
return m_bots.length <int32_t> ();
|
2020-06-12 18:52:38 +03:00
|
|
|
}
|
|
|
|
|
|
2019-08-12 14:16:28 +03:00
|
|
|
// get the list of filters
|
|
|
|
|
SmallArray <BotTask> &getFilters () {
|
|
|
|
|
return m_filters;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void createRandom (bool manual = false) {
|
|
|
|
|
addbot ("", -1, -1, -1, -1, manual);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool isBombPlanted () const {
|
|
|
|
|
return m_bombPlanted;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float getTimeBombPlanted () const {
|
|
|
|
|
return m_timeBombPlanted;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float getRoundStartTime () const {
|
|
|
|
|
return m_timeRoundStart;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float getRoundMidTime () const {
|
|
|
|
|
return m_timeRoundMid;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float getRoundEndTime () const {
|
|
|
|
|
return m_timeRoundEnd;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool isRoundOver () const {
|
2020-02-08 00:03:52 +03:00
|
|
|
return m_roundOver;
|
2019-08-12 14:16:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool canPause () const {
|
|
|
|
|
return m_botsCanPause;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void setCanPause (const bool pause) {
|
|
|
|
|
m_botsCanPause = pause;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool hasBombSay (int type) {
|
|
|
|
|
return (m_bombSayStatus & type) == type;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void clearBombSay (int type) {
|
|
|
|
|
m_bombSayStatus &= ~type;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void setPlantedBombSearchTimestamp (const float timestamp) {
|
|
|
|
|
m_plantSearchUpdateTime = timestamp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float getPlantedBombSearchTimestamp () const {
|
|
|
|
|
return m_plantSearchUpdateTime;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void setLastRadioTimestamp (const int team, const float timestamp) {
|
|
|
|
|
if (team == Team::CT || team == Team::Terrorist) {
|
|
|
|
|
m_lastRadioTime[team] = timestamp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float getLastRadioTimestamp (const int team) const {
|
|
|
|
|
if (team == Team::CT || team == Team::Terrorist) {
|
|
|
|
|
return m_lastRadioTime[team];
|
|
|
|
|
}
|
|
|
|
|
return 0.0f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void setLastRadio (const int team, const int radio) {
|
|
|
|
|
m_lastRadio[team] = radio;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int getLastRadio (const int team) const {
|
|
|
|
|
return m_lastRadio[team];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void setLastChatTimestamp (const float timestamp) {
|
|
|
|
|
m_lastChatTime = timestamp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float getLastChatTimestamp () const {
|
|
|
|
|
return m_lastChatTime;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// some bots are online ?
|
|
|
|
|
bool hasBotsOnline () {
|
|
|
|
|
return getBotCount () > 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
Bot *operator [] (int index) {
|
|
|
|
|
return findBotByIndex (index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Bot *operator [] (edict_t *ent) {
|
|
|
|
|
return findBotByEntity (ent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
UniqueBot *begin () {
|
|
|
|
|
return m_bots.begin ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UniqueBot *begin () const {
|
|
|
|
|
return m_bots.begin ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UniqueBot *end () {
|
|
|
|
|
return m_bots.end ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UniqueBot *end () const {
|
|
|
|
|
return m_bots.end ();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2023-05-06 20:14:03 +03:00
|
|
|
// bot async worker wrapper
|
|
|
|
|
class BotThreadWorker final : public Singleton <BotThreadWorker> {
|
|
|
|
|
private:
|
|
|
|
|
ThreadPool m_botWorker;
|
|
|
|
|
|
|
|
|
|
public:
|
2023-05-12 20:00:06 +03:00
|
|
|
explicit BotThreadWorker () = default;
|
2023-05-06 20:14:03 +03:00
|
|
|
~BotThreadWorker () = default;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
void shutdown ();
|
|
|
|
|
void startup (int workers);
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
template <typename F> void enqueue (F &&fn) {
|
|
|
|
|
if (m_botWorker.threadCount () == 0) {
|
|
|
|
|
fn (); // no threads, no fun, just run task in current thread
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-05-12 20:00:06 +03:00
|
|
|
m_botWorker.enqueue (cr::move (fn));
|
2023-05-06 20:14:03 +03:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2023-05-12 22:12:22 +03:00
|
|
|
// expose global
|
2020-06-12 18:52:38 +03:00
|
|
|
CR_EXPOSE_GLOBAL_SINGLETON (BotManager, bots);
|
2023-05-06 20:14:03 +03:00
|
|
|
|
|
|
|
|
// expose async worker
|
|
|
|
|
CR_EXPOSE_GLOBAL_SINGLETON (BotThreadWorker, worker);
|