Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4941 in orxonox.OLD for orxonox/trunk/src/util


Ignore:
Timestamp:
Jul 23, 2005, 1:08:39 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: new garbage-collection-algorithm works, but the entities are not correctly setup for re-entering the scene.

Location:
orxonox/trunk/src/util
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/util/fast_factory.cc

    r4940 r4941  
    178178  else
    179179  {
    180     FastObjectMember* tmpC = deadList;
     180    FastObjectMember* tmpC = this->deadList;
    181181    this->deadList = this->deadList->next;
    182182
  • orxonox/trunk/src/util/fast_factory.h

    r4940 r4941  
    2323#include "base_object.h"
    2424
    25 
    26 // FORWARD DECLARATION //
    27 class GarbageCollector;
    28 template<class T>
    29 class tList;
    30 
    3125/**
    32  * Creates a FastFactory to a Loadable FastFactory.
     26 * Creates a FastFactory to a Createable FastFactory.
    3327 */
    34 //#define CREATE_FAST_FACTORY(CLASS_NAME, CLASS_ID) \
    35 //tFastFactory<CLASS_NAME>* global_##CLASS_NAME##_FastFactory = new tFastFactory<CLASS_NAME>(#CLASS_NAME, CLASS_ID)
     28#define CREATE_FAST_FACTORY(CLASS_NAME, CLASS_ID) \
     29  tFastFactory<CLASS_NAME>* global_##CLASS_NAME##_FastFactory = tFastFactory<CLASS_NAME>::getFastFactory(CLASS_ID, #CLASS_NAME)
    3630
    3731//! A struct, that holds Lists of Objects of a certain type.
    38 struct FastObjectMember
     32typedef struct FastObjectMember
    3933  {
    4034    BaseObject*          objectPointer;      //!< Pointer to the Object Stored in this Class (if it is the DeadList, else it is bork)
     
    6559
    6660    void prepare(unsigned int count);
    67     // retrival functions for fast Ineraction
    68     //FastFactory* getFastFactory(ClassID classID);
    6961
    7062    static void flushAll(bool hardFLUSH = false);
     
    110102    FastFactory*          next;                 //!< pointer to the next FastFactory.
    111103  };
     104
     105
    112106
    113107/**
     
    157151}
    158152
    159 
    160153/**
    161154 * fabricates an Object of Class T, that corresponds to classID.
  • orxonox/trunk/src/util/garbage_collector.cc

    r4938 r4941  
    3737   this->setClassID(CL_GARBAGE_COLLECTOR, "GarbageCollector");
    3838   this->setName("GarbageCollector");
     39
     40   this->collectedObjects = NULL;
     41   this->unusedContainers = NULL;
    3942
    4043   this->time = 0;
     
    8184
    8285/**
     86 * collect an Object, that should be scheduled for clearing.
     87 * @param object the Object to schedule.
     88 */
     89void GarbageCollector::collect(BaseObject* object)
     90{
     91  printf("TEST\n");
     92  State::getWorldEntityList()->remove(dynamic_cast<WorldEntity*>(object));
     93  FastObjectMember* tmpC;
     94  if (unlikely(this->unusedContainers == NULL))
     95  {
     96    tmpC = new FastObjectMember;
     97  }
     98  else
     99  {
     100    tmpC = this->unusedContainers;
     101    this->unusedContainers = this->unusedContainers->next;
     102  }
     103
     104  tmpC->next = this->collectedObjects;
     105  tmpC->objectPointer = object;
     106  this->collectedObjects = tmpC;
     107}
     108
     109/**
    83110 *  this ticks the GarbageCollector to give it the time pulse
    84111 * @param time: the time passed since last tick
     
    92119
    93120
     121void GarbageCollector::update()
     122{
     123  if (this->time < this->delay)
     124  {
     125    return;
     126  }
     127  if (this->collectedObjects == NULL)
     128    return;
     129  else
     130  {
     131    FastObjectMember* tmpC = this->collectedObjects;
     132    FastObjectMember* moveC;
     133    while (tmpC != NULL)
     134    {
     135      WorldEntity* entity = dynamic_cast<WorldEntity*>(tmpC->objectPointer);
     136      //State::getWorldEntityList()->remove(entity);
     137      entity->remove();
     138      FastFactory::kill(entity, true);
     139
     140      moveC = tmpC->next;
     141      tmpC->next = this->unusedContainers;
     142      this->unusedContainers = tmpC;
     143      tmpC = moveC;
     144    }
     145    this->collectedObjects = NULL;
     146  }
     147}
     148
    94149/**
    95150 *  this updated the gargabe collection, if the time is ready
    96151*/
    97 void GarbageCollector::update()
    98 {
    99   if( this->time < this->delay)
    100     return;
    101   /* garbage collect */
    102   PRINTF(3)("=============================\n");
    103   PRINTF(3)("Processing Garbage Collection\n");
    104   PRINTF(3)("=============================\n");
    105   int counter = 0;
    106 
    107   tList<WorldEntity>* list = State::getWorldEntityList();
    108 
    109   tIterator<WorldEntity>* iterator = list->getIterator();
    110   WorldEntity* entity = iterator->nextElement();
    111   while( entity != NULL)
    112     {
    113       if( entity->isFinalized())
    114         {
    115           PRINTF(4)("= finalizing object\n");
    116           ++counter;
    117 
    118           /* first remove out of entity list */
    119           list->remove(entity);
    120           /* second remove out of pnode tree */
    121           entity->remove();
    122           /* then finaly delete reference */
    123           //delete entity;
    124           //FastFactory::kill();
    125           //ObjectManager::getInstance()->addToDeadList(entity->getClassID() & CL_MASK_LOWLEVEL_CLASS, entity);
    126         }
    127       entity = iterator->nextElement();
    128     }
    129 
    130   PRINTF(3)("= collected %i unused objects\n", counter);
    131   PRINTF(3)("=============================\n");
    132 
    133   //ObjectManager::getInstance()->debug();
    134 
    135   /* reset time to count again up to this->delay */
    136   this->time = 0;
    137 }
     152// void GarbageCollector::update()
     153// {
     154//   if( this->time < this->delay)
     155//     return;
     156//   /* garbage collect */
     157//   PRINTF(3)("=============================\n");
     158//   PRINTF(3)("Processing Garbage Collection\n");
     159//   PRINTF(3)("=============================\n");
     160//   int counter = 0;
     161//
     162//   tList<WorldEntity>* list = State::getWorldEntityList();
     163//
     164//   tIterator<WorldEntity>* iterator = list->getIterator();
     165//   WorldEntity* entity = iterator->nextElement();
     166//   while( entity != NULL)
     167//     {
     168//       if( entity->isFinalized())
     169//         {
     170//           PRINTF(4)("= finalizing object\n");
     171//           ++counter;
     172//
     173//           /* first remove out of entity list */
     174//           list->remove(entity);
     175//           /* second remove out of pnode tree */
     176//           entity->remove();
     177//           /* then finaly delete reference */
     178//           //delete entity;
     179//           //FastFactory::kill();
     180//           //ObjectManager::getInstance()->addToDeadList(entity->getClassID() & CL_MASK_LOWLEVEL_CLASS, entity);
     181//         }
     182//       entity = iterator->nextElement();
     183//     }
     184//
     185//   PRINTF(3)("= collected %i unused objects\n", counter);
     186//   PRINTF(3)("=============================\n");
     187//
     188//   //ObjectManager::getInstance()->debug();
     189//
     190//   /* reset time to count again up to this->delay */
     191//   this->time = 0;
     192// }
  • orxonox/trunk/src/util/garbage_collector.h

    r4836 r4941  
    11/*!
    2     \file garbage_collector.h
    3   * Definition of the proto class template, used quickly start work
    4    @todo Example: this shows how to use simply add a Marker that here has to be done something.
    5 
    6     The Protoclass exists, to help you quikly getting the run for how to develop in orxonox.
    7     It is an example for the CODING-CONVENTION, and a starting-point for every class.
    8 */
     2 * @file garbage_collector.h
     3 * Definition of the proto class template, used quickly start work
     4 * @todo Example: this shows how to use simply add a Marker that here has to be done something.
     5 *
     6 *  The Protoclass exists, to help you quikly getting the run for how to develop in orxonox.
     7 *  It is an example for the CODING-CONVENTION, and a starting-point for every class.
     8 */
    99
    1010#ifndef _GARBAGE_COLLECTOR_H
     
    1313#include "base_object.h"
    1414
     15#include "fast_factory.h"
    1516
    1617//! this class maintains the garbage collection.
     
    3031  void forceCollection();
    3132
     33  void collect(BaseObject* object);
     34
    3235  void tick(float time);
    3336  void update();
     
    3841 private:
    3942  static GarbageCollector*    singletonRef;           //!< The reference to this class (singleton)
    40   float                       delay;                  //!< this is the delay to wait until collection
     43
     44  FastObjectMember*           collectedObjects;       //!< A list of recently collected Objects, that want to be deleted.
     45  FastObjectMember*           unusedContainers;       //!< A list of unused containers.
     46  float                       delay;                  //!< this is the delay to wait until collection.
    4147  float                       time;                   //!< the current time
    4248
Note: See TracChangeset for help on using the changeset viewer.