Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 4322 was 4322, checked in by patrick, 19 years ago

now the objectmanagment works smoothly with the garbage collection: shoots (projectiles) are now precached (100 pieces) used from this pool and recyled :)

File size: 2.6 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 "projectile.h"
22
23using namespace std;
24
25
26/**
27   \brief standard constructor
28*/
29ObjectManager::ObjectManager () 
30{
31  this->setClassID(CL_OBJECT_MANAGER, "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   \returns a Pointer to this Class
50*/
51ObjectManager* ObjectManager::getInstance(void)
52{
53  if (!ObjectManager::singletonRef)
54    ObjectManager::singletonRef = new ObjectManager();
55  return ObjectManager::singletonRef;
56}
57
58
59/**
60   \brief standard deconstructor
61
62*/
63ObjectManager::~ObjectManager () 
64{
65  ObjectManager::singletonRef = NULL;
66}
67
68
69void ObjectManager::addToDeadList(int index, BaseObject* object)
70{
71  if( likely(this->managedObjectList[index] != NULL))
72    this->managedObjectList[index]->add(object);
73  else
74    PRINTF(0)(" Error: unable to add object to the list nr. %i: no list initialized - ignoring\n", index);
75}
76
77
78BaseObject* ObjectManager::getFromDeadList(int index, int number)
79{
80  if( likely(this->managedObjectList[index] != NULL))
81    {
82      BaseObject* obj = this->managedObjectList[index]->firstElement();
83      this->managedObjectList[index]->remove(obj);
84      return obj;
85    }
86  else
87    PRINTF(0)(" Error: unable to get object from the list nr. %i: no elements initialized - ignoring\n", index);
88}
89
90
91void ObjectManager::debug()
92{
93  PRINT(0)("\n==========================| ObjectManager::debug() |===\n");
94  PRINT(0)("=  Number of registerable classes: %i\n", CL_NUMBER ); 
95  PRINT(0)("=  Currently cached objects: \n");
96  for(int i = 0; i < CL_NUMBER; ++i)
97    {
98      if( this->managedObjectList[i] != NULL)
99        PRINT(0)("=   o Class Nr. %i has cached %i object(s)\n", i, this->managedObjectList[i]->getSize());
100      else
101        PRINT(0)("=   o Class Nr. %i has cached 0 object(s)\n", i);
102    }
103  PRINT(0)("=======================================================\n");
104}
Note: See TracBrowser for help on using the repository browser.