Linked lists error handling and consequences 💀
This commit is contained in:
parent
8b37fc78fa
commit
457de07ecb
|
|
@ -90,7 +90,7 @@ int asset_manager_init(asset_manager_t *asset_manager)
|
|||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
linked_list_push_back_elem(&asset_manager->assets_header_defs, elem);
|
||||
if(linked_list_push_back_elem(&asset_manager->assets_header_defs, elem)) return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
debug_printf("Initialized asset manager.");
|
||||
|
|
@ -121,11 +121,11 @@ static inline bool condition_is_asset_unused(elem_t *elem, va_list args __attrib
|
|||
return !((asset_t *)elem->data)->nb_refs;
|
||||
}
|
||||
|
||||
inline void asset_manager_collect_garbage(asset_manager_t *asset_manager)
|
||||
inline int asset_manager_collect_garbage(asset_manager_t *asset_manager)
|
||||
{
|
||||
assert("Asset manager cannot be NULL" && asset_manager);
|
||||
|
||||
linked_list_remove_if(&asset_manager->assets, condition_is_asset_unused);
|
||||
return linked_list_remove_if(&asset_manager->assets, condition_is_asset_unused);
|
||||
}
|
||||
|
||||
// Only for this file
|
||||
|
|
|
|||
21
src/ecs.c
21
src/ecs.c
|
|
@ -111,9 +111,9 @@ static inline int action_update_component(elem_t *elem, va_list args __attribute
|
|||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
inline void update_entity(entity_t *entity)
|
||||
inline int update_entity(entity_t *entity)
|
||||
{
|
||||
linked_list_for_each(&entity->components, action_update_component);
|
||||
return linked_list_for_each(&entity->components, action_update_component);
|
||||
}
|
||||
|
||||
// Only for this file
|
||||
|
|
@ -145,28 +145,29 @@ inline void entity_manager_init(entity_manager_t *entity_manager)
|
|||
debug_printf("Initialized entity manager.");
|
||||
}
|
||||
|
||||
inline void entity_manager_add_entity(entity_manager_t *entity_manager, entity_t *entity)
|
||||
inline int entity_manager_add_entity(entity_manager_t *entity_manager, entity_t *entity)
|
||||
{
|
||||
assert("Entity manager cannot be NULL" && entity_manager);
|
||||
|
||||
linked_list_push_back(&entity_manager->entities, entity);
|
||||
if(linked_list_push_back(&entity_manager->entities, entity)) return EXIT_FAILURE;
|
||||
|
||||
debug_printf("Added entity %d to entity manager.", entity->id);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
// Only for this file
|
||||
// No args
|
||||
static inline int action_update_entity(elem_t *elem, va_list args __attribute__((unused)))
|
||||
{
|
||||
update_entity((entity_t *)elem->data);
|
||||
return EXIT_SUCCESS;
|
||||
return update_entity((entity_t *)elem->data);
|
||||
}
|
||||
|
||||
inline void entity_manager_update(entity_manager_t *entity_manager)
|
||||
inline int entity_manager_update(entity_manager_t *entity_manager)
|
||||
{
|
||||
assert("Entity manager cannot be NULL" && entity_manager);
|
||||
|
||||
linked_list_for_each(&entity_manager->entities, action_update_entity);
|
||||
return linked_list_for_each(&entity_manager->entities, action_update_entity);
|
||||
}
|
||||
|
||||
// Only for this file
|
||||
|
|
@ -190,11 +191,11 @@ static inline bool condition_is_entity_name(elem_t *elem, va_list args)
|
|||
return ((entity_t *)elem->data)->id == va_arg(args, unsigned int);
|
||||
}
|
||||
|
||||
inline void entity_manager_remove_entity(entity_manager_t *entity_manager, unsigned int id)
|
||||
inline int entity_manager_remove_entity(entity_manager_t *entity_manager, unsigned int id)
|
||||
{
|
||||
assert("Entity manager cannot be NULL" && entity_manager);
|
||||
|
||||
linked_list_remove_if(&entity_manager->entities, condition_is_entity_name, id);
|
||||
return linked_list_remove_if(&entity_manager->entities, condition_is_entity_name, id);
|
||||
}
|
||||
|
||||
inline void entity_manager_exit(entity_manager_t *entity_manager)
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ typedef struct asset_manager_t {
|
|||
|
||||
int asset_manager_init(asset_manager_t *asset_manager);
|
||||
int asset_manager_exit(asset_manager_t *asset_manager);
|
||||
void asset_manager_collect_garbage(asset_manager_t *asset_manager);
|
||||
int asset_manager_collect_garbage(asset_manager_t *asset_manager);
|
||||
|
||||
int asset_manager_load_asset(asset_manager_t *asset_manager, const char *asset_name, asset_type_t asset_type);
|
||||
int asset_manager_let_go_asset(asset_manager_t *asset_manager, const char *asset_name);
|
||||
|
|
|
|||
|
|
@ -14,9 +14,9 @@ typedef enum component_type_t {
|
|||
typedef struct component_t component_t;
|
||||
|
||||
// Component init function. It is called when component added to entity. This function is necessary.
|
||||
typedef void (*component_init_t)(component_t *component, va_list args);
|
||||
typedef int (*component_init_t)(component_t *component, va_list args);
|
||||
// Component update function. It is called in the main loop to update the component. This function is necessary.
|
||||
typedef void (*component_update_t)(component_t *component);
|
||||
typedef int (*component_update_t)(component_t *component);
|
||||
// Component draw function. It is called in the main loop to draw the component on screen. This function is not necessary.
|
||||
typedef int (*component_draw_t)(component_t *component);
|
||||
// Component deleter function. It is called when the component is removed. It should free the data in the component data but not the component itself.
|
||||
|
|
@ -53,7 +53,7 @@ void add_component(entity_t *entity, component_t *component, ...);
|
|||
|
||||
component_t *get_component(entity_t *entity, component_type_t component_type);
|
||||
|
||||
void update_entity(entity_t *entity);
|
||||
int update_entity(entity_t *entity);
|
||||
|
||||
int draw_entity(entity_t *entity);
|
||||
|
||||
|
|
@ -65,13 +65,13 @@ typedef struct entity_manager_t {
|
|||
|
||||
void entity_manager_init(entity_manager_t *entity_manager);
|
||||
|
||||
void entity_manager_add_entity(entity_manager_t *entity_manager, entity_t *entity);
|
||||
int entity_manager_add_entity(entity_manager_t *entity_manager, entity_t *entity);
|
||||
|
||||
void entity_manager_update(entity_manager_t *entity_manager);
|
||||
int entity_manager_update(entity_manager_t *entity_manager);
|
||||
|
||||
int entity_manager_draw(entity_manager_t *entity_manager);
|
||||
|
||||
void entity_manager_remove_entity(entity_manager_t *entity_manager, const unsigned int id);
|
||||
int entity_manager_remove_entity(entity_manager_t *entity_manager, const unsigned int id);
|
||||
|
||||
void entity_manager_exit(entity_manager_t *entity_manager);
|
||||
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ int game_init(void);
|
|||
void game_handle_event(void);
|
||||
|
||||
// Update game
|
||||
void game_update(void);
|
||||
int game_update(void);
|
||||
|
||||
// Render game
|
||||
int game_render(void);
|
||||
|
|
|
|||
|
|
@ -125,7 +125,7 @@ void destroy_elem(elem_t *elem, const deleter_t elem_deleter);
|
|||
* @param linked_list Pointer to a linked list
|
||||
* @param elem Pointer to an element
|
||||
*/
|
||||
void linked_list_push_back_elem(linked_list_t *linked_list, elem_t *elem);
|
||||
int linked_list_push_back_elem(linked_list_t *linked_list, elem_t *elem);
|
||||
|
||||
/**
|
||||
* @brief Insert an element from the front in a linked list, do nothing on error.
|
||||
|
|
@ -133,7 +133,7 @@ void linked_list_push_back_elem(linked_list_t *linked_list, elem_t *elem);
|
|||
* @param linked_list Pointer to a linked list
|
||||
* @param elem Pointer to an element
|
||||
*/
|
||||
void linked_list_push_front_elem(linked_list_t *linked_list, elem_t *elem);
|
||||
int linked_list_push_front_elem(linked_list_t *linked_list, elem_t *elem);
|
||||
|
||||
/**
|
||||
* @brief Insert an element initialised and filled with data from the back in a linked list, do nothing on error.
|
||||
|
|
@ -141,7 +141,7 @@ void linked_list_push_front_elem(linked_list_t *linked_list, elem_t *elem);
|
|||
* @param linked_list Pointer to a linked list
|
||||
* @param data Pointer to any data
|
||||
*/
|
||||
void linked_list_push_back(linked_list_t *linked_list, void *data);
|
||||
int linked_list_push_back(linked_list_t *linked_list, void *data);
|
||||
|
||||
/**
|
||||
* @brief Insert an element filled with data from the front in a linked list.
|
||||
|
|
@ -149,21 +149,21 @@ void linked_list_push_back(linked_list_t *linked_list, void *data);
|
|||
* @param linked_list Pointer to a linked list
|
||||
* @param data Pointer to any data
|
||||
*/
|
||||
void linked_list_push_front(linked_list_t *linked_list, void *data);
|
||||
int linked_list_push_front(linked_list_t *linked_list, void *data);
|
||||
|
||||
/**
|
||||
* @brief Delete the last element in the given linked list, do nothing on error.
|
||||
*
|
||||
* @param linked_list Pointer to a linked list
|
||||
*/
|
||||
void linked_list_pop_back(linked_list_t *linked_list);
|
||||
int linked_list_pop_back(linked_list_t *linked_list);
|
||||
|
||||
/**
|
||||
* @brief Delete the first element in the given linked list, do nothing on error.
|
||||
*
|
||||
* @param linked_list Pointer to a linked list
|
||||
*/
|
||||
void linked_list_pop_front(linked_list_t *linked_list);
|
||||
int linked_list_pop_front(linked_list_t *linked_list);
|
||||
|
||||
/**
|
||||
* @brief Clear the given linked list, do nothing on error.
|
||||
|
|
@ -217,7 +217,7 @@ void *linked_list_get(const linked_list_t *linked_list, const size_t index);
|
|||
* @param elem Pointer to an element
|
||||
* @param index Index to insert element
|
||||
*/
|
||||
void linked_list_insert_elem(linked_list_t *linked_list, elem_t *elem, const size_t index);
|
||||
int linked_list_insert_elem(linked_list_t *linked_list, elem_t *elem, const size_t index);
|
||||
|
||||
/**
|
||||
* @brief Insert element with data at the given index in the linked list, do nothing on error.
|
||||
|
|
@ -226,7 +226,7 @@ void linked_list_insert_elem(linked_list_t *linked_list, elem_t *elem, const siz
|
|||
* @param data Data to put in the new element
|
||||
* @param index Index to insert the element
|
||||
*/
|
||||
void linked_list_insert(linked_list_t *linked_list, void *data, const size_t index);
|
||||
int linked_list_insert(linked_list_t *linked_list, void *data, const size_t index);
|
||||
|
||||
/**
|
||||
* @brief Remove the given elem in the linked list, do nothing on error.
|
||||
|
|
@ -234,7 +234,7 @@ void linked_list_insert(linked_list_t *linked_list, void *data, const size_t ind
|
|||
* @param linked_list Pointer to a linked list
|
||||
* @param elem Element to remove
|
||||
*/
|
||||
void linked_list_remove_elem(linked_list_t *linked_list, elem_t *elem);
|
||||
int linked_list_remove_elem(linked_list_t *linked_list, elem_t *elem);
|
||||
|
||||
/**
|
||||
* @brief Remove element at the given index in the linked list, do nothing on error.
|
||||
|
|
@ -242,7 +242,7 @@ void linked_list_remove_elem(linked_list_t *linked_list, elem_t *elem);
|
|||
* @param linked_list Pointer to a linked list
|
||||
* @param index Index of the element
|
||||
*/
|
||||
void linked_list_remove(linked_list_t *linked_list, const size_t index);
|
||||
int linked_list_remove(linked_list_t *linked_list, const size_t index);
|
||||
|
||||
/**
|
||||
* @brief Return first element that the condition verify
|
||||
|
|
@ -273,7 +273,7 @@ void *linked_list_get_if(const linked_list_t *linked_list, const condition_t con
|
|||
* @param condition Condition to verify
|
||||
* @param ... Argument to pass to the condition
|
||||
*/
|
||||
void linked_list_remove_if(linked_list_t *linked_list, const condition_t condition, ...);
|
||||
int linked_list_remove_if(linked_list_t *linked_list, const condition_t condition, ...);
|
||||
|
||||
/**
|
||||
* @brief Apply an action to every elements in the list.
|
||||
|
|
|
|||
|
|
@ -50,11 +50,15 @@ void linked_list_init(linked_list_t *linked_list, const size_t data_size, const
|
|||
linked_list->elem_deleter = elem_deleter;
|
||||
}
|
||||
|
||||
void linked_list_push_back_elem(linked_list_t *linked_list, elem_t *elem)
|
||||
int linked_list_push_back_elem(linked_list_t *linked_list, elem_t *elem)
|
||||
{
|
||||
assert("Linked list cannot be NULL" && linked_list);
|
||||
|
||||
if(!elem) return; // Not fatal
|
||||
if(!elem)
|
||||
{
|
||||
error_printf("Elem cannot be NULL.");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
elem->prev = linked_list->last;
|
||||
elem->next = NULL;
|
||||
|
|
@ -67,13 +71,19 @@ void linked_list_push_back_elem(linked_list_t *linked_list, elem_t *elem)
|
|||
linked_list->last = elem;
|
||||
|
||||
linked_list->size++;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
void linked_list_push_front_elem(linked_list_t *linked_list, elem_t *elem)
|
||||
int linked_list_push_front_elem(linked_list_t *linked_list, elem_t *elem)
|
||||
{
|
||||
assert("Linked list cannot be NULL" && linked_list);
|
||||
|
||||
if(!elem) return; // Not fatal
|
||||
if(!elem)
|
||||
{
|
||||
error_printf("Elem cannot be NULL.");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
elem->next = linked_list->first;
|
||||
elem->prev = NULL;
|
||||
|
|
@ -86,9 +96,11 @@ void linked_list_push_front_elem(linked_list_t *linked_list, elem_t *elem)
|
|||
linked_list->first = elem;
|
||||
|
||||
linked_list->size++;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
void linked_list_push_back(linked_list_t *linked_list, void *data)
|
||||
int linked_list_push_back(linked_list_t *linked_list, void *data)
|
||||
{
|
||||
assert("Linked list cannot be NULL" && linked_list);
|
||||
|
||||
|
|
@ -96,14 +108,16 @@ void linked_list_push_back(linked_list_t *linked_list, void *data)
|
|||
if(!tmp)
|
||||
{
|
||||
error_printf("Failed to allocate memory : %d", errno);
|
||||
return;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
tmp->data = data;
|
||||
|
||||
linked_list_push_back_elem(linked_list, tmp);
|
||||
if(linked_list_push_back_elem(linked_list, tmp)) return EXIT_FAILURE;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
void linked_list_push_front(linked_list_t *linked_list, void *data)
|
||||
int linked_list_push_front(linked_list_t *linked_list, void *data)
|
||||
{
|
||||
assert("Linked list cannot be NULL" && linked_list);
|
||||
|
||||
|
|
@ -111,19 +125,25 @@ void linked_list_push_front(linked_list_t *linked_list, void *data)
|
|||
if(!tmp)
|
||||
{
|
||||
error_printf("Failed to allocate memory : %d", errno);
|
||||
return;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
tmp->data = data;
|
||||
|
||||
linked_list_push_front_elem(linked_list, tmp);
|
||||
if(linked_list_push_front_elem(linked_list, tmp)) return EXIT_FAILURE;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
void linked_list_pop_back(linked_list_t *linked_list)
|
||||
int linked_list_pop_back(linked_list_t *linked_list)
|
||||
{
|
||||
assert("Linked list cannot be NULL" && linked_list);
|
||||
|
||||
elem_t *tmp = linked_list->last;
|
||||
if(!tmp) return;
|
||||
if(!tmp)
|
||||
{
|
||||
error_printf("No elem to pop back.");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
linked_list->last = tmp->prev;
|
||||
|
||||
|
|
@ -135,14 +155,20 @@ void linked_list_pop_back(linked_list_t *linked_list)
|
|||
destroy_elem(tmp, linked_list->elem_deleter);
|
||||
|
||||
linked_list->size--;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
void linked_list_pop_front(linked_list_t *linked_list)
|
||||
int linked_list_pop_front(linked_list_t *linked_list)
|
||||
{
|
||||
assert("Linked list cannot be NULL" && linked_list);
|
||||
|
||||
elem_t *tmp = linked_list->first;
|
||||
if(!tmp) return;
|
||||
if(!tmp)
|
||||
{
|
||||
error_printf("No elem to pop front.");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
linked_list->first = tmp->next;
|
||||
|
||||
|
|
@ -154,6 +180,8 @@ void linked_list_pop_front(linked_list_t *linked_list)
|
|||
destroy_elem(tmp, linked_list->elem_deleter);
|
||||
|
||||
linked_list->size--;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
void linked_list_clear(linked_list_t *linked_list)
|
||||
|
|
@ -196,7 +224,11 @@ elem_t *linked_list_get_elem(const linked_list_t *linked_list, size_t index)
|
|||
{
|
||||
assert("Linked list cannot be NULL" && linked_list);
|
||||
|
||||
if(!linked_list_is_in_bound(linked_list, index)) return NULL;
|
||||
if(!linked_list_is_in_bound(linked_list, index))
|
||||
{
|
||||
error_printf("List index out of range.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(index == 0)
|
||||
return linked_list->first;
|
||||
|
|
@ -227,37 +259,47 @@ void *linked_list_get(const linked_list_t *linked_list, size_t index)
|
|||
return tmp->data;
|
||||
}
|
||||
|
||||
void linked_list_insert_elem(linked_list_t *linked_list, elem_t *elem, size_t index)
|
||||
int linked_list_insert_elem(linked_list_t *linked_list, elem_t *elem, size_t index)
|
||||
{
|
||||
assert("Linked list cannot be NULL" && linked_list);
|
||||
|
||||
if(!elem) return; // Not fatal
|
||||
if(!linked_list_is_in_bound(linked_list, index)) return;
|
||||
if(!elem)
|
||||
{
|
||||
error_printf("Elem cannot be NULL.");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if(index > linked_list->size)
|
||||
{
|
||||
error_printf("Insert index out of range.");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if(index == 0)
|
||||
{
|
||||
linked_list_push_front_elem(linked_list, elem);
|
||||
return linked_list_push_front_elem(linked_list, elem);
|
||||
}
|
||||
else if(index == (linked_list->size - 1))
|
||||
else if(index == linked_list->size)
|
||||
{
|
||||
linked_list_push_back_elem(linked_list, elem);
|
||||
return linked_list_push_back_elem(linked_list, elem);
|
||||
}
|
||||
else
|
||||
{
|
||||
elem_t *next_insert_elem = linked_list_get_elem(linked_list, index);
|
||||
elem_t *prev_insert_elem = next_insert_elem->prev;
|
||||
|
||||
elem->prev = prev_insert_elem;
|
||||
elem->next = next_insert_elem;
|
||||
elem_t *next_insert_elem = linked_list_get_elem(linked_list, index);
|
||||
if(!next_insert_elem) return EXIT_FAILURE;
|
||||
elem_t *prev_insert_elem = next_insert_elem->prev;
|
||||
|
||||
prev_insert_elem->next = elem;
|
||||
next_insert_elem->prev = elem;
|
||||
elem->prev = prev_insert_elem;
|
||||
elem->next = next_insert_elem;
|
||||
|
||||
linked_list->size++;
|
||||
}
|
||||
prev_insert_elem->next = elem;
|
||||
next_insert_elem->prev = elem;
|
||||
|
||||
linked_list->size++;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
void linked_list_insert(linked_list_t *linked_list, void *data, size_t index)
|
||||
int linked_list_insert(linked_list_t *linked_list, void *data, size_t index)
|
||||
{
|
||||
assert("Linked list cannot be NULL" && linked_list);
|
||||
|
||||
|
|
@ -265,47 +307,53 @@ void linked_list_insert(linked_list_t *linked_list, void *data, size_t index)
|
|||
if(!tmp)
|
||||
{
|
||||
error_printf("Failed to allocate memory : %d", errno);
|
||||
return;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
tmp->data = data;
|
||||
|
||||
linked_list_insert_elem(linked_list, tmp, index);
|
||||
return linked_list_insert_elem(linked_list, tmp, index);
|
||||
}
|
||||
|
||||
void linked_list_remove_elem(linked_list_t *linked_list, elem_t *elem)
|
||||
int linked_list_remove_elem(linked_list_t *linked_list, elem_t *elem)
|
||||
{
|
||||
assert("Linked list cannot be NULL" && linked_list);
|
||||
|
||||
if(!elem) return;
|
||||
if(!elem)
|
||||
{
|
||||
error_printf("Elem cannot be NULL.");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if(elem == linked_list->first)
|
||||
{
|
||||
linked_list_pop_front(linked_list);
|
||||
return linked_list_pop_front(linked_list);
|
||||
}
|
||||
else if(elem == linked_list->last)
|
||||
{
|
||||
linked_list_pop_back(linked_list);
|
||||
return linked_list_pop_back(linked_list);
|
||||
}
|
||||
else
|
||||
{
|
||||
elem_t *prev_insert_elem = elem->prev;
|
||||
elem_t *next_insert_elem = elem->next;
|
||||
|
||||
prev_insert_elem->next = next_insert_elem;
|
||||
next_insert_elem->prev = prev_insert_elem;
|
||||
elem_t *prev_elem = elem->prev;
|
||||
elem_t *next_elem = elem->next;
|
||||
|
||||
destroy_elem(elem, linked_list->elem_deleter);
|
||||
prev_elem->next = next_elem;
|
||||
next_elem->prev = prev_elem;
|
||||
|
||||
linked_list->size--;
|
||||
}
|
||||
destroy_elem(elem, linked_list->elem_deleter);
|
||||
|
||||
linked_list->size--;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
void linked_list_remove(linked_list_t *linked_list, size_t index)
|
||||
int linked_list_remove(linked_list_t *linked_list, size_t index)
|
||||
{
|
||||
assert("Linked list cannot be NULL" && linked_list);
|
||||
|
||||
elem_t *tmp = linked_list_get_elem(linked_list, index);
|
||||
if(tmp) linked_list_remove_elem(linked_list, tmp);
|
||||
if(!tmp) return EXIT_FAILURE;
|
||||
|
||||
return linked_list_remove_elem(linked_list, tmp);
|
||||
}
|
||||
|
||||
elem_t *linked_list_get_elem_if(const linked_list_t *linked_list, const condition_t condition, ...)
|
||||
|
|
@ -380,7 +428,7 @@ void *linked_list_get_if(const linked_list_t *linked_list, const condition_t con
|
|||
return NULL;
|
||||
}
|
||||
|
||||
void linked_list_remove_if(linked_list_t *linked_list, const condition_t condition, ...)
|
||||
int linked_list_remove_if(linked_list_t *linked_list, const condition_t condition, ...)
|
||||
{
|
||||
assert("Linked list cannot be NULL" && linked_list);
|
||||
assert("Condition cannot be NULL" && condition);
|
||||
|
|
@ -400,7 +448,13 @@ void linked_list_remove_if(linked_list_t *linked_list, const condition_t conditi
|
|||
|
||||
if(condition(actual_elem, args_copy))
|
||||
{
|
||||
linked_list_remove_elem(linked_list, actual_elem);
|
||||
if(linked_list_remove_elem(linked_list, actual_elem))
|
||||
{
|
||||
va_end(args_copy);
|
||||
va_end(args);
|
||||
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
va_end(args_copy);
|
||||
|
|
@ -409,6 +463,8 @@ void linked_list_remove_if(linked_list_t *linked_list, const condition_t conditi
|
|||
}
|
||||
|
||||
va_end(args);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int linked_list_for_each(const linked_list_t *linked_list, const action_t action, ...)
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ int main(void)
|
|||
{
|
||||
update_time();
|
||||
game_handle_event();
|
||||
game_update();
|
||||
if(game_update()) exit_status = EXIT_FAILURE;
|
||||
if(game_render()) exit_status = EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue