diff --git a/.codecov.yml b/.codecov.yml index c1c3711..69ebbfa 100644 --- a/.codecov.yml +++ b/.codecov.yml @@ -1,3 +1,4 @@ ignore: - - catch.hpp - - catch_main.hpp + - "catch.hpp" + - "catch_main.hpp" + - "*_tests.cpp" diff --git a/ecs.hpp b/ecs.hpp index 60e5e16..7f31414 100644 --- a/ecs.hpp +++ b/ecs.hpp @@ -7,11 +7,14 @@ #pragma once #include +#include #include #include #include +#include #include +#include #include // ----------------------------------------------------------------------------- @@ -25,7 +28,46 @@ namespace ecs_hpp class world; class entity; - using entity_id = std::uint64_t; + using family_id = std::uint16_t; + using entity_id = std::uint32_t; + + static_assert( + std::is_unsigned::value, + "ecs_hpp::family_id must be an unsigned integer"); + + static_assert( + std::is_unsigned::value, + "ecs_hpp::entity_id must be an unsigned integer"); +} + +// ----------------------------------------------------------------------------- +// +// detail +// +// ----------------------------------------------------------------------------- + +namespace ecs_hpp +{ + namespace detail + { + template < typename Tag = void > + struct type_family_base { + static family_id last_id_; + }; + + template < typename T > + class type_family : private type_family_base<> { + public: + static family_id id() noexcept { + static family_id self_id = ++last_id_; + assert(self_id > 0u && "ecs_hpp::family_id overflow"); + return self_id; + } + }; + + template < typename Tag > + family_id type_family_base::last_id_{0u}; + } } // ----------------------------------------------------------------------------- diff --git a/ecs_tests.cpp b/ecs_tests.cpp index 57bb26a..c1b2af1 100644 --- a/ecs_tests.cpp +++ b/ecs_tests.cpp @@ -12,23 +12,36 @@ namespace ecs = ecs_hpp; namespace { - struct position { + struct position_c { int x{0}; int y{0}; - position() = default; - position(int nx, int ny) : x(nx), y(ny) {} + position_c() = default; + position_c(int nx, int ny) : x(nx), y(ny) {} }; - struct velocity { + struct velocity_c { int dx{0}; int dy{0}; - velocity() = default; - velocity(int ndx, int ndy) : dx(ndx), dy(ndy) {} + velocity_c() = default; + velocity_c(int ndx, int ndy) : dx(ndx), dy(ndy) {} }; } +TEST_CASE("detail") { + SECTION("get_type_id") { + REQUIRE(ecs::detail::type_family::id() == 1u); + REQUIRE(ecs::detail::type_family::id() == 1u); + + REQUIRE(ecs::detail::type_family::id() == 2u); + REQUIRE(ecs::detail::type_family::id() == 2u); + + REQUIRE(ecs::detail::type_family::id() == 1u); + REQUIRE(ecs::detail::type_family::id() == 2u); + } +} + TEST_CASE("world") { SECTION("entities") { { diff --git a/scripts/upload_coverage.sh b/scripts/upload_coverage.sh index d13a427..d7f223a 100755 --- a/scripts/upload_coverage.sh +++ b/scripts/upload_coverage.sh @@ -11,7 +11,7 @@ lcov -d . -z ctest --verbose lcov -d . -c -o "coverage.info" -lcov -r "coverage.info" "*/usr/*" "*/catch.hpp" "*/catch_main.cpp" -o "coverage.info" +lcov -r "coverage.info" "*/usr/*" "*/catch.hpp" "*/catch_main.cpp" "*_tests.cpp" -o "coverage.info" lcov -l "coverage.info" bash <(curl -s https://codecov.io/bash) || echo "Codecov did not collect coverage reports"