[Project64] Clean up SystemEvents.cpp

This commit is contained in:
zilmar 2016-09-25 06:46:19 +10:00
parent 90560dd0da
commit 64a6cec068
2 changed files with 198 additions and 198 deletions

View File

@ -26,198 +26,198 @@ CSystemEvents::~CSystemEvents()
void CSystemEvents::QueueEvent(SystemEvent action) void CSystemEvents::QueueEvent(SystemEvent action)
{ {
CGuard Guard(m_CS); CGuard Guard(m_CS);
for (EventList::const_iterator iter = m_Events.begin(); iter != m_Events.end(); iter++) for (EventList::const_iterator iter = m_Events.begin(); iter != m_Events.end(); iter++)
{ {
if (*iter == action) if (*iter == action)
{ {
return; return;
} }
} }
m_Events.push_back(action); m_Events.push_back(action);
m_bDoSomething = true; m_bDoSomething = true;
} }
void CSystemEvents::ExecuteEvents() void CSystemEvents::ExecuteEvents()
{ {
EventList Events; EventList Events;
{ {
CGuard Guard(m_CS); CGuard Guard(m_CS);
m_bDoSomething = false; m_bDoSomething = false;
if (m_Events.size() == 0) if (m_Events.size() == 0)
{ {
return; return;
} }
Events = m_Events; Events = m_Events;
m_Events.clear(); m_Events.clear();
} }
bool bPause = false, bLoadedSave = false; bool bPause = false, bLoadedSave = false;
for (EventList::const_iterator iter = Events.begin(); !bLoadedSave && iter != Events.end(); iter++) for (EventList::const_iterator iter = Events.begin(); !bLoadedSave && iter != Events.end(); iter++)
{ {
switch (*iter) switch (*iter)
{ {
case SysEvent_CloseCPU: case SysEvent_CloseCPU:
m_System->m_EndEmulation = true; m_System->m_EndEmulation = true;
break; break;
case SysEvent_ResetCPU_Soft: case SysEvent_ResetCPU_Soft:
m_System->GameReset(); m_System->GameReset();
break; break;
case SysEvent_ResetCPU_SoftDone: case SysEvent_ResetCPU_SoftDone:
m_System->Reset(true, false); m_System->Reset(true, false);
break; break;
case SysEvent_ResetCPU_Hard: case SysEvent_ResetCPU_Hard:
m_System->Reset(true, true); m_System->Reset(true, true);
break; break;
case SysEvent_Profile_GenerateLogs: case SysEvent_Profile_GenerateLogs:
m_System->m_Profile.GenerateLog(); m_System->m_Profile.GenerateLog();
break; break;
case SysEvent_Profile_StartStop: case SysEvent_Profile_StartStop:
case SysEvent_Profile_ResetLogs: case SysEvent_Profile_ResetLogs:
m_System->m_Profile.ResetCounters(); m_System->m_Profile.ResetCounters();
break; break;
case SysEvent_ExecuteInterrupt: case SysEvent_ExecuteInterrupt:
g_Reg->DoIntrException(false); g_Reg->DoIntrException(false);
break; break;
case SysEvent_Interrupt_SP: case SysEvent_Interrupt_SP:
g_Reg->MI_INTR_REG |= MI_INTR_SP; g_Reg->MI_INTR_REG |= MI_INTR_SP;
g_Reg->DoIntrException(false); g_Reg->DoIntrException(false);
break; break;
case SysEvent_Interrupt_SI: case SysEvent_Interrupt_SI:
g_Reg->MI_INTR_REG |= MI_INTR_SI; g_Reg->MI_INTR_REG |= MI_INTR_SI;
g_Reg->DoIntrException(false); g_Reg->DoIntrException(false);
break; break;
case SysEvent_Interrupt_AI: case SysEvent_Interrupt_AI:
g_Reg->MI_INTR_REG |= MI_INTR_AI; g_Reg->MI_INTR_REG |= MI_INTR_AI;
g_Reg->DoIntrException(false); g_Reg->DoIntrException(false);
break; break;
case SysEvent_Interrupt_VI: case SysEvent_Interrupt_VI:
g_Reg->MI_INTR_REG |= MI_INTR_VI; g_Reg->MI_INTR_REG |= MI_INTR_VI;
g_Reg->DoIntrException(false); g_Reg->DoIntrException(false);
break; break;
case SysEvent_Interrupt_PI: case SysEvent_Interrupt_PI:
g_Reg->MI_INTR_REG |= MI_INTR_PI; g_Reg->MI_INTR_REG |= MI_INTR_PI;
g_Reg->DoIntrException(false); g_Reg->DoIntrException(false);
break; break;
case SysEvent_Interrupt_DP: case SysEvent_Interrupt_DP:
g_Reg->MI_INTR_REG |= MI_INTR_DP; g_Reg->MI_INTR_REG |= MI_INTR_DP;
g_Reg->DoIntrException(false); g_Reg->DoIntrException(false);
break; break;
case SysEvent_SaveMachineState: case SysEvent_SaveMachineState:
if (!m_System->SaveState()) if (!m_System->SaveState())
{ {
m_Events.push_back(SysEvent_SaveMachineState); m_Events.push_back(SysEvent_SaveMachineState);
m_bDoSomething = true; m_bDoSomething = true;
} }
break; break;
case SysEvent_LoadMachineState: case SysEvent_LoadMachineState:
if (m_System->LoadState()) if (m_System->LoadState())
{ {
bLoadedSave = true; bLoadedSave = true;
} }
break; break;
case SysEvent_ChangePlugins: case SysEvent_ChangePlugins:
ChangePluginFunc(); ChangePluginFunc();
break; break;
case SysEvent_ChangingFullScreen: case SysEvent_ChangingFullScreen:
g_Notify->ChangeFullScreen(); g_Notify->ChangeFullScreen();
break; break;
case SysEvent_GSButtonPressed: case SysEvent_GSButtonPressed:
if (m_System->HasCheatsSlectionChanged()) if (m_System->HasCheatsSlectionChanged())
{ {
m_System->SetCheatsSlectionChanged(false); m_System->SetCheatsSlectionChanged(false);
m_System->m_Cheats.LoadCheats(false, m_Plugins); m_System->m_Cheats.LoadCheats(false, m_Plugins);
} }
m_System->m_Cheats.ApplyGSButton(g_MMU); m_System->m_Cheats.ApplyGSButton(g_MMU);
break; break;
case SysEvent_PauseCPU_FromMenu: case SysEvent_PauseCPU_FromMenu:
if (!g_Settings->LoadBool(GameRunning_CPU_Paused)) if (!g_Settings->LoadBool(GameRunning_CPU_Paused))
{ {
g_Settings->SaveBool(GameRunning_CPU_Paused, true); g_Settings->SaveBool(GameRunning_CPU_Paused, true);
bPause = true; bPause = true;
} }
g_Settings->SaveDword(GameRunning_CPU_PausedType, PauseType_FromMenu); g_Settings->SaveDword(GameRunning_CPU_PausedType, PauseType_FromMenu);
break; break;
case SysEvent_PauseCPU_AppLostFocus: case SysEvent_PauseCPU_AppLostFocus:
if (!g_Settings->LoadBool(GameRunning_CPU_Paused)) if (!g_Settings->LoadBool(GameRunning_CPU_Paused))
{ {
g_Settings->SaveBool(GameRunning_CPU_Paused, true); g_Settings->SaveBool(GameRunning_CPU_Paused, true);
g_Settings->SaveDword(GameRunning_CPU_PausedType, PauseType_AppLostFocus); g_Settings->SaveDword(GameRunning_CPU_PausedType, PauseType_AppLostFocus);
bPause = true; bPause = true;
} }
break; break;
case SysEvent_PauseCPU_AppLostActive: case SysEvent_PauseCPU_AppLostActive:
if (!g_Settings->LoadBool(GameRunning_CPU_Paused)) if (!g_Settings->LoadBool(GameRunning_CPU_Paused))
{ {
g_Settings->SaveBool(GameRunning_CPU_Paused, true); g_Settings->SaveBool(GameRunning_CPU_Paused, true);
g_Settings->SaveDword(GameRunning_CPU_PausedType, PauseType_AppLostActive); g_Settings->SaveDword(GameRunning_CPU_PausedType, PauseType_AppLostActive);
bPause = true; bPause = true;
} }
break; break;
case SysEvent_PauseCPU_SaveGame: case SysEvent_PauseCPU_SaveGame:
if (!g_Settings->LoadBool(GameRunning_CPU_Paused)) if (!g_Settings->LoadBool(GameRunning_CPU_Paused))
{ {
g_Settings->SaveBool(GameRunning_CPU_Paused, true); g_Settings->SaveBool(GameRunning_CPU_Paused, true);
g_Settings->SaveDword(GameRunning_CPU_PausedType, PauseType_SaveGame); g_Settings->SaveDword(GameRunning_CPU_PausedType, PauseType_SaveGame);
bPause = true; bPause = true;
} }
break; break;
case SysEvent_PauseCPU_LoadGame: case SysEvent_PauseCPU_LoadGame:
if (!g_Settings->LoadBool(GameRunning_CPU_Paused)) if (!g_Settings->LoadBool(GameRunning_CPU_Paused))
{ {
g_Settings->SaveBool(GameRunning_CPU_Paused, true); g_Settings->SaveBool(GameRunning_CPU_Paused, true);
g_Settings->SaveDword(GameRunning_CPU_PausedType, PauseType_LoadGame); g_Settings->SaveDword(GameRunning_CPU_PausedType, PauseType_LoadGame);
bPause = true; bPause = true;
} }
break; break;
case SysEvent_PauseCPU_DumpMemory: case SysEvent_PauseCPU_DumpMemory:
if (!g_Settings->LoadBool(GameRunning_CPU_Paused)) if (!g_Settings->LoadBool(GameRunning_CPU_Paused))
{ {
g_Settings->SaveBool(GameRunning_CPU_Paused, true); g_Settings->SaveBool(GameRunning_CPU_Paused, true);
g_Settings->SaveDword(GameRunning_CPU_PausedType, PauseType_DumpMemory); g_Settings->SaveDword(GameRunning_CPU_PausedType, PauseType_DumpMemory);
bPause = true; bPause = true;
} }
break; break;
case SysEvent_PauseCPU_SearchMemory: case SysEvent_PauseCPU_SearchMemory:
if (!g_Settings->LoadBool(GameRunning_CPU_Paused)) if (!g_Settings->LoadBool(GameRunning_CPU_Paused))
{ {
g_Settings->SaveBool(GameRunning_CPU_Paused, true); g_Settings->SaveBool(GameRunning_CPU_Paused, true);
g_Settings->SaveDword(GameRunning_CPU_PausedType, PauseType_SearchMemory); g_Settings->SaveDword(GameRunning_CPU_PausedType, PauseType_SearchMemory);
bPause = true; bPause = true;
} }
break; break;
case SysEvent_PauseCPU_Settings: case SysEvent_PauseCPU_Settings:
if (!g_Settings->LoadBool(GameRunning_CPU_Paused)) if (!g_Settings->LoadBool(GameRunning_CPU_Paused))
{ {
g_Settings->SaveBool(GameRunning_CPU_Paused, true); g_Settings->SaveBool(GameRunning_CPU_Paused, true);
g_Settings->SaveDword(GameRunning_CPU_PausedType, PauseType_Settings); g_Settings->SaveDword(GameRunning_CPU_PausedType, PauseType_Settings);
bPause = true; bPause = true;
} }
break; break;
case SysEvent_PauseCPU_Cheats: case SysEvent_PauseCPU_Cheats:
if (!g_Settings->LoadBool(GameRunning_CPU_Paused)) if (!g_Settings->LoadBool(GameRunning_CPU_Paused))
{ {
g_Settings->SaveBool(GameRunning_CPU_Paused, true); g_Settings->SaveBool(GameRunning_CPU_Paused, true);
g_Settings->SaveDword(GameRunning_CPU_PausedType, PauseType_Cheats); g_Settings->SaveDword(GameRunning_CPU_PausedType, PauseType_Cheats);
bPause = true; bPause = true;
} }
break; break;
default: default:
g_Notify->BreakPoint(__FILE__, __LINE__); g_Notify->BreakPoint(__FILE__, __LINE__);
break; break;
} }
} }
if (bPause) if (bPause)
{ {
m_System->Pause(); m_System->Pause();
} }
} }
void CSystemEvents::ChangePluginFunc() void CSystemEvents::ChangePluginFunc()
{ {
g_Notify->DisplayMessage(0, MSG_PLUGIN_INIT); g_Notify->DisplayMessage(0, MSG_PLUGIN_INIT);
m_System->PluginReset(); m_System->PluginReset();
} }

