More code for event handling

almost working, for some reason the event handler creates 2 instances instead of one
if anyone can see why from the code I'll be like SOOOO happy:P



git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@1798 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
nakeee
2009-01-05 22:51:35 +00:00
parent bfe43d0c61
commit 790ee70b36
7 changed files with 255 additions and 105 deletions

View File

@ -60,7 +60,6 @@
#include "MemTools.h"
#include "Host.h"
#include "LogManager.h"
#include "InputCommon.h"
#include "State.h"
@ -135,8 +134,6 @@ bool Init(const SCoreStartupParameter _CoreParameter)
g_CoreStartupParameter = _CoreParameter;
InputCommon::Init();
// start the thread again
_dbg_assert_(HLE, g_pThread == NULL);
@ -238,44 +235,44 @@ void* GetWindowHandle()
THREAD_RETURN CpuThread(void *pArg)
{
Common::SetCurrentThreadName("CPU thread");
const SCoreStartupParameter& _CoreParameter = g_CoreStartupParameter;
const SCoreStartupParameter& _CoreParameter = g_CoreStartupParameter;
if (!g_CoreStartupParameter.bUseDualCore)
{
PluginVideo::Video_Prepare(); //wglMakeCurrent
}
if (_CoreParameter.bRunCompareServer)
{
CPUCompare::StartServer();
PowerPC::state = PowerPC::CPU_RUNNING;
PluginVideo::Video_Prepare(); //wglMakeCurrent
}
else if (_CoreParameter.bRunCompareClient)
if (_CoreParameter.bRunCompareServer)
{
PanicAlert("Compare Debug : Press OK when ready.");
CPUCompare::ConnectAsClient();
CPUCompare::StartServer();
PowerPC::state = PowerPC::CPU_RUNNING;
}
if (_CoreParameter.bLockThreads)
Common::Thread::SetCurrentThreadAffinity(1); //Force to first core
if (_CoreParameter.bUseFastMem)
else if (_CoreParameter.bRunCompareClient)
{
PanicAlert("Compare Debug : Press OK when ready.");
CPUCompare::ConnectAsClient();
}
if (_CoreParameter.bLockThreads)
Common::Thread::SetCurrentThreadAffinity(1); //Force to first core
if (_CoreParameter.bUseFastMem)
{
#ifdef _M_X64
// Let's run under memory watch
EMM::InstallExceptionHandler();
// Let's run under memory watch
EMM::InstallExceptionHandler();
#else
PanicAlert("32-bit platforms do not support fastmem yet. Report this bug.");
PanicAlert("32-bit platforms do not support fastmem yet. Report this bug.");
#endif
}
CCPU::Run();
if (_CoreParameter.bRunCompareServer || _CoreParameter.bRunCompareClient)
CCPU::Run();
if (_CoreParameter.bRunCompareServer || _CoreParameter.bRunCompareClient)
{
CPUCompare::Stop();
CPUCompare::Stop();
}
return 0;
return 0;
}
//////////////////////////////////////////
@ -370,55 +367,55 @@ THREAD_RETURN EmuThread(void *pArg)
else
PowerPC::SetMode(PowerPC::MODE_INTERPRETER);
// update the window again because all stuff is initialized
Host_UpdateDisasmDialog();
Host_UpdateMainFrame();
// update the window again because all stuff is initialized
Host_UpdateDisasmDialog();
Host_UpdateMainFrame();
//This thread, after creating the EmuWindow, spawns a CPU thread,
//then takes over and becomes the graphics thread
//In single core mode, the CPU thread does the graphics. In fact, the
//CPU thread should in this case also create the emuwindow...
// Spawn the CPU thread
Common::Thread *cpuThread = NULL;
//////////////////////////////////////////////////////////////////////////
// ENTER THE VIDEO THREAD LOOP
//////////////////////////////////////////////////////////////////////////
if (!Core::GetStartupParameter().bUseDualCore)
{
#ifdef _WIN32
cpuThread = new Common::Thread(CpuThread, pArg);
//Common::SetCurrentThreadName("Idle thread");
//TODO(ector) : investigate using GetMessage instead .. although
//then we lose the powerdown check. ... unless powerdown sends a message :P
while (PowerPC::state != PowerPC::CPU_POWERDOWN)
{
if (Callback_PeekMessages) {
Callback_PeekMessages();
}
Common::SleepCurrentThread(20);
}
#else
// In single-core mode, the Emulation main thread is also the CPU thread
CpuThread(pArg);
#endif
#ifdef _WIN32
cpuThread = new Common::Thread(CpuThread, pArg);
//Common::SetCurrentThreadName("Idle thread");
//TODO(ector) : investigate using GetMessage instead .. although
//then we lose the powerdown check. ... unless powerdown sends a message :P
while (PowerPC::state != PowerPC::CPU_POWERDOWN)
{
if (Callback_PeekMessages) {
Callback_PeekMessages();
}
Common::SleepCurrentThread(20);
}
#else
// In single-core mode, the Emulation main thread is also the CPU thread
CpuThread(pArg);
#endif
}
else
{
cpuThread = new Common::Thread(CpuThread, pArg);
PluginVideo::Video_Prepare(); //wglMakeCurrent
Common::SetCurrentThreadName("Video thread");
PluginVideo::Video_EnterLoop();
cpuThread = new Common::Thread(CpuThread, pArg);
PluginVideo::Video_Prepare(); //wglMakeCurrent
Common::SetCurrentThreadName("Video thread");
PluginVideo::Video_EnterLoop();
}
// Wait for CPU thread to exit - it should have been signaled to do so by now
if (cpuThread)
cpuThread->WaitForDeath();
cpuThread->WaitForDeath();
if (g_pUpdateFPSDisplay != NULL)
g_pUpdateFPSDisplay("Stopping...");
g_pUpdateFPSDisplay("Stopping...");
if (cpuThread)
{
@ -427,20 +424,19 @@ THREAD_RETURN EmuThread(void *pArg)
cpuThread = NULL;
}
g_bHwInit = false;
PluginPAD::PAD_Shutdown();
PluginPAD::UnloadPlugin();
if (_CoreParameter.bWii)
{
PluginWiimote::Wiimote_Shutdown();
PluginWiimote::UnloadPlugin();
PluginWiimote::Wiimote_Shutdown();
PluginWiimote::UnloadPlugin();
}
PluginDSP::DSP_Shutdown();
PluginDSP::UnloadPlugin();
PluginVideo::Video_Shutdown();
PluginVideo::UnloadPlugin();
InputCommon::Shutdown();
HW::Shutdown();
LOG(MASTER_LOG, "EmuThread exited");

