mirror of
https://github.com/zoriya/Gamacon.git
synced 2026-06-06 05:05:36 +00:00
merge
This commit is contained in:
+2
-1
@@ -32,6 +32,7 @@ void *new_component(const void *component, ...);
|
||||
void component_destroy(void *component);
|
||||
gc_component *component_remove(gc_component *cmp, const char *name);
|
||||
|
||||
#define GETCMP(entity, x) ((struct x *)entity->get_component(entity, #x))
|
||||
#define GETCMP(entity, x) ((struct x *)((gc_entity *)entity)->\
|
||||
get_component(entity, #x))
|
||||
#define GETCOLCMP(x) ((struct x *)entity_get_component(\
|
||||
entity_get(engine->scene, id), #x))
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
//
|
||||
// Created by anonymus-raccoon on 3/3/20.
|
||||
//
|
||||
|
||||
#ifndef _TAG_COMPONENT_H_
|
||||
#define _TAG_COMPONENT_H_
|
||||
|
||||
#include "component.h"
|
||||
|
||||
struct tag_component
|
||||
{
|
||||
gc_component base;
|
||||
char *tag;
|
||||
};
|
||||
|
||||
const struct tag_component tag_component;
|
||||
|
||||
#endif //_TAG_COMPONENT_H_
|
||||
+1
-1
@@ -23,7 +23,7 @@ struct gc_entity
|
||||
void (*remove_component)(const gc_scene *scene, const gc_entity *entity, \
|
||||
const char *name);
|
||||
char *(*serialize)(gc_entity *entity, int fd);
|
||||
void (*destroy)(gc_entity *entity);
|
||||
void (*destroy)(gc_entity *entity, gc_scene *scene);
|
||||
};
|
||||
|
||||
gc_entity *entity_create(void);
|
||||
|
||||
+3
-1
@@ -16,5 +16,7 @@ struct gc_list
|
||||
};
|
||||
|
||||
gc_list *list_add(gc_list *list, void *obj);
|
||||
gc_list *list_remove(gc_list *list, void *obj);
|
||||
|
||||
#define LISTADD(list, obj) (list = list_add(list, obj))
|
||||
#define LISTADD(list, obj) (list = list_add(list, obj))
|
||||
#define LISTREM(list, obj) (list = list_remove(list, obj))
|
||||
+3
-1
@@ -11,4 +11,6 @@
|
||||
|
||||
int prefab_load(gc_engine *engine, const char *path);
|
||||
int prefab_loadentities(node *n, gc_engine *engine, gc_scene *scene);
|
||||
gc_entity *deserialize_entity(gc_engine *engine, gc_scene *scene, node *n);
|
||||
gc_entity *deserialize_entity(gc_engine *engine, gc_scene *scene, node *n);
|
||||
gc_component *deserialize_component(gc_engine *engine, gc_entity *entity, \
|
||||
gc_scene *scene, node *n);
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** MUL_my_runner_2019
|
||||
** File description:
|
||||
** parralax_component
|
||||
*/
|
||||
|
||||
#include "components/tag_component.h"
|
||||
#include <malloc.h>
|
||||
#include "xml.h"
|
||||
#include "components/parallax_component.h"
|
||||
#include "components/transform_component.h"
|
||||
|
||||
static void ctr(void *component, va_list args)
|
||||
{
|
||||
struct tag_component *cmp = (struct tag_component *)component;
|
||||
|
||||
cmp->tag = va_arg(args, char *);
|
||||
}
|
||||
|
||||
static void fdctr(gc_entity *entity, gc_scene *scene, void *component, node *n)
|
||||
{
|
||||
struct tag_component *cmp = (struct tag_component *)component;
|
||||
|
||||
cmp->tag = xml_getproperty(n, "tag");
|
||||
(void)scene;
|
||||
(void)entity;
|
||||
}
|
||||
|
||||
static void dtr(void *component)
|
||||
{
|
||||
struct tag_component *cmp = (struct tag_component *)component;
|
||||
|
||||
free(cmp->tag);
|
||||
}
|
||||
|
||||
static char *serialize(void *component)
|
||||
{
|
||||
(void)component;
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
const struct tag_component tag_component = {
|
||||
base: {
|
||||
name: "tag_component",
|
||||
size: sizeof(struct tag_component),
|
||||
dependencies: (char *[]){NULL},
|
||||
ctr: &ctr,
|
||||
fdctr: &fdctr,
|
||||
dtr: &dtr,
|
||||
serialize: &serialize,
|
||||
destroy: &component_destroy
|
||||
},
|
||||
tag: NULL
|
||||
};
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include "xml.h"
|
||||
#include "read_line.h"
|
||||
#include "utility.h"
|
||||
#include "entity.h"
|
||||
#include "engine.h"
|
||||
|
||||
@@ -44,6 +44,7 @@ int prefab_loadentities(node *n, gc_engine *engine, gc_scene *scene)
|
||||
return (-1);
|
||||
scene->add_entity(scene, entity);
|
||||
}
|
||||
|
||||
if (engine->on_resize && engine->get_screen_size && engine->scene)
|
||||
engine->on_resize(engine, engine->get_screen_size(engine));
|
||||
return (0);
|
||||
}
|
||||
@@ -6,7 +6,6 @@
|
||||
*/
|
||||
|
||||
#include "engine.h"
|
||||
#include "system.h"
|
||||
#include "components/movable_component.h"
|
||||
#include "components/parallax_component.h"
|
||||
#include "components/fixed_to_cam_component.h"
|
||||
@@ -21,6 +20,7 @@
|
||||
#include "components/vertex_component.h"
|
||||
#include <stdlib.h>
|
||||
#include "components/clickable_component.h"
|
||||
#include "components/tag_component.h"
|
||||
#include "components/input_component.h"
|
||||
|
||||
void engine_add_component(gc_engine *engine, const void *component)
|
||||
@@ -47,4 +47,5 @@ void engine_add_buildin_components(gc_engine *engine)
|
||||
engine->add_component(engine, &clickable_component);
|
||||
engine->add_component(engine, &vertex_component);
|
||||
engine->add_component(engine, &input_component);
|
||||
engine->add_component(engine, &tag_component);
|
||||
}
|
||||
@@ -15,7 +15,6 @@
|
||||
#include "systems/collision_system.h"
|
||||
#include "systems/camerafollow_system.h"
|
||||
#include "sfml_renderer.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
void engine_add_system(gc_engine *engine, const void *system)
|
||||
{
|
||||
|
||||
+5
-1
@@ -53,11 +53,15 @@ char *entity_serialize(gc_entity *entity, int fd)
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
static void destroy(gc_entity *entity)
|
||||
static void destroy(gc_entity *entity, gc_scene *scene)
|
||||
{
|
||||
gc_component *next = NULL;
|
||||
|
||||
for (gc_component *cmp = entity->components; cmp; cmp = next) {
|
||||
for (gc_tupple *tup = scene->entities_by_cmp; tup; tup = tup->next)
|
||||
if (!my_strcmp(tup->name, cmp->name))
|
||||
tup_remove(tup, entity->id);
|
||||
LISTREM(scene->entities, entity);
|
||||
next = cmp->next;
|
||||
cmp->destroy(cmp);
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ void scene_destroy(gc_scene *scene)
|
||||
|
||||
for (gc_list *entity = scene->entities; entity; entity = next) {
|
||||
next = entity->next;
|
||||
((gc_entity *)entity->data)->destroy(entity->data);
|
||||
((gc_entity *)entity->data)->destroy(entity->data, scene);
|
||||
free(entity);
|
||||
}
|
||||
free_data(scene);
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "systems/sfml_renderer_system.h"
|
||||
#include "ui.h"
|
||||
#include <malloc.h>
|
||||
#include "components/tag_component.h"
|
||||
#include "components/input_component.h"
|
||||
|
||||
gc_entity *background_from_text(gc_engine *engine, gc_scene *scene, node *n, \
|
||||
@@ -58,6 +59,9 @@ gc_list *new_button(gc_engine *engine, gc_scene *scene, node *n)
|
||||
background->add_component(background, new_component(&input_component));
|
||||
background->add_component(background, new_component(&clickable_component,
|
||||
scene, xml_getproperty(n, "click")));
|
||||
if (xml_hasproperty(n, "tag"))
|
||||
background->add_component(background, new_component(&tag_component,
|
||||
xml_getproperty(n, "tag")));
|
||||
LISTADD(entities, background);
|
||||
LISTADD(entities, new_text(engine, scene, n));
|
||||
return (entities);
|
||||
|
||||
+17
-5
@@ -8,9 +8,11 @@
|
||||
#include "components/transform_component.h"
|
||||
#include "components/renderer.h"
|
||||
#include "components/fixed_to_cam_component.h"
|
||||
#include "components/tag_component.h"
|
||||
#include "systems/sfml_renderer_system.h"
|
||||
#include "ui.h"
|
||||
#include <malloc.h>
|
||||
#include "prefab.h"
|
||||
|
||||
gc_entity *new_text(gc_engine *engine, gc_scene *scene, node *n)
|
||||
{
|
||||
@@ -21,11 +23,9 @@ gc_entity *new_text(gc_engine *engine, gc_scene *scene, node *n)
|
||||
else
|
||||
entity = entity_create();
|
||||
entity->add_component(entity, new_component(&transform_component,
|
||||
(gc_vector2){0, 0},
|
||||
(gc_vector2){0, 0}));
|
||||
(gc_vector2){0, 0}, (gc_vector2){0, 0}));
|
||||
entity->add_component(entity, new_component(&renderer_component,
|
||||
GC_TXTREND,
|
||||
xml_getproperty(n, "text"),
|
||||
GC_TXTREND, xml_getproperty(n, "text"),
|
||||
scene->get_data(scene, "font", NULL),
|
||||
xml_getintprop(n, "size"),
|
||||
xml_gettempprop(n, "color"), xml_getbool(n, "resize", true)));
|
||||
@@ -33,6 +33,9 @@ gc_entity *new_text(gc_engine *engine, gc_scene *scene, node *n)
|
||||
(gc_vector2){xml_getintprop(n, "x"),xml_getintprop(n, "y")},
|
||||
xml_propcontains(n, "x", "%"), xml_propcontains(n, "y", "%"),
|
||||
0, 0, false, false));
|
||||
if (xml_hasproperty(n, "tag"))
|
||||
entity->add_component(entity, new_component(&tag_component,
|
||||
xml_getproperty(n, "tag")));
|
||||
return (entity);
|
||||
}
|
||||
|
||||
@@ -52,6 +55,9 @@ gc_entity *new_sprite(gc_engine *engine, gc_scene *scene, node *n)
|
||||
xml_propcontains(n, "x", "%"), xml_propcontains(n, "y", "%"),
|
||||
xml_getintprop(n, "width"), xml_getintprop(n, "height"),
|
||||
xml_propcontains(n, "width", "%"), xml_propcontains(n, "height", "%")));
|
||||
if (xml_hasproperty(n, "tag"))
|
||||
entity->add_component(entity, new_component(&tag_component,
|
||||
xml_getproperty(n, "tag")));
|
||||
return (entity);
|
||||
}
|
||||
|
||||
@@ -72,8 +78,14 @@ gc_data *text_make(gc_engine *engine, gc_scene *scene, node *n)
|
||||
{
|
||||
gc_list *list = NULL;
|
||||
gc_data *data = malloc(sizeof(*data));
|
||||
gc_component *cmp;
|
||||
gc_entity *txt = new_text(engine, scene, n);
|
||||
|
||||
LISTADD(list, new_text(engine, scene, n));
|
||||
LISTADD(list, txt);
|
||||
for (n = n->child; n; n = n->next) {
|
||||
cmp = deserialize_component(engine, txt, scene, n);
|
||||
txt->add_component(txt, cmp);
|
||||
}
|
||||
data->name = "text";
|
||||
data->type = "ui";
|
||||
data->destroy = NULL;
|
||||
|
||||
@@ -26,4 +26,20 @@ gc_list *list_add(gc_list *list, void *obj)
|
||||
list->data = obj;
|
||||
list->next = NULL;
|
||||
return (listconst);
|
||||
}
|
||||
|
||||
gc_list *list_remove(gc_list *list, void *obj)
|
||||
{
|
||||
gc_list *listconst = list;
|
||||
|
||||
if (!list)
|
||||
return (NULL);
|
||||
if (list->data == obj)
|
||||
return (list->next);
|
||||
while (list->next && list->next->data != obj)
|
||||
list = list->next;
|
||||
if (!list->next)
|
||||
return (listconst);
|
||||
list->next = list->next->next;
|
||||
return (listconst);
|
||||
}
|
||||
Reference in New Issue
Block a user