Permalink
Browse files

Merge Cleanup (#416)

* cleanup System

* cleanup Sim & Net

* cleanup Game/

* cleanup Rendering

* cleanup Lua rendering related

* cleanup Lua

* cleanup Map

* banish watchdog UB

* nlc cleanup Game/ std::

* nlc Lua

* nlc Net/

* nlc Rendering

* nlc System

* s/memset/assert

* s/auto/uint
  • Loading branch information...
gajop committed Nov 14, 2018
1 parent 62297f4 commit 63851c0aaee9adad0141cbb73581c38602ca91b3
Showing with 130 additions and 126 deletions.
  1. +1 −1 rts/Game/Camera/FreeController.cpp
  2. +3 −2 rts/Game/GameHelper.cpp
  3. +2 −2 rts/Game/TraceRay.cpp
  4. +4 −2 rts/Game/UI/QuitBox.cpp
  5. +4 −2 rts/Game/UI/ShareBox.cpp
  6. +10 −10 rts/Lua/LuaOpenGLUtils.cpp
  7. +2 −5 rts/Lua/LuaSyncedRead.cpp
  8. +2 −2 rts/Lua/LuaTextures.cpp
  9. +3 −2 rts/Lua/LuaUnitDefs.cpp
  10. +2 −2 rts/Lua/LuaUnsyncedRead.cpp
  11. +6 −5 rts/Lua/LuaWeaponDefs.cpp
  12. +4 −1 rts/Map/SMF/SMFReadMap.cpp
  13. +3 −3 rts/Net/GameServer.cpp
  14. +1 −1 rts/Rendering/DefaultPathDrawer.cpp
  15. +3 −1 rts/Rendering/Env/Decals/GroundDecalHandler.cpp
  16. +1 −1 rts/Rendering/Env/Decals/GroundDecalHandler.h
  17. +1 −1 rts/Rendering/Env/Particles/Classes/ShieldSegmentProjectile.cpp
  18. +1 −1 rts/Rendering/Env/Particles/Classes/ShieldSegmentProjectile.h
  19. +1 −0 rts/Rendering/Fonts/CFontTexture.cpp
  20. +1 −0 rts/Rendering/HUDDrawer.cpp
  21. +3 −6 rts/Rendering/Map/InfoTexture/Modern/Combiner.cpp
  22. +5 −5 rts/Rendering/Models/3DModel.cpp
  23. +1 −1 rts/Rendering/Shaders/Shader.cpp
  24. +11 −11 rts/Rendering/ShadowHandler.cpp
  25. +1 −1 rts/Rendering/Textures/Bitmap.cpp
  26. +1 −1 rts/Rendering/Textures/Bitmap.h
  27. +3 −3 rts/Rendering/Textures/QuadtreeAtlasAlloc.cpp
  28. +9 −9 rts/Rendering/Textures/TAPalette.cpp
  29. +2 −2 rts/Rendering/Textures/TextureAtlas.cpp
  30. +15 −18 rts/Rendering/Textures/nv_dds.cpp
  31. +3 −3 rts/Rendering/Textures/nv_dds.h
  32. +1 −1 rts/Sim/MoveTypes/StrafeAirMoveType.cpp
  33. +1 −2 rts/System/FileSystem/DataDirLocater.cpp
  34. +2 −2 rts/System/LoadSave/DemoReader.cpp
  35. +1 −1 rts/System/LoadSave/DemoRecorder.cpp
  36. +1 −0 rts/System/Log/Backend.cpp
  37. +2 −7 rts/System/Log/DefaultFilter.cpp
  38. +1 −1 rts/System/Matrix44f.cpp
  39. +3 −2 rts/System/Platform/CpuID.cpp
  40. +1 −1 rts/System/Platform/Threading.cpp
  41. +1 −1 rts/System/creg/Serializer.cpp
  42. +1 −1 rts/System/creg/creg.h
  43. +3 −3 rts/System/float3.cpp
  44. +3 −0 rts/System/myMath.cpp
@@ -359,7 +359,7 @@ float3 CFreeController::SwitchFrom() const
{
const float x = max(0.1f, min(float3::maxxpos - 0.1f, pos.x));
const float z = max(0.1f, min(float3::maxzpos - 0.1f, pos.z));
return float3(x, CGround::GetHeightAboveWater(x, z, false) + 5.0f, z);
return {x, CGround::GetHeightAboveWater(x, z, false) + 5.0f, z};
}
@@ -60,6 +60,7 @@ void CGameHelper::Update()
// need to use explicit indexing because CUnit::DoDamage
// can add *new* WaitingDamage's for this frame while we
// are still iterating
// NOLINTNEXTLINE(modernize-loop-convert)
for (size_t n = 0; n < waitingDamages[wdIdx].size(); n++) {
const WaitingDamage& wd = waitingDamages[wdIdx][n];
@@ -1223,8 +1224,8 @@ CGameHelper::BuildSquareStatus CGameHelper::TestBuildSquare(
CUnit* u = dynamic_cast<CUnit*>(so);
// blocking-map can lag behind because it is not updated every frame
assert(true || (so->pos.x >= xrange.x && so->pos.x <= xrange.y));
assert(true || (so->pos.z >= zrange.x && so->pos.z <= zrange.y));
assert(true || (so->pos.x >= xrange.x && so->pos.x <= xrange.y)); // NOLINT{misc-static-assert}
assert(true || (so->pos.z >= zrange.x && so->pos.z <= zrange.y)); // NOLINT{misc-static-assert}
if (f != nullptr) {
if ((allyteam < 0) || f->IsInLosForAllyTeam(allyteam)) {
@@ -391,7 +391,7 @@ float GuiTraceRay(
if (u == exclude)
continue;
// test this bit only in synced traces, rely on noSelect here
if (false && !u->HasCollidableStateBit(CSolidObject::CSTATE_BIT_QUADMAPRAYS))
if (false && !u->HasCollidableStateBit(CSolidObject::CSTATE_BIT_QUADMAPRAYS)) // NOLINT{readability-simplify-boolean-expr}
continue;
if (u->noSelect)
continue;
@@ -433,7 +433,7 @@ float GuiTraceRay(
if (!gu->spectatingFullView && !f->IsInLosForAllyTeam(gu->myAllyTeam))
continue;
// test this bit only in synced traces, rely on noSelect here
if (false && !f->HasCollidableStateBit(CSolidObject::CSTATE_BIT_QUADMAPRAYS))
if (false && !f->HasCollidableStateBit(CSolidObject::CSTATE_BIT_QUADMAPRAYS)) // NOLINT{misc-static-assert}
continue;
if (f->noSelect)
continue;
@@ -2,6 +2,8 @@
#include "QuitBox.h"
#include <cmath>
#include "MouseHandler.h"
#include "Game/GameSetup.h"
#include "Game/GlobalUnsynced.h"
@@ -21,7 +23,6 @@
#include <SDL_keycode.h>
#define MAX_QUIT_TEAMS (teamHandler.ActiveTeams() - 1)
#undef CreateDirectory
@@ -372,7 +373,8 @@ void CQuitBox::MouseMove(int x, int y, int dx, int dy, int button)
const float sz = scrollbarBox.y2 - scrollbarBox.y1;
const float tsz = sz / (float)MAX_QUIT_TEAMS;
*(volatile int *)&startTeam = std::max(0, std::min((int)(scr / tsz + 0.5), MAX_QUIT_TEAMS - numTeamsDisp));
// ??
*(volatile int*) &startTeam = std::max(0, std::min((int)std::lround(scr / tsz), MAX_QUIT_TEAMS - numTeamsDisp));
return;
}
@@ -2,6 +2,8 @@
#include "ShareBox.h"
#include <cmath>
#include "MouseHandler.h"
#include "Game/GlobalUnsynced.h"
#include "Game/SelectedUnitsHandler.h"
@@ -16,7 +18,6 @@
#include <SDL_keycode.h>
#define MAX_SHARE_TEAMS (teamHandler.ActiveTeams() - 1)
int CShareBox::lastShareTeam = 0;
@@ -397,7 +398,8 @@ void CShareBox::MouseMove(int x, int y, int dx, int dy, int button)
float sz = scrollbarBox.y2 - scrollbarBox.y1;
float tsz = sz / (float)MAX_SHARE_TEAMS;
*(volatile int *)&startTeam = std::max(0, std::min((int)(scr / tsz + 0.5), MAX_SHARE_TEAMS - numTeamsDisp));
// ??
*(volatile int*) &startTeam = std::max(0, std::min((int)std::lround(scr / tsz), MAX_SHARE_TEAMS - numTeamsDisp));
return;
}
@@ -765,7 +765,7 @@ int2 LuaMatTexture::GetSize() const
case LUATEX_NAMED: {
const CNamedTextures::TexInfo* namedTexInfo = CNamedTextures::GetInfo(*reinterpret_cast<const size_t*>(&data));
return int2(namedTexInfo->xsize, namedTexInfo->ysize);
return {namedTexInfo->xsize, namedTexInfo->ysize};
} break;
case LUATEX_LUATEXTURE: {
@@ -774,20 +774,20 @@ int2 LuaMatTexture::GetSize() const
const LuaTextures& luaTextures = CLuaHandle::GetActiveTextures(reinterpret_cast<lua_State*>(state));
const LuaTextures::Texture* luaTexture = luaTextures.GetInfo(*reinterpret_cast<const size_t*>(&data));
return int2(luaTexture->xsize, luaTexture->ysize);
return {luaTexture->xsize, luaTexture->ysize};
} break;
case LUATEX_UNITTEXTURE1: {
const CS3OTextureHandler::S3OTexMat* texMat = textureHandlerS3O.GetTexture(*reinterpret_cast<const int*>(&data));
return int2(texMat->tex1SizeX, texMat->tex1SizeY);
return {static_cast<int>(texMat->tex1SizeX), static_cast<int>(texMat->tex1SizeY)};
} break;
case LUATEX_UNITTEXTURE2: {
const CS3OTextureHandler::S3OTexMat* texMat = textureHandlerS3O.GetTexture(*reinterpret_cast<const int*>(&data));
return int2(texMat->tex2SizeX, texMat->tex2SizeY);
return {static_cast<int>(texMat->tex2SizeX), static_cast<int>(texMat->tex2SizeY)};
} break;
case LUATEX_3DOTEXTURE: {
return int2(textureHandler3DO.GetAtlasTexSizeX(), textureHandler3DO.GetAtlasTexSizeY());
return {static_cast<int>(textureHandler3DO.GetAtlasTexSizeX()), static_cast<int>(textureHandler3DO.GetAtlasTexSizeY())};
} break;
@@ -796,13 +796,13 @@ int2 LuaMatTexture::GetSize() const
const UnitDef* ud = reinterpret_cast<const UnitDef*>(data);
unitDrawer->GetUnitDefImage(ud); // forced existance
const UnitDefImage* bp = ud->buildPic;
return int2(bp->imageSizeX, bp->imageSizeY);
return {bp->imageSizeX, bp->imageSizeY};
}
} break;
case LUATEX_UNITRADARICON: {
const UnitDef* ud = reinterpret_cast<const UnitDef*>(data);
const icon::CIcon it = ud->iconType;
return int2(it->GetSizeX(), it->GetSizeY());
return {it->GetSizeX(), it->GetSizeY()};
} break;
@@ -823,7 +823,7 @@ int2 LuaMatTexture::GetSize() const
} break;
case LUATEX_HEIGHTMAP: {
if (heightMapTexture != nullptr)
return int2(heightMapTexture->GetSizeX(), heightMapTexture->GetSizeY());
return {heightMapTexture->GetSizeX(), heightMapTexture->GetSizeY()};
} break;
@@ -890,9 +890,9 @@ int2 LuaMatTexture::GetSize() const
case LUATEX_FONT:
return int2(font->GetTextureWidth(), font->GetTextureHeight());
return {font->GetTextureWidth(), font->GetTextureHeight()};
case LUATEX_FONTSMALL:
return int2(smallFont->GetTextureWidth(), smallFont->GetTextureHeight());
return {smallFont->GetTextureWidth(), smallFont->GetTextureHeight()};
case LUATEX_NONE:
@@ -452,11 +452,8 @@ static inline bool IsProjectileVisible(lua_State* L, const CProjectile* pro)
if (CLuaHandle::GetHandleReadAllyTeam(L) < 0)
return CLuaHandle::GetHandleFullRead(L);
if ((CLuaHandle::GetHandleReadAllyTeam(L) != pro->GetAllyteamID()) &&
(!losHandler->InLos(pro->pos, CLuaHandle::GetHandleReadAllyTeam(L)))) {
return false;
}
return true;
return !((CLuaHandle::GetHandleReadAllyTeam(L) != pro->GetAllyteamID()) &&
(!losHandler->InLos(pro->pos, CLuaHandle::GetHandleReadAllyTeam(L))));
}
@@ -88,13 +88,13 @@ std::string LuaTextures::Create(const Texture& tex)
if (freeIndices.empty()) {
textureMap.insert(buf, textureVec.size());
textureVec.emplace_back(std::move(newTex));
textureVec.emplace_back(newTex);
return buf;
}
// recycle
textureMap[buf] = freeIndices.back();
textureVec[freeIndices.back()] = std::move(newTex);
textureVec[freeIndices.back()] = newTex;
freeIndices.pop_back();
return buf;
}
@@ -75,8 +75,9 @@ bool LuaUnitDefs::PushEntries(lua_State* L)
const std::array<const IndxFuncType, 3> indxFuncs = {{UnitDefIndex, UnitDefNewIndex, UnitDefMetatable}};
const std::array<const IterFuncType, 2> iterFuncs = {{Pairs, Next}};
for (auto it = defsVec.cbegin(); it != defsVec.cend(); ++it) {
const auto def = unitDefHandler->GetUnitDefByID(it->id);
for (const auto& unitDef: defsVec) {
// The first unitDef is invalid (dummy), so we skip it
const auto def = unitDefHandler->GetUnitDefByID(unitDef.id);
if (def == nullptr)
continue;
@@ -1281,13 +1281,13 @@ int LuaUnsyncedRead::GetWaterMode(lua_State* L)
int LuaUnsyncedRead::GetMapDrawMode(lua_State* L)
{
std::string mode = infoTextureHandler->GetMode();
if (mode == "") { mode = "normal"; } else // NOLINT(readability-container-size-empty)
if (mode == "") { mode = "normal"; } else // NOLINT
if (mode == "path") { mode = "pathTraversability"; } else
if (mode == "heat") { mode = "pathHeat"; } else
if (mode == "flow") { mode = "pathFlow"; } else
if (mode == "pathcost") { mode = "pathCost"; }
lua_pushsstring(L, mode);
lua_pushsstring(L, mode); // NOLINT{readability-misleading-indentation}
return 1;
}
@@ -74,8 +74,9 @@ bool LuaWeaponDefs::PushEntries(lua_State* L)
const std::array<const IndxFuncType, 3> indxFuncs = {{WeaponDefIndex, WeaponDefNewIndex, WeaponDefMetatable}};
const std::array<const IterFuncType, 2> iterFuncs = {{Pairs, Next}};
for (auto it = defsVec.cbegin(); it != defsVec.cend(); ++it) {
const auto def = weaponDefHandler->GetWeaponDefByID(it->id);
for (const auto& weaponDef: defsVec) {
// The first weaponDef is invalid (dummy), so we skip it
const auto def = weaponDefHandler->GetWeaponDefByID(weaponDef.id);
if (def == nullptr)
continue;
@@ -370,9 +371,9 @@ static int CustomParamsTable(lua_State* L, const void* data)
const spring::unordered_map<std::string, std::string>& params = *((const spring::unordered_map<std::string, std::string>*)data);
lua_newtable(L);
for (auto it = params.cbegin(); it != params.cend(); ++it) {
lua_pushsstring(L, it->first);
lua_pushsstring(L, it->second);
for (const auto& param: params) {
lua_pushsstring(L, param.first);
lua_pushsstring(L, param.second);
lua_rawset(L, -3);
}
return 1;
@@ -61,7 +61,10 @@ CSMFReadMap::CSMFReadMap(const std::string& mapName): CEventClient("[CSMFReadMap
haveSplatDetailDistribTexture = (!mapInfo->smf.splatDetailTexName.empty() && !mapInfo->smf.splatDistrTexName.empty());
haveSplatNormalDistribTexture = false;
memset(&splatNormalTextures[0], 0, NUM_SPLAT_DETAIL_NORMALS * sizeof(splatNormalTextures[0]));
for (const MapTexture& mapTex: splatNormalTextures) {
assert(!mapTex.HasLuaTex());
assert(mapTex.GetID() == 0);
}
for (const std::string& texName: mapInfo->smf.splatDetailNormalTexNames) {
haveSplatNormalDistribTexture |= !texName.empty();
@@ -132,8 +132,7 @@ CGameServer::CGameServer(
const std::shared_ptr<const GameData> newGameData,
const std::shared_ptr<const CGameSetup> newGameSetup
)
: quitServer(false)
, serverFrameNum(-1)
: serverFrameNum(-1)
, serverStartTime(spring_gettime())
, readyTime(spring_notime)
@@ -168,6 +167,7 @@ CGameServer::CGameServer(
, gameHasStarted(false)
, generatedGameID(false)
, reloadingServer(false)
, quitServer(false)
{
myClientSetup = newClientSetup;
myGameData = newGameData;
@@ -2159,7 +2159,7 @@ void CGameServer::StartGame(bool forced)
const unsigned int team = p.team;
const float3& teamStartPos = teams[team].GetStartPos();
if (false && !teams[team].HasLeader())
if (false && !teams[team].HasLeader()) // NOLINT{readability-simplify-boolean-expr}
continue;
teamStartPosSent[team] = true;
@@ -539,7 +539,7 @@ void DefaultPathDrawer::Draw(const CPathEstimator* pe) const {
}
#if (PE_EXTRA_DEBUG_OVERLAYS == 1)
if ((drawLowResPE || drawMedResPE) && false) {
if ((drawLowResPE || drawMedResPE) && false) { // NOLINT{readability-simplify-boolean-expr}
const PathNodeBuffer& openBlockBuffer = pe->openBlockBuffer;
char blockCostsStr[32];
@@ -815,8 +815,10 @@ void CGroundDecalHandler::TestScarOverlaps(const Scar& scar)
for (int y = y1; y <= y2; ++y) {
for (int x = x1; x <= x2; ++x) {
auto& quad = scarField[y * scarFieldX+ x];
auto& quad = scarField[y * scarFieldX + x];
// The quad might change in the loop below
// NOLINTNEXTLINE{modernize-loop-convert}
for (size_t i = 0; i < quad.size(); i++) {
Scar& testScar = scars[ quad[i] ];
@@ -275,7 +275,7 @@ class CGroundDecalHandler: public IGroundDecalDrawer, public CEventClient, publi
std::vector<int> addedScars;
// stores indices into <scars> of reserved slots, per quad
std::vector< std::vector<int> > scarField;
std::vector<std::vector<int>> scarField;
int scarFieldX;
@@ -43,7 +43,7 @@ static spring::unsynced_map<const AtlasedTexture*, std::vector<float2> > spheret
ShieldSegmentCollection& ShieldSegmentCollection::operator = (ShieldSegmentCollection&& ssc) {
ShieldSegmentCollection& ShieldSegmentCollection::operator=(ShieldSegmentCollection&& ssc) noexcept {
shield = ssc.shield; ssc.shield = nullptr;
shieldTexture = ssc.shieldTexture; ssc.shieldTexture = nullptr;
@@ -26,7 +26,7 @@ class ShieldSegmentCollection
ShieldSegmentCollection(ShieldSegmentCollection&& ssc) { *this = std::move(ssc); }
~ShieldSegmentCollection() { Kill(); }
ShieldSegmentCollection& operator = (ShieldSegmentCollection&& ssc);
ShieldSegmentCollection& operator=(ShieldSegmentCollection&& ssc) noexcept;
void Init(CPlasmaRepulser*);
void Kill();
@@ -263,6 +263,7 @@ static std::shared_ptr<FontFace> GetFontFace(const std::string& fontfile, const
#ifndef HEADLESS
// NOLINTNEXTLINE{misc-misplaced-const}
static std::shared_ptr<FontFace> GetFontForCharacters(const std::vector<char32_t>& characters, const FT_Face origFace, const int origSize)
{
#if defined(USE_FONTCONFIG)
@@ -16,6 +16,7 @@
#include "Sim/Misc/GlobalSynced.h"
#include "System/myMath.h"
#include <cmath>
HUDDrawer* HUDDrawer::GetInstance()
{
@@ -75,14 +75,11 @@ void CInfoTextureCombiner::SwitchMode(const std::string& name)
// WTF? fully reloaded from disk on every switch?
if (name == "los") {
disabled = !CreateShader("shaders/GLSL/infoLOS.lua", true, float4(0.5f, 0.5f, 0.5f, 1.0f));
} else
if (name == "metal") {
} else if (name == "metal") {
disabled = !CreateShader("shaders/GLSL/infoMetal.lua", true, float4(0.f, 0.f, 0.f, 1.0f));
} else
if (name == "height") {
} else if (name == "height") {
disabled = !CreateShader("shaders/GLSL/infoHeight.lua");
} else
if (name == "path") {
} else if (name == "path") {
disabled = !CreateShader("shaders/GLSL/infoPath.lua");
} else {
//FIXME allow "info:myluainfotex"
Oops, something went wrong.

0 comments on commit 63851c0

Please sign in to comment.