[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 | |
---|
[4930] | 21 | #include "debug.h" |
---|
[4288] | 22 | |
---|
[4245] | 23 | using namespace std; |
---|
| 24 | |
---|
| 25 | |
---|
[4932] | 26 | |
---|
| 27 | |
---|
[4245] | 28 | /** |
---|
[4932] | 29 | * constructor, sets everything to zero and define factoryName |
---|
| 30 | */ |
---|
[4933] | 31 | FastFactory::FastFactory (ClassID classID, const char* fastFactoryName) |
---|
[4932] | 32 | { |
---|
| 33 | this->setClassID(CL_FAST_FACTORY, "FastFactory"); |
---|
| 34 | this->setName(fastFactoryName); |
---|
| 35 | |
---|
| 36 | this->storedClassID = classID; |
---|
| 37 | this->next = NULL; |
---|
| 38 | |
---|
[4933] | 39 | this->storedDeadObjects = 0; |
---|
| 40 | |
---|
[4932] | 41 | FastFactory::registerFastFactory(this); |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | /** a reference to the First FastFactory */ |
---|
| 45 | FastFactory* FastFactory::first = NULL; |
---|
| 46 | |
---|
| 47 | /** |
---|
| 48 | * destructor |
---|
| 49 | * clear the Q |
---|
| 50 | */ |
---|
| 51 | FastFactory::~FastFactory () |
---|
| 52 | { |
---|
| 53 | if (this == first) |
---|
| 54 | this->first = NULL; |
---|
| 55 | |
---|
| 56 | if (this->next) |
---|
| 57 | delete this->next; |
---|
| 58 | } |
---|
| 59 | |
---|
[4933] | 60 | void FastFactory::registerFastFactory(FastFactory* fastFactory) |
---|
[4932] | 61 | { |
---|
[4933] | 62 | PRINTF(4)("Registered FastFactory for '%s'\n", fastFactory->getName()); |
---|
[4932] | 63 | |
---|
| 64 | if( FastFactory::first == NULL) |
---|
[4933] | 65 | FastFactory::first = fastFactory; |
---|
[4932] | 66 | else |
---|
| 67 | { |
---|
| 68 | FastFactory* tmpFac = FastFactory::first; |
---|
| 69 | while( tmpFac->next != NULL) |
---|
| 70 | tmpFac = tmpFac->next; |
---|
[4933] | 71 | tmpFac->setNext(fastFactory); |
---|
[4932] | 72 | } |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | |
---|
[4933] | 76 | /** |
---|
| 77 | * searches for a FastFactory |
---|
| 78 | * @param factoryName the Name of the Factory to search for (not used) |
---|
| 79 | * @param classID the ClassID of the FastFactory to search for |
---|
| 80 | * @returns true if found, false otherwise. |
---|
| 81 | */ |
---|
| 82 | FastFactory* FastFactory::searchFastFactory(ClassID classID, const char* fastFactoryName) |
---|
| 83 | { |
---|
| 84 | if (FastFactory::first == NULL) |
---|
| 85 | return NULL; |
---|
| 86 | else |
---|
| 87 | { |
---|
| 88 | FastFactory* tmpFac = FastFactory::first; |
---|
| 89 | while (tmpFac != NULL) |
---|
| 90 | { |
---|
| 91 | if (tmpFac->storedClassID == classID) |
---|
| 92 | return tmpFac; |
---|
| 93 | tmpFac = tmpFac->next; |
---|
| 94 | } |
---|
| 95 | } |
---|
| 96 | return NULL; |
---|
| 97 | } |
---|
[4932] | 98 | |
---|
| 99 | |
---|
| 100 | |
---|
| 101 | |
---|
| 102 | |
---|
| 103 | |
---|
| 104 | |
---|
| 105 | |
---|
| 106 | |
---|
| 107 | |
---|
| 108 | |
---|
| 109 | /** |
---|
[4836] | 110 | * standard constructor |
---|
[4245] | 111 | */ |
---|
[4592] | 112 | ObjectManager::ObjectManager () |
---|
[4245] | 113 | { |
---|
[4320] | 114 | this->setClassID(CL_OBJECT_MANAGER, "ObjectManager"); |
---|
[4597] | 115 | this->setName("ObjectManager"); |
---|
[4592] | 116 | |
---|
[4245] | 117 | } |
---|
| 118 | |
---|
[4322] | 119 | |
---|
[4245] | 120 | /** |
---|
[4836] | 121 | * the singleton reference to this class |
---|
[4245] | 122 | */ |
---|
| 123 | ObjectManager* ObjectManager::singletonRef = NULL; |
---|
| 124 | |
---|
| 125 | /** |
---|
[4836] | 126 | * standard deconstructor |
---|
[4245] | 127 | */ |
---|
[4592] | 128 | ObjectManager::~ObjectManager () |
---|
[4245] | 129 | { |
---|
| 130 | ObjectManager::singletonRef = NULL; |
---|
[4285] | 131 | } |
---|
[4245] | 132 | |
---|
[4485] | 133 | /** |
---|
[4836] | 134 | * outputs some simple debug information about the ObjectManage |
---|
[4485] | 135 | */ |
---|
[4746] | 136 | void ObjectManager::debug() const |
---|
[4287] | 137 | { |
---|
| 138 | PRINT(0)("\n==========================| ObjectManager::debug() |===\n"); |
---|
[4932] | 139 | /* PRINT(0)("= Number of registerable classes: %i\n", CL_NUMBER ); |
---|
| 140 | PRINT(0)("= Currently cached objects: \n"); |
---|
| 141 | for(int i = 0; i < CL_NUMBER; ++i) |
---|
| 142 | { |
---|
[4318] | 143 | if( this->managedObjectList[i] != NULL) |
---|
[4592] | 144 | PRINT(0)("= o Class Nr. %i has cached %i object(s)\n", i, this->managedObjectList[i]->getSize()); |
---|
[4287] | 145 | else |
---|
[4592] | 146 | PRINT(0)("= o Class Nr. %i has cached 0 object(s)\n", i); |
---|
[4932] | 147 | }*/ |
---|
[4287] | 148 | PRINT(0)("=======================================================\n"); |
---|
| 149 | } |
---|
[4930] | 150 | |
---|
[4931] | 151 | |
---|