From c030f3e70aaa962961087850e478d3cb483cb98c Mon Sep 17 00:00:00 2001 From: fincs Date: Sun, 5 Mar 2017 23:28:30 +0100 Subject: [PATCH] Use weak symbols instead of function pointers for optional features --- include/c3d/light.h | 2 -- source/base.c | 30 ++++++++++++++++++++++-------- source/internal.h | 4 ---- source/lightenv.c | 7 ++----- source/renderqueue.c | 16 +++++++++++----- 5 files changed, 35 insertions(+), 24 deletions(-) diff --git a/include/c3d/light.h b/include/c3d/light.h index cb3ec7b..c2ec4e8 100644 --- a/include/c3d/light.h +++ b/include/c3d/light.h @@ -49,8 +49,6 @@ enum struct C3D_LightEnv_t { - void (* Update)(C3D_LightEnv* env); - void (* Dirty)(C3D_LightEnv* env); u32 flags; C3D_LightLut* luts[6]; float ambient[3]; diff --git a/source/base.c b/source/base.c index 46555e6..64d3bed 100644 --- a/source/base.c +++ b/source/base.c @@ -7,6 +7,24 @@ C3D_Context __C3D_Context; static aptHookCookie hookCookie; +__attribute__((weak)) void C3Di_RenderQueueWaitDone(void) +{ +} + +__attribute__((weak)) void C3Di_RenderQueueExit(void) +{ +} + +__attribute__((weak)) void C3Di_LightEnvUpdate(C3D_LightEnv* env) +{ + (void)env; +} + +__attribute__((weak)) void C3Di_LightEnvDirty(C3D_LightEnv* env) +{ + (void)env; +} + static void C3Di_AptEventHook(APT_HookType hookType, C3D_UNUSED void* param) { C3D_Context* ctx = C3Di_GetContext(); @@ -15,8 +33,7 @@ static void C3Di_AptEventHook(APT_HookType hookType, C3D_UNUSED void* param) { case APTHOOK_ONSUSPEND: { - if (ctx->renderQueueWaitDone) - ctx->renderQueueWaitDone(); + C3Di_RenderQueueWaitDone(); break; } case APTHOOK_ONRESTORE: @@ -32,7 +49,7 @@ static void C3Di_AptEventHook(APT_HookType hookType, C3D_UNUSED void* param) C3D_LightEnv* env = ctx->lightEnv; if (env) - env->Dirty(env); + C3Di_LightEnvDirty(env); break; } default: @@ -56,7 +73,6 @@ bool C3D_Init(size_t cmdBufSize) GPUCMD_SetBuffer(ctx->cmdBuf, ctx->cmdBufSize, 0); ctx->flags = C3DiF_Active | C3DiF_TexEnvBuf | C3DiF_TexEnvAll | C3DiF_Effect | C3DiF_TexStatus | C3DiF_TexAll; - ctx->renderQueueExit = NULL; // TODO: replace with direct struct access C3D_DepthMap(true, -1.0f, 0.0f); @@ -221,7 +237,7 @@ void C3Di_UpdateContext(void) } if (env) - env->Update(env); + C3Di_LightEnvUpdate(env); if (ctx->fixedAttribDirty) { @@ -292,9 +308,7 @@ void C3D_Fini(void) if (!(ctx->flags & C3DiF_Active)) return; - if (ctx->renderQueueExit) - ctx->renderQueueExit(); - + C3Di_RenderQueueExit(); aptUnhook(&hookCookie); linearFree(ctx->cmdBuf); ctx->flags = 0; diff --git a/source/internal.h b/source/internal.h index b1ffefa..ca68063 100644 --- a/source/internal.h +++ b/source/internal.h @@ -51,10 +51,6 @@ typedef struct u16 fixedAttribDirty, fixedAttribEverDirty; C3D_FVec fixedAttribs[12]; - - void (* renderQueueWaitDone)(void); - void (* renderQueueExit)(void); - } C3D_Context; enum diff --git a/source/lightenv.c b/source/lightenv.c index 452b970..8ecf05f 100644 --- a/source/lightenv.c +++ b/source/lightenv.c @@ -47,7 +47,7 @@ static void C3Di_LightEnvSelectLayer(C3D_LightEnv* env) env->conf.config[0] = (env->conf.config[0] &~ (0xF<<4)) | (GPU_LIGHT_ENV_LAYER_CONFIG(i)<<4); } -static void C3Di_LightEnvUpdate(C3D_LightEnv* env) +void C3Di_LightEnvUpdate(C3D_LightEnv* env) { int i; C3D_LightEnvConf* conf = &env->conf; @@ -129,7 +129,7 @@ static void C3Di_LightEnvUpdate(C3D_LightEnv* env) } } -static void C3Di_LightEnvDirty(C3D_LightEnv* env) +void C3Di_LightEnvDirty(C3D_LightEnv* env) { env->flags |= C3DF_LightEnv_Dirty; int i; @@ -152,9 +152,6 @@ static void C3Di_LightEnvDirty(C3D_LightEnv* env) void C3D_LightEnvInit(C3D_LightEnv* env) { memset(env, 0, sizeof(*env)); - env->Update = C3Di_LightEnvUpdate; - env->Dirty = C3Di_LightEnvDirty; - env->flags = C3DF_LightEnv_Dirty; env->conf.config[0] = (4<<8) | BIT(27) | BIT(31); env->conf.config[1] = ~0; diff --git a/source/renderqueue.c b/source/renderqueue.c index 9a08ece..6f30bab 100644 --- a/source/renderqueue.c +++ b/source/renderqueue.c @@ -21,6 +21,7 @@ static struct } queuedFrame[2]; static u8 queueSwap, queuedCount, queuedState; +static bool initialized; static bool inFrame, inSafeTransfer, inSafeClear; static float framerate = 60.0f; static float framerateCounter[2] = { 60.0f, 60.0f }; @@ -248,11 +249,14 @@ static void C3Di_RenderQueueInit(void) gspSetEventCallback(GSPGPU_EVENT_VBlank1, onVBlank1, NULL, false); } -static void C3Di_RenderQueueExit(void) +void C3Di_RenderQueueExit(void) { int i; C3D_RenderTarget *a, *next; + if (!initialized) + return; + for (a = firstTarget; a; a = next) { next = a->next; @@ -269,10 +273,13 @@ static void C3Di_RenderQueueExit(void) queueSwap = 0; queuedCount = 0; queuedState = 0; + initialized = false; } -static void C3Di_RenderQueueWaitDone(void) +void C3Di_RenderQueueWaitDone(void) { + if (!initialized) + return; while (queuedCount || transferQueue || clearQueue) gspWaitForAnyEvent(); } @@ -284,11 +291,10 @@ static bool checkRenderQueueInit(void) if (!(ctx->flags & C3DiF_Active)) return false; - if (!ctx->renderQueueExit) + if (!initialized) { C3Di_RenderQueueInit(); - ctx->renderQueueWaitDone = C3Di_RenderQueueWaitDone; - ctx->renderQueueExit = C3Di_RenderQueueExit; + initialized = true; } return true;