From b95cff5f0c5271c095ecffdba977b493572531e8 Mon Sep 17 00:00:00 2001 From: Abdelrahman Date: Sat, 24 Dec 2022 00:44:31 +0000 Subject: [PATCH] Updated the aliases and switched from u64 to size_t in the for loops --- include/aliases.h | 1 + src/AssetManager.c | 11 ++++++----- src/GameEngine.c | 9 +++++---- src/ObjectStore.c | 4 ++-- src/reusable_ids.c | 3 ++- 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/include/aliases.h b/include/aliases.h index 9ed6d99..66e6ab0 100644 --- a/include/aliases.h +++ b/include/aliases.h @@ -8,6 +8,7 @@ extern "C" { #endif // !__cplusplus #define INTERNAL static +#define STATIC_DURATION static #define i8 int8_t #define i16 int16_t diff --git a/src/AssetManager.c b/src/AssetManager.c index ac1ee9b..ae46db0 100644 --- a/src/AssetManager.c +++ b/src/AssetManager.c @@ -9,6 +9,7 @@ #include "constants.h" #include "reusable_ids.h" #include +#include #include #include #include @@ -51,7 +52,7 @@ u64 hash_path(const char *path) { u64 i = 0; - for (u64 j = 0; path[j]; ++j) { + for (size_t j = 0; path[j]; ++j) { i += (u64)path[j] * HASH_PRIME_01 % MAX_ASSET_COUNT; } @@ -72,7 +73,7 @@ void insert_id_node(IDNodeList *node_list, AssetID id) { } IDNode *last_node = node_list->start_node; - for (u64 i = 1; i < node_list->node_count; ++i) { + for (size_t i = 1; i < node_list->node_count; ++i) { last_node = last_node->next; } @@ -98,7 +99,7 @@ void remove_id_node(IDNodeList *node_list, AssetID id) { IDNode *node = NULL; IDNode *prev = NULL; IDNode *current = node_list->start_node; - for (u64 i = 0; i < node_list->node_count; ++i) { + for (size_t i = 0; i < node_list->node_count; ++i) { if (current->id == id) { node = current; break; @@ -138,7 +139,7 @@ AssetID get_asset_id_from_id_node(AssetManager *am, IDNodeList *node_list, } IDNode *id_node = node_list->start_node; - for (u64 i = 0; i < node_list->node_count; ++i) { + for (size_t i = 0; i < node_list->node_count; ++i) { if (!id_node) { break; } @@ -379,7 +380,7 @@ 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 (u64 i = 0; i < MAX_ASSET_COUNT; ++i) { + for (size_t i = 0; i < MAX_ASSET_COUNT; ++i) { if (!(*am)->assets[i].path) { continue; } diff --git a/src/GameEngine.c b/src/GameEngine.c index 99b1f1c..178a8da 100644 --- a/src/GameEngine.c +++ b/src/GameEngine.c @@ -22,6 +22,7 @@ #include "engine_build_config.h" #include "reusable_ids.h" #include +#include #include #include @@ -467,7 +468,7 @@ void pause_all_instances_of_audio_asset(AssetID id) { u64 channel_count = Mix_AllocateChannels(-1); - for (u64 i = 0; i < channel_count; ++i) { + for (size_t i = 0; i < channel_count; ++i) { if (chunk == Mix_GetChunk(i)) { Mix_Pause(i); } @@ -486,7 +487,7 @@ void resume_all_instances_of_audio_asset(AssetID id) { u64 channel_count = Mix_AllocateChannels(-1); - for (u64 i = 0; i < channel_count; ++i) { + for (size_t i = 0; i < channel_count; ++i) { if (chunk == Mix_GetChunk(i)) { Mix_Resume(i); } @@ -505,7 +506,7 @@ void stop_all_instances_of_audio_asset(AssetID id) { u64 channel_count = Mix_AllocateChannels(-1); - for (u64 i = 0; i < channel_count; ++i) { + for (size_t i = 0; i < channel_count; ++i) { if (chunk == Mix_GetChunk(i)) { Mix_HaltChannel(i); } @@ -524,7 +525,7 @@ void fade_out_all_instances_of_audio_asset(AssetID id, u32 fade_length_in_ms) { u64 channel_count = Mix_AllocateChannels(-1); - for (u64 i = 0; i < channel_count; ++i) { + for (size_t i = 0; i < channel_count; ++i) { if (chunk == Mix_GetChunk(i)) { Mix_FadeOutChannel(i, fade_length_in_ms); } diff --git a/src/ObjectStore.c b/src/ObjectStore.c index 5708279..c2445a9 100644 --- a/src/ObjectStore.c +++ b/src/ObjectStore.c @@ -46,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 (u64 i = 0; i < MAX_OBJ_COUNT; ++i) { + for (size_t i = 0; i < MAX_OBJ_COUNT; ++i) { if (object == os->object_ptrs[i]) { return true; } @@ -150,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 (u64 i = 0; i < MAX_OBJ_COUNT; ++i) { + for (size_t 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/reusable_ids.c b/src/reusable_ids.c index ed89bd9..3d19e33 100644 --- a/src/reusable_ids.c +++ b/src/reusable_ids.c @@ -1,10 +1,11 @@ #include "reusable_ids.h" #include "aliases.h" +#include i32 reuse_id(i32 *ids, u64 count) { i32 id = ids[0]; - for (u64 i = 0; i < count; ++i) { + for (size_t i = 0; i < count; ++i) { // Remove the first id and make sure the remaining ones are packed ids[i] = ids[i + 1]; }