From eab57e4022dc969ae51c70917b1f69eb863460f9 Mon Sep 17 00:00:00 2001 From: jadebenn Date: Tue, 17 Dec 2024 00:25:29 -0600 Subject: [PATCH] documentation and cleanup --- dECS/CMakeLists.txt | 12 +++++++++--- dECS/Core.cpp | 12 ++++++------ tests/dECSTests/TestECS.cpp | 4 ++-- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/dECS/CMakeLists.txt b/dECS/CMakeLists.txt index 7852ced2..b9c55052 100644 --- a/dECS/CMakeLists.txt +++ b/dECS/CMakeLists.txt @@ -1,7 +1,13 @@ +set(gcc_like_cxx "$") +set(msvc_cxx "$") + add_library(dECS STATIC -"Core.h" -"Core.cpp" + "Core.h" + "Core.cpp" ) target_include_directories(dECS PUBLIC .) target_link_libraries(dECS PRIVATE dCommon magic_enum::magic_enum) -target_compile_options(dECS PRIVATE "-Wall") +target_compile_options(dECS PRIVATE + "$<${gcc_like_cxx}:$>" + "$<${msvc_cxx}:$>" +) diff --git a/dECS/Core.cpp b/dECS/Core.cpp index 88a9083d..a187386f 100644 --- a/dECS/Core.cpp +++ b/dECS/Core.cpp @@ -23,10 +23,10 @@ namespace dECS { void* Entity::AddComponent(const eReplicaComponentType kind, const StorageConstructor storageConstructor) { if (auto w = m_World.lock()) { - // add to kind signature + // Add to kind signature w->map[m_Id].set(kind, true); - // get or add storage + // Get or add storage auto storageIt = w->data.find(kind); if (storageIt == w->data.cend()) { bool inserted = false; @@ -35,7 +35,7 @@ namespace dECS { } auto& storage = *storageIt->second; - // return reference if already mapped, otherwise add component + // Return reference if already mapped, otherwise add component auto compIt = storage.rowMap.find(m_Id); if (compIt == storage.rowMap.cend()) { const auto curSize = storage.rowMap.size(); @@ -50,13 +50,13 @@ namespace dECS { const void* Entity::GetComponent(const eReplicaComponentType kind) const { if (auto const w = m_World.lock()) { - const auto& compSig = w->map.at(m_Id); - if (!compSig.test(kind)) return nullptr; + // Check that the entity has this component + if (!w->map[m_Id].test(kind)) return nullptr; + // Get the location where it's stored const auto& storage = *w->data.at(kind); const auto it = storage.rowMap.find(m_Id); if (it == storage.rowMap.cend()) return nullptr; - const auto row = it->second; return storage.at(row); } diff --git a/tests/dECSTests/TestECS.cpp b/tests/dECSTests/TestECS.cpp index 0d1b5af4..0bceacbd 100644 --- a/tests/dECSTests/TestECS.cpp +++ b/tests/dECSTests/TestECS.cpp @@ -61,7 +61,7 @@ TEST(ECSTest, WorldScope) { ASSERT_NE(cPtr, nullptr); } - // Attempting to access this component now that the world has gone - // out of scope should return nullptr + // Attempting to access this component should return nullptr + // now that the world has gone out of scope ASSERT_EQ(e->GetComponent(), nullptr); }