@@ -111,11 +111,6 @@ using namespace std::placeholders;
111111static AVIDump avi;
112112#endif
113113
114- // TODO: Ugly!
115- static bool frameStep_;
116- static int lastNumFlips;
117- static bool startDumping;
118-
119114extern bool g_TakeScreenshot;
120115
121116static void AssertCancelCallback (const char *message, void *userdata) {
@@ -127,35 +122,6 @@ static void AssertCancelCallback(const char *message, void *userdata) {
127122 emuScreen->SendImDebuggerCommand (ImCommand{ ImCmd::SHOW_IN_CPU_DISASM, currentMIPS->pc });
128123}
129124
130- static void __EmuScreenVblank ()
131- {
132- auto sy = GetI18NCategory (I18NCat::SYSTEM);
133-
134- if (frameStep_ && lastNumFlips != gpuStats.numFlips ) {
135- frameStep_ = false ;
136- Core_Break (BreakReason::FrameAdvance, 0 );
137- lastNumFlips = gpuStats.numFlips ;
138- }
139- #ifndef MOBILE_DEVICE
140- if (g_Config.bDumpFrames && !startDumping)
141- {
142- avi.Start (PSP_CoreParameter ().renderWidth , PSP_CoreParameter ().renderHeight );
143- g_OSD.Show (OSDType::MESSAGE_INFO, sy->T (" AVI Dump started." ), 1 .0f );
144- startDumping = true ;
145- }
146- if (g_Config.bDumpFrames && startDumping)
147- {
148- avi.AddFrame ();
149- }
150- else if (!g_Config.bDumpFrames && startDumping)
151- {
152- avi.Stop ();
153- g_OSD.Show (OSDType::MESSAGE_INFO, sy->T (" AVI Dump stopped." ), 1 .0f );
154- startDumping = false ;
155- }
156- #endif
157- }
158-
159125// Handles control rotation due to internal screen rotation.
160126static void SetPSPAnalog (int stick, float x, float y) {
161127 switch (g_Config.iInternalScreenRotation ) {
@@ -189,10 +155,6 @@ static void SetPSPAnalog(int stick, float x, float y) {
189155EmuScreen::EmuScreen (const Path &filename)
190156 : gamePath_(filename) {
191157 saveStateSlot_ = SaveState::GetCurrentSlot ();
192- __DisplayListenVblank (__EmuScreenVblank);
193- frameStep_ = false ;
194- lastNumFlips = gpuStats.numFlips ;
195- startDumping = false ;
196158 controlMapper_.SetCallbacks (
197159 std::bind (&EmuScreen::onVKey, this , _1, _2),
198160 std::bind (&EmuScreen::onVKeyAnalog, this , _1, _2),
@@ -366,6 +328,8 @@ void EmuScreen::ProcessGameBoot(const Path &filename) {
366328
367329// Only call this on successful boot.
368330void EmuScreen::bootComplete () {
331+ __DisplayListenVblank ([this ]() {HandleVBlank (); });
332+
369333 // Initialize retroachievements, now that we're on the right thread.
370334 if (g_Config.bAchievementsEnable ) {
371335 std::string errorString;
@@ -440,8 +404,10 @@ void EmuScreen::bootComplete() {
440404
441405 saveStateSlot_ = SaveState::GetCurrentSlot ();
442406
443- loadingViewColor_->Divert (0x00FFFFFF , 0 .2f );
444- loadingViewVisible_->Divert (UI::V_INVISIBLE, 0 .2f );
407+ if (loadingViewColor_)
408+ loadingViewColor_->Divert (0x00FFFFFF , 0 .2f );
409+ if (loadingViewVisible_)
410+ loadingViewVisible_->Divert (UI::V_INVISIBLE, 0 .2f );
445411
446412 std::string gameID = g_paramSFO.GetValueString (" DISC_ID" );
447413 g_Config.TimeTracker ().Start (gameID);
@@ -475,11 +441,11 @@ EmuScreen::~EmuScreen() {
475441 g_logManager.EnableOutput (LogOutput::RingBuffer);
476442
477443#ifndef MOBILE_DEVICE
478- if (g_Config.bDumpFrames && startDumping )
444+ if (g_Config.bDumpFrames && startDumping_ )
479445 {
480446 avi.Stop ();
481447 g_OSD.Show (OSDType::MESSAGE_INFO, " AVI Dump stopped." , 2 .0f );
482- startDumping = false ;
448+ startDumping_ = false ;
483449 }
484450#endif
485451
@@ -801,14 +767,6 @@ void EmuScreen::onVKey(VirtKey virtualKeyCode, bool down) {
801767 }
802768 break ;
803769
804- case VIRTKEY_FRAME_ADVANCE:
805- // Can't do this reliably in an async fashion, so we just set a variable.
806- // Is this used by anyone? There's no good way to resume, other than PAUSE_NO_MENU or the debugger.
807- if (down && !NetworkWarnUserIfOnlineAndCantSpeed ()) {
808- doFrameAdvance_.store (true );
809- }
810- break ;
811-
812770 case VIRTKEY_RESET_EMULATION:
813771 if (down) {
814772 System_PostUIMessage (UIMessage::REQUEST_GAME_RESET);
@@ -1007,6 +965,19 @@ void EmuScreen::ProcessVKey(VirtKey virtKey) {
1007965 break ;
1008966 }
1009967
968+ case VIRTKEY_FRAME_ADVANCE:
969+ // Can't do this reliably in an async fashion, so we just set a variable.
970+ // Is this used by anyone? There's no user-friendly way to resume, other than PAUSE_NO_MENU or the debugger.
971+ if (!NetworkWarnUserIfOnlineAndCantSpeed ()) {
972+ if (Core_IsStepping ()) {
973+ Core_Resume ();
974+ frameStep_ = true ;
975+ } else {
976+ Core_Break (BreakReason::FrameAdvance);
977+ }
978+ }
979+ break ;
980+
1010981 default :
1011982 break ;
1012983 }
@@ -1217,7 +1188,14 @@ void EmuScreen::CreateViews() {
12171188 root_->Add (buttons);
12181189
12191190 resumeButton_ = buttons->Add (new Button (dev->T (" Resume" )));
1220- resumeButton_->OnClick .Handle (this , &EmuScreen::OnResume);
1191+ resumeButton_->OnClick .Add ([this ](UI::EventParams &) {
1192+ if (coreState == CoreState::CORE_RUNTIME_ERROR) {
1193+ // Force it!
1194+ Memory::MemFault_IgnoreLastCrash ();
1195+ coreState = CoreState::CORE_RUNNING_CPU;
1196+ }
1197+ return UI::EVENT_DONE;
1198+ });
12211199 resumeButton_->SetVisibility (V_GONE);
12221200
12231201 resetButton_ = buttons->Add (new Button (dev->T (" Reset" )));
@@ -1237,7 +1215,10 @@ void EmuScreen::CreateViews() {
12371215 backButton_->SetVisibility (V_GONE);
12381216
12391217 cardboardDisableButton_ = root_->Add (new Button (sc->T (" Cardboard VR OFF" ), new AnchorLayoutParams (bounds.centerX (), NONE, NONE, 30 , true )));
1240- cardboardDisableButton_->OnClick .Handle (this , &EmuScreen::OnDisableCardboard);
1218+ cardboardDisableButton_->OnClick .Add ([](UI::EventParams &) {
1219+ g_Config.bEnableCardboardVR = false ;
1220+ return UI::EVENT_DONE;
1221+ });
12411222 cardboardDisableButton_->SetVisibility (V_GONE);
12421223 cardboardDisableButton_->SetScale (0 .65f ); // make it smaller - this button can be in the way otherwise.
12431224
@@ -1331,11 +1312,6 @@ UI::EventReturn EmuScreen::OnDevTools(UI::EventParams ¶ms) {
13311312 return UI::EVENT_DONE;
13321313}
13331314
1334- UI::EventReturn EmuScreen::OnDisableCardboard (UI::EventParams ¶ms) {
1335- g_Config.bEnableCardboardVR = false ;
1336- return UI::EVENT_DONE;
1337- }
1338-
13391315UI::EventReturn EmuScreen::OnChat (UI::EventParams ¶ms) {
13401316 if (chatButton_ != nullptr && chatButton_->GetVisibility () == UI::V_VISIBLE) {
13411317 chatButton_->SetVisibility (UI::V_GONE);
@@ -1357,15 +1333,6 @@ UI::EventReturn EmuScreen::OnChat(UI::EventParams ¶ms) {
13571333 return UI::EVENT_DONE;
13581334}
13591335
1360- UI::EventReturn EmuScreen::OnResume (UI::EventParams ¶ms) {
1361- if (coreState == CoreState::CORE_RUNTIME_ERROR) {
1362- // Force it!
1363- Memory::MemFault_IgnoreLastCrash ();
1364- coreState = CoreState::CORE_RUNNING_CPU;
1365- }
1366- return UI::EVENT_DONE;
1367- }
1368-
13691336// To avoid including proAdhoc.h, which includes a lot of stuff.
13701337int GetChatMessageCount ();
13711338
@@ -1512,6 +1479,26 @@ void EmuScreen::darken() {
15121479 }
15131480}
15141481
1482+ // TODO: We probably shouldn't even handle frame dumping at vblank, we can just as well handle it directly in EmuScreen.
1483+ void EmuScreen::HandleVBlank () {
1484+ #ifndef MOBILE_DEVICE
1485+ if (g_Config.bDumpFrames && !startDumping_) {
1486+ auto sy = GetI18NCategory (I18NCat::SYSTEM);
1487+ avi.Start (PSP_CoreParameter ().renderWidth , PSP_CoreParameter ().renderHeight );
1488+ g_OSD.Show (OSDType::MESSAGE_INFO, sy->T (" AVI Dump started." ), 1 .0f );
1489+ startDumping_ = true ;
1490+ }
1491+ if (g_Config.bDumpFrames && startDumping_) {
1492+ avi.AddFrame ();
1493+ } else if (!g_Config.bDumpFrames && startDumping_) {
1494+ auto sy = GetI18NCategory (I18NCat::SYSTEM);
1495+ avi.Stop ();
1496+ g_OSD.Show (OSDType::MESSAGE_INFO, sy->T (" AVI Dump stopped." ), 1 .0f );
1497+ startDumping_ = false ;
1498+ }
1499+ #endif
1500+ }
1501+
15151502ScreenRenderFlags EmuScreen::render (ScreenRenderMode mode) {
15161503 // Moved from update, because we want it to be possible for booting to happen even when the screen
15171504 // is in the background, like when choosing Reset from the pause menu.
@@ -1532,7 +1519,7 @@ ScreenRenderFlags EmuScreen::render(ScreenRenderMode mode) {
15321519
15331520 ProcessQueuedVKeys ();
15341521
1535- bool skipBufferEffects = g_Config.bSkipBufferEffects ;
1522+ const bool skipBufferEffects = g_Config.bSkipBufferEffects ;
15361523
15371524 bool framebufferBound = false ;
15381525
@@ -1631,19 +1618,6 @@ ScreenRenderFlags EmuScreen::render(ScreenRenderMode mode) {
16311618
16321619 PSP_UpdateDebugStats ((DebugOverlay)g_Config.iDebugOverlay == DebugOverlay::DEBUG_STATS || g_Config.bLogFrameDrops );
16331620
1634- if (doFrameAdvance_.exchange (false )) {
1635- if (!Achievements::WarnUserIfHardcoreModeActive (false )) {
1636- // If game is running, pause emulation immediately. Otherwise, advance a single frame.
1637- if (Core_IsStepping ()) {
1638- frameStep_ = true ;
1639- Core_Resume ();
1640- } else if (!frameStep_) {
1641- lastNumFlips = gpuStats.numFlips ;
1642- Core_Break (BreakReason::FrameAdvance, 0 );
1643- }
1644- }
1645- }
1646-
16471621 // Running it early allows things like direct readbacks of buffers, things we can't do
16481622 // when we have started the final render pass. Well, technically we probably could with some manipulation
16491623 // of pass order in the render managers..
@@ -1665,7 +1639,7 @@ ScreenRenderFlags EmuScreen::render(ScreenRenderMode mode) {
16651639 switch (coreState) {
16661640 case CORE_NEXTFRAME:
16671641 // Reached the end of the frame while running at full blast, all good. Set back to running for the next frame
1668- coreState = CORE_RUNNING_CPU;
1642+ coreState = frameStep_ ? CORE_STEPPING_CPU : CORE_RUNNING_CPU;
16691643 flags |= ScreenRenderFlags::HANDLED_THROTTLING;
16701644 Achievements::FrameUpdate ();
16711645 break ;
@@ -1708,6 +1682,13 @@ ScreenRenderFlags EmuScreen::render(ScreenRenderMode mode) {
17081682 PSP_EndHostFrame ();
17091683 }
17101684
1685+ if (frameStep_) {
1686+ frameStep_ = false ;
1687+ if (coreState == CORE_RUNNING_CPU) {
1688+ Core_Break (BreakReason::FrameAdvance, 0 );
1689+ }
1690+ }
1691+
17111692 if (gpu && gpu->PresentedThisFrame ()) {
17121693 framebufferBound = true ;
17131694 }
0 commit comments