Merge pull request #38 from georgemoralis/sdl_events

Sdl events
This commit is contained in:
georgemoralis 2023-09-14 19:34:47 +03:00 committed by GitHub
commit 12f097d86b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 5 deletions

View file

@ -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;
@ -23,17 +24,17 @@ static void CreateSdlWindow(WindowCtx* ctx) {
} }
ctx->m_window = SDL_CreateWindowWithPosition("shadps4", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, ctx->m_window = SDL_CreateWindowWithPosition("shadps4", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height,
(static_cast<uint32_t>(SDL_WINDOW_HIDDEN) | static_cast<uint32_t>(SDL_WINDOW_VULKAN))); (static_cast<uint32_t>(SDL_WINDOW_HIDDEN) | static_cast<uint32_t>(SDL_WINDOW_VULKAN)));
ctx->is_window_hidden = true;//hide window until we need to show something (should draw something in buffers) ctx->is_window_hidden = true; // hide window until we need to show something (should draw something in buffers)
if (ctx->m_window == nullptr) { if (ctx->m_window == nullptr) {
printf("%s\n", SDL_GetError()); printf("%s\n", SDL_GetError());
std::_Exit(0); std::_Exit(0);
} }
SDL_SetWindowResizable(ctx->m_window, SDL_FALSE);//we don't support resizable atm SDL_SetWindowResizable(ctx->m_window, SDL_FALSE); // we don't support resizable atm
SDL_ShowWindow(g_window_ctx->m_window);//TODO should be removed just left it over to make it fancy :D SDL_ShowWindow(g_window_ctx->m_window); // TODO should be removed just left it over to make it fancy :D
} }
void emuRun() { void emuRun() {
g_window_ctx->m_mutex.LockMutex(); g_window_ctx->m_mutex.LockMutex();
@ -45,8 +46,39 @@ void emuRun() {
} }
g_window_ctx->m_mutex.UnlockMutex(); g_window_ctx->m_mutex.UnlockMutex();
bool exit_loop = false;
for (;;) { for (;;) {
HLE::Libs::Graphics::VideoOut::videoOutFlip(100000); // flip every 0.1 sec if (exit_loop) {
break;
}
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
}
} }
std::_Exit(0); std::_Exit(0);
} }

View file

@ -12,6 +12,16 @@ struct WindowCtx {
SDL_Window* m_window = nullptr; SDL_Window* m_window = nullptr;
bool is_window_hidden = true; bool is_window_hidden = true;
}; };
struct EmuPrivate {
EmuPrivate() = default;
Lib::Mutex m_mutex;
HLE::Libs::Graphics::GraphicCtx* m_graphic_ctx = nullptr;
void* data1 = nullptr;
void* data2 = nullptr;
u32 m_screen_width = {0};
u32 m_screen_height = {0};
};
void emuInit(u32 width, u32 height); void emuInit(u32 width, u32 height);
void emuRun(); void emuRun();
} // namespace Emulator } // namespace Emulator