Advertisement
Guest User

Untitled

a guest
Jun 24th, 2018
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.25 KB | None | 0 0
  1. entity iterator cpp
  2. #pragma once
  3. #include "EntityIterator.h"
  4.  
  5. /*
  6.  
  7. EntityIterator::EntityIterator(Scene* scene, size_t index, bool bIsEnd, bool bIncludePendingDestroy)
  8.     : m_bIsEnd(bIsEnd), m_index(index), m_scene(scene), m_bIncludePendingDestroy(bIncludePendingDestroy)
  9. {
  10.     if (index >= m_scene->GetEntityCount())
  11.         this->m_bIsEnd = true;
  12. }
  13.  
  14. bool EntityIterator::IsEnd() const
  15. {
  16.     return m_bIsEnd || m_index >= m_scene->GetEntityCount();
  17. }
  18.  
  19. Entity* EntityIterator::Get() const
  20. {
  21.     if (IsEnd())
  22.         return nullptr;
  23.  
  24.     return m_scene->GetEntityByIndex(m_index);
  25. }
  26.  
  27. EntityIterator& EntityIterator::operator++()
  28. {
  29.     ++m_index;
  30.     while (m_index < m_scene->GetEntityCount() && (Get() == nullptr || (Get()->IsPendingDestroy() && !m_bIncludePendingDestroy)))
  31.     {
  32.         ++m_index;
  33.     }
  34.  
  35.     if (m_index >= m_scene->GetEntityCount())
  36.         m_bIsEnd = true;
  37.  
  38.     return *this;
  39. }
  40.  
  41. bool operator==(const EntityIterator& other) const
  42.     {
  43.         if (m_scene != other.m_scene)
  44.             return false;
  45.  
  46.         if (IsEnd())
  47.             return other.IsEnd();
  48.  
  49.         return m_index == other.m_index;
  50.     }
  51.  
  52.     bool operator!=(const EntityIterator& other) const
  53.     {
  54.         if (m_scene != other.m_scene)
  55.             return true;
  56.  
  57.         if (IsEnd())
  58.             return !other.IsEnd();
  59.  
  60.         return m_index != other.m_index;
  61.     }
  62.     */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement