From 3536f1c7cc52792a7d833b4f823aa515dc00d933 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Mon, 30 Dec 2013 10:51:29 +0100 Subject: Added CObjectManager::Flush() Possible fix for #275 --- src/object/objman.cpp | 16 ++++++++++++---- src/object/objman.h | 4 +++- src/object/robotmain.cpp | 6 ++++++ 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/object/objman.cpp b/src/object/objman.cpp index 0471ebf..131d007 100644 --- a/src/object/objman.cpp +++ b/src/object/objman.cpp @@ -30,7 +30,7 @@ CObjectManager::CObjectManager() { m_table[i] = nullptr; } - usedCount = 0; + m_usedCount = 0; } CObjectManager::~CObjectManager() @@ -39,16 +39,16 @@ CObjectManager::~CObjectManager() bool CObjectManager::AddInstance(CObject* instance) { - if (usedCount >= MAX_OBJECTS) return false; + if (m_usedCount >= MAX_OBJECTS) return false; m_table[instance->GetID()] = instance; - usedCount++; + m_usedCount++; return true; } bool CObjectManager::DeleteInstance(CObject* instance) { - for (int i = 0; i < usedCount; i++) + for (int i = 0; i < m_usedCount; i++) { if (m_table[i] == instance) m_table[i] = nullptr; @@ -386,3 +386,11 @@ CObject* CObjectManager::CreateObject(Math::Vector pos, float angle, ObjectType return object; } +void CObjectManager::Flush() +{ + for (int i = 0; i < MAX_OBJECTS; i++) + { + m_table[i] = nullptr; + } + m_usedCount = 0; +} diff --git a/src/object/objman.h b/src/object/objman.h index 1d67468..390587b 100644 --- a/src/object/objman.h +++ b/src/object/objman.h @@ -45,9 +45,11 @@ public: CObject* SearchInstance(int id); //! Creates an object CObject* CreateObject(Math::Vector pos, float angle, ObjectType type, float power = -1.f, float zoom = 1.f, float height = 0.f, bool trainer = false, bool toy = false, int option = 0); + //! Removes all objects + void Flush(); protected: CObject* m_table[MAX_OBJECTS]; - int usedCount; + int m_usedCount; }; diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index 0852df0..308b172 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -1148,6 +1148,8 @@ void CRobotMain::ChangePhase(Phase phase) iMan->Flush(CLASS_PHYSICS); iMan->Flush(CLASS_BRAIN); iMan->Flush(CLASS_PYRO); + + CObjectManager::GetInstancePointer()->Flush(); Math::Point dim, pos; @@ -3869,6 +3871,8 @@ void CRobotMain::ScenePerso() iMan->Flush(CLASS_PHYSICS); iMan->Flush(CLASS_BRAIN); iMan->Flush(CLASS_PYRO); + + CObjectManager::GetInstancePointer()->Flush(); m_dialog->SetSceneName("perso"); m_dialog->SetSceneRank(0); @@ -6546,6 +6550,8 @@ void CRobotMain::ResetCreate() iMan->Flush(CLASS_PHYSICS); iMan->Flush(CLASS_BRAIN); iMan->Flush(CLASS_PYRO); + + CObjectManager::GetInstancePointer()->Flush(); m_camera->SetType(Gfx::CAM_TYPE_DIALOG); -- cgit v1.2.3-1-g7c22