diff options
Diffstat (limited to 'src/code')
| -rw-r--r-- | src/code/PreRender.c | 9 | ||||
| -rw-r--r-- | src/code/sys_slowly.c | 53 |
2 files changed, 39 insertions, 23 deletions
diff --git a/src/code/PreRender.c b/src/code/PreRender.c index 247325251..16ae999c5 100644 --- a/src/code/PreRender.c +++ b/src/code/PreRender.c @@ -1,4 +1,5 @@ #include "global.h" +#include "slowly.h" #include "stack.h" /** @@ -411,7 +412,7 @@ void PreRender_ApplyFilters(PreRender* this) { } } -extern SlowlyTask D_801F6E00; +extern SlowlyMgr sSlowlyMgr; extern s32 D_801F6FC0; extern StackEntry sSlowlyStackInfo; extern STACK(sSlowlyStack, 0x1000); @@ -423,12 +424,12 @@ void PreRender_ApplyFiltersSlowlyInit(PreRender* this) { if ((this->cvgSave != NULL) && (this->fbufSave != NULL)) { if (D_801F6FC0) { StackCheck_Cleanup(&sSlowlyStackInfo); - Slowly_Stop(&D_801F6E00); + Slowly_Destroy(&sSlowlyMgr); } this->unk_4D = 1; StackCheck_Init(&sSlowlyStackInfo, sSlowlyStack, STACK_TOP(sSlowlyStack), 0, 0x100, "slowly"); - Slowly_Start(&D_801F6E00, STACK_TOP(sSlowlyStack), PreRender_ApplyFilters, this, NULL); + Slowly_Init(&sSlowlyMgr, STACK_TOP(sSlowlyStack), (void*)PreRender_ApplyFilters, this, NULL); D_801F6FC0 = true; } } @@ -439,7 +440,7 @@ void PreRender_ApplyFiltersSlowlyInit(PreRender* this) { void PreRender_ApplyFiltersSlowlyDestroy(PreRender* this) { if (D_801F6FC0) { StackCheck_Cleanup(&sSlowlyStackInfo); - Slowly_Stop(&D_801F6E00); + Slowly_Destroy(&sSlowlyMgr); D_801F6FC0 = false; } } diff --git a/src/code/sys_slowly.c b/src/code/sys_slowly.c index 415d5f297..29ac0db78 100644 --- a/src/code/sys_slowly.c +++ b/src/code/sys_slowly.c @@ -1,43 +1,58 @@ +/** + * @file sys_slowly.c + * + * This file implements a manager for running an asynchronous task on a thread with the lowest priority. + * + * The task callback is expected to have up to 2 void* arguments and have a void return. Setting `argCount` will adjust + * how many args the callback gets called with, but defaults to 2 and using the 2 argument callback. + * + * @note: `argCount` must be set manually, as this file implements no way to configure it. + */ +#include "slowly.h" #include "global.h" -#define SLOWLY_STATUS_DONE (1 << 0) -#define SLOWLY_STATUS_STARTED (1 << 1) - -void Slowly_Main(SlowlyTask* slowly) { +void Slowly_Main(SlowlyMgr* slowly) { slowly->status |= SLOWLY_STATUS_STARTED; - switch (slowly->callbackArgCount) { - case SLOWLY_CALLBACK_NO_ARGS: - slowly->callback0(); + switch (slowly->argCount) { + case 0: + slowly->callback.zero(); + break; + + case 1: + slowly->callback.one(slowly->arg0); break; - case SLOWLY_CALLBACK_ONE_ARG: - slowly->callback1(slowly->callbackArg0); + + case 2: + slowly->callback.two(slowly->arg0, slowly->arg1); break; - case SLOWLY_CALLBACK_TWO_ARGS: - slowly->callback2(slowly->callbackArg0, slowly->callbackArg1); + + default: break; } slowly->status |= SLOWLY_STATUS_DONE; } -void Slowly_ThreadEntry(SlowlyTask* slowly) { +void Slowly_ThreadEntry(void* arg) { + SlowlyMgr* slowly = (SlowlyMgr*)arg; + Slowly_Main(slowly); } -void Slowly_Start(SlowlyTask* slowly, void* stack, void (*callback)(), void* callbackArg0, void* callbackArg1) { - bzero(slowly, sizeof(SlowlyTask)); +void Slowly_Init(SlowlyMgr* slowly, void* stack, SlowlyCallbackTwo callback, void* arg0, void* arg1) { + bzero(slowly, sizeof(SlowlyMgr)); - slowly->callbackArgCount = SLOWLY_CALLBACK_TWO_ARGS; + slowly->argCount = 2; slowly->status = 0; - slowly->callback0 = callback; - slowly->callbackArg0 = callbackArg0; - slowly->callbackArg1 = callbackArg1; + slowly->callback.two = callback; + slowly->arg0 = arg0; + slowly->arg1 = arg1; osCreateThread(&slowly->thread, Z_THREAD_ID_SLOWLY, Slowly_ThreadEntry, slowly, stack, Z_PRIORITY_SLOWLY); osStartThread(&slowly->thread); } -void Slowly_Stop(SlowlyTask* slowly) { +void Slowly_Destroy(SlowlyMgr* slowly) { osDestroyThread(&slowly->thread); } |
