-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmanager.hpp
More file actions
67 lines (53 loc) · 2.29 KB
/
Copy pathmanager.hpp
File metadata and controls
67 lines (53 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/* File: /lib/ecs/manager.hpp
*
* This file is a part of cpplib project which is distributed under MIT License.
* See file LICENSE for full license details.
*
* Copyright (c) 2020-present Nikita Zuev (V.Slavski!) <[email protected]>
*/
#ifndef CPPLIB__lib__ecs__manager__hpp
#define CPPLIB__lib__ecs__manager__hpp
#include <map>
#include <cpp/lib_algorithm>
#include "../../lib/tl/noncopyable.hpp"
#include "../../lib/tl/listener.hpp"
#include "../../lib/cstring.hpp"
#include "../../lib/ptr.hpp"
#include "../../lib/ref.hpp"
#include "./entity.hpp"
namespace lib::ecs {
// DECLARATION lib::ecs::Manager<>
template< class Component >
class Manager final
: tl::noncopymovable< Manager<Component> >
{
public:
using EntityType = Entity< Component >;
using EntityPtr = SPtr< EntityType >;
using EntityList = ::std::map< typename EntityType::Id, EntityPtr >;
using ComponentPtr = Component *;
using ComponentMeta = Ref< EntityType >;
using ComponentList = ::std::map< ComponentMeta, Ptr<Component>, ::cpp::ref_less<ComponentMeta> >;
constexpr Manager() noexcept;
constexpr ~Manager() noexcept;
constexpr const EntityList & get_entities() const noexcept;
constexpr const ComponentList & get_components( typename Component::Type type ) const noexcept;
constexpr void reset() noexcept;
constexpr EntityPtr add( typename EntityType::Id id = EntityType::INVALID_ID ) noexcept;
constexpr bool remove( typename EntityType::Id id ) noexcept;
constexpr bool remove( SPtr<EntityType> & entity ) noexcept;
constexpr EntityPtr get( typename EntityType::Id id ) const noexcept;
constexpr ComponentPtr add( EntityType & entity, typename Component::Type type ) noexcept;
constexpr ComponentPtr add( EntityType & entity, const cstring & name ) noexcept;
constexpr bool remove( EntityType & entity, typename Component::Type type ) noexcept;
constexpr bool remove( EntityType & entity, const cstring & name ) noexcept;
tl::listener<void, EntityType & > on_entity_added;
tl::listener<void, EntityType & > on_entity_removed;
tl::listener<void, EntityType &, Component & > on_component_added;
tl::listener<void, EntityType &, Component & > on_component_removed;
private:
::std::map< typename Component::Type, ComponentList > components;
EntityList entities;
};
} // namespace lib::ecs
#endif // CPPLIB__lib__ecs__manager__hpp