mirror of
https://github.com/zeldaret/mm.git
synced 2026-05-23 15:01:32 -04:00
587d12e3cb
* thread, scene and interface * non header stuff * fix missing stuff * z64sound_source.h * collision_check.h * Update include/z64sound_source.h Co-authored-by: engineer124 <47598039+engineer124@users.noreply.github.com> * Update include/z64scene.h Co-authored-by: engineer124 <47598039+engineer124@users.noreply.github.com> * Update include/z64thread.h Co-authored-by: engineer124 <47598039+engineer124@users.noreply.github.com> * review * review * Update src/code/z_collision_check.c Co-authored-by: engineer124 <47598039+engineer124@users.noreply.github.com> * Update src/code/z_sound_source.c Co-authored-by: engineer124 <47598039+engineer124@users.noreply.github.com> --------- Co-authored-by: engineer124 <47598039+engineer124@users.noreply.github.com>
62 lines
1.6 KiB
C
62 lines
1.6 KiB
C
/**
|
|
* @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"
|
|
#include "stackcheck.h"
|
|
#include "z64thread.h"
|
|
|
|
void Slowly_Main(SlowlyMgr* slowly) {
|
|
slowly->status |= SLOWLY_STATUS_STARTED;
|
|
|
|
switch (slowly->argCount) {
|
|
case 0:
|
|
slowly->callback.zero();
|
|
break;
|
|
|
|
case 1:
|
|
slowly->callback.one(slowly->arg0);
|
|
break;
|
|
|
|
case 2:
|
|
slowly->callback.two(slowly->arg0, slowly->arg1);
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
|
|
slowly->status |= SLOWLY_STATUS_DONE;
|
|
}
|
|
|
|
void Slowly_ThreadEntry(void* arg) {
|
|
SlowlyMgr* slowly = (SlowlyMgr*)arg;
|
|
|
|
Slowly_Main(slowly);
|
|
}
|
|
|
|
void Slowly_Init(SlowlyMgr* slowly, void* stack, SlowlyCallbackTwo callback, void* arg0, void* arg1) {
|
|
bzero(slowly, sizeof(SlowlyMgr));
|
|
|
|
slowly->argCount = 2;
|
|
slowly->status = 0;
|
|
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_Destroy(SlowlyMgr* slowly) {
|
|
osDestroyThread(&slowly->thread);
|
|
}
|