Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/chat/src/modules/pickup/PickupManager.cc @ 6632

Last change on this file since 6632 was 6524, checked in by dafrick, 15 years ago

Merged pickup branch into trunk. Yay. Persisting bugs will be fixed, very soon.

File size: 4.0 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      ...
24 *   Co-authors:
25 *      ...
26 *
27*/
28
29/**
30    @file
31    @brief Implementation of the PickupManager class.
32*/
33
34#include "PickupManager.h"
35
36#include "core/CoreIncludes.h"
37#include "core/ScopedSingletonManager.h"
38#include "core/Identifier.h"
39#include "interfaces/PickupCarrier.h"
40#include "worldentities/pawns/Pawn.h"
41#include "PickupRepresentation.h"
42
43namespace orxonox
44{
45
46    ManageScopedSingleton(PickupManager, ScopeID::Root, false);
47   
48    /**
49    @brief
50        Constructor. Registers the PickupManager and creates the default PickupRepresentation.
51    */
52    PickupManager::PickupManager()
53    {
54        this->defaultRepresentation_ = NULL;
55        this->pickupCarrierStructure_ = NULL;
56        RegisterRootObject(PickupManager);
57       
58        this->defaultRepresentation_ = new PickupRepresentation();
59    }
60   
61    /**
62    @brief
63        Destructor.
64        Destroys the default PickupRepresentation.
65    */
66    PickupManager::~PickupManager()
67    {
68        if(this->defaultRepresentation_ != NULL)
69            this->defaultRepresentation_->destroy();
70       
71        if(this->pickupCarrierStructure_ != NULL)
72            delete this->pickupCarrierStructure_;
73    }
74   
75    /**
76    @brief
77        Registers a PickupRepresentation together with the PickupIdentifier of the Pickupable the PickupRepresentation represents.
78        For every type of Pickupable (uniquely idnetified by a PickupIdentifier) there can be one (and just one) PickupRepresentation registered.
79    @param identifier
80        The PickupIdentifier identifying the Pickupable.
81    @param representation
82        A pointer to the PickupRepresentation.
83    @return
84        Returns true if successful and false if not.
85    */
86    //TODO: Make sure that either the PickupRepresentation is destroyed upon destruction of the PickupManager if the representation wasn't created with XMLPort.
87    bool PickupManager::registerRepresentation(const PickupIdentifier* identifier, PickupRepresentation* representation)
88    {
89        if(this->representations_.find(identifier) != this->representations_.end()) //!< If the Pickupable already has a RepresentationRegistered.
90            return false;
91       
92        this->representations_[identifier] = representation;
93       
94        COUT(4) << "PickupRepresentation " << representation << " registered with the PickupManager." << std::endl;
95        return true;
96    }
97   
98    /**
99    @brief
100        Get the PickupRepresentation representing the Pickupable with the input PickupIdentifier.
101    @param identifier
102        The PickupIdentifier.
103    @return
104        Returns a pointer to the PickupRepresentation.
105    */
106    PickupRepresentation* PickupManager::getRepresentation(const PickupIdentifier* identifier)
107    {
108        std::map<const PickupIdentifier*, PickupRepresentation*, PickupIdentifierCompare>::iterator it = this->representations_.find(identifier);
109        if(it == this->representations_.end())
110        {
111            COUT(4) << "PickupManager::getRepresentation() returned default representation." << std::endl;
112            return this->defaultRepresentation_;
113        }
114       
115        return it->second;
116    }
117   
118}
Note: See TracBrowser for help on using the repository browser.