Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/presentation2012merge/src/modules/pickup/PickupCollectionIdentifier.cc @ 9314

Last change on this file since 9314 was 9314, checked in by landauf, 12 years ago

probably a bugfix: PickupIdentifier compared only the first parameter in the map.
also some performance enhancements

  • Property svn:eol-style set to native
File size: 3.6 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 *      Damian 'Mozork' Frick
24 *   Co-authors:
25 *      ...
26 *
27*/
28
29/**
30    @file PickupCollectionIdentifier.cc
31    @brief Implementation of PickupCollectionIdentifier.
32*/
33
34#include "core/CoreIncludes.h"
35
36#include "PickupCollectionIdentifier.h"
37#include "PickupCollection.h"
38
39namespace orxonox
40{
41
42    /**
43    @brief
44        Constructor. Registers the object.
45    */
46    PickupCollectionIdentifier::PickupCollectionIdentifier(PickupCollection* collection) : PickupIdentifier(collection)
47    {
48        RegisterObject(PickupCollectionIdentifier);
49
50        this->collection_ = collection;
51    }
52
53    /**
54    @brief
55        Destructor.
56    */
57    PickupCollectionIdentifier::~PickupCollectionIdentifier()
58    {
59
60    }
61
62    /**
63    @brief
64        Compares a PickupCollectionIdentifier with a PickupIdentifier and returns 0 if a == b, <0 if a < b and >0 if a > b for a.compare(b), where a is a PickupCollectionIdentifier and b is just some PickupIdentifier.
65    @param identifier
66        Pointer to the second PickupIdentifier, b.
67    @return
68        Returns an integer. 0 if the two compared PickupIdentifiers are the same, <0 if a < b and >0 if a > b.
69    */
70    int PickupCollectionIdentifier::compare(const PickupIdentifier* identifier) const
71    {
72        assert(identifier);
73
74        const PickupCollectionIdentifier* collectionIdentifier = orxonox_cast<const PickupCollectionIdentifier*>(identifier);
75
76        // If the input PickupIdentifier 'identifier' is no PickupCollectionIdentifier then just the two PickupIdentifiers are compared.
77        if(collectionIdentifier == NULL)
78        {
79            return this->PickupIdentifier::compare(identifier);
80        }
81
82        // If the number of Pickupables each of the two PickupCollectionIdentifiers contain differ, the one with less is considered smaller.
83        if(this->collection_->getPickups().size() != collectionIdentifier->collection_->getPickups().size())
84            return this->collection_->getPickups().size()-collectionIdentifier->collection_->getPickups().size();
85
86        // Compare the Pickupables of the two PickupCollectionIdentifiers one after the other. the one with the first 'smaller' one is considered smaller.
87        std::list<CollectiblePickup*>::const_iterator it1 = this->collection_->getPickups().begin();
88        std::list<CollectiblePickup*>::const_iterator it2 = collectionIdentifier->collection_->getPickups().begin();
89        for( ; it1 != this->collection_->getPickups().end(); ++it1, ++it2)
90        {
91            const PickupIdentifier* id1 = (*it1)->getPickupIdentifier();
92            const PickupIdentifier* id2 = (*it2)->getPickupIdentifier();
93
94            int result = id1->compare(id2);
95            if(result != 0)
96                return result;
97        }
98
99        // This means they are equal.
100        return 0;
101    }
102
103}
104
Note: See TracBrowser for help on using the repository browser.