move most os_* funcs to oslib

add os_DestroyWindow and os_UpdateInputState
This commit is contained in:
Flyinghead 2024-04-12 17:37:45 +02:00
parent b378161837
commit 336706e728
21 changed files with 125 additions and 264 deletions

View File

@ -24,50 +24,10 @@
#include "sdl/sdl.h" #include "sdl/sdl.h"
#endif #endif
#if defined(USE_EVDEV)
#include "evdev.h"
#endif
#ifdef USE_BREAKPAD #ifdef USE_BREAKPAD
#include "breakpad/client/linux/handler/exception_handler.h" #include "breakpad/client/linux/handler/exception_handler.h"
#endif #endif
void os_SetupInput()
{
#if defined(USE_EVDEV)
input_evdev_init();
#endif
#if defined(SUPPORT_X11)
input_x11_init();
#endif
#if defined(USE_SDL)
input_sdl_init();
#endif
}
void os_TermInput()
{
#if defined(USE_EVDEV)
input_evdev_close();
#endif
#if defined(USE_SDL)
input_sdl_quit();
#endif
}
void UpdateInputState()
{
#if defined(USE_EVDEV)
input_evdev_handle();
#endif
#if defined(USE_SDL)
input_sdl_handle();
#endif
}
void os_DoEvents() void os_DoEvents()
{ {
#if defined(SUPPORT_X11) #if defined(SUPPORT_X11)
@ -76,31 +36,11 @@ void os_DoEvents()
#endif #endif
} }
void os_SetWindowText(const char * text)
{
#if defined(SUPPORT_X11)
x11_window_set_text(text);
#endif
#if defined(USE_SDL)
sdl_window_set_text(text);
#endif
}
void os_CreateWindow()
{
#if defined(SUPPORT_X11)
x11_window_create();
#endif
#if defined(USE_SDL)
sdl_window_create();
#endif
}
void common_linux_setup(); void common_linux_setup();
// Find the user config directory. // Find the user config directory.
// $HOME/.config/flycast on linux // $HOME/.config/flycast on linux
std::string find_user_config_dir() static std::string find_user_config_dir()
{ {
std::string xdg_home; std::string xdg_home;
if (nowide::getenv("XDG_CONFIG_HOME") != nullptr) if (nowide::getenv("XDG_CONFIG_HOME") != nullptr)
@ -129,7 +69,7 @@ std::string find_user_config_dir()
// Find the user data directory. // Find the user data directory.
// $HOME/.local/share/flycast on linux // $HOME/.local/share/flycast on linux
std::string find_user_data_dir() static std::string find_user_data_dir()
{ {
std::string xdg_home; std::string xdg_home;
if (nowide::getenv("XDG_DATA_HOME") != nullptr) if (nowide::getenv("XDG_DATA_HOME") != nullptr)
@ -181,7 +121,7 @@ static void addDirectoriesFromPath(std::vector<std::string>& dirs, const std::st
// /etc/flycast/ // /etc/flycast/
// /etc/xdg/flycast/ // /etc/xdg/flycast/
// . // .
std::vector<std::string> find_system_config_dirs() static std::vector<std::string> find_system_config_dirs()
{ {
std::vector<std::string> dirs; std::vector<std::string> dirs;
@ -225,7 +165,7 @@ std::vector<std::string> find_system_config_dirs()
// <$FLYCAST_BIOS_PATH> // <$FLYCAST_BIOS_PATH>
// ./ // ./
// ./data // ./data
std::vector<std::string> find_system_data_dirs() static std::vector<std::string> find_system_data_dirs()
{ {
std::vector<std::string> dirs; std::vector<std::string> dirs;
@ -328,13 +268,6 @@ int main(int argc, char* argv[])
mainui_loop(); mainui_loop();
#if defined(SUPPORT_X11)
x11_window_destroy();
#endif
#if defined(USE_SDL)
sdl_window_destroy();
#endif
flycast_term(); flycast_term();
os_UninstallFaultHandler(); os_UninstallFaultHandler();

View File

@ -21,6 +21,8 @@
#define DEFAULT_WINDOW_WIDTH 640 #define DEFAULT_WINDOW_WIDTH 640
#define DEFAULT_WINDOW_HEIGHT 480 #define DEFAULT_WINDOW_HEIGHT 480
static void x11_window_set_text(const char *text);
static Window x11_win; static Window x11_win;
Display *x11_disp; Display *x11_disp;
@ -356,7 +358,7 @@ void x11_window_create()
} }
} }
void x11_window_set_text(const char* text) static void x11_window_set_text(const char* text)
{ {
if (x11_win) if (x11_win)
{ {

View File

@ -1,11 +1,10 @@
#pragma once #pragma once
extern void input_x11_init(); void input_x11_init();
extern void event_x11_handle(); void event_x11_handle();
extern void input_x11_handle(); void input_x11_handle();
extern void x11_window_create(); void x11_window_create();
extern void x11_window_set_text(const char* text); void x11_window_destroy();
extern void x11_window_destroy();
// numbers // numbers
const int KEY_1 = 10; const int KEY_1 = 10;

View File

@ -162,7 +162,7 @@ static void linux_fix_personality()
#endif #endif
} }
#if defined(__unix__) && !defined(LIBRETRO) #if defined(__unix__) && !defined(LIBRETRO) && !defined(__ANDROID__)
static void sigintHandler(int) static void sigintHandler(int)
{ {
dc_exit(); dc_exit();
@ -175,7 +175,7 @@ void common_linux_setup()
enable_runfast(); enable_runfast();
os_InstallFaultHandler(); os_InstallFaultHandler();
#if defined(__unix__) && !defined(LIBRETRO) #if defined(__unix__) && !defined(LIBRETRO) && !defined(__ANDROID__)
// exit cleanly on ^C // exit cleanly on ^C
signal(SIGINT, sigintHandler); signal(SIGINT, sigintHandler);
#endif #endif

View File

@ -23,10 +23,9 @@
#include "input/keyboard_device.h" #include "input/keyboard_device.h"
#include "input/mouse.h" #include "input/mouse.h"
#include "cfg/option.h" #include "cfg/option.h"
#include "oslib/oslib.h"
#include <algorithm> #include <algorithm>
void UpdateInputState();
namespace ggpo namespace ggpo
{ {
@ -35,7 +34,7 @@ bool inRollback;
static void getLocalInput(MapleInputState inputState[4]) static void getLocalInput(MapleInputState inputState[4])
{ {
if (!config::ThreadedRendering) if (!config::ThreadedRendering)
UpdateInputState(); os_UpdateInputState();
std::lock_guard<std::mutex> lock(relPosMutex); std::lock_guard<std::mutex> lock(relPosMutex);
for (int player = 0; player < 4; player++) for (int player = 0; player < 4; player++)
{ {
@ -706,7 +705,7 @@ bool nextFrame()
// may call save_game_state // may call save_game_state
do { do {
if (!config::ThreadedRendering) if (!config::ThreadedRendering)
UpdateInputState(); os_UpdateInputState();
Inputs inputs; Inputs inputs;
inputs.kcode = ~kcode[0]; inputs.kcode = ~kcode[0];
if (rt[0] >= 0x4000) if (rt[0] >= 0x4000)

View File

@ -83,6 +83,7 @@ void SaveSettings()
void flycast_term() void flycast_term()
{ {
os_DestroyWindow();
gui_cancel_load(); gui_cancel_load();
lua::term(); lua::term();
emu.term(); emu.term();

View File

@ -25,6 +25,20 @@
#ifndef _WIN32 #ifndef _WIN32
#include <unistd.h> #include <unistd.h>
#endif #endif
#if defined(USE_SDL)
#include "sdl/sdl.h"
#else
#if defined(SUPPORT_X11)
#include "linux-dist/x11.h"
#endif
#if defined(USE_EVDEV)
#include "linux-dist/evdev.h"
#endif
#endif
#if defined(_WIN32) && !defined(TARGET_UWP)
#include "windows/rawinput.h"
#endif
#include "profiler/fc_profiler.h"
namespace hostfs namespace hostfs
{ {
@ -139,6 +153,70 @@ std::string getTextureDumpPath()
} }
void os_CreateWindow()
{
#if defined(USE_SDL)
sdl_window_create();
#elif defined(SUPPORT_X11)
x11_window_create();
#endif
}
void os_DestroyWindow()
{
#if defined(USE_SDL)
sdl_window_destroy();
#elif defined(SUPPORT_X11)
x11_window_destroy();
#endif
}
void os_SetupInput()
{
#if defined(USE_SDL)
input_sdl_init();
#else
#if defined(SUPPORT_X11)
input_x11_init();
#endif
#if defined(USE_EVDEV)
input_evdev_init();
#endif
#endif
#if defined(_WIN32) && !defined(TARGET_UWP)
if (config::UseRawInput)
rawinput::init();
#endif
}
void os_TermInput()
{
#if defined(USE_SDL)
input_sdl_quit();
#else
#if defined(USE_EVDEV)
input_evdev_close();
#endif
#endif
#if defined(_WIN32) && !defined(TARGET_UWP)
if (config::UseRawInput)
rawinput::term();
#endif
}
void os_UpdateInputState()
{
FC_PROFILE_SCOPE;
#if defined(USE_SDL)
input_sdl_handle();
#else
#if defined(USE_EVDEV)
input_evdev_handle();
#endif
#endif
}
#ifdef USE_BREAKPAD #ifdef USE_BREAKPAD
#include "rend/boxart/http_client.h" #include "rend/boxart/http_client.h"

View File

@ -4,12 +4,12 @@
#include <malloc.h> #include <malloc.h>
#endif #endif
void os_SetWindowText(const char* text);
void os_DoEvents(); void os_DoEvents();
void os_CreateWindow(); void os_CreateWindow();
void os_DestroyWindow();
void os_SetupInput(); void os_SetupInput();
void os_TermInput(); void os_TermInput();
void os_UpdateInputState();
void os_InstallFaultHandler(); void os_InstallFaultHandler();
void os_UninstallFaultHandler(); void os_UninstallFaultHandler();
void os_RunInstance(int argc, const char *argv[]); void os_RunInstance(int argc, const char *argv[]);

View File

@ -24,6 +24,7 @@
#include "imgui_internal.h" #include "imgui_internal.h"
#include "gui.h" #include "gui.h"
#include "emulator.h" #include "emulator.h"
#include "oslib/oslib.h"
#include <algorithm> #include <algorithm>
#include <chrono> #include <chrono>
@ -78,6 +79,7 @@ public:
{ {
progress.reset(); progress.reset();
future = std::async(std::launch::async, [this, path] { future = std::async(std::launch::async, [this, path] {
ThreadName _("GameLoader");
emu.loadGame(path.c_str(), &progress); emu.loadGame(path.c_str(), &progress);
}); });
} }

View File

@ -34,14 +34,12 @@ static bool mainui_enabled;
u32 MainFrameCount; u32 MainFrameCount;
static bool forceReinit; static bool forceReinit;
void UpdateInputState();
bool mainui_rend_frame() bool mainui_rend_frame()
{ {
FC_PROFILE_SCOPE; FC_PROFILE_SCOPE;
os_DoEvents(); os_DoEvents();
UpdateInputState(); os_UpdateInputState();
if (gui_is_open() || gui_state == GuiState::VJoyEdit) if (gui_is_open() || gui_state == GuiState::VJoyEdit)
{ {

View File

@ -562,12 +562,6 @@ void input_sdl_handle()
} }
} }
void sdl_window_set_text(const char* text)
{
if (window != nullptr)
SDL_SetWindowTitle(window, text);
}
static float hdpiScaling = 1.f; static float hdpiScaling = 1.f;
static inline void get_window_state() static inline void get_window_state()

View File

@ -6,7 +6,6 @@ void input_sdl_init();
void input_sdl_handle(); void input_sdl_handle();
void input_sdl_quit(); void input_sdl_quit();
void sdl_window_create(); void sdl_window_create();
void sdl_window_set_text(const char* text);
void sdl_window_destroy(); void sdl_window_destroy();
bool sdl_recreate_window(u32 flags); bool sdl_recreate_window(u32 flags);
void sdl_fix_steamdeck_dpi(SDL_Window *window); void sdl_fix_steamdeck_dpi(SDL_Window *window);

View File

@ -28,8 +28,6 @@
#include <nowide/convert.hpp> #include <nowide/convert.hpp>
#include "cfg/option.h" #include "cfg/option.h"
#include "rend/gui.h" #include "rend/gui.h"
#else
#include "rawinput.h"
#endif #endif
#include "oslib/oslib.h" #include "oslib/oslib.h"
#include "stdclass.h" #include "stdclass.h"
@ -51,26 +49,6 @@
#include <windows.h> #include <windows.h>
#include <windowsx.h> #include <windowsx.h>
void os_SetupInput()
{
input_sdl_init();
#ifndef TARGET_UWP
if (config::UseRawInput)
rawinput::init();
#endif
}
void os_TermInput()
{
input_sdl_quit();
#ifndef TARGET_UWP
if (config::UseRawInput)
rawinput::term();
#endif
}
static void setupPath() static void setupPath()
{ {
#ifndef TARGET_UWP #ifndef TARGET_UWP
@ -110,23 +88,6 @@ static void setupPath()
#endif #endif
} }
void UpdateInputState()
{
FC_PROFILE_SCOPE;
input_sdl_handle();
}
void os_CreateWindow()
{
sdl_window_create();
}
void os_SetWindowText(const char* text)
{
sdl_window_set_text(text);
}
static void reserveBottomMemory() static void reserveBottomMemory()
{ {
#if defined(_WIN64) && defined(_DEBUG) #if defined(_WIN64) && defined(_DEBUG)
@ -433,8 +394,6 @@ int main(int argc, char* argv[])
mainui_loop(); mainui_loop();
sdl_window_destroy();
flycast_term(); flycast_term();
os_UninstallFaultHandler(); os_UninstallFaultHandler();

View File

@ -99,27 +99,8 @@ void os_DoEvents()
{ {
} }
void os_CreateWindow()
{
}
void UpdateInputState()
{
}
void common_linux_setup(); void common_linux_setup();
void os_SetupInput()
{
}
void os_TermInput()
{
}
void os_SetWindowText(char const *Text)
{
}
#if defined(USE_BREAKPAD) #if defined(USE_BREAKPAD)
static bool dumpCallback(const google_breakpad::MinidumpDescriptor& descriptor, void* context, bool succeeded) static bool dumpCallback(const google_breakpad::MinidumpDescriptor& descriptor, void* context, bool succeeded)
{ {

View File

@ -23,6 +23,8 @@
#import "AppDelegate.h" #import "AppDelegate.h"
#import <AVFoundation/AVFoundation.h> #import <AVFoundation/AVFoundation.h>
#include <mach/task.h>
#include <mach/mach_init.h>
#include "emulator.h" #include "emulator.h"
#include "log/LogManager.h" #include "log/LogManager.h"
#include "cfg/option.h" #include "cfg/option.h"
@ -50,6 +52,11 @@ static bool emulatorRunning;
if (error != nil) if (error != nil)
NSLog(@"AVAudioSession.setActive: %@", error); NSLog(@"AVAudioSession.setActive: %@", error);
if (getppid() != 1) {
/* Make LLDB ignore EXC_BAD_ACCESS for debugging */
task_set_exception_ports(mach_task_self(), EXC_MASK_BAD_ACCESS, MACH_PORT_NULL, EXCEPTION_DEFAULT, 0);
}
return YES; return YES;
} }

View File

@ -54,8 +54,6 @@ std::map<GCController *, std::shared_ptr<IOSGamepad>> IOSGamepad::controllers;
std::map<GCKeyboard *, std::shared_ptr<IOSKeyboard>> IOSKeyboard::keyboards; std::map<GCKeyboard *, std::shared_ptr<IOSKeyboard>> IOSKeyboard::keyboards;
std::map<GCMouse *, std::shared_ptr<IOSMouse>> IOSMouse::mice; std::map<GCMouse *, std::shared_ptr<IOSMouse>> IOSMouse::mice;
void common_linux_setup();
static bool lockedPointer; static bool lockedPointer;
static void updatePointerLock(Event event, void *) static void updatePointerLock(Event event, void *)
{ {
@ -210,7 +208,7 @@ static void updateAudioSession(Event event, void *)
} }
#endif #endif
common_linux_setup(); os_InstallFaultHandler();
flycast_init(0, nullptr); flycast_init(0, nullptr);
config::ContentPath.get().clear(); config::ContentPath.get().clear();

View File

@ -20,8 +20,6 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#include <string> #include <string>
#include <mach/task.h>
#include <mach/mach_init.h>
int darw_printf(const char* text,...) int darw_printf(const char* text,...)
{ {
@ -40,24 +38,6 @@ int darw_printf(const char* text,...)
void os_DoEvents() { void os_DoEvents() {
} }
void os_SetWindowText(const char* t) {
}
void os_CreateWindow() {
if (getppid() != 1) {
/* Make LLDB ignore EXC_BAD_ACCESS for debugging */
task_set_exception_ports(mach_task_self(), EXC_MASK_BAD_ACCESS, MACH_PORT_NULL, EXCEPTION_DEFAULT, 0);
}
}
void UpdateInputState() {
}
void os_SetupInput() {
}
void os_TermInput() {
}
std::string os_Locale(){ std::string os_Locale(){
return [[[NSLocale preferredLanguages] objectAtIndex:0] UTF8String]; return [[[NSLocale preferredLanguages] objectAtIndex:0] UTF8String];
} }

View File

@ -47,10 +47,6 @@ int darw_printf(const char* text, ...)
return 0; return 0;
} }
void os_SetWindowText(const char * text) {
puts(text);
}
void os_DoEvents() { void os_DoEvents() {
#if defined(USE_SDL) #if defined(USE_SDL)
NSMenuItem *editMenuItem = [[NSApp mainMenu] itemAtIndex:1]; NSMenuItem *editMenuItem = [[NSApp mainMenu] itemAtIndex:1];
@ -58,43 +54,6 @@ void os_DoEvents() {
#endif #endif
} }
void UpdateInputState() {
#if defined(USE_SDL)
input_sdl_handle();
#endif
}
void os_CreateWindow() {
#ifdef DEBUG
int ret = task_set_exception_ports(
mach_task_self(),
EXC_MASK_BAD_ACCESS,
MACH_PORT_NULL,
EXCEPTION_DEFAULT,
0);
if (ret != KERN_SUCCESS) {
printf("task_set_exception_ports: %s\n", mach_error_string(ret));
}
#endif
sdl_window_create();
}
void os_SetupInput()
{
#if defined(USE_SDL)
input_sdl_init();
#endif
}
void os_TermInput()
{
#if defined(USE_SDL)
input_sdl_quit();
#endif
}
void common_linux_setup();
static int emu_flycast_init(); static int emu_flycast_init();
static void emu_flycast_term() static void emu_flycast_term()
@ -172,7 +131,6 @@ extern "C" int SDL_main(int argc, char *argv[])
mainui_loop(); mainui_loop();
sdl_window_destroy();
emu_flycast_term(); emu_flycast_term();
os_UninstallFaultHandler(); os_UninstallFaultHandler();
@ -182,7 +140,7 @@ extern "C" int SDL_main(int argc, char *argv[])
static int emu_flycast_init() static int emu_flycast_init()
{ {
LogManager::Init(); LogManager::Init();
common_linux_setup(); os_InstallFaultHandler();
NSArray *arguments = [[NSProcessInfo processInfo] arguments]; NSArray *arguments = [[NSProcessInfo processInfo] arguments];
unsigned long argc = [arguments count]; unsigned long argc = [arguments count];
char **argv = (char **)malloc(argc * sizeof(char*)); char **argv = (char **)malloc(argc * sizeof(char*));
@ -201,6 +159,19 @@ static int emu_flycast_init()
for (unsigned long i = 0; i < paramCount; i++) for (unsigned long i = 0; i < paramCount; i++)
free(argv[i]); free(argv[i]);
free(argv); free(argv);
#if defined(DEBUG) || defined(DEBUGFAST)
int ret = task_set_exception_ports(
mach_task_self(),
EXC_MASK_BAD_ACCESS,
MACH_PORT_NULL,
EXCEPTION_DEFAULT,
0);
if (ret != KERN_SUCCESS) {
printf("task_set_exception_ports: %s\n", mach_error_string(ret));
}
#endif
return rc; return rc;
} }

View File

@ -221,7 +221,6 @@ static std::vector<std::string> disk_paths;
static std::vector<std::string> disk_labels; static std::vector<std::string> disk_labels;
static bool disc_tray_open = false; static bool disc_tray_open = false;
void UpdateInputState();
static bool set_variable_visibility(void); static bool set_variable_visibility(void);
void retro_set_video_refresh(retro_video_refresh_t cb) void retro_set_video_refresh(retro_video_refresh_t cb)
@ -1170,7 +1169,7 @@ void retro_run()
emu.start(); emu.start();
poll_cb(); poll_cb();
UpdateInputState(); os_UpdateInputState();
bool fastforward = false; bool fastforward = false;
if (environ_cb(RETRO_ENVIRONMENT_GET_FASTFORWARDING, &fastforward)) if (environ_cb(RETRO_ENVIRONMENT_GET_FASTFORWARDING, &fastforward))
settings.input.fastForwardMode = fastforward; settings.input.fastForwardMode = fastforward;
@ -3357,7 +3356,7 @@ static void UpdateInputState(u32 port)
} }
} }
void UpdateInputState() void os_UpdateInputState()
{ {
UpdateInputState(0); UpdateInputState(0);
UpdateInputState(1); UpdateInputState(1);
@ -3710,5 +3709,3 @@ void gui_display_notification(const char *msg, int duration)
retromsg.frames = duration / 17; retromsg.frames = duration / 17;
environ_cb(RETRO_ENVIRONMENT_SET_MESSAGE, &retromsg); environ_cb(RETRO_ENVIRONMENT_SET_MESSAGE, &retromsg);
} }
void os_RunInstance(int argc, const char *argv[]) { }

View File

@ -17,7 +17,6 @@
#ifndef LIBRETRO #ifndef LIBRETRO
#include "nswitch.h" #include "nswitch.h"
#include "stdclass.h" #include "stdclass.h"
#include "sdl/sdl.h"
#include "log/LogManager.h" #include "log/LogManager.h"
#include "emulator.h" #include "emulator.h"
#include "rend/mainui.h" #include "rend/mainui.h"
@ -48,7 +47,6 @@ int main(int argc, char *argv[])
mainui_loop(); mainui_loop();
sdl_window_destroy();
flycast_term(); flycast_term();
socketExit(); socketExit();
@ -56,28 +54,8 @@ int main(int argc, char *argv[])
return 0; return 0;
} }
void os_SetupInput()
{
input_sdl_init();
}
void os_TermInput()
{
input_sdl_quit();
}
void UpdateInputState()
{
input_sdl_handle();
}
void os_DoEvents() void os_DoEvents()
{ {
} }
void os_CreateWindow()
{
sdl_window_create();
}
#endif //!LIBRETRO #endif //!LIBRETRO

View File

@ -15,25 +15,10 @@ HWND getNativeHwnd()
} }
#endif #endif
void os_SetupInput()
{
}
void os_TermInput()
{
}
void UpdateInputState()
{
}
void os_DoEvents() void os_DoEvents()
{ {
} }
void os_CreateWindow()
{
}
void os_RunInstance(int argc, const char *argv[]) void os_RunInstance(int argc, const char *argv[])
{ {
} }