checkpoint

This commit is contained in:
Kylie C 2025-09-02 22:28:10 -04:00
parent d8fe5f960f
commit 6b177afbd6
10 changed files with 277 additions and 2 deletions

120
3rdparty/sdl3-shim/SDL3/SDL.h vendored Normal file
View File

@ -0,0 +1,120 @@
#pragma once
// https://wiki.libsdl.org/SDL3/README-migration#sdl_stdinch
#define SDL_bool bool
#include <SDL2/SDL.h>
#include "SDL_events.h"
#include "SDL_gamepad.h"
#include "SDL_iostream.h"
#include "SDL_keyboard.h"
#include "SDL_mutex.h"
#include "SDL_pixels.h"
#include "SDL_surface.h"
#include "SDL_timer.h"
// https://wiki.libsdl.org/SDL3/README-migration#sdl_logh
#define SDL_LogTrace SDL_LogVerbose
// https://wiki.libsdl.org/SDL3/README-migration#sdl_videoh
typedef Uint32 SDL_DisplayID;
inline SDL_DisplayID SDL_GetPrimaryDisplay()
{
return 0;
}
// Modified from 83bb0f9105922fd49282f0b931f7873a71877ac8 SDL_video.c#L1331
inline SDL_DisplayMode** SDL_GetFullscreenDisplayModes(SDL_DisplayID displayID, int *count)
{
int i;
if (count) *count = 0;
const int num_modes = SDL_GetNumDisplayModes(displayID);
SDL_DisplayMode** result = static_cast<SDL_DisplayMode**>(SDL_malloc(sizeof(SDL_DisplayMode*) * num_modes));
if (result) {
SDL_DisplayMode *modes = (SDL_DisplayMode *)((Uint8 *)result + ((num_modes + 1) * sizeof(*result)));
for (i = 0; i < num_modes; ++i) {
if (SDL_GetDisplayMode(displayID, i, &modes[i]) == 0) {
result[i] = modes++;
}
}
result[i] = NULL;
if (count) {
*count = num_modes;
}
SDL_free(modes);
} else {
if (count) {
*count = 0;
}
}
return result;
}
inline SDL_DisplayMode* SDL_GetCurrentDisplayMode(SDL_DisplayID displayID)
{
SDL_DisplayMode* mode = nullptr;
SDL_GetCurrentDisplayMode(displayID, mode);
return mode;
}
#define SDL_GetWindowSize(...) (SDL_GetWindowSize(__VA_ARGS__), true )
// https://wiki.libsdl.org/SDL3/README-migration#sdl_videoh
#define SDL_GL_DestroyContext SDL_GL_DeleteContext
// https://wiki.libsdl.org/SDL3/README-migration#sdl_renderh
// hardcode -1 as all uses are NULL or -1 (hacks out failure)
#define SDL_CreateRenderer(window, name) SDL_CreateRenderer(window, -1, 0)
#define SDL_RenderTexture SDL_RenderCopyF
// https://wiki.libsdl.org/SDL3/README-migration#sdl_haptich
// SDL_MouseID/SDL_KeyboardID are new
typedef int SDL_MouseID;
typedef int SDL_KeyboardID;
#define SDL_GetKeyboardState (const bool*)SDL_GetKeyboardState
typedef int SDL_HapticID;
#define SDL_CloseHaptic SDL_HapticClose
#define SDL_OpenHaptic SDL_HapticOpen
#define SDL_OpenHapticFromJoystick SDL_HapticOpenFromJoystick
#define SDL_OpenHapticFromMouse SDL_HapticOpenFromMouse
#define SDL_InitHapticRumble SDL_HapticRumbleInit
#define SDL_PlayHapticRumble SDL_HapticRumblePlay
#define SDL_GetHapticID SDL_HapticIndex
// Modified from cc9937201e421ec55b12ad3f07ff2268f15096e8 SDL_haptic.c#L150
inline SDL_HapticID* SDL_GetHaptics(int *count)
{
const int num_haptics = SDL_NumHaptics();
if (count) *count = 0;
SDL_HapticID* haptics = static_cast<SDL_HapticID*>(SDL_malloc((num_haptics + 1) * sizeof(*haptics)));
if (haptics) {
if (count) {
*count = num_haptics;
}
int haptic_index = 0;
for (int device_index = 0; device_index < num_haptics; ++device_index) {
SDL_Haptic* haptic = SDL_HapticOpen(device_index);
if (haptic) {
haptics[haptic_index] = SDL_GetHapticID(haptic);
SDL_HapticClose(haptic);
++haptic_index;
}
}
haptics[haptic_index] = 0;
} else { if (count) *count = 0; }
return haptics;
}

