better event handling
This commit is contained in:
parent
61280cb6cf
commit
da2a942415
|
@ -5,6 +5,7 @@
|
||||||
namespace Emulator {
|
namespace Emulator {
|
||||||
|
|
||||||
static WindowCtx* g_window_ctx = nullptr;
|
static WindowCtx* g_window_ctx = nullptr;
|
||||||
|
bool m_emu_needs_exit = false;
|
||||||
|
|
||||||
void emuInit(u32 width, u32 height) {
|
void emuInit(u32 width, u32 height) {
|
||||||
g_window_ctx = new WindowCtx;
|
g_window_ctx = new WindowCtx;
|
||||||
|
@ -45,25 +46,40 @@ void emuRun() {
|
||||||
}
|
}
|
||||||
g_window_ctx->m_mutex.UnlockMutex();
|
g_window_ctx->m_mutex.UnlockMutex();
|
||||||
|
|
||||||
|
bool exit_loop = false;
|
||||||
auto* pdata = new EmuPrivate;
|
|
||||||
pdata->m_graphic_ctx = static_cast<HLE::Libs::Graphics::GraphicCtx*>(&g_window_ctx->m_graphic_ctx);
|
|
||||||
|
|
||||||
pdata->data1 = pdata;
|
|
||||||
pdata->data2 = new SDL_Event;
|
|
||||||
|
|
||||||
pdata->m_screen_width = pdata->m_graphic_ctx->screen_width;
|
|
||||||
pdata->m_screen_height = pdata->m_graphic_ctx->screen_height;
|
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
SDL_Event* ev = static_cast<SDL_Event*>(pdata->data2);
|
if (exit_loop) {
|
||||||
if (SDL_PollEvent(ev)!= 0)
|
break;
|
||||||
{
|
|
||||||
printf("Event: 0x%04\n", ev->type);
|
|
||||||
printf("]");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SDL_Event event;
|
||||||
|
if (SDL_PollEvent(&event) != 0) {
|
||||||
|
printf("Event: 0x%04\n", event.type);
|
||||||
|
switch (event.type) {
|
||||||
|
case SDL_EVENT_QUIT: m_emu_needs_exit = true; break;
|
||||||
|
|
||||||
|
case SDL_EVENT_TERMINATING: m_emu_needs_exit = true; break;
|
||||||
|
|
||||||
|
case SDL_EVENT_WILL_ENTER_BACKGROUND: break;
|
||||||
|
|
||||||
|
case SDL_EVENT_DID_ENTER_BACKGROUND: break;
|
||||||
|
|
||||||
|
case SDL_EVENT_WILL_ENTER_FOREGROUND: break;
|
||||||
|
|
||||||
|
case SDL_EVENT_DID_ENTER_FOREGROUND: break;
|
||||||
|
|
||||||
|
case SDL_EVENT_KEY_DOWN:
|
||||||
|
case SDL_EVENT_KEY_UP: break;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
exit_loop = m_emu_needs_exit;
|
||||||
|
|
||||||
|
if (!exit_loop) {
|
||||||
HLE::Libs::Graphics::VideoOut::videoOutFlip(100000); // flip every 0.1 sec
|
HLE::Libs::Graphics::VideoOut::videoOutFlip(100000); // flip every 0.1 sec
|
||||||
}
|
}
|
||||||
|
}
|
||||||
std::_Exit(0);
|
std::_Exit(0);
|
||||||
}
|
}
|
||||||
} // namespace Emulator
|
} // namespace Emulator
|
Loading…
Reference in New Issue