From da86fd4875ba6bcea1dd4051b27261896091f98e Mon Sep 17 00:00:00 2001 From: kichikuou Date: Sat, 27 Jul 2024 07:55:32 +0900 Subject: [PATCH] vmGraph changes for DALK Gaiden The effect API is slightly changed so that it can be used from pre-SACT graphics engines. --- include/effect.h | 6 +++++ src/effect.c | 50 +++++++++++++--------------------- src/hll/SACT2.c | 45 +++++++++++++++++++++++++++++++ src/hll/vmGraph.c | 68 +++++++++++++++++++++++++++++++++++++++++------ 4 files changed, 130 insertions(+), 39 deletions(-) diff --git a/include/effect.h b/include/effect.h index 08714a3..d2181c0 100644 --- a/include/effect.h +++ b/include/effect.h @@ -75,4 +75,10 @@ enum effect { extern const char *effect_names[NR_EFFECTS]; +int effect_init(enum effect type); +void effect_record_old(void); +void effect_record_new(void); +int effect_update(float rate); +int effect_fini(void); + #endif /* SYSTEM4_EFFECT_H */ diff --git a/src/effect.c b/src/effect.c index bad4650..bb3247d 100644 --- a/src/effect.c +++ b/src/effect.c @@ -19,8 +19,6 @@ #include #include "effect.h" #include "gfx/gfx.h" -#include "parts.h" -#include "sact.h" #include "system4.h" #include "xsystem4.h" @@ -276,7 +274,7 @@ static effect_fun effect_functions[NR_EFFECTS] = { [EFFECT_ZOOM_IN_CROSSFADE] = effect_zoom_in_crossfade, }; -int sact_TRANS_Begin(int type) +int effect_init(enum effect type) { if (type <= 0 || type >= NR_EFFECTS) { WARNING("Invalid or unknown effect: %d", type); @@ -301,14 +299,26 @@ int sact_TRANS_Begin(int type) effect.on = true; effect.type = type; - gfx_copy_main_surface(&effect.old); - PE_UpdateComponent(0); - scene_render(); - gfx_copy_main_surface(&effect.new); return 1; } -int sact_TRANS_Update(float rate) +void effect_record_old(void) +{ + if (!effect.on) { + return; + } + gfx_copy_main_surface(&effect.old); +} + +void effect_record_new(void) +{ + if (!effect.on) { + return; + } + gfx_copy_main_surface(&effect.new); +} + +int effect_update(float rate) { if (!effect.on) { return 0; @@ -323,32 +333,10 @@ int sact_TRANS_Update(float rate) return 1; } -int sact_TRANS_End(void) +int effect_fini(void) { effect.on = false; gfx_delete_texture(&effect.old); gfx_delete_texture(&effect.new); return 1; } - -int sact_Effect(int type, int time, possibly_unused int key) -{ - uint32_t start = SDL_GetTicks(); - if (!sact_TRANS_Begin(type)) - return 0; - - uint32_t t = SDL_GetTicks() - start; - while (t < time) { - sact_TRANS_Update((float)t / (float)time); - uint32_t t2 = SDL_GetTicks() - start; - if (t2 < t + 16) { - SDL_Delay(t + 16 - t2); - t += 16; - } else { - t = t2; - } - } - - sact_TRANS_End(); - return 1; -} diff --git a/src/hll/SACT2.c b/src/hll/SACT2.c index d93b538..380f4f7 100644 --- a/src/hll/SACT2.c +++ b/src/hll/SACT2.c @@ -26,10 +26,12 @@ #include "hll.h" #include "asset_manager.h" #include "audio.h" +#include "effect.h" #include "input.h" #include "queue.h" #include "gfx/gfx.h" #include "gfx/font.h" +#include "parts.h" #include "sact.h" #include "scene.h" #include "vm/page.h" @@ -175,6 +177,28 @@ int sact_Update(void) return 1; } +int sact_Effect(int type, int time, possibly_unused int key) +{ + uint32_t start = SDL_GetTicks(); + if (!sact_TRANS_Begin(type)) + return 0; + + uint32_t t = SDL_GetTicks() - start; + while (t < time) { + sact_TRANS_Update((float)t / (float)time); + uint32_t t2 = SDL_GetTicks() - start; + if (t2 < t + 16) { + SDL_Delay(t + 16 - t2); + t += 16; + } else { + t = t2; + } + } + + sact_TRANS_End(); + return 1; +} + HLL_WARN_UNIMPLEMENTED(1, int, SACT2, EffectSetMask, int cg); //int SACT2_EffectSetMaskSP(int sp); @@ -962,6 +986,27 @@ HLL_WARN_UNIMPLEMENTED( , void, SACTDX, SetVolumeMixerBGMGroupNum, int n); //static void SACTDX_Key_ClearFlagNoCtrl(void); //static void SACTDX_Key_ClearFlagOne(int nKeyCode); +int sact_TRANS_Begin(int type) +{ + if (!effect_init(type)) + return 0; + effect_record_old(); + PE_UpdateComponent(0); + scene_render(); + effect_record_new(); + return 1; +} + +int sact_TRANS_Update(float rate) +{ + return effect_update(rate); +} + +int sact_TRANS_End(void) +{ + return effect_fini(); +} + bool sact_VIEW_SetMode(int mode) { view_mode = mode; diff --git a/src/hll/vmGraph.c b/src/hll/vmGraph.c index 181a499..4adf67e 100644 --- a/src/hll/vmGraph.c +++ b/src/hll/vmGraph.c @@ -14,6 +14,7 @@ * along with this program; if not, see . */ +#include "effect.h" #include "gfx/gfx.h" #include "vmSurface.h" #include "hll.h" @@ -61,7 +62,15 @@ static void vmGraph_CopySprite(int dst_surface, int dx, int dy, int src_surface, //void vmGraph_Blend(int dst_surface, int dx, int dy, int src_surface, int sx, int sy, int width, int height, int alpha); //void vmGraph_BlendSrcBright(int dst_surface, int dx, int dy, int src_surface, int sx, int sy, int width, int height, int alpha, int nRate); -//void vmGraph_BlendAddSatur(int dst_surface, int dx, int dy, int src_surface, int sx, int sy, int width, int height); + +static void vmGraph_BlendAddSatur(int dst_surface, int dx, int dy, int src_surface, int sx, int sy, int width, int height) +{ + struct vm_surface *dst = vm_surface_get(dst_surface); + struct vm_surface *src = vm_surface_get(src_surface); + if (!dst || !src) + return; + gfx_blend_add_satur(&dst->texture, dx, dy, &src->texture, sx, sy, width, height); +} static void vmGraph_BlendAlphaMap(int dst_surface, int dx, int dy, int src_surface, int sx, int sy, int width, int height) { @@ -79,7 +88,16 @@ static void vmGraph_BlendAlphaMap(int dst_surface, int dx, int dy, int src_surfa //void vmGraph_BlendAlphaMapBright(int dst_surface, int dx, int dy, int src_surface, int sx, int sy, int width, int height, int nRate); //void vmGraph_BlendAlphaMapAlphaSrcBright(int dst_surface, int dx, int dy, int src_surface, int sx, int sy, int width, int height, int alpha, int nRate); //void vmGraph_BlendUseAMapColor(int dst_surface, int dx, int dy, int width, int height, int hAlphaSurface, int nAx, int nAy, int r, int g, int b, int alpha); -//void vmGraph_BlendScreen(int dst_surface, int dx, int dy, int src_surface, int sx, int sy, int width, int height); + +static void vmGraph_BlendScreen(int dst_surface, int dx, int dy, int src_surface, int sx, int sy, int width, int height) +{ + struct vm_surface *dst = vm_surface_get(dst_surface); + struct vm_surface *src = vm_surface_get(src_surface); + if (!dst || !src) + return; + gfx_blend_screen(&dst->texture, dx, dy, &src->texture, sx, sy, width, height); +} + //void vmGraph_BlendMultiply(int dst_surface, int dx, int dy, int src_surface, int sx, int sy, int width, int height); //void vmGraph_BlendScreenAlpha(int dst_surface, int dx, int dy, int src_surface, int sx, int sy, int width, int height, int alpha); @@ -127,7 +145,15 @@ static void vmGraph_AddDA_DAxSA(int dst_surface, int dx, int dy, int src_surface gfx_add_da_daxsa(&dst->texture, dx, dy, &src->texture, sx, sy, width, height); } -//void vmGraph_SubDA_DAxSA(int dst_surface, int dx, int dy, int src_surface, int sx, int sy, int width, int height); +static void vmGraph_SubDA_DAxSA(int dst_surface, int dx, int dy, int src_surface, int sx, int sy, int width, int height) +{ + struct vm_surface *dst = vm_surface_get(dst_surface); + struct vm_surface *src = vm_surface_get(src_surface); + if (!dst || !src) + return; + gfx_sub_da_daxsa(&dst->texture, dx, dy, &src->texture, sx, sy, width, height); +} + //void vmGraph_BrightDestOnly(int surface, int x, int y, int width, int height, int nRate); //void vmGraph_CopyTextureWrap(int dst_surface, int dx, int dy, int d_width, int d_height, int src_surface, int sx, int sy, int s_width, int s_height, int nU, int nV); //void vmGraph_CopyTextureWrapAlpha(int dst_surface, int dx, int dy, int d_width, int d_height, int src_surface, int sx, int sy, int s_width, int s_height, int nU, int nV, int alpha); @@ -158,7 +184,33 @@ static void vmGraph_CopyStretch(int surface, int dx, int dy, int d_width, int d_ //void vmGraph_CopyStretchBlend(int surface, int dx, int dy, int d_width, int d_height, int src_surface, float sx, float sy, float s_width, float s_height, int alpha); //void vmGraph_CopyStretchBlendAlphaMap(int surface, int dx, int dy, int d_width, int d_height, int src_surface, float sx, float sy, float s_width, float s_height); HLL_WARN_UNIMPLEMENTED( , void, vmGraph, SetClickCancel, int click); -//int vmGraph_EffectCopy(int dx, int dy, int src_surface, int sx, int sy, int width, int height, int nEffect, int nTotalTime); + +static int vmGraph_EffectCopy(int dx, int dy, int src_surface, int sx, int sy, int width, int height, int effect, int total_time) +{ + uint32_t start = SDL_GetTicks(); + if (!effect_init(effect)) + return 0; + effect_record_old(); + vmGraph_Copy(vm_surface_get_main_surface(), dx, dy, src_surface, sx, sy, width, height); + effect_record_new(); + + uint32_t t = SDL_GetTicks() - start; + while (t < total_time) { + effect_update((float)t / (float)total_time); + uint32_t t2 = SDL_GetTicks() - start; + if (t2 < t + 16) { + SDL_Delay(t + 16 - t2); + t += 16; + } else { + t = t2; + } + } + effect_update(1.0); + + effect_fini(); + return 1; +} + //int vmGraph_GetMainWidth(void); //int vmGraph_GetMainHeight(void); //int vmGraph_GetMainBpp(void); @@ -178,7 +230,7 @@ HLL_LIBRARY(vmGraph, HLL_EXPORT(CopySprite, vmGraph_CopySprite), HLL_TODO_EXPORT(Blend, vmGraph_Blend), HLL_TODO_EXPORT(BlendSrcBright, vmGraph_BlendSrcBright), - HLL_TODO_EXPORT(BlendAddSatur, vmGraph_BlendAddSatur), + HLL_EXPORT(BlendAddSatur, vmGraph_BlendAddSatur), HLL_EXPORT(BlendAlphaMap, vmGraph_BlendAlphaMap), HLL_TODO_EXPORT(BlendAlphaMapSrcOnly, vmGraph_BlendAlphaMapSrcOnly), HLL_TODO_EXPORT(BlendAlphaMapColor, vmGraph_BlendAlphaMapColor), @@ -187,7 +239,7 @@ HLL_LIBRARY(vmGraph, HLL_TODO_EXPORT(BlendAlphaMapBright, vmGraph_BlendAlphaMapBright), HLL_TODO_EXPORT(BlendAlphaMapAlphaSrcBright, vmGraph_BlendAlphaMapAlphaSrcBright), HLL_TODO_EXPORT(BlendUseAMapColor, vmGraph_BlendUseAMapColor), - HLL_TODO_EXPORT(BlendScreen, vmGraph_BlendScreen), + HLL_EXPORT(BlendScreen, vmGraph_BlendScreen), HLL_TODO_EXPORT(BlendMultiply, vmGraph_BlendMultiply), HLL_TODO_EXPORT(BlendScreenAlpha, vmGraph_BlendScreenAlpha), HLL_EXPORT(Fill, vmGraph_Fill), @@ -197,7 +249,7 @@ HLL_LIBRARY(vmGraph, HLL_TODO_EXPORT(SaturDP_DPxSA, vmGraph_SaturDP_DPxSA), HLL_TODO_EXPORT(ScreenDA_DAxSA, vmGraph_ScreenDA_DAxSA), HLL_EXPORT(AddDA_DAxSA, vmGraph_AddDA_DAxSA), - HLL_TODO_EXPORT(SubDA_DAxSA, vmGraph_SubDA_DAxSA), + HLL_EXPORT(SubDA_DAxSA, vmGraph_SubDA_DAxSA), HLL_TODO_EXPORT(BrightDestOnly, vmGraph_BrightDestOnly), HLL_TODO_EXPORT(CopyTextureWrap, vmGraph_CopyTextureWrap), HLL_TODO_EXPORT(CopyTextureWrapAlpha, vmGraph_CopyTextureWrapAlpha), @@ -205,7 +257,7 @@ HLL_LIBRARY(vmGraph, HLL_TODO_EXPORT(CopyStretchBlend, vmGraph_CopyStretchBlend), HLL_TODO_EXPORT(CopyStretchBlendAlphaMap, vmGraph_CopyStretchBlendAlphaMap), HLL_EXPORT(SetClickCancel, vmGraph_SetClickCancel), - HLL_TODO_EXPORT(EffectCopy, vmGraph_EffectCopy), + HLL_EXPORT(EffectCopy, vmGraph_EffectCopy), HLL_EXPORT(GetMainSurface, vm_surface_get_main_surface), HLL_TODO_EXPORT(GetMainWidth, vmGraph_GetMainWidth), HLL_TODO_EXPORT(GetMainHeight, vmGraph_GetMainHeight),