Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/modules/pickup/PickupManager.cc @ 6540

Last change on this file since 6540 was 6540, checked in by dafrick, 14 years ago

Removed some TODO's. Finished up documenting pickup module.

File size: 3.7 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 PickupManager.cc
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() : defaultRepresentation_(NULL)
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   
70    /**
71    @brief
72        Registers a PickupRepresentation together with the PickupIdentifier of the Pickupable the PickupRepresentation represents.
73        For every type of Pickupable (uniquely idnetified by a PickupIdentifier) there can be one (and just one) PickupRepresentation registered.
74    @param identifier
75        The PickupIdentifier identifying the Pickupable.
76    @param representation
77        A pointer to the PickupRepresentation.
78    @return
79        Returns true if successful and false if not.
80    */
81    bool PickupManager::registerRepresentation(const PickupIdentifier* identifier, PickupRepresentation* representation)
82    {
83        if(this->representations_.find(identifier) != this->representations_.end()) //!< If the Pickupable already has a RepresentationRegistered.
84            return false;
85       
86        this->representations_[identifier] = representation;
87       
88        COUT(4) << "PickupRepresentation " << representation << " registered with the PickupManager." << std::endl;
89        return true;
90    }
91   
92    /**
93    @brief
94        Get the PickupRepresentation representing the Pickupable with the input PickupIdentifier.
95    @param identifier
96        The PickupIdentifier.
97    @return
98        Returns a pointer to the PickupRepresentation.
99    */
100    PickupRepresentation* PickupManager::getRepresentation(const PickupIdentifier* identifier)
101    {
102        std::map<const PickupIdentifier*, PickupRepresentation*, PickupIdentifierCompare>::iterator it = this->representations_.find(identifier);
103        if(it == this->representations_.end())
104        {
105            COUT(4) << "PickupManager::getRepresentation() returned default representation." << std::endl;
106            return this->defaultRepresentation_;
107        }
108       
109        return it->second;
110    }
111   
112}
Note: See TracBrowser for help on using the repository browser.