Skip to content

Commit a4c9284

Browse files
first pass at move to SDL3
Also updates imgui and related addons to newest versions
1 parent 25dbfc6 commit a4c9284

File tree

269 files changed

+37138
-14577
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

269 files changed

+37138
-14577
lines changed

code/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ TARGET_LINK_LIBRARIES(code PUBLIC ${PNG_LIBS})
3939
TARGET_LINK_LIBRARIES(code PUBLIC ${JPEG_LIBS})
4040
TARGET_LINK_LIBRARIES(code PUBLIC lz4)
4141

42-
TARGET_LINK_LIBRARIES(code PUBLIC sdl2)
42+
TARGET_LINK_LIBRARIES(code PUBLIC sdl3)
4343

4444
if (FSO_BUILD_WITH_FFMPEG)
4545
TARGET_LINK_LIBRARIES(code PUBLIC ffmpeg)

code/bmpman/bmpman.cpp

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#define WIN32_LEAN_AND_MEAN
1414
#define BMPMAN_INTERNAL
1515

16+
#include "globalincs/pstypes.h"
1617
#include "anim/animplay.h"
1718
#include "anim/packunpack.h"
1819
#include "bmpman/bm_internal.h"
@@ -3397,37 +3398,18 @@ bool bm_validate_filename(const SCP_string& file, bool single_frame, bool animat
33973398
}
33983399
return false;
33993400
}
3400-
SDL_Surface* bm_to_sdl_surface(int handle) {
3401-
Assertion(bm_is_valid(handle), "%d is no valid bitmap handle!", handle);
3402-
3403-
int w;
3404-
int h;
3405-
3406-
bm_get_info(handle, &w, &h, nullptr, nullptr);
3407-
Uint32 rmask, gmask, bmask, amask;
34083401

3409-
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
3410-
rmask = 0x0000ff00;
3411-
gmask = 0x00ff0000;
3412-
bmask = 0xff000000;
3413-
amask = 0x000000ff;
3414-
#else
3415-
rmask = 0x00ff0000;
3416-
gmask = 0x0000ff00;
3417-
bmask = 0x000000ff;
3418-
amask = 0xff000000;
3419-
#endif
3402+
SDL_Surface* bm_to_sdl_surface(int handle)
3403+
{
3404+
Assertion(bm_is_valid(handle), "%d is no valid bitmap handle!", handle);
34203405

3421-
SDL_Surface* bitmapSurface = SDL_CreateRGBSurface(0, w, h, 32, rmask, gmask, bmask, amask);
3422-
if (SDL_LockSurface(bitmapSurface) < 0) {
3423-
return nullptr;
3424-
}
34253406
bitmap* bmp = bm_lock(handle, 32, BMP_TEX_XPARENT);
34263407

3427-
memcpy(bitmapSurface->pixels, reinterpret_cast<void*>(bmp->data), static_cast<size_t>(w * h * 4));
3408+
auto bitmapSurface = SDL_CreateSurfaceFrom(bmp->w, bmp->h, SDL_PIXELFORMAT_BGRA32,
3409+
reinterpret_cast<void *>(bmp->data),
3410+
bmp->rowsize * (bmp->bpp >> 3));
34283411

34293412
bm_unlock(handle);
3430-
SDL_UnlockSurface(bitmapSurface);
34313413

34323414
return bitmapSurface;
34333415

code/controlconfig/controlsconfigcommon.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ const char *textify_scancode(int code)
658658
}
659659

660660
SCP_string name;
661-
unicode::convert_encoding(name, SDL_GetKeyName(SDL_GetKeyFromScancode(fs2_to_sdl(keycode))), unicode::Encoding::Encoding_utf8);
661+
unicode::convert_encoding(name, SDL_GetKeyName(SDL_GetKeyFromScancode(fs2_to_sdl(keycode), SDL_KMOD_NONE, false)), unicode::Encoding::Encoding_utf8);
662662
strcat_s(text, name.c_str());
663663
return text;
664664
}

code/cutscene/movie.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
#include <windows.h>
1515
#endif
1616

