Optimizing view iterators

This commit is contained in:
Zoe Roux
2021-06-05 19:55:38 +02:00
parent f3ce14caca
commit 1b4e8d2151
3 changed files with 14 additions and 12 deletions
+9 -5
View File
@@ -19,9 +19,9 @@ namespace WAL
class ViewEntity
{
private:
std::tuple<std::reference_wrapper<Entity>, std::reference_wrapper<Components>...> _value;
std::tuple<std::reference_wrapper<Entity>, std::reference_wrapper<Components>...> &_value;
public:
explicit ViewEntity(std::tuple<std::reference_wrapper<Entity>, std::reference_wrapper<Components>...> value)
explicit ViewEntity(std::tuple<std::reference_wrapper<Entity>, std::reference_wrapper<Components>...> &value)
: _value(value)
{}
@@ -63,19 +63,22 @@ namespace WAL
public:
ViewEntity<Components...> &operator*()
{
this->_entity.emplace(*this->_it);
return this->_entity.value();
if (!this->_entity)
this->_entity.emplace(*this->_it);
return *this->_entity;
}
ViewEntity<Components...> *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;
}
+1 -1
View File
@@ -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.