fix: center-screen messages not appearing (fix: #446)

fix: crash when creating too much threads
refactor: fix typos in comments in headers
This commit is contained in:
jeefo 2023-05-12 22:12:22 +03:00
commit 7f4d4748fa
No known key found for this signature in database
GPG key ID: 927BCA0779BEA8ED
22 changed files with 105 additions and 99 deletions

View file

@ -8,7 +8,7 @@
#include <yapb.h>
ConVar cv_graph_analyze_auto_start ("yb_graph_analyze_auto_start", "1", "Autostart analyzer if all other cases are failed.");
ConVar cv_graph_analyze_auto_save ("yb_graph_analyze_auto_save", "1", "Auto save results of analyzation to graph file. And re-add bots.");
ConVar cv_graph_analyze_auto_save ("yb_graph_analyze_auto_save", "1", "Auto save results of analysis to graph file. And re-add bots.");
ConVar cv_graph_analyze_distance ("yb_graph_analyze_distance", "64", "The minimum distance to keep nodes from each other.", true, 42.0f, 128.0f);
ConVar cv_graph_analyze_max_jump_height ("yb_graph_analyze_max_jump_height", "44", "Max jump height to test if next node will be unreachable.", true, 44.0f, 64.0f);
ConVar cv_graph_analyze_fps ("yb_graph_analyze_fps", "30.0", "The FPS at which analyzer process is running. This keeps game from freezing during analyzing.", false, 25.0f, 99.0f);
@ -37,7 +37,7 @@ void GraphAnalyze::start () {
for (auto &optimized : m_optimizedNodes) {
optimized = false;
}
ctrl.msg ("Starting map analyzation.");
ctrl.msg ("Starting map analysis.");
}
else {
m_updateInterval = 0.0f;
@ -143,7 +143,7 @@ void GraphAnalyze::finish () {
// un-silence all graph messages
graph.setMessageSilence (false);
ctrl.msg ("Completed map analyzation.");
ctrl.msg ("Completed map analysis.");
// auto save bots graph
if (cv_graph_analyze_auto_save.bool_ ()) {

View file

@ -689,7 +689,7 @@ Vector Bot::getCampDirection (const Vector &dest) {
}
float minDistance = kInfiniteDistance;
int lookAtWaypoint = kInvalidNodeIndex;
int lookAtNode = kInvalidNodeIndex;
const Path &path = graph[tempIndex];
for (auto &link : path.links) {
@ -700,12 +700,12 @@ Vector Bot::getCampDirection (const Vector &dest) {
if (distance < minDistance) {
minDistance = distance;
lookAtWaypoint = link.index;
lookAtNode = link.index;
}
}
if (graph.exists (lookAtWaypoint)) {
return graph[lookAtWaypoint].origin;
if (graph.exists (lookAtNode)) {
return graph[lookAtNode].origin;
}
}
auto dangerIndex = practice.getIndex (m_team, m_currentNodeIndex, m_currentNodeIndex);
@ -1498,7 +1498,7 @@ void Bot::overrideConditions () {
if (isKnifeMode () && (util.isPlayer (m_enemy) || (cv_attack_monsters.bool_ () && util.isMonster (m_enemy)))) {
float length = pev->origin.distance2d (m_enemy->v.origin);
// do waypoint movement if enemy is not reachable with a knife
// do nodes movement if enemy is not reachable with a knife
if (length > 250.0f && (m_states & Sense::SeeingEnemy)) {
int nearestToEnemyPoint = graph.getNearest (m_enemy->v.origin);
@ -2490,7 +2490,7 @@ void Bot::checkRadioQueue () {
float minDistance = kInfiniteDistance;
int bombPoint = kInvalidNodeIndex;
// find nearest bomb waypoint to player
// find nearest bomb node to player
for (auto &point : graph.m_goalPoints) {
distance = graph[point].origin.distanceSq (m_radioEntity->v.origin);
@ -2500,7 +2500,7 @@ void Bot::checkRadioQueue () {
}
}
// mark this waypoint as restricted point
// mark this node as restricted point
if (bombPoint != kInvalidNodeIndex && !graph.isVisited (bombPoint)) {
// does this bot want to defuse?
if (getCurrentTaskId () == Task::Normal) {

View file

@ -2335,7 +2335,7 @@ void BotControl::createMenus () {
"0. Exit",
&BotControl::menuGraphPage2);
// select waypoint radius menu
// select nodes radius menu
m_menus.emplace (
Menu::NodeRadius, keys (9),
"\\yWaypoint Radius\\w\n\n"
@ -2351,7 +2351,7 @@ void BotControl::createMenus () {
"0. Exit",
&BotControl::menuGraphRadius);
// waypoint add menu
// nodes add menu
m_menus.emplace (
Menu::NodeType, keys (9),
"\\yWaypoint Type\\w\n\n"

View file

@ -38,8 +38,8 @@ void Game::precache () {
m_drawModels[DrawLine::Simple] = m_engineWrap.precacheModel ("sprites/laserbeam.spr");
m_drawModels[DrawLine::Arrow] = m_engineWrap.precacheModel ("sprites/arrow1.spr");
m_engineWrap.precacheSound ("weapons/xbow_hit1.wav"); // waypoint add
m_engineWrap.precacheSound ("weapons/mine_activate.wav"); // waypoint delete
m_engineWrap.precacheSound ("weapons/xbow_hit1.wav"); // node add
m_engineWrap.precacheSound ("weapons/mine_activate.wav"); // node delete
m_engineWrap.precacheSound ("common/wpn_hudon.wav"); // path add/delete done
m_mapFlags = 0; // reset map type as worldspawn is the first entity spawned
@ -474,10 +474,16 @@ uint8_t *Game::getVisibilitySet (Bot *bot, bool pvs) {
void Game::sendClientMessage (bool console, edict_t *ent, StringRef message) {
// helper to sending the client message
// do not send messages to fakeclients
// do not send messages to fake clients
if (!util.isPlayer (ent) || util.isFakeClient (ent)) {
return;
}
// if console message and destination is listenserver entity, just print via server message instead of through unreliable channel
if (console && ent == game.getLocalEntity ()) {
sendServerMessage (message);
return;
}
const String &buffer = message;
// used to split messages

View file

@ -675,7 +675,7 @@ void BotGraph::add (int type, const Vector &pos) {
else {
auto nearest = getEditorNearest ();
// do not allow to place waypoints "inside" waypoints, make at leat 10 units range
// do not allow to place node "inside" node, make at leat 10 units range
if (exists (nearest) && newOrigin.distanceSq (m_paths[nearest].origin) < cr::sqrf (10.0f)) {
msg ("Can't add node. It's way to near to %d node. Please move some units anywhere.", nearest);
return;
@ -981,7 +981,7 @@ bool BotGraph::isConnected (int a, int b) {
}
int BotGraph::getFacingIndex () {
// find the waypoint the user is pointing at
// find the node the user is pointing at
Twin <int32_t, float> result { kInvalidNodeIndex, 5.32f };
auto nearestNode = getEditorNearest ();
@ -991,7 +991,7 @@ int BotGraph::getFacingIndex () {
for (const auto &path : m_paths) {
// skip nearest waypoint to editor, since this used mostly for adding / removing paths
// skip nearest node to editor, since this used mostly for adding / removing paths
if (path.number == nearestNode) {
continue;
}
@ -999,12 +999,12 @@ int BotGraph::getFacingIndex () {
const auto &to = path.origin - m_editor->v.origin;
auto angles = (to.angles () - m_editor->v.v_angle).clampAngles ();
// skip the waypoints that are too far away from us, and we're not looking at them directly
// skip the nodes that are too far away from us, and we're not looking at them directly
if (to.lengthSq () > cr::sqrf (500.0f) || cr::abs (angles.y) > result.second) {
continue;
}
// check if visible, (we're not using visiblity tables here, as they not valid at time of waypoint editing)
// check if visible, (we're not using visibility tables here, as they not valid at time of node editing)
TraceResult tr {};
game.testLine (editorEyes, path.origin, TraceIgnore::Everything, m_editor, &tr);

View file

@ -1973,11 +1973,11 @@ void BotThreadWorker::startup (int workers) {
requestedThreadCount = 1;
}
}
requestedThreadCount = cr::clamp (requestedThreadCount, 1, hardwareConcurrency);
requestedThreadCount = cr::clamp (requestedThreadCount, 1, hardwareConcurrency - 1);
// notify user
game.print ("Starting up bot thread worker with %d threads.", requestedThreadCount);
// start up the worker
m_botWorker.startup (static_cast <int> (requestedThreadCount));
m_botWorker.startup (static_cast <size_t> (requestedThreadCount));
}

View file

@ -18,7 +18,7 @@ void Bot::normal_ () {
int debugGoal = cv_debug_goal.int_ ();
// user forced a waypoint as a goal?
// user forced a node as a goal?
if (debugGoal != kInvalidNodeIndex && getTask ()->data != debugGoal) {
clearSearchNodes ();
@ -127,7 +127,7 @@ void Bot::normal_ () {
}
}
else {
// some goal waypoints are map dependant so check it out...
// some goal nodes are map dependent so check it out...
if (game.mapIs (MapFlags::HostageRescue)) {
// CT Bot has some hostages following?
if (m_team == Team::CT && m_hasHostage) {
@ -190,7 +190,7 @@ void Bot::normal_ () {
auto currIndex = getTask ()->data;
auto destIndex = graph.exists (currIndex) ? currIndex : findBestGoal ();
// check for existence (this is fail over, for i.e. csdm, this should be not true with normal game play, only when spawned outside of covered area)
// check for existence (this is fail over, for i.e. CSDM, this should be not true with normal game play, only when spawned outside of covered area)
if (!graph.exists (destIndex)) {
destIndex = graph.getFarest (pev->origin, 1024.0f);
}
@ -207,7 +207,8 @@ void Bot::normal_ () {
}
ensureCurrentNodeIndex ();
// do pathfinding if it's not the current waypoint
// do pathfinding if it's not the current
if (destIndex != m_currentNodeIndex) {
findPath (m_currentNodeIndex, destIndex, pathSearchType);
}
@ -256,7 +257,7 @@ void Bot::spraypaint_ () {
m_entity = sprayOrigin;
if (getTask ()->time - 0.5f < game.time ()) {
// emit spraycan sound
// emit spray can sound
engfuncs.pfnEmitSound (ent (), CHAN_VOICE, "player/sprayer.wav", 1.0f, ATTN_NORM, 0, 100);
game.testLine (getEyesPos (), getEyesPos () + forward * 128.0f, TraceIgnore::Monsters, ent (), &tr);
@ -350,9 +351,9 @@ void Bot::seekCover_ () {
m_prevGoalIndex = kInvalidNodeIndex;
}
// reached final waypoint?
// reached final node?
else if (updateNavigation ()) {
// yep. activate hide behaviour
// yep. activate hide behavior
completeTask ();
m_prevGoalIndex = kInvalidNodeIndex;
@ -366,7 +367,7 @@ void Bot::seekCover_ () {
m_lookAtSafe = dest;
m_campDirection = 0;
// chosen waypoint is a camp waypoint?
// chosen node is a camp node?
if (m_pathFlags & NodeFlag::Camp) {
// use the existing camp node prefs
if (m_pathFlags & NodeFlag::Crouch) {
@ -709,7 +710,7 @@ void Bot::moveToPos_ () {
m_position = nullptr;
}
// didn't choose goal waypoint yet?
// didn't choose goal node yet?
else if (!hasActiveGoal ()) {
int destIndex = kInvalidNodeIndex;
int goal = getTask ()->data;
@ -804,7 +805,7 @@ void Bot::defuseBomb_ () {
// exception: bomb has been defused
if (bombPos.empty ()) {
// fix for stupid behaviour of CT's when bot is defused
// fix for stupid behavior of CT's when bot is defused
for (const auto &bot : bots) {
if (bot->m_team == m_team && bot->m_notKilled) {
auto defendPoint = graph.getFarest (bot->pev->origin);
@ -1034,13 +1035,13 @@ void Bot::followUser_ () {
getTask ()->data = kInvalidNodeIndex;
}
// didn't choose goal waypoint yet?
// didn't choose goal node yet?
if (!hasActiveGoal ()) {
int destIndex = graph.getNearest (m_targetEntity->v.origin);
auto points = graph.getNarestInRadius (200.0f, m_targetEntity->v.origin);
for (auto &newIndex : points) {
// if waypoint not yet used, assign it as dest
// if node not yet used, assign it as dest
if (newIndex != m_currentNodeIndex && !isOccupiedNode (newIndex)) {
destIndex = newIndex;
}
@ -1288,7 +1289,7 @@ void Bot::doublejump_ () {
getTask ()->data = kInvalidNodeIndex;
}
// didn't choose goal waypoint yet?
// didn't choose goal node yet?
if (!hasActiveGoal ()) {
int destIndex = graph.getNearest (m_doubleJumpOrigin);
@ -1339,7 +1340,7 @@ void Bot::escapeFromBomb_ () {
startTask (Task::Camp, TaskPri::Camp, kInvalidNodeIndex, game.time () + 10.0f, true);
}
// didn't choose goal waypoint yet?
// didn't choose goal node yet?
else if (!hasActiveGoal ()) {
int bestIndex = kInvalidNodeIndex;
@ -1591,7 +1592,6 @@ void Bot::pickupItem_ () {
return EntitySearchResult::Continue;
}
}
int hostageNodeIndex = graph.getNearest (ent->v.origin);
if (graph.exists (hostageNodeIndex)) {