Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core3/src/core/ObjectList.h @ 1591

Last change on this file since 1591 was 1591, checked in by landauf, 16 years ago

Again some heavy changes in ObjectList and Iterator:
there are now two types of iterators:

Iterator<ClassName> can iterate through any objectlist, either given by ObjectList<AnyClassName>::begin() or anyidentifier→getObjects()→begin(). Important note Iterator<ClassName> uses dynamic_cast.
And yes, it's possible to do this: Iterator<WorldEntity> it = ObjectList<SpaceShip>::begin()

ObjectList<ClassName>::iterator is the second iterator - it uses the ObjectList in a templated manner and therefore doesn't need dynamic_cast. But the only thing you can do is iterating through exactly the right ObjectList: ObjectList<ClassName>::iterator it = ObjectList<ClassName>::begin(). Anything else fails.

Those changes bring, at my system, something around +12% FPS compared with trunk and +25% FPS compared with the last revision of core3. Although I have to admit the FPS gain is only that high because iterating through objects is the main thing we're doing ingame right now. It would look totally different with physics, sound, AI, scripts, triggers and so on.

  • Property svn:eol-style set to native
File size: 2.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 *      Fabian 'x3n' Landau
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29/**
30    @file ObjectList.h
31    @brief Definition and implementation of the ObjectList class.
32
33    The ObjectList is a wrapper of an ObjectListBase of a given class.
34    Use Iterator<class> to iterate through all objects of the class.
35*/
36
37#ifndef _ObjectList_H__
38#define _ObjectList_H__
39
40#include "CorePrereqs.h"
41
42#include "Identifier.h"
43#include "ObjectListIterator.h"
44
45namespace orxonox
46{
47    // ###############################
48    // ###       ObjectList        ###
49    // ###############################
50    //! The ObjectList contains all objects of the given class.
51    /**
52        Wraps the ObjectListBase of the corresponding Identifier.
53        Use ObjectListIterator<class> to iterate through all objects in the list.
54    */
55    template <class T>
56    class ObjectList
57    {
58        public:
59            typedef ObjectListIterator<T> iterator;
60
61            /** @brief Returns an Iterator to the first element in the list. @return The Iterator */
62            inline static ObjectListElement<T>* begin()
63                { return ((ObjectListElement<T>*)ClassIdentifier<T>::getIdentifier()->getObjects()->begin().element_); }
64
65            /** @brief Returns an Iterator to the element after the last element in the list. @return The Iterator */
66            inline static ObjectListElement<T>* end()
67                { return ((ObjectListElement<T>*)ClassIdentifier<T>::getIdentifier()->getObjects()->end().element_); }
68
69            /** @brief Returns an Iterator to the last element in the list. @return The Iterator */
70            inline static ObjectListElement<T>* rbegin()
71                { return ((ObjectListElement<T>*)ClassIdentifier<T>::getIdentifier()->getObjects()->rbegin().element_); }
72
73            /** @brief Returns an Iterator to the element before the first element in the list. @return The Iterator */
74            inline static ObjectListElement<T>* rend()
75                { return ((ObjectListElement<T>*)ClassIdentifier<T>::getIdentifier()->getObjects()->rend().element_); }
76    };
77}
78
79#endif /* _ObjectList_H__ */
Note: See TracBrowser for help on using the repository browser.