Solving a bug with tupple deletion

This commit is contained in:
AnonymusRaccoon
2020-03-10 16:55:21 +01:00
parent af57877b65
commit adc521633b
7 changed files with 22 additions and 28 deletions
+1 -1
View File
@@ -16,6 +16,6 @@ typedef enum gc_mousekeys
{
GC_LEFT,
GC_RIGHT
};
} gc_mousekeys;
#endif //_KEYBINDINGS_H_
+1 -1
View File
@@ -60,7 +60,7 @@ static void destroy(gc_entity *entity, gc_scene *scene)
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(tup->entities, entity);
LISTREM(scene->entities, entity);
next = cmp->next;
cmp->destroy(cmp);
+1 -1
View File
@@ -83,7 +83,7 @@ const char *name)
return;
for (gc_tupple *tup = scene->entities_by_cmp; tup; tup = tup->next) {
if (!my_strcmp(tup->name, name))
tup_remove(tup, entity->id);
LISTREM(tup->entities, entity);
}
component_destroy(cmp);
}
-3
View File
@@ -7,9 +7,6 @@
#include <SFML/Window.h>
#include "sfml_renderer.h"
#include "systems/sfml_renderer_system.h"
#include "systems/camerafollow_system.h"
#include "components/clickable_component.h"
#include "components/transform_component.h"
void sfml_handle_events(gc_engine *engine)
{
+6 -2
View File
@@ -25,10 +25,11 @@ gc_text *text)
char *texture_name = xml_gettmpstring(n, "sprite", "button_background");
sfTexture *texture = scene->get_data(scene, "sprite", texture_name);
gc_vector2i s = {xml_getintprop(n, "width"), xml_getintprop(n, "height")};
gc_vector2 ts = rend->get_text_size(rend, text);
gc_vector2 ts;
if (!rend)
return (NULL);
ts = rend->get_text_size(rend, text);
if (!texture)
my_printf("No texture defined for the button_background.\n");
entity->add_component(entity, new_component(&transform_component,
@@ -62,6 +63,8 @@ gc_list *new_button(gc_engine *engine, gc_scene *scene, node *n)
if (xml_hasproperty(n, "tag"))
background->add_component(background, new_component(&tag_component,
xml_getproperty(n, "tag")));
if (xml_hasproperty(n, "tooltip"))
LISTADD(entities, tooltip_make(engine, scene, n, background));
LISTADD(entities, background);
LISTADD(entities, new_text(engine, scene, n));
return (entities);
@@ -70,10 +73,11 @@ gc_list *new_button(gc_engine *engine, gc_scene *scene, node *n)
gc_data *button_make(gc_engine *engine, gc_scene *scene, node *n)
{
gc_data *data = malloc(sizeof(*data));
gc_list *list = new_button(engine, scene, n);
data->name = "button";
data->type = "ui";
data->destroy = NULL;
data->custom = new_button(engine, scene, n);
data->custom = list;
return (data);
}
+13 -4
View File
@@ -12,6 +12,18 @@
#include "components/renderer.h"
#include "components/transform_component.h"
static void setup_position(gc_entity *entity, gc_scene *scene, node *n)
{
entity->add_component(entity, new_component(&fixed_to_cam,
(gc_vector2){
xml_getintprop(n, "x") + xml_getintprop(n, "tooltip_x"),
xml_getintprop(n, "y") - xml_getintprop(n, "tooltip_y")
},
xml_propcontains(n, "x", "%"),
xml_propcontains(n, "y", "%"),
0, 0, false, false));
}
gc_entity *tooltip_make(gc_engine *engine, gc_scene *scene, node *n, \
gc_entity *parent)
{
@@ -25,10 +37,7 @@ gc_entity *parent)
GC_TXTREND, xml_getproperty(n, "tooltip"),
scene->get_data(scene, "font", NULL), xml_getintprop(n, "size"),
xml_gettempprop(n, "color"), xml_getbool(n, "resize", true)));
entity->add_component(entity, new_component(&fixed_to_cam,
(gc_vector2){xml_getintprop(n, "x") + 10,xml_getintprop(n, "y") - 5},
xml_propcontains(n, "x", "%"), xml_propcontains(n, "y", "%"),
0, 0, false, false));
setup_position(entity, scene, n);
entity->add_component(entity, new_component(&tooltip_component,
GETCMP(parent, transform_component), xml_getfloatprop(n, "padding_x"),
xml_getfloatprop(n, "padding_y")));
-16
View File
@@ -41,20 +41,4 @@ gc_tupple *tupple_add(gc_tupple *list, const char *name, gc_entity *entity)
list->entities = list_add(NULL, entity);
list->next = NULL;
return (listconst);
}
void tup_remove(gc_tupple *tup, int id)
{
gc_list *prev = NULL;
for (gc_list *ent = tup->entities; ent; ent = ent->next) {
if (((gc_entity *)ent->data)->id == id) {
if (prev)
prev->next = ent->next;
else
tup->entities = ent->next;
return;
}
prev = ent;
}
}