From ab4d6a82b8ec00246ffce3462a9386be4025c067 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Wed, 24 Feb 2010 20:56:44 +0000 Subject: [PATCH] changed m_objects to use an IDSet git-svn-id: svn://anubis/anaglym/trunk@265 99a6e188-d820-4881-8870-2d33a10e2619 --- Engine.cc | 20 ++++++++------------ Engine.h | 3 +-- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/Engine.cc b/Engine.cc index 34e3a91..74abb67 100644 --- a/Engine.cc +++ b/Engine.cc @@ -88,7 +88,6 @@ static void checkGLErrorLine(const char * function, int line) Engine::Engine(const string & path, AV & av) : m_av(av) { - m_next_object_index = 1; m_eye[0] = 0; m_eye[1] = -1; m_eye[2] = 0; @@ -279,20 +278,18 @@ bool Engine::fileExists(const string & path) int Engine::addObject(WFObj * obj, bool is_static, bool is_reference, float scale) { - int id = m_next_object_index++; Object * o = new Object(is_static, is_reference, m_world, obj, scale); + int id = m_objects.add(o); o->setID(id); - m_objects[id] = o; return id; } int Engine::addObject(bool is_static, bool is_reference, OdeWorld::GeomType geom_type, refptr< vector > args) { - int id = m_next_object_index++; Object * o = new Object(is_static, is_reference, m_world, geom_type, args); + int id = m_objects.add(o); o->setID(id); - m_objects[id] = o; return id; } @@ -406,16 +403,15 @@ void Engine::removeObject(int id) int Engine::cloneObject(const Engine::Object * obj) { - int id = m_next_object_index++; Object * o = new Object(*obj); + int id = m_objects.add(o); o->setID(id); - m_objects[id] = o; return id; } Engine::Object * Engine::getObject(int id) { - return m_objects.find(id) != m_objects.end() ? m_objects[id] : NULL; + return m_objects.contains(id) ? m_objects[id] : NULL; } void Engine::startFrame() @@ -654,8 +650,7 @@ void Engine::clearWorld() { while (!m_objects.empty()) { - std::map::iterator it = m_objects.begin(); - removeObject(it->first); + removeObject(m_objects.begin()->first); } } @@ -1141,8 +1136,9 @@ void Engine::doPhysics() void Engine::drawObjects() { - std::map::iterator it; - for (it = m_objects.begin(); it != m_objects.end(); it++) + for (std::map::const_iterator it = m_objects.begin(); + it != m_objects.end(); + it++) { it->second->draw(); } diff --git a/Engine.h b/Engine.h index 6898730..3c3253f 100644 --- a/Engine.h +++ b/Engine.h @@ -264,10 +264,9 @@ class Engine std::string m_program_directory; std::string m_engine_path; OdeWorld m_world; - std::map m_objects; + IDSet m_objects; IDSet< refptr > m_sounds; IDSet m_joints; - int m_next_object_index; GLdouble m_eye[3]; GLdouble m_center[3]; GLdouble m_up[3];