Permalink
Browse files

delintify some

  • Loading branch information...
rt
rt committed Dec 1, 2018
1 parent d289ee3 commit 49bfcb449b7ad884604bfe3337052ac6b01e687e
@@ -390,9 +390,11 @@ float GuiTraceRay(
if (u == exclude)
continue;
#if 0
// test this bit only in synced traces, rely on noSelect here
if (false && !u->HasCollidableStateBit(CSolidObject::CSTATE_BIT_QUADMAPRAYS)) // NOLINT{readability-simplify-boolean-expr}
if (!u->HasCollidableStateBit(CSolidObject::CSTATE_BIT_QUADMAPRAYS))
continue;
#endif
if (u->noSelect)
continue;
if (!unitVisible)
@@ -432,9 +434,11 @@ float GuiTraceRay(
for (const CFeature* f: quad.features) {
if (!gu->spectatingFullView && !f->IsInLosForAllyTeam(gu->myAllyTeam))
continue;
#if 0
// test this bit only in synced traces, rely on noSelect here
if (false && !f->HasCollidableStateBit(CSolidObject::CSTATE_BIT_QUADMAPRAYS)) // NOLINT{misc-static-assert}
if (!f->HasCollidableStateBit(CSolidObject::CSTATE_BIT_QUADMAPRAYS))
continue;
#endif
if (f->noSelect)
continue;
@@ -1322,14 +1322,24 @@ int LuaUnsyncedRead::GetWaterMode(lua_State* L)
int LuaUnsyncedRead::GetMapDrawMode(lua_State* L)
{
std::string mode = infoTextureHandler->GetMode();
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); // NOLINT{readability-misleading-indentation}
using P = std::pair<const char*, const char*>;
constexpr std::array<P, 5> modes = {
P( "", "normal" ),
P( "path", "pathTraversability"),
P( "heat", "pathHeat" ),
P( "flow", "pathFlow" ),
P("pathcost", "pathCost" ),
};
const auto& mode = infoTextureHandler->GetMode();
const auto iter = std::find_if(modes.begin(), modes.end(), [&mode](const P& p) { return (strcmp(p.first, mode.c_str()) == 0); });
if (iter != modes.end()) {
lua_pushstring(L, iter->second);
} else {
lua_pushstring(L, mode.c_str());
}
return 1;
}
@@ -582,32 +582,35 @@ template <typename T>
int PackType(lua_State* L)
{
std::vector<T> vals;
std::vector<char> buf;
if (lua_istable(L, 1)) {
vals.reserve(lua_objlen(L, 1));
for (int i = 1; lua_rawgeti(L, 1, i), lua_isnumber(L, -1); lua_pop(L, 1), i++) {
vals.push_back((T)lua_tonumber(L, -1));
vals.push_back(static_cast<T>(lua_tonumber(L, -1)));
}
} else {
const int args = lua_gettop(L);
for (int i = 1; i <= args; i++) {
if (!lua_isnumber(L, i))
vals.resize(lua_gettop(L));
for (size_t i = 0; i < vals.size(); i++) {
if (!lua_isnumber(L, i + 1))
break;
vals.push_back((T)lua_tonumber(L, i));
vals[i] = static_cast<T>(lua_tonumber(L, i + 1));
}
}
if (vals.empty())
return 0;
const int bufSize = sizeof(T) * vals.size();
char* buf = new char[bufSize];
for (int i = 0; i < (int)vals.size(); i++) {
memcpy(buf + (i * sizeof(T)), &vals[i], sizeof(T));
buf.resize(sizeof(T) * vals.size(), 0);

This comment has been minimized.

@gajop

gajop Dec 5, 2018

Member

this could probably be done while initializing std::vector<char> buf(sizeof(T) * vals.size(), 0);

for (size_t i = 0; i < vals.size(); i++) {
memcpy(buf.data() + (i * sizeof(T)), &vals[i], sizeof(T));
}
lua_pushlstring(L, buf, bufSize);
delete[] buf;
lua_pushlstring(L, buf.data(), buf.size());
return 1;
}
@@ -75,7 +75,7 @@ CSMFGroundDrawer::CSMFGroundDrawer(CSMFReadMap* rm)
drawForward = true;
drawDeferred = geomBuffer.Valid();
drawMapEdges = configHandler->GetBool("MapBorder");
drawWaterPlane = false && waterRendering->hasWaterPlane; // NOLINT{readability-simplify-boolean-expr}
drawWaterPlane = false; // waterRendering->hasWaterPlane;
smfRenderStates[RENDER_STATE_SSP]->Init(this);
smfRenderStates[RENDER_STATE_SSP]->Update(this, nullptr);
@@ -538,7 +538,9 @@ void DefaultPathDrawer::Draw(const CPathEstimator* pe) const {
}
#if (PE_EXTRA_DEBUG_OVERLAYS == 1)
if ((drawLowResPE || drawMedResPE) && false) { // NOLINT{readability-simplify-boolean-expr}
if (drawLowResPE || drawMedResPE) {
return; // TMI
const PathNodeBuffer& openBlockBuffer = pe->openBlockBuffer;
char blockCostsStr[32];
@@ -593,9 +593,11 @@ void CGlobalRendering::SwapBuffers(bool allowSwapBuffers, bool clearErrors)
if (clearErrors || glDebugErrors)
glClearErrors("GR", __func__, glDebugErrors);
#if 0
// not swapping while still incrementing drawFrame can cause weirdness
if (false && !allowSwapBuffers && !forceSwapBuffers) // NOLINT{readability-simplify-boolean-expr}
if (!allowSwapBuffers && !forceSwapBuffers)
return;
#endif
const spring_time pre = spring_now();
@@ -578,44 +578,28 @@ void LocalModel::UpdateBoundingVolume()
if (!piece->HasGeometryData())
continue;
#if 0
const unsigned int vcount = piece->GetVertexCount();
if (vcount >= 8) {
#endif
// transform only the corners of the piece's bounding-box
const float3 pMins = piece->mins; // NOLINT{readability-misleading-indentation}
const float3 pMaxs = piece->maxs;
const float3 verts[8] = {
// bottom
float3(pMins.x, pMins.y, pMins.z),
float3(pMaxs.x, pMins.y, pMins.z),
float3(pMaxs.x, pMins.y, pMaxs.z),
float3(pMins.x, pMins.y, pMaxs.z),
// top
float3(pMins.x, pMaxs.y, pMins.z),
float3(pMaxs.x, pMaxs.y, pMins.z),
float3(pMaxs.x, pMaxs.y, pMaxs.z),
float3(pMins.x, pMaxs.y, pMaxs.z),
};
for (const float3& v: verts) {
const float3 vertex = matrix * v;
bbMins = float3::min(bbMins, vertex);
bbMaxs = float3::max(bbMaxs, vertex);
}
#if 0
} else {
// note: not as efficient because of branching and virtual calls
for (unsigned int k = 0; k < vcount; k++) {
const float3 vertex = matrix * piece->GetVertexPos(k);
bbMins = float3::min(bbMins, vertex);
bbMaxs = float3::max(bbMaxs, vertex);
}
// transform only the corners of the piece's bounding-box
const float3 pMins = piece->mins;
const float3 pMaxs = piece->maxs;
const float3 verts[8] = {
// bottom
float3(pMins.x, pMins.y, pMins.z),
float3(pMaxs.x, pMins.y, pMins.z),
float3(pMaxs.x, pMins.y, pMaxs.z),
float3(pMins.x, pMins.y, pMaxs.z),
// top
float3(pMins.x, pMaxs.y, pMins.z),
float3(pMaxs.x, pMaxs.y, pMins.z),
float3(pMaxs.x, pMaxs.y, pMaxs.z),
float3(pMins.x, pMaxs.y, pMaxs.z),
};
for (const float3& v: verts) {
const float3 vertex = matrix * v;
bbMins = float3::min(bbMins, vertex);
bbMaxs = float3::max(bbMaxs, vertex);
}
#endif
}
// note: offset is relative to object->pos
@@ -771,7 +771,7 @@ void CUnitDrawer::DrawUnitIcon(CUnit* unit, GL::RenderDataBufferTC* buffer, bool
void CUnitDrawer::SetupAlphaDrawing(bool deferredPass, bool aboveWater)
{
unitDrawerStates[DRAWER_STATE_SEL] = const_cast<IUnitDrawerState*>(GetWantedDrawerState(true));
unitDrawerStates[DRAWER_STATE_SEL]->Enable(this, deferredPass && false, true); // NOLINT{readability-simplify-boolean-expr}
unitDrawerStates[DRAWER_STATE_SEL]->Enable(this, /*deferredPass*/ false, true);
glAttribStatePtr->PushBits(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_POLYGON_BIT);
glAttribStatePtr->PolygonMode(GL_FRONT_AND_BACK, GL_LINE * wireFrameMode + GL_FILL * (1 - wireFrameMode));
@@ -794,7 +794,7 @@ void CUnitDrawer::SetupAlphaDrawing(bool deferredPass, bool aboveWater)
void CUnitDrawer::ResetAlphaDrawing(bool deferredPass)
{
unitDrawerStates[DRAWER_STATE_SEL]->Disable(this, deferredPass && false); // NOLINT{readability-misleading-indentation}
unitDrawerStates[DRAWER_STATE_SEL]->Disable(this, /*deferredPass*/ false);
glAttribStatePtr->PopBits();
}
@@ -278,15 +278,15 @@ void CLogOutput::LogConfigInfo()
void CLogOutput::LogSystemInfo()
{
LOG("============== <User System> ==============");
LOG(" Spring %s", SpringVersion::GetFull().c_str());
LOG(" Build Environment: %s", SpringVersion::GetBuildEnvironment().c_str());
LOG(" Compiler Version: %s", SpringVersion::GetCompiler().c_str());
LOG(" Operating System: %s", Platform::GetOSDisplayStr().c_str());
LOG(" Hardware Config: %s", Platform::GetHardwareStr().c_str());
LOG(" Binary Word Size: %s", Platform::GetWordSizeStr().c_str());
LOG(" Process Clock: %s", spring_clock::GetName());
LOG(" Physical CPU Cores: %d", Threading::GetPhysicalCpuCores());
LOG(" Logical CPU Cores: %d", Threading::GetLogicalCpuCores());
LOG(" Spring Engine Version: %s", SpringVersion::GetFull().c_str());
LOG(" Build Environment: %s", SpringVersion::GetBuildEnvironment().c_str());
LOG(" Compiler Version: %s", SpringVersion::GetCompiler().c_str());
LOG(" Operating System: %s", Platform::GetOSDisplayStr().c_str());
LOG(" Hardware Config: %s", Platform::GetHardwareStr().c_str());
LOG(" Binary Word Size: %s", Platform::GetWordSizeStr().c_str());
LOG(" Process Clock: %s", spring_clock::GetName());
LOG(" Physical CPU Cores: %d", Threading::GetPhysicalCpuCores());
LOG(" Logical CPU Cores: %d", Threading::GetLogicalCpuCores());
LOG("============== </User System> ==============\n");
}
@@ -38,9 +38,7 @@ namespace Threading {
THREAD_IDX_LAST = 5,
};
static bool cachedThreadIDs[THREAD_IDX_LAST] = {false, false, false, false, false};
static NativeThreadId nativeThreadIDs[THREAD_IDX_LAST] = {};
static Error threadError;
thread_local std::shared_ptr<Threading::ThreadControls> threadCtls;
@@ -315,10 +313,7 @@ namespace Threading {
// those two threads are joined and respawned when reloading, KISS here
// (while other threads never call Set*Thread more than once making the
// is-cached flags redundant anyway)
if (true || !cachedThreadIDs[threadIndex]) // NOLINT{readability-simplify-boolean-expr}
nativeThreadIDs[threadIndex] = Threading::GetCurrentThreadId();
cachedThreadIDs[threadIndex] = true;
nativeThreadIDs[threadIndex] = Threading::GetCurrentThreadId();
if (!setControls)
return;
@@ -400,7 +400,7 @@ namespace Watchdog
// start the watchdog thread
hangDetectorThread = std::move(spring::thread(&HangDetectorLoop));
LOG("[WatchDog%s] Installed (HangTimeout: %isec)", __func__, hangTimeoutSecs);
LOG("[WatchDog::%s] installed (hang-timeout: %is)", __func__, hangTimeoutSecs);
}
Oops, something went wrong.

1 comment on commit 49bfcb4

@gajop

This comment has been minimized.

Member

gajop commented on 49bfcb4 Dec 5, 2018

Thanks for the follow up cleanups and bug fixes!
Also, west-const best-const ^^

Please sign in to comment.