[4592] | 1 | /* |
---|
[4245] | 2 | orxonox - the future of 3D-vertical-scrollers |
---|
| 3 | |
---|
| 4 | Copyright (C) 2004 orx |
---|
| 5 | |
---|
| 6 | This program is free software; you can redistribute it and/or modify |
---|
| 7 | it under the terms of the GNU General Public License as published by |
---|
| 8 | the Free Software Foundation; either version 2, or (at your option) |
---|
| 9 | any later version. |
---|
| 10 | |
---|
| 11 | ### File Specific: |
---|
| 12 | main-programmer: Patrick Boenzli |
---|
| 13 | */ |
---|
| 14 | |
---|
| 15 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_OBJECT_MANAGER |
---|
| 16 | |
---|
| 17 | #include "object_manager.h" |
---|
[4288] | 18 | #include "garbage_collector.h" |
---|
[4286] | 19 | #include "list.h" |
---|
[4245] | 20 | |
---|
[4288] | 21 | |
---|
[4245] | 22 | using namespace std; |
---|
| 23 | |
---|
| 24 | |
---|
| 25 | /** |
---|
| 26 | \brief standard constructor |
---|
| 27 | */ |
---|
[4592] | 28 | ObjectManager::ObjectManager () |
---|
[4245] | 29 | { |
---|
[4320] | 30 | this->setClassID(CL_OBJECT_MANAGER, "ObjectManager"); |
---|
[4597] | 31 | this->setName("ObjectManager"); |
---|
[4592] | 32 | |
---|
[4286] | 33 | this->managedObjectList = new tList<BaseObject>*[CL_NUMBER]; |
---|
[4318] | 34 | for(int i = 0; i < CL_NUMBER; ++i) |
---|
| 35 | { |
---|
| 36 | this->managedObjectList[i] = NULL; |
---|
| 37 | } |
---|
[4245] | 38 | } |
---|
| 39 | |
---|
[4322] | 40 | |
---|
[4245] | 41 | /** |
---|
| 42 | \brief the singleton reference to this class |
---|
| 43 | */ |
---|
| 44 | ObjectManager* ObjectManager::singletonRef = NULL; |
---|
| 45 | |
---|
| 46 | /** |
---|
| 47 | \brief standard deconstructor |
---|
| 48 | */ |
---|
[4592] | 49 | ObjectManager::~ObjectManager () |
---|
[4245] | 50 | { |
---|
| 51 | ObjectManager::singletonRef = NULL; |
---|
[4285] | 52 | } |
---|
[4245] | 53 | |
---|
[4485] | 54 | /** |
---|
| 55 | \brief adds an element to the list of dead objects |
---|
| 56 | \param index: The type of object to add |
---|
| 57 | \param object: pointer to the object at hand |
---|
| 58 | */ |
---|
[4322] | 59 | void ObjectManager::addToDeadList(int index, BaseObject* object) |
---|
[4288] | 60 | { |
---|
| 61 | if( likely(this->managedObjectList[index] != NULL)) |
---|
| 62 | this->managedObjectList[index]->add(object); |
---|
| 63 | else |
---|
[4324] | 64 | PRINTF(0)(" Critical: unable to add object to the list nr. %i: no list initialized - ignoring\n", index); |
---|
[4288] | 65 | } |
---|
[4285] | 66 | |
---|
[4485] | 67 | /** |
---|
| 68 | \brief resurects an object |
---|
| 69 | \param index: the type of resource to load |
---|
| 70 | \param number: how many of them |
---|
[4285] | 71 | |
---|
[4485] | 72 | \todo if it is unable to get an object from the deadList, it should create it |
---|
| 73 | */ |
---|
[4322] | 74 | BaseObject* ObjectManager::getFromDeadList(int index, int number) |
---|
[4289] | 75 | { |
---|
| 76 | if( likely(this->managedObjectList[index] != NULL)) |
---|
| 77 | { |
---|
| 78 | BaseObject* obj = this->managedObjectList[index]->firstElement(); |
---|
| 79 | this->managedObjectList[index]->remove(obj); |
---|
[4324] | 80 | if( unlikely(obj == NULL)) |
---|
[4592] | 81 | { |
---|
| 82 | PRINTF(0)("Critical: there was no object anymore in the dead list! This could result in Segfaults\n"); |
---|
| 83 | } |
---|
[4289] | 84 | return obj; |
---|
| 85 | } |
---|
| 86 | else |
---|
[4324] | 87 | PRINTF(0)(" Critical: unable to get object from the list nr. %i: no elements initialized - ignoring\n", index); |
---|
| 88 | return NULL; |
---|
[4289] | 89 | } |
---|
[4287] | 90 | |
---|
[4485] | 91 | /** |
---|
| 92 | \brief outputs some simple debug information about the ObjectManage |
---|
| 93 | */ |
---|
[4746] | 94 | void ObjectManager::debug() const |
---|
[4287] | 95 | { |
---|
| 96 | PRINT(0)("\n==========================| ObjectManager::debug() |===\n"); |
---|
[4592] | 97 | PRINT(0)("= Number of registerable classes: %i\n", CL_NUMBER ); |
---|
[4287] | 98 | PRINT(0)("= Currently cached objects: \n"); |
---|
| 99 | for(int i = 0; i < CL_NUMBER; ++i) |
---|
| 100 | { |
---|
[4318] | 101 | if( this->managedObjectList[i] != NULL) |
---|
[4592] | 102 | PRINT(0)("= o Class Nr. %i has cached %i object(s)\n", i, this->managedObjectList[i]->getSize()); |
---|
[4287] | 103 | else |
---|
[4592] | 104 | PRINT(0)("= o Class Nr. %i has cached 0 object(s)\n", i); |
---|
[4287] | 105 | } |
---|
| 106 | PRINT(0)("=======================================================\n"); |
---|
| 107 | } |
---|