[4245] | 1 | /* |
---|
| 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 | |
---|
[4311] | 21 | #include "projectile.h" |
---|
[4288] | 22 | |
---|
[4245] | 23 | using namespace std; |
---|
| 24 | |
---|
| 25 | |
---|
| 26 | /** |
---|
| 27 | \brief standard constructor |
---|
| 28 | */ |
---|
| 29 | ObjectManager::ObjectManager () |
---|
| 30 | { |
---|
[4286] | 31 | this->setClassName ("ObjectManager"); |
---|
| 32 | |
---|
| 33 | //this->managedObjectList = new BaseObject*[CL_NUMBER]; |
---|
| 34 | this->managedObjectList = new tList<BaseObject>*[CL_NUMBER]; |
---|
[4288] | 35 | |
---|
| 36 | this->garbageCollector = GarbageCollector::getInstance(); |
---|
[4245] | 37 | } |
---|
| 38 | |
---|
| 39 | /** |
---|
| 40 | \brief the singleton reference to this class |
---|
| 41 | */ |
---|
| 42 | ObjectManager* ObjectManager::singletonRef = NULL; |
---|
| 43 | |
---|
| 44 | /** |
---|
| 45 | \returns a Pointer to this Class |
---|
| 46 | */ |
---|
| 47 | ObjectManager* ObjectManager::getInstance(void) |
---|
| 48 | { |
---|
| 49 | if (!ObjectManager::singletonRef) |
---|
| 50 | ObjectManager::singletonRef = new ObjectManager(); |
---|
| 51 | return ObjectManager::singletonRef; |
---|
| 52 | } |
---|
| 53 | |
---|
[4285] | 54 | |
---|
[4245] | 55 | /** |
---|
| 56 | \brief standard deconstructor |
---|
| 57 | |
---|
| 58 | */ |
---|
| 59 | ObjectManager::~ObjectManager () |
---|
| 60 | { |
---|
| 61 | ObjectManager::singletonRef = NULL; |
---|
[4285] | 62 | } |
---|
[4245] | 63 | |
---|
[4285] | 64 | |
---|
[4312] | 65 | /* |
---|
[4311] | 66 | void ObjectManager::cache(classList index, int number, Projectile* copyObject) |
---|
[4285] | 67 | { |
---|
[4286] | 68 | //this->managedObjectList[index] = new BaseObject[number]; |
---|
| 69 | this->managedObjectList[index] = new tList<BaseObject>(); |
---|
| 70 | for(int i = 0; i < number; ++i) |
---|
| 71 | { |
---|
[4311] | 72 | this->managedObjectList[index]->add(new Projectile(*copyObject)); |
---|
[4286] | 73 | } |
---|
[4245] | 74 | } |
---|
[4312] | 75 | */ |
---|
[4285] | 76 | |
---|
| 77 | |
---|
[4288] | 78 | void ObjectManager::addToDeadList(classList index, BaseObject* object) |
---|
| 79 | { |
---|
| 80 | if( likely(this->managedObjectList[index] != NULL)) |
---|
| 81 | this->managedObjectList[index]->add(object); |
---|
| 82 | else |
---|
[4289] | 83 | PRINTF(0)(" Error: unable to add object to the list nr. %i: no list initialized - ignoring\n", index); |
---|
[4288] | 84 | } |
---|
[4285] | 85 | |
---|
| 86 | |
---|
[4288] | 87 | BaseObject* ObjectManager::getFromDeadList(classList index, int number) |
---|
[4289] | 88 | { |
---|
| 89 | if( likely(this->managedObjectList[index] != NULL)) |
---|
| 90 | { |
---|
| 91 | BaseObject* obj = this->managedObjectList[index]->firstElement(); |
---|
| 92 | this->managedObjectList[index]->remove(obj); |
---|
| 93 | return obj; |
---|
| 94 | } |
---|
| 95 | else |
---|
| 96 | PRINTF(0)(" Error: unable to get object from the list nr. %i: no elements initialized - ignoring\n", index); |
---|
| 97 | } |
---|
[4287] | 98 | |
---|
| 99 | |
---|
| 100 | void ObjectManager::debug() |
---|
| 101 | { |
---|
| 102 | PRINT(0)("\n==========================| ObjectManager::debug() |===\n"); |
---|
| 103 | PRINT(0)("= Number of registerable classes: %i\n", CL_NUMBER ); |
---|
| 104 | PRINT(0)("= Currently cached objects: \n"); |
---|
| 105 | for(int i = 0; i < CL_NUMBER; ++i) |
---|
| 106 | { |
---|
| 107 | if(this->managedObjectList[i] != NULL) |
---|
| 108 | PRINT(0)("= o Class Nr. %i has cached %i object(s)\n", i, this->managedObjectList[i]->getSize()); |
---|
| 109 | else |
---|
| 110 | PRINT(0)("= o Class Nr. %i has cached 0 object(s)\n", i); |
---|
| 111 | } |
---|
| 112 | PRINT(0)("=======================================================\n"); |
---|
| 113 | } |
---|