Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 4319 was 4318, checked in by patrick, 20 years ago

orxonox/trunk: now changed the orxonox baseobject to object id representation. this is much faster, but needs some care, when defining new classes

File size: 2.6 KB
RevLine 
[4245]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"
[4288]18#include "garbage_collector.h"
[4286]19#include "list.h"
[4245]20
[4311]21#include "projectile.h"
[4288]22
[4245]23using namespace std;
24
25
26/**
27   \brief standard constructor
28*/
29ObjectManager::ObjectManager () 
30{
[4318]31  this->setClassID(CL_OBJECT_MANAGER);
[4286]32 
33  this->managedObjectList = new tList<BaseObject>*[CL_NUMBER];
[4318]34  for(int i = 0; i < CL_NUMBER; ++i)
35    {
36      this->managedObjectList[i] = NULL;
37    }
[4288]38
39  this->garbageCollector = GarbageCollector::getInstance();
[4245]40}
41
42/**
43   \brief the singleton reference to this class
44*/
45ObjectManager* ObjectManager::singletonRef = NULL;
46
47/**
48   \returns a Pointer to this Class
49*/
50ObjectManager* ObjectManager::getInstance(void)
51{
52  if (!ObjectManager::singletonRef)
53    ObjectManager::singletonRef = new ObjectManager();
54  return ObjectManager::singletonRef;
55}
56
[4285]57
[4245]58/**
59   \brief standard deconstructor
60
61*/
62ObjectManager::~ObjectManager () 
63{
64  ObjectManager::singletonRef = NULL;
[4285]65}
[4245]66
[4285]67
[4288]68void ObjectManager::addToDeadList(classList index, BaseObject* object)
69{
70  if( likely(this->managedObjectList[index] != NULL))
71    this->managedObjectList[index]->add(object);
72  else
[4289]73    PRINTF(0)(" Error: unable to add object to the list nr. %i: no list initialized - ignoring\n", index);
[4288]74}
[4285]75
76
[4288]77BaseObject* ObjectManager::getFromDeadList(classList index, int number)
[4289]78{
79  if( likely(this->managedObjectList[index] != NULL))
80    {
81      BaseObject* obj = this->managedObjectList[index]->firstElement();
82      this->managedObjectList[index]->remove(obj);
83      return obj;
84    }
85  else
86    PRINTF(0)(" Error: unable to get object from the list nr. %i: no elements initialized - ignoring\n", index);
87}
[4287]88
89
90void ObjectManager::debug()
91{
92  PRINT(0)("\n==========================| ObjectManager::debug() |===\n");
93  PRINT(0)("=  Number of registerable classes: %i\n", CL_NUMBER ); 
94  PRINT(0)("=  Currently cached objects: \n");
95  for(int i = 0; i < CL_NUMBER; ++i)
96    {
[4318]97      if( this->managedObjectList[i] != NULL)
[4287]98        PRINT(0)("=   o Class Nr. %i has cached %i object(s)\n", i, this->managedObjectList[i]->getSize());
99      else
100        PRINT(0)("=   o Class Nr. %i has cached 0 object(s)\n", i);
101    }
102  PRINT(0)("=======================================================\n");
103}
Note: See TracBrowser for help on using the repository browser.