Line |
Branch |
Exec |
Source |
1 |
|
|
/* |
2 |
|
|
* Filename: source/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 our_rpg |
8 |
|
|
*/ |
9 |
|
|
|
10 |
|
|
#include "world.h" |
11 |
|
|
#include "world_logger.h" |
12 |
|
|
|
13 |
|
✗ |
int world_constructor(world_t *world, FILE *log_file) |
14 |
|
|
{ |
15 |
|
|
int rvalue = 0; |
16 |
|
|
|
17 |
|
✗ |
rvalue = vector_constructor(&world->resource_list, sizeof(resource_t), 0); |
18 |
|
✗ |
if (rvalue < 0) |
19 |
|
|
return -1; |
20 |
|
✗ |
rvalue = vector_constructor(&world->entity_list, sizeof(entity_t), 0); |
21 |
|
✗ |
if (rvalue < 0) |
22 |
|
|
return -1; |
23 |
|
✗ |
rvalue = vector_constructor(&world->system_list, sizeof(system_t), 0); |
24 |
|
✗ |
if (rvalue < 0) { |
25 |
|
|
return -1; |
26 |
|
|
} |
27 |
|
✗ |
world_log_init(log_file); |
28 |
|
✗ |
log_debug("World created"); |
29 |
|
✗ |
return 0; |
30 |
|
|
} |
31 |
|
|
|
32 |
|
✗ |
void world_destructor(world_t *world) |
33 |
|
|
{ |
34 |
|
|
entity_t *entity = 0; |
35 |
|
|
|
36 |
|
✗ |
while (world->entity_list.size(&world->entity_list)) { |
37 |
|
✗ |
entity = world->entity_list.back(&world->entity_list); |
38 |
|
✗ |
while (entity->components.size(&entity->components)) { |
39 |
|
✗ |
component_destructor(entity->components.back(&entity->components)); |
40 |
|
✗ |
entity->components.pop_back(&entity->components); |
41 |
|
|
} |
42 |
|
✗ |
entity->components.destructor(&entity->components); |
43 |
|
✗ |
world->entity_list.pop_back(&world->entity_list); |
44 |
|
|
} |
45 |
|
✗ |
world->entity_list.destructor(&world->entity_list); |
46 |
|
✗ |
world->system_list.destructor(&world->system_list); |
47 |
|
✗ |
while (world->resource_list.size(&world->resource_list)) { |
48 |
|
|
(resource_t *) |
49 |
|
|
{ |
50 |
|
✗ |
world->resource_list.back(&world->resource_list) |
51 |
|
✗ |
} -> destructor(world->resource_list.back(&world->resource_list)); |
52 |
|
✗ |
world->resource_list.pop_back(&world->resource_list); |
53 |
|
|
} |
54 |
|
✗ |
world->resource_list.destructor(&world->resource_list); |
55 |
|
✗ |
world_log_destroy(); |
56 |
|
|
} |
57 |
|
|
|