diff --git a/include/dusk/frame_interpolation.h b/include/dusk/frame_interpolation.h index 3ba1af4799..7894eda9c2 100644 --- a/include/dusk/frame_interpolation.h +++ b/include/dusk/frame_interpolation.h @@ -16,7 +16,7 @@ void ensure_initialized(); void begin_record(); void end_record(); -void begin_frame(bool is_sim_frame, float step); +void begin_frame(bool enabled, bool is_sim_frame, float step); void interpolate(); float get_interpolation_step(); @@ -29,6 +29,8 @@ bool is_enabled(); void set_ui_tick_pending(bool value); bool get_ui_tick_pending(); +bool is_sim_frame(); + void record_camera(::camera_process_class* cam, int camera_id); void interp_view(::view_class* view); void record_final_mtx(Mtx m, const void *key); diff --git a/include/f_pc/f_pc_leaf.h b/include/f_pc/f_pc_leaf.h index 33d7e85d29..414d706b6a 100644 --- a/include/f_pc/f_pc_leaf.h +++ b/include/f_pc/f_pc_leaf.h @@ -25,7 +25,7 @@ typedef struct leafdraw_class : base_process_class { #endif /* 0xB8 */ leafdraw_method_class* leaf_methods; /* 0xBC */ s8 unk_0xBC; - /* 0xBD */ u8 unk_0xBD; + /* 0xBD */ u8 draw_interp_frame; /* 0xBE */ draw_priority_class draw_priority; } leafdraw_class; diff --git a/src/d/d_kankyo.cpp b/src/d/d_kankyo.cpp index 05a0f70f5a..6b84fbae43 100644 --- a/src/d/d_kankyo.cpp +++ b/src/d/d_kankyo.cpp @@ -8106,23 +8106,11 @@ void dKankyo_HIO_c::genMessage(JORMContext* mctx) { #endif -#if TARGET_PC -static void interp_callback(bool isSimFrame, void* pUserWork) { - if (!isSimFrame) { - g_env_light.drawKankyo(); - } -} -#endif - void dScnKy_env_light_c::drawKankyo() { setSunpos(); SetBaseLight(); setLight(); dKy_setLight_nowroom(g_env_light.PrevCol); - -#if TARGET_PC - dusk::frame_interp::add_interpolation_callback(interp_callback, nullptr); -#endif } void dKy_undwater_filter_draw() { @@ -8264,6 +8252,10 @@ static int dKy_Create(void* i_this) { kankyo_class* kankyo = (kankyo_class*)i_this; BOOL next_time_set = false; +#if TARGET_PC + kankyo->base.draw_interp_frame = true; +#endif + stage_envr_info_class* stage_envr_p = dComIfGp_getStageEnvrInfo(); if (stage_envr_p != NULL && dComIfGp_getStartStageRoomNo() != -1) { stage_envr_p += dComIfGp_getStartStageRoomNo(); diff --git a/src/dusk/frame_interpolation.cpp b/src/dusk/frame_interpolation.cpp index 01604ede4f..c07e1f5cee 100644 --- a/src/dusk/frame_interpolation.cpp +++ b/src/dusk/frame_interpolation.cpp @@ -53,16 +53,6 @@ struct InterpolationCallBackWork { std::vector s_interpolationCallBackWork; -void set_enabled(bool enabled) { - if (g_enabled == enabled) - return; - - g_enabled = enabled; - - if (!g_enabled) - s_interpolationCallBackWork.clear(); -} - void copy_view_to_snap(CameraSnapshot* dst, const view_class& v) { dst->eye = v.lookat.eye; dst->center = v.lookat.center; @@ -134,20 +124,24 @@ void clear_replacements() { namespace dusk::frame_interp { void ensure_initialized() { - set_enabled(getSettings().game.enableFrameInterpolation); s_initialized = true; } +void begin_frame(bool enabled, bool is_sim_frame, float step) { + g_enabled = enabled; + g_is_sim_frame = is_sim_frame; + g_step = std::clamp(step, 0.0f, 1.0f); + if (is_sim_frame) { + s_interpolationCallBackWork.clear(); + } +} + bool is_enabled() { return g_enabled; } -void begin_frame(bool is_sim_frame, float step) { - g_is_sim_frame = is_sim_frame; - g_step = std::clamp(step, 0.0f, 1.0f); - if (is_sim_frame) { - s_interpolationCallBackWork.clear(); - } +bool is_sim_frame() { + return g_is_sim_frame; } void begin_record() { @@ -285,6 +279,12 @@ void record_camera(::camera_process_class* cam, int camera_id) { } void interp_view(::view_class* view) { + if (!g_enabled) + return; + + if (!s_cam_prev.valid || !s_cam_curr.valid) + return; + const f32 step = get_interpolation_step(); cXyz eye; cXyz center; diff --git a/src/f_pc/f_pc_leaf.cpp b/src/f_pc/f_pc_leaf.cpp index eab6532a92..7f6d6df802 100644 --- a/src/f_pc/f_pc_leaf.cpp +++ b/src/f_pc/f_pc_leaf.cpp @@ -6,6 +6,10 @@ #include "f_pc/f_pc_leaf.h" #include "f_pc/f_pc_debug_sv.h" +#if TARGET_PC +#include "dusk/frame_interpolation.h" +#endif + s16 fpcLf_GetPriority(const leafdraw_class* i_leaf) { return fpcDwPi_Get(&i_leaf->draw_priority); } @@ -16,6 +20,11 @@ int fpcLf_DrawMethod(leafdraw_method_class* i_methods, void* i_process) { int fpcLf_Draw(leafdraw_class* i_leaf) { int ret = 0; +#if TARGET_PC + if (!i_leaf->draw_interp_frame && !dusk::frame_interp::is_sim_frame()) { + return ret; + } +#endif if (i_leaf->unk_0xBC == 0) { ret = fpcLf_DrawMethod(i_leaf->leaf_methods, i_leaf); } @@ -56,6 +65,9 @@ int fpcLf_Create(leafdraw_class* i_leaf) { LEAFDRAW_BASE(i_leaf).subtype = fpcBs_MakeOfType(&g_fpcLf_type); fpcDwPi_Init(&i_leaf->draw_priority, pprofile->priority); i_leaf->unk_0xBC = 0; +#if TARGET_PC + i_leaf->draw_interp_frame = false; +#endif } int ret = fpcMtd_Create(&i_leaf->leaf_methods->base, i_leaf); diff --git a/src/m_Do/m_Do_main.cpp b/src/m_Do/m_Do_main.cpp index 7ef445fbe6..77bccadede 100644 --- a/src/m_Do/m_Do_main.cpp +++ b/src/m_Do/m_Do_main.cpp @@ -70,6 +70,7 @@ #include "dusk/config.hpp" #include "dusk/imgui/ImGuiConsole.hpp" #include "tracy/Tracy.hpp" +#include "f_pc/f_pc_draw.h" // --- GLOBALS --- s8 mDoMain::developmentMode = -1; @@ -233,8 +234,8 @@ void main01(void) { mDoGph_gInf_c::updateRenderSize(); + dusk::frame_interp::begin_frame(pacing.is_interpolating, pacing.do_sim_tick, pacing.interpolation_step); if (pacing.is_interpolating) { - dusk::frame_interp::begin_frame(pacing.do_sim_tick, pacing.interpolation_step); if (pacing.do_sim_tick) { dusk::frame_interp::set_ui_tick_pending(true); mDoCPd_c::read(); @@ -242,6 +243,9 @@ void main01(void) { fapGm_Execute(); mDoAud_Execute(); dusk::game_clock::reset_accumulator(); + } else { + // run draw functions for anything specially marked to handle interp on non-sim ticks + fpcM_DrawIterater((fpcM_DrawIteraterFunc)fpcM_Draw); } dusk::frame_interp::interpolate(); {