Use weak symbols instead of function pointers for optional features

This commit is contained in:
fincs 2017-03-05 23:28:30 +01:00
parent 96e65d48be
commit c030f3e70a
5 changed files with 35 additions and 24 deletions

View File

@ -49,8 +49,6 @@ enum
struct C3D_LightEnv_t struct C3D_LightEnv_t
{ {
void (* Update)(C3D_LightEnv* env);
void (* Dirty)(C3D_LightEnv* env);
u32 flags; u32 flags;
C3D_LightLut* luts[6]; C3D_LightLut* luts[6];
float ambient[3]; float ambient[3];

View File

@ -7,6 +7,24 @@ C3D_Context __C3D_Context;
static aptHookCookie hookCookie; 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) static void C3Di_AptEventHook(APT_HookType hookType, C3D_UNUSED void* param)
{ {
C3D_Context* ctx = C3Di_GetContext(); C3D_Context* ctx = C3Di_GetContext();
@ -15,8 +33,7 @@ static void C3Di_AptEventHook(APT_HookType hookType, C3D_UNUSED void* param)
{ {
case APTHOOK_ONSUSPEND: case APTHOOK_ONSUSPEND:
{ {
if (ctx->renderQueueWaitDone) C3Di_RenderQueueWaitDone();
ctx->renderQueueWaitDone();
break; break;
} }
case APTHOOK_ONRESTORE: case APTHOOK_ONRESTORE:
@ -32,7 +49,7 @@ static void C3Di_AptEventHook(APT_HookType hookType, C3D_UNUSED void* param)
C3D_LightEnv* env = ctx->lightEnv; C3D_LightEnv* env = ctx->lightEnv;
if (env) if (env)
env->Dirty(env); C3Di_LightEnvDirty(env);
break; break;
} }
default: default:
@ -56,7 +73,6 @@ bool C3D_Init(size_t cmdBufSize)
GPUCMD_SetBuffer(ctx->cmdBuf, ctx->cmdBufSize, 0); GPUCMD_SetBuffer(ctx->cmdBuf, ctx->cmdBufSize, 0);
ctx->flags = C3DiF_Active | C3DiF_TexEnvBuf | C3DiF_TexEnvAll | C3DiF_Effect | C3DiF_TexStatus | C3DiF_TexAll; ctx->flags = C3DiF_Active | C3DiF_TexEnvBuf | C3DiF_TexEnvAll | C3DiF_Effect | C3DiF_TexStatus | C3DiF_TexAll;
ctx->renderQueueExit = NULL;
// TODO: replace with direct struct access // TODO: replace with direct struct access
C3D_DepthMap(true, -1.0f, 0.0f); C3D_DepthMap(true, -1.0f, 0.0f);
@ -221,7 +237,7 @@ void C3Di_UpdateContext(void)
} }
if (env) if (env)
env->Update(env); C3Di_LightEnvUpdate(env);
if (ctx->fixedAttribDirty) if (ctx->fixedAttribDirty)
{ {
@ -292,9 +308,7 @@ void C3D_Fini(void)
if (!(ctx->flags & C3DiF_Active)) if (!(ctx->flags & C3DiF_Active))
return; return;
if (ctx->renderQueueExit) C3Di_RenderQueueExit();
ctx->renderQueueExit();
aptUnhook(&hookCookie); aptUnhook(&hookCookie);
linearFree(ctx->cmdBuf); linearFree(ctx->cmdBuf);
ctx->flags = 0; ctx->flags = 0;

View File

@ -51,10 +51,6 @@ typedef struct
u16 fixedAttribDirty, fixedAttribEverDirty; u16 fixedAttribDirty, fixedAttribEverDirty;
C3D_FVec fixedAttribs[12]; C3D_FVec fixedAttribs[12];
void (* renderQueueWaitDone)(void);
void (* renderQueueExit)(void);
} C3D_Context; } C3D_Context;
enum enum

View File

@ -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); 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; int i;
C3D_LightEnvConf* conf = &env->conf; 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; env->flags |= C3DF_LightEnv_Dirty;
int i; int i;
@ -152,9 +152,6 @@ static void C3Di_LightEnvDirty(C3D_LightEnv* env)
void C3D_LightEnvInit(C3D_LightEnv* env) void C3D_LightEnvInit(C3D_LightEnv* env)
{ {
memset(env, 0, sizeof(*env)); memset(env, 0, sizeof(*env));
env->Update = C3Di_LightEnvUpdate;
env->Dirty = C3Di_LightEnvDirty;
env->flags = C3DF_LightEnv_Dirty; env->flags = C3DF_LightEnv_Dirty;
env->conf.config[0] = (4<<8) | BIT(27) | BIT(31); env->conf.config[0] = (4<<8) | BIT(27) | BIT(31);
env->conf.config[1] = ~0; env->conf.config[1] = ~0;

View File

@ -21,6 +21,7 @@ static struct
} queuedFrame[2]; } queuedFrame[2];
static u8 queueSwap, queuedCount, queuedState; static u8 queueSwap, queuedCount, queuedState;
static bool initialized;
static bool inFrame, inSafeTransfer, inSafeClear; static bool inFrame, inSafeTransfer, inSafeClear;
static float framerate = 60.0f; static float framerate = 60.0f;
static float framerateCounter[2] = { 60.0f, 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); gspSetEventCallback(GSPGPU_EVENT_VBlank1, onVBlank1, NULL, false);
} }
static void C3Di_RenderQueueExit(void) void C3Di_RenderQueueExit(void)
{ {
int i; int i;
C3D_RenderTarget *a, *next; C3D_RenderTarget *a, *next;
if (!initialized)
return;
for (a = firstTarget; a; a = next) for (a = firstTarget; a; a = next)
{ {
next = a->next; next = a->next;
@ -269,10 +273,13 @@ static void C3Di_RenderQueueExit(void)
queueSwap = 0; queueSwap = 0;
queuedCount = 0; queuedCount = 0;
queuedState = 0; queuedState = 0;
initialized = false;
} }
static void C3Di_RenderQueueWaitDone(void) void C3Di_RenderQueueWaitDone(void)
{ {
if (!initialized)
return;
while (queuedCount || transferQueue || clearQueue) while (queuedCount || transferQueue || clearQueue)
gspWaitForAnyEvent(); gspWaitForAnyEvent();
} }
@ -284,11 +291,10 @@ static bool checkRenderQueueInit(void)
if (!(ctx->flags & C3DiF_Active)) if (!(ctx->flags & C3DiF_Active))
return false; return false;
if (!ctx->renderQueueExit) if (!initialized)
{ {
C3Di_RenderQueueInit(); C3Di_RenderQueueInit();
ctx->renderQueueWaitDone = C3Di_RenderQueueWaitDone; initialized = true;
ctx->renderQueueExit = C3Di_RenderQueueExit;
} }
return true; return true;