GCC Code Coverage Report


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

Line Branch Exec Source
1 /*
2 * Filename: /home/thomas/Documents/Perso/our_rpg/sources/System/display.c
3 * Path: /home/thomas/Documents/Perso/our_rpg/sources/System
4 * Created Date: Sunday, February 12th 2023, 6:18:12 pm
5 * Author: Thomas
6 *
7 * Copyright (c) 2023 our_rpg
8 */
9
10 #include "world.h"
11 #include "world_entity.h"
12 #include "world_resource.h"
13 #include "systems.h"
14 #include "components.h"
15 #include "resources.h"
16 #include "raylib.h"
17 #include "world_logger.h"
18
19 int system_display_constructor(system_t *system)
20 {
21 system->type = S_DISPLAY;
22 system->run = &system_display;
23 system->active = true;
24 log_info("Display system created.");
25 return 0;
26 }
27
28 int system_display(void *ptr)
29 {
30 vector_t entities = {0};
31 entity_t *entity = 0;
32 int rvalue = world_join_entities(ptr, &entities, 3, C_DISPLAYABLE, C_POSITION, C_SIZE);
33 ecs_vector2f_t position = {0};
34 ecs_vector2i_t size = {0};
35 Color color = RED;
36 ecs_color_t *color_tmp = 0;
37 resource_t *camera = world_get_resource_by_type(ptr, R_CAMERA);
38
39 if (rvalue < 0)
40 return rvalue;
41 BeginDrawing();
42 ClearBackground(RAYWHITE);
43 if (camera) {
44 BeginMode2D(*(Camera2D *){camera->data});
45 }
46 for (unsigned int i = 0; i < entities.size(&entities); i++) {
47 entity = *(entity_t **)entities.at(&entities, i);
48 position = *(ecs_vector2f_t *){entity_get_component(entity, C_POSITION)->data};
49 size = *(ecs_vector2i_t *){entity_get_component(entity, C_SIZE)->data};
50 if (entity_get_component(entity, C_COLOR)) {
51 color_tmp = entity_get_component(entity, C_COLOR)->data;
52 color = (Color){color_tmp->r, color_tmp->g, color_tmp->b, color_tmp->a};
53 }
54 DrawRectangle(position.x, position.y, size.x, size.y, color);
55 }
56 if (camera)
57 EndMode2D();
58 EndDrawing();
59 entities.destructor(&entities);
60 return 0;
61 }
62