Give in to popular demand and also export ScheduledTask_Add

Also export Keybind_IsPressed
This commit is contained in:
UnknownShadow200 2020-06-13 13:12:35 +10:00
parent c0545de38b
commit 3861b0bd10
4 changed files with 18 additions and 16 deletions

View File

@ -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;
}
}

View File

@ -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

View File

@ -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);

View File

@ -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;
};