Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/util/object_manager.cc @ 4936

Last change on this file since 4936 was 4936, checked in by bensch, 19 years ago

orxonox/trunk: FastFactory: gets flushed now → devMail is withdrawn now.
Also reimplemented much stuff, so it now works most out of the BaseClass. → still some minor stuff to fix.
GarbageCollector, i will come to you soon …

File size: 4.9 KB
Line 
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
23using namespace std;
24
25
26
27
28/**
29 *  constructor, sets everything to zero and define factoryName
30 */
31FastFactory::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 */
45FastFactory* FastFactory::first = NULL;
46
47/**
48 *  destructor
49 *  clear the Q
50 */
51FastFactory::~FastFactory ()
52{
53  if (this == first)
54    this->first = NULL;
55
56  if (this->next)
57    delete this->next;
58}
59
60void 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 */
82FastFactory* 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 */
102void FastFactory::flushAll(bool hardFLUSH)
103{
104  FastFactory* tmpFac = FastFactory::first;
105  while (tmpFac != NULL)
106  {
107    tmpFac->flush(hardFLUSH);
108    tmpFac = tmpFac->next;
109  }
110}
111
112
113/**
114 * ereases all the remaining containers, without deleting the stored Objects inside of them.
115 */
116void FastFactory::flush(bool hardFLUSH)
117{
118  FastObjectMember* tmpMember = this->deadList, *delMember = NULL;
119  while (tmpMember != NULL)
120  {
121    delMember = tmpMember;
122    tmpMember = tmpMember->next;
123    if (unlikely(hardFLUSH == true))
124      delete delMember->objectPointer;
125    delete delMember;
126  }
127  this->deadList = NULL;
128
129  tmpMember = this->unusedContainers;
130  while (tmpMember != NULL)
131  {
132    delMember = tmpMember;
133    tmpMember = tmpMember->next;
134    delete delMember;
135  }
136  this->unusedContainers = NULL;
137}
138
139
140
141BaseObject* FastFactory::resurect(ClassID classID)
142{
143  PRINTF(4)("Resurecting Object of type %s\n", this->getName());
144  if (unlikely(this->deadList == NULL))
145  {
146    PRINTF(2)("The deadList of Class %s is empty, this may be either because it has not been filled yet, or the cache is to small.\n" \
147        "Fabricating a new %s", this->getName(), this->getName());
148    this->fabricate();
149    return this->resurect(classID);
150  }
151  else
152  {
153  FastObjectMember* tmpC = deadList;
154  this->deadList = this->deadList->next;
155
156  tmpC->next = this->unusedContainers;
157  this->unusedContainers = tmpC;
158
159  return tmpC->objectPointer;
160  }
161}
162
163
164
165void FastFactory::kill(ClassID classID, BaseObject* object)
166{
167  FastObjectMember* tmpC;
168  if (unlikely(this->unusedContainers == NULL))
169  {
170    tmpC = new FastObjectMember;
171  }
172  else
173  {
174    tmpC = this->unusedContainers;
175    this->unusedContainers = this->unusedContainers->next;
176  }
177
178  tmpC->next = this->deadList;
179  tmpC->objectPointer = object;
180}
181
182
183
184
185
186
187
188
189
190
191
192/**
193 *  standard constructor
194*/
195ObjectManager::ObjectManager ()
196{
197  this->setClassID(CL_OBJECT_MANAGER, "ObjectManager");
198  this->setName("ObjectManager");
199
200}
201
202
203/**
204 *  the singleton reference to this class
205*/
206ObjectManager* ObjectManager::singletonRef = NULL;
207
208/**
209 *  standard deconstructor
210*/
211ObjectManager::~ObjectManager ()
212{
213  ObjectManager::singletonRef = NULL;
214}
215
216/**
217 *  outputs some simple debug information about the ObjectManage
218*/
219void ObjectManager::debug() const
220{
221  PRINT(0)("\n==========================| ObjectManager::debug() |===\n");
222/* PRINT(0)("=  Number of registerable classes: %i\n", CL_NUMBER );
223 PRINT(0)("=  Currently cached objects: \n");
224 for(int i = 0; i < CL_NUMBER; ++i)
225   {
226      if( this->managedObjectList[i] != NULL)
227        PRINT(0)("=   o Class Nr. %i has cached %i object(s)\n", i, this->managedObjectList[i]->getSize());
228      else
229        PRINT(0)("=   o Class Nr. %i has cached 0 object(s)\n", i);
230    }*/
231  PRINT(0)("=======================================================\n");
232}
233
234
Note: See TracBrowser for help on using the repository browser.