Modified topics creation and deletion location.
This commit is contained in:
parent
513b8d1f37
commit
5ba0ff9be3
|
|
@ -47,8 +47,16 @@ inline int event_bus_exit(void)
|
|||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
// Arg : size_t id
|
||||
static inline bool condition_is_topic_id(elem_t *elem, void *arg)
|
||||
{
|
||||
return ((topic_t *)elem->data)->id == *(size_t *)arg;
|
||||
}
|
||||
|
||||
int event_bus_new_topic(size_t id)
|
||||
{
|
||||
if(linked_list_get_if(&game.event_bus.topics, condition_is_topic_id, &id)) return EXIT_SUCCESS;
|
||||
|
||||
elem_t *topic_elem = create_elem(&game.event_bus.topics, id);
|
||||
if(!topic_elem) return_failure_int;
|
||||
|
||||
|
|
@ -59,12 +67,6 @@ int event_bus_new_topic(size_t id)
|
|||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
// Arg : size_t id
|
||||
static inline bool condition_is_topic_id(elem_t *elem, void *arg)
|
||||
{
|
||||
return ((topic_t *)elem->data)->id == *(size_t *)arg;
|
||||
}
|
||||
|
||||
inline int event_bus_remove_topic(size_t id)
|
||||
{
|
||||
if(linked_list_remove_if(&game.event_bus.topics, condition_is_topic_id, &id)) return_failure_int;
|
||||
|
|
|
|||
16
src/map.c
16
src/map.c
|
|
@ -321,7 +321,7 @@ int map_load_entities(map_t *map)
|
|||
component_data->type = data->type;
|
||||
component_data->state = data->state;
|
||||
|
||||
if(event_bus_new_topic(component_data->topic_id)) return_failure_int;
|
||||
if(event_bus_new_topic(data->topic_id)) return_failure_int;
|
||||
|
||||
break;
|
||||
}
|
||||
|
|
@ -368,8 +368,20 @@ int map_remove_entities(map_t *map)
|
|||
switch(component_def->type)
|
||||
{
|
||||
case SPRITE_COMPONENT:
|
||||
{
|
||||
if(asset_manager_let_go_asset((char *)component_def->attributes)) return_failure_int;
|
||||
break;
|
||||
|
||||
case INTERACT_COMPONENT:
|
||||
{
|
||||
struct {
|
||||
fvector2d_t position;
|
||||
fvector2d_t scale;
|
||||
int topic_id;
|
||||
int type;
|
||||
int state;
|
||||
} *data = component_def->attributes;
|
||||
|
||||
if(event_bus_remove_topic(data->topic_id)) return_failure_int;
|
||||
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue