Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/resource/src/core/GameState.h @ 3348

Last change on this file since 3348 was 3280, checked in by rgrieder, 15 years ago

Merged most of the core4 revisions back to the trunk except for:

  • orxonox_cast
  • all the radical changes in the input library
  • 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 *      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        Helper class to group construction parameters for better genericity.
48    */
49    struct GameStateConstrParams
50    {
51        std::string name;
52        bool bIgnoreTickTime;
53    };
54
55    /**
56    @brief
57        An implementation of a tree to manage game states.
58        This leads to a certain hierarchy that is created at runtime.
59        To actually use the structure, you will have to derive from it and
60        implement 'enter', 'leave' and 'tick'. The latter corresponds to an
61        update function.
62
63        Internally the tree is managed by two maps per node: One stores all its
64        children, grandchildren, etc. by name of the state. The other maps these
65        children states to the actual child of the node.
66        An example: Foo is a grandchildren of Bar and Foofoo is the Foo's parent.
67        Then Bar stores Foo in map by its name. The other one then maps Foo to Foofoo.
68    */
69    class _CoreExport GameState
70    {
71        friend class Game;
72
73    public:
74        /**
75        @brief
76            Gives information about what the GameState is currently doing
77        */
78        struct State
79        {
80            unsigned active       : 1;
81            unsigned activating   : 1;
82            unsigned deactivating : 1;
83            unsigned updating     : 1;
84            unsigned suspended    : 1;
85            unsigned topState     : 1;
86        };
87
88    public:
89        GameState(const GameStateConstrParams& params);
90        virtual ~GameState();
91
92        const std::string& getName() const { return name_; }
93        State getActivity()          const { return this->activity_; }
94        GameState* getParent()       const { return this->parent_; }
95
96        bool ignoreTickTime()        const { return this->bIgnoreTickTime_; }
97
98        void addChild(GameState* state);
99        void removeChild(GameState* state);
100
101    protected:
102        virtual void activate() { }
103        virtual void deactivate() { }
104        virtual void update(const Clock& time) { }
105
106    private:
107        void setParent(GameState* state) { this->parent_ = state; }
108        void setActivity(State activity);
109        void activateInternal();
110        void deactivateInternal();
111        void updateInternal(const Clock& time);
112
113        const std::string                        name_;
114        State                                    activity_;
115        const bool                               bIgnoreTickTime_;
116        GameState*                               parent_;
117        std::map<std::string, GameState*>        children_;
118    };
119}
120
121#endif /* _GameState_H__ */
Note: See TracBrowser for help on using the repository browser.