Skip to content

Commit

Permalink
documentation and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jadebenn committed Dec 17, 2024
1 parent 179f0cf commit eab57e4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
12 changes: 9 additions & 3 deletions dECS/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
set(gcc_like_cxx "$<COMPILE_LANG_AND_ID:CXX,ARMClang,AppleClang,Clang,GNU,LCC>")
set(msvc_cxx "$<COMPILE_LANG_AND_ID:CXX,MSVC>")

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}:$<BUILD_INTERFACE:-Wall;-Wextra>>"
"$<${msvc_cxx}:$<BUILD_INTERFACE:/W3>>"
)
12 changes: 6 additions & 6 deletions dECS/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand All @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/dECSTests/TestECS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ TEST(ECSTest, WorldScope) {
ASSERT_NE(cPtr, nullptr);

Check failure on line 61 in tests/dECSTests/TestECS.cpp

View workflow job for this annotation

GitHub Actions / Build & Test (windows-2022)

'cPtr': cannot be used before it is initialized [D:\a\DarkflameServer\DarkflameServer\build\msvc\tests\dECSTests\dECSTests.vcxproj]
}

// 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<TestComponent>(), nullptr);

Check failure on line 66 in tests/dECSTests/TestECS.cpp

View workflow job for this annotation

GitHub Actions / Build & Test (windows-2022)

syntax error: ')' [D:\a\DarkflameServer\DarkflameServer\build\msvc\tests\dECSTests\dECSTests.vcxproj]

Check failure on line 66 in tests/dECSTests/TestECS.cpp

View workflow job for this annotation

GitHub Actions / Build & Test (windows-2022)

illegal else without matching if [D:\a\DarkflameServer\DarkflameServer\build\msvc\tests\dECSTests\dECSTests.vcxproj]
}

0 comments on commit eab57e4

Please sign in to comment.