Skip to content

Commit

Permalink
Upgrade to SDL 3.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
tanis2000 committed Jan 23, 2025
1 parent f09c009 commit 1b38a9d
Show file tree
Hide file tree
Showing 2,460 changed files with 670,932 additions and 373,208 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ if("${CMAKE_VERSION}" VERSION_GREATER 3.5)
cmake_policy(SET CMP0025 NEW)
endif()

# Workaround for https://gitlab.kitware.com/cmake/cmake/-/issues/24104
# See also https://github.com/libsdl-org/SDL/issues/6454
enable_language(OBJC)

# cmake modules directory
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

Expand Down
4 changes: 2 additions & 2 deletions cmake/BinocleMac.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ list (APPEND BINOCLE_LINK_LIBRARIES "-l iconv")

set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-invalid-offsetof -std=gnu++0x")

set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -framework AppKit -framework AudioToolbox -framework AudioUnit -framework Carbon -framework Cocoa -framework CoreAudio -framework CoreHaptics -framework CoreMotion -framework CoreVideo -framework ForceFeedback -framework GameController -framework IOKit -framework OpenGL -framework CoreServices -framework Security -framework Metal -framework MetalKit")
set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -framework AppKit -framework AudioToolbox -framework AudioUnit -framework Carbon -framework Cocoa -framework CoreAudio -framework CoreHaptics -framework CoreMotion -framework CoreVideo -framework ForceFeedback -framework GameController -framework IOKit -framework OpenGL -framework CoreServices -framework Security -framework Metal -framework MetalKit")
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -framework AppKit -framework AudioToolbox -framework AudioUnit -framework Carbon -framework Cocoa -framework CoreAudio -framework CoreHaptics -framework CoreMotion -framework CoreVideo -framework ForceFeedback -framework GameController -framework IOKit -framework OpenGL -framework CoreServices -framework Security -framework Metal -framework MetalKit -framework UniformTypeIdentifiers")
set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -framework AppKit -framework AudioToolbox -framework AudioUnit -framework Carbon -framework Cocoa -framework CoreAudio -framework CoreHaptics -framework CoreMotion -framework CoreVideo -framework ForceFeedback -framework GameController -framework IOKit -framework OpenGL -framework CoreServices -framework Security -framework Metal -framework MetalKit -framework UniformTypeIdentifiers")
# set(EXTRA_LIBRARIES "${EXTRA_LIBRARIES} -framework IOKit -framework AppKit -framework GLUT -framework GLKit -framework OpenGL -framework AudioToolbox -framework OpenAL -framework CoreAudio -framework AudioUnit -framework QuartzCore -framework CoreGraphics -framework CoreServices -framework ForceFeedback")

set(CMAKE_OSX_DEPLOYMENT_TARGET 10.9)
Expand Down
7 changes: 1 addition & 6 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ endif ()

