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"
#endif
#if defined(USE_EVDEV)
#include "evdev.h"
#endif
#ifdef USE_BREAKPAD
#include "breakpad/client/linux/handler/exception_handler.h"
#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()
{
#if defined(SUPPORT_X11)
@ -76,31 +36,11 @@ void os_DoEvents()
#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();
// Find the user config directory.
// $HOME/.config/flycast on linux
std::string find_user_config_dir()
static std::string find_user_config_dir()
{
std::string xdg_home;
if (nowide::getenv("XDG_CONFIG_HOME") != nullptr)
@ -129,7 +69,7 @@ std::string find_user_config_dir()
// Find the user data directory.
// $HOME/.local/share/flycast on linux
std::string find_user_data_dir()
static std::string find_user_data_dir()
{
std::string xdg_home;
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/xdg/flycast/
// .
std::vector<std::string> find_system_config_dirs()
static std::vector<std::string> find_system_config_dirs()
{
std::vector<std::string> dirs;
@ -225,7 +165,7 @@ std::vector<std::string> find_system_config_dirs()
// <$FLYCAST_BIOS_PATH>
// ./
// ./data
std::vector<std::string> find_system_data_dirs()
static std::vector<std::string> find_system_data_dirs()
{
std::vector<std::string> dirs;
@ -328,13 +268,6 @@ int main(int argc, char* argv[])
mainui_loop();
#if defined(SUPPORT_X11)
x11_window_destroy();
#endif
#if defined(USE_SDL)
sdl_window_destroy();
#endif
flycast_term();
os_UninstallFaultHandler();

View File

@ -21,6 +21,8 @@
#define DEFAULT_WINDOW_WIDTH 640
#define DEFAULT_WINDOW_HEIGHT 480
static void x11_window_set_text(const char *text);
static Window x11_win;
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)
{

View File

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

View File

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

View File

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

View File

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

View File

@ -25,6 +25,20 @@
#ifndef _WIN32
#include <unistd.h>
#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
{
@ -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
#include "rend/boxart/http_client.h"

View File

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

View File

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

View File

@ -34,14 +34,12 @@ static bool mainui_enabled;
u32 MainFrameCount;
static bool forceReinit;
void UpdateInputState();
bool mainui_rend_frame()
{
FC_PROFILE_SCOPE;
os_DoEvents();
UpdateInputState();
os_UpdateInputState();
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 inline void get_window_state()

View File

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

View File

@ -28,8 +28,6 @@
#include <nowide/convert.hpp>
#include "cfg/option.h"
#include "rend/gui.h"
#else
#include "rawinput.h"
#endif
#include "oslib/oslib.h"
#include "stdclass.h"
@ -51,26 +49,6 @@
#include <windows.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()
{
#ifndef TARGET_UWP
@ -110,23 +88,6 @@ static void setupPath()
#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()
{
#if defined(_WIN64) && defined(_DEBUG)
@ -433,8 +394,6 @@ int main(int argc, char* argv[])
mainui_loop();
sdl_window_destroy();
flycast_term();
os_UninstallFaultHandler();

View File

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

View File

@ -23,6 +23,8 @@
#import "AppDelegate.h"
#import <AVFoundation/AVFoundation.h>
#include <mach/task.h>
#include <mach/mach_init.h>
#include "emulator.h"
#include "log/LogManager.h"
#include "cfg/option.h"
@ -50,6 +52,11 @@ static bool emulatorRunning;
if (error != nil)
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;
}

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<GCMouse *, std::shared_ptr<IOSMouse>> IOSMouse::mice;
void common_linux_setup();
static bool lockedPointer;
static void updatePointerLock(Event event, void *)
{
@ -210,7 +208,7 @@ static void updateAudioSession(Event event, void *)
}
#endif
common_linux_setup();
os_InstallFaultHandler();
flycast_init(0, nullptr);
config::ContentPath.get().clear();

View File

@ -20,8 +20,6 @@
#import <Foundation/Foundation.h>
#include <string>
#include <mach/task.h>
#include <mach/mach_init.h>
int darw_printf(const char* text,...)
{
@ -40,24 +38,6 @@ int darw_printf(const char* text,...)
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(){
return [[[NSLocale preferredLanguages] objectAtIndex:0] UTF8String];
}

View File

@ -47,10 +47,6 @@ int darw_printf(const char* text, ...)
return 0;
}
void os_SetWindowText(const char * text) {
puts(text);
}
void os_DoEvents() {
#if defined(USE_SDL)
NSMenuItem *editMenuItem = [[NSApp mainMenu] itemAtIndex:1];
@ -58,43 +54,6 @@ void os_DoEvents() {
#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 void emu_flycast_term()
@ -172,7 +131,6 @@ extern "C" int SDL_main(int argc, char *argv[])
mainui_loop();
sdl_window_destroy();
emu_flycast_term();
os_UninstallFaultHandler();
@ -182,7 +140,7 @@ extern "C" int SDL_main(int argc, char *argv[])
static int emu_flycast_init()
{
LogManager::Init();
common_linux_setup();
os_InstallFaultHandler();
NSArray *arguments = [[NSProcessInfo processInfo] arguments];
unsigned long argc = [arguments count];
char **argv = (char **)malloc(argc * sizeof(char*));
@ -201,6 +159,19 @@ static int emu_flycast_init()
for (unsigned long i = 0; i < paramCount; i++)
free(argv[i]);
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;
}

View File

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

View File

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

View File

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