18
3rdparty/sdl3-shim/SDL3/SDL_events.h vendored Normal file
View File

@ -0,0 +1,18 @@
#pragma once
#include <SDL2/SDL_events.h>
// https://wiki.libsdl.org/SDL3/README-migration#sdl_eventsh
#define SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED SDL_WINDOWEVENT_SIZE_CHANGED
#define SDL_EVENT_MOUSE_BUTTON_DOWN SDL_MOUSEBUTTONDOWN
#define SDL_EVENT_MOUSE_BUTTON_UP SDL_MOUSEBUTTONUP
#define SDL_EVENT_MOUSE_MOTION SDL_MOUSEMOTION
#define SDL_EVENT_FINGER_MOTION SDL_FINGERMOTION
#define SDL_EVENT_FINGER_DOWN SDL_FINGERDOWN
#define SDL_EVENT_FINGER_UP SDL_FINGERUP
#define SDL_EVENT_FINGER_CANCELED 0
#define SDL_EVENT_QUIT SDL_QUIT

7
3rdparty/sdl3-shim/SDL3/SDL_gamepad.h vendored Normal file
View File

@ -0,0 +1,7 @@
#pragma once
#include <SDL_gamecontroller.h>
// https://wiki.libsdl.org/SDL3/README-migration#sdl_gamecontrollerh
#define SDL_Gamepad SDL_GameController

49
3rdparty/sdl3-shim/SDL3/SDL_iostream.h vendored Normal file
View File

@ -0,0 +1,49 @@
#pragma once
#include <SDL2/SDL_rwops.h>
// https://wiki.libsdl.org/SDL3/README-migration#sdl_rwopsh
#define SDL_IOStream SDL_RWops
typedef int SDL_IOWhence;
#define SDL_IO_SEEK_SET RW_SEEK_SET
#define SDL_IO_SEEK_CUR RW_SEEK_CUR
#define SDL_IO_SEEK_END RW_SEEK_END
// #define SDL_IOFromConstMem SDL_RWFromConstMem
#define SDL_IOFromFile SDL_RWFromFile
#define SDL_IOFromMem SDL_RWFromMem
#define SDL_CloseIO SDL_RWclose
#define SDL_ReadIO(ctx, ptr, size) SDL_RWread(ctx, ptr, 1, size)
#define SDL_SeekIO SDL_RWseek
#define SDL_GetIOSize SDL_RWsize
#define SDL_TellIO SDL_RWtell
#define SDL_WriteIO(ctx, ptr, size) SDL_RWwrite(ctx, ptr, 1, size)
// #define SDL_ReadU16BE SDL_ReadBE16
// #define SDL_ReadU32BE SDL_ReadBE32
// #define SDL_ReadU64BE SDL_ReadBE64
// #define SDL_ReadU16LE SDL_ReadLE16
// #define SDL_ReadU32LE SDL_ReadLE32
// #define SDL_ReadU64LE SDL_ReadLE64
// #define SDL_WriteU16BE SDL_WriteBE16
// #define SDL_WriteU32BE SDL_WriteBE32
// #define SDL_WriteU64BE SDL_WriteBE64
// #define SDL_WriteU16LE SDL_WriteLE16
// #define SDL_WriteU32LE SDL_WriteLE32
// #define SDL_WriteU64LE SDL_WriteLE64
// FIXME: If Write/Read fail SDL_GetIOStatus is not aware.
typedef enum SDL_IOStatus
{
SDL_IO_STATUS_READY,
SDL_IO_STATUS_ERROR,
} SDL_IOStatus;
inline SDL_IOStatus SDL_GetIOStatus(SDL_RWops *context)
{
if (!context) {
return SDL_IO_STATUS_ERROR;
}
return SDL_IO_STATUS_READY;
}

11
3rdparty/sdl3-shim/SDL3/SDL_mutex.h vendored Normal file
View File

@ -0,0 +1,11 @@
#pragma once
#include <SDL2/SDL_mutex.h>
// https://wiki.libsdl.org/SDL3/README-migration#sdl_mutexh
#define SDL_Mutex SDL_mutex
#define SDL_Semaphore SDL_sem
#define SDL_WaitSemaphore SDL_SemWait

24
3rdparty/sdl3-shim/SDL3/SDL_pixels.h vendored Normal file
View File