if (NOT EMSCRIPTEN)
set(BINOCLE_STATIC_LIBS ${BINOCLE_STATIC_LIBS}
$<TARGET_OBJECTS:SDL2::SDL2main>
$<TARGET_OBJECTS:SDL2::SDL2-static>
$<TARGET_OBJECTS:SDL3::SDL3-static>
$<TARGET_OBJECTS:ogg>
$<TARGET_OBJECTS:vorbis>
$<TARGET_OBJECTS:zlib>
Expand All @@ -41,7 +40,6 @@ endif()

if (APPLE AND NOT IOS AND NOT WATCHOS)
set(BINOCLE_STATIC_LIBS ${BINOCLE_STATIC_LIBS}
$<TARGET_OBJECTS:SDL2::SDL2main>
$<TARGET_OBJECTS:glew>
# we're using lua instead of luajit on macos to be able to test with valgrind
#$<TARGET_OBJECTS:luajit-5.1>
Expand All @@ -68,15 +66,13 @@ endif()

if (IOS)
set(BINOCLE_STATIC_LIBS ${BINOCLE_STATIC_LIBS}
$<TARGET_OBJECTS:SDL2::SDL2main>
$<TARGET_OBJECTS:lua>
$<TARGET_OBJECTS:luasocket>
)
endif()

if (WATCHOS)
set(BINOCLE_STATIC_LIBS ${BINOCLE_STATIC_LIBS}
$<TARGET_OBJECTS:SDL2::SDL2main>
$<TARGET_OBJECTS:lua>
$<TARGET_OBJECTS:luasocket>
)
Expand All @@ -93,7 +89,6 @@ endif()

if (MSVC)
set(BINOCLE_STATIC_LIBS ${BINOCLE_STATIC_LIBS}
$<TARGET_OBJECTS:SDL2::SDL2main>
$<TARGET_OBJECTS:glew>
# we're using lua instead of luajit on macos to be able to test with valgrind
#$<TARGET_OBJECTS:luajit-5.1>
Expand Down
29 changes: 14 additions & 15 deletions src/binocle/core/binocle_atlas.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,36 @@
// All rights reserved.
//

#include <string.h>
#include "binocle_atlas.h"
#include "binocle_sdl.h"
#include "binocle_array.h"
#include "binocle_log.h"
#include "binocle_subtexture.h"
#include "binocle_sdl.h"
#include "binocle_sprite.h"
#include <parson/parson.h>
#include "binocle_subtexture.h"
#include "sokol_gfx.h"
#include "binocle_array.h"
#include <parson/parson.h>

bool binocle_atlas_load_texturepacker(char *filename, binocle_atlas_texturepacker *atlas) {
binocle_log_info("Loading TexturePacker file: %s", filename);
SDL_strlcpy(atlas->asset_filename, filename, BINOCLE_MAX_ATLAS_FILENAME_LENGTH);

SDL_RWops *file = SDL_RWFromFile(filename, "rb");
SDL_IOStream *file = SDL_IOFromFile(filename, "rb");
if (file == NULL) {
binocle_log_error("Cannot open JSON file");
return false;
}

Sint64 res_size = SDL_RWsize(file);
Sint64 res_size = SDL_GetIOSize(file);
char *res = (char *) SDL_malloc(res_size + 1);

Sint64 nb_read_total = 0, nb_read = 1;
size_t nb_read_total = 0, nb_read = 1;
char *buf = res;
while (nb_read_total < res_size && nb_read != 0) {
nb_read = SDL_RWread(file, buf, 1, (res_size - nb_read_total));
nb_read = SDL_ReadIO(file, buf, res_size - nb_read_total);
nb_read_total += nb_read;
buf += nb_read;
}
SDL_RWclose(file);
SDL_CloseIO(file);
if (nb_read_total != res_size) {
binocle_log_error("Size mismatch");
SDL_free(res);
Expand Down Expand Up @@ -376,23 +375,23 @@ void binocle_atlas_load_libgdx(char *filename, struct sg_image *texture, struct
int *num_subtextures) {
*num_subtextures = 0;
binocle_log_info("Loading LibGDX file: %s", filename);
SDL_RWops *file = SDL_RWFromFile(filename, "rb");
SDL_IOStream *file = SDL_IOFromFile(filename, "rb");
if (file == NULL) {
binocle_log_error("Cannot open text file");
return;
}

Sint64 res_size = SDL_RWsize(file);
Sint64 res_size = SDL_GetIOSize(file);
char *res = (char *) SDL_malloc(res_size + 1);

Sint64 nb_read_total = 0, nb_read = 1;
size_t nb_read_total = 0, nb_read = 1;
char *buf = res;
while (nb_read_total < res_size && nb_read != 0) {
nb_read = SDL_RWread(file, buf, 1, (res_size - nb_read_total));
nb_read = SDL_ReadIO(file, buf, res_size - nb_read_total);
nb_read_total += nb_read;
buf += nb_read;
}
SDL_RWclose(file);
SDL_CloseIO(file);
if (nb_read_total != res_size) {
binocle_log_error("Size mismatch");
SDL_free(res);
Expand Down
1 change: 1 addition & 0 deletions src/binocle/core/binocle_atlas.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#define BINOCLE_ATLAS_H

#include <stdbool.h>
#include <stdlib.h>
#include "kazmath/kazmath.h"

#define BINOCLE_MAX_ATLAS_FILENAME_LENGTH (1024)
Expand Down
10 changes: 5 additions & 5 deletions src/binocle/core/binocle_bitmapfont.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,23 +120,23 @@ void binocle_bitmapfont_parse_common_line(binocle_bitmapfont *font, const char *
binocle_bitmapfont *binocle_bitmapfont_from_file(const char *filename, bool flip) {
binocle_bitmapfont *font = binocle_bitmapfont_new();

SDL_RWops *file = SDL_RWFromFile(filename, "rb");
SDL_IOStream *file = SDL_IOFromFile(filename, "rb");
if (file == NULL) {
binocle_log_error("Cannot open BitmapFont file %s", filename);
return font;
}

Sint64 res_size = SDL_RWsize(file);
Sint64 res_size = SDL_GetIOSize(file);
char *res = (char *) malloc(res_size + 1);

Sint64 nb_read_total = 0, nb_read = 1;
size_t nb_read_total = 0, nb_read = 1;
char *buf = res;
while (nb_read_total < res_size && nb_read != 0) {
nb_read = SDL_RWread(file, buf, 1, (res_size - nb_read_total));
nb_read = SDL_ReadIO(file, buf, res_size - nb_read_total);
nb_read_total += nb_read;
buf += nb_read;
}
SDL_RWclose(file);
SDL_CloseIO(file);
if (nb_read_total != res_size) {
binocle_log_error("Size mismatch");
free(res);
Expand Down
2 changes: 1 addition & 1 deletion src/binocle/core/binocle_fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "binocle_fs.h"
#include "binocle_log.h"
#include <physfs.h>
#include <SDL.h>
#include <SDL3/SDL.h>

#define CUTE_PATH_IMPLEMENTATION
#include <cute_path/cute_path.h>
Expand Down
1 change: 1 addition & 0 deletions src/binocle/core/binocle_http.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "binocle_sdl.h"
#include "binocle_log.h"
#include <stdbool.h>
#include <stdlib.h>

#if defined(__EMSCRIPTEN__)

Expand Down
47 changes: 21 additions & 26 deletions src/binocle/core/binocle_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ binocle_input binocle_input_new() {

void binocle_input_update(binocle_input *input) {
int i;
const Uint8 *state = SDL_GetKeyboardState(NULL);
const bool *state = SDL_GetKeyboardState(NULL);
for (i = 0; i < KEY_MAX; i++) {
input->previousKeys[i] = input->currentKeys[i];
input->currentKeys[i] = state[i];
}
for (i = 0; i < MOUSE_MAX; i++) {
if (i == 0) continue;
input->previousMouseButtons[i] = input->currentMouseButtons[i];
input->currentMouseButtons[i] = (SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(i)) == 0 ? false : true;
input->currentMouseButtons[i] = (SDL_GetMouseState(NULL, NULL) & SDL_BUTTON_MASK(i)) == 0 ? false : true;
}
input->curPrintableKey = KEY_UNKNOWN;

memset(input->text, 0, SDL_TEXTINPUTEVENT_TEXT_SIZE);
memset(input->text, 0, BINOCLE_INPUT_TEXT_SIZE);

input->mouseWheelX = 0;
input->mouseWheelY = 0;
Expand All @@ -46,88 +46,83 @@ void binocle_input_update(binocle_input *input) {
SDL_Event event = {0};
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_QUIT:
case SDL_EVENT_QUIT:
input->quit_requested = true;
break;

case SDL_WINDOWEVENT: {
switch (event.window.event) {
case SDL_WINDOWEVENT_FOCUS_LOST:
case SDL_EVENT_WINDOW_FOCUS_LOST:
input->willPause = true;
break;

case SDL_WINDOWEVENT_FOCUS_GAINED:
case SDL_EVENT_WINDOW_FOCUS_GAINED:
input->willPause = false;
break;

case SDL_WINDOWEVENT_SIZE_CHANGED:
case SDL_EVENT_WINDOW_RESIZED:
input->resized = true;
input->newWindowSize.x = (float)event.window.data1;
input->newWindowSize.y = (float)event.window.data2;
break;
}
break;
}

case SDL_KEYDOWN: {
int index = event.key.keysym.scancode;
case SDL_EVENT_KEY_DOWN: {
int index = event.key.scancode;

if (binocle_input_is_printable((binocle_input_keyboard_key) index))
input->curPrintableKey = (binocle_input_keyboard_key) index;
}
break;

case SDL_KEYUP: {
case SDL_EVENT_KEY_UP: {

int index = event.key.keysym.scancode;
int index = event.key.scancode;
}
break;

case SDL_MOUSEMOTION:
case SDL_EVENT_MOUSE_MOTION:
input->mouseX = event.motion.x;
input->mouseY = event.motion.y;
break;

case SDL_MOUSEBUTTONDOWN:
case SDL_EVENT_MOUSE_BUTTON_DOWN:

break;

case SDL_MOUSEBUTTONUP:
case SDL_EVENT_MOUSE_BUTTON_UP:

break;

case SDL_MOUSEWHEEL: {
case SDL_EVENT_MOUSE_WHEEL: {
input->mouseWheelX = event.wheel.x;
input->mouseWheelY = event.wheel.y;
break;
}

case SDL_FINGERDOWN:
case SDL_EVENT_FINGER_DOWN:
input->touch.x = event.tfinger.x;
input->touch.y = event.tfinger.y;
input->touch.dx = event.tfinger.dx;
input->touch.dy = event.tfinger.dy;
input->touch.pressure = event.tfinger.pressure;
input->touch.type = FINGER_DOWN;
break;
case SDL_FINGERMOTION:
case SDL_EVENT_FINGER_MOTION:
input->touch.x = event.tfinger.x;
input->touch.y = event.tfinger.y;
input->touch.dx = event.tfinger.dx;
input->touch.dy = event.tfinger.dy;
input->touch.pressure = event.tfinger.pressure;
input->touch.type = FINGER_MOTION;
break;
case SDL_FINGERUP:
case SDL_EVENT_FINGER_UP:
input->touch.x = event.tfinger.x;
input->touch.y = event.tfinger.y;
input->touch.dx = event.tfinger.dx;
input->touch.dy = event.tfinger.dy;
input->touch.pressure = event.tfinger.pressure;
input->touch.type = FINGER_UP;
break;
case SDL_TEXTINPUT: {
memcpy(input->text, event.text.text, SDL_TEXTINPUTEVENT_TEXT_SIZE);
case SDL_EVENT_TEXT_INPUT: {
memcpy(input->text, event.text.text, BINOCLE_INPUT_TEXT_SIZE);
break;
}
default:
Expand Down Expand Up @@ -280,7 +275,7 @@ kmVec2 binocle_input_get_mouse_position(binocle_input input, binocle_camera came
}

bool binocle_input_is_printable(SDL_Keycode key) {
return ((key > SDLK_SPACE) && (key < SDLK_z));
return ((key > SDLK_SPACE) && (key < SDLK_Z));
}

bool binocle_input_is_printable_key_down(binocle_input input) {
Expand Down
30 changes: 10 additions & 20 deletions src/binocle/core/binocle_input.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "binocle_sdl.h"
#include "binocle_math.h"

#define BINOCLE_INPUT_TEXT_SIZE (8192)

struct binocle_camera;

typedef enum binocle_input_mouse_button {
Expand Down Expand Up @@ -255,33 +257,21 @@ typedef enum binocle_input_keyboard_key {
KEY_RIGHT_ALT = SDL_SCANCODE_RALT,
KEY_RIGHT_GUI = SDL_SCANCODE_RGUI,
KEY_MODE = SDL_SCANCODE_MODE,
KEY_AUDIONEXT = SDL_SCANCODE_AUDIONEXT,
KEY_AUDIOPREV = SDL_SCANCODE_AUDIOPREV,
KEY_AUDIOSTOP = SDL_SCANCODE_AUDIOSTOP,
KEY_AUDIOPLAY = SDL_SCANCODE_AUDIOPLAY,
KEY_AUDIOMUTE = SDL_SCANCODE_AUDIOMUTE,
KEY_MEDIASELECT = SDL_SCANCODE_MEDIASELECT,
KEY_WWW = SDL_SCANCODE_WWW,
KEY_MAIL = SDL_SCANCODE_MAIL,
KEY_CALCULATOR = SDL_SCANCODE_CALCULATOR,
KEY_COMPUTER = SDL_SCANCODE_COMPUTER,
KEY_AUDIONEXT = SDL_SCANCODE_MEDIA_NEXT_TRACK,
KEY_AUDIOPREV = SDL_SCANCODE_MEDIA_PREVIOUS_TRACK,
KEY_AUDIOSTOP = SDL_SCANCODE_MEDIA_STOP,
KEY_AUDIOPLAY = SDL_SCANCODE_MEDIA_PLAY,
KEY_AUDIOMUTE = SDL_SCANCODE_MUTE,
KEY_MEDIASELECT = SDL_SCANCODE_MEDIA_SELECT,
KEY_AC_SEARCH = SDL_SCANCODE_AC_SEARCH,
KEY_AC_HOME = SDL_SCANCODE_AC_HOME,
KEY_AC_BACK = SDL_SCANCODE_AC_BACK,
KEY_AC_FORWARD = SDL_SCANCODE_AC_FORWARD,
KEY_AC_STOP = SDL_SCANCODE_AC_STOP,
KEY_AC_REFRESH = SDL_SCANCODE_AC_REFRESH,
KEY_AC_BOOKMARKS = SDL_SCANCODE_AC_BOOKMARKS,
KEY_BRIGHTNESSDOWN = SDL_SCANCODE_BRIGHTNESSDOWN,
KEY_BRIGHTNESSUP = SDL_SCANCODE_BRIGHTNESSUP,
KEY_DISPLAYSWITCH = SDL_SCANCODE_DISPLAYSWITCH,
KEY_KBDILLUMTOGGLE = SDL_SCANCODE_KBDILLUMTOGGLE,
KEY_KBDILLUMDOWN = SDL_SCANCODE_KBDILLUMDOWN,
KEY_KBDILLUMUP = SDL_SCANCODE_KBDILLUMUP,
KEY_EJECT = SDL_SCANCODE_EJECT,
KEY_EJECT = SDL_SCANCODE_MEDIA_EJECT,
KEY_SLEEP = SDL_SCANCODE_SLEEP,
KEY_APP1 = SDL_SCANCODE_APP1,
KEY_APP2 = SDL_SCANCODE_APP2,
KEY_MAX
} binocle_input_keyboard_key;

Expand Down Expand Up @@ -326,7 +316,7 @@ typedef struct binocle_input {

binocle_input_touch touch;

char text[SDL_TEXTINPUTEVENT_TEXT_SIZE];
char text[BINOCLE_INPUT_TEXT_SIZE];

/**
* By default the mouse position has the origin at the top-left of the screen.
Expand Down
Loading

0 comments on commit 1b38a9d

Please sign in to comment.