mirror of
https://github.com/zoriya/Gamacon.git
synced 2026-06-06 13:12:54 +00:00
Cleaning up
This commit is contained in:
@@ -31,7 +31,9 @@ SRC = src/engine/engine.c \
|
||||
src/deserializer/prefab.c \
|
||||
src/system.c \
|
||||
src/systems/texture_renderer_system.c \
|
||||
src/engine/engine_system_builder.c
|
||||
src/systems/parallax_system.c \
|
||||
src/engine/engine_system_builder.c \
|
||||
src/engine/engine_component_builder.c
|
||||
|
||||
OBJ = $(SRC:%.c=%.o)
|
||||
|
||||
|
||||
@@ -28,5 +28,4 @@ struct gc_component
|
||||
};
|
||||
|
||||
void *new_component(const void *component, ...);
|
||||
const void *get_component(char *name);
|
||||
void component_destroy(void *component);
|
||||
+10
-1
@@ -29,6 +29,10 @@ struct gc_engine
|
||||
|
||||
gc_list *systems;
|
||||
void (*add_system)(gc_engine *engine, const gc_system *system);
|
||||
const gc_system *(*get_system)(gc_engine *engine, const char *name);
|
||||
gc_list *components;
|
||||
void (*add_component)(gc_engine *engine, const void *component);
|
||||
const void *(*get_component)(gc_engine *engine, const char *name);
|
||||
|
||||
sfRenderWindow *window;
|
||||
sfSprite *sprite;
|
||||
@@ -42,4 +46,9 @@ void handle_events(gc_engine *engine);
|
||||
int change_scene(gc_engine *engine, gc_scene *scene);
|
||||
|
||||
void engine_add_buildin_systems(gc_engine *engine);
|
||||
void engine_add_system(gc_engine *engine, const gc_system *system);
|
||||
const gc_system *engine_get_system(gc_engine *engine, const char *name);
|
||||
void engine_add_system(gc_engine *engine, const gc_system *system);
|
||||
|
||||
void engine_add_buildin_components(gc_engine *engine);
|
||||
const void *engine_get_component(gc_engine *engine, const char *name);
|
||||
void engine_add_component(gc_engine *engine, const void *component);
|
||||
@@ -0,0 +1,12 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** MUL_my_runner_2019
|
||||
** File description:
|
||||
** texture_renderer_system
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "system.h"
|
||||
|
||||
extern const gc_system parallax_system;
|
||||
+4
-12
@@ -13,19 +13,11 @@
|
||||
#include "utility.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
const void *get_component(char *name)
|
||||
const void *engine_get_component(gc_engine *engine, const char *name)
|
||||
{
|
||||
static const void *all_components[] = {
|
||||
&transform_component,
|
||||
&movable_component,
|
||||
&texture_renderer,
|
||||
¶llax_component,
|
||||
NULL
|
||||
};
|
||||
|
||||
for (int i = 0; all_components[i]; i++) {
|
||||
if (!my_strcmp(((const gc_component *)all_components[i])->name, name))
|
||||
return (all_components[i]);
|
||||
for (gc_list *cmp = engine->components; cmp; cmp = cmp->next) {
|
||||
if (!my_strcmp(((const gc_component *)cmp->data)->name, name))
|
||||
return (cmp->data);
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ static void texture_rend_fdctr(gc_engine *engine, void *component, node *n)
|
||||
cmp->sprite->rect.width = xml_getfloatprop(rect, "width");
|
||||
cmp->sprite->rect.top = xml_getfloatprop(rect, "top");
|
||||
cmp->sprite->rect.left = xml_getfloatprop(rect, "left");
|
||||
if (cmp->sprite && cmp->sprite->rect.height < 0) {
|
||||
if (cmp->sprite->texture && cmp->sprite->rect.height < 0) {
|
||||
size = sfTexture_getSize(cmp->sprite->texture->texture);
|
||||
cmp->sprite->rect.height = (float)size.y;
|
||||
cmp->sprite->rect.width = (float)size.x;
|
||||
|
||||
@@ -14,11 +14,9 @@
|
||||
|
||||
gc_component *deserialize_component(gc_engine *engine, node *n)
|
||||
{
|
||||
const gc_component *model;
|
||||
const void *model = engine->get_component(engine, n->name);
|
||||
gc_component *cmp = NULL;
|
||||
|
||||
|
||||
model = get_component(n->name);
|
||||
if (!model)
|
||||
return (NULL);
|
||||
cmp = new_component(model, 0, 0, 0, 0, 0, 0, 0);
|
||||
|
||||
+1
-2
@@ -80,8 +80,7 @@ gc_engine *engine_create(char *title, unsigned framerate)
|
||||
engine->draw_texture = &renderer_draw_texture;
|
||||
engine->destroy = &engine_destroy;
|
||||
engine->scene = NULL;
|
||||
engine->systems = NULL;
|
||||
engine->add_system = &engine_add_system;
|
||||
engine_add_buildin_systems(engine);
|
||||
engine_add_buildin_components(engine);
|
||||
return (engine);
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** MUL_my_runner_2019
|
||||
** File description:
|
||||
** engine_system_builder
|
||||
*/
|
||||
|
||||
#include "engine.h"
|
||||
#include "system.h"
|
||||
#include "components/movable_component.h"
|
||||
#include "components/parallax_component.h"
|
||||
#include "components/texture_renderer.h"
|
||||
#include "components/transform_component.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
void engine_add_component(gc_engine *engine, const void *component)
|
||||
{
|
||||
gc_list *components = engine->components;
|
||||
|
||||
if (!components) {
|
||||
engine->components = malloc(sizeof(gc_list));
|
||||
if (!engine->components)
|
||||
return;
|
||||
engine->components->data = (void *)component;
|
||||
engine->components->next = NULL;
|
||||
} else {
|
||||
while (components->next)
|
||||
components = components->next;
|
||||
components->next = malloc(sizeof(gc_list));
|
||||
if (!components->next)
|
||||
return;
|
||||
components->next->data = (void *)component;
|
||||
components->next->next = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void engine_add_buildin_components(gc_engine *engine)
|
||||
{
|
||||
engine->components = NULL;
|
||||
engine->add_component = &engine_add_component;
|
||||
engine->get_component = &engine_get_component;
|
||||
engine->add_component(engine, &transform_component);
|
||||
engine->add_component(engine, &movable_component);
|
||||
engine->add_component(engine, &texture_renderer);
|
||||
engine->add_component(engine, ¶llax_component);
|
||||
}
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "engine.h"
|
||||
#include "system.h"
|
||||
#include "systems/texture_renderer_system.h"
|
||||
#include "systems/parallax_system.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
void engine_add_system(gc_engine *engine, const gc_system *system)
|
||||
@@ -16,12 +17,16 @@ void engine_add_system(gc_engine *engine, const gc_system *system)
|
||||
|
||||
if (!systems) {
|
||||
engine->systems = malloc(sizeof(gc_list));
|
||||
if (!engine->systems)
|
||||
return;
|
||||
engine->systems->data = (void *)system;
|
||||
engine->systems->next = NULL;
|
||||
} else {
|
||||
while (systems->next)
|
||||
systems = systems->next;
|
||||
systems->next = malloc(sizeof(gc_list));
|
||||
if (!systems->next)
|
||||
return;
|
||||
systems->next->data = (void *)system;
|
||||
systems->next->next = NULL;
|
||||
}
|
||||
@@ -29,5 +34,9 @@ void engine_add_system(gc_engine *engine, const gc_system *system)
|
||||
|
||||
void engine_add_buildin_systems(gc_engine *engine)
|
||||
{
|
||||
engine->systems = NULL;
|
||||
engine->add_system = &engine_add_system;
|
||||
engine->get_system = &engine_get_system;
|
||||
engine->add_system(engine, &texture_renderer_system);
|
||||
engine->add_system(engine, ¶llax_system);
|
||||
}
|
||||
@@ -26,7 +26,7 @@ void renderer_draw_texture(gc_engine *engine, gc_sprite *sprite)
|
||||
sfSprite_setTexture(engine->sprite, sprite->texture->texture, true);
|
||||
sfSprite_setPosition(engine->sprite, pos);
|
||||
sfSprite_setScale(engine->sprite, scale);
|
||||
// sfSprite_setTextureRect(engine->sprite, rect);
|
||||
sfSprite_setTextureRect(engine->sprite, rect);
|
||||
sfRenderWindow_drawSprite(engine->window, engine->sprite, NULL);
|
||||
}
|
||||
|
||||
|
||||
@@ -41,6 +41,9 @@ gc_texture *texture_create(const char *path)
|
||||
return (NULL);
|
||||
texture->texture = sfTexture_createFromFile(path, NULL);
|
||||
texture->name = my_strdup(path);
|
||||
if (!texture->texture || !texture->name)
|
||||
return (NULL);
|
||||
sfTexture_setRepeated(texture->texture, sfTrue);
|
||||
texture->destroy = &texture_destroy;
|
||||
return (texture);
|
||||
}
|
||||
+2
-2
@@ -23,11 +23,11 @@ bool system_check_dependencies(const gc_system *sys, const gc_entity *entity)
|
||||
return (true);
|
||||
}
|
||||
|
||||
const void *get_system(gc_engine *engine, char *name)
|
||||
const gc_system *engine_get_system(gc_engine *engine, const char *name)
|
||||
{
|
||||
for (gc_list *sys = engine->systems; sys; sys = sys->next) {
|
||||
if (!my_strcmp(((const gc_system *)sys->data)->name, name))
|
||||
return (sys);
|
||||
return (sys->data);
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ void parallax_update_entity(gc_engine *engine, gc_entity *entity, float dtime)
|
||||
if (!text->sprite)
|
||||
return;
|
||||
text->sprite->rect.left += parallax->speed * dtime;
|
||||
(void)engine;
|
||||
}
|
||||
|
||||
void parallax_destroy(void *system)
|
||||
@@ -31,7 +32,7 @@ void parallax_destroy(void *system)
|
||||
(void)system;
|
||||
}
|
||||
|
||||
const gc_system texture_renderer_system = {
|
||||
const gc_system parallax_system = {
|
||||
name: "ParallaxSystem",
|
||||
component_name: "ParallaxComponent",
|
||||
check_dependencies: &system_check_dependencies,
|
||||
|
||||
Reference in New Issue
Block a user