neoGFX
Cross-platform C++ app/game engine
entity.hpp
Go to the documentation of this file.
1 // entity.hpp
2 /*
3  neogfx C++ GUI Library
4  Copyright (c) 2018 Leigh Johnston. All Rights Reserved.
5 
6  This program is free software: you can redistribute it and / or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 #pragma once
20 
21 #include <neogfx/neogfx.hpp>
22 #include <neogfx/core/event.hpp>
23 #include <neogfx/game/i_ecs.hpp>
24 
25 namespace neogfx::game
26 {
27  class entity
28  {
29  public:
30  entity(i_ecs& aEcs, entity_id aId);
31  entity(i_ecs& aEcs, const entity_archetype_id& aArchetypeId);
32  template <typename... ComponentData>
33  entity(i_ecs& aEcs, const entity_archetype_id& aArchetypeId, ComponentData&&... aComponentData) :
34  entity{ aEcs, aEcs.create_entity(aArchetypeId, aComponentData...) } {}
35  ~entity();
36  public:
37  entity(const entity& aOther) = delete;
38  entity& operator=(const entity& aOther) = delete;
39  public:
40  i_ecs& ecs() const;
41  entity_id id() const;
42  bool detached_or_destroyed() const;
43  entity_id detach();
44  private:
45  i_ecs& iEcs;
46  entity_id iId;
47  sink iSink;
48  };
49 }
entity(i_ecs &aEcs, const entity_archetype_id &aArchetypeId, ComponentData &&... aComponentData)
Definition: entity.hpp:33
bool detached_or_destroyed() const
entity_id id() const
entity(i_ecs &aEcs, entity_id aId)
id_t entity_id
Definition: ecs_ids.hpp:34
entity & operator=(const entity &aOther)=delete
i_ecs & ecs() const
virtual entity_id create_entity(const entity_archetype_id &aArchetypeId)=0