Skip to content

Commit

Permalink
Replace all SDL.h includes with SDLmzx.h (formerly compat_sdl.h).
Browse files Browse the repository at this point in the history
  • Loading branch information
AliceLR committed Jan 19, 2024
1 parent 7be09aa commit 3e07841
Show file tree
Hide file tree
Showing 26 changed files with 50 additions and 66 deletions.
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
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
4 changes: 4 additions & 0 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>
#ifdef _WIN32
#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
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
2 changes: 1 addition & 1 deletion src/editor/clipboard_x11.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include "clipboard.h"

#if defined(CONFIG_SDL)
#include "../compat_sdl.h"
#include "../SDLmzx.h"
#include "../render_sdl.h"
#endif

Expand Down
3 changes: 1 addition & 2 deletions src/event_sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include "SDLmzx.h"
#include "configure.h"
#include "event.h"
#include "graphics.h"
#include "compat_sdl.h"
#include "render_sdl.h"
#include "util.h"

#include <SDL.h>
#include <ctype.h>
#include <stdint.h>
#include <stdlib.h>
Expand Down
2 changes: 1 addition & 1 deletion src/graphics.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
#endif

#ifdef CONFIG_SDL
#include "compat_sdl.h"
#include "SDLmzx.h"
#include "render_sdl.h"
#endif // CONFIG_SDL

Expand Down
2 changes: 1 addition & 1 deletion src/network/Socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ int Socket::poll(struct pollfd *fds, unsigned int nfds, int timeout_ms)
*/

// For LoadObject/LoadFunction
#include <SDL.h>
#include "../SDLmzx.h"

static struct
{
Expand Down
2 changes: 1 addition & 1 deletion src/network/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@

#include "HTTPHost.hpp"

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

#include <SDL.h>
#include <assert.h>

#define INBOUND_PORT 5656
Expand Down
3 changes: 1 addition & 2 deletions src/old/render_sdl2accel.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
// a significant FPS drop at speed 2. On top of that even just drawing chars to
// a screen is much slower than MZX's software-based renderers right now.

#include <SDL.h>

#include "SDLmzx.h"
#include "graphics.h"
#include "platform.h"
#include "render.h"
Expand Down
20 changes: 3 additions & 17 deletions src/platform_endian.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* MegaZeux
*
* Copyright (C) 2008 Alistair John Strachan <[email protected]
* Copyright (C) 2020, 2024 Alice Rowan <[email protected]>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
Expand All @@ -20,26 +21,13 @@
#ifndef __ENDIAN_H
#define __ENDIAN_H

/* If SDL is available, include the header and use SDL's configured
* endianness. If it's not available, use GCC/clang or a list of architectures
* (both checks borrowed from SDL) to determine the endianness.
/* Use GCC/clang or a list of architectures (both checks borrowed from SDL) to
* determine the endianness. If SDL is enabled, platform_sdl.c will check this.
*/

#define PLATFORM_LIL_ENDIAN 0x1234
#define PLATFORM_BIG_ENDIAN 0x4321

#if defined(CONFIG_SDL) && !defined(SKIP_SDL)

#include <SDL_endian.h>

#if SDL_BYTEORDER == SDL_BIG_ENDIAN
#define PLATFORM_BYTE_ORDER PLATFORM_BIG_ENDIAN
#else
#define PLATFORM_BYTE_ORDER PLATFORM_LIL_ENDIAN
#endif

#else // !CONFIG_SDL

#if defined(__BIG_ENDIAN__)
#define PLATFORM_BYTE_ORDER PLATFORM_BIG_ENDIAN
#elif defined(__LITTLE_ENDIAN__)
Expand All @@ -64,8 +52,6 @@
#define PLATFORM_BYTE_ORDER PLATFORM_LIL_ENDIAN
#endif

#endif // CONFIG_SDL

/* ModPlug and XMP both use this name to find out about endianness. It's not
* too bad to pollute our namespace with it, so just do so here.
*/
Expand Down
14 changes: 11 additions & 3 deletions src/platform_sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include "compat.h"
#include "SDLmzx.h"
#include "platform.h"
#include "util.h"

#include <SDL.h>

#ifdef CONFIG_PSP
#include <psppower.h>
#endif
Expand All @@ -38,6 +36,14 @@
#include <fat.h>
#endif

/* Verify that SDL's endianness matches what platform_endian.h claims... */
#if SDL_BYTEORDER == SDL_BIG_ENDIAN && PLATFORM_BYTE_ORDER != PLATFORM_BIG_ENDIAN
#error Endian mismatch: SDL detected big, but MZX detected little. Report this!
#endif
#if SDL_BYTEORDER == SDL_LIL_ENDIAN && PLATFORM_BYTE_ORDER != PLATFORM_LIL_ENDIAN
#error Endian mismatch: SDL detected little, but MZX detected big. Report this!
#endif

#ifdef __EMSCRIPTEN__
#include <emscripten.h>
void delay(uint32_t ms)
Expand All @@ -61,7 +67,9 @@ uint64_t get_ticks(void)
}

#ifdef __WIN32__
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <windows.h>

/**
Expand Down
4 changes: 3 additions & 1 deletion src/platform_time.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@
#endif

#ifdef _WIN32
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <windows.h>
#include <SDL.h>
#include "SDLmzx.h"

#define WINDOWS_TO_UNIX_SECONDS 11644473600LL
#define WINDOWS_TO_UNIX_100NS 10000000LL
Expand Down
3 changes: 1 addition & 2 deletions src/render_gp2x.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include "SDLmzx.h"
#include "platform.h"
#include "graphics.h"
#include "render.h"
Expand All @@ -26,8 +27,6 @@
#include <stdlib.h>
#include <string.h>

#include <SDL.h>

struct gp2x_render_data
{
struct sdl_render_data sdl;
Expand Down
4 changes: 1 addition & 3 deletions src/render_sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include "compat_sdl.h"
#include "SDLmzx.h"
#include "render_sdl.h"
#include "util.h"

#include <limits.h>

#include <SDL.h>

CORE_LIBSPEC Uint32 sdl_window_id;

#if SDL_VERSION_ATLEAST(2,0,0)
Expand Down
3 changes: 1 addition & 2 deletions src/render_sdl.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@

__M_BEGIN_DECLS

#include "SDLmzx.h"
#include "graphics.h"

#include <SDL.h>

struct sdl_render_data
{
#if SDL_VERSION_ATLEAST(2,0,0)
Expand Down
2 changes: 1 addition & 1 deletion src/render_soft.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include "util.h"

#ifdef CONFIG_SDL
#include <SDL.h>
#include "SDLmzx.h"
#include "render_sdl.h"
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/render_softscale.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
* nearest or linear scaling based on the scaling ratio and window size.
*/

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

#include "SDLmzx.h"
#include "graphics.h"
#include "render.h"
#include "render_layer.h"
Expand Down
Loading

0 comments on commit 3e07841

Please sign in to comment.