Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 22, 2011, 10:23:04 PM (14 years ago)
Author:
rgrieder
Message:

Manage PawnManager by Scopes. Then the singleton should get deleted in any case.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/kicklib2/src/orxonox/PawnManager.cc

    r5929 r8307  
    2929#include "PawnManager.h"
    3030
     31#include "util/ScopedSingletonManager.h"
    3132#include "core/CoreIncludes.h"
    3233#include "worldentities/pawns/Pawn.h"
     
    3435namespace orxonox
    3536{
    36     PawnManager* PawnManager::singletonPtr_s = 0;
     37    ManageScopedSingleton(PawnManager, ScopeID::Root, false);
    3738
    3839    PawnManager::PawnManager()
     
    4344    PawnManager::~PawnManager()
    4445    {
     46        // Be sure to delete all the pawns
     47        for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it != ObjectList<Pawn>::end(); )
     48            (it++)->destroy();
    4549    }
    4650
    47     void PawnManager::touch()
     51    void PawnManager::preUpdate(const Clock& time)
    4852    {
    49         if (!PawnManager::singletonPtr_s)
    50             new PawnManager();
    51     }
    52 
    53     void PawnManager::tick(float dt)
    54     {
    55         unsigned int count = 0;
    56         for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it != ObjectList<Pawn>::end(); ++count)
     53        for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it != ObjectList<Pawn>::end(); )
    5754        {
    5855            if (!it->isAlive())
     
    6158                ++it;
    6259        }
    63 
    64         if (count == 0)
    65             this->destroy();
    6660    }
    6761}
Note: See TracChangeset for help on using the changeset viewer.