From 9f2b556f18c218f3c4653b7d1abdd792abd545e6 Mon Sep 17 00:00:00 2001 From: korenkonder Date: Tue, 23 Jul 2024 00:58:13 +0300 Subject: [PATCH] Moved framerate related stuff to it's own file --- src/CRE/Glitter/particle_manager.cpp | 1 + src/CRE/app_system_detail.cpp | 336 ++++++++++++++++++ src/CRE/app_system_detail.hpp | 36 ++ src/CRE/auth_3d.cpp | 1 + src/CRE/effect.cpp | 1 + src/CRE/frame_rate_control.cpp | 2 +- src/CRE/light_param/wind.cpp | 1 + src/CRE/pv_param.cpp | 5 +- src/CRE/render_context.cpp | 19 +- src/CRE/rob/ex_block.cpp | 1 + src/CRE/shader_ft.cpp | 3 +- src/CRE/static_var.cpp | 37 -- src/CRE/static_var.hpp | 5 - src/CRE/task.cpp | 17 +- src/KKdLib/time.cpp | 34 +- src/KKdLib/time.hpp | 2 + src/KKdLib/timer.cpp | 14 - src/KKdLib/timer.hpp | 1 - src/ReDIVA/app.cpp | 16 +- .../classes/graphics/render_settings.cpp | 1 - .../classes/information/frame_speed.cpp | 4 +- src/ReDIVA/data_edit/glitter_editor.cpp | 1 + src/ReDIVA/data_initialize.cpp | 5 +- src/ReDIVA/data_test/auth_3d_test.cpp | 31 ++ src/ReDIVA/data_test/motion_test.cpp | 1 + src/ReDIVA/data_test/opd_test.cpp | 3 +- src/ReDIVA/dw.cpp | 16 +- src/ReDIVA/dw.hpp | 3 - src/ReDIVA/input.cpp | 3 - src/ReDIVA/pv_game/pv_game.cpp | 14 +- src/ReDIVA/pv_game/pv_game_pv_data.cpp | 13 +- src/ReDIVA/pv_game/pv_game_pv_data.hpp | 2 +- src/ReDIVA/system_startup.cpp | 3 +- src/ReDIVA/x_pv_game.cpp | 18 +- src/ReDIVA/x_pv_game.hpp | 2 +- 35 files changed, 503 insertions(+), 149 deletions(-) create mode 100644 src/CRE/app_system_detail.cpp create mode 100644 src/CRE/app_system_detail.hpp diff --git a/src/CRE/Glitter/particle_manager.cpp b/src/CRE/Glitter/particle_manager.cpp index 564ac214..1358a131 100644 --- a/src/CRE/Glitter/particle_manager.cpp +++ b/src/CRE/Glitter/particle_manager.cpp @@ -4,6 +4,7 @@ */ #include "glitter.hpp" +#include "../app_system_detail.hpp" #include "../render_context.hpp" extern render_context* rctx_ptr; diff --git a/src/CRE/app_system_detail.cpp b/src/CRE/app_system_detail.cpp new file mode 100644 index 00000000..4a0e3b10 --- /dev/null +++ b/src/CRE/app_system_detail.cpp @@ -0,0 +1,336 @@ +/* + by korenkonder + GitHub/GitLab: korenkonder +*/ + +#include "app_system_detail.hpp" +#include "../KKdLib/time.hpp" +#include "resolution_mode.hpp" + +struct time_pair { + int64_t value; + int64_t max; + + inline time_pair() : value(), max() { + + } + + inline void reset() { + value = 0; + max = 0; + } + + inline void reset_max() { + max = 0; + } + + inline void set_value(int64_t value) { + this->value = value; + max = max_def(max, value); + } +}; + +namespace app_system_detail { + namespace SystemInfo { + struct MeasureFps { + int32_t state; + int64_t max_time; + time_struct time_start; + int32_t main_timer; + float_t fps; + int64_t retry_count; + + MeasureFps(); + + inline void init(int32_t max_time_sec) { + state = 1; + max_time = 1000000LL * max_time_sec; + fps = 60.0f; + retry_count = 0; + } + + void exec(); + }; + + MeasureFps measure_fps; + } + + struct SystemWork { + bool field_0; + bool field_1; + bool pause; + uint32_t main_timer; + int32_t field_8; + float_t frame_speed; + float_t delta_frame_history_frac; + int32_t delta_frame_history_int; + bool select_frame_speed; + float_t frame_rate; + float_t fps; + time_pair time_ctrl; + time_pair time_file; + time_pair time_calc; + time_pair time_disp; + time_pair time_vblank; + time_pair time_swap; + time_struct time_ctrl_start; + time_struct time_file_start; + time_struct time_calc_start; + time_struct time_disp_start; + time_struct time_rndr_start; + bool vsync_emulation; + uint32_t field_DC; + int64_t field_E0; + float_t next_frame_speed; + bool next_select_frame_speed; + int32_t field_F0; + bool field_F4; + + SystemWork(); + }; + + SystemWork system_work; +} + +bool main_thread_id_init; +int32_t main_thread_id; + +static void delta_frame_history_ctrl(); + +static void main_thread_id_get(); + +static void sub_140193580(); +static void sub_140194B70(); + +void finish_calc_process() { + app_system_detail::system_work.time_calc.set_value(app_system_detail::system_work.time_calc_start.calc_time_int()); +} + +void finish_render_process() { + app_system_detail::system_work.time_disp.set_value(app_system_detail::system_work.time_disp_start.calc_time_int()); + + time_struct time_swap_start; + + /*extern void app_swap_buffers(); + app_swap_buffers();*/ + + app_system_detail::system_work.time_swap.set_value(time_swap_start.calc_time_int()); + + app_system_detail::system_work.time_ctrl.set_value(app_system_detail::system_work.time_ctrl_start.calc_time_int()); + + sub_140194B70(); + + app_system_detail::system_work.main_timer++; + app_system_detail::SystemInfo::measure_fps.exec(); +} + +float_t get_anim_frame_speed() { + return 60.0f / app_system_detail::SystemInfo::measure_fps.fps; +} + +float_t get_delta_frame() { + if (!app_system_detail::system_work.select_frame_speed) + return app_system_detail::system_work.frame_speed; + + float_t freq_ratio = app_system_detail::system_work.frame_rate / get_fps(); + freq_ratio = max_def(freq_ratio, 1.0f); + return freq_ratio * app_system_detail::system_work.frame_speed; +} + +int32_t get_delta_frame_history_int() { + return app_system_detail::system_work.delta_frame_history_int; +} + +float_t get_fps() { + return app_system_detail::system_work.fps; +} + +float_t get_frame_speed() { + return app_system_detail::system_work.frame_speed; +} + +uint32_t get_main_timer() { + return app_system_detail::system_work.main_timer; +} + +float_t get_measured_fps() { + return app_system_detail::SystemInfo::measure_fps.fps; +} + +bool get_pause() { + return app_system_detail::system_work.pause; +} + +void measure_fps_init(int32_t max_time_sec) { + app_system_detail::SystemInfo::measure_fps.init(max_time_sec); +} + +bool measure_fps_check_state() { + return app_system_detail::SystemInfo::measure_fps.state == 3; +} + +void set_next_frame_speed(float_t value) { + app_system_detail::system_work.next_frame_speed = value; +} + +void set_vsync_emulation(bool value) { + app_system_detail::system_work.vsync_emulation = value; +} + +void start_frame_process() { + app_system_detail::system_work.time_ctrl_start.get_timestamp(); + app_system_detail::system_work.time_calc_start.get_timestamp(); + + app_system_detail::system_work.select_frame_speed = app_system_detail::system_work.next_select_frame_speed; + app_system_detail::system_work.frame_speed = app_system_detail::system_work.next_frame_speed; + + if (!get_pause()) + delta_frame_history_ctrl(); +} + +void start_render_process() { + app_system_detail::system_work.time_disp_start.get_timestamp(); +} + +void system_work_init(uint32_t a1) { + app_system_detail::system_work.field_0 = false; + app_system_detail::system_work.field_1 = false; + app_system_detail::system_work.pause = false; + app_system_detail::system_work.main_timer = 0; + app_system_detail::system_work.field_8 = 0; + app_system_detail::system_work.frame_speed = 1.0f; + app_system_detail::system_work.delta_frame_history_frac = 0.0f; + app_system_detail::system_work.delta_frame_history_int = 0; + app_system_detail::system_work.select_frame_speed = false; + app_system_detail::system_work.frame_rate = 60.0f; + app_system_detail::system_work.fps = 60.0f; + app_system_detail::system_work.time_ctrl.reset(); + app_system_detail::system_work.time_file.reset(); + app_system_detail::system_work.time_calc.reset(); + app_system_detail::system_work.time_disp.reset(); + app_system_detail::system_work.time_vblank.reset(); + app_system_detail::system_work.time_swap.reset(); + app_system_detail::system_work.next_frame_speed = 1.0f; + app_system_detail::system_work.next_select_frame_speed = false; + app_system_detail::system_work.field_F0 = 0; + app_system_detail::system_work.field_F4 = 0; + + main_thread_id_get(); + //sub_1400DE570(); + sub_140193580(); + /*sub_140194A90(); + sub_1401932F0(); + sub_1400BEAB0(); + sub_14066D890(a1); + sub_140670680(); + sub_14019AA80(); + sub_1405E2EA0(); + CoInitializeEx(0, 0);*/ +} + +bool sub_1401921D0() { + return app_system_detail::system_work.field_0; +} + +int32_t sub_140192D00() { + return app_system_detail::system_work.field_8; +} + +void sub_140194880(int32_t a1) { + if (a1 > 2) + a1 = 0; + app_system_detail::system_work.field_8 = a1; +} + +app_system_detail::SystemInfo::MeasureFps::MeasureFps() + : state(), max_time(), main_timer(), fps(), retry_count() { + init(0); +} + +void app_system_detail::SystemInfo::MeasureFps::exec() { + switch (state) { + case 1: + time_start.get_timestamp(); + state = 2; + main_timer = get_main_timer(); + break; + case 2: { + /*int64_t time = time_start.calc_time_int(); + float_t fps = roundf((float_t)(1000000 * (get_main_timer() - main_timer)) / (float_t)time * 100.0f) * 0.01f; + if (max_time >= time) + break; + + if (res_window_get()->resolution_mode == RESOLUTION_MODE_HD && (fps < 59.940002f || fps > 60.060001f)) { + printf_debug("%s: %f(%zu) -> retry\n", "app_system_detail::SystemInfo::MeasureFps::exec", fps, retry_count); + retry_count++; + if (retry_count < 3) { + state = 1; + break; + } + + fps = 60.0f; + } + + this->fps = fps; + state = 3; + printf_debug("%s: %f(%zu)\n", "app_system_detail::SystemInfo::MeasureFps::exec", fps, retry_count);*/ + + this->fps = 60.0; + state = 3; + } break; + } +} + +app_system_detail::SystemWork::SystemWork() : field_0(), field_1(), pause(), main_timer(), field_8(), frame_speed(), +delta_frame_history_frac(), delta_frame_history_int(), select_frame_speed(), frame_rate(), fps(), vsync_emulation(), +field_DC(), field_E0(), next_frame_speed(), next_select_frame_speed(), field_F0(), field_F4() { + +} + +static void delta_frame_history_ctrl() { + float_t& delta_frame_history_frac = app_system_detail::system_work.delta_frame_history_frac; + int32_t& delta_frame_history_int = app_system_detail::system_work.delta_frame_history_int; + + delta_frame_history_frac += get_delta_frame(); + + float_t mod; + delta_frame_history_frac = modff(delta_frame_history_frac, &mod); + delta_frame_history_int = (int32_t)mod; + + if (delta_frame_history_frac < 0.001f) + delta_frame_history_frac = 0.0f; + else if (1.0f - delta_frame_history_frac < 0.001f) { + delta_frame_history_int++; + delta_frame_history_frac = 0.0f; + } +} + +static void main_thread_id_get() { + main_thread_id = GetCurrentThreadId(); + main_thread_id_init = true; +} + +static void sub_140193580() { + set_vsync_emulation(false); + app_system_detail::system_work.field_E0 = 0; + app_system_detail::system_work.time_rndr_start.get_timestamp(); +} + +static void sub_140194B70() { + int64_t time_rndr = app_system_detail::system_work.time_rndr_start.calc_time_int_get_timestamp(); + app_system_detail::system_work.fps = (float_t)1000000LL / (float_t)time_rndr; + + time_struct time_vblank_start; + if (app_system_detail::system_work.vsync_emulation) { + app_system_detail::system_work.field_E0 += time_rndr; + app_system_detail::system_work.field_DC++; + app_system_detail::system_work.fps = (float_t)(1000000LL * app_system_detail::system_work.field_DC) + / (float_t)app_system_detail::system_work.field_E0; + if (app_system_detail::system_work.field_DC >= 60) { + app_system_detail::system_work.field_DC /= 2; + app_system_detail::system_work.field_E0 /= 2; + } + } + + app_system_detail::system_work.time_vblank.set_value(time_vblank_start.calc_time_int()); +} \ No newline at end of file diff --git a/src/CRE/app_system_detail.hpp b/src/CRE/app_system_detail.hpp new file mode 100644 index 00000000..e7e3a60c --- /dev/null +++ b/src/CRE/app_system_detail.hpp @@ -0,0 +1,36 @@ +/* + by korenkonder + GitHub/GitLab: korenkonder +*/ + +#pragma once + +#include "../KKdLib/default.hpp" + +extern void finish_calc_process(); +extern void finish_render_process(); + +extern float_t get_anim_frame_speed(); +extern float_t get_delta_frame(); +extern int32_t get_delta_frame_history_int(); +extern float_t get_fps(); +extern float_t get_frame_speed(); +extern uint32_t get_main_timer(); +extern float_t get_measured_fps(); +extern bool get_pause(); + +extern void measure_fps_init(int32_t max_time_sec); +extern bool measure_fps_check_state(); + +extern void set_next_frame_speed(float_t value); +extern void set_vsync_emulation(bool value); + +extern void start_frame_process(); +extern void start_render_process(); + +extern void system_work_init(uint32_t a1); + +extern bool sub_1401921D0(); + +extern int32_t sub_140192D00(); +extern void sub_140194880(int32_t a1); diff --git a/src/CRE/auth_3d.cpp b/src/CRE/auth_3d.cpp index 331be42d..ef736ad6 100644 --- a/src/CRE/auth_3d.cpp +++ b/src/CRE/auth_3d.cpp @@ -14,6 +14,7 @@ #include "../KKdLib/sort.hpp" #include "../KKdLib/str_utils.hpp" #include "rob/rob.hpp" +#include "app_system_detail.hpp" #include "clear_color.hpp" #include "data.hpp" #include "effect.hpp" diff --git a/src/CRE/effect.cpp b/src/CRE/effect.cpp index 8785c915..f7edbd76 100644 --- a/src/CRE/effect.cpp +++ b/src/CRE/effect.cpp @@ -12,6 +12,7 @@ #include "GL/shader_storage_buffer.hpp" #include "GL/uniform_buffer.hpp" #include "rob/rob.hpp" +#include "app_system_detail.hpp" #include "auth_3d.hpp" #include "data.hpp" #include "gl_state.hpp" diff --git a/src/CRE/frame_rate_control.cpp b/src/CRE/frame_rate_control.cpp index bd70d1fe..b5744711 100644 --- a/src/CRE/frame_rate_control.cpp +++ b/src/CRE/frame_rate_control.cpp @@ -4,7 +4,7 @@ */ #include "frame_rate_control.hpp" -#include "static_var.hpp" +#include "app_system_detail.hpp" SysFrameRate sys_frame_rate; diff --git a/src/CRE/light_param/wind.cpp b/src/CRE/light_param/wind.cpp index 8e1b891c..307b9927 100644 --- a/src/CRE/light_param/wind.cpp +++ b/src/CRE/light_param/wind.cpp @@ -5,6 +5,7 @@ #include "wind.hpp" #include "../rob/rob.hpp" +#include "../app_system_detail.hpp" static float_t wind_apply_spc(wind* w, float_t frame); static void wind_ctrl(wind* w); diff --git a/src/CRE/pv_param.cpp b/src/CRE/pv_param.cpp index b870a9fc..600acf96 100644 --- a/src/CRE/pv_param.cpp +++ b/src/CRE/pv_param.cpp @@ -4,10 +4,11 @@ */ #include "pv_param.hpp" -#include "render.hpp" -#include "render_context.hpp" #include "../KKdLib/io/file_stream.hpp" #include "../KKdLib/str_utils.hpp" +#include "app_system_detail.hpp" +#include "render.hpp" +#include "render_context.hpp" extern render_context* rctx_ptr; diff --git a/src/CRE/render_context.cpp b/src/CRE/render_context.cpp index c413d28b..407acdf9 100644 --- a/src/CRE/render_context.cpp +++ b/src/CRE/render_context.cpp @@ -4,14 +4,12 @@ */ #include "render_context.hpp" +#include "app_system_detail.hpp" #include "shader_ft.hpp" #include "sound.hpp" #include "sprite.hpp" #include "task.hpp" -float_t delta_frame_history = 0; -int32_t delta_frame_history_int = 0; - extern float_t rob_frame; extern render_context* rctx_ptr; @@ -666,28 +664,20 @@ render_context::~render_context() { } void render_context::ctrl() { - if (!get_pause()) { - delta_frame_history += get_delta_frame(); - float_t mod; - delta_frame_history = modff(delta_frame_history, &mod); - delta_frame_history_int = (int32_t)mod; - if (delta_frame_history < 0.001f) - delta_frame_history = 0.0f; - else if (1.0f - delta_frame_history < 0.001f) - delta_frame_history_int++; - } - rctx_ptr = this; + start_frame_process(); extern bool game_state_get_pause(); if (!get_pause() || !game_state_get_pause()) app::TaskWork::ctrl(); sound_ctrl(); file_handler_storage_ctrl(); + finish_calc_process(); } void render_context::disp() { rctx_ptr = this; + start_render_process(); disp_manager->refresh(); draw_state->stats_prev = draw_state->stats; draw_state->stats.reset(); @@ -708,6 +698,7 @@ void render_context::disp() { render_manager->field_31C = false; if (!get_pause()) app::TaskWork::basic(); + finish_render_process(); } void render_context::free() { diff --git a/src/CRE/rob/ex_block.cpp b/src/CRE/rob/ex_block.cpp index 83f2234b..e527c75b 100644 --- a/src/CRE/rob/ex_block.cpp +++ b/src/CRE/rob/ex_block.cpp @@ -6,6 +6,7 @@ #include "rob.hpp" #include "../../KKdLib/key_val.hpp" #include "../../KKdLib/str_utils.hpp" +#include "../app_system_detail.hpp" #include "../data.hpp" #include "skin_param.hpp" diff --git a/src/CRE/shader_ft.cpp b/src/CRE/shader_ft.cpp index 2bdaf7e3..2ed3142e 100644 --- a/src/CRE/shader_ft.cpp +++ b/src/CRE/shader_ft.cpp @@ -5,6 +5,7 @@ #include "shader_ft.hpp" #include "../KKdLib/str_utils.hpp" +#include "app_system_detail.hpp" #include "gl_state.hpp" #include "random.hpp" #include "render_context.hpp" @@ -1399,7 +1400,7 @@ static void glass_eye_calc(glass_eye_struct* glass_eye) { return; } - uint32_t frame = get_frame_counter(); + uint32_t frame = get_main_timer(); if (frame == glass_eye->frame) return; diff --git a/src/CRE/static_var.cpp b/src/CRE/static_var.cpp index 42dbadf4..abf63cfb 100644 --- a/src/CRE/static_var.cpp +++ b/src/CRE/static_var.cpp @@ -4,9 +4,6 @@ */ #include "static_var.hpp" -#include "../KKdLib/timer.hpp" - -extern timer* render_timer; int32_t sv_max_texture_buffer_size = 0x100000; int32_t sv_max_texture_size = 2048; @@ -16,16 +13,6 @@ bool sv_anisotropy_changed = false; int32_t sv_old_anisotropy = 1; int32_t sv_anisotropy = 1; -bool pause = false; - -size_t frame_counter = 0; - -bool select_frame_speed = false; -float_t frame_speed = 1.0f; -float_t target_anim_fps = 60.0f; -float_t target_fps = 60.0f; -float_t current_fps = 60.0f; - int32_t uniform_value[U_MAX]; const vec3 sv_rgb_to_luma = { @@ -51,30 +38,6 @@ void sv_anisotropy_set(int32_t value) { sv_old_anisotropy = sv_anisotropy; } -float_t get_anim_frame_speed() { - return 60.0f / target_anim_fps; -} - -float_t get_delta_frame() { - if (!select_frame_speed) - return frame_speed; - - double_t freq_ratio = render_timer->get_freq_ratio(); - return (float_t)(freq_ratio * frame_speed); -} - -uint32_t get_frame_counter() { - return (uint32_t)frame_counter; -} - -bool get_pause() { - return pause; -} - -float_t get_target_anim_fps() { - return target_anim_fps; -} - void uniform_value_reset() { uniform_value[U_ANISO] = 0; uniform_value[U0B] = 0; diff --git a/src/CRE/static_var.hpp b/src/CRE/static_var.hpp index 71b6df71..bec8ce22 100644 --- a/src/CRE/static_var.hpp +++ b/src/CRE/static_var.hpp @@ -119,9 +119,4 @@ extern const mat3 sv_rgb_to_ypbpr; extern const mat3 sv_ypbpr_to_rgb; extern void sv_anisotropy_set(int32_t value); -extern float_t get_anim_frame_speed(); -extern float_t get_delta_frame(); -extern uint32_t get_frame_counter(); -extern bool get_pause(); -extern float_t get_target_anim_fps(); extern void uniform_value_reset(); diff --git a/src/CRE/task.cpp b/src/CRE/task.cpp index 958af32a..91cf1907 100644 --- a/src/CRE/task.cpp +++ b/src/CRE/task.cpp @@ -4,14 +4,9 @@ */ #include "task.hpp" +#include "../CRE/app_system_detail.hpp" #include "../KKdLib/time.hpp" -extern float_t get_delta_frame(); -extern uint32_t get_frame_counter(); - -extern float_t delta_frame_history; -extern int32_t delta_frame_history_int; - namespace app { static void Task_add_base_calc_time(Task* t, uint32_t value); static void Task_do_basic(Task* t); @@ -225,7 +220,7 @@ namespace app { i = task_work->tasks.erase(i); } - int32_t frames = delta_frame_history_int; + int32_t frames = get_delta_frame_history_int(); if (frames > 1) for (int32_t i = frames - 1; i; i--) Task_do_ctrl_frames(frames, true); @@ -375,16 +370,16 @@ namespace app { static void Task_set_calc_time(Task* t) { t->calc_time = t->base_calc_time; - uint32_t frame_counter = get_frame_counter(); - if (frame_counter == (frame_counter / 300) * 300) + uint32_t main_timer = get_main_timer(); + if (main_timer == (main_timer / 300) * 300) t->calc_time_max = 0; t->calc_time = max_def(t->calc_time, t->calc_time_max); } static void Task_set_disp_time(Task* t, uint32_t value) { t->disp_time = value; - uint32_t frame_counter = get_frame_counter(); - if (frame_counter == (frame_counter / 300) * 300) + uint32_t main_timer = get_main_timer(); + if (main_timer == (main_timer / 300) * 300) t->disp_time_max = 0; t->disp_time = max_def(t->disp_time, t->disp_time_max); } diff --git a/src/KKdLib/time.cpp b/src/KKdLib/time.cpp index f395acb5..98918390 100644 --- a/src/KKdLib/time.cpp +++ b/src/KKdLib/time.cpp @@ -14,16 +14,38 @@ time_struct::time_struct() : timestamp() { double_t time_struct::calc_time() { LARGE_INTEGER timestamp; - if (QueryPerformanceCounter(×tamp)) - return (double_t)(timestamp.QuadPart - this->timestamp.QuadPart) * inv_freq; - return 0.0; + if (!QueryPerformanceCounter(×tamp)) + timestamp.QuadPart = 0; + + return (double_t)(timestamp.QuadPart - this->timestamp.QuadPart) * inv_freq; +} + +double_t time_struct::calc_time_get_timestamp() { + LARGE_INTEGER timestamp; + if (!QueryPerformanceCounter(×tamp)) + timestamp.QuadPart = 0; + + double_t time = (double_t)(timestamp.QuadPart - this->timestamp.QuadPart) * inv_freq; + this->timestamp = timestamp; + return time; } int64_t time_struct::calc_time_int() { LARGE_INTEGER timestamp; - if (QueryPerformanceCounter(×tamp)) - return (int64_t)((double_t)(timestamp.QuadPart - this->timestamp.QuadPart) * inv_freq * 1000.0); - return 0; + if (!QueryPerformanceCounter(×tamp)) + timestamp.QuadPart = 0; + + return (int64_t)((double_t)(timestamp.QuadPart - this->timestamp.QuadPart) * inv_freq * 1000.0); +} + +int64_t time_struct::calc_time_int_get_timestamp() { + LARGE_INTEGER timestamp; + if (!QueryPerformanceCounter(×tamp)) + timestamp.QuadPart = 0; + + int64_t time = (int64_t)((double_t)(timestamp.QuadPart - this->timestamp.QuadPart) * inv_freq * 1000.0); + this->timestamp = timestamp; + return time; } void time_struct::get_timestamp() { diff --git a/src/KKdLib/time.hpp b/src/KKdLib/time.hpp index 2f8d966b..99145559 100644 --- a/src/KKdLib/time.hpp +++ b/src/KKdLib/time.hpp @@ -14,6 +14,8 @@ struct time_struct { time_struct(); double_t calc_time(); + double_t calc_time_get_timestamp(); int64_t calc_time_int(); + int64_t calc_time_int_get_timestamp(); void get_timestamp(); }; diff --git a/src/KKdLib/timer.cpp b/src/KKdLib/timer.cpp index bd8bb9c7..8421bbfc 100644 --- a/src/KKdLib/timer.cpp +++ b/src/KKdLib/timer.cpp @@ -84,20 +84,6 @@ double_t timer::get_freq_hist() { return freq_hist; } -double_t timer::get_freq_ratio() { - double_t freq_ratio = 0.0; - { - std::unique_lock u_lock(freq_mtx); - freq_ratio = freq; - } - - { - std::unique_lock u_lock(freq_hist_mtx); - freq_ratio /= freq_hist; - } - return freq_ratio; -} - void timer::reset() { if (!QueryPerformanceCounter(&curr_time)) curr_time.QuadPart = 0; diff --git a/src/KKdLib/timer.hpp b/src/KKdLib/timer.hpp index b5711110..75eb2e35 100644 --- a/src/KKdLib/timer.hpp +++ b/src/KKdLib/timer.hpp @@ -31,7 +31,6 @@ struct timer { double_t get_freq(); void set_freq(double_t freq); double_t get_freq_hist(); - double_t get_freq_ratio(); void reset(); void sleep(double_t msec); }; diff --git a/src/ReDIVA/app.cpp b/src/ReDIVA/app.cpp index aca60bd5..916faeb9 100644 --- a/src/ReDIVA/app.cpp +++ b/src/ReDIVA/app.cpp @@ -11,6 +11,7 @@ #include "../CRE/rob/rob.hpp" #include "../CRE/rob/motion.hpp" #include "../CRE/rob/skin_param.hpp" +#include "../CRE/app_system_detail.hpp" #include "../CRE/auth_2d.hpp" #include "../CRE/auth_3d.hpp" #include "../CRE/camera.hpp" @@ -233,7 +234,6 @@ GLFWwindow* window; ImGuiContext* imgui_context; lock_cs* imgui_context_lock; bool global_context_menu; -extern size_t frame_counter; render_context* rctx_ptr; bool task_stage_is_modern; @@ -310,8 +310,6 @@ int32_t app_main(const app_init_struct& ais) { rctx = render_context_load(); lock_unlock(render_lock); - frame_counter = 0; - #if !(BAKE_PNG || BAKE_VIDEO) glfwGetFramebufferSize(window, &width, &height); #endif @@ -354,6 +352,10 @@ void app_set_render_scale_index(int32_t index) { scale_index = index >= 0 && index < RENDER_SCALE_MAX ? index : RENDER_SCALE_100; } +void app_swap_buffers() { + glfwSwapBuffers(window); +} + float_t rob_frame = 0.0f; render_data::render_data() { @@ -547,11 +549,10 @@ static void app_main_loop(render_context* rctx) { render_context_disp(rctx); close |= !!glfwWindowShouldClose(window); - frame_counter++; Input::EndFrame(); - glfwSwapBuffers(window); + app_swap_buffers(); render_timer->end_of_cycle(); } } @@ -564,6 +565,11 @@ static void app_free() { } static render_context* render_context_load() { + system_work_init(13); + + // Enable the dw_gui widgets + sub_140194880(1); + data_struct_init(); data_struct_load("ReDIVA_data.txt"); data_struct_load_db(); diff --git a/src/ReDIVA/classes/graphics/render_settings.cpp b/src/ReDIVA/classes/graphics/render_settings.cpp index 0c6b101a..64e7e118 100644 --- a/src/ReDIVA/classes/graphics/render_settings.cpp +++ b/src/ReDIVA/classes/graphics/render_settings.cpp @@ -5,7 +5,6 @@ #include "render_settings.hpp" #include "../../../CRE/lock.hpp" -#include "../../../CRE/static_var.hpp" #include "../../../KKdLib/timer.hpp" #include "../../app.hpp" #include "../../imgui_helper.hpp" diff --git a/src/ReDIVA/classes/information/frame_speed.cpp b/src/ReDIVA/classes/information/frame_speed.cpp index 7113018e..5b7d1ab2 100644 --- a/src/ReDIVA/classes/information/frame_speed.cpp +++ b/src/ReDIVA/classes/information/frame_speed.cpp @@ -4,11 +4,11 @@ */ #include "frame_speed.hpp" +#include "../../../CRE/app_system_detail.hpp" #include "../../imgui_helper.hpp" extern int32_t width; extern int32_t height; -extern float_t frame_speed; static const char* information_frame_speed_window_title = "FrameSpeedWindow##Information"; @@ -44,8 +44,10 @@ void information_frame_speed_imgui(class_data* data) { return; } + float_t frame_speed = get_frame_speed(); ImGui::GetContentRegionAvailSetNextItemWidth(); ImGui::ColumnSliderFloatButton("frame speed", &frame_speed, 0.01f, 0.0f, 3.0f, 0.1f, "%.2f", 0); + set_next_frame_speed(frame_speed); data->imgui_focus |= ImGui::IsWindowFocused(); ImGui::End(); diff --git a/src/ReDIVA/data_edit/glitter_editor.cpp b/src/ReDIVA/data_edit/glitter_editor.cpp index 03239a97..daf776a2 100644 --- a/src/ReDIVA/data_edit/glitter_editor.cpp +++ b/src/ReDIVA/data_edit/glitter_editor.cpp @@ -14,6 +14,7 @@ #include "../../KKdLib/txp.hpp" #include "../../KKdLib/vec.hpp" #include "../../CRE/Glitter/glitter.hpp" +#include "../../CRE/app_system_detail.hpp" #include "../../CRE/camera.hpp" #include "../../CRE/data.hpp" #include "../../CRE/gl_state.hpp" diff --git a/src/ReDIVA/data_initialize.cpp b/src/ReDIVA/data_initialize.cpp index 129f1d57..b9314871 100644 --- a/src/ReDIVA/data_initialize.cpp +++ b/src/ReDIVA/data_initialize.cpp @@ -6,6 +6,7 @@ #include "data_initialize.hpp" #include "../CRE/rob/rob.hpp" #include "../CRE/auth_2d.hpp" +#include "../CRE/app_system_detail.hpp" #include "../CRE/customize_item_table.hpp" #include "../CRE/data.hpp" #include "../CRE/font.hpp" @@ -69,11 +70,11 @@ bool TaskDataInit::ctrl() { state = field_6C ? 2 : 4; break; case 2: - //sub_140194800(10); + measure_fps_init(10); state = 3; break; case 3: - //if (sub_1401935C0()) // Measure FPS + if (measure_fps_check_state()) state = 4; break; case 4: { diff --git a/src/ReDIVA/data_test/auth_3d_test.cpp b/src/ReDIVA/data_test/auth_3d_test.cpp index 698b6318..98797789 100644 --- a/src/ReDIVA/data_test/auth_3d_test.cpp +++ b/src/ReDIVA/data_test/auth_3d_test.cpp @@ -5,6 +5,7 @@ #include "auth_3d_test.hpp" #include "../../CRE/rob/rob.hpp" +#include "../../CRE/app_system_detail.hpp" #include "../../CRE/clear_color.hpp" #include "../../CRE/data.hpp" #include "../../CRE/effect.hpp" @@ -311,6 +312,7 @@ static SelectionButtonBool selection_button_bool; static bool snap_shot; static void auth_3d_test_window_init(); +static const char* get_dev_ram_ss_dir(); Auth3dTestTask::Auth3dTestTask::Window::Window() { stage_link_change = true; @@ -439,6 +441,31 @@ bool Auth3dTestTask::ctrl() { mat4_translate(&trans_value, &mat); mat4_mul_rotate_y(&mat, rot_y_value * DEG_TO_RAD_FLOAT, &mat); auth_3d_id.set_mat(mat); + + if (!snap_shot_state && ::snap_shot && snap_shot) + snap_shot_state = 1; + + if (snap_shot_state == 2) { + snap_shot = false; + sub_140194880(2); + snap_shot_state = 0; + } + + if (snap_shot_state == 1) { + data_struct* aft_data = &data_list[DATA_AFT]; + auth_3d_database* aft_auth_3d_db = &aft_data->data_ft.auth_3d_db; + + const char* name = auth_3d_data_get_uid_name(auth_3d_id.get_uid(), aft_auth_3d_db); + + std::string path(get_dev_ram_ss_dir()); + path.append("/"); + path.append(name); + + //screen_shot_impl_ptr->capture_window_frame(path, auth_3d_id.get_frame()); + + if (auth_3d_id.get_ended()) + snap_shot_state = 2; + } } sub_140244610(); @@ -1575,3 +1602,7 @@ static void auth_3d_test_window_init() { auth_3d_test_window->rob_window->Disp(); } } + +static const char* get_dev_ram_ss_dir() { + return "dev_ram/ss"; +} diff --git a/src/ReDIVA/data_test/motion_test.cpp b/src/ReDIVA/data_test/motion_test.cpp index edfc8f36..74e08d9b 100644 --- a/src/ReDIVA/data_test/motion_test.cpp +++ b/src/ReDIVA/data_test/motion_test.cpp @@ -7,6 +7,7 @@ #include "../../KKdLib/prj/algorithm.hpp" #include "../../CRE/rob/motion.hpp" #include "../../CRE/rob/skin_param.hpp" +#include "../../CRE/app_system_detail.hpp" #include "../../CRE/clear_color.hpp" #include "../../CRE/data.hpp" #include "../../CRE/render_context.hpp" diff --git a/src/ReDIVA/data_test/opd_test.cpp b/src/ReDIVA/data_test/opd_test.cpp index 346ecf2f..05c4025e 100644 --- a/src/ReDIVA/data_test/opd_test.cpp +++ b/src/ReDIVA/data_test/opd_test.cpp @@ -4,6 +4,7 @@ */ #include "opd_test.hpp" +#include "../../CRE/app_system_detail.hpp" #include "../../CRE/data.hpp" #include "../../CRE/module_table.hpp" #include "../../KKdLib/io/path.hpp" @@ -155,7 +156,7 @@ void TaskDataTestOpd::disp() { print_work.text_current_loc = 10.0f; print_work.SetResolutionMode(RESOLUTION_MODE_MAX); print_work.printf_align_left("OSAGE PLAY DATA MAKE MODE \n"); - print_work.printf_align_left("%s\n", cursor_array[get_frame_counter() % 3]); + print_work.printf_align_left("%s\n", cursor_array[get_main_timer() % 3]); print_work.printf_align_left("STATUS: "); switch (state) { diff --git a/src/ReDIVA/dw.cpp b/src/ReDIVA/dw.cpp index cc854781..40111a5b 100644 --- a/src/ReDIVA/dw.cpp +++ b/src/ReDIVA/dw.cpp @@ -4,6 +4,7 @@ */ #include "dw.hpp" +#include "../CRE/app_system_detail.hpp" #include "../CRE/data.hpp" #include "input_state.hpp" #include "print_work.hpp" @@ -164,10 +165,6 @@ namespace dw_gui_detail { dw_gui_detail::Display* dw_gui_detail_display; -int32_t dword_140EDA6B8; - -extern bool input_locked; - static bool dw_gui_get_ctrl(); static bool dw_gui_get_disp(); @@ -3121,17 +3118,6 @@ void dw_gui_ctrl_disp() { dw_gui_detail_display->Draw(); }; -int32_t sub_140192D00() { - //return dword_140EDA6B8; - return 1; -} - -void sub_140194880(int32_t a1) { - if (a1 > 2) - a1 = 0; - dword_140EDA6B8 = a1; -} - PrintWorkDebug::PrintWorkDebug() { prio = spr::SPR_PRIO_29; SetResolutionMode(RESOLUTION_MODE_MAX); diff --git a/src/ReDIVA/dw.hpp b/src/ReDIVA/dw.hpp index ca480af5..e05f40cc 100644 --- a/src/ReDIVA/dw.hpp +++ b/src/ReDIVA/dw.hpp @@ -878,6 +878,3 @@ extern void dw_init(dw::init_data& init_data); extern void dw_free(); extern void dw_gui_ctrl_disp(); - -extern int32_t sub_140192D00(); -extern void sub_140194880(int32_t a1); diff --git a/src/ReDIVA/input.cpp b/src/ReDIVA/input.cpp index 12ab5b8c..651a29ea 100644 --- a/src/ReDIVA/input.cpp +++ b/src/ReDIVA/input.cpp @@ -285,9 +285,6 @@ namespace Input { speed *= frame_speed; speed_fast *= frame_speed; speed_slow *= frame_speed; - speed *= freq / freq_hist; - speed_fast *= freq / freq_hist; - speed_slow *= freq / freq_hist; speed *= 10.0; speed_fast *= 10.0; speed_slow *= 10.0; diff --git a/src/ReDIVA/pv_game/pv_game.cpp b/src/ReDIVA/pv_game/pv_game.cpp index af349579..270b3948 100644 --- a/src/ReDIVA/pv_game/pv_game.cpp +++ b/src/ReDIVA/pv_game/pv_game.cpp @@ -8,6 +8,7 @@ #include "../../CRE/Glitter/glitter.hpp" #include "../../CRE/rob/motion.hpp" #include "../../CRE/rob/skin_param.hpp" +#include "../../CRE/app_system_detail.hpp" #include "../../CRE/customize_item_table.hpp" #include "../../CRE/effect.hpp" #include "../../CRE/hand_item.hpp" @@ -1799,7 +1800,7 @@ void pv_game::edit_effect_ctrl(float_t delta_time) { float_t end_frame = data.edit_effect.data.end_frame; float_t frame = 0.0f; if (end_frame > 0.0f) { - frame = get_target_anim_fps() * data.edit_effect.data.time; + frame = get_measured_fps() * data.edit_effect.data.time; if (data.edit_effect.data.loop) frame = fmodf(frame, end_frame + 1.0f); else if (frame > end_frame) @@ -3712,7 +3713,7 @@ bool pv_game::load() { } float_t view_point_xz_pos_angle = - (float_t)(36 * get_frame_counter() % 360) * DEG_TO_RAD_FLOAT; + (float_t)(36 * get_main_timer() % 360) * DEG_TO_RAD_FLOAT; vec3 view_point; view_point.x = sinf(view_point_xz_pos_angle) * 40.0f; view_point.y = 0.0f; @@ -5295,8 +5296,7 @@ bool TaskPvGame::dest() { if (!unload()) return false; - extern float_t frame_speed; - frame_speed = 1.0f; + set_next_frame_speed(1.0f); //touch_util::touch_reaction_set_enable(true); return true; @@ -5400,8 +5400,7 @@ void TaskPvGame::basic() { if (pause && !is_paused) { pv_game_time_pause(); - extern float_t frame_speed; - frame_speed = 0.0f; + set_next_frame_speed(0.0f); is_paused = true; } @@ -5409,8 +5408,7 @@ void TaskPvGame::basic() { if (!pause && is_paused) { pv_game_time_start(); - extern float_t frame_speed; - frame_speed = 1.0f; + set_next_frame_speed(1.0f); is_paused = false; } diff --git a/src/ReDIVA/pv_game/pv_game_pv_data.cpp b/src/ReDIVA/pv_game/pv_game_pv_data.cpp index f0dacf79..ffb99655 100644 --- a/src/ReDIVA/pv_game/pv_game_pv_data.cpp +++ b/src/ReDIVA/pv_game/pv_game_pv_data.cpp @@ -5,6 +5,7 @@ #include "pv_game_pv_data.hpp" #include "../../CRE/rob/motion.hpp" +#include "../../CRE/app_system_detail.hpp" #include "../../CRE/pv_expression.hpp" #include "../../CRE/pv_param.hpp" #include "../information/dw_console.hpp" @@ -320,7 +321,7 @@ scene_rot_y(), field_2C550(), branch_mode(), last_challenge_note(), field_2C560( fov = 32.2673416137695f; min_dist = 0.05f; target_flying_time = -1.0f; - target_anim_fps = 60.0f; + measured_fps = 60.0f; anim_frame_speed = 1.0f; time_signature = -1; scene_rot_mat = mat4_identity; @@ -1145,7 +1146,7 @@ bool pv_game_pv_data::dsc_ctrl(float_t delta_time, int64_t curr_time, /*if (!has_perf_id) { int32_t mottbl_index = mouth_anim_id_to_mottbl_index(mouth_anim_id); float_t value = pv_game->data.field_2D090 && mottbl_index != 144 ? 0.0f : 1.0f; - rob_chr->set_mouth_mottbl_motion(0, mottbl_index, value, 0, target_anim_fps * 0.1, + rob_chr->set_mouth_mottbl_motion(0, mottbl_index, value, 0, measured_fps * 0.1, 0.0f, 1.0f, -1, pv_game->data.get_anim_offset(), aft_mot_db); }*/ } @@ -1240,7 +1241,7 @@ bool pv_game_pv_data::dsc_ctrl(float_t delta_time, int64_t curr_time, break; int32_t mottbl_index = mouth_anim_id_to_mottbl_index(mouth_anim_id); - blend_duration *= target_anim_fps; + blend_duration *= measured_fps; float_t value = pv_game->data.field_2D090 && mottbl_index != 144 ? 0.0f : 1.0f; rob_chr->set_mouth_mottbl_motion(0, mottbl_index, value, 0, blend_duration, @@ -1374,14 +1375,14 @@ bool pv_game_pv_data::dsc_ctrl(float_t delta_time, int64_t curr_time, v13 = 0; float_t v363 = motion_storage_get_mot_data_frame_count(rob_chr-> get_rob_cmn_mottbl_motion_id(mottbl_index), aft_mot_db) - 1.0f; - step = v533 > 0.0f ? v363 / target_anim_fps * v533 : 1.0f; + step = v533 > 0.0f ? v363 / measured_fps * v533 : 1.0f; } break; case 3: { state = 4; v13 = 0; float_t v363 = motion_storage_get_mot_data_frame_count(rob_chr-> get_rob_cmn_mottbl_motion_id(mottbl_index), aft_mot_db) - 1.0f; - step = v533 > 0.0f ? v363 / target_anim_fps * v533 : 1.0f; + step = v533 > 0.0f ? v363 / measured_fps * v533 : 1.0f; } break; } @@ -2365,7 +2366,7 @@ void pv_game_pv_data::init(::pv_game* pv_game, bool music_play) { this->pv_game = pv_game; //field_2BF80 = sub_14013C8F0(); music = pv_game_music_get(); - target_anim_fps = get_target_anim_fps(); + measured_fps = get_measured_fps(); anim_frame_speed = get_anim_frame_speed(); pv_expression_array_reset(); diff --git a/src/ReDIVA/pv_game/pv_game_pv_data.hpp b/src/ReDIVA/pv_game/pv_game_pv_data.hpp index 27f7303b..7e914d92 100644 --- a/src/ReDIVA/pv_game/pv_game_pv_data.hpp +++ b/src/ReDIVA/pv_game/pv_game_pv_data.hpp @@ -279,7 +279,7 @@ struct pv_game_pv_data { //struc_162* field_2BF80; struct pv_game_music* music; p_file_handler dsc_file_handler; - float_t target_anim_fps; + float_t measured_fps; float_t anim_frame_speed; float_t target_flying_time; int32_t time_signature; diff --git a/src/ReDIVA/system_startup.cpp b/src/ReDIVA/system_startup.cpp index cb6c9a89..9befdce4 100644 --- a/src/ReDIVA/system_startup.cpp +++ b/src/ReDIVA/system_startup.cpp @@ -4,6 +4,7 @@ */ #include "system_startup.hpp" +#include "../CRE/app_system_detail.hpp" #include "../CRE/auth_2d.hpp" #include "../CRE/mdata_manager.hpp" #include "../CRE/sprite.hpp" @@ -246,7 +247,7 @@ namespace system_startup_detail { break; case 1: { system_startup->print_work.PrintText(app::TEXT_FLAG_ALIGN_FLAG_LEFT, "DHCP WAIT "); - std::string buf = system_startup_get_wait(8, get_frame_counter() / 15); + std::string buf = system_startup_get_wait(8, get_main_timer() / 15); system_startup->print_work.PrintText(app::TEXT_FLAG_ALIGN_FLAG_LEFT, buf.data(), buf.size()); system_startup->print_work.PrintText(app::TEXT_FLAG_ALIGN_FLAG_LEFT, "\n"); diff --git a/src/ReDIVA/x_pv_game.cpp b/src/ReDIVA/x_pv_game.cpp index 7c7e2217..6a10aac3 100644 --- a/src/ReDIVA/x_pv_game.cpp +++ b/src/ReDIVA/x_pv_game.cpp @@ -9,6 +9,7 @@ #include "../CRE/rob/rob.hpp" #include "../CRE/rob/motion.hpp" #include "../CRE/rob/skin_param.hpp" +#include "../CRE/app_system_detail.hpp" #include "../CRE/data.hpp" #include "../CRE/effect.hpp" #include "../CRE/item_table.hpp" @@ -2623,7 +2624,7 @@ void x_pv_game_title::unload_data() { x_pv_game_pv_data::x_pv_game_pv_data() : pv_game(), dsc_data_ptr(), dsc_data_ptr_end(), play(), chara_id(), dsc_time(), pv_end(), playdata(), scene_rot_y(), branch_mode() { - target_anim_fps = 60.0f; + measured_fps = 60.0f; anim_frame_speed = 1.0f; scene_rot_mat = mat4_identity; @@ -4123,11 +4124,11 @@ void x_pv_game_pv_data::find_stage_effects(prj::vector_pair& s void x_pv_game_pv_data::init(class x_pv_game* pv_game, bool music_play) { this->pv_game = pv_game; - target_anim_fps = 60.0f; + measured_fps = 60.0f; anim_frame_speed = 1.0f; scene_rot_mat = mat4_identity; - target_anim_fps = get_target_anim_fps(); + measured_fps = get_measured_fps(); anim_frame_speed = get_anim_frame_speed(); pv_expression_array_reset(); @@ -7409,8 +7410,7 @@ bool x_pv_game::ctrl() { Glitter::glt_particle_manager->SetPause(false); get_data().bar_beat.reset_time(); - extern float_t frame_speed; - frame_speed = 1.0f; + set_next_frame_speed(1.0f); pause = false; step_frame = false; @@ -7848,8 +7848,8 @@ bool x_pv_game::dest() { task_rob_manager_del_task(); Glitter::glt_particle_manager->SetPause(false); - extern float_t frame_speed; - frame_speed = 1.0f; + + set_next_frame_speed(1.0f); extern bool close; //close = true; @@ -7912,8 +7912,8 @@ void x_pv_game::basic() { } Glitter::glt_particle_manager->SetPause(pause); - extern float_t frame_speed; - frame_speed = pause ? 0.0f : 1.0f; + + set_next_frame_speed(pause ? 0.0f : 1.0f); #if BAKE_PV826 for (auto& i : effchrpv_auth_3d_rob_mot_ids) { diff --git a/src/ReDIVA/x_pv_game.hpp b/src/ReDIVA/x_pv_game.hpp index 9982f456..156a8abf 100644 --- a/src/ReDIVA/x_pv_game.hpp +++ b/src/ReDIVA/x_pv_game.hpp @@ -566,7 +566,7 @@ struct x_pv_game_pv_data { std::vector set_motion[ROB_CHARA_COUNT]; int32_t chara_id; class x_pv_game* pv_game; - float_t target_anim_fps; + float_t measured_fps; float_t anim_frame_speed; int64_t dsc_time; bool pv_end;