entity
Entity/Component System for C++
destruction_queue.hpp
Go to the documentation of this file.
1
// ****************************************************************************
2
// entity/component/destruction_queue.h
3
//
4
// Represents a way to queue component destruction in order to
5
// reduce creation complexity from O(m*nlog(n)) to O(m+n)
6
//
7
// Copyright Chris Glover 2014-2015
8
//
9
// Distributed under the Boost Software License, Version 1.0.
10
// See accompanying file LICENSE_1_0.txt or copy at
11
// http://www.boost.org/LICENSE_1_0.txt
12
//
13
// ****************************************************************************
14
#ifndef _ENTITY_COMPONENT_DESTRUCTIONQUEUE_H_INCLUDED_
15
#define _ENTITY_COMPONENT_DESTRUCTIONQUEUE_H_INCLUDED_
16
17
#include <algorithm>
18
#include <functional>
19
#include <vector>
20
21
#include "entity/config.hpp"
// IWYU pragma: keep
22
#include "
entity/entity.hpp
"
23
24
// ----------------------------------------------------------------------------
25
//
26
namespace
entity
{
namespace
component
27
{
28
template
<
typename
ComponentPool>
29
class
destruction_queue
30
{
31
public
:
32
33
typedef
typename
ComponentPool::type
type
;
34
35
destruction_queue
(ComponentPool& p)
36
: pool_(p)
37
{}
38
39
~destruction_queue
()
40
{
41
flush
();
42
}
43
44
void
push
(
weak_entity
e)
45
{
46
destroyed_.push_back(e);
47
}
48
49
void
flush
()
50
{
51
std::sort(destroyed_.begin(), destroyed_.end(), std::greater<weak_entity>());
52
pool_.destroy_range(destroyed_.begin(), destroyed_.end());
53
clear
();
54
}
55
56
void
clear
()
57
{
58
destroyed_.clear();
59
}
60
61
private
:
62
63
// No copying.
64
destruction_queue
(
destruction_queue
const
&);
65
destruction_queue
operator=(
destruction_queue
);
66
67
std::vector<weak_entity> destroyed_;
68
ComponentPool& pool_;
69
};
70
} }
// namespace entity { namespace component {
71
72
#endif // _ENTITY_COMPONENT_DESTRUCTIONQUEUE_H_INCLUDED_
entity::component::destruction_queue::clear
void clear()
Definition:
destruction_queue.hpp:56
entity::component::destruction_queue::flush
void flush()
Definition:
destruction_queue.hpp:49
entity::component::destruction_queue::destruction_queue
destruction_queue(ComponentPool &p)
Definition:
destruction_queue.hpp:35
entity
Definition:
for_each.hpp:32
entity::component::destruction_queue
Definition:
dense_pool.hpp:50
entity::weak_entity
Definition:
entity.hpp:188
entity.hpp
entity::component::destruction_queue::type
ComponentPool::type type
Definition:
destruction_queue.hpp:33
entity::component::destruction_queue::push
void push(weak_entity e)
Definition:
destruction_queue.hpp:44
entity::component::destruction_queue::~destruction_queue
~destruction_queue()
Definition:
destruction_queue.hpp:39
entity
component
destruction_queue.hpp
Generated by
1.8.9.1