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" |
---|
18 | #include "garbage_collector.h" |
---|
19 | #include "list.h" |
---|
20 | |
---|
21 | #include "debug.h" |
---|
22 | |
---|
23 | using namespace std; |
---|
24 | |
---|
25 | |
---|
26 | |
---|
27 | |
---|
28 | /** |
---|
29 | * constructor, sets everything to zero and define factoryName |
---|
30 | */ |
---|
31 | FastFactory::FastFactory (ClassID classID, const char* fastFactoryName) |
---|
32 | { |
---|
33 | this->setClassID(CL_FAST_FACTORY, "FastFactory"); |
---|
34 | this->setName(fastFactoryName); |
---|
35 | |
---|
36 | this->storedClassID = classID; |
---|
37 | this->next = NULL; |
---|
38 | |
---|
39 | this->storedDeadObjects = 0; |
---|
40 | |
---|
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 | |
---|
60 | void FastFactory::registerFastFactory(FastFactory* fastFactory) |
---|
61 | { |
---|
62 | PRINTF(4)("Registered FastFactory for '%s'\n", fastFactory->getName()); |
---|
63 | |
---|
64 | if( FastFactory::first == NULL) |
---|
65 | FastFactory::first = fastFactory; |
---|
66 | else |
---|
67 | { |
---|
68 | FastFactory* tmpFac = FastFactory::first; |
---|
69 | while( tmpFac->next != NULL) |
---|
70 | tmpFac = tmpFac->next; |
---|
71 | tmpFac->setNext(fastFactory); |
---|
72 | } |
---|
73 | } |
---|
74 | |
---|
75 | |
---|
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 | } |
---|
98 | |
---|
99 | |
---|
100 | |
---|
101 | |
---|
102 | |
---|
103 | |
---|
104 | |
---|
105 | |
---|
106 | |
---|
107 | |
---|
108 | |
---|
109 | /** |
---|
110 | * standard constructor |
---|
111 | */ |
---|
112 | ObjectManager::ObjectManager () |
---|
113 | { |
---|
114 | this->setClassID(CL_OBJECT_MANAGER, "ObjectManager"); |
---|
115 | this->setName("ObjectManager"); |
---|
116 | |
---|
117 | } |
---|
118 | |
---|
119 | |
---|
120 | /** |
---|
121 | * the singleton reference to this class |
---|
122 | */ |
---|
123 | ObjectManager* ObjectManager::singletonRef = NULL; |
---|
124 | |
---|
125 | /** |
---|
126 | * standard deconstructor |
---|
127 | */ |
---|
128 | ObjectManager::~ObjectManager () |
---|
129 | { |
---|
130 | ObjectManager::singletonRef = NULL; |
---|
131 | } |
---|
132 | |
---|
133 | /** |
---|
134 | * outputs some simple debug information about the ObjectManage |
---|
135 | */ |
---|
136 | void ObjectManager::debug() const |
---|
137 | { |
---|
138 | PRINT(0)("\n==========================| ObjectManager::debug() |===\n"); |
---|
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 | { |
---|
143 | if( this->managedObjectList[i] != NULL) |
---|
144 | PRINT(0)("= o Class Nr. %i has cached %i object(s)\n", i, this->managedObjectList[i]->getSize()); |
---|
145 | else |
---|
146 | PRINT(0)("= o Class Nr. %i has cached 0 object(s)\n", i); |
---|
147 | }*/ |
---|
148 | PRINT(0)("=======================================================\n"); |
---|
149 | } |
---|
150 | |
---|
151 | |
---|