diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2023-03-15 14:52:54 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2023-03-15 15:09:09 +0100 |
commit | 2e0c0009806860e4e8ac24663afdc5d926d1213f (patch) | |
tree | 24a88dfa818e52179b0955a463da4b9cfa834b4d /src/world.hpp | |
parent | c6c3c887e99c57fb567252053190ce4a24f65455 (diff) |
src: add O(1) chunk access from entity
Diffstat (limited to 'src/world.hpp')
-rw-r--r-- | src/world.hpp | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/world.hpp b/src/world.hpp index 6781ee3c..5da700e3 100644 --- a/src/world.hpp +++ b/src/world.hpp @@ -37,7 +37,7 @@ private: explicit world(std::size_t capacity); - void do_make_entity(const std::shared_ptr<entity>& e, global_coords pos); + void do_make_entity(const std::shared_ptr<entity>& e, chunk& c, global_coords pos); void do_kill_entity(std::uint64_t id); friend struct entity; @@ -67,12 +67,12 @@ public: std::size_t collect_threshold() const noexcept { return _collect_every; } template<typename T, typename... Xs> - requires requires { T{std::uint64_t(), std::declval<world&>(), entity_type(), std::declval<Xs>()...}; } + requires requires(chunk& c) { T{std::uint64_t(), c, entity_type(), std::declval<Xs>()...}; } std::shared_ptr<T> make_entity(global_coords pos, Xs&&... xs) { static_assert(std::is_base_of_v<entity, T>); - auto ret = std::shared_ptr<T>(new T{++entity_counter, *this, entity_type_<T>::value, std::forward<Xs>(xs)...}); - do_make_entity(std::static_pointer_cast<entity>(ret), pos); + auto ret = std::shared_ptr<T>(new T{++entity_counter, operator[](pos.chunk()), entity_type_<T>::value, std::forward<Xs>(xs)...}); + do_make_entity(std::static_pointer_cast<entity>(ret), ret->c, pos); return ret; } |