GCC Code Coverage Report


Directory: ./
File: lib/ecs/src/EntityManager.cpp
Date: 2025-09-29 13:19:55
Exec Total Coverage
Lines: 21 29 72.4%
Functions: 5 6 83.3%
Branches: 16 32 50.0%

Line Branch Exec Source
1 #include "ECS/EntityManager.hpp"
2 #include <algorithm>
3
4 namespace ECS {
5
1/2
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 EntityManager::EntityManager() : m_nextEntityID(1) {
6 // Reserve space for better performance
7
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
6 m_aliveEntities.reserve(1000);
8 6 }
9
10 8 EntityID EntityManager::CreateEntity() {
11 EntityID entityID;
12
13
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
8 if (!m_freeEntities.empty()) {
14 entityID = m_freeEntities.front();
15 m_freeEntities.pop();
16 } else {
17 8 entityID = m_nextEntityID++;
18 }
19
20 // Ensure the alive entities vector is large enough
21
1/2
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
8 if (entityID >= m_aliveEntities.size()) {
22 8 m_aliveEntities.resize(entityID + 1, false);
23 }
24
25
1/2
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
8 m_aliveEntities[entityID] = true;
26 8 return entityID;
27 }
28
29 1 void EntityManager::DestroyEntity(EntityID entity) {
30
5/10
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 1 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
1 if (entity != INVALID_ENTITY && entity < m_aliveEntities.size() && m_aliveEntities[entity]) {
31
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 m_aliveEntities[entity] = false;
32 1 m_freeEntities.push(entity);
33 }
34 1 }
35
36 3 bool EntityManager::IsEntityAlive(EntityID entity) const {
37
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 return entity != INVALID_ENTITY &&
38
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
6 entity < m_aliveEntities.size() &&
39
2/2
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 1 times.
6 m_aliveEntities[entity];
40 }
41
42 void EntityManager::Clear() {
43 m_aliveEntities.clear();
44 std::queue<EntityID> empty;
45 m_freeEntities.swap(empty);
46 m_nextEntityID = 1;
47 }
48
49 1 size_t EntityManager::GetAliveEntityCount() const {
50
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 return std::count(m_aliveEntities.begin(), m_aliveEntities.end(), true);
51 }
52 }
53