@ -0,0 +1,24 @@
#pragma once
#include <SDL2/SDL_pixels.h>
// https://wiki.libsdl.org/SDL3/README-migration#sdl_pixelsh
#define bits_per_pixel BitsPerPixel
typedef SDL_PixelFormat SDL2_PixelFormat;
#define SDL_PixelFormatDetails SDL2_PixelFormat
#define SDL_PixelFormat SDL_PixelFormatEnum
#define SDL_GetRGBA(pixel, format, palette, r,g,b,a) SDL_GetRGBA(pixel, format, r,g,b,a)
#define SDL_MapRGBA(format, palette, r,g,b,a) SDL_MapRGBA(format, r,g,b,a)
#define SDL_GetRGB(pixel, format, palette, r,g,b) SDL_GetRGB(pixel, format, r,g,b)
#define SDL_MapRGB(format, palette, r,g,b) SDL_MapRGB(format, r,g,b)
#define SDL_GetPixelFormatDetails SDL_AllocFormat
#define SDL_CreatePalette SDL_AllocPalette
#define SDL_DestroyPalette SDL_FreePalette
#define SDL_GetPixelFormatForMasks (SDL_PixelFormat)SDL_MasksToPixelFormatEnum
#define SDL_GetSurfacePalette(surface) (nullptr)

34
3rdparty/sdl3-shim/SDL3/SDL_surface.h vendored Normal file
View File

@ -0,0 +1,34 @@
#pragma once
#include <SDL2/SDL_surface.h>
#include "SDL_pixels.h"
// https://wiki.libsdl.org/SDL3/README-migration#sdl_surfaceh
struct SDL_SurfaceShim : SDL_Surface {
SDL_PixelFormat format;
explicit SDL_SurfaceShim(const SDL_Surface* s)
: SDL_Surface(*s), format(static_cast<SDL_PixelFormat>(s->format->format)) {}
};
#define SDL_Surface SDL_SurfaceShim
#define SDL_FillSurfaceRect(...) (SDL_FillRect(__VA_ARGS__) == 0)
// #define SDL_ConvertSurface(...) SDL_ConvertSurface(__VA_ARGS__, 0)
#define SDL_DestroySurface SDL_FreeSurface
#define SDL_CreateSurface(width, height, format) (SDL_Surface*)SDL_CreateRGBSurfaceWithFormat(0 , width, height, SDL_BITSPERPIXEL(format) ,format)
inline SDL_Surface* SDL_ConvertSurface(SDL_Surface* surface, SDL_PixelFormat format)
{
const SDL_PixelFormatDetails* formatDetails = SDL_AllocFormat(format);
return static_cast<SDL_Surface*>(SDL_ConvertSurface(surface, formatDetails, 0));
};
#define SDL_SCALEMODE_LINEAR SDL_ScaleModeLinear
#define SDL_SCALEMODE_NEAREST SDL_ScaleModeNearest
#define SDL_BlitSurfaceScaled(surface, rect, destSurface, destRect, scaleMode) (SDL_BlitScaled(surface, rect, destSurface, destRect) == 0)
#define SDL_SetSurfaceColorKey SDL_SetColorKey

11
3rdparty/sdl3-shim/SDL3/SDL_timer.h vendored Normal file
View File

@ -0,0 +1,11 @@
#pragma once
#include <SDL2/SDL_timer.h>
// https://wiki.libsdl.org/SDL3/README-migration#sdl_timerh
// https://wiki.libsdl.org/SDL3/README-migration#sdl_timerh | SDL_GetTicksNS()
#define SDL_GetTicksNS SDL_GetTicks
// time is in miliseconds not nanoseconds
#define SDL_NS_TO_MS(MS) (MS)

View File

@ -8,6 +8,7 @@
#include "mxpresenter.h"
#include "mxqueue.h"
#include <SDL3/SDL.h>
#include <SDL3/SDL_haptic.h>
#include <SDL3/SDL_joystick.h>
#include <SDL3/SDL_keyboard.h>

View File

@ -152,7 +152,7 @@ HRESULT DirectDrawImpl::EnumDisplayModes(
#ifdef MINIWIN_PIXELFORMAT
format = MINIWIN_PIXELFORMAT;
#else
format = modes[i]->format;
format = static_cast<SDL_PixelFormat>(modes[i]->format);
#endif
const SDL_PixelFormatDetails* details = SDL_GetPixelFormatDetails(format);
@ -245,7 +245,7 @@ HRESULT DirectDrawImpl::GetDisplayMode(LPDDSURFACEDESC lpDDSurfaceDesc)
#ifdef MINIWIN_PIXELFORMAT
format = MINIWIN_PIXELFORMAT;
#else
format = mode->format;
format = static_cast<SDL_PixelFormat>(mode->format);
#endif
const SDL_PixelFormatDetails* details = SDL_GetPixelFormatDetails(format);