diff --git a/ext/crlib/cr-alloc.h b/ext/crlib/cr-alloc.h index 40ddf6d..65b69bf 100644 --- a/ext/crlib/cr-alloc.h +++ b/ext/crlib/cr-alloc.h @@ -34,7 +34,7 @@ public: public: template T *allocate (const size_t length = 1) { - auto memory = reinterpret_cast (malloc (length * sizeof (T))); + auto memory = reinterpret_cast (malloc (cr::max (1u, length * sizeof (T)))); if (!memory) { plat.abort (); diff --git a/ext/crlib/cr-deque.h b/ext/crlib/cr-deque.h index a233a64..6052e25 100644 --- a/ext/crlib/cr-deque.h +++ b/ext/crlib/cr-deque.h @@ -113,7 +113,7 @@ private: } public: - explicit Deque () : contents_ (nullptr), capacity_ (0) + explicit Deque () : capacity_ (0), contents_ (nullptr) { } Deque (Deque &&rhs) : contents_ (cr::move (rhs.contents_)), capacity_ (rhs.capacity_) { diff --git a/ext/crlib/cr-platform.h b/ext/crlib/cr-platform.h index 5624411..9b7d678 100644 --- a/ext/crlib/cr-platform.h +++ b/ext/crlib/cr-platform.h @@ -102,6 +102,11 @@ CR_NAMESPACE_BEGIN # define __PLACEMENT_NEW_INLINE 1 #endif +// disabled gcc warnings +#if defined (CR_CXX_GCC) +# pragma GCC diagnostic ignored "-Wignored-attributes" +#endif + CR_NAMESPACE_END #if defined(CR_WINDOWS) diff --git a/inc/engine.h b/inc/engine.h index 91b4414..45a6515 100644 --- a/inc/engine.h +++ b/inc/engine.h @@ -120,8 +120,8 @@ public: using EntitySearch = Lambda ; private: - int m_drawModels[DrawLine::Count]; - int m_spawnCount[Team::Unassigned]; + int m_drawModels[DrawLine::Count] { }; + int m_spawnCount[Team::Unassigned] { }; // bot client command StringArray m_botArgs; @@ -608,6 +608,21 @@ public: ++m_cursor; } + + String readString () { + if (m_buffer.length () < m_cursor) { + return ""; + } + String out; + + for (; m_cursor < m_buffer.length () && m_buffer[m_cursor] != kNullChar; ++m_cursor) { + out += m_buffer[m_cursor]; + } + ++m_cursor; + + return out; + } + void shiftToEnd () { m_cursor = m_buffer.length (); } diff --git a/inc/manager.h b/inc/manager.h index d8a5fba..5ebad18 100644 --- a/inc/manager.h +++ b/inc/manager.h @@ -116,7 +116,7 @@ public: int getHumansCount (bool ignoreSpectators = false); int getAliveHumansCount (); - float getConnectTime (int botId, float original); + float getConnectTime (StringRef name, float original); float getAverageTeamKPD (bool calcForBots); void setBombPlanted (bool isPlanted); diff --git a/meson.build b/meson.build index d5bea2b..4ea7ed4 100644 --- a/meson.build +++ b/meson.build @@ -45,7 +45,7 @@ buildVersion = meson.project_version () compilerId = buildCompiler.get_id () compilerVersion = buildCompiler.version () -isOptimize = get_option ('buildtype') == 'release' +isOptimize = get_option ('buildtype') == 'release' or get_option ('buildtype') == 'debugoptimized' isVC = compilerId == 'msvc' or compilerId == 'intel-cl' or compilerId == 'clang-cl' isGCC = compilerId == 'gcc' isIntel = compilerId == 'intel' or compilerId == 'intel-cl' @@ -82,7 +82,11 @@ if isCLang or isGCC or (isIntel and not isWindows) '-m32', '-fno-threadsafe-statics', '-fno-exceptions', - '-fno-rtti', + '-fno-rtti' + ] + + flagsCompiler += [ + '-pedantic' ] if isOptimize @@ -132,7 +136,6 @@ if isLinux or isDarwin flagsCompiler += [ '-g3', '-ggdb', - '-O3', '-DCR_DEBUG' ] else diff --git a/src/engine.cpp b/src/engine.cpp index fbb0ef2..85cd233 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -27,9 +27,6 @@ Game::Game () { m_precached = false; - plat.bzero (m_drawModels, sizeof (m_drawModels)); - plat.bzero (m_spawnCount, sizeof (m_spawnCount)); - m_gameFlags = 0; m_mapFlags = 0; m_slowFrame = 0.0; diff --git a/src/graph.cpp b/src/graph.cpp index 14d2a86..7afcca7 100644 --- a/src/graph.cpp +++ b/src/graph.cpp @@ -870,7 +870,7 @@ void BotGraph::toggleFlags (int toggleFlag) { if (m_paths[index].flags & toggleFlag) { m_paths[index].flags &= ~toggleFlag; } - else if (!(m_paths[index].flags & toggleFlag)) { + else { if (toggleFlag == NodeFlag::Sniper && !(m_paths[index].flags & NodeFlag::Camp)) { ctrl.msg ("Cannot assign sniper flag to node %d. This is not camp node.", index); return; @@ -2277,13 +2277,13 @@ void BotGraph::frame () { } } - // create path pointer for faster access - auto &path = m_paths[nearestIndex]; - // draw a paths, camplines and danger directions for nearest node if (nearestDistance <= 56.0f && m_pathDisplayTime <= game.time ()) { m_pathDisplayTime = game.time () + 1.0f; + // create path pointer for faster access + auto &path = m_paths[nearestIndex]; + // draw the camplines if (path.flags & NodeFlag::Camp) { float height = 36.0f; @@ -2940,10 +2940,9 @@ void BotGraph::updateGlobalPractice () { // get the most dangerous node for this position for both teams for (int team = Team::Terrorist; team < kGameTeamNum; ++team) { int bestIndex = kInvalidNodeIndex; // best index to store - int maxDamage = 0; - + for (int i = 0; i < length (); ++i) { - maxDamage = 0; + int maxDamage = 0; bestIndex = kInvalidNodeIndex; for (int j = 0; j < length (); ++j) { diff --git a/src/manager.cpp b/src/manager.cpp index b1c921b..01a9f4f 100644 --- a/src/manager.cpp +++ b/src/manager.cpp @@ -757,11 +757,11 @@ void BotManager::listBots () { ctrl.msg ("%d bots", m_bots.length ()); } -float BotManager::getConnectTime (int botId, float original) { +float BotManager::getConnectTime (StringRef name, float original) { // this function get's fake bot player time. for (const auto &bot : m_bots) { - if (bot->entindex () == botId) { + if (name == bot->pev->netname.chars ()) { return bot->getConnectionTime (); } } diff --git a/src/navigate.cpp b/src/navigate.cpp index 4c5b85f..1f9414b 100644 --- a/src/navigate.cpp +++ b/src/navigate.cpp @@ -581,6 +581,7 @@ void Bot::checkTerrain (float movedDistance, const Vector &dirNormal) { do { sorting = false; + for (i = 0; i < 3; ++i) { if (state[i + kMaxCollideMoves] < state[i + kMaxCollideMoves + 1]) { cr::swap (state[i], state[i + 1]); @@ -591,8 +592,8 @@ void Bot::checkTerrain (float movedDistance, const Vector &dirNormal) { } } while (sorting); - for (i = 0; i < kMaxCollideMoves; ++i) { - m_collideMoves[i] = state[i]; + for (int j = 0; j < kMaxCollideMoves; ++j) { + m_collideMoves[j] = state[j]; } m_collideTime = game.time (); diff --git a/src/support.cpp b/src/support.cpp index bd87a87..18d1760 100644 --- a/src/support.cpp +++ b/src/support.cpp @@ -691,11 +691,11 @@ int32 BotSupport::sendTo (int socket, const void *message, size_t length, int fl for (uint8 i = 0; i < count; ++i) { buffer.skip (); // number - buffer.skipString (); // name + auto name = buffer.readString (); // name buffer.skip (); // score auto ctime = buffer.read (); // override connection time - buffer.write (bots.getConnectTime (i, ctime)); + buffer.write (bots.getConnectTime (name, ctime)); } return send (buffer.data ()); }