17-
#include "freespace.h"
1817
#include "globalincs/pstypes.h"
18+
#include "freespace.h"
1919
#include "globalincs/alphacolors.h"
2020
#include "globalincs/systemvars.h"
2121
#include "io/cursor.h"
@@ -208,7 +208,7 @@ void movie_display_loop(Player* player, PlaybackState* state) {
208208
auto sleepTime = static_cast<std::uint64_t>((1. / (4. * player->getMovieProperties().fps)) * 1000.);
209209

210210
auto listener = [state](const SDL_Event& event) {
211-
switch (event.key.keysym.sym) {
211+
switch (event.key.key) {
212212
case SDLK_ESCAPE:
213213
case SDLK_KP_ENTER:
214214
case SDLK_RETURN:
@@ -220,7 +220,7 @@ void movie_display_loop(Player* player, PlaybackState* state) {
220220
}
221221
};
222222
// Use a dedicated listener here since we want to listen for the KEYUP event
223-
auto key_handle = os::events::addEventListener(SDL_KEYUP, os::events::DEFAULT_LISTENER_WEIGHT - 10, listener);
223+
auto key_handle = os::events::addEventListener(SDL_EVENT_KEY_UP, os::events::DEFAULT_LISTENER_WEIGHT - 10, listener);
224224

225225
// slight hack to make sure that game_set_frametime() doesn't also try to cap the framerate
226226
auto fpsCapSave = Cmdline_NoFPSCap;

code/debugconsole/console.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -489,13 +489,15 @@ void dc_putc(char c)
489489
}
490490

491491
bool handle_textInputEvent(const SDL_Event& event) {
492-
if (event.text.text[0] != '\0' && event.text.text[0] != '\1') {
493-
for (char c : event.text.text) {
494-
if (c < 32)
492+
const char *p = event.text.text;
493+
494+
if (*p != '\0' && *p != '\1') {
495+
for (; *p; ++p) {
496+
if (*p < 32)
495497
break;
496498

497499
if (dc_command_buf.size() < MAX_CLI_LEN) {
498-
dc_command_buf.push_back(c);
500+
dc_command_buf.push_back(*p);
499501
}
500502
}
501503
}
@@ -515,8 +517,8 @@ void debug_console(void (*_func)(void))
515517
dc_init();
516518
}
517519

518-
auto textListener = os::events::addEventListener(SDL_TEXTINPUT, 10000, &handle_textInputEvent);
519-
SDL_StartTextInput();
520+
auto textListener = os::events::addEventListener(SDL_EVENT_TEXT_INPUT, 10000, &handle_textInputEvent);
521+
SDL_StartTextInput(os::getSDLMainWindow());
520522

521523
dc_draw(TRUE);
522524

@@ -618,7 +620,7 @@ void debug_console(void (*_func)(void))
618620
dc_draw(TRUE);
619621
}
620622

621-
SDL_StopTextInput();
623+
SDL_StopTextInput(os::getSDLMainWindow());
622624
os::events::removeEventListener(textListener);
623625

624626
while( key_inkey() ) {

code/external_dll/externalcode.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
#include "globalincs/pstypes.h"
55

6-
#include <SDL_loadso.h>
76

87
/* This class loads external libraries for FSO use.
98
* Uses SDL to do the actual loading so this should be supported on most platforms
@@ -44,7 +43,7 @@ class SCP_ExternalCode
4443
{
4544
if (m_library != NULL && functionname != NULL)
4645
{
47-
void* func = SDL_LoadFunction(m_library, functionname);
46+
void* func = reinterpret_cast<void *>(SDL_LoadFunction(m_library, functionname));
4847

4948
#ifndef NDEBUG
5049
if (func == NULL)
@@ -66,7 +65,7 @@ class SCP_ExternalCode
6665
}
6766

6867
private:
69-
void* m_library;
68+
SDL_SharedObject* m_library;
7069
};
7170

7271
/* These are available if you're compiling an external DLL

code/globalincs/pstypes.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,10 @@ const float PI2 = (PI*2.0f);
348348
const float PI_2 = (PI/2.0f);
349349
const float PI_4 = (PI/4.0f);
350350

351+
// not defined generally on Windows, no longer included in SDL
352+
#ifndef M_PI
353+
#define M_PI SDL_PI_F
354+
#endif
351355

352356
extern int Fred_running; // Is Fred running, or FreeSpace?
353357
extern bool running_unittests;
@@ -377,10 +381,10 @@ const size_t INVALID_SIZE = static_cast<size_t>(-1);
377381
// turn off inline asm
378382
#undef USE_INLINE_ASM
379383

380-
#define INTEL_INT(x) SDL_Swap32(x)
381-
#define INTEL_LONG(x) SDL_Swap64(x)
382-
#define INTEL_SHORT(x) SDL_Swap16(x)
383-
#define INTEL_FLOAT(x) SDL_SwapFloat((*x))
384+
#define INTEL_INT(x) SDL_Swap32LE(x)
385+
#define INTEL_LONG(x) SDL_Swap64LE(x)
386+
#define INTEL_SHORT(x) SDL_Swap16LE(x)
387+
#define INTEL_FLOAT(x) SDL_SwapFloatLE((*x))
384388

385389
#else // Little Endian -
386390
#define INTEL_INT(x) x

0 commit comments

Comments
 (0)