diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2023-03-14 07:33:47 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2023-03-14 07:33:47 +0100 |
commit | dc5e66b5a29fd7de8ddf59852ceefd982289b7c3 (patch) | |
tree | 18bf0a274f1595d6d2d6cfb32a3b3825d843e315 /src/world.cpp | |
parent | 29bdd5f2170b9d46a8b3b0973c4c0845d6a2b61e (diff) |
a
Diffstat (limited to 'src/world.cpp')
-rw-r--r-- | src/world.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/world.cpp b/src/world.cpp index 1fcee1d8..ea767422 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -1,5 +1,6 @@ #include "world.hpp" #include "chunk.hpp" +#include "entity.hpp" namespace floormat { @@ -7,6 +8,14 @@ world::world() : world{initial_capacity} { } +world::~world() noexcept +{ + _teardown = true; + _last_chunk = {}; + _chunks.clear(); + _entities.clear(); +} + world::world(std::size_t capacity) : _chunks{capacity, hasher} { _chunks.max_load_factor(max_load_factor); @@ -69,4 +78,24 @@ void world::collect(bool force) fm_debug("world: collected %zu/%zu chunks", len, len0); } +static constexpr std::uint64_t min_id = 1u << 16; +std::uint64_t world::entity_counter = min_id; + +void world::do_make_entity(const std::shared_ptr<entity>& e, global_coords pos) +{ + fm_debug_assert(e->id > min_id && &e->w == this); + fm_assert(Vector2ui(e->bbox_size).product() > 0); + fm_assert(e->type != entity_type::none); + e->coord = pos; + _entities[e->id] = e; + operator[](pos.chunk()).add_entity(e); +} + +void world::do_kill_entity(std::uint64_t id) +{ + fm_debug_assert(id > min_id); + auto cnt = _entities.erase(id); + fm_debug_assert(cnt > 0); +} + } // namespace floormat |