From 3861b0bd1052bb01f716f845bcf60b03592564f6 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sat, 13 Jun 2020 13:12:35 +1000 Subject: [PATCH] Give in to popular demand and also export ScheduledTask_Add Also export Keybind_IsPressed --- src/Game.c | 27 +++++++++++++++------------ src/Game.h | 4 ++-- src/Input.h | 2 +- src/Stream.h | 1 - 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/Game.c b/src/Game.c index cabcaed56..c7aa1fa50 100644 --- a/src/Game.c +++ b/src/Game.c @@ -54,9 +54,6 @@ cc_bool Game_AllowServerTextures; cc_bool Game_ViewBobbing, Game_HideGui; cc_bool Game_BreakableLiquids, Game_ScreenshotRequested; -static struct ScheduledTask tasks[6]; -static int tasksCount, entTaskI; - static char usernameBuffer[FILENAME_SIZE]; static char mppassBuffer[STRING_SIZE]; String Game_Username = String_FromArray(usernameBuffer); @@ -72,15 +69,22 @@ void Game_AddComponent(struct IGameComponent* comp) { LinkedList_Add(comp, comps_head, comps_tail); } +#define TASKS_DEF_ELEMS 6 +static struct ScheduledTask defaultTasks[TASKS_DEF_ELEMS]; +static int tasksCapacity = TASKS_DEF_ELEMS, tasksCount, entTaskI; +static struct ScheduledTask* tasks = defaultTasks; + int ScheduledTask_Add(double interval, ScheduledTaskCallback callback) { struct ScheduledTask task; task.accumulator = 0.0; task.interval = interval; task.Callback = callback; - if (tasksCount == Array_Elems(tasks)) { - Logger_Abort("ScheduledTask_Add - hit max count"); + if (tasksCount == tasksCapacity) { + Utils_Resize((void**)&tasks, &tasksCapacity, + sizeof(struct ScheduledTask), TASKS_DEF_ELEMS, TASKS_DEF_ELEMS); } + tasks[tasksCount++] = task; return tasksCount - 1; } @@ -493,18 +497,17 @@ static void Game_Render3D(double delta, float t) { } static void PerformScheduledTasks(double time) { - struct ScheduledTask task; + struct ScheduledTask* task; int i; for (i = 0; i < tasksCount; i++) { - task = tasks[i]; - task.accumulator += time; + task = &tasks[i]; + task->accumulator += time; - while (task.accumulator >= task.interval) { - task.Callback(&task); - task.accumulator -= task.interval; + while (task->accumulator >= task->interval) { + task->Callback(task); + task->accumulator -= task->interval; } - tasks[i] = task; } } diff --git a/src/Game.h b/src/Game.h index 35a082ad1..6dcdf12c4 100644 --- a/src/Game.h +++ b/src/Game.h @@ -111,6 +111,6 @@ struct ScheduledTask { }; typedef void (*ScheduledTaskCallback)(struct ScheduledTask* task); -/* Adds a component to list of scheduled tasks. (always at end) */ -CC_NOINLINE int ScheduledTask_Add(double interval, ScheduledTaskCallback callback); +/* Adds a task to list of scheduled tasks. (always at end) */ +CC_API int ScheduledTask_Add(double interval, ScheduledTaskCallback callback); #endif diff --git a/src/Input.h b/src/Input.h index 16eeb3cb2..0bf1dfa85 100644 --- a/src/Input.h +++ b/src/Input.h @@ -121,7 +121,7 @@ extern cc_uint8 KeyBinds[KEYBIND_COUNT]; extern const cc_uint8 KeyBind_Defaults[KEYBIND_COUNT]; /* Gets whether the key bound to the given key binding is pressed. */ -cc_bool KeyBind_IsPressed(KeyBind binding); +CC_API cc_bool KeyBind_IsPressed(KeyBind binding); /* Set the key that the given key binding is bound to. (also updates options list) */ void KeyBind_Set(KeyBind binding, int key); diff --git a/src/Stream.h b/src/Stream.h index e90523621..47d987010 100644 --- a/src/Stream.h +++ b/src/Stream.h @@ -34,7 +34,6 @@ struct Stream { struct { cc_uint8* Cur; cc_uint32 Left, Length; cc_uint8* Base; } Mem; struct { struct Stream* Source; cc_uint32 Left, Length; } Portion; struct { cc_uint8* Cur; cc_uint32 Left, Length; cc_uint8* Base; struct Stream* Source; cc_uint32 End; } Buffered; - struct { cc_uint8* Cur; cc_uint32 Left, Last; cc_uint8* Base; struct Stream* Source; } Ogg; struct { struct Stream* Source; cc_uint32 CRC32; } CRC32; } Meta; };