Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/libraries/core/GameState.h @ 5904

Last change on this file since 5904 was 5738, checked in by landauf, 15 years ago

merged libraries2 back to trunk

  • 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 *      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 GameStateInfo& info);
80        virtual ~GameState();
81
82        const std::string& getName()   const;
83        State getActivity()            const { return activity_; }
84        const GameStateInfo& getInfo() const { return info_; }
85
86    protected:
87        virtual void activate() { }
88        virtual void deactivate() { }
89        virtual void update(const Clock& time) { }
90
91    private:
92        void setActivity(State activity);
93        void activateInternal();
94        void deactivateInternal();
95        void updateInternal(const Clock& time);
96
97        const GameStateInfo& info_;
98        State                activity_;
99    };
100}
101
102#endif /* _GameState_H__ */
Note: See TracBrowser for help on using the repository browser.