diff --git a/lib/wal/sources/View/View.hpp b/lib/wal/sources/View/View.hpp index cbee789e..15b31e09 100644 --- a/lib/wal/sources/View/View.hpp +++ b/lib/wal/sources/View/View.hpp @@ -19,9 +19,9 @@ namespace WAL class ViewEntity { private: - std::tuple, std::reference_wrapper...> _value; + std::tuple, std::reference_wrapper...> &_value; public: - explicit ViewEntity(std::tuple, std::reference_wrapper...> value) + explicit ViewEntity(std::tuple, std::reference_wrapper...> &value) : _value(value) {} @@ -63,19 +63,22 @@ namespace WAL public: ViewEntity &operator*() { - this->_entity.emplace(*this->_it); - return this->_entity.value(); + if (!this->_entity) + this->_entity.emplace(*this->_it); + return *this->_entity; } ViewEntity *operator->() { - this->_entity.emplace(*this->_it); + if (!this->_entity) + this->_entity =(*this->_it); return &this->_entity; } ViewIterator &operator++() { this->_it++; + this->_entity = std::nullopt; return *this; } @@ -83,6 +86,7 @@ namespace WAL { ViewIterator copy = *this; this->_it++; + this->_entity = std::nullopt; return *this; } diff --git a/lib/wal/sources/Wal.hpp b/lib/wal/sources/Wal.hpp index f0c8dd50..85a7804e 100644 --- a/lib/wal/sources/Wal.hpp +++ b/lib/wal/sources/Wal.hpp @@ -84,7 +84,7 @@ namespace WAL //! @brief True if the engine should close after the end of the current tick. bool shouldClose = false; //! @brief The time between each fixed update. - static constexpr std::chrono::nanoseconds timestep = std::chrono::milliseconds(8); + static constexpr std::chrono::nanoseconds timestep = std::chrono::milliseconds(16); //! @brief Create a new system in place. //! @return The wal instance used to call this function is returned. This allow method chaining. diff --git a/sources/System/Collision/CollisionSystem.cpp b/sources/System/Collision/CollisionSystem.cpp index 4e992bda..6a3e36cd 100644 --- a/sources/System/Collision/CollisionSystem.cpp +++ b/sources/System/Collision/CollisionSystem.cpp @@ -32,13 +32,11 @@ namespace BBM position += movable->getVelocity(); Vector3f minA = Vector3f::min(position, position + col.bound); Vector3f maxA = Vector3f::max(position, position + col.bound); - for (auto other : this->getView()) { - if (other->getUid() == entity->getUid()) + for (auto &[other, posB, colB] : this->getView()) { + if (other.getUid() == entity->getUid()) continue; - auto colB = other.get(); - auto posB = other.get().position; - Vector3f minB = Vector3f::min(posB, posB + colB.bound); - Vector3f maxB = Vector3f::max(posB, posB + colB.bound); + Vector3f minB = Vector3f::min(posB.position, posB.position + colB.bound); + Vector3f maxB = Vector3f::max(posB.position, posB.position + colB.bound); if (collide(minA, maxA, minB, maxB)) { col.onCollide(entity, other); colB.onCollided(entity, other);