Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/core/GameState.h @ 3255

Last change on this file since 3255 was 3196, checked in by rgrieder, 15 years ago

Merged pch branch back to trunk.

  • Property svn:eol-style set to native
File size: 3.4 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 *      Reto Grieder
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29/**
30@file
31@brief
32    Definition of GameState class.
33*/
34
35#ifndef _GameState_H__
36#define _GameState_H__
37
38#include "CorePrereqs.h"
39
40#include <map>
41#include <string>
42
43namespace orxonox
44{
45    /**
46    @brief
47        An implementation of a tree to manage game states.
48        This leads to a certain hierarchy that is created at runtime.
49        To actually use the structure, you will have to derive from it and
50        implement 'enter', 'leave' and 'tick'. The latter corresponds to an
51        update function.
52
53        Internally the tree is managed by two maps per node: One stores all its
54        children, grandchildren, etc. by name of the state. The other maps these
55        children states to the actual child of the node.
56        An example: Foo is a grandchildren of Bar and Foofoo is the Foo's parent.
57        Then Bar stores Foo in map by its name. The other one then maps Foo to Foofoo.
58    */
59    class _CoreExport GameState
60    {
61        friend class Game;
62
63    public:
64        /**
65        @brief
66            Gives information about what the GameState is currently doing
67        */
68        struct State
69        {
70            unsigned active       : 1;
71            unsigned activating   : 1;
72            unsigned deactivating : 1;
73            unsigned updating     : 1;
74            unsigned suspended    : 1;
75            unsigned topState     : 1;
76        };
77
78    public:
79        GameState(const std::string& name, bool countTicktime = true);
80        virtual ~GameState();
81
82        const std::string& getName() const { return name_; }
83        State getActivity()          const { return this->activity_; }
84        GameState* getParent()       const { return this->parent_; }
85
86        bool getCountTickTime()      const { return this->bCountTickTime_; }
87
88        void addChild(GameState* state);
89        void removeChild(GameState* state);
90
91    protected:
92        virtual void activate() = 0;
93        virtual void deactivate() = 0;
94        virtual void update(const Clock& time) = 0;
95
96    private:
97        void setParent(GameState* state) { this->parent_ = state; }
98        void setActivity(State activity);
99        void activateInternal();
100        void deactivateInternal();
101        void updateInternal(const Clock& time);
102
103        const std::string                        name_;
104        State                                    activity_;
105        const bool                               bCountTickTime_;
106        GameState*                               parent_;
107        std::map<std::string, GameState*>        children_;
108    };
109}
110
111#endif /* _GameState_H__ */
Note: See TracBrowser for help on using the repository browser.