[WIP-THREAD] Encapsulate log calls for queueing.

Reasonable, but it could be a lot better.
This commit is contained in:
Edênis Freindorfer Azevedo 2020-07-09 19:04:36 -03:00
parent ccd9847672
commit 06313d9df1
No known key found for this signature in database
GPG Key ID: 968FB6EC280C7222
3 changed files with 27 additions and 3 deletions

View File

@ -59,6 +59,7 @@ GameArea::GameArea()
Bind(WX_THREAD_REQUEST_DRAWFRAME, &GameArea::RequestDrawFrame, this);
Bind(WX_THREAD_REQUEST_UPDATESTATUSBAR, &GameArea::RequestUpdateStatusBar, this);
Bind(WX_THREAD_REQUEST_GBPRINTER, &GameArea::ShowPrinter, this);
Bind(WX_THREAD_REQUEST_UPDATELOG, &GameArea::RequestUpdateLog, this);
#endif
}
@ -1211,7 +1212,6 @@ void GameArea::RequestDrawFrame(wxThreadEvent& WXUNUSED(event))
void GameArea::RequestUpdateStatusBar(wxThreadEvent& event)
{
//wxCriticalSectionLocker lock(MainFrame::emulationCS);
MainFrame* f = wxGetApp().frame;
int speed = event.GetPayload<int>();
int frames = event.GetExtraLong(); // should probably use payload too
@ -1234,6 +1234,24 @@ void GameArea::RequestUpdateStatusBar(wxThreadEvent& event)
wxGetApp().frame->SetStatusText(s, 1);
}
void GameArea::UpdateLog()
{
wxQueueEvent(this, new wxThreadEvent(WX_THREAD_REQUEST_UPDATELOG));
}
void GameArea::RequestUpdateLog(wxThreadEvent& WXUNUSED(event))
{
#ifndef NO_THREAD_MAINLOOP
wxCriticalSectionLocker lock(MainFrame::emulationCS);
#endif
LogDialog* d = wxGetApp().frame->logdlg;
if (d && d->IsShown()) {
d->Update();
}
}
#endif // NO_THREAD_MAINLOOP
void GameArea::DestroyDrawingPanel()

View File

@ -1287,12 +1287,15 @@ void log(const char* defaultMsg, ...)
wxGetApp().log.append(msg);
if (wxGetApp().IsMainLoopRunning()) {
#ifndef NO_THREAD_MAINLOOP
wxGetApp().frame->GetPanel()->UpdateLog();
#else
LogDialog* d = wxGetApp().frame->logdlg;
if (d && d->IsShown()) {
d->Update();
}
systemScreenMessage(msg);
#endif
//systemScreenMessage(msg);
}
}

View File

@ -511,6 +511,7 @@ wxDEFINE_EVENT(WX_THREAD_REQUEST_UPDATEDRAWPANEL, wxThreadEvent);
wxDEFINE_EVENT(WX_THREAD_REQUEST_DRAWFRAME, wxThreadEvent);
wxDEFINE_EVENT(WX_THREAD_REQUEST_UPDATESTATUSBAR, wxThreadEvent);
wxDEFINE_EVENT(WX_THREAD_REQUEST_GBPRINTER, wxThreadEvent);
wxDEFINE_EVENT(WX_THREAD_REQUEST_UPDATELOG, wxThreadEvent);
#endif // NO_THREAD_MAINLOOP
class GameArea : public wxPanel, public HiDPIAware
@ -533,6 +534,8 @@ public:
void RequestStatusBar(int speed, int frames);
void RequestGBPrinter(uint16_t*, uint16_t**, int, int, int*, int*);
void ShowPrinter(wxThreadEvent&);
void RequestUpdateLog(wxThreadEvent&);
void UpdateLog();
#endif
void DestroyDrawingPanel();