Renamed macros for compatibility with diferent standar libraries.
This commit is contained in:
parent
c458cb72ce
commit
30dc3adf13
|
|
@ -2,10 +2,12 @@
|
||||||
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
#include "game.h"
|
#include "game.h"
|
||||||
#include "linked_list.h"
|
#include "linked_list.h"
|
||||||
#include "texture.h"
|
#include "texture.h"
|
||||||
#include "map.h"
|
#include "map.h"
|
||||||
|
#include "utils.h"
|
||||||
#include "memory_alloc.h"
|
#include "memory_alloc.h"
|
||||||
#include "errors.h"
|
#include "errors.h"
|
||||||
|
|
||||||
|
|
@ -16,7 +18,7 @@ int create_asset(asset_t *asset, va_list args)
|
||||||
asset->type = ASSET_NULL;
|
asset->type = ASSET_NULL;
|
||||||
asset->nb_refs = 0;
|
asset->nb_refs = 0;
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int destroy_asset(asset_t *asset)
|
int destroy_asset(asset_t *asset)
|
||||||
|
|
@ -36,10 +38,10 @@ int destroy_asset(asset_t *asset)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
error_printf("Asset type not valid : %d", asset->type);
|
error_printf("Asset type not valid : %d", asset->type);
|
||||||
return EXIT_FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
// No args
|
// No args
|
||||||
|
|
@ -47,14 +49,14 @@ int create_asset_header_def(asset_header_def_t *asset_header_def, va_list args _
|
||||||
{
|
{
|
||||||
asset_header_def->name = NULL;
|
asset_header_def->name = NULL;
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int destroy_asset_header_def(asset_header_def_t *asset_header_def)
|
int destroy_asset_header_def(asset_header_def_t *asset_header_def)
|
||||||
{
|
{
|
||||||
free(asset_header_def->name);
|
free(asset_header_def->name);
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int asset_manager_init(void)
|
int asset_manager_init(void)
|
||||||
|
|
@ -66,15 +68,11 @@ int asset_manager_init(void)
|
||||||
if(!game.asset_manager.asset_file)
|
if(!game.asset_manager.asset_file)
|
||||||
{
|
{
|
||||||
error_printf("Failed to open asset file : %d", errno);
|
error_printf("Failed to open asset file : %d", errno);
|
||||||
return EXIT_FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t nb_assets;
|
uint32_t nb_assets;
|
||||||
if(fread(&nb_assets, sizeof(nb_assets), 1, game.asset_manager.asset_file) != 1)
|
if(file_read(&nb_assets, sizeof(nb_assets), 1, game.asset_manager.asset_file)) return_failure_int;
|
||||||
{
|
|
||||||
error_printf("Failed to read asset file : %d", ferror(game.asset_manager.asset_file));
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(linked_list_reserve(&game.asset_manager.assets_header_defs, nb_assets)) return_failure_int;
|
if(linked_list_reserve(&game.asset_manager.assets_header_defs, nb_assets)) return_failure_int;
|
||||||
|
|
||||||
|
|
@ -98,7 +96,7 @@ int asset_manager_init(void)
|
||||||
if(ch == EOF)
|
if(ch == EOF)
|
||||||
{
|
{
|
||||||
error_printf("Failed to read asset file : %d", ferror(game.asset_manager.asset_file));
|
error_printf("Failed to read asset file : %d", ferror(game.asset_manager.asset_file));
|
||||||
return EXIT_FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
asset_header_def->name[name_size - 1] = ch;
|
asset_header_def->name[name_size - 1] = ch;
|
||||||
|
|
@ -108,17 +106,14 @@ int asset_manager_init(void)
|
||||||
asset_header_def->name[name_size] = '\0';
|
asset_header_def->name[name_size] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
if(fread(&asset_header_def->start, sizeof(asset_header_def->start), 1, game.asset_manager.asset_file) != 1)
|
if(file_read(&asset_header_def->start, sizeof(asset_header_def->start), 1, game.asset_manager.asset_file)) return_failure_int;
|
||||||
{
|
|
||||||
error_printf("Failed to read asset file : %d", ferror(game.asset_manager.asset_file));
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
linked_list_push_back(&game.asset_manager.assets_header_defs, asset_header_def_elem);
|
linked_list_push_back(&game.asset_manager.assets_header_defs, asset_header_def_elem);
|
||||||
}
|
}
|
||||||
|
|
||||||
debug_printf("Initialized asset manager.");
|
debug_printf("Initialized asset manager.");
|
||||||
return EXIT_SUCCESS;
|
|
||||||
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int asset_manager_exit(void)
|
int asset_manager_exit(void)
|
||||||
|
|
@ -131,12 +126,12 @@ int asset_manager_exit(void)
|
||||||
if(fclose(game.asset_manager.asset_file))
|
if(fclose(game.asset_manager.asset_file))
|
||||||
{
|
{
|
||||||
error_printf("Failed to close asset file : %d", errno);
|
error_printf("Failed to close asset file : %d", errno);
|
||||||
return EXIT_FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
debug_printf("Exited asset manager.");
|
debug_printf("Exited asset manager.");
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only for this file
|
// Only for this file
|
||||||
|
|
@ -150,7 +145,7 @@ inline int asset_manager_collect_garbage(void)
|
||||||
{
|
{
|
||||||
if(linked_list_remove_if(&game.asset_manager.assets, condition_is_asset_unused, NULL)) return_failure_int;
|
if(linked_list_remove_if(&game.asset_manager.assets, condition_is_asset_unused, NULL)) return_failure_int;
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only for this file
|
// Only for this file
|
||||||
|
|
@ -237,7 +232,7 @@ int asset_manager_let_go_asset(char *asset_name)
|
||||||
if(!asset_elem)
|
if(!asset_elem)
|
||||||
{
|
{
|
||||||
error_printf("Asset doesn't exists : %s", asset_name);
|
error_printf("Asset doesn't exists : %s", asset_name);
|
||||||
return EXIT_FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
asset_t *asset = asset_elem->data;
|
asset_t *asset = asset_elem->data;
|
||||||
|
|
@ -245,7 +240,7 @@ int asset_manager_let_go_asset(char *asset_name)
|
||||||
|
|
||||||
debug_printf("Asset \"%s\" has been let go, nb refs : %d", asset->name, asset->nb_refs);
|
debug_printf("Asset \"%s\" has been let go, nb refs : %d", asset->name, asset->nb_refs);
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
asset_t *asset_manager_get_asset(char *asset_name)
|
asset_t *asset_manager_get_asset(char *asset_name)
|
||||||
|
|
|
||||||
29
core/ecs.c
29
core/ecs.c
|
|
@ -1,6 +1,7 @@
|
||||||
#include "ecs.h"
|
#include "ecs.h"
|
||||||
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
#include <errno.h>
|
||||||
#include "game.h"
|
#include "game.h"
|
||||||
#include "components.h"
|
#include "components.h"
|
||||||
#include "memory_alloc.h"
|
#include "memory_alloc.h"
|
||||||
|
|
@ -36,7 +37,7 @@ int create_component(component_t *component, va_list args)
|
||||||
if(!component->data) \
|
if(!component->data) \
|
||||||
{ \
|
{ \
|
||||||
error_printf("Failed to allocate memory : %d", errno); \
|
error_printf("Failed to allocate memory : %d", errno); \
|
||||||
return EXIT_FAILURE; \
|
return FAILURE; \
|
||||||
} \
|
} \
|
||||||
component->deleter = PREFIX##_destroy; \
|
component->deleter = PREFIX##_destroy; \
|
||||||
break;
|
break;
|
||||||
|
|
@ -44,17 +45,17 @@ int create_component(component_t *component, va_list args)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
error_printf("Component type doesn't exists : %d", component->type);
|
error_printf("Component type doesn't exists : %d", component->type);
|
||||||
return EXIT_FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int destroy_component(component_t *component)
|
inline int destroy_component(component_t *component)
|
||||||
{
|
{
|
||||||
if(component->deleter(component)) return_failure_int;
|
if(component->deleter(component)) return_failure_int;
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int create_entity(entity_t *entity, va_list args)
|
int create_entity(entity_t *entity, va_list args)
|
||||||
|
|
@ -64,14 +65,14 @@ int create_entity(entity_t *entity, va_list args)
|
||||||
|
|
||||||
linked_list_init(&entity->components, sizeof(component_t), (allocator_t)create_component, (deleter_t)destroy_component);
|
linked_list_init(&entity->components, sizeof(component_t), (allocator_t)create_component, (deleter_t)destroy_component);
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int destroy_entity(entity_t *entity)
|
inline int destroy_entity(entity_t *entity)
|
||||||
{
|
{
|
||||||
if(linked_list_exit(&entity->components)) return_failure_int;
|
if(linked_list_exit(&entity->components)) return_failure_int;
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
component_t *entity_new_component(entity_t *entity, component_type_t component_type)
|
component_t *entity_new_component(entity_t *entity, component_type_t component_type)
|
||||||
|
|
@ -115,14 +116,14 @@ static inline int action_update_component(elem_t *elem, void *arg __attribute__(
|
||||||
|
|
||||||
if(component->update(component)) return_failure_int;
|
if(component->update(component)) return_failure_int;
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int update_entity(entity_t *entity)
|
inline int update_entity(entity_t *entity)
|
||||||
{
|
{
|
||||||
if(linked_list_for_each(&entity->components, action_update_component, NULL)) return_failure_int;
|
if(linked_list_for_each(&entity->components, action_update_component, NULL)) return_failure_int;
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
// No args
|
// No args
|
||||||
|
|
@ -133,14 +134,14 @@ static inline int action_draw_component(elem_t *elem, void *arg __attribute__((u
|
||||||
if(component->draw)
|
if(component->draw)
|
||||||
if(component->draw(component)) return_failure_int;
|
if(component->draw(component)) return_failure_int;
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int draw_entity(entity_t *entity)
|
inline int draw_entity(entity_t *entity)
|
||||||
{
|
{
|
||||||
if(linked_list_for_each(&entity->components, action_draw_component, NULL)) return_failure_int;
|
if(linked_list_for_each(&entity->components, action_draw_component, NULL)) return_failure_int;
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void entity_manager_init(void)
|
inline void entity_manager_init(void)
|
||||||
|
|
@ -172,7 +173,7 @@ inline int entity_manager_update(void)
|
||||||
{
|
{
|
||||||
if(linked_list_for_each(&game.entity_manager.entities, action_update_entity, NULL)) return_failure_int;
|
if(linked_list_for_each(&game.entity_manager.entities, action_update_entity, NULL)) return_failure_int;
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
// No args
|
// No args
|
||||||
|
|
@ -193,7 +194,7 @@ inline int entity_manager_draw(void)
|
||||||
|
|
||||||
if(linked_list_for_each(&game.entity_manager.entities, action_draw_entity, NULL)) return_failure_int;
|
if(linked_list_for_each(&game.entity_manager.entities, action_draw_entity, NULL)) return_failure_int;
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only for this file
|
// Only for this file
|
||||||
|
|
@ -209,7 +210,7 @@ inline int entity_manager_remove_entity(size_t id)
|
||||||
|
|
||||||
debug_printf("Removed entity %lu from entity manager.", id);
|
debug_printf("Removed entity %lu from entity manager.", id);
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int entity_manager_exit(void)
|
inline int entity_manager_exit(void)
|
||||||
|
|
@ -218,5 +219,5 @@ inline int entity_manager_exit(void)
|
||||||
|
|
||||||
debug_printf("Exited entity manager.");
|
debug_printf("Exited entity manager.");
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ inline int create_subscription(subscription_t *subscription, va_list args)
|
||||||
subscription->callback = va_arg(args, callback_t);
|
subscription->callback = va_arg(args, callback_t);
|
||||||
subscription->data = va_arg(args, void *);
|
subscription->data = va_arg(args, void *);
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Arg : size_t id
|
// Arg : size_t id
|
||||||
|
|
@ -22,14 +22,14 @@ inline int create_topic(topic_t *topic, va_list args)
|
||||||
|
|
||||||
linked_list_init(&topic->subscriptions, sizeof(subscription_t), (allocator_t)create_subscription, NULL);
|
linked_list_init(&topic->subscriptions, sizeof(subscription_t), (allocator_t)create_subscription, NULL);
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int destroy_topic(topic_t *topic)
|
inline int destroy_topic(topic_t *topic)
|
||||||
{
|
{
|
||||||
if(linked_list_exit(&topic->subscriptions)) return_failure_int;
|
if(linked_list_exit(&topic->subscriptions)) return_failure_int;
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void event_bus_init(void)
|
inline void event_bus_init(void)
|
||||||
|
|
@ -44,7 +44,7 @@ inline int event_bus_exit(void)
|
||||||
if(linked_list_exit(&game.event_bus.topics)) return_failure_int;
|
if(linked_list_exit(&game.event_bus.topics)) return_failure_int;
|
||||||
|
|
||||||
debug_printf("Exited event bus.");
|
debug_printf("Exited event bus.");
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Arg : size_t id
|
// Arg : size_t id
|
||||||
|
|
@ -55,7 +55,7 @@ static inline bool condition_is_topic_id(elem_t *elem, void *arg)
|
||||||
|
|
||||||
int event_bus_new_topic(size_t id)
|
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;
|
if(linked_list_get_if(&game.event_bus.topics, condition_is_topic_id, &id)) return SUCCESS;
|
||||||
|
|
||||||
elem_t *topic_elem = create_elem(&game.event_bus.topics, id);
|
elem_t *topic_elem = create_elem(&game.event_bus.topics, id);
|
||||||
if(!topic_elem) return_failure_int;
|
if(!topic_elem) return_failure_int;
|
||||||
|
|
@ -64,7 +64,7 @@ int event_bus_new_topic(size_t id)
|
||||||
|
|
||||||
debug_printf("Created new topic with id : %lu", id);
|
debug_printf("Created new topic with id : %lu", id);
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int event_bus_remove_topic(size_t id)
|
inline int event_bus_remove_topic(size_t id)
|
||||||
|
|
@ -73,7 +73,7 @@ inline int event_bus_remove_topic(size_t id)
|
||||||
|
|
||||||
debug_printf("Removed topic with id : %lu", id);
|
debug_printf("Removed topic with id : %lu", id);
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Args : va_list args
|
// Args : va_list args
|
||||||
|
|
@ -83,7 +83,7 @@ static int action_execute_callback(elem_t *elem, void *arg)
|
||||||
|
|
||||||
if(subscription->callback(arg, subscription->data)) return_failure_int;
|
if(subscription->callback(arg, subscription->data)) return_failure_int;
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int event_bus_publish(size_t id, void *arg)
|
int event_bus_publish(size_t id, void *arg)
|
||||||
|
|
@ -97,7 +97,7 @@ int event_bus_publish(size_t id, void *arg)
|
||||||
|
|
||||||
debug_printf("Published event on topic with id : %lu", id);
|
debug_printf("Published event on topic with id : %lu", id);
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int event_bus_subscribe(size_t id, callback_t callback, void *data)
|
int event_bus_subscribe(size_t id, callback_t callback, void *data)
|
||||||
|
|
@ -106,7 +106,7 @@ int event_bus_subscribe(size_t id, callback_t callback, void *data)
|
||||||
if(!topic_elem)
|
if(!topic_elem)
|
||||||
{
|
{
|
||||||
error_printf("Topic with id : %lu doesn't exists.", id);
|
error_printf("Topic with id : %lu doesn't exists.", id);
|
||||||
return EXIT_FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
topic_t *topic = topic_elem->data;
|
topic_t *topic = topic_elem->data;
|
||||||
|
|
@ -118,7 +118,7 @@ int event_bus_subscribe(size_t id, callback_t callback, void *data)
|
||||||
|
|
||||||
debug_printf("Subscribed to topic with id : %lu", id);
|
debug_printf("Subscribed to topic with id : %lu", id);
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Arg : callback_t callback
|
// Arg : callback_t callback
|
||||||
|
|
@ -136,5 +136,5 @@ int event_bus_unsubscribe(size_t id, callback_t callback)
|
||||||
|
|
||||||
if(linked_list_remove_if(&topic->subscriptions, condition_is_callback, &callback)) return_failure_int;
|
if(linked_list_remove_if(&topic->subscriptions, condition_is_callback, &callback)) return_failure_int;
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,7 @@
|
||||||
SOURCES += $(addprefix host/$(TARGET_HOST)/, \
|
SOURCES += $(addprefix host/$(TARGET_HOST)/, \
|
||||||
|
utils.c \
|
||||||
|
display.c \
|
||||||
|
texture.c \
|
||||||
vector2d.c \
|
vector2d.c \
|
||||||
inputs.c \
|
inputs.c \
|
||||||
update_time.c \
|
update_time.c \
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,44 @@
|
||||||
|
#include "display.h"
|
||||||
|
|
||||||
|
#include <gint/display.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "game.h"
|
||||||
|
#include "errors.h"
|
||||||
|
|
||||||
|
int vpos = 0;
|
||||||
|
|
||||||
|
inline int display_init(void)
|
||||||
|
{
|
||||||
|
return SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void display_exit(void)
|
||||||
|
{
|
||||||
|
#include <gint/keyboard.h>
|
||||||
|
dupdate();
|
||||||
|
getkey();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline int display_clear(void)
|
||||||
|
{
|
||||||
|
dclear(C_WHITE);
|
||||||
|
return SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline int display_update(void)
|
||||||
|
{
|
||||||
|
dupdate();
|
||||||
|
return SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline int display_draw_texture(texture_t *texture, const rect_t *src_rect, const rect_t *dst_rect, bool flip)
|
||||||
|
{
|
||||||
|
dsubimage_rgb16_effect((int)dst_rect->x, (int)dst_rect->y, texture, (int)src_rect->x, (int)src_rect->y, (int)src_rect->w, (int)src_rect->h, flip ? IMAGE_HFLIP : DIMAGE_NONE);
|
||||||
|
return SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline int display_draw_frect(const frect_t *frect, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
|
||||||
|
{
|
||||||
|
drect((int)frect->x, (int)frect->y, (int)(frect->x + frect->w), (int)(frect->y + frect->h), (r >> 3 ) | (g >> 2) | (g >> 3));
|
||||||
|
return SUCCESS;
|
||||||
|
}
|
||||||
|
|
@ -5,11 +5,16 @@
|
||||||
#include "texture.h"
|
#include "texture.h"
|
||||||
#include "vector2d.h"
|
#include "vector2d.h"
|
||||||
|
|
||||||
|
#define COLOR_BLACK 0, 0, 0
|
||||||
|
#define COLOR_RED 255, 0, 0
|
||||||
|
#define COLOR_GREEN 0, 255, 0
|
||||||
|
#define COLOR_BLUE 0, 0, 255
|
||||||
|
#define COLOR_WHITE 255, 255, 255
|
||||||
|
|
||||||
#define DISPLAY_WIDTH DWIDTH
|
#define DISPLAY_WIDTH DWIDTH
|
||||||
#define DISPLAY_HEIGHT DHEIGHT
|
#define DISPLAY_HEIGHT DHEIGHT
|
||||||
|
|
||||||
typedef struct display_t {
|
typedef int display_t;
|
||||||
} display_t;
|
|
||||||
|
|
||||||
int display_init(void);
|
int display_init(void);
|
||||||
void display_exit(void);
|
void display_exit(void);
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,80 @@
|
||||||
|
#ifndef _ERRORS_H
|
||||||
|
#define _ERRORS_H
|
||||||
|
|
||||||
|
#include <gint/display.h>
|
||||||
|
#include <gint/keyboard.h>
|
||||||
|
|
||||||
|
#define SUCCESS 0
|
||||||
|
#define FAILURE 1
|
||||||
|
|
||||||
|
#ifndef DEBUG
|
||||||
|
#define DEBUG 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
extern int vpos;
|
||||||
|
|
||||||
|
#if DEBUG > 0
|
||||||
|
#define debug_printf(...) \
|
||||||
|
do { \
|
||||||
|
dprint_opt(0, vpos, C_BLACK, C_WHITE, DTEXT_LEFT, DTEXT_TOP, "INFO: " __VA_ARGS__); \
|
||||||
|
vpos = vpos % DHEIGHT + 10; \
|
||||||
|
dupdate(); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define warning_printf(...) \
|
||||||
|
do { \
|
||||||
|
dprint_opt(0, vpos, C_BLACK, C_WHITE, DTEXT_LEFT, DTEXT_TOP, "WARNING: " __VA_ARGS__); \
|
||||||
|
vpos = vpos % DHEIGHT + 10; \
|
||||||
|
dupdate(); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define error_printf(...) \
|
||||||
|
do { \
|
||||||
|
dprint_opt(0, vpos, C_RED, C_WHITE, DTEXT_LEFT, DTEXT_TOP, "ERROR: " __VA_ARGS__); \
|
||||||
|
vpos = vpos % DHEIGHT + 10; \
|
||||||
|
dupdate(); \
|
||||||
|
getkey(); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define return_failure_int \
|
||||||
|
do { \
|
||||||
|
dprint_opt(-250, vpos, C_RED, C_WHITE, DTEXT_LEFT, DTEXT_TOP, "in %s:%d", __FILE__, __LINE__); \
|
||||||
|
vpos = vpos % DHEIGHT + 10; \
|
||||||
|
return EXIT_FAILURE; \
|
||||||
|
} while (0);
|
||||||
|
|
||||||
|
#define return_failure_ptr \
|
||||||
|
do { \
|
||||||
|
dprint_opt(-250, vpos, C_RED, C_WHITE, DTEXT_LEFT, DTEXT_TOP, "in %s:%d", __FILE__, __LINE__); \
|
||||||
|
vpos = vpos % DHEIGHT + 10; \
|
||||||
|
return NULL; \
|
||||||
|
} while (0);
|
||||||
|
|
||||||
|
#define goto_failure \
|
||||||
|
do { \
|
||||||
|
dprint_opt(-250, vpos, C_RED, C_WHITE, DTEXT_LEFT, DTEXT_TOP, "in %s:%d", __FILE__, __LINE__); \
|
||||||
|
vpos = vpos % DHEIGHT + 10; \
|
||||||
|
goto failure; \
|
||||||
|
} while (0);
|
||||||
|
#else
|
||||||
|
#define debug_printf(...)
|
||||||
|
|
||||||
|
#define warning_printf(...) \
|
||||||
|
do { \
|
||||||
|
dprint_opt(0, 0, C_BLACK, C_WHITE, DTEXT_LEFT, DTEXT_TOP, "WARNING: " __VA_ARGS__); \
|
||||||
|
dupdate(); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define error_printf(...) \
|
||||||
|
do { \
|
||||||
|
dprint_opt(0, 10, C_RED, C_WHITE, DTEXT_LEFT, DTEXT_TOP, "ERROR: " __VA_ARGS__); \
|
||||||
|
dupdate(); \
|
||||||
|
getkey(); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define return_failure_int return FAILURE;
|
||||||
|
#define return_failure_ptr return NULL;
|
||||||
|
#define goto_failure goto failure;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // _ERRORS_H
|
||||||
|
|
@ -6,11 +6,14 @@ inline int poll_event(input_event_t *event)
|
||||||
{
|
{
|
||||||
key_event_t gint_event = pollevent();
|
key_event_t gint_event = pollevent();
|
||||||
|
|
||||||
if(gint_event.type = KEYEV_NONE)
|
if(gint_event.type == KEYEV_NONE)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
event->type = gint_event.type;
|
event->type = gint_event.type;
|
||||||
event->key = gint_event.key;
|
event->key = gint_event.key;
|
||||||
|
|
||||||
|
if(event->key == KEY_EXIT)
|
||||||
|
event->type = INPUT_EVENT_QUIT;
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,41 @@
|
||||||
|
#include "texture.h"
|
||||||
|
|
||||||
|
#include <gint/image.h>
|
||||||
|
#include "asset_manager.h"
|
||||||
|
#include "game.h"
|
||||||
|
#include "display.h"
|
||||||
|
#include "utils.h"
|
||||||
|
#include "errors.h"
|
||||||
|
|
||||||
|
texture_t *load_texture(void)
|
||||||
|
{
|
||||||
|
uint16_t width, height;
|
||||||
|
|
||||||
|
if(file_read(&width, sizeof(width), 1, game.asset_manager.asset_file)) return_failure_ptr;
|
||||||
|
|
||||||
|
if(file_read(&height, sizeof(height), 1, game.asset_manager.asset_file)) return_failure_ptr;
|
||||||
|
|
||||||
|
texture_t *texture = image_alloc(width, height, IMAGE_RGB565A);
|
||||||
|
if(!texture)
|
||||||
|
{
|
||||||
|
error_printf("Failed to create texture.");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(uint16_t line = 0; line < height; line++)
|
||||||
|
{
|
||||||
|
if(file_read(&((uint8_t *)texture->data)[line * texture->stride], sizeof(uint16_t), width, game.asset_manager.asset_file)) goto_failure;
|
||||||
|
}
|
||||||
|
|
||||||
|
return texture;
|
||||||
|
|
||||||
|
failure:
|
||||||
|
image_free(texture);
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void destroy_texture(texture_t *texture)
|
||||||
|
{
|
||||||
|
image_free(texture);
|
||||||
|
}
|
||||||
|
|
@ -7,8 +7,8 @@
|
||||||
|
|
||||||
typedef bopti_image_t texture_t;
|
typedef bopti_image_t texture_t;
|
||||||
|
|
||||||
#define get_width(T) T->width
|
#define texture_get_width(T) T->width
|
||||||
#define get_height(T) T->height
|
#define texture_get_height(T) T->height
|
||||||
|
|
||||||
texture_t *load_texture(void);
|
texture_t *load_texture(void);
|
||||||
void destroy_texture(texture_t *texture);
|
void destroy_texture(texture_t *texture);
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,31 @@
|
||||||
#include "update_time.h"
|
#include "update_time.h"
|
||||||
|
|
||||||
#include <time.h>
|
#include <gint/timer.h>
|
||||||
|
#include <gint/clock.h>
|
||||||
#include "game.h"
|
#include "game.h"
|
||||||
|
|
||||||
|
#define ENGINE_TICK 25
|
||||||
|
|
||||||
|
static int callback_tick(volatile int *tick)
|
||||||
|
{
|
||||||
|
*tick = 1;
|
||||||
|
return TIMER_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static volatile int tick = 1;
|
||||||
|
|
||||||
|
static int t;
|
||||||
|
|
||||||
inline void update_time(void)
|
inline void update_time(void)
|
||||||
{
|
{
|
||||||
static clock_t last_clock_state = 0;
|
if(t == 0)
|
||||||
clock_t start_clock = clock();
|
{
|
||||||
game.delta_time_ms = (float)(start_clock - last_clock_state) / (float)CLOCKS_PER_SEC;
|
t = timer_configure(TIMER_ANY, ENGINE_TICK*1000, GINT_CALL(callback_tick, &tick));
|
||||||
if(game.delta_time_ms > 100.0f) game.delta_time_ms = 100.0f;
|
if(t >= 0) timer_start(t);
|
||||||
last_clock_state = start_clock;
|
}
|
||||||
|
|
||||||
|
game.delta_time_ms = 25.0f;
|
||||||
|
|
||||||
|
while(!tick) sleep();
|
||||||
|
tick = 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
|
#include "errors.h"
|
||||||
|
|
||||||
|
int file_read(void *ptr, size_t size, size_t nb, FILE *file)
|
||||||
|
{
|
||||||
|
if(fread(ptr, size, nb, file) != size * nb)
|
||||||
|
{
|
||||||
|
error_printf("Failed to read file : %d", ferror(file));
|
||||||
|
return FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return SUCCESS;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
#ifndef _UTILS_H
|
||||||
|
#define _UTILS_H
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int file_read(void *ptr, size_t size, size_t nb, FILE *file);
|
||||||
|
|
||||||
|
#endif // _UTILS_H
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
SOURCES += $(addprefix host/$(TARGET_HOST)/, \
|
SOURCES += $(addprefix host/$(TARGET_HOST)/, \
|
||||||
|
utils.c \
|
||||||
display.c \
|
display.c \
|
||||||
vector2d.c \
|
vector2d.c \
|
||||||
texture.c \
|
texture.c \
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include <SDL3/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <errno.h>
|
||||||
#include "asset_manager.h"
|
#include "asset_manager.h"
|
||||||
#include "game.h"
|
#include "game.h"
|
||||||
#include "texture.h"
|
#include "texture.h"
|
||||||
|
|
@ -14,20 +15,20 @@ inline int display_init(void)
|
||||||
if(!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS))
|
if(!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS))
|
||||||
{
|
{
|
||||||
error_printf("Failed to initialise SDL3 : %s", SDL_GetError());
|
error_printf("Failed to initialise SDL3 : %s", SDL_GetError());
|
||||||
return EXIT_FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!SDL_SetAppMetadata("2D_Engine_SDL3_Core", "1.0", "2D_Engine"))
|
if(!SDL_SetAppMetadata("2D_Engine_SDL3_Core", "1.0", "2D_Engine"))
|
||||||
{
|
{
|
||||||
error_printf("Failed to set app metadata : %s", SDL_GetError());
|
error_printf("Failed to set app metadata : %s", SDL_GetError());
|
||||||
return EXIT_FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
game.display.window = SDL_CreateWindow("2D_Engine", DISPLAY_WIDTH, DISPLAY_HEIGHT, 0);
|
game.display.window = SDL_CreateWindow("2D_Engine", DISPLAY_WIDTH, DISPLAY_HEIGHT, 0);
|
||||||
if(!game.display.window)
|
if(!game.display.window)
|
||||||
{
|
{
|
||||||
error_printf("Failed to create window : %s", SDL_GetError());
|
error_printf("Failed to create window : %s", SDL_GetError());
|
||||||
return EXIT_FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DRIVERS
|
#ifdef DRIVERS
|
||||||
|
|
@ -46,19 +47,19 @@ inline int display_init(void)
|
||||||
if(!game.display.renderer)
|
if(!game.display.renderer)
|
||||||
{
|
{
|
||||||
error_printf("Failed to create renderer : %s", SDL_GetError());
|
error_printf("Failed to create renderer : %s", SDL_GetError());
|
||||||
return EXIT_FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!SDL_SetRenderVSync(game.display.renderer, 1))
|
if(!SDL_SetRenderVSync(game.display.renderer, 1))
|
||||||
{
|
{
|
||||||
error_printf("Failed to activate adaptative vsync : %s", SDL_GetError());
|
error_printf("Failed to activate adaptative vsync : %s", SDL_GetError());
|
||||||
return EXIT_FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!SDL_SetRenderDrawBlendMode(game.display.renderer, SDL_BLENDMODE_BLEND))
|
if(!SDL_SetRenderDrawBlendMode(game.display.renderer, SDL_BLENDMODE_BLEND))
|
||||||
{
|
{
|
||||||
error_printf("Failed to set renderer draw blend mode : %s", SDL_GetError());
|
error_printf("Failed to set renderer draw blend mode : %s", SDL_GetError());
|
||||||
return EXIT_FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
if(!SDL_SetDefaultTextureScaleMode(game.display.renderer, SDL_SCALEMODE_NEAREST))
|
if(!SDL_SetDefaultTextureScaleMode(game.display.renderer, SDL_SCALEMODE_NEAREST))
|
||||||
|
|
@ -69,7 +70,7 @@ inline int display_init(void)
|
||||||
*/
|
*/
|
||||||
debug_printf("Initialized display.");
|
debug_printf("Initialized display.");
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void display_exit(void)
|
inline void display_exit(void)
|
||||||
|
|
@ -83,19 +84,19 @@ inline void display_exit(void)
|
||||||
|
|
||||||
inline int display_clear(void)
|
inline int display_clear(void)
|
||||||
{
|
{
|
||||||
if(!SDL_SetRenderDrawColor(game.display.renderer, C_WHITE, 255))
|
if(!SDL_SetRenderDrawColor(game.display.renderer, COLOR_WHITE, 255))
|
||||||
{
|
{
|
||||||
error_printf("Failed to change renderer draw color : %s", SDL_GetError());
|
error_printf("Failed to change renderer draw color : %s", SDL_GetError());
|
||||||
return EXIT_FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!SDL_RenderClear(game.display.renderer))
|
if(!SDL_RenderClear(game.display.renderer))
|
||||||
{
|
{
|
||||||
error_printf("Failed to clear renderer : %s", SDL_GetError());
|
error_printf("Failed to clear renderer : %s", SDL_GetError());
|
||||||
return EXIT_FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int display_update(void)
|
inline int display_update(void)
|
||||||
|
|
@ -103,7 +104,7 @@ inline int display_update(void)
|
||||||
if(!SDL_RenderPresent(game.display.renderer))
|
if(!SDL_RenderPresent(game.display.renderer))
|
||||||
{
|
{
|
||||||
error_printf("Failed to present renderer : %s", SDL_GetError());
|
error_printf("Failed to present renderer : %s", SDL_GetError());
|
||||||
return EXIT_FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if DEBUG >= 1
|
#if DEBUG >= 1
|
||||||
|
|
@ -124,12 +125,12 @@ inline int display_update(void)
|
||||||
if(sprintf(title, "2D_Engine | cur: %.2ffps | max: %.2ffps | low: %.2ffps", fps, max_fps_10s, low_fps_10s) == -1)
|
if(sprintf(title, "2D_Engine | cur: %.2ffps | max: %.2ffps | low: %.2ffps", fps, max_fps_10s, low_fps_10s) == -1)
|
||||||
{
|
{
|
||||||
error_printf("Sprintf failed : %d", errno);
|
error_printf("Sprintf failed : %d", errno);
|
||||||
return EXIT_FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
if(!SDL_SetWindowTitle(game.display.window, title))
|
if(!SDL_SetWindowTitle(game.display.window, title))
|
||||||
{
|
{
|
||||||
error_printf("Failed to set window title : %s", SDL_GetError());
|
error_printf("Failed to set window title : %s", SDL_GetError());
|
||||||
return EXIT_FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -144,7 +145,7 @@ inline int display_update(void)
|
||||||
}
|
}
|
||||||
#endif // DEBUG >= 1
|
#endif // DEBUG >= 1
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int display_draw_texture(texture_t *texture, const rect_t *src_rect, const rect_t *dst_rect, bool flip)
|
int display_draw_texture(texture_t *texture, const rect_t *src_rect, const rect_t *dst_rect, bool flip)
|
||||||
|
|
@ -164,10 +165,10 @@ int display_draw_texture(texture_t *texture, const rect_t *src_rect, const rect_
|
||||||
if(!SDL_RenderTextureRotated(game.display.renderer, texture, src_rect ? &src_frect : NULL, dst_rect ? &dst_frect : NULL, 0, NULL, flip))
|
if(!SDL_RenderTextureRotated(game.display.renderer, texture, src_rect ? &src_frect : NULL, dst_rect ? &dst_frect : NULL, 0, NULL, flip))
|
||||||
{
|
{
|
||||||
error_printf("Failed to copy texture to renderer : %s", SDL_GetError());
|
error_printf("Failed to copy texture to renderer : %s", SDL_GetError());
|
||||||
return EXIT_FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int display_draw_frect(const frect_t *frect, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
|
int display_draw_frect(const frect_t *frect, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
|
||||||
|
|
@ -175,7 +176,7 @@ int display_draw_frect(const frect_t *frect, unsigned int r, unsigned int g, uns
|
||||||
if(!SDL_SetRenderDrawColor(game.display.renderer, r, g, b, a))
|
if(!SDL_SetRenderDrawColor(game.display.renderer, r, g, b, a))
|
||||||
{
|
{
|
||||||
error_printf("Failed to change renderer draw color : %s", SDL_GetError());
|
error_printf("Failed to change renderer draw color : %s", SDL_GetError());
|
||||||
return EXIT_FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
frect_t display_frect = {
|
frect_t display_frect = {
|
||||||
|
|
@ -188,8 +189,8 @@ int display_draw_frect(const frect_t *frect, unsigned int r, unsigned int g, uns
|
||||||
if(!SDL_RenderRect(game.display.renderer, &display_frect))
|
if(!SDL_RenderRect(game.display.renderer, &display_frect))
|
||||||
{
|
{
|
||||||
error_printf("Failed to draw rectangle to renderer : %s", SDL_GetError());
|
error_printf("Failed to draw rectangle to renderer : %s", SDL_GetError());
|
||||||
return EXIT_FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,11 @@
|
||||||
#include "texture.h"
|
#include "texture.h"
|
||||||
#include "vector2d.h"
|
#include "vector2d.h"
|
||||||
|
|
||||||
#define C_BLACK 0, 0, 0
|
#define COLOR_BLACK 0, 0, 0
|
||||||
#define C_RED 255, 0, 0
|
#define COLOR_RED 255, 0, 0
|
||||||
#define C_GREEN 0, 255, 0
|
#define COLOR_GREEN 0, 255, 0
|
||||||
#define C_BLUE 0, 0, 255
|
#define COLOR_BLUE 0, 0, 255
|
||||||
#define C_WHITE 255, 255, 255
|
#define COLOR_WHITE 255, 255, 255
|
||||||
|
|
||||||
#define DISPLAY_WIDTH 720
|
#define DISPLAY_WIDTH 720
|
||||||
#define DISPLAY_HEIGHT 480
|
#define DISPLAY_HEIGHT 480
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
#ifndef ERRORS_H
|
#ifndef _ERRORS_H
|
||||||
#define ERRORS_H
|
#define _ERRORS_H
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <errno.h>
|
|
||||||
#include <assert.h>
|
#define SUCCESS 0
|
||||||
|
#define FAILURE 1
|
||||||
|
|
||||||
#ifndef DEBUG
|
#ifndef DEBUG
|
||||||
#define DEBUG 0
|
#define DEBUG 0
|
||||||
|
|
@ -40,12 +41,12 @@
|
||||||
fprintf(stderr, "\tin %s:%d:%s()\n", __FILE__, __LINE__, __func__); \
|
fprintf(stderr, "\tin %s:%d:%s()\n", __FILE__, __LINE__, __func__); \
|
||||||
return NULL; \
|
return NULL; \
|
||||||
} while (0);
|
} while (0);
|
||||||
|
|
||||||
#define goto_failure \
|
#define goto_failure \
|
||||||
do { \
|
do { \
|
||||||
fprintf(stderr, "\tin %s:%d:%s()\n", __FILE__, __LINE__, __func__); \
|
fprintf(stderr, "\tin %s:%d:%s()\n", __FILE__, __LINE__, __func__); \
|
||||||
goto failure; \
|
goto failure; \
|
||||||
} while (0);
|
} while (0);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
#define debug_printf(...)
|
#define debug_printf(...)
|
||||||
|
|
||||||
|
|
@ -66,4 +67,4 @@
|
||||||
#define goto_failure goto failure;
|
#define goto_failure goto failure;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // ERRORS_H
|
#endif // _ERRORS_H
|
||||||
|
|
@ -3,23 +3,16 @@
|
||||||
#include "asset_manager.h"
|
#include "asset_manager.h"
|
||||||
#include "game.h"
|
#include "game.h"
|
||||||
#include "display.h"
|
#include "display.h"
|
||||||
|
#include "utils.h"
|
||||||
#include "errors.h"
|
#include "errors.h"
|
||||||
|
|
||||||
texture_t *load_texture(void)
|
texture_t *load_texture(void)
|
||||||
{
|
{
|
||||||
uint16_t width, height;
|
uint16_t width, height;
|
||||||
|
|
||||||
if(fread(&width, sizeof(width), 1, game.asset_manager.asset_file) != 1)
|
if(file_read(&width, sizeof(width), 1, game.asset_manager.asset_file)) return_failure_ptr;
|
||||||
{
|
|
||||||
error_printf("Failed to read in asset file : %d", ferror(game.asset_manager.asset_file));
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(fread(&height, sizeof(height), 1, game.asset_manager.asset_file) != 1)
|
if(file_read(&height, sizeof(height), 1, game.asset_manager.asset_file)) return_failure_ptr;
|
||||||
{
|
|
||||||
error_printf("Failed to read in asset file : %d", ferror(game.asset_manager.asset_file));
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_Surface *tmp_surface = SDL_CreateSurface(width, height, SDL_PIXELFORMAT_RGB565);
|
SDL_Surface *tmp_surface = SDL_CreateSurface(width, height, SDL_PIXELFORMAT_RGB565);
|
||||||
if(!tmp_surface)
|
if(!tmp_surface)
|
||||||
|
|
@ -34,11 +27,7 @@ texture_t *load_texture(void)
|
||||||
goto failure;
|
goto failure;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(fread(tmp_surface->pixels, sizeof(uint16_t), width * height, game.asset_manager.asset_file) != (size_t)width * (size_t)height)
|
if(file_read(tmp_surface->pixels, sizeof(uint16_t), width * height, game.asset_manager.asset_file)) goto_failure;
|
||||||
{
|
|
||||||
error_printf("Failed to read asset file : %d", ferror(game.asset_manager.asset_file));
|
|
||||||
goto failure;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!SDL_SetSurfaceColorKey(tmp_surface, true, TEXTURE_TRANSPARENT_COLOR))
|
if(!SDL_SetSurfaceColorKey(tmp_surface, true, TEXTURE_TRANSPARENT_COLOR))
|
||||||
{
|
{
|
||||||
|
|
@ -65,6 +54,7 @@ texture_t *load_texture(void)
|
||||||
|
|
||||||
failure:
|
failure:
|
||||||
SDL_DestroySurface(tmp_surface);
|
SDL_DestroySurface(tmp_surface);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,9 @@
|
||||||
|
|
||||||
inline void update_time(void)
|
inline void update_time(void)
|
||||||
{
|
{
|
||||||
static uint64_t last_clock_state = 0;
|
static uint64_t last_clock = 0;
|
||||||
uint64_t start_clock = SDL_GetTicksNS();
|
uint64_t start_clock = SDL_GetTicksNS();
|
||||||
game.delta_time_ms = SDL_NS_TO_MS((float)(start_clock - last_clock_state));
|
game.delta_time_ms = SDL_NS_TO_MS((float)(start_clock - last_clock));
|
||||||
if(game.delta_time_ms > 100.0f) game.delta_time_ms = 100.0f;
|
if(game.delta_time_ms > 100.0f) game.delta_time_ms = 100.0f;
|
||||||
last_clock_state = start_clock;
|
last_clock = start_clock;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
|
#include "errors.h"
|
||||||
|
|
||||||
|
int file_read(void *ptr, size_t size, size_t nb, FILE *file)
|
||||||
|
{
|
||||||
|
if(fread(ptr, size, nb, file) != nb)
|
||||||
|
{
|
||||||
|
error_printf("Failed to read file : %d", ferror(file));
|
||||||
|
return FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return SUCCESS;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
#ifndef _UTILS_H
|
||||||
|
#define _UTILS_H
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int file_read(void *ptr, size_t size, size_t nb, FILE *file);
|
||||||
|
|
||||||
|
#endif // _UTILS_H
|
||||||
|
|
@ -1,6 +1,9 @@
|
||||||
#include <stdarg.h>
|
|
||||||
#include "memory_alloc.h"
|
|
||||||
#include "linked_list.h"
|
#include "linked_list.h"
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <assert.h>
|
||||||
|
#include "memory_alloc.h"
|
||||||
#include "errors.h"
|
#include "errors.h"
|
||||||
|
|
||||||
elem_t *create_elem(linked_list_t *linked_list, ...)
|
elem_t *create_elem(linked_list_t *linked_list, ...)
|
||||||
|
|
@ -65,7 +68,7 @@ inline int destroy_elem(linked_list_t *linked_list, elem_t *elem)
|
||||||
free(elem);
|
free(elem);
|
||||||
}
|
}
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void linked_list_init(linked_list_t *linked_list, size_t data_size, const allocator_t allocator, const deleter_t elem_deleter)
|
void linked_list_init(linked_list_t *linked_list, size_t data_size, const allocator_t allocator, const deleter_t elem_deleter)
|
||||||
|
|
@ -114,7 +117,7 @@ int linked_list_exit(linked_list_t *linked_list)
|
||||||
free(tmp);
|
free(tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int linked_list_clear(linked_list_t *linked_list)
|
int linked_list_clear(linked_list_t *linked_list)
|
||||||
|
|
@ -138,7 +141,7 @@ int linked_list_clear(linked_list_t *linked_list)
|
||||||
|
|
||||||
linked_list->size = 0;
|
linked_list->size = 0;
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int linked_list_reserve(linked_list_t *linked_list, size_t target_max_size)
|
int linked_list_reserve(linked_list_t *linked_list, size_t target_max_size)
|
||||||
|
|
@ -153,7 +156,7 @@ int linked_list_reserve(linked_list_t *linked_list, size_t target_max_size)
|
||||||
if(!elem)
|
if(!elem)
|
||||||
{
|
{
|
||||||
error_printf("Failed to allocate memory : %d", errno);
|
error_printf("Failed to allocate memory : %d", errno);
|
||||||
return EXIT_FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
elem->data = malloc(linked_list->data_size);
|
elem->data = malloc(linked_list->data_size);
|
||||||
|
|
@ -161,14 +164,14 @@ int linked_list_reserve(linked_list_t *linked_list, size_t target_max_size)
|
||||||
{
|
{
|
||||||
free(elem);
|
free(elem);
|
||||||
error_printf("Failed to allocate memory : %d", errno);
|
error_printf("Failed to allocate memory : %d", errno);
|
||||||
return EXIT_FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
elem->next = linked_list->reserved;
|
elem->next = linked_list->reserved;
|
||||||
linked_list->reserved = elem;
|
linked_list->reserved = elem;
|
||||||
}
|
}
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void linked_list_push_back(linked_list_t *linked_list, elem_t *elem)
|
void linked_list_push_back(linked_list_t *linked_list, elem_t *elem)
|
||||||
|
|
@ -289,12 +292,12 @@ int linked_list_insert(linked_list_t *linked_list, elem_t *elem, size_t index) /
|
||||||
if(index == 0)
|
if(index == 0)
|
||||||
{
|
{
|
||||||
linked_list_push_front(linked_list, elem);
|
linked_list_push_front(linked_list, elem);
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
else if(index == linked_list->size)
|
else if(index == linked_list->size)
|
||||||
{
|
{
|
||||||
linked_list_push_back(linked_list, elem);
|
linked_list_push_back(linked_list, elem);
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
elem_t *next_insert_elem = linked_list_get(linked_list, index);
|
elem_t *next_insert_elem = linked_list_get(linked_list, index);
|
||||||
|
|
@ -309,7 +312,7 @@ int linked_list_insert(linked_list_t *linked_list, elem_t *elem, size_t index) /
|
||||||
|
|
||||||
linked_list->size++;
|
linked_list->size++;
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int linked_list_remove(linked_list_t *linked_list, elem_t *elem)
|
int linked_list_remove(linked_list_t *linked_list, elem_t *elem)
|
||||||
|
|
@ -328,7 +331,7 @@ int linked_list_remove(linked_list_t *linked_list, elem_t *elem)
|
||||||
|
|
||||||
linked_list->size--;
|
linked_list->size--;
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
elem_t *linked_list_get_if(const linked_list_t *linked_list, const condition_t condition, void *arg)
|
elem_t *linked_list_get_if(const linked_list_t *linked_list, const condition_t condition, void *arg)
|
||||||
|
|
@ -377,7 +380,7 @@ int linked_list_remove_if(linked_list_t *linked_list, const condition_t conditio
|
||||||
actual_elem = next_elem;
|
actual_elem = next_elem;
|
||||||
}
|
}
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int linked_list_for_each(const linked_list_t *linked_list, const action_t action, void *arg)
|
int linked_list_for_each(const linked_list_t *linked_list, const action_t action, void *arg)
|
||||||
|
|
@ -397,7 +400,7 @@ int linked_list_for_each(const linked_list_t *linked_list, const action_t action
|
||||||
current_elem = current_elem->next;
|
current_elem = current_elem->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void swap_elems_data(elem_t *elem_a, elem_t *elem_b)
|
static inline void swap_elems_data(elem_t *elem_a, elem_t *elem_b)
|
||||||
|
|
|
||||||
112
core/map.c
112
core/map.c
|
|
@ -6,6 +6,7 @@
|
||||||
#include "components.h"
|
#include "components.h"
|
||||||
#include "vector2d.h"
|
#include "vector2d.h"
|
||||||
#include "display.h"
|
#include "display.h"
|
||||||
|
#include "utils.h"
|
||||||
#include "memory_alloc.h"
|
#include "memory_alloc.h"
|
||||||
#include "errors.h"
|
#include "errors.h"
|
||||||
|
|
||||||
|
|
@ -13,23 +14,11 @@ map_t *load_map(void)
|
||||||
{
|
{
|
||||||
map_t *map = malloc(sizeof(map_t));
|
map_t *map = malloc(sizeof(map_t));
|
||||||
|
|
||||||
if(fread(&map->width, sizeof(map->width), 1, game.asset_manager.asset_file) != 1)
|
if(file_read(&map->width, sizeof(map->width), 1, game.asset_manager.asset_file)) return_failure_ptr;
|
||||||
{
|
|
||||||
error_printf("Failed to read in asset file : %d", ferror(game.asset_manager.asset_file));
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(fread(&map->height, sizeof(map->height), 1, game.asset_manager.asset_file) != 1)
|
if(file_read(&map->height, sizeof(map->height), 1, game.asset_manager.asset_file)) return_failure_ptr;
|
||||||
{
|
|
||||||
error_printf("Failed to read in asset file : %d", ferror(game.asset_manager.asset_file));
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(fread(&map->backgroundlayernb, sizeof(map->backgroundlayernb), 1, game.asset_manager.asset_file) != 1)
|
if(file_read(&map->backgroundlayernb, sizeof(map->backgroundlayernb), 1, game.asset_manager.asset_file)) return_failure_ptr;
|
||||||
{
|
|
||||||
error_printf("Failed to read in asset file : %d", ferror(game.asset_manager.asset_file));
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
linked_list_init(&map->backgroundlayers, map->width * map->height * sizeof(uint16_t), NULL, NULL);
|
linked_list_init(&map->backgroundlayers, map->width * map->height * sizeof(uint16_t), NULL, NULL);
|
||||||
if(linked_list_reserve(&map->backgroundlayers, map->backgroundlayernb)) return_failure_ptr;
|
if(linked_list_reserve(&map->backgroundlayers, map->backgroundlayernb)) return_failure_ptr;
|
||||||
|
|
@ -40,34 +29,18 @@ map_t *load_map(void)
|
||||||
if(!backgroundlayer_elem) return_failure_ptr;
|
if(!backgroundlayer_elem) return_failure_ptr;
|
||||||
|
|
||||||
uint16_t *backgroundlayer = backgroundlayer_elem->data;
|
uint16_t *backgroundlayer = backgroundlayer_elem->data;
|
||||||
if(fread(backgroundlayer, sizeof(*backgroundlayer), map->width * map->height, game.asset_manager.asset_file) != (size_t)map->width * (size_t)map->height)
|
if(file_read(backgroundlayer, sizeof(*backgroundlayer), map->width * map->height, game.asset_manager.asset_file)) return_failure_ptr;
|
||||||
{
|
|
||||||
error_printf("Failed to read in asset file : %d", ferror(game.asset_manager.asset_file));
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
linked_list_push_back(&map->backgroundlayers, backgroundlayer_elem);
|
linked_list_push_back(&map->backgroundlayers, backgroundlayer_elem);
|
||||||
}
|
}
|
||||||
|
|
||||||
map->foregroundlayer = malloc(map->width * map->height * sizeof(*map->foregroundlayer));
|
map->foregroundlayer = malloc(map->width * map->height * sizeof(*map->foregroundlayer));
|
||||||
if(fread(map->foregroundlayer, sizeof(*map->foregroundlayer), map->width * map->height, game.asset_manager.asset_file) != (size_t)map->width * (size_t)map->height)
|
if(file_read(map->foregroundlayer, sizeof(*map->foregroundlayer), map->width * map->height, game.asset_manager.asset_file)) return_failure_ptr;
|
||||||
{
|
|
||||||
error_printf("Failed to read in asset file : %d", ferror(game.asset_manager.asset_file));
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
map->hitboxes = malloc(map->width * map->height * sizeof(*map->hitboxes));
|
map->hitboxes = malloc(map->width * map->height * sizeof(*map->hitboxes));
|
||||||
if(fread(map->hitboxes, sizeof(*map->hitboxes), map->width * map->height, game.asset_manager.asset_file) != (size_t)map->width * (size_t)map->height)
|
if(file_read(map->hitboxes, sizeof(*map->hitboxes), map->width * map->height, game.asset_manager.asset_file)) return_failure_ptr;
|
||||||
{
|
|
||||||
error_printf("Failed to read in asset file : %d", ferror(game.asset_manager.asset_file));
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(fread(&map->entities_nb, sizeof(map->entities_nb), 1, game.asset_manager.asset_file) != 1)
|
if(file_read(&map->entities_nb, sizeof(map->entities_nb), 1, game.asset_manager.asset_file)) return_failure_ptr;
|
||||||
{
|
|
||||||
error_printf("Failed to read in asset file : %d", ferror(game.asset_manager.asset_file));
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
map->entities_defs = calloc(map->entities_nb, sizeof(map_entity_def_t));
|
map->entities_defs = calloc(map->entities_nb, sizeof(map_entity_def_t));
|
||||||
|
|
||||||
|
|
@ -75,17 +48,9 @@ map_t *load_map(void)
|
||||||
{
|
{
|
||||||
map_entity_def_t *entity_def = &map->entities_defs[i];
|
map_entity_def_t *entity_def = &map->entities_defs[i];
|
||||||
|
|
||||||
if(fread(&entity_def->id, sizeof(entity_def->id), 1, game.asset_manager.asset_file) != 1)
|
if(file_read(&entity_def->id, sizeof(entity_def->id), 1, game.asset_manager.asset_file)) return_failure_ptr;
|
||||||
{
|
|
||||||
error_printf("Failed to read in asset file : %d", ferror(game.asset_manager.asset_file));
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(fread(&entity_def->components_nb, sizeof(entity_def->components_nb), 1, game.asset_manager.asset_file) != 1)
|
if(file_read(&entity_def->components_nb, sizeof(entity_def->components_nb), 1, game.asset_manager.asset_file)) return_failure_ptr;
|
||||||
{
|
|
||||||
error_printf("Failed to read in asset file : %d", ferror(game.asset_manager.asset_file));
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
entity_def->components_defs = calloc(entity_def->components_nb, sizeof(map_entity_component_def_t));
|
entity_def->components_defs = calloc(entity_def->components_nb, sizeof(map_entity_component_def_t));
|
||||||
|
|
||||||
|
|
@ -93,11 +58,7 @@ map_t *load_map(void)
|
||||||
{
|
{
|
||||||
map_entity_component_def_t *component_def = &entity_def->components_defs[j];
|
map_entity_component_def_t *component_def = &entity_def->components_defs[j];
|
||||||
|
|
||||||
if(fread(&component_def->type, sizeof(component_def->type), 1, game.asset_manager.asset_file) != 1)
|
if(file_read(&component_def->type, sizeof(component_def->type), 1, game.asset_manager.asset_file)) return_failure_ptr;
|
||||||
{
|
|
||||||
error_printf("Failed to read in asset file : %d", ferror(game.asset_manager.asset_file));
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch(component_def->type)
|
switch(component_def->type)
|
||||||
{
|
{
|
||||||
|
|
@ -107,11 +68,7 @@ map_t *load_map(void)
|
||||||
case HITBOX_COMPONENT:
|
case HITBOX_COMPONENT:
|
||||||
data_size = sizeof(fvector2d_t) * 2;
|
data_size = sizeof(fvector2d_t) * 2;
|
||||||
component_def->attributes = malloc(data_size);
|
component_def->attributes = malloc(data_size);
|
||||||
if(fread(component_def->attributes, data_size, 1, game.asset_manager.asset_file) != 1)
|
if(file_read(component_def->attributes, data_size, 1, game.asset_manager.asset_file)) return_failure_ptr;
|
||||||
{
|
|
||||||
error_printf("Failed to read in asset file : %d", ferror(game.asset_manager.asset_file));
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SPRITE_COMPONENT:
|
case SPRITE_COMPONENT:
|
||||||
|
|
@ -144,41 +101,20 @@ map_t *load_map(void)
|
||||||
case ANIMATION_SYSTEM:
|
case ANIMATION_SYSTEM:
|
||||||
data_size = sizeof(int) * 2 + sizeof(float) + sizeof(bool) * 3;
|
data_size = sizeof(int) * 2 + sizeof(float) + sizeof(bool) * 3;
|
||||||
component_def->attributes = malloc(data_size);
|
component_def->attributes = malloc(data_size);
|
||||||
if(fread(component_def->attributes, data_size, 1, game.asset_manager.asset_file) != 1)
|
if(file_read(component_def->attributes, data_size, 1, game.asset_manager.asset_file)) return_failure_ptr;
|
||||||
{
|
|
||||||
error_printf("Failed to read in asset file : %d", ferror(game.asset_manager.asset_file));
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case INTERACT_COMPONENT:
|
case INTERACT_COMPONENT:
|
||||||
data_size = sizeof(fvector2d_t) * 2 + sizeof(int) * 3;
|
data_size = sizeof(fvector2d_t) * 2 + sizeof(int) * 3;
|
||||||
component_def->attributes = malloc(data_size);
|
component_def->attributes = malloc(data_size);
|
||||||
if(fread(component_def->attributes, data_size, 1, game.asset_manager.asset_file) != 1)
|
if(file_read(component_def->attributes, data_size, 1, game.asset_manager.asset_file)) return_failure_ptr;
|
||||||
{
|
|
||||||
error_printf("Failed to read in asset file : %d", ferror(game.asset_manager.asset_file));
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DOOR_COMPONENT:
|
case DOOR_COMPONENT:
|
||||||
data_size = sizeof(int) + sizeof(bool);
|
|
||||||
component_def->attributes = malloc(data_size);
|
|
||||||
if(fread(component_def->attributes, data_size, 1, game.asset_manager.asset_file) != 1)
|
|
||||||
{
|
|
||||||
error_printf("Failed to read in asset file : %d", ferror(game.asset_manager.asset_file));
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case LEVER_COMPONENT:
|
case LEVER_COMPONENT:
|
||||||
data_size = sizeof(int) + sizeof(bool);
|
data_size = sizeof(int) + sizeof(bool);
|
||||||
component_def->attributes = malloc(data_size);
|
component_def->attributes = malloc(data_size);
|
||||||
if(fread(component_def->attributes, data_size, 1, game.asset_manager.asset_file) != 1)
|
if(file_read(component_def->attributes, data_size, 1, game.asset_manager.asset_file)) return_failure_ptr;
|
||||||
{
|
|
||||||
error_printf("Failed to read in asset file : %d", ferror(game.asset_manager.asset_file));
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
@ -222,7 +158,7 @@ int destroy_map(map_t *map)
|
||||||
|
|
||||||
free(map);
|
free(map);
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int map_load_entities(map_t *map)
|
int map_load_entities(map_t *map)
|
||||||
|
|
@ -366,12 +302,12 @@ int map_load_entities(map_t *map)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
error_printf("Component type not supported for loading : %s (%d)", component_type_to_name(component_def->type), component_def->type);
|
error_printf("Component type not supported for loading : %s (%d)", component_type_to_name(component_def->type), component_def->type);
|
||||||
return EXIT_FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int map_remove_entities(map_t *map)
|
int map_remove_entities(map_t *map)
|
||||||
|
|
@ -413,13 +349,13 @@ int map_remove_entities(map_t *map)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static inline int draw_tile(uint16_t tile_x, uint16_t tile_y, uint16_t tile_id)
|
static inline int draw_tile(uint16_t tile_x, uint16_t tile_y, uint16_t tile_id)
|
||||||
{
|
{
|
||||||
if(!tile_id) return EXIT_SUCCESS;
|
if(!tile_id) return SUCCESS;
|
||||||
|
|
||||||
rect_t src_frect = {
|
rect_t src_frect = {
|
||||||
.x = tile_id * TILE_SIZE % texture_get_width(game.map->tileset),
|
.x = tile_id * TILE_SIZE % texture_get_width(game.map->tileset),
|
||||||
|
|
@ -437,7 +373,7 @@ static inline int draw_tile(uint16_t tile_x, uint16_t tile_y, uint16_t tile_id)
|
||||||
|
|
||||||
if(display_draw_texture(game.map->tileset, &src_frect, &dst_frect, false)) return_failure_int;
|
if(display_draw_texture(game.map->tileset, &src_frect, &dst_frect, false)) return_failure_int;
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int map_display_background(void)
|
int map_display_background(void)
|
||||||
|
|
@ -470,7 +406,7 @@ int map_display_background(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int map_display_foreground(void)
|
int map_display_foreground(void)
|
||||||
|
|
@ -497,7 +433,7 @@ int map_display_foreground(void)
|
||||||
if(draw_tile(tile_x, tile_y, game.map->foregroundlayer[tile_y * game.map->width + tile_x])) return_failure_int;
|
if(draw_tile(tile_x, tile_y, game.map->foregroundlayer[tile_y * game.map->width + tile_x])) return_failure_int;
|
||||||
}
|
}
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if DEBUG > 1
|
#if DEBUG > 1
|
||||||
|
|
@ -531,7 +467,7 @@ int map_display_hitboxes(void)
|
||||||
.h = TILE_SIZE
|
.h = TILE_SIZE
|
||||||
};
|
};
|
||||||
|
|
||||||
if(display_draw_frect(&draw_frect, C_RED, 128)) return_failure_int;
|
if(display_draw_frect(&draw_frect, COLOR_RED, 128)) return_failure_int;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,14 +15,14 @@ int animation_system_init(component_t *system)
|
||||||
if(!system_data->sprite_component)
|
if(!system_data->sprite_component)
|
||||||
{
|
{
|
||||||
error_printf("Animation system require a sprite component.");
|
error_printf("Animation system require a sprite component.");
|
||||||
return EXIT_FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
linked_list_init(&system_data->frames, sizeof(rect_t), NULL, NULL);
|
linked_list_init(&system_data->frames, sizeof(rect_t), NULL, NULL);
|
||||||
|
|
||||||
system_data->frame_timer_ms = 0.0f;
|
system_data->frame_timer_ms = 0.0f;
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int animation_system_update(component_t *system)
|
int animation_system_update(component_t *system)
|
||||||
|
|
@ -77,7 +77,7 @@ int animation_system_update(component_t *system)
|
||||||
sprite_component_data->src_rect = *(rect_t *)system_data->current_frame->data;
|
sprite_component_data->src_rect = *(rect_t *)system_data->current_frame->data;
|
||||||
}
|
}
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int animation_system_destroy(component_t *system)
|
inline int animation_system_destroy(component_t *system)
|
||||||
|
|
@ -88,7 +88,7 @@ inline int animation_system_destroy(component_t *system)
|
||||||
|
|
||||||
free(system_data);
|
free(system_data);
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int animation_system_apply_changes(component_t *system)
|
inline int animation_system_apply_changes(component_t *system)
|
||||||
|
|
@ -119,10 +119,10 @@ inline int animation_system_apply_changes(component_t *system)
|
||||||
if(!system_data->current_frame)
|
if(!system_data->current_frame)
|
||||||
{
|
{
|
||||||
error_printf("Current frame number out of range.");
|
error_printf("Current frame number out of range.");
|
||||||
return EXIT_FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
sprite_component_data->src_rect = *(rect_t *)system_data->current_frame->data;
|
sprite_component_data->src_rect = *(rect_t *)system_data->current_frame->data;
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,19 +17,19 @@ inline int door_component_init(component_t *component)
|
||||||
if(!component_data->animation_system)
|
if(!component_data->animation_system)
|
||||||
{
|
{
|
||||||
error_printf("Door component require an animation system.");
|
error_printf("Door component require an animation system.");
|
||||||
return EXIT_FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
component_data->hitbox_component = entity_get_component(component->entity, HITBOX_COMPONENT);
|
component_data->hitbox_component = entity_get_component(component->entity, HITBOX_COMPONENT);
|
||||||
if(!component_data->hitbox_component)
|
if(!component_data->hitbox_component)
|
||||||
{
|
{
|
||||||
error_printf("Door component require an hitbox component.");
|
error_printf("Door component require an hitbox component.");
|
||||||
return EXIT_FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
component_data->last_state = false;
|
component_data->last_state = false;
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int door_component_update(component_t *component)
|
inline int door_component_update(component_t *component)
|
||||||
|
|
@ -48,7 +48,7 @@ inline int door_component_update(component_t *component)
|
||||||
|
|
||||||
component_data->last_state = component_data->state;
|
component_data->last_state = component_data->state;
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int door_component_destroy(component_t *component)
|
inline int door_component_destroy(component_t *component)
|
||||||
|
|
@ -57,7 +57,7 @@ inline int door_component_destroy(component_t *component)
|
||||||
|
|
||||||
free(component_data);
|
free(component_data);
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Event arg : size_t state, Subscription data : entity_t *entity
|
// Event arg : size_t state, Subscription data : entity_t *entity
|
||||||
|
|
@ -68,7 +68,7 @@ static inline int door_component_callback(void *event_arg, void *subscription_da
|
||||||
|
|
||||||
component_data->state = *(size_t *)event_arg;
|
component_data->state = *(size_t *)event_arg;
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int door_component_subscribe(component_t *component)
|
inline int door_component_subscribe(component_t *component)
|
||||||
|
|
@ -77,5 +77,5 @@ inline int door_component_subscribe(component_t *component)
|
||||||
|
|
||||||
if(event_bus_subscribe(component_data->topic_id, door_component_callback, component)) return_failure_int;
|
if(event_bus_subscribe(component_data->topic_id, door_component_callback, component)) return_failure_int;
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ inline int hitbox_component_init(component_t *component)
|
||||||
if(!component_data->transform_component)
|
if(!component_data->transform_component)
|
||||||
{
|
{
|
||||||
error_printf("Hitbox component require a transform component.");
|
error_printf("Hitbox component require a transform component.");
|
||||||
return EXIT_FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
component_data->position = (fvector2d_t) {
|
component_data->position = (fvector2d_t) {
|
||||||
|
|
@ -29,7 +29,7 @@ inline int hitbox_component_init(component_t *component)
|
||||||
|
|
||||||
component_data->activated = true;
|
component_data->activated = true;
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int hitbox_component_update(component_t *component)
|
inline int hitbox_component_update(component_t *component)
|
||||||
|
|
@ -42,7 +42,7 @@ inline int hitbox_component_update(component_t *component)
|
||||||
component_data->bounds.w = transform_component_data->bounds.w * component_data->scale.x;
|
component_data->bounds.w = transform_component_data->bounds.w * component_data->scale.x;
|
||||||
component_data->bounds.h = transform_component_data->bounds.h * component_data->scale.y;
|
component_data->bounds.h = transform_component_data->bounds.h * component_data->scale.y;
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if DEBUG >= 2
|
#if DEBUG >= 2
|
||||||
|
|
@ -53,9 +53,9 @@ inline int hitbox_component_draw(const component_t *component)
|
||||||
const hitbox_component_data_t *component_data = component->data;
|
const hitbox_component_data_t *component_data = component->data;
|
||||||
|
|
||||||
if(component_data->activated)
|
if(component_data->activated)
|
||||||
if(display_draw_frect(&component_data->bounds, C_RED, 128)) return_failure_int;
|
if(display_draw_frect(&component_data->bounds, COLOR_RED, 128)) return_failure_int;
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
#endif // DEBUG >= 2
|
#endif // DEBUG >= 2
|
||||||
|
|
||||||
|
|
@ -65,5 +65,5 @@ inline int hitbox_component_destroy(component_t *component)
|
||||||
|
|
||||||
free(component_data);
|
free(component_data);
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ inline int interact_component_init(component_t *component)
|
||||||
if(!component_data->transform_component)
|
if(!component_data->transform_component)
|
||||||
{
|
{
|
||||||
error_printf("Hitbox component require a transform component.");
|
error_printf("Hitbox component require a transform component.");
|
||||||
return EXIT_FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
component_data->position = (fvector2d_t) {
|
component_data->position = (fvector2d_t) {
|
||||||
|
|
@ -30,7 +30,7 @@ inline int interact_component_init(component_t *component)
|
||||||
component_data->topic_id = 0;
|
component_data->topic_id = 0;
|
||||||
component_data->activated = true;
|
component_data->activated = true;
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int interact_component_update(component_t *component)
|
inline int interact_component_update(component_t *component)
|
||||||
|
|
@ -43,7 +43,7 @@ inline int interact_component_update(component_t *component)
|
||||||
component_data->bounds.w = transform_component_data->bounds.w * component_data->scale.x;
|
component_data->bounds.w = transform_component_data->bounds.w * component_data->scale.x;
|
||||||
component_data->bounds.h = transform_component_data->bounds.h * component_data->scale.y;
|
component_data->bounds.h = transform_component_data->bounds.h * component_data->scale.y;
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if DEBUG >= 2
|
#if DEBUG >= 2
|
||||||
|
|
@ -53,7 +53,7 @@ inline int interact_component_draw(const component_t *component)
|
||||||
{
|
{
|
||||||
const interact_component_data_t *component_data = component->data;
|
const interact_component_data_t *component_data = component->data;
|
||||||
|
|
||||||
if(display_draw_frect(&component_data->bounds, C_GREEN, 128)) return_failure_int;
|
if(display_draw_frect(&component_data->bounds, COLOR_GREEN, 128)) return_failure_int;
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
@ -65,7 +65,7 @@ inline int interact_component_destroy(component_t *component)
|
||||||
|
|
||||||
free(component_data);
|
free(component_data);
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int interact_component_interact(component_t *component)
|
inline int interact_component_interact(component_t *component)
|
||||||
|
|
@ -80,10 +80,10 @@ inline int interact_component_interact(component_t *component)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
error_printf("Interaction type not valid : %d", component_data->type);
|
error_printf("Interaction type not valid : %d", component_data->type);
|
||||||
return EXIT_FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(event_bus_publish(component_data->topic_id, &component_data->state)) return_failure_int;
|
if(event_bus_publish(component_data->topic_id, &component_data->state)) return_failure_int;
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,12 +17,12 @@ inline int lever_component_init(component_t *component)
|
||||||
if(!component_data->animation_system)
|
if(!component_data->animation_system)
|
||||||
{
|
{
|
||||||
error_printf("Lever component require an animation system.");
|
error_printf("Lever component require an animation system.");
|
||||||
return EXIT_FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
component_data->last_state = false;
|
component_data->last_state = false;
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int lever_component_update(component_t *component)
|
inline int lever_component_update(component_t *component)
|
||||||
|
|
@ -38,7 +38,7 @@ inline int lever_component_update(component_t *component)
|
||||||
|
|
||||||
component_data->last_state = component_data->state;
|
component_data->last_state = component_data->state;
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int lever_component_destroy(component_t *component)
|
inline int lever_component_destroy(component_t *component)
|
||||||
|
|
@ -47,7 +47,7 @@ inline int lever_component_destroy(component_t *component)
|
||||||
|
|
||||||
free(component_data);
|
free(component_data);
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Event arg : size_t state, Subscription data : component_t *component
|
// Event arg : size_t state, Subscription data : component_t *component
|
||||||
|
|
@ -58,7 +58,7 @@ static inline int lever_component_callback(void *event_arg, void *subscription_d
|
||||||
|
|
||||||
component_data->state = *(size_t *)event_arg;
|
component_data->state = *(size_t *)event_arg;
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int lever_component_subscribe(component_t *component)
|
inline int lever_component_subscribe(component_t *component)
|
||||||
|
|
@ -67,5 +67,5 @@ inline int lever_component_subscribe(component_t *component)
|
||||||
|
|
||||||
if(event_bus_subscribe(component_data->topic_id, lever_component_callback, component)) return_failure_int;
|
if(event_bus_subscribe(component_data->topic_id, lever_component_callback, component)) return_failure_int;
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ inline int lua_component_init(component_t *component)
|
||||||
|
|
||||||
luaL_dostring(component_data->lua_state, "function f (a) print(a) end");
|
luaL_dostring(component_data->lua_state, "function f (a) print(a) end");
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int lua_component_update(component_t *component __attribute__((unused)))
|
inline int lua_component_update(component_t *component __attribute__((unused)))
|
||||||
|
|
@ -27,7 +27,7 @@ inline int lua_component_update(component_t *component __attribute__((unused)))
|
||||||
|
|
||||||
luaL_dostring(component_data->lua_state, "f(\"prout\")");
|
luaL_dostring(component_data->lua_state, "f(\"prout\")");
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if DEBUG >= 2
|
#if DEBUG >= 2
|
||||||
|
|
@ -47,5 +47,5 @@ inline int lua_component_destroy(component_t *component)
|
||||||
|
|
||||||
free(component_data);
|
free(component_data);
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,14 +16,14 @@ inline int physics_system_init(component_t *component)
|
||||||
if(!system_data->transform_component)
|
if(!system_data->transform_component)
|
||||||
{
|
{
|
||||||
error_printf("Physics system require a transform component.");
|
error_printf("Physics system require a transform component.");
|
||||||
return EXIT_FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
system_data->hitbox_component = entity_get_component(component->entity, HITBOX_COMPONENT);
|
system_data->hitbox_component = entity_get_component(component->entity, HITBOX_COMPONENT);
|
||||||
if(!system_data->hitbox_component)
|
if(!system_data->hitbox_component)
|
||||||
{
|
{
|
||||||
error_printf("Physics system require an hitbox component.");
|
error_printf("Physics system require an hitbox component.");
|
||||||
return EXIT_FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
system_data->target_velocity = (fvector2d_t) {
|
system_data->target_velocity = (fvector2d_t) {
|
||||||
|
|
@ -40,7 +40,7 @@ inline int physics_system_init(component_t *component)
|
||||||
|
|
||||||
system_data->smoothing_factor = 1.0f;
|
system_data->smoothing_factor = 1.0f;
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Args : component_t *component
|
// Args : component_t *component
|
||||||
|
|
@ -58,7 +58,7 @@ int physics_system_update(component_t *component)
|
||||||
if(hitbox_component_data->activated)
|
if(hitbox_component_data->activated)
|
||||||
{
|
{
|
||||||
// Resolve entities collisions.
|
// Resolve entities collisions.
|
||||||
if(linked_list_for_each(&game.entity_manager.entities, action_detect_solve_entities_collision, component)) return EXIT_FAILURE;
|
if(linked_list_for_each(&game.entity_manager.entities, action_detect_solve_entities_collision, component)) return FAILURE;
|
||||||
|
|
||||||
// Resolve map collisions
|
// Resolve map collisions
|
||||||
if(game.map)
|
if(game.map)
|
||||||
|
|
@ -136,7 +136,7 @@ int physics_system_update(component_t *component)
|
||||||
transform_component_data->bounds.x += system_data->velocity.x * (float)game.delta_time_ms / 1000.0f;
|
transform_component_data->bounds.x += system_data->velocity.x * (float)game.delta_time_ms / 1000.0f;
|
||||||
transform_component_data->bounds.y += system_data->velocity.y * (float)game.delta_time_ms / 1000.0f;
|
transform_component_data->bounds.y += system_data->velocity.y * (float)game.delta_time_ms / 1000.0f;
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int physics_system_destroy(component_t *component)
|
inline int physics_system_destroy(component_t *component)
|
||||||
|
|
@ -145,7 +145,7 @@ inline int physics_system_destroy(component_t *component)
|
||||||
|
|
||||||
free(system_data);
|
free(system_data);
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int action_detect_solve_entities_collision(elem_t *elem, void *arg)
|
static inline int action_detect_solve_entities_collision(elem_t *elem, void *arg)
|
||||||
|
|
@ -160,15 +160,15 @@ static inline int action_detect_solve_entities_collision(elem_t *elem, void *arg
|
||||||
|
|
||||||
if(target_entity->id == physics_system->entity->id)
|
if(target_entity->id == physics_system->entity->id)
|
||||||
{
|
{
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
const component_t *target_hitbox_component = entity_get_component(target_entity, HITBOX_COMPONENT);
|
const component_t *target_hitbox_component = entity_get_component(target_entity, HITBOX_COMPONENT);
|
||||||
if(!target_hitbox_component) return EXIT_SUCCESS;
|
if(!target_hitbox_component) return SUCCESS;
|
||||||
|
|
||||||
const hitbox_component_data_t *target_hitbox_component_data = target_hitbox_component->data;
|
const hitbox_component_data_t *target_hitbox_component_data = target_hitbox_component->data;
|
||||||
|
|
||||||
if(!target_hitbox_component_data->activated) return EXIT_SUCCESS;
|
if(!target_hitbox_component_data->activated) return SUCCESS;
|
||||||
|
|
||||||
const frect_t *hitbox_bounds = &hitbox_component_data->bounds;
|
const frect_t *hitbox_bounds = &hitbox_component_data->bounds;
|
||||||
const frect_t *target_hitbox_bounds = &target_hitbox_component_data->bounds;
|
const frect_t *target_hitbox_bounds = &target_hitbox_component_data->bounds;
|
||||||
|
|
@ -210,5 +210,5 @@ static inline int action_detect_solve_entities_collision(elem_t *elem, void *arg
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,26 +18,26 @@ inline int player_system_init(component_t *component)
|
||||||
if(!system_data->sprite_component)
|
if(!system_data->sprite_component)
|
||||||
{
|
{
|
||||||
error_printf("Player system require a sprite component.");
|
error_printf("Player system require a sprite component.");
|
||||||
return EXIT_FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
system_data->animation_system = entity_get_component(component->entity, ANIMATION_SYSTEM);
|
system_data->animation_system = entity_get_component(component->entity, ANIMATION_SYSTEM);
|
||||||
if(!system_data->animation_system)
|
if(!system_data->animation_system)
|
||||||
{
|
{
|
||||||
error_printf("Player system require an animation system.");
|
error_printf("Player system require an animation system.");
|
||||||
return EXIT_FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
system_data->physics_system = entity_get_component(component->entity, PHYSICS_SYSTEM);
|
system_data->physics_system = entity_get_component(component->entity, PHYSICS_SYSTEM);
|
||||||
if(!system_data->physics_system)
|
if(!system_data->physics_system)
|
||||||
{
|
{
|
||||||
error_printf("Player system require a physics system.");
|
error_printf("Player system require a physics system.");
|
||||||
return EXIT_FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
system_data->state = PLAYER_MOVING;
|
system_data->state = PLAYER_MOVING;
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void player_system_get_inputs(player_system_data_t *system_data);
|
static void player_system_get_inputs(player_system_data_t *system_data);
|
||||||
|
|
@ -54,7 +54,7 @@ inline int player_system_update(component_t *component)
|
||||||
if(player_system_set_animation_and_speed(system_data)) return_failure_int;
|
if(player_system_set_animation_and_speed(system_data)) return_failure_int;
|
||||||
if(player_system_process_interaction(system_data)) return_failure_int;
|
if(player_system_process_interaction(system_data)) return_failure_int;
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int player_system_destroy(component_t *component)
|
inline int player_system_destroy(component_t *component)
|
||||||
|
|
@ -63,7 +63,7 @@ inline int player_system_destroy(component_t *component)
|
||||||
|
|
||||||
free(component_data);
|
free(component_data);
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void player_system_get_inputs(player_system_data_t *system_data)
|
static inline void player_system_get_inputs(player_system_data_t *system_data)
|
||||||
|
|
@ -169,7 +169,7 @@ static inline int player_system_set_animation_and_speed(player_system_data_t *sy
|
||||||
if(animation_system_apply_changes(system_data->animation_system)) return_failure_int;
|
if(animation_system_apply_changes(system_data->animation_system)) return_failure_int;
|
||||||
}
|
}
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Args : player_system_data_t *system_data
|
// Args : player_system_data_t *system_data
|
||||||
|
|
@ -181,13 +181,13 @@ static inline int action_detect_activate_interact(elem_t *elem, void *arg)
|
||||||
physics_system_data_t *physics_system_data = system_data->physics_system->data;
|
physics_system_data_t *physics_system_data = system_data->physics_system->data;
|
||||||
|
|
||||||
component_t *target_interact_component = entity_get_component(target_entity, INTERACT_COMPONENT);
|
component_t *target_interact_component = entity_get_component(target_entity, INTERACT_COMPONENT);
|
||||||
if(!target_interact_component) return EXIT_SUCCESS;
|
if(!target_interact_component) return SUCCESS;
|
||||||
|
|
||||||
interact_component_data_t *target_interact_component_data = target_interact_component->data;
|
interact_component_data_t *target_interact_component_data = target_interact_component->data;
|
||||||
|
|
||||||
if(!target_interact_component_data->activated)
|
if(!target_interact_component_data->activated)
|
||||||
{
|
{
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
const frect_t *hitbox_bounds = &((hitbox_component_data_t *)physics_system_data->hitbox_component->data)->bounds;
|
const frect_t *hitbox_bounds = &((hitbox_component_data_t *)physics_system_data->hitbox_component->data)->bounds;
|
||||||
|
|
@ -198,7 +198,7 @@ static inline int action_detect_activate_interact(elem_t *elem, void *arg)
|
||||||
if(interact_component_interact(target_interact_component)) return_failure_int;
|
if(interact_component_interact(target_interact_component)) return_failure_int;
|
||||||
}
|
}
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int player_system_process_interaction(player_system_data_t *system_data)
|
static inline int player_system_process_interaction(player_system_data_t *system_data)
|
||||||
|
|
@ -212,5 +212,5 @@ static inline int player_system_process_interaction(player_system_data_t *system
|
||||||
|
|
||||||
last_state = game.inputs.keys[KEY_INTERACT];
|
last_state = game.inputs.keys[KEY_INTERACT];
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ inline int sprite_component_init(component_t *component)
|
||||||
if(!component_data->transform_component)
|
if(!component_data->transform_component)
|
||||||
{
|
{
|
||||||
error_printf("Sprite component require a transform component.");
|
error_printf("Sprite component require a transform component.");
|
||||||
return EXIT_FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
transform_component_data_t *transform_component_data = component_data->transform_component->data;
|
transform_component_data_t *transform_component_data = component_data->transform_component->data;
|
||||||
|
|
@ -26,7 +26,7 @@ inline int sprite_component_init(component_t *component)
|
||||||
|
|
||||||
component_data->flip = false;
|
component_data->flip = false;
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int sprite_component_update(component_t *component)
|
inline int sprite_component_update(component_t *component)
|
||||||
|
|
@ -37,7 +37,7 @@ inline int sprite_component_update(component_t *component)
|
||||||
frect_to_rect(&transform_component_data->bounds, &component_data->dst_rect);
|
frect_to_rect(&transform_component_data->bounds, &component_data->dst_rect);
|
||||||
component->entity->draw_priority = transform_component_data->bounds.y + transform_component_data->bounds.h;
|
component->entity->draw_priority = transform_component_data->bounds.y + transform_component_data->bounds.h;
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int sprite_component_draw(const component_t *component)
|
inline int sprite_component_draw(const component_t *component)
|
||||||
|
|
@ -46,7 +46,7 @@ inline int sprite_component_draw(const component_t *component)
|
||||||
|
|
||||||
if(display_draw_texture(component_data->texture, &component_data->src_rect, &component_data->dst_rect, component_data->flip)) return_failure_int;
|
if(display_draw_texture(component_data->texture, &component_data->src_rect, &component_data->dst_rect, component_data->flip)) return_failure_int;
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int sprite_component_destroy(component_t *component)
|
inline int sprite_component_destroy(component_t *component)
|
||||||
|
|
@ -55,5 +55,5 @@ inline int sprite_component_destroy(component_t *component)
|
||||||
|
|
||||||
free(component_data);
|
free(component_data);
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,12 +16,12 @@ inline int transform_component_init(component_t *component)
|
||||||
.h = 32.0f
|
.h = 32.0f
|
||||||
};
|
};
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int transform_component_update(component_t *component __attribute__((unused)))
|
inline int transform_component_update(component_t *component __attribute__((unused)))
|
||||||
{
|
{
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if DEBUG >= 2
|
#if DEBUG >= 2
|
||||||
|
|
@ -31,9 +31,9 @@ inline int transform_component_draw(const component_t *component)
|
||||||
{
|
{
|
||||||
const transform_component_data_t *component_data = component->data;
|
const transform_component_data_t *component_data = component->data;
|
||||||
|
|
||||||
if(display_draw_frect(&component_data->bounds, C_BLUE, 128)) return_failure_int;
|
if(display_draw_frect(&component_data->bounds, COLOR_BLUE, 128)) return_failure_int;
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
#endif // DEBUG >= 2
|
#endif // DEBUG >= 2
|
||||||
|
|
||||||
|
|
@ -43,5 +43,5 @@ inline int transform_component_destroy(component_t *component)
|
||||||
|
|
||||||
free(component_data);
|
free(component_data);
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -129,7 +129,7 @@ int game_init(void)
|
||||||
*/
|
*/
|
||||||
game.is_running = true;
|
game.is_running = true;
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void game_handle_event(void)
|
void game_handle_event(void)
|
||||||
|
|
@ -158,7 +158,7 @@ int game_update(void)
|
||||||
|
|
||||||
camera_update();
|
camera_update();
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int game_render(void)
|
int game_render(void)
|
||||||
|
|
@ -200,7 +200,7 @@ int game_render(void)
|
||||||
return_failure_int;
|
return_failure_int;
|
||||||
}
|
}
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int game_exit(void)
|
int game_exit(void)
|
||||||
|
|
@ -210,5 +210,5 @@ int game_exit(void)
|
||||||
if(event_bus_exit()) return_failure_int;
|
if(event_bus_exit()) return_failure_int;
|
||||||
display_exit();
|
display_exit();
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue