diff --git a/include/GameEngine.h b/include/GameEngine.h index d1da857..2f6c53e 100644 --- a/include/GameEngine.h +++ b/include/GameEngine.h @@ -7,8 +7,8 @@ #include "SDL_pixels.h" #include "Window.h" #include "reusable_ids.h" +#include #include -#include #ifdef __cplusplus extern "C" { @@ -24,12 +24,12 @@ extern "C" { */ bool init_engine(const char *game_name, WindowSize window_size, SDL_Color window_background_color, bool full_screen, - uint8_t audio_tracks); + u8 audio_tracks); bool game_running(); void close_engine(); -int64_t get_time(); +i64 get_time(); // END GENERAL ENGINE API // ASSET MANAGEMENT API @@ -75,40 +75,37 @@ void clip_render_rects_to_drawing_area(RenderRect *src, RenderRect *dest); RenderRect get_texture_asset_rect(AssetID id); void render_texture_asset(AssetID id, RenderRect *src, RenderRect *dest); TextSize get_text_size_from_font_asset(AssetID id, const char *text); -void render_text_with_font_asset(AssetID id, const char *text, float x, float y, +void render_text_with_font_asset(AssetID id, const char *text, f32 x, f32 y, SDL_Color color); -void set_font_asset_size(AssetID id, uint32_t size); +void set_font_asset_size(AssetID id, u32 size); // END RENDERING API // AUDIO API -int8_t play_audio_asset(AssetID id, int16_t loops, bool fade_in, - uint32_t fade_length_in_ms); -void pause_audio_asset_on_track(AssetID id, uint8_t track); -void resume_audio_asset_on_track(AssetID id, uint8_t track); -void stop_audio_asset_on_track(AssetID id, uint8_t track); -void fade_out_audio_asset_on_track(AssetID id, uint8_t track, - uint32_t fade_length_in_ms); +i8 play_audio_asset(AssetID id, i16 loops, bool fade_in, u32 fade_length_in_ms); +void pause_audio_asset_on_track(AssetID id, u8 track); +void resume_audio_asset_on_track(AssetID id, u8 track); +void stop_audio_asset_on_track(AssetID id, u8 track); +void fade_out_audio_asset_on_track(AssetID id, u8 track, u32 fade_length_in_ms); void pause_all_instances_of_audio_asset(AssetID id); void resume_all_instances_of_audio_asset(AssetID id); void stop_all_instances_of_audio_asset(AssetID id); -void fade_out_all_instances_of_audio_asset(AssetID id, - uint32_t fade_length_in_ms); -int8_t get_audio_asset_volume(AssetID id); -void set_audio_asset_volume(AssetID id, int8_t volume); -void play_music_asset(AssetID id, int16_t loops, bool fade_in, - uint32_t fade_length_in_ms); +void fade_out_all_instances_of_audio_asset(AssetID id, u32 fade_length_in_ms); +i8 get_audio_asset_volume(AssetID id); +void set_audio_asset_volume(AssetID id, i8 volume); +void play_music_asset(AssetID id, i16 loops, bool fade_in, + u32 fade_length_in_ms); void pause_music_asset(AssetID id); void resume_music_asset(AssetID id); void stop_music_asset(AssetID id); -void fade_out_music_asset(AssetID id, uint32_t fade_length_in_ms); -int8_t get_music_asset_volume(AssetID id); -void set_music_asset_volume(AssetID id, int8_t volume); +void fade_out_music_asset(AssetID id, u32 fade_length_in_ms); +i8 get_music_asset_volume(AssetID id); +void set_music_asset_volume(AssetID id, i8 volume); bool is_music_asset_playing(AssetID id); void pause_playing_music(); void resume_playing_music(); void stop_playing_music(); -void fade_out_playing_music(uint32_t fade_length_in_ms); -void set_playing_music_volume(int8_t volume); +void fade_out_playing_music(u32 fade_length_in_ms); +void set_playing_music_volume(i8 volume); bool is_music_playing(); // END AUDIO API diff --git a/include/ObjectStore.h b/include/ObjectStore.h index 25466bd..fae95f2 100644 --- a/include/ObjectStore.h +++ b/include/ObjectStore.h @@ -3,16 +3,16 @@ #include "Renderer.h" #include "SDL_events.h" +#include "aliases.h" #include "engine_build_config.h" #include "reusable_ids.h" -#include #ifdef __cplusplus extern "C" { #endif // !__cplusplus typedef void (*EventHandlerPtr)(void *object, const SDL_Event *event); -typedef void (*UpdateFuncPtr)(void *object, float delta); +typedef void (*UpdateFuncPtr)(void *object, f32 delta); typedef void (*RenderFuncPtr)(void *object); typedef struct object_store ObjectStore; @@ -40,7 +40,7 @@ ObjectID add_object_to_store(ObjectStore *os, void *object, EventHandlerPtr eh, void remove_object_from_store(ObjectStore *os, ObjectID *id_ptr); void handle_all_objects_events(ObjectStore *os, const SDL_Event *event); -void update_all_objects(ObjectStore *os, float delta); +void update_all_objects(ObjectStore *os, f32 delta); void render_all_objects(ObjectStore *os); /** diff --git a/include/Renderer.h b/include/Renderer.h index 9c5149f..45125c4 100644 --- a/include/Renderer.h +++ b/include/Renderer.h @@ -6,8 +6,8 @@ #include "SDL_render.h" #include "SDL_surface.h" #include "SDL_video.h" +#include "aliases.h" #include -#include #ifdef __cplusplus extern "C" { @@ -16,15 +16,15 @@ extern "C" { typedef struct renderer Renderer; typedef struct { - int32_t width; - int32_t height; + i32 width; + i32 height; } TextSize; typedef struct { - float x; - float y; - float width; - float height; + f32 x; + f32 y; + f32 width; + f32 height; } RenderRect; /** @@ -40,14 +40,14 @@ Renderer *create_renderer(SDL_Window *window); * Useful when rendering on screens that support high DPI since the drawable * area is usually bigger than the user-defined size. */ -void get_render_output_size(Renderer *renderer, int32_t *w, int32_t *h); +void get_render_output_size(Renderer *renderer, i32 *w, i32 *h); void set_render_draw_color(const Renderer *renderer, SDL_Color color); void render_clear(const Renderer *renderer, SDL_Color color); -void draw_rect(const Renderer *renderer, SDL_Color color, float x, float y, - float w, float h); -void fill_rect(const Renderer *renderer, SDL_Color color, float x, float y, - float w, float h); +void draw_rect(const Renderer *renderer, SDL_Color color, f32 x, f32 y, f32 w, + f32 h); +void fill_rect(const Renderer *renderer, SDL_Color color, f32 x, f32 y, f32 w, + f32 h); void render_surface(const Renderer *renderer, SDL_Surface *surface, const RenderRect *dest); void render_texture(const Renderer *renderer, SDL_Texture *texture, diff --git a/include/Window.h b/include/Window.h index 7817155..191cef4 100644 --- a/include/Window.h +++ b/include/Window.h @@ -5,22 +5,21 @@ #include "SDL.h" #include "SDL_pixels.h" #include -#include #ifdef __cplusplus extern "C" { #endif // !__cplusplus typedef struct window_size { - int32_t width; - int32_t height; + i32 width; + i32 height; } WindowSize; typedef struct drawing_area { - float x; - float y; - float width; - float height; + f32 x; + f32 y; + f32 width; + f32 height; } WindowDrawingArea; typedef struct window { diff --git a/include/aliases.h b/include/aliases.h index 50a6b8c..9ed6d99 100644 --- a/include/aliases.h +++ b/include/aliases.h @@ -1,12 +1,27 @@ #ifndef ALIASES_H #define ALIASES_H +#include + #ifdef __cplusplus extern "C" { #endif // !__cplusplus #define INTERNAL static +#define i8 int8_t +#define i16 int16_t +#define i32 int32_t +#define i64 int64_t + +#define u8 uint8_t +#define u16 uint16_t +#define u32 uint32_t +#define u64 uint64_t + +#define f32 float +#define f64 double + #ifdef __cplusplus } #endif // !__cplusplus diff --git a/include/math_utils.h b/include/math_utils.h index 295580f..dc02e8b 100644 --- a/include/math_utils.h +++ b/include/math_utils.h @@ -1,14 +1,14 @@ #ifndef MATH_UTILS_H #define MATH_UTILS_H -#include +#include "aliases.h" #ifdef __cplusplus extern "C" { #endif // !__cplusplus -int32_t max_int(int32_t a, int32_t b); -int32_t min_int(int32_t a, int32_t b); +i32 max_int(i32 a, i32 b); +i32 min_int(i32 a, i32 b); #ifdef __cplusplus } diff --git a/include/reusable_ids.h b/include/reusable_ids.h index 9116ff2..e8269ab 100644 --- a/include/reusable_ids.h +++ b/include/reusable_ids.h @@ -1,8 +1,7 @@ #ifndef REUSABLE_IDS_H #define REUSABLE_IDS_H -#include -#include +#include "aliases.h" #ifdef __cplusplus extern "C" { @@ -10,10 +9,10 @@ extern "C" { #define INVALID_ID -1 -typedef int32_t ObjectID; -typedef int32_t AssetID; +typedef i32 ObjectID; +typedef i32 AssetID; -int32_t reuse_id(int32_t *ids, size_t count); +i32 reuse_id(i32 *ids, u64 count); #ifdef __cplusplus } diff --git a/src/AssetManager.c b/src/AssetManager.c index cff6b47..ac1ee9b 100644 --- a/src/AssetManager.c +++ b/src/AssetManager.c @@ -5,11 +5,10 @@ #include "SDL_mixer.h" #include "SDL_render.h" #include "SDL_ttf.h" +#include "aliases.h" #include "constants.h" #include "reusable_ids.h" #include -#include -#include #include #include #include @@ -33,27 +32,27 @@ struct id_node { typedef struct id_node_list { IDNode *start_node; - size_t node_count; + u64 node_count; } IDNodeList; struct asset_manager { - size_t count; - size_t deleted_count; + u64 count; + u64 deleted_count; AssetID reusable_ids[MAX_ASSET_COUNT]; Asset assets[MAX_ASSET_COUNT]; - size_t user_counter[MAX_ASSET_COUNT]; + u64 user_counter[MAX_ASSET_COUNT]; IDNodeList hashed_path_ids[MAX_ASSET_COUNT]; }; -size_t hash_path(const char *path) { +u64 hash_path(const char *path) { /** * Converts a string into a numerical index using a simple hashing algorithm */ - size_t i = 0; + u64 i = 0; - for (size_t j = 0; path[j]; ++j) { - i += (size_t)path[j] * HASH_PRIME_01 % MAX_ASSET_COUNT; + for (u64 j = 0; path[j]; ++j) { + i += (u64)path[j] * HASH_PRIME_01 % MAX_ASSET_COUNT; } i = (i * HASH_PRIME_02) % MAX_ASSET_COUNT; @@ -73,7 +72,7 @@ void insert_id_node(IDNodeList *node_list, AssetID id) { } IDNode *last_node = node_list->start_node; - for (size_t i = 1; i < node_list->node_count; ++i) { + for (u64 i = 1; i < node_list->node_count; ++i) { last_node = last_node->next; } @@ -99,7 +98,7 @@ void remove_id_node(IDNodeList *node_list, AssetID id) { IDNode *node = NULL; IDNode *prev = NULL; IDNode *current = node_list->start_node; - for (size_t i = 0; i < node_list->node_count; ++i) { + for (u64 i = 0; i < node_list->node_count; ++i) { if (current->id == id) { node = current; break; @@ -139,7 +138,7 @@ AssetID get_asset_id_from_id_node(AssetManager *am, IDNodeList *node_list, } IDNode *id_node = node_list->start_node; - for (size_t i = 0; i < node_list->node_count; ++i) { + for (u64 i = 0; i < node_list->node_count; ++i) { if (!id_node) { break; } @@ -178,7 +177,7 @@ AssetID load_asset_to_manager(AssetManager *am, const char *path, return INVALID_ID; } - size_t hash_index = hash_path(path); + u64 hash_index = hash_path(path); AssetID existing_id = get_asset_id_from_id_node(am, &(am->hashed_path_ids[hash_index]), path); @@ -255,7 +254,7 @@ AssetID load_asset_to_manager(AssetManager *am, const char *path, AssetID id; if (am->deleted_count > 0) { - id = (AssetID)reuse_id((int32_t *)am->reusable_ids, am->deleted_count); + id = (AssetID)reuse_id((i32 *)am->reusable_ids, am->deleted_count); am->deleted_count -= 1; am->count += 1; } else { @@ -308,7 +307,7 @@ void remove_asset_from_manager(AssetManager *am, AssetID *id_ptr) { return; } - size_t hash_index = hash_path(am->assets[id].path); + u64 hash_index = hash_path(am->assets[id].path); remove_id_node(&(am->hashed_path_ids[hash_index]), id); free(am->assets[id].path); @@ -380,14 +379,14 @@ void destroy_asset_manager(AssetManager **am) { // TODO (Abdelrahman): Figure out if there is a better way to remove all of // the existing assets without having to loop for the maximum number of // assets allowed. - for (size_t i = 0; i < MAX_ASSET_COUNT; ++i) { + for (u64 i = 0; i < MAX_ASSET_COUNT; ++i) { if (!(*am)->assets[i].path) { continue; } (*am)->user_counter[i] = 0; - size_t hash_index = hash_path((*am)->assets[i].path); + u64 hash_index = hash_path((*am)->assets[i].path); remove_id_node(&((*am)->hashed_path_ids[hash_index]), i); free((*am)->assets[i].path); diff --git a/src/GameEngine.c b/src/GameEngine.c index 6f7ec46..814e1dc 100644 --- a/src/GameEngine.c +++ b/src/GameEngine.c @@ -22,8 +22,6 @@ #include "engine_build_config.h" #include "reusable_ids.h" #include -#include -#include #include #include @@ -33,8 +31,8 @@ INTERNAL struct game_engine { bool running; - float delta; - uint64_t last_time; + f32 delta; + u64 last_time; Window window; SDL_Event event; ObjectStore *object_store; @@ -43,7 +41,7 @@ INTERNAL struct game_engine { bool init_engine(const char *game_name, WindowSize window_size, SDL_Color window_background_color, bool full_screen, - uint8_t audio_tracks) { + u8 audio_tracks) { bool initialisation_complete = true; const char *current_platform = SDL_GetPlatform(); @@ -59,7 +57,7 @@ bool init_engine(const char *game_name, WindowSize window_size, return false; } - uint32_t img_flags = IMG_INIT_PNG; + u32 img_flags = IMG_INIT_PNG; if (strcmp(current_platform, "Android") != 0) { // Apparently, Android devices don't support TIFF images, so we only enable // TIFF support when we are not running Android. @@ -177,7 +175,7 @@ void close_engine() { #endif /* DEBUG_ENGINE */ } -int64_t get_time() { return SDL_GetTicks64(); } +i64 get_time() { return SDL_GetTicks64(); } ObjectID add_object(void *object, EventHandlerPtr event_handler, UpdateFuncPtr update_func, RenderFuncPtr render_func) { @@ -252,10 +250,10 @@ void clip_render_rects_to_drawing_area(RenderRect *src, RenderRect *dest) { return; } - float x_offset = 0.0f; - float y_offset = 0.0f; - float x_clip = 0.0f; - float y_clip = 0.0f; + f32 x_offset = 0.0f; + f32 y_offset = 0.0f; + f32 x_clip = 0.0f; + f32 y_clip = 0.0f; // If the rectangle is partially out of the horizontal bounds of the drawing // area, calculate how much of its width will be clipped @@ -302,8 +300,8 @@ RenderRect get_texture_asset_rect(AssetID id) { SDL_Texture *texture = get_texture(GameEngine.asset_manager, id); if (texture) { - int32_t w = 0; - int32_t h = 0; + i32 w = 0; + i32 h = 0; if (SDL_QueryTexture(texture, NULL, NULL, &w, &h) == 0) { rect.width = w; rect.height = h; @@ -344,7 +342,7 @@ TextSize get_text_size_from_font_asset(AssetID id, const char *text) { return output; } -void render_text_with_font_asset(AssetID id, const char *text, float x, float y, +void render_text_with_font_asset(AssetID id, const char *text, f32 x, f32 y, SDL_Color color) { if (id < 0) { return; @@ -361,8 +359,8 @@ void render_text_with_font_asset(AssetID id, const char *text, float x, float y, } // Get the width and height, in pixels, of the text rendered using the font - int32_t w = 0; - int32_t h = 0; + i32 w = 0; + i32 h = 0; TTF_SizeText(font, text, &w, &h); RenderRect rect = {x, y, w, h}; @@ -373,7 +371,7 @@ void render_text_with_font_asset(AssetID id, const char *text, float x, float y, surface = NULL; } -void set_font_asset_size(AssetID id, uint32_t size) { +void set_font_asset_size(AssetID id, u32 size) { if (id < 0) { return; } @@ -386,8 +384,8 @@ void set_font_asset_size(AssetID id, uint32_t size) { TTF_SetFontSize(font, size); } -int8_t play_audio_asset(AssetID id, int16_t loops, bool fade_in, - uint32_t fade_length_in_ms) { +i8 play_audio_asset(AssetID id, i16 loops, bool fade_in, + u32 fade_length_in_ms) { if (id < 0) { return -1; } @@ -404,7 +402,7 @@ int8_t play_audio_asset(AssetID id, int16_t loops, bool fade_in, } } -void pause_audio_asset_on_track(AssetID id, uint8_t track) { +void pause_audio_asset_on_track(AssetID id, u8 track) { if (id < 0) { return; } @@ -417,7 +415,7 @@ void pause_audio_asset_on_track(AssetID id, uint8_t track) { Mix_Pause(track); } -void resume_audio_asset_on_track(AssetID id, uint8_t track) { +void resume_audio_asset_on_track(AssetID id, u8 track) { if (id < 0) { return; } @@ -430,7 +428,7 @@ void resume_audio_asset_on_track(AssetID id, uint8_t track) { Mix_Resume(track); } -void stop_audio_asset_on_track(AssetID id, uint8_t track) { +void stop_audio_asset_on_track(AssetID id, u8 track) { if (id < 0) { return; } @@ -443,8 +441,8 @@ void stop_audio_asset_on_track(AssetID id, uint8_t track) { Mix_HaltChannel(track); } -void fade_out_audio_asset_on_track(AssetID id, uint8_t track, - uint32_t fade_length_in_ms) { +void fade_out_audio_asset_on_track(AssetID id, u8 track, + u32 fade_length_in_ms) { if (id < 0) { return; } @@ -467,9 +465,9 @@ void pause_all_instances_of_audio_asset(AssetID id) { return; } - size_t channel_count = Mix_AllocateChannels(-1); + u64 channel_count = Mix_AllocateChannels(-1); - for (size_t i = 0; i < channel_count; ++i) { + for (u64 i = 0; i < channel_count; ++i) { if (chunk == Mix_GetChunk(i)) { Mix_Pause(i); } @@ -486,9 +484,9 @@ void resume_all_instances_of_audio_asset(AssetID id) { return; } - size_t channel_count = Mix_AllocateChannels(-1); + u64 channel_count = Mix_AllocateChannels(-1); - for (size_t i = 0; i < channel_count; ++i) { + for (u64 i = 0; i < channel_count; ++i) { if (chunk == Mix_GetChunk(i)) { Mix_Resume(i); } @@ -505,17 +503,16 @@ void stop_all_instances_of_audio_asset(AssetID id) { return; } - size_t channel_count = Mix_AllocateChannels(-1); + u64 channel_count = Mix_AllocateChannels(-1); - for (size_t i = 0; i < channel_count; ++i) { + for (u64 i = 0; i < channel_count; ++i) { if (chunk == Mix_GetChunk(i)) { Mix_HaltChannel(i); } } } -void fade_out_all_instances_of_audio_asset(AssetID id, - uint32_t fade_length_in_ms) { +void fade_out_all_instances_of_audio_asset(AssetID id, u32 fade_length_in_ms) { if (id < 0) { return; } @@ -525,16 +522,16 @@ void fade_out_all_instances_of_audio_asset(AssetID id, return; } - size_t channel_count = Mix_AllocateChannels(-1); + u64 channel_count = Mix_AllocateChannels(-1); - for (size_t i = 0; i < channel_count; ++i) { + for (u64 i = 0; i < channel_count; ++i) { if (chunk == Mix_GetChunk(i)) { Mix_FadeOutChannel(i, fade_length_in_ms); } } } -int8_t get_audio_asset_volume(AssetID id) { +i8 get_audio_asset_volume(AssetID id) { if (id < 0) { return -1; } @@ -547,7 +544,7 @@ int8_t get_audio_asset_volume(AssetID id) { return chunk->volume; } -void set_audio_asset_volume(AssetID id, int8_t volume) { +void set_audio_asset_volume(AssetID id, i8 volume) { if (id < 0) { return; } @@ -560,8 +557,8 @@ void set_audio_asset_volume(AssetID id, int8_t volume) { Mix_VolumeChunk(chunk, volume); } -void play_music_asset(AssetID id, int16_t loops, bool fade_in, - uint32_t fade_length_in_ms) { +void play_music_asset(AssetID id, i16 loops, bool fade_in, + u32 fade_length_in_ms) { if (id < 0 || is_music_asset_playing(id)) { return; } @@ -617,7 +614,7 @@ void stop_music_asset(AssetID id) { Mix_HaltMusic(); } -void fade_out_music_asset(AssetID id, uint32_t fade_length_in_ms) { +void fade_out_music_asset(AssetID id, u32 fade_length_in_ms) { if (id < 0 || !is_music_asset_playing(id)) { return; } @@ -630,7 +627,7 @@ void fade_out_music_asset(AssetID id, uint32_t fade_length_in_ms) { Mix_FadeOutMusic(fade_length_in_ms); } -int8_t get_music_asset_volume(AssetID id) { +i8 get_music_asset_volume(AssetID id) { if (id < 0) { return -1; } @@ -643,7 +640,7 @@ int8_t get_music_asset_volume(AssetID id) { return Mix_GetMusicVolume(music); } -void set_music_asset_volume(AssetID id, int8_t volume) { +void set_music_asset_volume(AssetID id, i8 volume) { if (id < 0 || !is_music_asset_playing(id)) { return; } @@ -693,11 +690,11 @@ void resume_playing_music() { Mix_ResumeMusic(); } void stop_playing_music() { Mix_HaltMusic(); } -void fade_out_playing_music(uint32_t fade_length_in_ms) { +void fade_out_playing_music(u32 fade_length_in_ms) { Mix_FadeOutMusic(fade_length_in_ms); } -void set_playing_music_volume(int8_t volume) { Mix_VolumeMusic(volume); } +void set_playing_music_volume(i8 volume) { Mix_VolumeMusic(volume); } bool is_music_playing() { return Mix_PlayingMusic(); } @@ -726,7 +723,7 @@ void update() { return; } - uint64_t current_time = SDL_GetTicks64(); + u64 current_time = SDL_GetTicks64(); // Get the delta time in seconds since the SDL_GetTicks64() returns the // time in milliseconds diff --git a/src/ObjectStore.c b/src/ObjectStore.c index d207972..5708279 100644 --- a/src/ObjectStore.c +++ b/src/ObjectStore.c @@ -1,4 +1,5 @@ #include "ObjectStore.h" +#include "aliases.h" #include "constants.h" #include "engine_build_config.h" #include "reusable_ids.h" @@ -13,8 +14,8 @@ #endif /* DEBUG_ENGINE */ struct object_store { - size_t count; - size_t deleted_count; + u64 count; + u64 deleted_count; ObjectID reusable_ids[MAX_OBJ_COUNT]; void *object_ptrs[MAX_OBJ_COUNT]; EventHandlerPtr event_handlers[MAX_OBJ_COUNT]; @@ -45,7 +46,7 @@ bool object_exists(ObjectStore *os, void *object) { // This is a crude implementation for checking that an object has already // been added. // TODO (Abdelrahman): Figure out if there is a better way of doing this - for (size_t i = 0; i < MAX_OBJ_COUNT; ++i) { + for (u64 i = 0; i < MAX_OBJ_COUNT; ++i) { if (object == os->object_ptrs[i]) { return true; } @@ -68,7 +69,7 @@ ObjectID add_object_to_store(ObjectStore *os, void *object, EventHandlerPtr eh, ObjectID id; if (os->deleted_count > 0) { - id = (ObjectID)reuse_id((int32_t *)os->reusable_ids, os->deleted_count); + id = (ObjectID)reuse_id((i32 *)os->reusable_ids, os->deleted_count); os->deleted_count -= 1; os->count += 1; } else { @@ -115,7 +116,7 @@ void handle_all_objects_events(ObjectStore *os, const SDL_Event *event) { } } -void update_all_objects(ObjectStore *os, float delta) { +void update_all_objects(ObjectStore *os, f32 delta) { if (!os || os->count == 0) { return; } @@ -149,7 +150,7 @@ void destroy_object_store(ObjectStore **os) { // TODO (Abdelrahman): Figure out if there is a better way to remove all of // the existing objects without having to loop for the maximum number of // objects allowed. - for (size_t i = 0; i < MAX_OBJ_COUNT; ++i) { + for (u64 i = 0; i < MAX_OBJ_COUNT; ++i) { (*os)->object_ptrs[i] = NULL; (*os)->event_handlers[i] = NULL; (*os)->update_funcs[i] = NULL; diff --git a/src/Renderer.c b/src/Renderer.c index 2696618..d81e4ec 100644 --- a/src/Renderer.c +++ b/src/Renderer.c @@ -6,6 +6,7 @@ #include "SDL_rect.h" #include "SDL_render.h" #include "SDL_video.h" +#include "aliases.h" #include "engine_build_config.h" #include #include @@ -37,7 +38,7 @@ Renderer *create_renderer(SDL_Window *window) { return renderer; } -void get_render_output_size(Renderer *renderer, int32_t *w, int32_t *h) { +void get_render_output_size(Renderer *renderer, i32 *w, i32 *h) { SDL_GetRendererOutputSize(renderer->SDL_base_renderer, w, h); } @@ -57,8 +58,8 @@ void render_clear(const Renderer *renderer, SDL_Color color) { SDL_RenderClear(renderer->SDL_base_renderer); } -void draw_rect(const Renderer *renderer, SDL_Color color, float x, float y, - float w, float h) { +void draw_rect(const Renderer *renderer, SDL_Color color, f32 x, f32 y, f32 w, + f32 h) { SDL_FRect dest = {x, y, w, h}; SDL_SetRenderDrawColor(renderer->SDL_base_renderer, color.r, color.g, color.b, @@ -66,8 +67,8 @@ void draw_rect(const Renderer *renderer, SDL_Color color, float x, float y, SDL_RenderDrawRectF(renderer->SDL_base_renderer, &dest); } -void fill_rect(const Renderer *renderer, SDL_Color color, float x, float y, - float w, float h) { +void fill_rect(const Renderer *renderer, SDL_Color color, f32 x, f32 y, f32 w, + f32 h) { SDL_FRect dest = {x, y, w, h}; SDL_SetRenderDrawColor(renderer->SDL_base_renderer, color.r, color.g, color.b, diff --git a/src/Window.c b/src/Window.c index 585eae1..a5fb49b 100644 --- a/src/Window.c +++ b/src/Window.c @@ -2,6 +2,7 @@ #include "Renderer.h" #include "SDL_platform.h" #include "SDL_video.h" +#include "aliases.h" #include "engine_build_config.h" #include "math_utils.h" #include @@ -94,19 +95,19 @@ bool init_window(Window *wnd, const char *title, WindowSize size, // Fit the window into the screen when running in full screen mode on // a non-mobile platform. Mobile platforms will be handled differently - float window_size_ratio = - (float)wnd->defined_size.width / (float)wnd->defined_size.height; + f32 window_size_ratio = + (f32)wnd->defined_size.width / (f32)wnd->defined_size.height; // Fit the drawing area size to the smallest dimension of the screen and // make sure the drawing area is centered if (wnd->real_size.height <= wnd->real_size.width) { wnd->drawing_area.width = - (int32_t)(window_size_ratio * wnd->real_size.height); + (i32)(window_size_ratio * wnd->real_size.height); wnd->drawing_area.x = 0.0f + ((wnd->real_size.width - wnd->drawing_area.width) / 2.0f); } else { wnd->drawing_area.height = - (int32_t)((float)wnd->real_size.width / window_size_ratio); + (i32)((f32)wnd->real_size.width / window_size_ratio); wnd->drawing_area.y = 0.0f + ((wnd->real_size.height - wnd->drawing_area.height) / 2.0f); } diff --git a/src/math_utils.c b/src/math_utils.c index 52a6107..d32c321 100644 --- a/src/math_utils.c +++ b/src/math_utils.c @@ -1,6 +1,6 @@ #include "math_utils.h" -#include +#include "aliases.h" -int32_t max_int(int32_t a, int32_t b) { return a >= b ? a : b; } +i32 max_int(i32 a, i32 b) { return a >= b ? a : b; } -int32_t min_int(int32_t a, int32_t b) { return a <= b ? a : b; } +i32 min_int(i32 a, i32 b) { return a <= b ? a : b; } diff --git a/src/reusable_ids.c b/src/reusable_ids.c index 0bb6b4a..ed89bd9 100644 --- a/src/reusable_ids.c +++ b/src/reusable_ids.c @@ -1,9 +1,10 @@ #include "reusable_ids.h" +#include "aliases.h" -int32_t reuse_id(int32_t *ids, size_t count) { - int32_t id = ids[0]; +i32 reuse_id(i32 *ids, u64 count) { + i32 id = ids[0]; - for (size_t i = 0; i < count; ++i) { + for (u64 i = 0; i < count; ++i) { // Remove the first id and make sure the remaining ones are packed ids[i] = ids[i + 1]; }