Skip to content

Commit

Permalink
Preparation for SDL3 support. (#418)
Browse files Browse the repository at this point in the history
* CONFIG_SDL is now defined to the SDL major version in config.h.
  This should NEVER be used unless it's impossible to use
  SDL_VERSION_ATLEAST instead. This exists mainly for SDL3's new
  method of including headers (SDL3/SDL.h instead of SDL.h).
* Replaced SDL_SysWMinfo_GetWND with SDL_GetWindowProperty_HWND to
  isolate the related SDL_SysWMinfo usage inside of compat_sdl.h.
* Removed SDL_SysWMmsg_GetXEvent as it was only used in the X11
  clipboard handler. The SDL_syswm.h functionality in the X11
  clipboard handler is difficult to generalize in non-SDL_syswm.h
  terms for compat_sdl.h, so it's been left in place.
* Separated all SDL code in the X11 clipboard handler from the X11
  code to make it easier to write the corresponding SDL3 functions.
* Replace all SDL.h includes with SDLmzx.h (formerly compat_sdl.h).
  • Loading branch information
AliceLR authored Jan 19, 2024
1 parent 88a20a3 commit 7dad36e
Show file tree
Hide file tree
Showing 30 changed files with 138 additions and 135 deletions.
2 changes: 1 addition & 1 deletion arch/msvc/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#define CONFDIR "./"
#define CONFFILE "config.txt"
#define SHAREDIR "./"
#define CONFIG_SDL
#define CONFIG_SDL 2
#define CONFIG_EDITOR
#define CONFIG_HELPSYS
#define CONFIG_RENDER_SOFT
Expand Down
8 changes: 4 additions & 4 deletions arch/xcode/MegaZeux.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
BF6058EC216B3725001B738C /* core.h in Headers */ = {isa = PBXBuildFile; fileRef = BF6058C9216B3722001B738C /* core.h */; };
BF6058ED216B3725001B738C /* game_update_board.c in Sources */ = {isa = PBXBuildFile; fileRef = BF6058CA216B3722001B738C /* game_update_board.c */; };
BF6058EE216B3725001B738C /* world_struct.h in Headers */ = {isa = PBXBuildFile; fileRef = BF6058CB216B3722001B738C /* world_struct.h */; };
BF6058EF216B3725001B738C /* compat_sdl.h in Headers */ = {isa = PBXBuildFile; fileRef = BF6058CC216B3722001B738C /* compat_sdl.h */; };
BF6058EF216B3725001B738C /* SDLmzx.h in Headers */ = {isa = PBXBuildFile; fileRef = BF6058CC216B3722001B738C /* SDLmzx.h */; };
BF6058F0216B3725001B738C /* renderers.h in Headers */ = {isa = PBXBuildFile; fileRef = BF6058CD216B3723001B738C /* renderers.h */; };
BF6058F1216B3725001B738C /* caption.c in Sources */ = {isa = PBXBuildFile; fileRef = BF6058CE216B3723001B738C /* caption.c */; };
BF6058F2216B3725001B738C /* game_ops.c in Sources */ = {isa = PBXBuildFile; fileRef = BF6058CF216B3723001B738C /* game_ops.c */; };
Expand Down Expand Up @@ -448,7 +448,7 @@
BF6058C9216B3722001B738C /* core.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = core.h; path = ../../src/core.h; sourceTree = "<group>"; };
BF6058CA216B3722001B738C /* game_update_board.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = game_update_board.c; path = ../../src/game_update_board.c; sourceTree = "<group>"; };
BF6058CB216B3722001B738C /* world_struct.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = world_struct.h; path = ../../src/world_struct.h; sourceTree = "<group>"; };
BF6058CC216B3722001B738C /* compat_sdl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = compat_sdl.h; path = ../../src/compat_sdl.h; sourceTree = "<group>"; };
BF6058CC216B3722001B738C /* SDLmzx.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDLmzx.h; path = ../../src/SDLmzx.h; sourceTree = "<group>"; };
BF6058CD216B3723001B738C /* renderers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = renderers.h; path = ../../src/renderers.h; sourceTree = "<group>"; };
BF6058CE216B3723001B738C /* caption.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = caption.c; path = ../../src/caption.c; sourceTree = "<group>"; };
BF6058CF216B3723001B738C /* game_ops.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = game_ops.c; path = ../../src/game_ops.c; sourceTree = "<group>"; };
Expand Down Expand Up @@ -885,7 +885,7 @@
BF6058CE216B3723001B738C /* caption.c */,
BF6058C8216B3721001B738C /* caption.h */,
BF6058BD216B3720001B738C /* compat.h */,
BF6058CC216B3722001B738C /* compat_sdl.h */,
BF6058CC216B3722001B738C /* SDLmzx.h */,
BFFF164E1FCDC64800BDEC58 /* configure.c */,
BFFF165A1FCDC64A00BDEC58 /* configure.h */,
BF6058D7216B3724001B738C /* const.h */,
Expand Down Expand Up @@ -1151,7 +1151,7 @@
buildActionMask = 2147483647;
files = (
BF6058FB216B3725001B738C /* keysym.h in Headers */,
BF6058EF216B3725001B738C /* compat_sdl.h in Headers */,
BF6058EF216B3725001B738C /* SDLmzx.h in Headers */,
BFFF17CE1FCDCCF300BDEC58 /* mdataio.h in Headers */,
BFD5B0422465AFAE00BC91E9 /* zip_deflate64.h in Headers */,
BF6058EA216B3725001B738C /* settings.h in Headers */,
Expand Down
2 changes: 1 addition & 1 deletion arch/xcode/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#define USERCONFFILE ".megazeux-config"
#define SHAREDIR "../Resources"
#define LICENSEDIR "../Resources"
#define CONFIG_SDL
#define CONFIG_SDL 2
#define CONFIG_EDITOR
#define CONFIG_HELPSYS
#define CONFIG_RENDER_SOFT
Expand Down
2 changes: 1 addition & 1 deletion config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ else
SDL="2"
fi
echo "Enabling SDL $SDL.x."
echo "#define CONFIG_SDL" >> src/config.h
echo "#define CONFIG_SDL $SDL" >> src/config.h
echo "BUILD_SDL=$SDL" >> platform.inc
fi

Expand Down
4 changes: 4 additions & 0 deletions docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,17 @@ USERS

DEVELOPERS

+ Renamed "compat_sdl.h" to "SDLmzx.h". This header is now used
to abstract ALL trivial includes of SDL headers. This makes
supporting the future release of SDL 3 cleaner.
+ The version of SDL to build with is now determined by the
config.sh options:
--enable-sdl (enables the default SDL version, usually 2);
--enable-sdl2 (enables SDL 2.x);
--enable-sdl1 (enables SDL 1.2.x);
--disable-sdl (disables SDL).
For compatibility, "--disable-libsdl2" is still recognized.
+ Added SDL 2 and SDL 1.2 support to the 3DS port. (asie)
+ -Og is now the default debug optimization level (was -O0).
+ Added --enable-lto to enable link-time optimizations.
+ The sanitizer config.sh options can now be used with release
Expand Down
42 changes: 20 additions & 22 deletions src/compat_sdl.h → src/SDLmzx.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ __M_BEGIN_DECLS
#if defined(CONFIG_SDL)

#include <SDL.h>
#if defined(_WIN32) || defined(CONFIG_X11)
#include <SDL_syswm.h>
#endif

#if !SDL_VERSION_ATLEAST(2,0,0)

Expand All @@ -40,6 +42,8 @@ __M_BEGIN_DECLS
// Data types

typedef SDLKey SDL_Keycode;
typedef int (*SDL_ThreadFunction)(void *);
typedef Uint32 SDL_threadID;
// Use a macro because sdl1.2-compat typedefs SDL_Window...
#define SDL_Window void

Expand Down Expand Up @@ -67,11 +71,13 @@ typedef SDLKey SDL_Keycode;

#define SDL_SetEventFilter(filter, userdata) SDL_SetEventFilter(filter)

#ifdef CONFIG_X11
static inline SDL_bool SDL_GetWindowWMInfo(SDL_Window *window,
SDL_SysWMinfo *info)
{
return SDL_GetWMInfo(info) == 1 ? SDL_TRUE : SDL_FALSE;
}
#endif

static inline SDL_Window *SDL_GetWindowFromID(Uint32 id)
{
Expand Down Expand Up @@ -121,35 +127,27 @@ static inline int SDL_GL_SetSwapInterval(int interval)
}
#endif

#ifdef CONFIG_X11
static inline XEvent *SDL_SysWMmsg_GetXEvent(SDL_SysWMmsg *msg)
#ifdef _WIN32
static inline HWND SDL_GetWindowProperty_HWND(SDL_Window *window)
{
return &msg->event.xevent;
SDL_SysWMinfo info;
SDL_VERSION(&info.version);
SDL_GetWindowWMInfo(window, &info);
return info.window;
}
#endif /* CONFIG_X11 */

#if defined(CONFIG_ICON) && defined(__WIN32__)
static inline HWND SDL_SysWMinfo_GetWND(SDL_SysWMinfo *info)
{
return info->window;
}
#endif /* CONFIG_ICON && __WIN32__ */
#endif /* _WIN32 */

#else /* SDL_VERSION_ATLEAST(2,0,0) */

#ifdef CONFIG_X11
static inline XEvent *SDL_SysWMmsg_GetXEvent(SDL_SysWMmsg *msg)
{
return &msg->msg.x11.event;
}
#endif /* CONFIG_X11 */

#if defined(CONFIG_ICON) && defined(__WIN32__)
static inline HWND SDL_SysWMinfo_GetWND(SDL_SysWMinfo *info)
#ifdef _WIN32
static inline HWND SDL_GetWindowProperty_HWND(SDL_Window *window)
{
return info->info.win.window;
SDL_SysWMinfo info;
SDL_VERSION(&info.version);
SDL_GetWindowWMInfo(window, &info);
return info.info.win.window;
}
#endif /* CONFIG_ICON && __WIN32__ */
#endif /* _WIN32 */

#endif /* SDL_VERSION_ATLEAST(2,0,0) */

Expand Down
2 changes: 1 addition & 1 deletion src/about.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <zlib.h>

#ifdef CONFIG_SDL
#include <SDL.h>
#include "SDLmzx.h"
#endif
#ifdef CONFIG_XMP
#include <xmp.h>
Expand Down
2 changes: 1 addition & 1 deletion src/audio/audio_sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
#include "audio.h"
#include "audio_struct.h"

#include "../SDLmzx.h"
#include "../util.h"

#include <SDL.h>
#include <stdlib.h>

#ifdef __EMSCRIPTEN__
Expand Down
6 changes: 1 addition & 5 deletions src/audio/audio_wav.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,11 @@
#include "ext.h"
#include "sampled_stream.h"

#include "../SDLmzx.h" // SDL WAV loader fallback
#include "../util.h"
#include "../io/path.h"
#include "../io/vio.h"

// For WAV loader fallback
#ifdef CONFIG_SDL
#include <SDL.h>
#endif

// If the WAV/SAM is larger than this, print a warning to the console.
// (Right now only do this for debug builds because a lot more games than
// anticipated use big WAVs and it could get annoying for end users.)
Expand Down
8 changes: 4 additions & 4 deletions src/audio/sampled_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ enum mixer_channels

enum mixer_volume
{
FIXED = 0,
FULL = 0,
DYNAMIC = 1
};

Expand Down Expand Up @@ -223,8 +223,8 @@ static void mixer_function(struct sampled_stream *s_src,
{
switch(volume_mode)
{
case FIXED:
mixer_function<CHANNELS, FIXED>(s_src, dest, write_len, src, volume, resample_mode);
case FULL:
mixer_function<CHANNELS, FULL>(s_src, dest, write_len, src, volume, resample_mode);
break;

case DYNAMIC:
Expand Down Expand Up @@ -323,7 +323,7 @@ void sampled_mix_data(struct sampled_stream *s_src,
resample_mode = FLAT;

if(!s_src->use_volume || volume == 256)
use_volume = FIXED;
use_volume = FULL;

if(s_src->channels < 2)
use_channels = MONO;
Expand Down
2 changes: 1 addition & 1 deletion src/configure.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#include "io/vio.h"

#ifdef CONFIG_SDL
#include <SDL_version.h>
#include "SDLmzx.h"
#endif

#define MAX_INCLUDE_DEPTH 16
Expand Down
3 changes: 1 addition & 2 deletions src/editor/clipboard_sdl2.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@

#include "clipboard.h"

#include "../SDLmzx.h"
#include "../util.h"

#include <SDL.h>

void copy_buffer_to_clipboard(char **buffer, int lines, int total_length)
{
int i;
Expand Down
Loading

0 comments on commit 7dad36e

Please sign in to comment.