mirror of
https://github.com/BlackMATov/ecs.hpp.git
synced 2025-12-13 02:26:27 +07:00
detail::type_family
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
ignore:
|
||||
- catch.hpp
|
||||
- catch_main.hpp
|
||||
- "catch.hpp"
|
||||
- "catch_main.hpp"
|
||||
- "*_tests.cpp"
|
||||
|
||||
44
ecs.hpp
44
ecs.hpp
@@ -7,11 +7,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <cassert>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
#include <mutex>
|
||||
#include <limits>
|
||||
#include <utility>
|
||||
#include <functional>
|
||||
#include <type_traits>
|
||||
#include <unordered_set>
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
@@ -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<family_id>::value,
|
||||
"ecs_hpp::family_id must be an unsigned integer");
|
||||
|
||||
static_assert(
|
||||
std::is_unsigned<entity_id>::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<Tag>::last_id_{0u};
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
@@ -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<position_c>::id() == 1u);
|
||||
REQUIRE(ecs::detail::type_family<position_c>::id() == 1u);
|
||||
|
||||
REQUIRE(ecs::detail::type_family<velocity_c>::id() == 2u);
|
||||
REQUIRE(ecs::detail::type_family<velocity_c>::id() == 2u);
|
||||
|
||||
REQUIRE(ecs::detail::type_family<position_c>::id() == 1u);
|
||||
REQUIRE(ecs::detail::type_family<velocity_c>::id() == 2u);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("world") {
|
||||
SECTION("entities") {
|
||||
{
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user