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.

Location:
code/branches/kicklib2/src/orxonox
Files:
3 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}
  • code/branches/kicklib2/src/orxonox/PawnManager.h

    r5781 r8307  
    3737namespace orxonox
    3838{
    39     class _OrxonoxExport PawnManager : protected Singleton<PawnManager>, public Tickable
     39    class _OrxonoxExport PawnManager : public Singleton<PawnManager>, public Tickable
    4040    {
    4141            friend class Singleton<PawnManager>;
    4242        public:
    43             static void touch();
     43            PawnManager();
     44            virtual ~PawnManager();
    4445
    45             virtual void tick(float dt);
     46            virtual void preUpdate(const Clock& time);
    4647
    4748        private:
    48             PawnManager();
    49             virtual ~PawnManager();
    5049
    5150            static PawnManager* singletonPtr_s;
  • code/branches/kicklib2/src/orxonox/worldentities/pawns/Pawn.cc

    r7889 r8307  
    3636#include "network/NetworkFunction.h"
    3737
    38 #include "PawnManager.h"
    3938#include "infos/PlayerInfo.h"
    4039#include "controllers/Controller.h"
     
    5958        RegisterObject(Pawn);
    6059
    61         PawnManager::touch();
    6260        this->bAlive_ = true;
    6361        this->bReload_ = false;
Note: See TracChangeset for help on using the changeset viewer.