ecs.cpp

1
2
3
#include <planet/ecs/storage.hpp>

#include <felspar/exceptions.hpp>

planet::ecs::detail

 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
namespace {
    struct eid_and_type_info : public felspar::stdexcept::logic_error {
        eid_and_type_info(
                std::string_view const m,
                planet::ecs::entity_id const eid,
                std::type_info const &ti,
                felspar::source_location const &loc)
        : felspar::stdexcept::logic_error{
                  std::string{m} + "\nEntity id " + std::to_string(eid.id())
                          + " type index: " + std::string{ti.name()},
                  loc} {}
    };
}


void planet::ecs::detail::throw_no_entities_instance(
        felspar::source_location const &loc) {
    throw felspar::stdexcept::logic_error{
            "The entities storage must be part of an entities structure before "
            "it can be used",
            loc};
}


void planet::ecs::detail::throw_component_type_not_valid(
        entity_id const &eid,
        std::type_info const &ti,
        felspar::source_location const &loc) {
    throw eid_and_type_info{
            "The provided type doesn't match a component type", eid, ti, loc};
}


void planet::ecs::detail::throw_component_not_present(
        entity_id const &eid,
        std::type_info const &ti,
        felspar::source_location const &loc) {
    throw eid_and_type_info{
            "This entity doesn't have that component at this time", eid, ti,
            loc};
}


void planet::ecs::detail::throw_entity_not_valid(
        entity_id const &eid, felspar::source_location const &loc) {
    throw felspar::stdexcept::logic_error{
            "This entity is not valid\nEntity ID: " + std::to_string(eid.id()),
            loc};
}


namespace {
    planet::telemetry::counter create_count{"planet_ecs_entities_created"};
    planet::telemetry::counter recycle_count{"planet_ecs_entities_recycled"};
    planet::telemetry::counter destroy_count{"planet_ecs_entities_destroyed"};
}
void planet::ecs::detail::count_create_entity() noexcept { ++create_count; }
void planet::ecs::detail::count_recycled_entity() noexcept { ++recycle_count; }
void planet::ecs::detail::count_destroy_entity() noexcept { ++destroy_count; }