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 | |
---|
22 | using namespace std; |
---|
23 | |
---|
24 | |
---|
25 | /** |
---|
26 | \brief standard constructor |
---|
27 | */ |
---|
28 | ObjectManager::ObjectManager () |
---|
29 | { |
---|
30 | this->setClassID(CL_OBJECT_MANAGER, "ObjectManager"); |
---|
31 | |
---|
32 | this->managedObjectList = new tList<BaseObject>*[CL_NUMBER]; |
---|
33 | for(int i = 0; i < CL_NUMBER; ++i) |
---|
34 | { |
---|
35 | this->managedObjectList[i] = NULL; |
---|
36 | } |
---|
37 | |
---|
38 | this->garbageCollector = GarbageCollector::getInstance(); |
---|
39 | } |
---|
40 | |
---|
41 | |
---|
42 | /** |
---|
43 | \brief the singleton reference to this class |
---|
44 | */ |
---|
45 | ObjectManager* ObjectManager::singletonRef = NULL; |
---|
46 | |
---|
47 | /** |
---|
48 | \brief standard deconstructor |
---|
49 | */ |
---|
50 | ObjectManager::~ObjectManager () |
---|
51 | { |
---|
52 | ObjectManager::singletonRef = NULL; |
---|
53 | } |
---|
54 | |
---|
55 | /** |
---|
56 | \brief adds an element to the list of dead objects |
---|
57 | \param index: The type of object to add |
---|
58 | \param object: pointer to the object at hand |
---|
59 | */ |
---|
60 | void ObjectManager::addToDeadList(int index, BaseObject* object) |
---|
61 | { |
---|
62 | if( likely(this->managedObjectList[index] != NULL)) |
---|
63 | this->managedObjectList[index]->add(object); |
---|
64 | else |
---|
65 | PRINTF(0)(" Critical: unable to add object to the list nr. %i: no list initialized - ignoring\n", index); |
---|
66 | } |
---|
67 | |
---|
68 | /** |
---|
69 | \brief resurects an object |
---|
70 | \param index: the type of resource to load |
---|
71 | \param number: how many of them |
---|
72 | |
---|
73 | \todo if it is unable to get an object from the deadList, it should create it |
---|
74 | */ |
---|
75 | BaseObject* ObjectManager::getFromDeadList(int index, int number) |
---|
76 | { |
---|
77 | if( likely(this->managedObjectList[index] != NULL)) |
---|
78 | { |
---|
79 | BaseObject* obj = this->managedObjectList[index]->firstElement(); |
---|
80 | this->managedObjectList[index]->remove(obj); |
---|
81 | if( unlikely(obj == NULL)) |
---|
82 | { |
---|
83 | PRINTF(0)("Critical: there was no object anymore in the dead list! This could result in Segfaults\n"); |
---|
84 | } |
---|
85 | return obj; |
---|
86 | } |
---|
87 | else |
---|
88 | PRINTF(0)(" Critical: unable to get object from the list nr. %i: no elements initialized - ignoring\n", index); |
---|
89 | return NULL; |
---|
90 | } |
---|
91 | |
---|
92 | /** |
---|
93 | \brief outputs some simple debug information about the ObjectManage |
---|
94 | */ |
---|
95 | void ObjectManager::debug(void) const |
---|
96 | { |
---|
97 | PRINT(0)("\n==========================| ObjectManager::debug() |===\n"); |
---|
98 | PRINT(0)("= Number of registerable classes: %i\n", CL_NUMBER ); |
---|
99 | PRINT(0)("= Currently cached objects: \n"); |
---|
100 | for(int i = 0; i < CL_NUMBER; ++i) |
---|
101 | { |
---|
102 | if( this->managedObjectList[i] != NULL) |
---|
103 | PRINT(0)("= o Class Nr. %i has cached %i object(s)\n", i, this->managedObjectList[i]->getSize()); |
---|
104 | else |
---|
105 | PRINT(0)("= o Class Nr. %i has cached 0 object(s)\n", i); |
---|
106 | } |
---|
107 | PRINT(0)("=======================================================\n"); |
---|
108 | } |
---|