Line data Source code
1 : /*
2 : * Copyright (C) 2025 aeml
3 : *
4 : * This program is free software: you can redistribute it and/or modify
5 : * it under the terms of the GNU General Public License as published by
6 : * the Free Software Foundation, either version 3 of the License, or
7 : * (at your option) any later version.
8 : *
9 : * This program is distributed in the hope that it will be useful,
10 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 : * GNU General Public License for more details.
13 : *
14 : * You should have received a copy of the GNU General Public License
15 : * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 : */
17 :
18 : #include "ecs/World.hpp"
19 : #include <algorithm>
20 :
21 : namespace ecs
22 : {
23 3926 : EntityId World::CreateEntity()
24 : {
25 3926 : const EntityId id = m_nextEntity++;
26 3926 : m_entities.push_back(id);
27 3926 : return id;
28 : }
29 :
30 2 : void World::DestroyEntity(EntityId id)
31 : {
32 4 : m_entities.erase(
33 2 : std::remove(m_entities.begin(), m_entities.end(), id),
34 2 : m_entities.end());
35 :
36 4 : for (auto& [typeKey, storage] : m_componentStores)
37 : {
38 : (void)typeKey;
39 2 : if (storage)
40 : {
41 2 : storage->RemoveEntity(id);
42 : }
43 : }
44 2 : }
45 :
46 69 : void World::AddSystem(std::unique_ptr<ISystem> system)
47 : {
48 69 : if (system)
49 : {
50 68 : m_systems.emplace_back(std::move(system));
51 : }
52 69 : }
53 :
54 2496 : void World::Update(float dt)
55 : {
56 6093 : for (auto& system : m_systems)
57 : {
58 3598 : system->Update(*this, dt);
59 : }
60 2495 : }
61 : }
|