nomlib
Loading...
Searching...
No Matches
IState.hpp
1/******************************************************************************
2
3 nomlib - C++11 cross-platform game engine
4
5Copyright (c) 2013, 2014 Jeffrey Carpenter <i8degrees@gmail.com>
6All rights reserved.
7
8Redistribution and use in source and binary forms, with or without
9modification, are permitted provided that the following conditions are met:
10
111. Redistributions of source code must retain the above copyright notice, this
12 list of conditions and the following disclaimer.
132. Redistributions in binary form must reproduce the above copyright notice,
14 this list of conditions and the following disclaimer in the documentation
15 and/or other materials provided with the distribution.
16
17THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28******************************************************************************/
29#ifndef NOMLIB_SYSTEM_ISTATE_HPP
30#define NOMLIB_SYSTEM_ISTATE_HPP
31
32#include "export.hpp"
33#include "nomlib/config.hpp"
34
35#include <string>
36
37namespace nom {
38
40enum : uint32 { NO_STATE = 0 };
41
43using StateSymbol = uint32;
44using EventSymbol = uint32;
45
46// Forward declarations
47class RenderWindow;
48struct Event;
49
53class NOM_EXPORT IState
54{
55 public:
56 typedef std::unique_ptr<IState> unique_ptr;
57
61 enum Flags
62 {
67 BackUpdate = OpaqueUpdate,
68
73 BackRender = OpaqueRender
74 };
75
79 enum Type
80 {
82 Parent = 0,
83 Child
84 };
85
87 IState( void );
88
90 virtual ~IState( void );
91
96 IState( uint32 id );
97
105 IState( uint32 id, uint32 flags, IState::Type type );
106
112 uint32 id ( void ) const;
113
121 virtual StateSymbol symbol() const;
122
128 uint32 timestamp ( void ) const;
129
135 uint32 flags ( void ) const;
136
140 IState::Type type( void ) const;
141
146
158 virtual std::string input_context() const;
159
170 virtual bool on_event(const nom::Event& ev);
171
177 virtual void on_update ( float );
178
187 virtual void on_draw ( RenderWindow& );
188
194 virtual void on_init ( void_ptr );
195
201 virtual void on_exit ( void_ptr );
202
208 virtual void on_pause ( void_ptr );
209
216 virtual void on_resume ( void_ptr );
217
218 private:
220 uint32 id_;
221
224
226 uint32 flags_;
227
230};
231
232} // namespace nom
233
234#endif // include guard defined
Type
State type enumeration.
Definition IState.hpp:80
@ Parent
Top-level / top-most placement on the stack.
Definition IState.hpp:82
Type type_
The type of state.
Definition IState.hpp:229
virtual void on_init(void_ptr)
User-defined implementation of the state's initialization logic.
uint32 id(void) const
Obtain the user-defined identifier of the state.
void set_type(IState::Type type)
Set the type of state.
uint32 id_
Unique identifier for the state.
Definition IState.hpp:220
virtual void on_draw(RenderWindow &)
virtual std::string input_context() const
The nom::InputStateMapper context key associated with this state.
uint32 timestamp(void) const
Obtain the recorded time stamp of the state.
virtual void on_resume(void_ptr)
User-defined implementation of the state's resume from pause state logic.
virtual bool on_event(const nom::Event &ev)
User-defined implementation of the state's event handling logic.
uint32 timestamp_
Number of ticks recorded at the time of state's construction.
Definition IState.hpp:223
uint32 flags_
Specialized state management.
Definition IState.hpp:226
IState(void)
Default constructor; initializes class variables to zero.
virtual void on_pause(void_ptr)
User-defined implementation of the state's paused state logic.
IState(uint32 id)
Constructor for user-defined initialization of the class variable fields.
Flags
Specialized control over state management.
Definition IState.hpp:62
uint32 flags(void) const
Obtain the user-defined flags of the state.
IState(uint32 id, uint32 flags, IState::Type type)
Constructor for user-defined initialization of the class variable fields.
IState::Type type(void) const
Get the type of state.
virtual void on_exit(void_ptr)
User-defined implementation of the state's destruction logic.
virtual ~IState(void)
Destructor; declared virtual for inheritance.
virtual void on_update(float)
User-defined implementation of the state's update logic.
virtual StateSymbol symbol() const
Obtain the stack symbol for this state.
Event handling types.
Definition Event.hpp:458