Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4936 in orxonox.OLD for orxonox


Ignore:
Timestamp:
Jul 22, 2005, 7:30:49 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: FastFactory: gets flushed now → devMail is withdrawn now.
Also reimplemented much stuff, so it now works most out of the BaseClass. → still some minor stuff to fix.
GarbageCollector, i will come to you soon …

Location:
orxonox/trunk/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/story_entities/world.cc

    r4921 r4936  
    201201  //delete animator
    202202
     203  FastFactory::flushAll();
    203204  delete NullParent::getInstance();
    204205  EventHandler::getInstance()->debug();
    205206
    206207  LoadClassDescription::printAll();
    207 
    208208  ResourceManager::getInstance()->unloadAllByPriority(RP_LEVEL);
    209209}
  • orxonox/trunk/src/util/object_manager.cc

    r4933 r4936  
    9797}
    9898
     99/**
     100 *
     101 */
     102void FastFactory::flushAll(bool hardFLUSH)
     103{
     104  FastFactory* tmpFac = FastFactory::first;
     105  while (tmpFac != NULL)
     106  {
     107    tmpFac->flush(hardFLUSH);
     108    tmpFac = tmpFac->next;
     109  }
     110}
     111
     112
     113/**
     114 * ereases all the remaining containers, without deleting the stored Objects inside of them.
     115 */
     116void FastFactory::flush(bool hardFLUSH)
     117{
     118  FastObjectMember* tmpMember = this->deadList, *delMember = NULL;
     119  while (tmpMember != NULL)
     120  {
     121    delMember = tmpMember;
     122    tmpMember = tmpMember->next;
     123    if (unlikely(hardFLUSH == true))
     124      delete delMember->objectPointer;
     125    delete delMember;
     126  }
     127  this->deadList = NULL;
     128
     129  tmpMember = this->unusedContainers;
     130  while (tmpMember != NULL)
     131  {
     132    delMember = tmpMember;
     133    tmpMember = tmpMember->next;
     134    delete delMember;
     135  }
     136  this->unusedContainers = NULL;
     137}
     138
     139
     140
     141BaseObject* FastFactory::resurect(ClassID classID)
     142{
     143  PRINTF(4)("Resurecting Object of type %s\n", this->getName());
     144  if (unlikely(this->deadList == NULL))
     145  {
     146    PRINTF(2)("The deadList of Class %s is empty, this may be either because it has not been filled yet, or the cache is to small.\n" \
     147        "Fabricating a new %s", this->getName(), this->getName());
     148    this->fabricate();
     149    return this->resurect(classID);
     150  }
     151  else
     152  {
     153  FastObjectMember* tmpC = deadList;
     154  this->deadList = this->deadList->next;
     155
     156  tmpC->next = this->unusedContainers;
     157  this->unusedContainers = tmpC;
     158
     159  return tmpC->objectPointer;
     160  }
     161}
     162
     163
     164
     165void FastFactory::kill(ClassID classID, BaseObject* object)
     166{
     167  FastObjectMember* tmpC;
     168  if (unlikely(this->unusedContainers == NULL))
     169  {
     170    tmpC = new FastObjectMember;
     171  }
     172  else
     173  {
     174    tmpC = this->unusedContainers;
     175    this->unusedContainers = this->unusedContainers->next;
     176  }
     177
     178  tmpC->next = this->deadList;
     179  tmpC->objectPointer = object;
     180}
     181
    99182
    100183
  • orxonox/trunk/src/util/object_manager.h

    r4935 r4936  
    5656    void kill(ClassID classID, BaseObject* object);
    5757
     58    virtual void fabricate() = NULL;
    5859    // retrival functions for fast Ineraction
    5960    //FastFactory* getFastFactory(ClassID classID);
     61
     62    static void flushAll(bool hardFLUSH = false);
     63    void flush(bool hardFLUSH = false);
    6064
    6165    /** @returns the first FastFactory */
     
    102106
    103107    T* resurect();
    104     void kill(T* object);
    105 
    106108  private:
    107109    tFastFactory(ClassID classID, const char* fastFactoryName);
    108110
    109     T* fabricate();
     111    virtual void fabricate();
    110112
    111113  private:
     
    142144
    143145template<class T>
    144     T* tFastFactory<T>::fabricate()
     146    void tFastFactory<T>::fabricate()
    145147{
    146148  FastObjectMember* tmpFirstDead = new FastObjectMember;
    147   T* fabricatedT = new T();
    148   tmpFirstDead->objectPointer = fabricatedT;
     149  tmpFirstDead->objectPointer = new T();
    149150  tmpFirstDead->next = this->deadList;
    150151  ++this->storedDeadObjects;
    151152
    152153  this->deadList = tmpFirstDead;
    153   return fabricatedT;
    154154}
    155155
     
    175175    PRINTF(2)("The deadList of Class %s is empty, this may be either because it has not been filled yet, or the cache is to small.\n" \
    176176        "Fabricating a new %s", this->getName(), this->getName());
    177     return this->fabricate();
     177    this->fabricate();
     178    return resurect();
    178179  }
    179180  else
     
    187188    return dynamic_cast<T*>(tmpC->objectPointer);
    188189  }
    189 }
    190 
    191 template<class T>
    192     void tFastFactory<T>::kill(T* object)
    193 {
    194   FastObjectMember* tmpC;
    195   if (unlikely(this->unusedContainers == NULL))
    196   {
    197     tmpC = new FastObjectMember;
    198   }
    199   else
    200   {
    201     tmpC = this->unusedContainers;
    202     this->unusedContainers = this->unusedContainers->next;
    203   }
    204 
    205   tmpC->next = this->deadList;
    206   tmpC->objectPointer = object;
    207190}
    208191
Note: See TracChangeset for help on using the changeset viewer.