Merge pull request #2152 from lioncash/timer
DolphinWX: Clean up some wxTimer code
This commit is contained in:
commit
081adc92c0
|
@ -508,15 +508,13 @@ CFrame::CFrame(wxFrame* parent,
|
|||
// check if game is running
|
||||
m_bHotkeysInit = InitControllers();
|
||||
|
||||
m_poll_hotkey_timer = new wxTimer(this);
|
||||
m_poll_hotkey_timer.SetOwner(this);
|
||||
Bind(wxEVT_TIMER, &CFrame::PollHotkeys, this);
|
||||
m_poll_hotkey_timer->Start(1000 / 60, wxTIMER_CONTINUOUS);
|
||||
m_poll_hotkey_timer.Start(1000 / 60, wxTIMER_CONTINUOUS);
|
||||
}
|
||||
// Destructor
|
||||
CFrame::~CFrame()
|
||||
{
|
||||
m_poll_hotkey_timer->Stop();
|
||||
|
||||
if (m_bHotkeysInit)
|
||||
{
|
||||
Wiimote::Shutdown();
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include <wx/mstream.h>
|
||||
#include <wx/panel.h>
|
||||
#include <wx/string.h>
|
||||
#include <wx/timer.h>
|
||||
#include <wx/toplevel.h>
|
||||
#include <wx/windowid.h>
|
||||
|
||||
|
@ -47,8 +48,6 @@ class wxAuiNotebook;
|
|||
class wxAuiNotebookEvent;
|
||||
class wxListEvent;
|
||||
class wxMenuItem;
|
||||
class wxTimer;
|
||||
class wxTimerEvent;
|
||||
class wxWindow;
|
||||
|
||||
class CRenderFrame : public wxFrame
|
||||
|
@ -198,7 +197,7 @@ private:
|
|||
EToolbar_Max
|
||||
};
|
||||
|
||||
wxTimer* m_poll_hotkey_timer;
|
||||
wxTimer m_poll_hotkey_timer;
|
||||
|
||||
wxBitmap m_Bitmaps[EToolbar_Max];
|
||||
wxBitmap m_BitmapsMenu[EToolbar_Max];
|
||||
|
|
|
@ -45,7 +45,7 @@ CLogWindow::CLogWindow(CFrame *parent, wxWindowID id, const wxPoint& pos,
|
|||
const wxSize& size, long style, const wxString& name)
|
||||
: wxPanel(parent, id, pos, size, style, name)
|
||||
, x(0), y(0), winpos(0)
|
||||
, Parent(parent), m_ignoreLogTimer(false), m_LogAccess(true)
|
||||
, Parent(parent), m_LogAccess(true)
|
||||
, m_Log(nullptr), m_cmdline(nullptr), m_FontChoice(nullptr)
|
||||
{
|
||||
Bind(wxEVT_CLOSE_WINDOW, &CLogWindow::OnClose, this);
|
||||
|
@ -55,8 +55,8 @@ CLogWindow::CLogWindow(CFrame *parent, wxWindowID id, const wxPoint& pos,
|
|||
|
||||
CreateGUIControls();
|
||||
|
||||
m_LogTimer = new wxTimer(this);
|
||||
m_LogTimer->Start(UPDATETIME);
|
||||
m_LogTimer.SetOwner(this);
|
||||
m_LogTimer.Start(UPDATETIME);
|
||||
}
|
||||
|
||||
void CLogWindow::CreateGUIControls()
|
||||
|
@ -177,8 +177,6 @@ CLogWindow::~CLogWindow()
|
|||
{
|
||||
m_LogManager->RemoveListener((LogTypes::LOG_TYPE)i, this);
|
||||
}
|
||||
m_LogTimer->Stop();
|
||||
delete m_LogTimer;
|
||||
}
|
||||
|
||||
void CLogWindow::OnClose(wxCloseEvent& event)
|
||||
|
@ -287,7 +285,7 @@ void CLogWindow::OnWrapLineCheck(wxCommandEvent& event)
|
|||
|
||||
void CLogWindow::OnLogTimer(wxTimerEvent& WXUNUSED(event))
|
||||
{
|
||||
if (!m_LogAccess || m_ignoreLogTimer)
|
||||
if (!m_LogAccess)
|
||||
return;
|
||||
|
||||
UpdateLog();
|
||||
|
@ -302,13 +300,10 @@ void CLogWindow::OnLogTimer(wxTimerEvent& WXUNUSED(event))
|
|||
|
||||
void CLogWindow::UpdateLog()
|
||||
{
|
||||
if (!m_LogAccess || !m_Log)
|
||||
if (!m_LogAccess || !m_Log || msgQueue.empty())
|
||||
return;
|
||||
|
||||
// m_LogTimer->Stop();
|
||||
// instead of stopping the timer, let's simply ignore its calls during UpdateLog,
|
||||
// because repeatedly stopping and starting a timer churns memory (and potentially leaks it).
|
||||
m_ignoreLogTimer = true;
|
||||
m_LogTimer.Stop();
|
||||
|
||||
std::lock_guard<std::mutex> lk(m_LogSection);
|
||||
while (!msgQueue.empty())
|
||||
|
@ -351,7 +346,7 @@ void CLogWindow::UpdateLog()
|
|||
msgQueue.pop();
|
||||
}
|
||||
|
||||
m_ignoreLogTimer = false;
|
||||
m_LogTimer.Start();
|
||||
}
|
||||
|
||||
void CLogWindow::Log(LogTypes::LOG_LEVELS level, const char *text)
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include <wx/gdicmn.h>
|
||||
#include <wx/panel.h>
|
||||
#include <wx/string.h>
|
||||
#include <wx/timer.h>
|
||||
#include <wx/translation.h>
|
||||
#include <wx/windowid.h>
|
||||
|
||||
|
@ -25,8 +26,6 @@ class wxBoxSizer;
|
|||
class wxCheckBox;
|
||||
class wxChoice;
|
||||
class wxTextCtrl;
|
||||
class wxTimer;
|
||||
class wxTimerEvent;
|
||||
|
||||
// Uses multiple inheritance - only sane because LogListener is a pure virtual interface.
|
||||
class CLogWindow : public wxPanel, LogListener
|
||||
|
@ -50,8 +49,7 @@ private:
|
|||
CFrame* Parent;
|
||||
wxFont DefaultFont, MonoSpaceFont;
|
||||
std::vector<wxFont> LogFont;
|
||||
wxTimer* m_LogTimer;
|
||||
bool m_ignoreLogTimer;
|
||||
wxTimer m_LogTimer;
|
||||
LogManager* m_LogManager;
|
||||
std::queue<std::pair<u8, wxString> > msgQueue;
|
||||
bool m_writeFile, m_writeWindow, m_writeDebugger, m_LogAccess;
|
||||
|
|
Loading…
Reference in New Issue