nomlib
Toggle main menu visibility
Loading...
Searching...
No Matches
include
nomlib
actions
DispatchQueue.hpp
1
/******************************************************************************
2
3
nomlib - C++11 cross-platform game engine
4
5
Copyright (c) 2013, 2014 Jeffrey Carpenter <i8degrees@gmail.com>
6
All rights reserved.
7
8
Redistribution and use in source and binary forms, with or without
9
modification, are permitted provided that the following conditions are met:
10
11
1. Redistributions of source code must retain the above copyright notice, this
12
list of conditions and the following disclaimer.
13
2. 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
17
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24
ON 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
26
SOFTWARE, 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
39
namespace
nom {
40
41
// Forward declarations
42
class
IActionObject
;
43
struct
DispatchEnqueue;
44
45
typedef
std::function<void()> action_callback_func;
46
48
class
DispatchQueue
49
{
50
public
:
51
typedef
DispatchQueue self_type;
52
54
enum
State
55
{
56
IDLING = 0,
57
RUNNING,
58
};
59
60
DispatchQueue
();
61
62
~DispatchQueue
();
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
91
DispatchQueue::State
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
113
template
<
typename
ObjectType,
typename
... ObjectArgs>
114
std::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
nom::DispatchQueue
The internal processing queue for actions.
Definition
DispatchQueue.hpp:49
nom::DispatchQueue::num_actions
nom::size_type num_actions() const
Get the total number of enqueued actions.
nom::DispatchQueue::num_actions_
nom::size_type num_actions_
The total number of actions enqueued.
Definition
DispatchQueue.hpp:105
nom::DispatchQueue::State
State
The status of the queue.
Definition
DispatchQueue.hpp:55
nom::DispatchQueue::actions_
container_type actions_
Enqueued actions.
Definition
DispatchQueue.hpp:101
nom::DispatchQueue::enqueue_action
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.
nom::DispatchQueue::create_dispatch_queue
std::unique_ptr< ObjectType > create_dispatch_queue(ObjectArgs &&... args)
Constructor function for creating a nom::DispatchQueue.
Definition
DispatchQueue.hpp:114
nom::DispatchQueue::update
DispatchQueue::State update(uint32 player_state, real32 delta_time)
Run the enqueued actions' update loop.
nom::IActionObject
Pure virtual base class interface for actions.
Definition
IActionObject.hpp:43
Generated on
for nomlib by
1.18.0