nomlib
Loading...
Searching...
No Matches
DispatchQueue.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_DISPATCH_QUEUE_HPP
30#define NOMLIB_ACTIONS_DISPATCH_QUEUE_HPP
31
32#include <memory>
33#include <functional>
34#include <vector>
35
36#include "nomlib/config.hpp"
37#include "nomlib/core/unique_ptr.hpp"
38
39namespace nom {
40
41// Forward declarations
42class IActionObject;
43struct DispatchEnqueue;
44
45typedef std::function<void()> action_callback_func;
46
48class DispatchQueue
49{
50 public:
51 typedef DispatchQueue self_type;
52
54 enum State
55 {
56 IDLING = 0,
57 RUNNING,
58 };
59
61
63
65 nom::size_type num_actions() const;
66
72 bool enqueue_action( const std::shared_ptr<IActionObject>& action,
73 const action_callback_func& completion_func );
74
92 update(uint32 player_state, real32 delta_time);
93
94 private:
95 static const char* DEBUG_CLASS_NAME;
96
97 typedef std::vector<std::unique_ptr<DispatchEnqueue>> container_type;
98 typedef container_type::iterator iterator_type;
99
101 container_type actions_;
102 iterator_type actions_iterator_;
103
105 nom::size_type num_actions_ = 0;
106};
107
113template<typename ObjectType, typename... ObjectArgs>
114std::unique_ptr<ObjectType> create_dispatch_queue(ObjectArgs&&... args)
115{
116 auto dispatch_queue =
117 nom::make_unique<ObjectType>( std::forward<ObjectArgs>(args) ... );
118
119 return std::move(dispatch_queue);
120}
121
122} // namespace nom
123
124#endif // include guard defined
125
The internal processing queue for actions.
nom::size_type num_actions() const
Get the total number of enqueued actions.
nom::size_type num_actions_
The total number of actions enqueued.
State
The status of the queue.
container_type actions_
Enqueued actions.
bool enqueue_action(const std::shared_ptr< IActionObject > &action, const action_callback_func &completion_func)
Append an action to the list of actions to be executed.
std::unique_ptr< ObjectType > create_dispatch_queue(ObjectArgs &&... args)
Constructor function for creating a nom::DispatchQueue.
DispatchQueue::State update(uint32 player_state, real32 delta_time)
Run the enqueued actions' update loop.
Pure virtual base class interface for actions.