Remove dependency on SDL headers in libretro builds

I'd already removed the SDL static libraries from libretro builds for
portability, but kept the headers to make it easier to port the codebase
to libretro. Eventually it was time to stop using the SDL headers as a
crutch.
This commit is contained in:
刘皓 2025-03-29 12:37:07 -04:00
parent b9e54fbb28
commit 81b94d1498
No known key found for this signature in database
GPG key ID: 7901753DB465B711
16 changed files with 97 additions and 44 deletions

View file

@ -112,7 +112,6 @@ if is_libretro
libretro_defines = [
'-DMKXPZ_VERSION="@0@"'.format(meson.project_version()),
'-DMKXPZ_RETRO',
'-DSHARED_FLUID',
'-D_FILE_OFFSET_BITS=64',
'-DMPG123_NO_LARGENAME',
'-DGL_GLES_PROTOTYPES=0',
@ -499,7 +498,6 @@ if is_libretro
libretro_deps = [
subproject('libretro-common').get_variable('libretro_common'),
subproject('sdl2-headers').get_variable('sdl2_headers'),
cmake.subproject('boost_asio', options: boost_options).dependency('boost_asio'),
cmake.subproject('boost_mp11', options: boost_options).dependency('boost_mp11'),
cmake.subproject('boost_describe', options: boost_options).dependency('boost_describe'),

View file

@ -1,8 +1,10 @@
#include "fluid-fun.h"
#include <string.h>
#include <SDL_loadso.h>
#include <SDL_platform.h>
#ifndef MKXPZ_RETRO
# include <SDL_loadso.h>
# include <SDL_platform.h>
#endif // MKXPZ_RETRO
#include "debugwriter.h"
@ -14,18 +16,18 @@
# define FLUID_LIB "libfluidsynth.3.dylib"
#elif defined(__WIN32__)
# define FLUID_LIB "fluidsynth.dll"
#elif !defined(SHARED_FLUID)
#elif !defined(MKXPZ_RETRO) && !defined(SHARED_FLUID)
# error "platform not recognized"
#endif
struct FluidFunctions fluid;
#ifndef SHARED_FLUID
#if !defined(MKXPZ_RETRO) && !defined(SHARED_FLUID)
static void *so;
#endif
void initFluidFunctions()
{
#ifdef SHARED_FLUID
#if defined(MKXPZ_RETRO) || defined(SHARED_FLUID)
#define FLUID_FUN(name, type) \
fluid.name = fluid_##name;
@ -55,7 +57,7 @@ FLUID_FUNCS2
return;
#ifndef SHARED_FLUID
#if !defined(MKXPZ_RETRO) && !defined(SHARED_FLUID)
fail:
Debug() << "Failed to load " FLUID_LIB ". Midi playback is disabled.";

View file

@ -1,12 +1,10 @@
#ifndef FLUIDFUN_H
#define FLUIDFUN_H
#ifdef SHARED_FLUID
# ifdef MKXPZ_RETRO
# include <fluidlite.h>
# else
# include <fluidsynth.h>
# endif // MKXPZ_RETRO
#ifdef MKXPZ_RETRO
# include <fluidlite.h>
#elif defined(SHARED_FLUID)
# include <fluidsynth.h>
#else
# define FLUIDSYNTH_VERSION_MAJOR 3
#endif
@ -31,7 +29,7 @@ typedef fluid_settings_t* (*NEWFLUIDSETTINGSPROC)(void);
typedef fluid_synth_t* (*NEWFLUIDSYNTHPROC)(fluid_settings_t* settings);
typedef void (*DELETEFLUIDSETTINGSPROC)(fluid_settings_t* settings);
#if (defined(SHARED_FLUID) && defined(MKXPZ_RETRO)) || FLUIDSYNTH_VERSION_MAJOR == 1
#if defined(MKXPZ_RETRO) || FLUIDSYNTH_VERSION_MAJOR == 1
typedef int (*DELETEFLUIDSYNTHPROC)(fluid_synth_t* synth);
#else
typedef void (*DELETEFLUIDSYNTHPROC)(fluid_synth_t* synth);

View file

@ -1455,8 +1455,10 @@ void Bitmap::stretchBlt(IntRect destRect,
}
}
#ifndef MKXPZ_RETRO // TODO
if (blitTemp)
SDL_FreeSurface(blitTemp);
#endif // MKXPZ_RETRO
p->addTaintedArea(destRect);
p->onModified();
@ -1764,6 +1766,7 @@ void Bitmap::clear()
p->onModified();
}
#ifndef MKXPZ_RETRO
static uint32_t &getPixelAt(SDL_Surface *surf, SDL_PixelFormat *form, int x, int y)
{
size_t offset = x*form->BytesPerPixel + y*surf->pitch;
@ -1771,6 +1774,7 @@ static uint32_t &getPixelAt(SDL_Surface *surf, SDL_PixelFormat *form, int x, int
return *((uint32_t*) bytes);
}
#endif // MKXPZ_RETRO
Color Bitmap::getPixel(int x, int y) const
{
@ -2077,6 +2081,7 @@ static std::string fixupString(const char *str)
return s;
}
#ifndef MKXPZ_RETRO
static void applyShadow(SDL_Surface *&in, const SDL_PixelFormat &fm, const SDL_Color &c)
{
SDL_Surface *out = SDL_CreateRGBSurface
@ -2163,6 +2168,7 @@ static void applyShadow(SDL_Surface *&in, const SDL_PixelFormat &fm, const SDL_C
SDL_FreeSurface(in);
in = out;
}
#endif // MKXPZ_RETRO
#ifdef MKXPZ_RETRO
IntRect Bitmap::textRect(const char *str)

View file

@ -26,7 +26,16 @@
#include "gl-util.h"
#include "vertex.h"
#include <SDL_surface.h>
#ifdef MKXPZ_RETRO
struct SDL_Surface
{
int w;
int h;
void *pixels;
};
#else
# include <SDL_surface.h>
#endif // MKXPZ_RETRO
namespace GLMeta
{

View file

@ -27,8 +27,6 @@
#include "shader.h"
#include "sharedstate.h"
#include <SDL_rect.h>
static void applyBool(GLenum state, bool mode) {
mode ? gl.Enable(state) : gl.Disable(state);
}

View file

@ -41,8 +41,6 @@
# define M_PI 3.14159265358979323846
#endif
#include <SDL_rect.h>
#include "sigslot/signal.hpp"
struct SpritePrivate

View file

@ -47,8 +47,6 @@
#include <algorithm>
#include <vector>
#include <SDL_surface.h>
extern const StaticRect autotileRects[];
typedef std::vector<SVertex> SVVector;

View file

@ -24,7 +24,17 @@
#include "util.h"
#include <SDL_rect.h>
#ifdef MKXPZ_RETRO
struct SDL_Rect
{
int x;
int y;
int w;
int h;
};
#else
# include <SDL_rect.h>
#endif // MKXPZ_RETRO
struct Vec2
{

View file

@ -27,7 +27,17 @@
#include "serializable.h"
#include "etc-internal.h"
#ifdef MKXPZ_RETRO
struct SDL_Color
{
uint8_t r;
uint8_t g;
uint8_t b;
uint8_t a;
};
#else
struct SDL_Color;
#endif // MKXPZ_RETRO
enum BlendType
{

View file

@ -22,11 +22,13 @@
#ifndef EVENTTHREAD_H
#define EVENTTHREAD_H
#include <SDL_scancode.h>
#include <SDL_mouse.h>
#include <SDL_mutex.h>
#include <SDL_atomic.h>
#include <SDL_gamecontroller.h>
#ifndef MKXPZ_RETRO
# include <SDL_scancode.h>
# include <SDL_mouse.h>
# include <SDL_mutex.h>
# include <SDL_atomic.h>
# include <SDL_gamecontroller.h>
#endif // MKXPZ_RETRO
#include <string>
@ -35,7 +37,9 @@
#include "config.h"
#include "etc-internal.h"
#include "sdl-util.h"
#include "keybindings.h"
#ifndef MKXPZ_RETRO
# include "keybindings.h"
#endif // MKXPZ_RETRO
#ifdef MKXPZ_RETRO
# include <alc.h>
@ -50,6 +54,7 @@ union SDL_Event;
class EventThread
{
#ifndef MKXPZ_RETRO
public:
struct ControllerState {
@ -143,13 +148,16 @@ private:
{
AtomicFlag sendUpdates;
} fps;
#endif // MKXPZ_RETRO
};
#ifndef MKXPZ_RETRO
/* Used to asynchronously inform the RGSS thread
* about certain value changes */
template<typename T>
struct UnidirMessage
{
#ifndef MKXPZ_RETRO
UnidirMessage()
: mutex(SDL_CreateMutex()),
current(T())
@ -199,6 +207,7 @@ private:
SDL_mutex *mutex;
mutable AtomicFlag changed;
T current;
#endif // MKXPZ_RETRO
};
struct SyncPoint
@ -233,6 +242,7 @@ private:
Util reply;
Util secondSync;
};
#endif // MKXPZ_RETRO
struct RGSSThreadData
{
@ -252,17 +262,22 @@ struct RGSSThreadData
AtomicFlag rqWindowAdjust;
EventThread *ethread;
#ifndef MKXPZ_RETRO
UnidirMessage<Vec2i> windowSizeMsg;
UnidirMessage<Vec2i> drawableSizeMsg;
UnidirMessage<BDescVec> bindingUpdateMsg;
SyncPoint syncPoint;
#endif // MKXPZ_RETRO
const char *argv0;
SDL_Window *window;
ALCdevice *alcDev;
#ifndef MKXPZ_RETRO
SDL_GLContext glContext;
#endif // MKXPZ_RETRO
Vec2 sizeResoRatio;
Vec2i screenOffset;
@ -279,8 +294,13 @@ struct RGSSThreadData
ALCdevice *alcDev,
int refreshRate,
int scalingFactor,
#ifdef MKXPZ_RETRO
const Config& newconf
#else
const Config& newconf,
SDL_GLContext ctx)
SDL_GLContext ctx
#endif // MKXPZ_RETRO
)
: ethread(ethread),
argv0(argv0),
window(window),
@ -288,8 +308,12 @@ struct RGSSThreadData
sizeResoRatio(1, 1),
refreshRate(refreshRate),
scale(scalingFactor),
#ifdef MKXPZ_RETRO
config(newconf)
#else
config(newconf),
glContext(ctx)
#endif // MKXPZ_RETRO
{
rqResetFinish.set();
}

View file

@ -277,7 +277,9 @@ static void strTolower(std::string &str) {
str[i] = tolower(str[i]);
}
#ifndef MKXPZ_RETRO
const Uint32 SDL_RWOPS_PHYSFS = SDL_RWOPS_UNKNOWN + 10;
#endif // MKXPZ_RETRO
struct FileSystemPrivate {
/* Maps: lower case full filepath,
@ -700,6 +702,7 @@ void FileSystem::openRead(OpenHandler &handler, const char *filename) {
throw Exception(Exception::NoFileError, "%s", filename);
}
#ifndef MKXPZ_RETRO
void FileSystem::openReadRaw(SDL_RWops &ops, const char *filename,
bool freeOnClose) {
@ -708,12 +711,11 @@ void FileSystem::openReadRaw(SDL_RWops &ops, const char *filename,
if (!handle)
throw Exception(Exception::NoFileError, "%s", filename);
#ifndef MKXPZ_RETRO
initReadOps(handle, ops, freeOnClose);
#endif // MKXPZ_RETRO
return;
}
#endif // MKXPZ_RETRO
#ifdef MKXPZ_RETRO
static std::string normalizePath(const char *path, bool preferred, bool absolute) {

View file

@ -24,9 +24,10 @@
#ifdef MKXPZ_RETRO
# include <memory>
#else
# include <SDL_rwops.h>
#endif // MKXPZ_RETRO
#include <physfs.h>
#include <SDL_rwops.h>
#include <string>
#ifndef MKXPZ_RETRO
@ -128,10 +129,12 @@ public:
void openRead(OpenHandler &handler,
const char *filename);
#ifndef MKXPZ_RETRO
/* Circumvents extension supplementing */
void openReadRaw(SDL_RWops &ops,
const char *filename,
bool freeOnClose = false);
#endif // MKXPZ_RETRO
std::string normalize(const char *pathname, bool preferred, bool absolute);
@ -146,6 +149,8 @@ private:
FileSystemPrivate *p;
};
#ifndef MKXPZ_RETRO
extern const Uint32 SDL_RWOPS_PHYSFS;
#endif // MKXPZ_RETRO
#endif // FILESYSTEM_H

View file

@ -1,9 +1,11 @@
#ifndef SDLUTIL_H
#define SDLUTIL_H
#include <SDL_atomic.h>
#include <SDL_thread.h>
#include <SDL_rwops.h>
#ifndef MKXPZ_RETRO
# include <SDL_atomic.h>
# include <SDL_thread.h>
# include <SDL_rwops.h>
#endif // MKXPZ_RETRO
#include <cstring>
#include <iostream>
@ -76,7 +78,6 @@ struct AtomicFlag
private:
mutable SDL_atomic_t atom;
};
#endif // MKXPZ_RETRO
template<class C, void (C::*func)()>
int __sdlThreadFun(void *obj)
@ -201,5 +202,6 @@ private:
SDLRWBuf<> buf;
std::istream s;
};
#endif // MKXPZ_RETRO
#endif // SDLUTIL_H

View file

@ -1,2 +0,0 @@
project('sdl2-headers', 'c', meson_version: '>=1.3.0')
sdl2_headers = declare_dependency(include_directories: 'include')

View file

@ -1,5 +0,0 @@
[wrap-git]
url = https://github.com/libsdl-org/SDL
revision = release-2.30.11
depth = 1
patch_directory = sdl2-headers