/* orxonox - the future of 3D-vertical-scrollers Copyright (C) 2004 orx This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. ### File Specific: main-programmer: Patrick Boenzli */ #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_OBJECT_MANAGER #include "object_manager.h" #include "garbage_collector.h" #include "list.h" using namespace std; /** \brief standard constructor */ ObjectManager::ObjectManager () { this->setClassID(CL_OBJECT_MANAGER, "ObjectManager"); this->setName("ObjectManager"); this->managedObjectList = new tList*[CL_NUMBER]; for(int i = 0; i < CL_NUMBER; ++i) { this->managedObjectList[i] = NULL; } this->garbageCollector = GarbageCollector::getInstance(); } /** \brief the singleton reference to this class */ ObjectManager* ObjectManager::singletonRef = NULL; /** \brief standard deconstructor */ ObjectManager::~ObjectManager () { ObjectManager::singletonRef = NULL; } /** \brief adds an element to the list of dead objects \param index: The type of object to add \param object: pointer to the object at hand */ void ObjectManager::addToDeadList(int index, BaseObject* object) { if( likely(this->managedObjectList[index] != NULL)) this->managedObjectList[index]->add(object); else PRINTF(0)(" Critical: unable to add object to the list nr. %i: no list initialized - ignoring\n", index); } /** \brief resurects an object \param index: the type of resource to load \param number: how many of them \todo if it is unable to get an object from the deadList, it should create it */ BaseObject* ObjectManager::getFromDeadList(int index, int number) { if( likely(this->managedObjectList[index] != NULL)) { BaseObject* obj = this->managedObjectList[index]->firstElement(); this->managedObjectList[index]->remove(obj); if( unlikely(obj == NULL)) { PRINTF(0)("Critical: there was no object anymore in the dead list! This could result in Segfaults\n"); } return obj; } else PRINTF(0)(" Critical: unable to get object from the list nr. %i: no elements initialized - ignoring\n", index); return NULL; } /** \brief outputs some simple debug information about the ObjectManage */ void ObjectManager::debug(void) const { PRINT(0)("\n==========================| ObjectManager::debug() |===\n"); PRINT(0)("= Number of registerable classes: %i\n", CL_NUMBER ); PRINT(0)("= Currently cached objects: \n"); for(int i = 0; i < CL_NUMBER; ++i) { if( this->managedObjectList[i] != NULL) PRINT(0)("= o Class Nr. %i has cached %i object(s)\n", i, this->managedObjectList[i]->getSize()); else PRINT(0)("= o Class Nr. %i has cached 0 object(s)\n", i); } PRINT(0)("=======================================================\n"); }