Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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// }
Note: See TracChangeset for help on using the changeset viewer.