2023-08-09 07:31:18 +00:00
|
|
|
#include "emulator.h"
|
2023-09-12 16:39:08 +00:00
|
|
|
|
2023-09-11 10:14:13 +00:00
|
|
|
#include "Core/PS4/HLE/Graphics/video_out.h"
|
2023-09-17 17:01:29 +00:00
|
|
|
#include <vulkan_util.h>
|
2023-08-09 07:31:18 +00:00
|
|
|
|
|
|
|
namespace Emulator {
|
2023-09-12 16:39:08 +00:00
|
|
|
|
|
|
|
static WindowCtx* g_window_ctx = nullptr;
|
2023-09-14 15:47:42 +00:00
|
|
|
bool m_emu_needs_exit = false;
|
2023-09-12 16:39:08 +00:00
|
|
|
|
|
|
|
void emuInit(u32 width, u32 height) {
|
|
|
|
g_window_ctx = new WindowCtx;
|
|
|
|
|
|
|
|
g_window_ctx->m_graphic_ctx.screen_width = width;
|
|
|
|
g_window_ctx->m_graphic_ctx.screen_height = height;
|
|
|
|
}
|
|
|
|
|
2023-09-15 21:03:11 +00:00
|
|
|
void checkAndWaitForGraphicsInit() {
|
|
|
|
Lib::LockMutexGuard lock(g_window_ctx->m_mutex);
|
|
|
|
|
|
|
|
while (!g_window_ctx->m_is_graphic_initialized) {
|
|
|
|
g_window_ctx->m_graphic_initialized_cond.WaitCondVar(&g_window_ctx->m_mutex);
|
|
|
|
}
|
|
|
|
}
|
2023-09-12 16:39:08 +00:00
|
|
|
static void CreateSdlWindow(WindowCtx* ctx) {
|
|
|
|
int width = static_cast<int>(ctx->m_graphic_ctx.screen_width);
|
|
|
|
int height = static_cast<int>(ctx->m_graphic_ctx.screen_height);
|
|
|
|
|
|
|
|
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
|
|
|
|
printf("%s\n", SDL_GetError());
|
2023-09-15 11:40:03 +00:00
|
|
|
std::exit(0);
|
2023-09-12 16:39:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ctx->m_window = SDL_CreateWindowWithPosition("shadps4", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height,
|
2023-09-14 15:47:42 +00:00
|
|
|
(static_cast<uint32_t>(SDL_WINDOW_HIDDEN) | static_cast<uint32_t>(SDL_WINDOW_VULKAN)));
|
2023-09-12 16:39:08 +00:00
|
|
|
|
2023-09-14 15:47:42 +00:00
|
|
|
ctx->is_window_hidden = true; // hide window until we need to show something (should draw something in buffers)
|
2023-09-12 16:39:08 +00:00
|
|
|
|
|
|
|
if (ctx->m_window == nullptr) {
|
|
|
|
printf("%s\n", SDL_GetError());
|
2023-09-15 11:40:03 +00:00
|
|
|
std::exit(0);
|
2023-09-12 16:39:08 +00:00
|
|
|
}
|
|
|
|
|
2023-09-14 15:47:42 +00:00
|
|
|
SDL_SetWindowResizable(ctx->m_window, SDL_FALSE); // we don't support resizable atm
|
2023-09-12 16:39:08 +00:00
|
|
|
}
|
2023-08-09 07:31:18 +00:00
|
|
|
void emuRun() {
|
2023-09-12 16:39:08 +00:00
|
|
|
g_window_ctx->m_mutex.LockMutex();
|
|
|
|
{
|
|
|
|
// init window and wait until init finishes
|
|
|
|
CreateSdlWindow(g_window_ctx);
|
2023-09-17 17:01:29 +00:00
|
|
|
Graphics::Vulkan::vulkanCreate(g_window_ctx);
|
2023-09-12 16:39:08 +00:00
|
|
|
g_window_ctx->m_is_graphic_initialized = true;
|
|
|
|
g_window_ctx->m_graphic_initialized_cond.SignalCondVar();
|
|
|
|
}
|
|
|
|
g_window_ctx->m_mutex.UnlockMutex();
|
2023-09-14 13:49:47 +00:00
|
|
|
|
2023-09-14 15:47:42 +00:00
|
|
|
bool exit_loop = false;
|
2023-09-14 13:49:47 +00:00
|
|
|
|
2023-09-14 15:47:42 +00:00
|
|
|
for (;;) {
|
|
|
|
if (exit_loop) {
|
|
|
|
break;
|
|
|
|
}
|
2023-09-14 13:49:47 +00:00
|
|
|
|
2023-09-14 15:47:42 +00:00
|
|
|
SDL_Event event;
|
|
|
|
if (SDL_PollEvent(&event) != 0) {
|
|
|
|
switch (event.type) {
|
|
|
|
case SDL_EVENT_QUIT: m_emu_needs_exit = true; break;
|
2023-09-12 16:39:08 +00:00
|
|
|
|
2023-09-14 15:47:42 +00:00
|
|
|
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
|
2023-09-14 13:49:47 +00:00
|
|
|
}
|
2023-08-09 07:31:18 +00:00
|
|
|
}
|
2023-09-15 11:40:03 +00:00
|
|
|
std::exit(0);
|
2023-08-09 07:31:18 +00:00
|
|
|
}
|
2023-09-12 16:39:08 +00:00
|
|
|
} // namespace Emulator
|