GCC Code Coverage Report


Directory: ./
File: submodules/ECS/source/world_system.c
Date: 2023-09-29 04:53:15
Exec Total Coverage
Lines: 0 41 0.0%
Branches: 0 22 0.0%

Line Branch Exec Source
1 /*
2 * Filename: /workspaces/our_rpg/lib/ECS/source/world_system.c
3 * Path: /workspaces/our_rpg/lib/ECS/source
4 * Created Date: Sunday, January 15th 2023, 3:59:16 pm
5 * Author: osvegn
6 *
7 * Copyright (c) 2023 our_rpg
8 */
9
10 #include "world.h"
11
12 /// @brief It finds the index of a system in a list of systems
13 /// @param system_list The list of systems to search through.
14 /// @param system The system to find.
15 /// @return The index of the system in the system_list vector, or list size if not found.
16 static unsigned int find_system(vector_t *system_list, system_t *system)
17 {
18 for (unsigned int i = 0; i < system_list->size(system_list); i++) {
19 if (system->type == (*(system_t *)(system_list->at(system_list, i))).type)
20 return i;
21 }
22 return system_list->size(system_list);
23 }
24
25 static unsigned int find_system_by_type(vector_t *system_list, unsigned int type)
26 {
27 for (unsigned int i = 0; i < system_list->size(system_list); i++) {
28 if (type == (*(system_t *)(system_list->at(system_list, i))).type) {
29 return i;
30 }
31 }
32 return system_list->size(system_list);
33 }
34
35 int world_add_system(world_t *world, system_t *system)
36 {
37 unsigned int index = find_system(&world->system_list, system);
38
39 if (index < world->system_list.size(&world->system_list)) {
40 return -1;
41 }
42 world->system_list.emplace_back(&world->system_list, system);
43 return 0;
44 }
45
46 int world_remove_system(world_t *world, system_t *system)
47 {
48 unsigned int index = find_system(&world->system_list, system);
49
50 if (index < world->system_list.size(&world->system_list)) {
51 world->system_list.erase(&world->system_list, index);
52 return 0;
53 }
54 return -1;
55 }
56
57 int world_remove_system_by_type(world_t *world, unsigned int type)
58 {
59 unsigned int index = find_system_by_type(&world->system_list, type);
60
61 if (index < world->system_list.size(&world->system_list)) {
62 world->system_list.erase(&world->system_list, index);
63 return 0;
64 }
65 return -1;
66 }
67
68 bool world_contains_system(world_t *world, system_t *system)
69 {
70 unsigned int index = find_system(&world->system_list, system);
71
72 if (index < world->system_list.size(&world->system_list)) {
73 return true;
74 }
75 return false;
76 }
77
78 bool world_contains_system_by_type(world_t *world, unsigned int type)
79 {
80 unsigned int index = find_system_by_type(&world->system_list, type);
81
82 if (index < world->system_list.size(&world->system_list)) {
83 return true;
84 }
85 return false;
86 }
87
88 system_t *world_get_system(world_t *world, system_t *system)
89 {
90 unsigned int index = find_system(&world->system_list, system);
91
92 if (index < world->system_list.size(&world->system_list)) {
93 return world->system_list.at(&world->system_list, index);
94 }
95 return 0;
96 }
97
98 system_t *world_get_system_by_type(world_t *world, unsigned int type)
99 {
100 unsigned int index = find_system_by_type(&world->system_list, type);
101
102 if (index < world->system_list.size(&world->system_list)) {
103 return world->system_list.at(&world->system_list, index);
104 }
105 return 0;
106 }
107