Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: setClassID implemented in all files

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