View File

@ -8,8 +8,8 @@ EventHandler *EventHandler::m_Instance = 0;
EventHandler::EventHandler() {
for (int i=0; i<NUMKEYS; i++)
for (int j=0; j<NUMMODS; j++)
keys[i][j] = NULL;
for (int j=0; j<NUMMODS; j++)
keys[i][j] = NULL;
// memset(keys, sizeof(listenFuncPtr) * NUMKEYS*NUMMODS, 0);
memset(mouse, sizeof(listenFuncPtr) * (sf::Mouse::Count+1), 0);
memset(joys, sizeof(listenFuncPtr) * (sf::Joy::Count+1), 0);
@ -20,25 +20,29 @@ EventHandler::~EventHandler() {
}
EventHandler *EventHandler::GetInstance() {
fprintf(stderr, "handler instance %p\n", m_Instance);
if (! m_Instance)
m_Instance = new EventHandler();
return m_Instance;
}
void EventHandler::Destroy() {
if (m_Instance)
delete m_Instance;
fprintf(stderr, "deleting instance %p\n", m_Instance);
m_Instance = 0;
}
bool EventHandler::RegisterEventListener(listenFuncPtr func, Keys key) {
if (key.inputType == KeyboardInput) {
// fprintf(stderr, "Registering %d:%d %p\n", key.keyCode, key.mods, func);
fprintf(stderr, "Registering %d:%d %p\n", key.keyCode, key.mods, func);
if (key.keyCode == sf::Key::Count || key.mods >= NUMMODS ||
key.keyCode >= NUMKEYS || keys[key.keyCode][key.mods])
key.keyCode >= NUMKEYS)
return false;
if (keys[key.keyCode][key.mods] && keys[key.keyCode][key.mods] != func)
return false
;
keys[key.keyCode][key.mods] = func;
} else if (key.inputType == MouseInput) {
if (mouse[key.mouseButton])
@ -68,12 +72,15 @@ void EventHandler::Update() {
for (unsigned int i = 0; i < eventQueue.size();i++) {
sf::Event ev = eventQueue.front();
eventQueue.pop();
keys[ev.Key.Code][ev.Key.Alt+2*ev.Key.Shift+4*ev.Key.Control](ev);
fprintf(stderr, "Updating event type %d code %d mod %d func %p\n", ev.Type, ev.Key.Code, ev.Key.Alt+2*ev.Key.Shift+4*ev.Key.Control, keys[ev.Key.Code][ev.Key.Alt+2*ev.Key.Shift+4*ev.Key.Control]);
if(keys[ev.Key.Code][ev.Key.Alt+2*ev.Key.Shift+4*ev.Key.Control])
keys[ev.Key.Code][ev.Key.Alt+2*ev.Key.Shift+4*ev.Key.Control](ev);
}
}
bool EventHandler::addEvent(sf::Event *ev) {
eventQueue.push(*ev);
fprintf(stderr, "Got event type %d code %d\n", ev->Type, ev->Key.Code);
return true;
}