@@ -190,8 +190,12 @@ static int game_framebuffer_msaa_resolved;
190190
191191uint32_t gfx_msaa_level = 1 ;
192192
193+ static bool has_drawn_imgui_menu;
194+
193195static bool dropped_frame;
194196
197+ static const std::unordered_map<Mtx *, MtxF> *current_mtx_replacements;
198+
195199static float buf_vbo[MAX_BUFFERED * (32 * 3 )]; // 3 vertices in a triangle and 32 floats per vtx
196200static size_t buf_vbo_len;
197201static size_t buf_vbo_num_tris;
@@ -916,20 +920,31 @@ static void gfx_matrix_mul(float res[4][4], const float a[4][4], const float b[4
916920
917921static void gfx_sp_matrix (uint8_t parameters, const int32_t *addr) {
918922 float matrix[4 ][4 ];
923+
924+ if (auto it = current_mtx_replacements->find ((Mtx *)addr); it != current_mtx_replacements->end ()) {
925+ for (int i = 0 ; i < 4 ; i++) {
926+ for (int j = 0 ; j < 4 ; j++) {
927+ float v = it->second .mf [i][j];
928+ int as_int = (int )(v * 65536 .0f );
929+ matrix[i][j] = as_int * (1 .0f / 65536 .0f );
930+ }
931+ }
932+ } else {
919933#ifndef GBI_FLOATS
920- // Original GBI where fixed point matrices are used
921- for (int i = 0 ; i < 4 ; i++) {
922- for (int j = 0 ; j < 4 ; j += 2 ) {
923- int32_t int_part = addr[i * 2 + j / 2 ];
924- uint32_t frac_part = addr[8 + i * 2 + j / 2 ];
925- matrix[i][j] = (int32_t )((int_part & 0xffff0000 ) | (frac_part >> 16 )) / 65536 .0f ;
926- matrix[i][j + 1 ] = (int32_t )((int_part << 16 ) | (frac_part & 0xffff )) / 65536 .0f ;
934+ // Original GBI where fixed point matrices are used
935+ for (int i = 0 ; i < 4 ; i++) {
936+ for (int j = 0 ; j < 4 ; j += 2 ) {
937+ int32_t int_part = addr[i * 2 + j / 2 ];
938+ uint32_t frac_part = addr[8 + i * 2 + j / 2 ];
939+ matrix[i][j] = (int32_t )((int_part & 0xffff0000 ) | (frac_part >> 16 )) / 65536 .0f ;
940+ matrix[i][j + 1 ] = (int32_t )((int_part << 16 ) | (frac_part & 0xffff )) / 65536 .0f ;
941+ }
927942 }
928- }
929943#else
930- // For a modified GBI where fixed point values are replaced with floats
931- memcpy (matrix, addr, sizeof (matrix));
944+ // For a modified GBI where fixed point values are replaced with floats
945+ memcpy (matrix, addr, sizeof (matrix));
932946#endif
947+ }
933948
934949 if (parameters & G_MTX_PROJECTION ) {
935950 if (parameters & G_MTX_LOAD ) {
@@ -2708,6 +2723,7 @@ void gfx_start_frame(void) {
27082723 gfx_wapi->handle_events ();
27092724 gfx_wapi->get_dimensions (&gfx_current_window_dimensions.width , &gfx_current_window_dimensions.height );
27102725 SohImGui::DrawMainMenuAndCalculateGameSize ();
2726+ has_drawn_imgui_menu = true ;
27112727 if (gfx_current_dimensions.height == 0 ) {
27122728 // Avoid division by zero
27132729 gfx_current_dimensions.height = 1 ;
@@ -2746,7 +2762,7 @@ void gfx_start_frame(void) {
27462762 fbActive = 0 ;
27472763}
27482764
2749- void gfx_run (Gfx *commands) {
2765+ void gfx_run (Gfx *commands, const std::unordered_map<Mtx *, MtxF>& mtx_replacements ) {
27502766 gfx_sp_reset ();
27512767
27522768 // puts("New frame");
@@ -2755,12 +2771,21 @@ void gfx_run(Gfx *commands) {
27552771
27562772 if (!gfx_wapi->start_frame ()) {
27572773 dropped_frame = true ;
2758- SohImGui::DrawFramebufferAndGameInput ();
2759- SohImGui::CancelFrame ();
2774+ if (has_drawn_imgui_menu) {
2775+ SohImGui::DrawFramebufferAndGameInput ();
2776+ SohImGui::CancelFrame ();
2777+ has_drawn_imgui_menu = false ;
2778+ }
27602779 return ;
27612780 }
27622781 dropped_frame = false ;
27632782
2783+ if (!has_drawn_imgui_menu) {
2784+ SohImGui::DrawMainMenuAndCalculateGameSize ();
2785+ }
2786+
2787+ current_mtx_replacements = &mtx_replacements;
2788+
27642789 double t0 = gfx_wapi->get_time ();
27652790 gfx_rapi->update_framebuffer_parameters (0 , gfx_current_window_dimensions.width , gfx_current_window_dimensions.height , 1 , false , true , true , !game_renders_to_framebuffer);
27662791 gfx_rapi->start_frame ();
@@ -2792,6 +2817,7 @@ void gfx_run(Gfx *commands) {
27922817 // printf("Process %f %f\n", t1, t1 - t0);
27932818 gfx_rapi->end_frame ();
27942819 gfx_wapi->swap_buffers_begin ();
2820+ has_drawn_imgui_menu = false ;
27952821}
27962822
27972823void gfx_end_frame (void ) {
0 commit comments