Skip to content

Commit

Permalink
Hush various clang-tidy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
jonesmz committed Apr 4, 2024
1 parent a747cab commit f59e5bf
Show file tree
Hide file tree
Showing 23 changed files with 100 additions and 71 deletions.
2 changes: 2 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Checks: 'clang-diagnostic-*,
,-readability-else-after-return,
,-readability-magic-numbers,
,-readability-identifier-length,
,-readability-function-cognitive-complexity,
,-readability-qualified-auto,
,-clang-analyzer-cplusplus.InnerPointer,
,-cplusplus.InnerPointer,
,-clang-diagnostic-ignored-optimization-argument,
Expand Down
4 changes: 2 additions & 2 deletions src/adera/drawing_gl/visualizer_shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void adera::shader::draw_ent_visualizer(
if (rData.m_wireframeOnly)
{
rShader.setColor(0x00000000_rgbaf);
Magnum::GL::Renderer::setDepthMask(false);
Magnum::GL::Renderer::setDepthMask(GL_FALSE);
}

MeshGlId const meshId = (*rData.m_pMeshId)[ent].m_glId;
Expand All @@ -72,6 +72,6 @@ void adera::shader::draw_ent_visualizer(

if (rData.m_wireframeOnly)
{
Magnum::GL::Renderer::setDepthMask(true);
Magnum::GL::Renderer::setDepthMask(GL_TRUE);
}
}
4 changes: 3 additions & 1 deletion src/osp/activescene/active_ent.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@

#include "../core/strong_id.h"

#include <cstdint> // for std::uint32_t

namespace osp::active
{

using ActiveEnt = StrongId<uint32_t, struct DummyForActiveEnt>;
using ActiveEnt = StrongId<std::uint32_t, struct DummyForActiveEnt>;

} // namespace osp::active
4 changes: 2 additions & 2 deletions src/osp/activescene/basic_fn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ SubtreeBuilder SubtreeBuilder::add_child(ActiveEnt ent, uint32_t descendantCount

m_first = childLast;

return SubtreeBuilder(m_rScnGraph, ent, childFirst, childLast);
return {m_rScnGraph, ent, childFirst, childLast};
}

SubtreeBuilder SysSceneGraph::add_descendants(ACtxSceneGraph& rScnGraph, uint32_t descendantCount, ActiveEnt root)
Expand Down Expand Up @@ -169,7 +169,7 @@ void SysSceneGraph::do_delete(ACtxSceneGraph& rScnGraph)
TreePos_t const keepLast = (notLast) ? (*itDelNext) : (treeLast);
assert(keepFirst <= keepLast);

std::size_t const shift = keepFirst - done;
std::ptrdiff_t const shift = keepFirst - done;

// Update descendant count of ancestors
ActiveEnt parent = rScnGraph.m_treeToEnt[*itDel];
Expand Down
2 changes: 1 addition & 1 deletion src/osp/activescene/prefab_fn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ void SysPrefabInit::init_info(
PrefabInstanceInfo &rInfo = rPrefabs.instanceInfo[ent];
rInfo.importer = rPfBasic.m_importerRes;
rInfo.prefab = rPfBasic.m_prefabId;
rInfo.obj = i;
rInfo.obj = static_cast<ObjId>(i);

if (parents[i] == -1)
{
Expand Down
22 changes: 16 additions & 6 deletions src/osp/core/global_id.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,36 @@
*/
#pragma once

#include <cstddef>
#include <longeron/utility/enum_traits.hpp> // for lgrn::underlying_int_type_t

#include <type_traits> // for std::is_integral_v

namespace osp
{

template <typename ID_T, typename DUMMY_T = void>
struct GlobalIdReg
{
[[nodiscard]] static inline ID_T create() noexcept
using underlying_t = lgrn::underlying_int_type_t<ID_T>;
static_assert(std::is_integral_v<underlying_t>);

[[nodiscard]] static constexpr ID_T create() noexcept
{
return ID_T{sm_count++};
}

[[nodiscard]] static constexpr std::size_t size() noexcept
{
return ID_T(sm_count++);
return std::size_t{sm_count};
}

[[nodiscard]] static inline std::size_t size() noexcept
[[nodiscard]] static constexpr underlying_t largest() noexcept
{
return sm_count;
return sm_count;
}

private:
static inline std::size_t sm_count{0};
static inline constinit underlying_t sm_count{0};
};

} // namespace osp
16 changes: 10 additions & 6 deletions src/osp/core/strong_id.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@
*/
#pragma once

#include <cstdint>
#include <typeindex> // light-ish header that happens to include std::hash
#include <longeron/id_management/null.hpp> // for lgrn::id_null
#include <longeron/utility/enum_traits.hpp> // for lgrn::underlying_int_type

#include <longeron/id_management/null.hpp>
#include <concepts> // for std::integral
#include <cstddef> // for std::size_t
#include <typeindex> // IWYU pragma: keep, light-ish header that happens to include std::hash

namespace osp
{
Expand Down Expand Up @@ -58,9 +60,10 @@ struct StrongId
: value{value}
{ };

constexpr explicit operator std::size_t() const noexcept
template<std::integral T>
constexpr explicit operator T() const noexcept
{
return value;
return static_cast<T>(value);
}

constexpr explicit operator INT_T() const noexcept
Expand All @@ -77,7 +80,8 @@ struct StrongId

// std::hash support for unordered containers
template <typename INT_T, typename DUMMY_T>
struct std::hash<osp::StrongId<INT_T, DUMMY_T>> {
struct std::hash<osp::StrongId<INT_T, DUMMY_T>>
{
constexpr auto operator() (osp::StrongId<INT_T, DUMMY_T> const& key) const
{
return key.value;
Expand Down
6 changes: 4 additions & 2 deletions src/osp/drawing/draw_ent.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@

#include "../core/strong_id.h"

#include <cstdint> // for std::uint32_t

namespace osp::draw
{

using DrawEnt = StrongId<uint32_t, struct DummyForDrawEnt>;
using DrawEnt = StrongId<std::uint32_t, struct DummyForDrawEnt>;

using MaterialId = StrongId<uint32_t, struct DummyForMaterialId>;
using MaterialId = StrongId<std::uint32_t, struct DummyForMaterialId>;

} // namespace osp::draw
4 changes: 2 additions & 2 deletions src/osp/drawing/prefab_draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ void SysPrefabDraw::init_mesh_and_material(
mat.types() & Magnum::Trade::MaterialType::PbrMetallicRoughness)
{
auto const& matPbr = mat.as<Magnum::Trade::PbrMetallicRoughnessMaterialData>();
if (int const baseColor = matPbr.baseColorTexture();
if (auto const baseColor = matPbr.baseColorTexture();
baseColor != -1)
{
osp::ResId const texRes = rImportData.m_textures[baseColor];
Expand Down Expand Up @@ -238,7 +238,7 @@ void SysPrefabDraw::resync_mesh_and_material(
mat.types() & Magnum::Trade::MaterialType::PbrMetallicRoughness)
{
auto const& matPbr = mat.as<Magnum::Trade::PbrMetallicRoughnessMaterialData>();
if (int const baseColor = matPbr.baseColorTexture();
if (auto const baseColor = matPbr.baseColorTexture();
baseColor != -1)
{
osp::ResId const texRes = rImportData.m_textures[baseColor];
Expand Down
6 changes: 3 additions & 3 deletions src/osp/drawing_gl/rendergl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ void SysRenderGL::display_texture(
Renderer::disable(Renderer::Feature::DepthTest);
Renderer::disable(Renderer::Feature::FaceCulling);
Renderer::disable(Renderer::Feature::Blending);
Renderer::setDepthMask(true);
Renderer::setDepthMask(GL_TRUE);

rRenderGl.m_fullscreenTriShader.display_texure(
rRenderGl.m_meshGl.get(rRenderGl.m_fullscreenTri),
Expand Down Expand Up @@ -352,7 +352,7 @@ void SysRenderGL::render_opaque(
Renderer::enable(Renderer::Feature::DepthTest);
Renderer::enable(Renderer::Feature::FaceCulling);
Renderer::disable(Renderer::Feature::Blending);
Renderer::setDepthMask(true);
Renderer::setDepthMask(GL_TRUE);

draw_group(group, visible, viewProj);
}
Expand All @@ -373,7 +373,7 @@ void SysRenderGL::render_transparent(

// temporary: disabled depth writing makes the plumes look nice, but
// can mess up other transparent objects once added
//Renderer::setDepthMask(false);
//Renderer::setDepthMask(GL_FALSE);

draw_group(group, visible, viewProj);
}
Expand Down
6 changes: 6 additions & 0 deletions src/osp/tasks/execute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,7 @@ static void pipeline_advance_reqs(Tasks const& tasks, TaskGraph const& graph, Ex
{
ExecPipeline &rReqTaskExecPl = rExec.plData[stgreqtask.reqPipeline];

// NOLINTBEGIN(bugprone-branch-clone)
bool const reqTaskDone = [&tasks, &rReqTaskExecPl, &stgreqtask, &rExec] () noexcept -> bool
{
if ( ! rReqTaskExecPl.running )
Expand Down Expand Up @@ -525,6 +526,7 @@ static void pipeline_advance_reqs(Tasks const& tasks, TaskGraph const& graph, Ex
return true; // On the right stage and task not running. This means it's done
}
}();
// NOLINTEND(bugprone-branch-clone)

if (reqTaskDone)
{
Expand Down Expand Up @@ -828,6 +830,7 @@ static bool is_pipeline_in_loop(Tasks const& tasks, TaskGraph const& graph, Exec

if (exec.plData[args.insideLoop].canceled)
{
// NOLINTBEGIN(readability-simplify-boolean-expr)
if (exec.plData[graph.pltreeToPipeline[insideLoopScopePos]].canceled)
{
return false; // insideLoop is canceled and will not loop again
Expand All @@ -837,6 +840,7 @@ static bool is_pipeline_in_loop(Tasks const& tasks, TaskGraph const& graph, Exec
return true; // insideLoop itself is canceled, but is parented to a non-canceled
// loop scope. It will loop more times.
}
// NOLINTEND(readability-simplify-boolean-expr)
}
else // insideLoop is canceled
{
Expand All @@ -856,6 +860,7 @@ static bool is_pipeline_in_loop(Tasks const& tasks, TaskGraph const& graph, Exec
{
if (exec.plData[args.insideLoop].canceled)
{
// NOLINTBEGIN(readability-simplify-boolean-expr)
if (exec.plData[graph.pltreeToPipeline[insideLoopScopePos]].canceled)
{
return false; // insideLoop is canceled and will not loop again
Expand All @@ -865,6 +870,7 @@ static bool is_pipeline_in_loop(Tasks const& tasks, TaskGraph const& graph, Exec
return true; // insideLoop is in a nested loop and is canceled, but is parented
// to a non-canceled loop scope. It will loop more times.
}
// NOLINTEND(readability-simplify-boolean-expr)
}
else
{
Expand Down
2 changes: 2 additions & 0 deletions src/osp/tasks/tasks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ TaskGraph make_exec_graph(Tasks const& tasks, ArrayView<TaskEdges const* const>
}
}

// NOLINTBEGIN(readability-use-anyofallof)
[[maybe_unused]] auto const all_counts_zero = [&] ()
{
if ( totalStageReqTasks != 0
Expand Down Expand Up @@ -331,6 +332,7 @@ TaskGraph make_exec_graph(Tasks const& tasks, ArrayView<TaskEdges const* const>

return true;
};
// NOLINTEND(readability-use-anyofallof)

LGRN_ASSERTM(all_counts_zero(), "Counts repurposed as items remaining, and must all be zero by the end here");

Expand Down
19 changes: 9 additions & 10 deletions src/osp/tasks/top_execute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@

#include <algorithm>
#include <iomanip>
#include <sstream>
#include <vector>

namespace osp
Expand All @@ -50,7 +49,7 @@ void top_run_blocking(Tasks const& tasks, TaskGraph const& graph, TopTaskDataVec

if (runTasksLeft != 0)
{
TaskId const task = rExec.tasksQueuedRun.at(0);
TaskId const task = rExec.tasksQueuedRun[0];
TopTask &rTopTask = rTaskData[task];

topDataRefs.clear();
Expand Down Expand Up @@ -99,17 +98,17 @@ std::ostream& operator<<(std::ostream& rStream, TopExecWriteState const& write)
{
auto const& [tasks, taskData, graph, exec] = write;

static constexpr int nameMinColumns = 50;
static constexpr int maxDepth = 4;
static constexpr std::size_t nameMinColumns = 50;
static constexpr std::size_t maxDepth = 4;

rStream << "Pipeline/Tree | Status | Stages | Pipeline Names\n"
<< "_________________________________________________________________________________________\n";

auto const write_pipeline = [&rStream, &tasks=tasks, &exec=exec, &graph=graph] (PipelineId const pipeline, int const depth)
auto const write_pipeline = [&rStream, &tasks=tasks, &exec=exec, &graph=graph] (PipelineId const pipeline, std::size_t const depth)
{
ExecPipeline const &plExec = exec.plData[pipeline];

for (int i = 0; i < depth; ++i)
for (std::size_t i = 0; i < depth; ++i)
{
rStream << "- ";
}
Expand Down Expand Up @@ -139,19 +138,19 @@ std::ostream& operator<<(std::ostream& rStream, TopExecWriteState const& write)

rStream << " | ";

int const stageCount = fanout_size(graph.pipelineToFirstAnystg, pipeline);
uint32_t const stageCount = fanout_size(graph.pipelineToFirstAnystg, pipeline);

PipelineInfo const& info = tasks.m_pipelineInfo[pipeline];

int charsUsed = 7; // "PL###" + ": "
std::size_t charsUsed = 7; // "PL###" + ": "

if (info.stageType != lgrn::id_null<PipelineInfo::stage_type_t>())
{
auto const stageNames = ArrayView<std::string_view const>{PipelineInfo::sm_stageNames[info.stageType]};

for (int stage = 0; stage < std::min<int>(stageNames.size(), stageCount); ++stage)
for (uint32_t stage = 0; stage < std::min(uint32_t(stageNames.size()), stageCount); ++stage)
{
bool const sel = int(plExec.stage) == stage;
bool const sel = uint32_t(plExec.stage) == stage;
rStream << (sel ? '[' : ' ')
<< stageNames[stage]
<< (sel ? ']' : ' ');
Expand Down
12 changes: 6 additions & 6 deletions src/planet-a/SubdivTriangleMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ ChunkedTriangleMeshInfo planeta::make_subdivtrimesh_general(
using std::ceil;
using std::pow;

float const C = chunkMax;
float const L = subdivLevels;
float const C = static_cast<float>(chunkMax);
float const L = static_cast<float>(subdivLevels);

// Calculate a fair number of shared vertices, based on a triangular
// tiling pattern.
Expand Down Expand Up @@ -72,7 +72,7 @@ ChunkId ChunkedTriangleMeshInfo::chunk_create(

// Create a new chunk ID
ChunkId const chunkId = m_chunkIds.create();
Chunk &rChunk = m_chunkData[size_t(chunkId)];
Chunk &rChunk = m_chunkData[std::size_t(chunkId)];

rChunk.m_skeletonTri = rSkel.tri_store(skTri);

Expand All @@ -84,16 +84,16 @@ ChunkId ChunkedTriangleMeshInfo::chunk_create(

for (int i = 0; i < 3; i ++)
{
size_t const cornerOffset = m_chunkWidth * i;
size_t const edgeOffset = m_chunkWidth * i + 1;
std::size_t const cornerOffset = static_cast<std::size_t>(m_chunkWidth) * i;
std::size_t const edgeOffset = static_cast<std::size_t>(m_chunkWidth) * i + 1;

ArrayView_t<SkVrtxId> const edge = edges[i];
{
SharedVrtxId const sharedId = shared_get_or_create(
tri.m_vertices[i], rSkel);
sharedSpace[cornerOffset] = shared_store(sharedId);
}
for (unsigned int j = 0; j < m_chunkWidth - 1; j ++)
for (std::size_t j = 0; j < m_chunkWidth - 1; j ++)
{
SharedVrtxId const sharedId = shared_get_or_create(edge[j], rSkel);
sharedSpace[edgeOffset + j] = shared_store(sharedId);
Expand Down
Loading

0 comments on commit f59e5bf

Please sign in to comment.