Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/pickup3/src/modules/pickup/PickupManager.cc @ 6475

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

Additional documentation, code niceifying and potential bug fixing. Also: Renamed DroppedItem to DroppedPickup.

File size: 3.9 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        RegisterRootObject(PickupManager);
55       
56        this->defaultRepresentation_ = new PickupRepresentation();
57    }
58   
59    /**
60    @brief
61        Destructor.
62        Destroys the default PickupRepresentation.
63    */
64    PickupManager::~PickupManager()
65    {
66        if(this->defaultRepresentation_ != NULL)
67            this->defaultRepresentation_->destroy();
68       
69        if(this->pickupCarrierStructure_ != NULL)
70            delete this->pickupCarrierStructure_;
71    }
72   
73    /**
74    @brief
75        Registers a PickupRepresentation together with the PickupIdentifier of the Pickupable the PickupRepresentation represents.
76        For every type of Pickupable (uniquely idnetified by a PickupIdentifier) there can be one (and just one) PickupRepresentation registered.
77    @param identifier
78        The PickupIdentifier identifying the Pickupable.
79    @param representation
80        A pointer to the PickupRepresentation.
81    @return
82        Returns true if successful and false if not.
83    */
84    //TODO: Make sure that either the PickupRepresentation is destroyed upon destruction of the PickupManager if the representation wasn't created with XMLPort.
85    bool PickupManager::registerRepresentation(const PickupIdentifier* identifier, PickupRepresentation* representation)
86    {
87        if(this->representations_.find(identifier) == this->representations_.end()) //!< If the Pickupable already has a RepresentationRegistered.
88            return false;
89       
90        this->representations_[identifier] = representation;
91       
92        COUT(4) << "PickupRepresentation " << representation << " registered with the PickupManager." << std::endl;
93        return true;
94    }
95   
96    /**
97    @brief
98        Get the PickupRepresentation representing the Pickupable with the input PickupIdentifier.
99    @param identifier
100        The PickupIdentifier.
101    @return
102        Returns a pointer to the PickupRepresentation.
103    */
104    PickupRepresentation* PickupManager::getRepresentation(const PickupIdentifier* identifier)
105    {
106        std::map<const PickupIdentifier*, PickupRepresentation*, PickupIdentifierCompare>::iterator it = this->representations_.find(identifier);
107        if(it == this->representations_.end())
108        {
109            COUT(4) << "PickupManager::getRepresentation() returned default representation." << std::endl;
110            return this->defaultRepresentation_;
111        }
112       
113        return it->second;
114    }
115   
116}
Note: See TracBrowser for help on using the repository browser.