GCC Code Coverage Report


Directory: ./
File: sources/System/system_world_initializer.c
Date: 2023-09-29 04:53:15
Exec Total Coverage
Lines: 0 26 0.0%
Branches: 0 8 0.0%

Line Branch Exec Source
1 /*
2 * Filename: world_initializer.c
3 * Path: our_rpg\sources\System
4 * Created Date: Sunday, January 22nd 2023, 1:13:50 am
5 * Author: osvegn
6 *
7 * Copyright (c) 2023 our_rpg
8 */
9
10 #include "resources.h"
11 #include "systems.h"
12 #include "world.h"
13 #include "components.h"
14 #include "world_entity.h"
15
16 int system_world_initializer_constructor(system_t *system)
17 {
18 system->type = S_WORLD_INITIALIZER;
19 system->run = &system_world_initializer;
20 system->active = true;
21 return 0;
22 }
23
24 static void entity_initializer(world_t *world)
25 {
26 entity_t e = {0};
27 component_t c = {0};
28
29 entity_constructor(&e);
30 component_displayable_constructor(&c, 0);
31 entity_add_component(&e, &c);
32 component_position_constructor(&c, &(ecs_vector2i_t){.x=100, .y=200});
33 entity_add_component(&e, &c);
34 component_size_constructor(&c, &(ecs_vector2i_t){.x=100, .y=100});
35 entity_add_component(&e, &c);
36 component_controllable_constructor(&c, 0);
37 entity_add_component(&e, &c);
38 component_speed_constructor(&c, &(int){1});
39 entity_add_component(&e, &c);
40 component_velocity_constructor(&c, 0);
41 entity_add_component(&e, &c);
42 world_add_entity(world, &e);
43 }
44
45 static void system_initializer(world_t *world)
46 {
47 system_t system;
48 vector_t *systems = &world->system_list;
49 int (*constructors[])(system_t *) = {
50 &system_load_scene_constructor,
51 0};
52
53 for (unsigned int i = 0; constructors[i]; i++) {
54 constructors[i](&system);
55 systems->emplace_back(systems, &system);
56 }
57 for (unsigned int i = 0; i < systems->size(systems); i++) {
58 if (((system_t *)systems->at(systems, i))->type ==
59 S_WORLD_INITIALIZER) {
60 systems->erase(systems, i);
61 break;
62 }
63 }
64 }
65
66 static void resource_initializer(world_t *world)
67 {
68 resource_t resource;
69 vector_t *resources = &world->resource_list;
70
71 void *data[] = {"config/basic_scene.json", 0};
72 int (*constructors[])(resource_t *,
73 void *) = {
74 &resource_scene_filename_constructor,
75 0};
76 for (unsigned int i = 0; constructors[i]; i++) {
77 constructors[i](&resource, data[i]);
78 resources->emplace_back(resources, &resource);
79 }
80 }
81
82 int system_world_initializer(void *ptr)
83 {
84 world_t *world = ptr;
85
86 resource_initializer(world);
87 system_initializer(world);
88 // entity_initializer(world);
89 return 0;
90 }
91