nomlib
Loading...
Searching...
No Matches
ActionPlayer.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_ACTIONS_ACTION_PLAYER_HPP
30#define NOMLIB_ACTIONS_ACTION_PLAYER_HPP
31
32#include <memory>
33#include <functional>
34#include <vector>
35#include <map>
36#include <deque>
37
38#include "export.hpp"
39#include "nomlib/config.hpp"
40
41namespace nom {
42
43// Forward declarations
44class IActionObject;
45class DispatchQueue;
46
47typedef std::function<void()> action_callback_func;
48
50class NOM_EXPORT ActionPlayer
51{
52 public:
53 typedef ActionPlayer self_type;
54
56 typedef std::vector<const char*> action_names;
57
59 enum State
60 {
61 RUNNING = 0,
62 PAUSED,
63 STOPPED,
64 };
65
67
69
71 ActionPlayer(const ActionPlayer& rhs) = delete;
72
74 ActionPlayer& operator =(const ActionPlayer& rhs) = delete;
75
81 bool idle() const;
82
84 nom::size_type num_actions() const;
85
90
97 void pause();
98
104 void resume();
105
113 void stop();
114
123 bool action_running(const std::string& action_id) const;
124
130 bool cancel_action(const std::string& action_id);
131
132 void cancel_actions(const action_names& actions);
133
138
147 bool run_action(const std::shared_ptr<IActionObject>& action);
148
160 bool run_action( const std::shared_ptr<IActionObject>& action,
161 const action_callback_func& completion_func );
162
173 bool update(real32 delta_time);
174
175 private:
198 bool run_action( const std::shared_ptr<IActionObject>& action,
199 std::unique_ptr<DispatchQueue> dispatch_queue,
200 const action_callback_func& completion_func );
201
202 static const char* DEBUG_CLASS_NAME;
203
204 typedef
205 std::map<std::string, std::unique_ptr<DispatchQueue>> container_type;
206
207 typedef container_type::iterator container_iterator;
208
209 ActionPlayer::State player_state_;
210
212 container_type actions_;
213
215 std::deque<container_iterator> free_list_;
216};
217
218} // namespace nom
219
220#endif // include guard defined
221
Interface for running and controlling action flow.
State
The status of the player.
bool idle() const
Get the status of the action queue.
bool run_action(const std::shared_ptr< IActionObject > &action)
Enqueue an action.
bool action_running(const std::string &action_id) const
Get the completion status of an action.
void stop()
Reset the enqueued actions back to its initial starting state.
void resume()
Resume the advancement of time for the enqueued actions.
bool run_action(const std::shared_ptr< IActionObject > &action, const action_callback_func &completion_func)
Enqueue an action with a completion callback.
nom::size_type num_actions() const
Get the number of actions enqueued.
ActionPlayer::State player_state() const
Get the control status of the queue.
void cancel_actions()
Stop executing the enqueued actions.
std::deque< container_iterator > free_list_
The actions pending removal.
bool cancel_action(const std::string &action_id)
Stop executing an action.
std::vector< const char * > action_names
bool update(real32 delta_time)
Run the enqueued actions' update loop.
container_type actions_
Enqueued actions.
bool run_action(const std::shared_ptr< IActionObject > &action, std::unique_ptr< DispatchQueue > dispatch_queue, const action_callback_func &completion_func)
Enqueue an action that runs on a specific dispatch queue.
void pause()
Freeze the enqueued actions from advancing forward in time.
ActionPlayer(const ActionPlayer &rhs)=delete
Disabled copy constructor.
The internal processing queue for actions.
Pure virtual base class interface for actions.