diff --git a/cpp_src/GuiHelpers.cpp b/cpp_src/GuiHelpers.cpp index d063f80..ef05783 100644 --- a/cpp_src/GuiHelpers.cpp +++ b/cpp_src/GuiHelpers.cpp @@ -13,6 +13,38 @@ void SetStatusBarText(const char* text) sb.SetWindowText(text); } +static int lastTick; + +BOOL RefreshScreen(int frameskip) +{ + // Bail out of this function if it couldn't be performed + if (!g_hwnd || !g_viewhwnd || g_closeApplication) + return 0; + + // Frameskip of 1 or higher + if (frameskip > 0) + { + // Frame was already processed + if (lastTick == g_timerGlobalCount) + return 0; + + // Skip frame with modulo + if ((g_timerGlobalCount % frameskip)) + return 0; + + // Remember the last time a frame was processed + lastTick = g_timerGlobalCount; + } + + // Force a screen update if the condition is met for it + AfxGetApp()->GetMainWnd()->Invalidate(); + SCREENUPDATE; + UpdateWindow(g_viewhwnd); + + // Screen was refreshed + return 1; +} + int EditText(int vk, int shift, int control, char* txt, int& cur, int max) { //returns 1 if TAB or ENTER was pressed diff --git a/cpp_src/GuiHelpers.h b/cpp_src/GuiHelpers.h index c04c53d..449585a 100644 --- a/cpp_src/GuiHelpers.h +++ b/cpp_src/GuiHelpers.h @@ -10,6 +10,8 @@ extern void SetStatusBarText(const char* text); +extern BOOL RefreshScreen(int frameskip = 0); + extern int EditText(int vk, int shift, int control, char* txt, int& cur, int max); extern BOOL IsHoveredXY(int x, int y, int xLength, int yLength); diff --git a/cpp_src/IO_Song_ExportSaprLzss.cpp b/cpp_src/IO_Song_ExportSaprLzss.cpp index f3a567c..0215d97 100644 --- a/cpp_src/IO_Song_ExportSaprLzss.cpp +++ b/cpp_src/IO_Song_ExportSaprLzss.cpp @@ -728,7 +728,9 @@ bool CSong::ExportLZSS_XEX(std::ofstream& ou) /// void CSong::DumpSongToPokeyBuffer(int playmode, int songline, int trackline) { - Stop(); + CString statusBarLog; + + Stop(); // Make sure RMT is stopped Atari_InitRMTRoutine(); // Reset the RMT routines SetChannelOnOff(-1, 0); // Switch all channels off @@ -741,12 +743,7 @@ void CSong::DumpSongToPokeyBuffer(int playmode, int songline, int trackline) Play(playmode, m_followplay); // Wait in a tight loop pumping messages until the playback stops - MSG msg; - CString statusBarLog; - CWnd* wnd = AfxGetApp()->GetMainWnd(); - - wnd->EnableWindow(FALSE); - wnd->BeginWaitCursor(); + EnableWindow(g_hwnd, FALSE); // The SAP-R dumper is running during that time... while (m_play != MPLAY_STOP) @@ -770,21 +767,12 @@ void CSong::DumpSongToPokeyBuffer(int playmode, int songline, int trackline) // Update the screen only once every few frames // Displaying everything in real time slows things down considerably! - if (g_timerGlobalCount % 8 != 0) + if (!RefreshScreen(1)) continue; - SCREENUPDATE; - // Display the number of frames dumped so far statusBarLog.Format("Generating Pokey stream, playing song in quick mode... %i frames recorded", g_PokeyStream.GetCurrentFrame()); SetStatusBarText(statusBarLog); - - // Send pending messages to update the screen - if (::PeekMessage(&msg, wnd->m_hWnd, 0, 0, PM_REMOVE)) - { - ::TranslateMessage(&msg); - ::DispatchMessage(&msg); - } } // End playback now, the SAP-R data should have been dumped successfully! @@ -793,26 +781,21 @@ void CSong::DumpSongToPokeyBuffer(int playmode, int songline, int trackline) statusBarLog.Format("Done... %i frames recorded in total, Loop point found at frame %i", g_PokeyStream.GetCurrentFrame(), g_PokeyStream.GetFirstCountPoint()); SetStatusBarText(statusBarLog); - wnd->EndWaitCursor(); - wnd->EnableWindow(); // Turn on the window again + EnableWindow(g_hwnd, TRUE); } // A dumb SAP-R LZSS optimisations bruteforcer, returns the optimal value and buffer int CSong::BruteforceOptimalLZSS(unsigned char* src, int srclen, unsigned char* dst) { - MSG msg; CString statusBarLog; - CWnd* wnd = AfxGetApp()->GetMainWnd(); - - wnd->EnableWindow(FALSE); - wnd->BeginWaitCursor(); - CCompressLzss lzssData; // Start from a high value to force the first pattern to be the best one int bestScore = 0xFFFFFF; int optimal = 0; + EnableWindow(g_hwnd, FALSE); + for (int i = 0; i < SAPR_OPTIMISATIONS_COUNT; i++) { int bruteforced = lzssData.LZSS_SAP(src, srclen, dst, i); @@ -823,23 +806,18 @@ int CSong::BruteforceOptimalLZSS(unsigned char* src, int srclen, unsigned char* optimal = i; } + // Always refresh the screen after each iteration + RefreshScreen(); + statusBarLog.Format("Compressing %i bytes, bruteforcing optimisation pattern %i... Current best: %i bytes with optimisation pattern %i", srclen, i, bestScore, optimal); SetStatusBarText(statusBarLog); - - // Send pending messages to update the screen - if (::PeekMessage(&msg, wnd->m_hWnd, 0, 0, PM_REMOVE)) - { - ::TranslateMessage(&msg); - ::DispatchMessage(&msg); - } } // Bruteforcing was completed, display some stats statusBarLog.Format("Done... %i bytes were shrunk to %i bytes using the optimisation pattern %i", srclen, bestScore, optimal); SetStatusBarText(statusBarLog); - wnd->EndWaitCursor(); - wnd->EnableWindow(); // Turn on the window again + EnableWindow(g_hwnd, TRUE); return lzssData.LZSS_SAP(src, srclen, dst, optimal); } diff --git a/cpp_src/RmtView.cpp b/cpp_src/RmtView.cpp index 67cb0a2..8ec0f72 100644 --- a/cpp_src/RmtView.cpp +++ b/cpp_src/RmtView.cpp @@ -276,12 +276,7 @@ void CRmtView::OnTimer(UINT_PTR nIDEvent) { KillTimer(m_timerDisplay); m_timerDisplay = SetTimer(1, m_timerDisplayTick[g_timerGlobalCount % 3], NULL); - - if (g_hwnd && !g_closeApplication) - { - AfxGetApp()->GetMainWnd()->Invalidate(); - SCREENUPDATE; - } + RefreshScreen(); } CView::OnTimer(nIDEvent);