View File

@ -59,31 +59,31 @@ class CPlugins;
class CSystemEvents class CSystemEvents
{ {
typedef std::vector<SystemEvent> EventList; typedef std::vector<SystemEvent> EventList;
protected: protected:
CSystemEvents(CN64System * System, CPlugins * Plugins); CSystemEvents(CN64System * System, CPlugins * Plugins);
virtual ~CSystemEvents(); virtual ~CSystemEvents();
public: public:
void ExecuteEvents(); void ExecuteEvents();
void QueueEvent(SystemEvent action); void QueueEvent(SystemEvent action);
const int32_t & DoSomething() const const int32_t & DoSomething() const
{ {
return m_bDoSomething; return m_bDoSomething;
} }
private: private:
CSystemEvents(); // Disable default constructor CSystemEvents(); // Disable default constructor
CSystemEvents(const CSystemEvents&); // Disable copy constructor CSystemEvents(const CSystemEvents&); // Disable copy constructor
CSystemEvents& operator=(const CSystemEvents&); // Disable assignment CSystemEvents& operator=(const CSystemEvents&); // Disable assignment
void ChangePluginFunc(); void ChangePluginFunc();
CN64System * m_System; CN64System * m_System;
CPlugins * m_Plugins; CPlugins * m_Plugins;
EventList m_Events; EventList m_Events;
int32_t m_bDoSomething; int32_t m_bDoSomething;
CriticalSection m_CS; CriticalSection m_CS;
}; };