Created
January 29, 2017 18:02
-
-
Save PoetaKodu/f6d163a759be4e710d273e24d1920ab4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CLevel::CLevel() | |
{ | |
} | |
//////////////////////////////////////////////////////////////// | |
CLevel::~CLevel() | |
{ | |
/* Przy niszczeniu sceny niszczymy także aktorów. */ | |
this->Cleanup(); | |
} | |
//////////////////////////////////////////////////////////////// | |
bool CLevel::Add(IActor *actor) | |
{ | |
/* Nie marnujmy czasu gdy podano wskaźnik zerowy. */ | |
if (actor) | |
{ | |
/* Sprawdzamy czy przypadkiem podany aktor | |
nie znajduje się już na scenie. | |
*/ | |
if (!this->Exists(actor)) | |
{ | |
m_actors.push_back(actor); | |
return true; | |
} | |
} | |
return false; | |
} | |
//////////////////////////////////////////////////////////////// | |
bool CLevel::Remove(IActor *actor) | |
{ | |
/* Nie marnujmy czasu gdy podano wskaźnik zerowy. */ | |
if (actor) | |
{ | |
/* Sprawdzamy czy aktor jest na scenie. | |
Jeśli tak to go usuwamy. | |
*/ | |
auto actorIt = std::find(m_actors.begin(), m_actors.end(), actor); | |
if (actorIt != m_actors.end()) | |
{ | |
m_actors.erase(actorIt); | |
return true; | |
} | |
} | |
return false; | |
} | |
//////////////////////////////////////////////////////////////// | |
bool CLevel::Exists(IActor *actor) const | |
{ | |
return std::find(m_actors.begin(), m_actors.end(), actor) != m_actors.end(); | |
} | |
//////////////////////////////////////////////////////////////// | |
std::size_t CLevel::Cleanup() | |
{ | |
/* Usuń wszystkich aktorów (z pamięci, nie tylko z kontenera)*/ | |
std::size_t actorsCount = m_actors.size(); | |
for (auto *actor : m_actors) | |
delete actor; | |
return actorsCount; | |
} | |
//////////////////////////////////////////////////////////////// | |
void CLevel::Update(const float &deltaTime) | |
{ | |
/* Wszyscy aktorzy zostają uaktualnieni. */ | |
for (auto *actor : m_actors) | |
actor->Update(deltaTime); | |
} | |
//////////////////////////////////////////////////////////////// | |
void CLevel::Draw() | |
{ | |
/* Wyświetlamy każdego aktora. */ | |
for (auto *actor : m_actors) | |
actor->Draw(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment