Directory: | source/ |
---|---|
File: | source/world_constructor.c |
Date: | 2023-12-18 09:27:49 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 32 | 35 | 91.4% |
Branches: | 11 | 14 | 78.6% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | * Filename: world_constructor.c | ||
3 | * Path: source | ||
4 | * Created Date: Monday, January 2nd 2023, 2:38:37 pm | ||
5 | * Author: osvegn | ||
6 | * | ||
7 | * Copyright (c) 2023 ECS | ||
8 | */ | ||
9 | |||
10 | #include "world.h" | ||
11 | #include "world_logger.h" | ||
12 | |||
13 | 39 | int world_constructor(world_t *world, FILE *log_file) | |
14 | { | ||
15 | 39 | int rvalue = 0; | |
16 | |||
17 | 39 | rvalue = vector_constructor(&world->resource_list, sizeof(resource_t), 0); | |
18 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 39 times.
|
39 | if (rvalue < 0) |
19 | ✗ | return -1; | |
20 | 39 | rvalue = vector_constructor(&world->entity_list, sizeof(entity_t), 0); | |
21 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 39 times.
|
39 | if (rvalue < 0) |
22 | ✗ | return -1; | |
23 | 39 | rvalue = vector_constructor(&world->system_list, sizeof(system_t), 0); | |
24 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 39 times.
|
39 | if (rvalue < 0) { |
25 | ✗ | return -1; | |
26 | } | ||
27 | 39 | world_log_init(log_file); | |
28 | 39 | log_info("World created"); | |
29 | 39 | return 0; | |
30 | } | ||
31 | |||
32 | 12 | void world_destructor(world_t *world) | |
33 | { | ||
34 | 12 | entity_t *entity = 0; | |
35 | 12 | resource_t *resource = 0; | |
36 | |||
37 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 2 taken 12 times.
|
14 | while (world->entity_list.size(&world->entity_list)) { |
38 | 2 | entity = world->entity_list.back(&world->entity_list); | |
39 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2 times.
|
4 | while (entity->components.size(&entity->components)) { |
40 | 2 | component_destructor(entity->components.back(&entity->components)); | |
41 | 2 | entity->components.pop_back(&entity->components); | |
42 | } | ||
43 | 2 | entity->components.destructor(&entity->components); | |
44 | 2 | world->entity_list.pop_back(&world->entity_list); | |
45 | } | ||
46 | 12 | world->entity_list.destructor(&world->entity_list); | |
47 | 12 | world->system_list.destructor(&world->system_list); | |
48 |
2/2✓ Branch 1 taken 4 times.
✓ Branch 2 taken 12 times.
|
16 | while (world->resource_list.size(&world->resource_list)) { |
49 | 4 | resource = world->resource_list.back(&world->resource_list); | |
50 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3 times.
|
4 | if (resource->destructor) |
51 | 1 | resource->destructor(resource); | |
52 | 4 | world->resource_list.pop_back(&world->resource_list); | |
53 | } | ||
54 | 12 | world->resource_list.destructor(&world->resource_list); | |
55 | 12 | log_info("World destroyed"); | |
56 | 12 | world_log_destroy(); | |
57 | 12 | } | |
58 |