diff --git a/CMakeLists.txt b/CMakeLists.txt index aa19165..0c97a10 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -95,12 +95,12 @@ ELSEIF ( WIN32 ) "${CMAKE_C_FLAGS_RELEASE} -mwindows" ) ENDIF () -#IF ( GCC ) -#SET ( -#CMAKE_C_FLAGS_DEBUG -#"${CMAKE_C_FLAGS_DEBUG} -fsanitize=address -fno-omit-frame-pointer" -#) -#ENDIF ( GCC ) +IF ( GCC ) + SET ( + CMAKE_C_FLAGS_DEBUG + "${CMAKE_C_FLAGS_DEBUG} -fsanitize=address -fno-omit-frame-pointer" + ) +ENDIF ( GCC ) if (STEAM) include_directories( @@ -108,48 +108,48 @@ if (STEAM) ) endif () -# Include SDL2 +# Include SDL set(SDL_STATIC ON) set(SDL_SHARED OFF) set(SDL_TEST OFF) add_subdirectory(lib/SDL) -set(SDL2_INCLUDE_DIR lib/SDL/include) -set(SDL2_LIBRARY SDL2-static) -set(SDL2_MAIN_LIBRARY SDL2main) +set(SDL_INCLUDE_DIR lib/SDL/include) +set(SDL_LIBRARY SDL3-static) +set(SDL_MAIN_LIBRARY SDLmain) -# Include SDL2_image/mixer/ttf +# Include SDL_image/mixer/ttf set(BUILD_SHARED_LIBS OFF) -set(SDL2IMAGE_PNG ON) -set(SDL2IMAGE_JPG ON) -set(SDL2IMAGE_AVIF OFF) -set(SDL2IMAGE_BMP OFF) -set(SDL2IMAGE_GIF OFF) -set(SDL2IMAGE_JXL OFF) -set(SDL2IMAGE_LBM OFF) -set(SDL2IMAGE_PCX OFF) -set(SDL2IMAGE_PNM OFF) -set(SDL2IMAGE_QOI OFF) -set(SDL2IMAGE_SVG OFF) -set(SDL2IMAGE_TGA OFF) -set(SDL2IMAGE_TIF OFF) -set(SDL2IMAGE_WEBP OFF) -set(SDL2IMAGE_XCF OFF) -set(SDL2IMAGE_XPM OFF) -set(SDL2IMAGE_XV OFF) +set(SDLIMAGE_PNG ON) +set(SDLIMAGE_JPG ON) +set(SDLIMAGE_AVIF OFF) +set(SDLIMAGE_BMP OFF) +set(SDLIMAGE_GIF OFF) +set(SDLIMAGE_JXL OFF) +set(SDLIMAGE_LBM OFF) +set(SDLIMAGE_PCX OFF) +set(SDLIMAGE_PNM OFF) +set(SDLIMAGE_QOI OFF) +set(SDLIMAGE_SVG OFF) +set(SDLIMAGE_TGA OFF) +set(SDLIMAGE_TIF OFF) +set(SDLIMAGE_WEBP OFF) +set(SDLIMAGE_XCF OFF) +set(SDLIMAGE_XPM OFF) +set(SDLIMAGE_XV OFF) add_subdirectory(lib/SDL_image) -set(SDL2_IMAGE_INCLUDE_DIR lib/SDL_image/include) -set(SDL2_IMAGE_LIBRARY SDL2_image) +set(SDL_IMAGE_INCLUDE_DIR lib/SDL_image/include) +set(SDL_IMAGE_LIBRARY SDL3_image-static) # opusfile caused issues in macos build and we don't need it anyways -set(SDL2MIXER_OPUS OFF) +set(SDLMIXER_OPUS OFF) add_subdirectory(lib/SDL_mixer) -set(SDL2_MIXER_INCLUDE_DIR lib/SDL_mixer/include) -set(SDL2_MIXER_LIBRARY SDL2_mixer) +set(SDL_MIXER_INCLUDE_DIR lib/SDL_mixer/include) +set(SDL_MIXER_LIBRARY SDL3_mixer-static) add_subdirectory(lib/SDL_ttf) -set(SDL2_TTF_INCLUDE_DIR lib/SDL_ttf/include) -set(SDL2_TTF_LIBRARY SDL2_ttf) +set(SDL_TTF_INCLUDE_DIR lib/SDL_ttf/include) +set(SDL_TTF_LIBRARY SDL3_ttf-static) # Include lua lib add_subdirectory(lib/lua-5.3.5) @@ -164,19 +164,6 @@ include_directories(lib/physfs-3.0/src) set(PHYSFS_LIBRARY physfs-static) set(PHYSFS_INCLUDE_DIR physfs-3.0/src) -include_directories( - ${PROJECT_BINARY_DIR} - ${SDL2_INCLUDE_DIR} - ${SDL2_IMAGE_INCLUDE_DIR} - ${SDL2_TTF_INCLUDE_DIR} - ${SDL2_MIXER_INCLUDE_DIR} - ${PHYSFS_INCLUDE_DIR} - ${LUA_INCLUDE_DIR} - lib/sqlite3 - lib/bh_random/src - lib/checksum/src - ) - if (CMOCKA_FOUND) include_directories( ${CMOCKA_INCLUDE_DIR} @@ -278,6 +265,19 @@ add_executable(breakhack ${STEAM_SOURCES} ) +include_directories( + ${PROJECT_BINARY_DIR} + ${SDL_INCLUDE_DIR} + ${SDL_IMAGE_INCLUDE_DIR} + ${SDL_TTF_INCLUDE_DIR} + ${SDL_MIXER_INCLUDE_DIR} + ${PHYSFS_INCLUDE_DIR} + ${LUA_INCLUDE_DIR} + lib/sqlite3 + lib/bh_random/src + lib/checksum/src + ) + if (MSVC) source_group("Header files" REGULAR_EXPRESSION ".*\\.h") source_group("Source files" REGULAR_EXPRESSION ".*\\.c") @@ -288,10 +288,10 @@ set_source_files_properties(lib/sqlite3/sqlite3.c COMPILE_FLAGS -w) target_link_libraries(breakhack ${CMAKE_DL_LIBS} # Sqlite needs DL libs - ${SDL2_LIBRARY} - ${SDL2_IMAGE_LIBRARY} - ${SDL2_TTF_LIBRARY} - ${SDL2_MIXER_LIBRARY} + ${SDL_LIBRARY} + ${SDL_IMAGE_LIBRARY} + ${SDL_TTF_LIBRARY} + ${SDL_MIXER_LIBRARY} ${LUA_LIBRARIES} ${PHYSFS_LIBRARY} bh_random @@ -300,7 +300,7 @@ target_link_libraries(breakhack if (MSVC OR MINGW) target_link_libraries(breakhack - ${SDL2_MAIN_LIBRARY} + ${SDL_MAIN_LIBRARY} ) endif () @@ -339,7 +339,7 @@ IF (CMOCKA_FOUND AND NOT OSX AND NOT CLANG) add_executable(test_input test/test_input.c src/input.c src/keyboard.c) target_link_libraries(test_input ${CMOCKA_LIBRARY} - ${SDL2_LIBRARY} + ${SDL_LIBRARY} ) #set_target_properties(test_input PROPERTIES #LINK_FLAGS "-Wl,--wrap,keyboard_direction_press -Wl,--wrap,keyboard_press") diff --git a/Makefile b/Makefile index 9a56026..9254e9b 100644 --- a/Makefile +++ b/Makefile @@ -43,15 +43,15 @@ install: setup: @mkdir -p build/debug - @mkdir -p build/release - @mkdir -p build/win-release @cmake -B build/debug -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=YES -GNinja + @mkdir -p build/release @cmake -B build/release -DCMAKE_BUILD_TYPE=Release -GNinja + @mkdir -p build/win-release @cmake -B build/win-release \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_TOOLCHAIN_FILE=build_deps/toolchains/mingw-w64-i686.cmake \ - -DSDL2MIXER_VENDORED=ON \ - -DSDL2TTF_VENDORED=ON \ + -DSDLMIXER_VENDORED=ON \ + -DSDLTTF_VENDORED=ON \ -GNinja @ln -fs build/debug/compile_commands.json @echo "Setup complete" diff --git a/lib/SDL b/lib/SDL index 2824d13..e292d1f 160000 --- a/lib/SDL +++ b/lib/SDL @@ -1 +1 @@ -Subproject commit 2824d138b9dcc2c113c8057d0ef377e3edfb24be +Subproject commit e292d1f5ace469f718d7b6b4dec8c28e37dcaa0e diff --git a/lib/SDL_image b/lib/SDL_image index 1cdf374..9b18364 160000 --- a/lib/SDL_image +++ b/lib/SDL_image @@ -1 +1 @@ -Subproject commit 1cdf374314cfb788cd9059aa2cff8281cb745c91 +Subproject commit 9b183647f2b662d2855dc75547b091065f14fc2d diff --git a/lib/SDL_mixer b/lib/SDL_mixer index 93ab764..5175907 160000 --- a/lib/SDL_mixer +++ b/lib/SDL_mixer @@ -1 +1 @@ -Subproject commit 93ab764453cad3bf3d85c05c02f81ca9c6a4a173 +Subproject commit 5175907b515ea9e07d0b35849bfaf09870d07d33 diff --git a/lib/SDL_ttf b/lib/SDL_ttf index 7185085..2554dd7 160000 --- a/lib/SDL_ttf +++ b/lib/SDL_ttf @@ -1 +1 @@ -Subproject commit 7185085beb39b9e8b17d18685a2a58a14b7c53ef +Subproject commit 2554dd7af438594dfc006ece291ad879ab36388b diff --git a/src/actiontext.h b/src/actiontext.h index 5bf6b80..52da84f 100644 --- a/src/actiontext.h +++ b/src/actiontext.h @@ -19,7 +19,7 @@ #ifndef ACTIONTEXT_H_ #define ACTIONTEXT_H_ -#include +#include #include #include "position.h" diff --git a/src/actiontextbuilder.h b/src/actiontextbuilder.h index 82467d0..c2d3298 100644 --- a/src/actiontextbuilder.h +++ b/src/actiontextbuilder.h @@ -19,7 +19,7 @@ #ifndef ACTIONTEXTBUILDER_H_ #define ACTIONTEXTBUILDER_H_ -#include +#include #include "actiontext.h" #include "camera.h" #include "update_data.h" diff --git a/src/animation.h b/src/animation.h index b21ee3e..533af53 100644 --- a/src/animation.h +++ b/src/animation.h @@ -19,7 +19,7 @@ #ifndef _ANIMATION_H #define _ANIMATION_H -#include +#include #include typedef struct Timer Timer; diff --git a/src/camera.h b/src/camera.h index 9fb876b..c72a093 100644 --- a/src/camera.h +++ b/src/camera.h @@ -19,7 +19,7 @@ #ifndef CAMERA_H_ #define CAMERA_H_ -#include +#include #include "position.h" #include "timer.h" diff --git a/src/collisions.h b/src/collisions.h index 3723d2d..12bbcfe 100644 --- a/src/collisions.h +++ b/src/collisions.h @@ -19,7 +19,7 @@ #ifndef COLLISIONS_H_ #define COLLISIONS_H_ -#include +#include #include #include "position.h" diff --git a/src/gamecontroller.c b/src/gamecontroller.c index cc41b2f..3c8664e 100644 --- a/src/gamecontroller.c +++ b/src/gamecontroller.c @@ -19,16 +19,16 @@ #include "gamecontroller.h" #include "util.h" -static SDL_GameController *controller = NULL; +static SDL_Gamepad *controller = NULL; static SDL_Haptic *haptic = NULL; static Uint8 controllerMode = 0; void -gamecontroller_set(SDL_GameController *ctrler) +gamecontroller_set(SDL_Gamepad *ctrler) { controller = ctrler; - const char *ctrlName = SDL_GameControllerName(controller); + const char *ctrlName = SDL_GetGamepadName(controller); info("Game controller connected: %s", ctrlName); // Try to determine if this is a PS3/4 controller @@ -39,17 +39,15 @@ gamecontroller_set(SDL_GameController *ctrler) else controllerMode = 1; - haptic = SDL_HapticOpenFromJoystick(SDL_GameControllerGetJoystick(controller)); + haptic = SDL_OpenHapticFromJoystick(SDL_GetGamepadJoystick(controller)); if (haptic) { info("Haptics are supported by controller: %s", ctrlName); - if (SDL_HapticRumbleInit(haptic) >= 0) { + if (SDL_InitHapticRumble(haptic)) { info("Haptics enabled for controller: %s", ctrlName); - } - else { + } else { info("Failed to enable haptics for: %s", ctrlName); } - } - else { + } else { info("Haptics not supported by controller: %s", ctrlName); } } @@ -60,21 +58,21 @@ gamecontroller_rumble(float intensity, Uint32 duration) if (!haptic) return; - if (SDL_HapticRumblePlay(haptic, intensity, duration) != 0) + if (SDL_PlayHapticRumble(haptic, intensity, duration) != 0) error("Failed to play rumble: %s", SDL_GetError()); } Uint8 -gamecontroller_mode() +gamecontroller_mode(void) { return controllerMode; } void -gamecontroller_close() +gamecontroller_close(void) { if (controller) - SDL_GameControllerClose(controller); + SDL_CloseGamepad(controller); if (haptic) - SDL_HapticClose(haptic); + SDL_CloseHaptic(haptic); } diff --git a/src/gamecontroller.h b/src/gamecontroller.h index 493b821..46742cf 100644 --- a/src/gamecontroller.h +++ b/src/gamecontroller.h @@ -18,15 +18,15 @@ #pragma once -#include +#include typedef struct GameController { - SDL_GameController *controller; + SDL_Gamepad *controller; unsigned int mode; } GameController; void -gamecontroller_set(SDL_GameController *controller); +gamecontroller_set(SDL_Gamepad *controller); void gamecontroller_rumble(float intensity, Uint32 duration); diff --git a/src/globals.h b/src/globals.h index 8f112cd..063017a 100644 --- a/src/globals.h +++ b/src/globals.h @@ -19,7 +19,7 @@ #ifndef GLOBALS_H_ #define GLOBALS_H_ -#include +#include TTF_Font *gFontLarge = NULL; TTF_Font *gFontSmall = NULL; diff --git a/src/gui.c b/src/gui.c index 0314e49..57dd5d2 100644 --- a/src/gui.c +++ b/src/gui.c @@ -457,12 +457,12 @@ gui_render_minimap(Gui *gui, Map *map, Camera *cam) { sprite_render(gui->miniMapFrame, cam); - SDL_Rect box = { 0, 0, 12, 8 }; + SDL_FRect box = { 0.0f, 0.0f, 12.0f, 8.0f }; for (Uint8 i = 0; i < MAP_H_ROOM_COUNT; ++i) { for (Uint8 j = 0; j < MAP_V_ROOM_COUNT; ++j) { Room *room = map->rooms[i][j]; - box.x = i*14 + 10; - box.y = j*10 + 14; + box.x = (float) i*14 + 10; + box.y = (float) j*10 + 14; if (room && room->visited) { if (map->currentRoom.x == i && map->currentRoom.y == j) SDL_SetRenderDrawColor(cam->renderer, 0, 255, 255, 255); @@ -470,7 +470,7 @@ gui_render_minimap(Gui *gui, Map *map, Camera *cam) SDL_SetRenderDrawColor(cam->renderer, 255, 255, 255, 255); SDL_RenderFillRect(cam->renderer, &box); SDL_SetRenderDrawColor(cam->renderer, 60, 134, 252, 255); - SDL_RenderDrawRect(cam->renderer, &box); + SDL_RenderRect(cam->renderer, &box); } } } diff --git a/src/gui_button.h b/src/gui_button.h index aa9a0aa..0fe85a6 100644 --- a/src/gui_button.h +++ b/src/gui_button.h @@ -19,7 +19,7 @@ #ifndef GUI_BUTTON_H_ #define GUI_BUTTON_H_ -#include +#include #include "pointer.h" #include "sprite.h" #include "linkedlist.h" diff --git a/src/input.c b/src/input.c index d567b81..25becbf 100644 --- a/src/input.c +++ b/src/input.c @@ -50,22 +50,22 @@ static Uint64 get_event_key(SDL_Event *event) { Uint64 key; - switch (event->key.keysym.sym) { + switch (event->key.key) { case SDLK_UP: - case SDLK_k: - case SDLK_w: + case SDLK_K : + case SDLK_W : key = KEY_UP; break; case SDLK_DOWN: - case SDLK_j: - case SDLK_s: + case SDLK_J : + case SDLK_S : key = KEY_DOWN; break; case SDLK_LEFT: - case SDLK_h: - case SDLK_a: + case SDLK_H : + case SDLK_A : key = KEY_LEFT; break; case SDLK_RIGHT: - case SDLK_l: - case SDLK_d: + case SDLK_L : + case SDLK_D : key = KEY_RIGHT; break; case SDLK_0: key = KEY_NUM0; break; @@ -96,30 +96,30 @@ get_event_button(SDL_Event *event) { Uint64 key; switch (event->jbutton.button) { - case SDL_CONTROLLER_BUTTON_DPAD_UP: + case SDL_GAMEPAD_BUTTON_DPAD_UP : key = KEY_UP; break; - case SDL_CONTROLLER_BUTTON_DPAD_DOWN: + case SDL_GAMEPAD_BUTTON_DPAD_DOWN : key = KEY_DOWN; break; - case SDL_CONTROLLER_BUTTON_DPAD_LEFT: + case SDL_GAMEPAD_BUTTON_DPAD_LEFT : key = KEY_LEFT; break; - case SDL_CONTROLLER_BUTTON_DPAD_RIGHT: + case SDL_GAMEPAD_BUTTON_DPAD_RIGHT : key = KEY_RIGHT; break; - case SDL_CONTROLLER_BUTTON_A: + case SDL_GAMEPAD_BUTTON_SOUTH : key = KEY_NUM1 | KEY_ENTER; break; - case SDL_CONTROLLER_BUTTON_X: + case SDL_GAMEPAD_BUTTON_WEST : key = KEY_NUM2; break; - case SDL_CONTROLLER_BUTTON_Y: + case SDL_GAMEPAD_BUTTON_NORTH : key = KEY_NUM3; break; - case SDL_CONTROLLER_BUTTON_B: + case SDL_GAMEPAD_BUTTON_EAST : key = KEY_NUM4; break; - case SDL_CONTROLLER_BUTTON_RIGHTSHOULDER: + case SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER : key = KEY_NUM5; break; - case SDL_CONTROLLER_BUTTON_START: + case SDL_GAMEPAD_BUTTON_START : key = KEY_ENTER; break; - case SDL_CONTROLLER_BUTTON_BACK: + case SDL_GAMEPAD_BUTTON_BACK : key = KEY_ESC; break; - case SDL_CONTROLLER_BUTTON_LEFTSTICK: - case SDL_CONTROLLER_BUTTON_RIGHTSTICK: + case SDL_GAMEPAD_BUTTON_LEFT_STICK : + case SDL_GAMEPAD_BUTTON_RIGHT_STICK : key = KEY_SPACE; break; default: key = 0; break; @@ -131,11 +131,11 @@ static Uint64 get_axis_motion(SDL_Event *event) { Uint64 key; - int angle = event->caxis.value; - switch (event->caxis.axis) { - case SDL_CONTROLLER_AXIS_LEFTX: + int angle = event->gaxis.value; + switch (event->gaxis.axis) { + case SDL_GAMEPAD_AXIS_LEFTX : key = angle < 0 ? KEY_LEFT : KEY_RIGHT; break; - case SDL_CONTROLLER_AXIS_LEFTY: + case SDL_GAMEPAD_AXIS_LEFTY : key = angle < 0 ? KEY_UP : KEY_DOWN; break; default: key = 0; @@ -147,19 +147,19 @@ static Uint32 get_event_modkey(SDL_Event *event) { Uint32 key = 0; - if (event->key.keysym.mod & (KMOD_LCTRL | KMOD_RCTRL)) { - switch (event->key.keysym.sym) { - case SDLK_s: + if (event->key.mod & (SDL_KMOD_LCTRL | SDL_KMOD_RCTRL)) { + switch (event->key.key) { + case SDLK_S : key = KEY_CTRL_S; break; - case SDLK_m: + case SDLK_M : key = KEY_CTRL_M; break; - case SDLK_d: + case SDLK_D : key = KEY_CTRL_D; break; - case SDLK_f: + case SDLK_F : key = KEY_CTRL_F; break; } - } else if (event->key.keysym.mod & (KMOD_LSHIFT | KMOD_RSHIFT)) { - switch (event->key.keysym.sym) { + } else if (event->key.mod & (SDL_KMOD_LSHIFT | SDL_KMOD_RSHIFT)) { + switch (event->key.key) { case SDLK_1: key = KEY_SHIFT_NUM1; break; case SDLK_2: @@ -195,36 +195,36 @@ get_event_mousebutton(SDL_Event *event) void input_handle_event(Input *input, SDL_Event *event) { - if (event->type == SDL_KEYDOWN) { + if (event->type == SDL_EVENT_KEY_DOWN) { Uint32 key; if ((key = get_event_modkey(event))) input->modKeyState |= key; else input->keyState |= get_event_key(event); } - else if (event->type == SDL_KEYUP) { + else if (event->type == SDL_EVENT_KEY_UP) { Uint32 key; if ((key = get_event_modkey(event))) input->modKeyState &= ~key; else input->keyState &= ~get_event_key(event); } - else if (event->type == SDL_MOUSEBUTTONDOWN) + else if (event->type == SDL_EVENT_MOUSE_BUTTON_DOWN) input->mouseButtonState |= get_event_mousebutton(event); - else if (event->type == SDL_MOUSEBUTTONUP) + else if (event->type == SDL_EVENT_MOUSE_BUTTON_UP) input->mouseButtonState &= ~get_event_mousebutton(event); - else if (event->type == SDL_MOUSEMOTION) { - input->mouseX = event->motion.x; - input->mouseY = event->motion.y; + else if (event->type == SDL_EVENT_MOUSE_MOTION) { + input->mouseX = (Uint32) event->motion.x; + input->mouseY = (Uint32) event->motion.y; } - else if (event->type == SDL_CONTROLLERBUTTONDOWN) { + else if (event->type == SDL_EVENT_GAMEPAD_BUTTON_DOWN) { input->keyState |= get_event_button(event); } - else if (event->type == SDL_CONTROLLERBUTTONUP) { + else if (event->type == SDL_EVENT_GAMEPAD_BUTTON_UP) { input->keyState &= ~get_event_button(event); } - else if (event->type == SDL_CONTROLLERAXISMOTION) { - if (event->caxis.value > 31500 || event->caxis.value < -31500) + else if (event->type == SDL_EVENT_GAMEPAD_AXIS_MOTION) { + if (event->gaxis.value > 31500 || event->gaxis.value < -31500) input->keyState |= get_axis_motion(event); else input->keyState &= ~get_axis_motion(event); diff --git a/src/input.h b/src/input.h index 59e2f47..45ad31b 100644 --- a/src/input.h +++ b/src/input.h @@ -19,7 +19,7 @@ #ifndef INPUT_H_ #define INPUT_H_ -#include +#include #include #define KEY_LEFT 0x1 diff --git a/src/io_util.c b/src/io_util.c index 18e6edb..4b95c7a 100644 --- a/src/io_util.c +++ b/src/io_util.c @@ -10,13 +10,13 @@ file_error(const char *path) fatal("Unable to open file %s: (%d) %s", path, code, PHYSFS_getErrorByCode(code)); } -SDL_RWops * +SDL_IOStream * io_load_rwops(const char *path) { if (!PHYSFS_exists(path)) file_error(path); - return PHYSFSRWOPS_openRead(path); + return PHYSFSIO_openRead(path); } void @@ -25,6 +25,7 @@ io_load_file_buffer(char **dest, unsigned long *len, const char *filepath) if (!PHYSFS_exists(filepath)) file_error(filepath); + debug("PHYSFS: Loading file %s", filepath); PHYSFS_File *file = PHYSFS_openRead(filepath); PHYSFS_sint64 size = (unsigned long) PHYSFS_fileLength(file); char *buffer = ec_malloc(sizeof(char) * (unsigned long) (size + 1)); diff --git a/src/io_util.h b/src/io_util.h index 34f0c41..b86983a 100644 --- a/src/io_util.h +++ b/src/io_util.h @@ -19,9 +19,9 @@ #ifndef IO_UTIL_H_ #define IO_UTIL_H_ -#include +#include -SDL_RWops * +SDL_IOStream * io_load_rwops(const char *path); void diff --git a/src/item_builder.c b/src/item_builder.c index bcc2f6a..c57115a 100644 --- a/src/item_builder.c +++ b/src/item_builder.c @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -#include +#include #include #include diff --git a/src/keyboard.c b/src/keyboard.c index b670003..f740cac 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -22,24 +22,24 @@ static bool extract_key(Direction dir, SDL_Event *event) { - Uint32 key = event->key.keysym.sym; + Uint32 key = event->key.key; switch (dir) { case UP: return key == SDLK_UP - || key == SDLK_w - || key == SDLK_k; + || key == SDLK_W + || key == SDLK_K; case DOWN: return key == SDLK_DOWN - || key == SDLK_s - || key == SDLK_j; + || key == SDLK_S + || key == SDLK_J; case LEFT: return key == SDLK_LEFT - || key == SDLK_a - || key == SDLK_h; + || key == SDLK_A + || key == SDLK_H; case RIGHT: return key == SDLK_RIGHT - || key == SDLK_l - || key == SDLK_d; + || key == SDLK_L + || key == SDLK_D; default: return false; } @@ -48,7 +48,7 @@ extract_key(Direction dir, SDL_Event *event) bool keyboard_direction_press(Direction dir, SDL_Event *event) { - if (event->type != SDL_KEYDOWN) + if (event->type != SDL_EVENT_KEY_DOWN) return false; return extract_key(dir, event); @@ -57,7 +57,7 @@ keyboard_direction_press(Direction dir, SDL_Event *event) bool keyboard_direction_release(Direction dir, SDL_Event *event) { - if (event->type != SDL_KEYUP) + if (event->type != SDL_EVENT_KEY_UP) return false; return extract_key(dir, event); @@ -66,30 +66,30 @@ keyboard_direction_release(Direction dir, SDL_Event *event) bool keyboard_press(Uint32 key, SDL_Event *event) { - if (event->type != SDL_KEYDOWN) + if (event->type != SDL_EVENT_KEY_DOWN) return false; - return key == (Uint32) event->key.keysym.sym; + return key == (Uint32) event->key.key; } bool keyboard_release(Uint32 key, SDL_Event *event) { - if (event->type != SDL_KEYUP) + if (event->type != SDL_EVENT_KEY_UP) return false; - return key == (Uint32) event->key.keysym.sym; + return key == (Uint32) event->key.key; } bool keyboard_mod_press(Uint32 key, Uint32 mod, SDL_Event *event) { - if (event->type != SDL_KEYDOWN) + if (event->type != SDL_EVENT_KEY_DOWN) return false; - if (!(event->key.keysym.mod & mod)) + if (!(event->key.mod & mod)) return false; - return key == (Uint32) event->key.keysym.sym; + return key == (Uint32) event->key.key; } diff --git a/src/keyboard.h b/src/keyboard.h index fd61375..b97cf32 100644 --- a/src/keyboard.h +++ b/src/keyboard.h @@ -19,7 +19,7 @@ #ifndef KEYBOARD_H_ #define KEYBOARD_H_ -#include +#include #include #include "defines.h" diff --git a/src/main.c b/src/main.c index f45d8bc..cbf7327 100644 --- a/src/main.c +++ b/src/main.c @@ -19,8 +19,8 @@ #include #include #include -#include -#include +#include +#include #include #include #include "linkedlist.h" @@ -166,7 +166,7 @@ static Sprite *howto_tooltip = NULL; static Sprite *new_artifact_tooltip = NULL; static unsigned int cLevel = 1; static float deltaTime = 1.0; -static double renderScale = 1.0; +static float renderScale = 1.0; static Turn currentTurn = PLAYER; static class_t playerClass = WARRIOR; static bool quickGame = false; @@ -198,9 +198,10 @@ bool initSDL(void) { int imgFlags = IMG_INIT_PNG; - if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_GAMECONTROLLER | SDL_INIT_HAPTIC) < 0) + debug("Initializing SDL"); + if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_GAMEPAD | SDL_INIT_HAPTIC)) { - error("Could not initiate SDL2: %s", SDL_GetError()); + error("Could not initiate SDL3: %s", SDL_GetError()); return false; } @@ -208,42 +209,50 @@ bool initSDL(void) if (dim.height > 1080) { info("Hi resolution screen detected (%u x %u)", dim.width, dim.height); - renderScale = ((double) dim.height)/1080; + // TODO(Linus): Fixme, this scaling is messing up the rendering + renderScale = 1.0; info("Scaling by %f", renderScale); } + debug("Initializing SDL_image"); if ( (IMG_Init(imgFlags) & imgFlags) == 0 ) { error("Unable to initiate img loading: %s", - IMG_GetError()); + SDL_GetError()); return false; } - if ( TTF_Init() == -1 ) { + debug("Initializing SDL_ttf"); + if (!TTF_Init()) { error("Unable to initiate ttf library: %s", - TTF_GetError()); + SDL_GetError()); return false; } - for (Uint8 i = 0; i < SDL_NumJoysticks(); ++i) { - if (!SDL_IsGameController(i)) + debug("Initializing gamepads"); + int num_joysticks; + SDL_JoystickID *sticks = SDL_GetJoysticks(&num_joysticks); + debug("Found %d joysticks", num_joysticks); + for (int i = 0; i < num_joysticks; i++) { + int stick = sticks[i]; + if (!SDL_IsGamepad(stick)) { continue; + } - SDL_GameController *ctrler = SDL_GameControllerOpen(i); + SDL_Gamepad *ctrler = SDL_OpenGamepad(stick); if (ctrler) { gamecontroller_set(ctrler); } } + SDL_free(sticks); + debug("Initializing SDL_mixer"); mixer_init(); char title_buffer[100]; m_sprintf(title_buffer, 100, "%s %d.%d.%d %s", GAME_TITLE, MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION, RELEASE_TYPE); gWindow = SDL_CreateWindow(title_buffer, - SDL_WINDOWPOS_UNDEFINED, - SDL_WINDOWPOS_UNDEFINED, (int)(SCREEN_WIDTH * renderScale), - (int)(SCREEN_HEIGHT * renderScale), - SDL_WINDOW_SHOWN); + (int)(SCREEN_HEIGHT * renderScale), 0); if (gWindow == NULL) { error("Unable to create window: %s", SDL_GetError()); @@ -251,30 +260,29 @@ bool initSDL(void) } // Set the window icon - window_icon = IMG_Load_RW(io_load_rwops("Extras/icon.png"), true); + window_icon = IMG_Load_IO(io_load_rwops("Extras/icon.png"), true); SDL_SetWindowIcon(gWindow, window_icon); - gRenderer = SDL_CreateRenderer(gWindow, -1, - SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE); + gRenderer = SDL_CreateRenderer(gWindow, NULL); if (gRenderer == NULL) { error("Unable to create renderer: %s", SDL_GetError()); return false; } - if (SDL_SetRenderDrawBlendMode(gRenderer, SDL_BLENDMODE_BLEND) < 0) { + if (!SDL_SetRenderDrawBlendMode(gRenderer, SDL_BLENDMODE_BLEND)) { error("Unable to set blend mode: %s", SDL_GetError()); return false; } - if (SDL_RenderSetLogicalSize(gRenderer, SCREEN_WIDTH, SCREEN_HEIGHT) < 0) + if (!SDL_SetRenderLogicalPresentation(gRenderer, (int)(SCREEN_WIDTH*renderScale), (int)(SCREEN_HEIGHT*renderScale), SDL_LOGICAL_PRESENTATION_INTEGER_SCALE)) { error("Unable to initiate scaling: %s", SDL_GetError()); return false; } - if (SDL_IsTextInputActive()) { + if (SDL_TextInputActive(gWindow)) { debug("Disabling text input"); - SDL_StopTextInput(); + SDL_StopTextInput(gWindow); } return true; @@ -661,7 +669,7 @@ repopulate_roommatrix(void) static void resetGame(void) { - SDL_FlushEvents(SDL_FIRSTEVENT, SDL_LASTEVENT); + SDL_FlushEvents(SDL_EVENT_FIRST, SDL_EVENT_LAST); if (mainMenu) { menu_destroy(mainMenu); @@ -775,26 +783,25 @@ init(void) static void toggle_fullscreen(void) { - bool isFullscreen = SDL_GetWindowFlags(gWindow) & SDL_WINDOW_FULLSCREEN_DESKTOP; + bool fullscreen = SDL_GetWindowFlags(gWindow) & SDL_WINDOW_FULLSCREEN; Settings *settings = settings_get(); - if (isFullscreen) { + if (!fullscreen) { initViewports(0); SDL_SetWindowFullscreen(gWindow, 0); settings->fullscreen_enabled = false; } else { int w, h, lw, lh; - SDL_RenderGetLogicalSize(gRenderer, &lw, &lh); + SDL_GetRenderLogicalPresentation(gRenderer, &lw, &lh, NULL); SDL_GetWindowSize(gWindow, &w, &h); double lratio = (double) w / (double) lw; - SDL_SetWindowFullscreen(gWindow, SDL_WINDOW_FULLSCREEN_DESKTOP); + SDL_SetWindowFullscreen(gWindow, true); - SDL_DisplayMode dMode; - SDL_GetWindowDisplayMode(gWindow, &dMode); - double ratio = (double) (dMode.w) / w; - double offset = ((dMode.w - w) / 2); + const SDL_DisplayMode *dMode = SDL_GetWindowFullscreenMode(gWindow); + double ratio = (double) (dMode->w) / w; + double offset = ((dMode->w - w) / 2.0); initViewports((Uint32)(offset/(ratio*lratio))); settings->fullscreen_enabled = true; } @@ -884,7 +891,7 @@ handle_events(void) input_reset(&input); while (SDL_PollEvent(&event) != 0) { - if (event.type == SDL_QUIT) { + if (event.type == SDL_EVENT_QUIT) { quit = true; continue; } @@ -895,7 +902,7 @@ handle_events(void) if (handleCount >= 20) { debug("Flushing event queue"); SDL_PumpEvents(); - SDL_FlushEvents(SDL_FIRSTEVENT, SDL_LASTEVENT); + SDL_FlushEvents(SDL_EVENT_FIRST, SDL_EVENT_LAST); break; } } @@ -1042,21 +1049,21 @@ run_game_update(void) static void render_gui(void) { - SDL_RenderSetViewport(gRenderer, &statsGuiViewport); + SDL_SetRenderViewport(gRenderer, &statsGuiViewport); gui_render_panel(gGui, gCamera); - SDL_RenderSetViewport(gRenderer, &minimapViewport); + SDL_SetRenderViewport(gRenderer, &minimapViewport); gui_render_minimap(gGui, gMap, gCamera); - SDL_RenderSetViewport(gRenderer, &skillBarViewport); + SDL_SetRenderViewport(gRenderer, &skillBarViewport); skillbar_render(gSkillBar, gPlayer, gCamera); - SDL_RenderSetViewport(gRenderer, &bottomGuiViewport); + SDL_SetRenderViewport(gRenderer, &bottomGuiViewport); gui_render_log(gGui, gCamera); - SDL_RenderSetViewport(gRenderer, &mainViewport); + SDL_SetRenderViewport(gRenderer, &mainViewport); } static void render_game_completed(void) { - SDL_RenderSetViewport(gRenderer, &gameViewport); + SDL_SetRenderViewport(gRenderer, &gameViewport); if (!is_player_dead()) { player_render(gPlayer, gCamera); player_render_toplayer(gPlayer, gCamera); @@ -1065,7 +1072,7 @@ render_game_completed(void) gui_render_event_message(gGui, gCamera); if (gGameState == IN_GAME_MENU) { - SDL_Rect dimmer = { 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT }; + SDL_FRect dimmer = { 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT }; SDL_SetRenderDrawColor(gRenderer, 0, 0, 0, 150); SDL_RenderFillRect(gRenderer, &dimmer); menu_render(inGameMenu, gCamera); @@ -1079,7 +1086,7 @@ render_game_completed(void) static void render_game(void) { - SDL_RenderSetViewport(gRenderer, &gameViewport); + SDL_SetRenderViewport(gRenderer, &gameViewport); map_render(gMap, gCamera); particle_engine_render_game(gCamera); @@ -1106,12 +1113,12 @@ run_game_render(void) render_game(); render_gui(); - SDL_RenderSetViewport(gRenderer, &mainViewport); + SDL_SetRenderViewport(gRenderer, &mainViewport); particle_engine_render_global(gCamera); gui_render_tooltip(gGui, gCamera); if (gGameState == IN_GAME_MENU) { - SDL_Rect dimmer = { 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT }; + SDL_FRect dimmer = { 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT }; SDL_SetRenderDrawColor(gRenderer, 0, 0, 0, 150); SDL_RenderFillRect(gRenderer, &dimmer); menu_render(inGameMenu, gCamera); @@ -1271,14 +1278,14 @@ run_menu(void) SDL_SetRenderDrawColor(gRenderer, 0, 0, 0, 0); SDL_RenderClear(gRenderer); if (gGameState != CHARACTER_MENU) { - SDL_RenderSetViewport(gRenderer, &menuViewport); + SDL_SetRenderViewport(gRenderer, &menuViewport); map_render(gMap, gCamera); map_render_mid_layer(gMap, gCamera); map_render_top_layer(gMap, gRoomMatrix, gCamera); roommatrix_render_lightmap(gRoomMatrix, gCamera); } - SDL_RenderSetViewport(gRenderer, &mainViewport); + SDL_SetRenderViewport(gRenderer, &mainViewport); render_current_screen(); menu_render(get_active_menu(), gCamera); @@ -1294,8 +1301,8 @@ run_menu(void) static void run(void) { - static int oldTime = 0; - static int currentTime = 0; + static Uint64 oldTime = 0; + static Uint64 currentTime = 0; bool quit = false; @@ -1344,7 +1351,7 @@ run(void) break; } - unsigned int ticks = timer_get_ticks(fpsTimer); + Uint32 ticks = (Uint32) timer_get_ticks(fpsTimer); if (ticks < 1000/60) SDL_Delay((1000/60) - ticks); timer_stop(fpsTimer); @@ -1354,7 +1361,7 @@ run(void) else { oldTime = currentTime; currentTime = SDL_GetTicks(); - deltaTime = (float) ((currentTime - oldTime) / 1000.0); + deltaTime = ((float)(currentTime - oldTime) / 1000.0f); } #ifdef DEBUG frame++; @@ -1398,7 +1405,7 @@ void close(void) if (characterSelectScreen) screen_destroy(characterSelectScreen); if (window_icon) { - SDL_FreeSurface(window_icon); + SDL_DestroySurface(window_icon); } sprite_destroy(howto_tooltip); diff --git a/src/map.h b/src/map.h index 5ae1cbc..969ee6d 100644 --- a/src/map.h +++ b/src/map.h @@ -19,7 +19,7 @@ #ifndef MAP_H_ #define MAP_H_ -#include +#include #include #include "linkedlist.h" diff --git a/src/menu.h b/src/menu.h index 005c33e..4df1eec 100644 --- a/src/menu.h +++ b/src/menu.h @@ -19,7 +19,7 @@ #ifndef MENU_H_ #define MENU_H_ -#include +#include #include "camera.h" #include "linkedlist.h" #include "texture.h" diff --git a/src/mixer.c b/src/mixer.c index dea48d2..7a923e2 100644 --- a/src/mixer.c +++ b/src/mixer.c @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -#include +#include #include "mixer.h" #include "util.h" #include "io_util.h" @@ -38,18 +38,21 @@ static char *music[LAST_MUSIC] = { static Mix_Music* load_song(char *path) { - Mix_Music *m = Mix_LoadMUS_RW(io_load_rwops(path), true); + Mix_Music *m = Mix_LoadMUS_IO(io_load_rwops(path), true); if (m == NULL) - fatal("Failed to load music: %s", Mix_GetError()); + fatal("Failed to load music: %s", SDL_GetError()); return m; } static Mix_Chunk* load_effect(char *path) { - Mix_Chunk *effect = Mix_LoadWAV_RW(io_load_rwops(path), true); + debug("Loading effect: %s", path); + SDL_IOStream *io = io_load_rwops(path); + debug("Loaded effect: %s", path); + Mix_Chunk *effect = Mix_LoadWAV_IO(io, true); if (effect == NULL) - fatal("Failed to load effect: %s", Mix_GetError()); + fatal("Failed to load effect (%s): %s", path, SDL_GetError()); return effect; } @@ -98,8 +101,13 @@ load_effects(void) void mixer_init(void) { - if (Mix_OpenAudio( 44100, MIX_DEFAULT_FORMAT, 2, 2048 ) == -1) { - fatal("Failed to load sound: %s", Mix_GetError()); + SDL_AudioSpec desired; + desired.freq = 44100; + desired.format = MIX_DEFAULT_FORMAT; + desired.channels = 2; + + if (!Mix_OpenAudio(0, &desired)) { + fatal("Failed to load sound: %s", SDL_GetError()); } load_effects(); @@ -159,7 +167,7 @@ mixer_play_music(Music mus) if (Mix_PlayingMusic()) mixer_stop_music(); - if (Mix_PlayMusic(current_song, -1) == -1) + if (!Mix_PlayMusic(current_song, -1)) fatal("Failed to play music"); } diff --git a/src/monster.h b/src/monster.h index f3a8d22..782336e 100644 --- a/src/monster.h +++ b/src/monster.h @@ -19,7 +19,7 @@ #ifndef MONSTER_H_ #define MONSTER_H_ -#include +#include #include "sprite.h" #include "stats.h" #include "actiontext.h" diff --git a/src/object.h b/src/object.h index 9011151..688227d 100644 --- a/src/object.h +++ b/src/object.h @@ -17,7 +17,7 @@ */ #pragma once -#include +#include #include #include "camera.h" #include "player.h" diff --git a/src/particle_engine.c b/src/particle_engine.c index 6445854..aa737eb 100644 --- a/src/particle_engine.c +++ b/src/particle_engine.c @@ -462,7 +462,7 @@ render_rect_particle(Particle *p, Camera *cam) p->color.g, p->color.b, p->color.a); - SDL_RenderFillRect(cam->renderer, &box); + SDL_RenderFillRect(cam->renderer, (SDL_FRect*) &box); // Reset the blend mode SDL_SetRenderDrawBlendMode(cam->renderer, SDL_BLENDMODE_BLEND); @@ -488,7 +488,7 @@ render_line_particle(Particle *p, Camera *cam) p->color.g, p->color.b, p->color.a); - SDL_RenderDrawLine(cam->renderer, spos.x, spos.y, epos.x, epos.y); + SDL_RenderLine(cam->renderer, (float) spos.x, (float) spos.y, (float) epos.x, (float) epos.y); // Reset the blend mode SDL_SetRenderDrawBlendMode(cam->renderer, SDL_BLENDMODE_BLEND); diff --git a/src/particle_engine.h b/src/particle_engine.h index 2acc0d0..a39cfec 100644 --- a/src/particle_engine.h +++ b/src/particle_engine.h @@ -19,7 +19,7 @@ #ifndef PARTICLE_ENGINE_H_ #define PARTICLE_ENGINE_H_ -#include +#include #include "position.h" #include "dimension.h" #include "camera.h" diff --git a/src/physfsrwops.c b/src/physfsrwops.c index 5b8ec84..e8b9d66 100644 --- a/src/physfsrwops.c +++ b/src/physfsrwops.c @@ -1,41 +1,24 @@ /* - * This code provides a glue layer between PhysicsFS and Simple Directmedia - * Layer's (SDL) RWops i/o abstraction. + * BreakHack - A dungeone crawler RPG + * Copyright (C) 2018 Linus Probert * - * License: this code is public domain. I make no warranty that it is useful, - * correct, harmless, or environmentally safe. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This particular file may be used however you like, including copying it - * verbatim into a closed-source project, exploiting it commercially, and - * removing any trace of my name from the source (although I hope you won't - * do that). I welcome enhancements and corrections to this file, but I do - * not require you to send me patches if you make changes. This code has - * NO WARRANTY. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * Unless otherwise stated, the rest of PhysicsFS falls under the zlib license. - * Please see LICENSE.txt in the root of the source tree. - * - * SDL 1.2 falls under the LGPL license. SDL 1.3+ is zlib, like PhysicsFS. - * You can get SDL at https://www.libsdl.org/ - * - * This file was written by Ryan C. Gordon. (icculus@icculus.org). + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ -#include /* used for SEEK_SET, SEEK_CUR, SEEK_END ... */ +#include #include "physfsrwops.h" - -/* SDL's RWOPS interface changed a little in SDL 2.0... */ -#if defined(SDL_VERSION_ATLEAST) -#if SDL_VERSION_ATLEAST(2, 0, 0) -#define TARGET_SDL2 1 -#endif -#endif - -#if !TARGET_SDL2 -#define RW_SEEK_SET SEEK_SET -#define RW_SEEK_CUR SEEK_CUR -#define RW_SEEK_END SEEK_END -#endif +#include "util.h" static const char *getLastPhysfsError(void) { @@ -43,28 +26,22 @@ static const char *getLastPhysfsError(void) return (err) ? PHYSFS_getErrorByCode(err) : NULL; } -#if TARGET_SDL2 -static Sint64 SDLCALL physfsrwops_size(struct SDL_RWops *rw) +static Sint64 physfsrwops_size(void *userdata) { - PHYSFS_File *handle = (PHYSFS_File *) rw->hidden.unknown.data1; + PHYSFS_File *handle = (PHYSFS_File *) userdata; return (Sint64) PHYSFS_fileLength(handle); -} /* physfsrwops_size */ -#endif +} -#if TARGET_SDL2 -static Sint64 SDLCALL physfsrwops_seek(struct SDL_RWops *rw, Sint64 offset, int whence) -#else -static int physfsrwops_seek(SDL_RWops *rw, int offset, int whence) -#endif +static Sint64 physfsrwops_seek(void *userdata, Sint64 offset, enum SDL_IOWhence whence) { - PHYSFS_File *handle = (PHYSFS_File *) rw->hidden.unknown.data1; + PHYSFS_File *handle = (PHYSFS_File *) userdata; PHYSFS_sint64 pos = 0; - if (whence == RW_SEEK_SET) + if (whence == SDL_IO_SEEK_SET) pos = (PHYSFS_sint64) offset; - else if (whence == RW_SEEK_CUR) + else if (whence == SDL_IO_SEEK_CUR) { const PHYSFS_sint64 current = PHYSFS_tell(handle); if (current == -1) @@ -77,17 +54,13 @@ static int physfsrwops_seek(SDL_RWops *rw, int offset, int whence) if (offset == 0) /* this is a "tell" call. We're done. */ { -#if TARGET_SDL2 return (Sint64) current; -#else - return (int) current; -#endif } /* if */ pos = current + ((PHYSFS_sint64) offset); } /* else if */ - else if (whence == RW_SEEK_END) + else if (whence == SDL_IO_SEEK_END) { const PHYSFS_sint64 len = PHYSFS_fileLength(handle); if (len == -1) @@ -117,135 +90,121 @@ static int physfsrwops_seek(SDL_RWops *rw, int offset, int whence) return -1; } /* if */ -#if TARGET_SDL2 return (Sint64) pos; -#else - return (int) pos; -#endif } /* physfsrwops_seek */ -#if TARGET_SDL2 -static size_t SDLCALL physfsrwops_read(struct SDL_RWops *rw, void *ptr, - size_t size, size_t maxnum) -#else -static int physfsrwops_read(SDL_RWops *rw, void *ptr, int size, int maxnum) -#endif +static size_t physfsrwops_read(void *userdata, void *ptr, size_t size, SDL_IOStatus *status) { - PHYSFS_File *handle = (PHYSFS_File *) rw->hidden.unknown.data1; - const PHYSFS_uint64 readlen = (PHYSFS_uint64) (maxnum * size); + PHYSFS_File *handle = (PHYSFS_File *) userdata; + const PHYSFS_uint64 readlen = (PHYSFS_uint64) size; const PHYSFS_sint64 rc = PHYSFS_readBytes(handle, ptr, readlen); if (rc != ((PHYSFS_sint64) readlen)) { - if (!PHYSFS_eof(handle)) /* not EOF? Must be an error. */ - { + if (!PHYSFS_eof(handle)) { SDL_SetError("PhysicsFS error: %s", getLastPhysfsError()); + *status = SDL_IO_STATUS_ERROR; + } else { + *status = SDL_IO_STATUS_EOF; + } + } else { + *status = SDL_IO_STATUS_READY; + } -#if TARGET_SDL2 - return 0; -#else - return -1; -#endif - } /* if */ - } /* if */ - -#if TARGET_SDL2 - return (size_t) rc / size; -#else - return (int) rc / size; -#endif -} /* physfsrwops_read */ + return (size_t) rc; +} -#if TARGET_SDL2 -static size_t SDLCALL physfsrwops_write(struct SDL_RWops *rw, const void *ptr, - size_t size, size_t num) -#else -static int physfsrwops_write(SDL_RWops *rw, const void *ptr, int size, int num) -#endif +static size_t SDLCALL physfsrwops_write(void *userdata, const void *ptr, + size_t size, SDL_IOStatus *status) { - PHYSFS_File *handle = (PHYSFS_File *) rw->hidden.unknown.data1; - const PHYSFS_uint64 writelen = (PHYSFS_uint64) (num * size); + PHYSFS_File *handle = (PHYSFS_File *) userdata; + const PHYSFS_uint64 writelen = (PHYSFS_uint64) size; const PHYSFS_sint64 rc = PHYSFS_writeBytes(handle, ptr, writelen); - if (rc != ((PHYSFS_sint64) writelen)) + if (rc != ((PHYSFS_sint64) writelen)) { SDL_SetError("PhysicsFS error: %s", getLastPhysfsError()); + *status = SDL_IO_STATUS_ERROR; + } else { + *status = SDL_IO_STATUS_READY; + } -#if TARGET_SDL2 return (size_t) rc; -#else - return (int) rc; -#endif -} /* physfsrwops_write */ +} -static int physfsrwops_close(SDL_RWops *rw) +static bool physfsrwops_close(void *userdata) { - PHYSFS_File *handle = (PHYSFS_File *) rw->hidden.unknown.data1; + PHYSFS_File *handle = (PHYSFS_File *) userdata; if (!PHYSFS_close(handle)) { SDL_SetError("PhysicsFS error: %s", getLastPhysfsError()); - return -1; + return false; } /* if */ - SDL_FreeRW(rw); - return 0; -} /* physfsrwops_close */ + return true; +} + +static bool physfsrwops_flush(void *userdata, enum SDL_IOStatus *status) +{ + bool result = true; + PHYSFS_File *handle = (PHYSFS_File *) userdata; + if (!PHYSFS_flush(handle)) { + SDL_SetError("PhysicsFS error: %s", getLastPhysfsError()); + *status = SDL_IO_STATUS_ERROR; + result = false; + } else { + *status = SDL_IO_STATUS_READY; + } + return result; +} -static SDL_RWops *create_rwops(PHYSFS_File *handle) +static SDL_IOStream *create_rwops(PHYSFS_File *handle) { - SDL_RWops *retval = NULL; + SDL_IOStream *retval = NULL; - if (handle == NULL) + if (handle == NULL) { SDL_SetError("PhysicsFS error: %s", getLastPhysfsError()); - else - { - retval = SDL_AllocRW(); - if (retval != NULL) - { -#if TARGET_SDL2 - retval->size = physfsrwops_size; -#endif - retval->seek = physfsrwops_seek; - retval->read = physfsrwops_read; - retval->write = physfsrwops_write; - retval->close = physfsrwops_close; - retval->hidden.unknown.data1 = handle; - } /* if */ - } /* else */ + } else { + SDL_IOStreamInterface iface; + SDL_INIT_INTERFACE(&iface); + iface.size = physfsrwops_size; + iface.seek = physfsrwops_seek; + iface.read = physfsrwops_read; + iface.write = physfsrwops_write; + iface.close = physfsrwops_close; + iface.flush = physfsrwops_flush; + retval = SDL_OpenIO(&iface, handle); + } return retval; -} /* create_rwops */ +} -SDL_RWops *PHYSFSRWOPS_makeRWops(PHYSFS_File *handle) +SDL_IOStream *PHYSFSIO_makeRWops(PHYSFS_File *handle) { - SDL_RWops *retval = NULL; + SDL_IOStream *retval = NULL; if (handle == NULL) - SDL_SetError("NULL pointer passed to PHYSFSRWOPS_makeRWops()."); + SDL_SetError("NULL pointer passed to PHYSFSIO_makeRWops()."); else retval = create_rwops(handle); return retval; -} /* PHYSFSRWOPS_makeRWops */ +} -SDL_RWops *PHYSFSRWOPS_openRead(const char *fname) +SDL_IOStream *PHYSFSIO_openRead(const char *fname) { return create_rwops(PHYSFS_openRead(fname)); -} /* PHYSFSRWOPS_openRead */ +} -SDL_RWops *PHYSFSRWOPS_openWrite(const char *fname) +SDL_IOStream *PHYSFSIO_openWrite(const char *fname) { return create_rwops(PHYSFS_openWrite(fname)); -} /* PHYSFSRWOPS_openWrite */ +} -SDL_RWops *PHYSFSRWOPS_openAppend(const char *fname) +SDL_IOStream *PHYSFSIO_openAppend(const char *fname) { return create_rwops(PHYSFS_openAppend(fname)); -} /* PHYSFSRWOPS_openAppend */ - - -/* end of physfsrwops.c ... */ - +} diff --git a/src/physfsrwops.h b/src/physfsrwops.h index 54b08a7..9fb9157 100644 --- a/src/physfsrwops.h +++ b/src/physfsrwops.h @@ -25,7 +25,7 @@ #define _INCLUDE_PHYSFSRWOPS_H_ #include "physfs.h" -#include "SDL.h" +#include #ifdef __cplusplus extern "C" { @@ -33,51 +33,51 @@ extern "C" { /** * Open a platform-independent filename for reading, and make it accessible - * via an SDL_RWops structure. The file will be closed in PhysicsFS when the + * via an SDL_IOStream structure. The file will be closed in PhysicsFS when the * RWops is closed. PhysicsFS should be configured to your liking before * opening files through this method. * * @param filename File to open in platform-independent notation. - * @return A valid SDL_RWops structure on success, NULL on error. Specifics + * @return A valid SDL_IOStream structure on success, NULL on error. Specifics * of the error can be gleaned from PHYSFS_getLastError(). */ -PHYSFS_DECL SDL_RWops *PHYSFSRWOPS_openRead(const char *fname); +PHYSFS_DECL SDL_IOStream *PHYSFSIO_openRead(const char *fname); /** * Open a platform-independent filename for writing, and make it accessible - * via an SDL_RWops structure. The file will be closed in PhysicsFS when the + * via an SDL_IOStream structure. The file will be closed in PhysicsFS when the * RWops is closed. PhysicsFS should be configured to your liking before * opening files through this method. * * @param filename File to open in platform-independent notation. - * @return A valid SDL_RWops structure on success, NULL on error. Specifics + * @return A valid SDL_IOStream structure on success, NULL on error. Specifics * of the error can be gleaned from PHYSFS_getLastError(). */ -PHYSFS_DECL SDL_RWops *PHYSFSRWOPS_openWrite(const char *fname); +PHYSFS_DECL SDL_IOStream *PHYSFSIO_openWrite(const char *fname); /** * Open a platform-independent filename for appending, and make it accessible - * via an SDL_RWops structure. The file will be closed in PhysicsFS when the + * via an SDL_IOStream structure. The file will be closed in PhysicsFS when the * RWops is closed. PhysicsFS should be configured to your liking before * opening files through this method. * * @param filename File to open in platform-independent notation. - * @return A valid SDL_RWops structure on success, NULL on error. Specifics + * @return A valid SDL_IOStream structure on success, NULL on error. Specifics * of the error can be gleaned from PHYSFS_getLastError(). */ -PHYSFS_DECL SDL_RWops *PHYSFSRWOPS_openAppend(const char *fname); +PHYSFS_DECL SDL_IOStream *PHYSFSIO_openAppend(const char *fname); /** - * Make a SDL_RWops from an existing PhysicsFS file handle. You should + * Make a SDL_IOStream from an existing PhysicsFS file handle. You should * dispose of any references to the handle after successful creation of * the RWops. The actual PhysicsFS handle will be destroyed when the * RWops is closed. * * @param handle a valid PhysicsFS file handle. - * @return A valid SDL_RWops structure on success, NULL on error. Specifics + * @return A valid SDL_IOStream structure on success, NULL on error. Specifics * of the error can be gleaned from PHYSFS_getLastError(). */ -PHYSFS_DECL SDL_RWops *PHYSFSRWOPS_makeRWops(PHYSFS_File *handle); +PHYSFS_DECL SDL_IOStream *PHYSFSIO_makeRWops(PHYSFS_File *handle); #ifdef __cplusplus } diff --git a/src/player.h b/src/player.h index b8f3216..ff08948 100644 --- a/src/player.h +++ b/src/player.h @@ -17,7 +17,7 @@ */ #pragma once -#include +#include #include "sprite.h" #include "stats.h" #include "actiontext.h" diff --git a/src/pointer.c b/src/pointer.c index c2262d0..54fb54b 100644 --- a/src/pointer.c +++ b/src/pointer.c @@ -25,7 +25,7 @@ Pointer * pointer_create(SDL_Renderer *renderer) { - SDL_ShowCursor(SDL_DISABLE); + SDL_HideCursor(); Pointer *p = ec_malloc(sizeof(Pointer)); p->sprite = sprite_create(); @@ -63,7 +63,7 @@ pointer_render(Pointer *p, Camera *cam) void pointer_destroy(Pointer *p) { - SDL_ShowCursor(SDL_ENABLE); + SDL_ShowCursor(); sprite_destroy(p->sprite); free(p); diff --git a/src/pointer.h b/src/pointer.h index 8d97184..98fcae9 100644 --- a/src/pointer.h +++ b/src/pointer.h @@ -19,7 +19,7 @@ #ifndef POINTER_H_ #define POINTER_H_ -#include +#include #include "sprite.h" #include "camera.h" #include "input.h" diff --git a/src/roommatrix.c b/src/roommatrix.c index d75e6dc..328402a 100644 --- a/src/roommatrix.c +++ b/src/roommatrix.c @@ -80,7 +80,7 @@ RoomMatrix* roommatrix_create(SDL_Renderer *renderer) Texture *lm = texture_create(); lm->dim = (Dimension) { MAP_ROOM_WIDTH, MAP_ROOM_HEIGHT }; texture_create_blank(lm, SDL_TEXTUREACCESS_TARGET, renderer); - texture_set_scale_mode(lm, SDL_ScaleModeBest); + texture_set_scale_mode(lm, SDL_SCALEMODE_LINEAR); texture_set_blend_mode(lm, SDL_BLENDMODE_BLEND); m->lightmap = lm; @@ -277,7 +277,7 @@ roommatrix_build_lightmap(RoomMatrix *matrix, Camera *camera) for (j = 0; j < MAP_ROOM_HEIGHT; ++j) { light = (Uint8) matrix->spaces[i][j].light; SDL_SetRenderDrawColor(camera->renderer, 0, 0, 0, 255-light); - SDL_RenderDrawPoint(camera->renderer, i, j); + SDL_RenderPoint(camera->renderer, (float) i, (float) j); } } SDL_RenderPresent(camera->renderer); @@ -288,9 +288,9 @@ void roommatrix_render_mouse_square(RoomMatrix *matrix, Camera *cam) { Position mmc = position_to_matrix_coords(&matrix->mousePos); - SDL_Rect box = (SDL_Rect) { - mmc.x*TILE_DIMENSION, - mmc.y*TILE_DIMENSION, + SDL_FRect box = (SDL_FRect) { + (float) mmc.x*TILE_DIMENSION, + (float) mmc.y*TILE_DIMENSION, TILE_DIMENSION, TILE_DIMENSION }; diff --git a/src/screenresolution.c b/src/screenresolution.c index c26d22b..675b747 100644 --- a/src/screenresolution.c +++ b/src/screenresolution.c @@ -19,18 +19,19 @@ #include "defines.h" #include "util.h" -#include +#include #include "screenresolution.h" Dimension getScreenDimensions(void) { - SDL_DisplayMode dm; - if (SDL_GetCurrentDisplayMode(0, &dm) != 0) + SDL_DisplayID display = SDL_GetPrimaryDisplay(); + const SDL_DisplayMode *dm = SDL_GetCurrentDisplayMode(display); + if (dm == NULL) { - error("SDL_GetDesktopDisplayMode failed: %s", SDL_GetError()); + error("SDL_GetDesktopDisplayMode(%d) failed: %s", display, SDL_GetError()); } - Dimension dim = (Dimension) { dm.w, dm.h }; + Dimension dim = (Dimension) { dm->w, dm->h }; return dim; } diff --git a/src/skillbar.c b/src/skillbar.c index 961edad..cd61b19 100644 --- a/src/skillbar.c +++ b/src/skillbar.c @@ -239,16 +239,16 @@ render_activation_indicator(SkillBar *bar, Camera *cam) if (!timer_started(bar->activationTimer)) return; - unsigned int ticks = timer_get_ticks(bar->activationTimer); + Uint64 ticks = timer_get_ticks(bar->activationTimer); if (ticks > 500) { timer_stop(bar->activationTimer); return; } - SDL_Rect square = { (bar->lastActivation - 1) * 32, 0, 32, 32 }; + SDL_FRect square = { (float) (bar->lastActivation - 1) * 32, 0, 32, 32 }; unsigned int opacity = (unsigned int) ticks/2; SDL_SetRenderDrawColor(cam->renderer, 255, 255, 0, (Uint8)(255 - opacity)); - SDL_RenderDrawRect(cam->renderer, &square); + SDL_RenderRect(cam->renderer, &square); } static void @@ -265,7 +265,7 @@ render_skill_countdown(SkillBar *bar, int index, unsigned int count, Camera *cam static void render_skills(Player *player, Camera *cam) { - static SDL_Rect activeSkillBox = { 0, 0, 32, 32 }; + static SDL_FRect activeSkillBox = { 0, 0, 32, 32 }; for (int i = 0; i < PLAYER_SKILL_COUNT; ++i) { if (!player->skills[i]) @@ -279,7 +279,7 @@ render_skills(Player *player, Camera *cam) sprite_render(skill->icon, cam); if (player->skills[i]->active) { - activeSkillBox.x = i * 32; + activeSkillBox.x = (float) i * 32.0f; SDL_SetRenderDrawColor(cam->renderer, 0, 0, 255, 100); SDL_RenderFillRect(cam->renderer, &activeSkillBox); } @@ -301,7 +301,7 @@ render_artifacts(SkillBar *bar, Camera *cam) static void render_skill_unavailable(SkillBar *bar, Player *player, Camera *cam) { - static SDL_Rect unavailableSkillBox = { 0, 0, 32, 32 }; + static SDL_FRect unavailableSkillBox = { 0, 0, 32, 32 }; for (int i = 0; i < PLAYER_SKILL_COUNT; ++i) { bool unavailable = false; @@ -322,7 +322,7 @@ render_skill_unavailable(SkillBar *bar, Player *player, Camera *cam) } if (unavailable) { - unavailableSkillBox.x = i * 32; + unavailableSkillBox.x = (float) i * 32; SDL_SetRenderDrawColor(cam->renderer, UNPACK_COLOR(color)); SDL_RenderFillRect(cam->renderer, &unavailableSkillBox); if (skill->resetCountdown) { diff --git a/src/skillbar.h b/src/skillbar.h index cd3b839..27b9041 100644 --- a/src/skillbar.h +++ b/src/skillbar.h @@ -19,7 +19,7 @@ #ifndef SKILLBAR_H_ #define SKILLBAR_H_ -#include +#include #include "linkedlist.h" #include "camera.h" #include "timer.h" diff --git a/src/sprite.h b/src/sprite.h index 05a3670..bb27a05 100644 --- a/src/sprite.h +++ b/src/sprite.h @@ -45,7 +45,7 @@ typedef struct Sprite { Dimension dim; double angle; SDL_Point rotationPoint; - SDL_RendererFlip flip; + SDL_FlipMode flip; Timer *renderTimer; Timer *animationTimer; unsigned int texture_index; diff --git a/src/stats.c b/src/stats.c index 991b259..fbea05a 100644 --- a/src/stats.c +++ b/src/stats.c @@ -19,7 +19,7 @@ #include #include #include -#include +#include #include "gui.h" #include "stats.h" diff --git a/src/texture.c b/src/texture.c index 5f48033..76a7c45 100644 --- a/src/texture.c +++ b/src/texture.c @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -#include +#include #include #include #include @@ -76,12 +76,12 @@ texture_load_from_file(Texture *texture, const char *path, SDL_Renderer *renderer) { - SDL_Surface *surface = IMG_Load_RW(io_load_rwops(path), true); + SDL_Surface *surface = IMG_Load_IO(io_load_rwops(path), true); if (surface == NULL) { error("Failed to load texture (%s): %s", - path, IMG_GetError()); + path, SDL_GetError()); return; } @@ -103,8 +103,9 @@ texture_load_from_file(Texture *texture, texture->lastAccess = SDL_GetTicks(); texture->path = path; + SDL_SetTextureScaleMode(texture->texture, SDL_SCALEMODE_NEAREST); - SDL_FreeSurface(surface); + SDL_DestroySurface(surface); } void @@ -115,16 +116,16 @@ texture_load_font(Texture *t, const char *path, unsigned int size, int outline) if (t->outlineFont) TTF_CloseFont(t->outlineFont); - t->font = TTF_OpenFontRW(io_load_rwops(path), true, size); + t->font = TTF_OpenFontIO(io_load_rwops(path), true, (float) size); if (outline) { - t->outlineFont = TTF_OpenFontRW(io_load_rwops(path), true, size); + t->outlineFont = TTF_OpenFontIO(io_load_rwops(path), true, (float) size); TTF_SetFontOutline(t->outlineFont, outline); } if (t->font == NULL) { error("Failed to load font %s: %s", path, - TTF_GetError()); + SDL_GetError()); return; } t->path = path; @@ -148,7 +149,7 @@ load_from_surface(Texture *t, SDL_Surface *surface, SDL_Renderer *renderer) t->dim.width = surface->w; t->dim.height = surface->h; - SDL_FreeSurface(surface); + SDL_DestroySurface(surface); } void @@ -161,11 +162,11 @@ texture_load_from_text(Texture *t, SDL_Surface *bg_surface = NULL; SDL_Surface *fg_surface = NULL; if (t->outlineFont) { - bg_surface = TTF_RenderText_Blended(t->outlineFont, text, oc); - fg_surface = TTF_RenderText_Blended(t->font, text, c); + bg_surface = TTF_RenderText_Blended(t->outlineFont, text, 0, oc); + fg_surface = TTF_RenderText_Blended(t->font, text, 0, c); } else { - fg_surface = TTF_RenderText_Blended(t->font, text, c); + fg_surface = TTF_RenderText_Blended(t->font, text, 0, c); } SDL_Surface *surface = fg_surface; if (bg_surface) { @@ -174,13 +175,13 @@ texture_load_from_text(Texture *t, SDL_SetSurfaceBlendMode(fg_surface, SDL_BLENDMODE_BLEND); SDL_BlitSurface(fg_surface, NULL, bg_surface, &rect); surface = bg_surface; - SDL_FreeSurface(fg_surface); + SDL_DestroySurface(fg_surface); } if (surface == NULL) { error("Unable to create texture from rendered text: %s", - IMG_GetError()); + SDL_GetError()); return; } @@ -197,12 +198,13 @@ texture_load_from_text_shaded(Texture *t, { SDL_Surface *surface = TTF_RenderText_Shaded( t->font, text, + 0, fg, bg ); if (surface == NULL) { error("Unable to create texture from rendered text: %s", - IMG_GetError()); + SDL_GetError()); return; } @@ -212,11 +214,11 @@ texture_load_from_text_shaded(Texture *t, void texture_load_from_text_blended(Texture *t, const char * text, SDL_Color fg, SDL_Renderer *renderer) { - SDL_Surface *surface = TTF_RenderText_Blended( t->font, text, fg ); + SDL_Surface *surface = TTF_RenderText_Blended( t->font, text, 0, fg ); if (surface == NULL) { error("Unable to create texture from rendered text: %s", - IMG_GetError()); + SDL_GetError()); return; } @@ -259,26 +261,48 @@ texture_render_clip(Texture *texture, SDL_Rect *box, SDL_Rect *clip, Camera *cam if (!texture->texture) return; - SDL_RenderCopy(cam->renderer, + SDL_FRect fclip; + SDL_FRect fbox; + if (clip) + SDL_RectToFRect(clip, &fclip); + if (box) + SDL_RectToFRect(box, &fbox); + + SDL_RenderTexture(cam->renderer, texture->texture, - clip, - box); + clip ? &fclip : NULL, + box ? &fbox : NULL); texture->lastAccess = SDL_GetTicks(); } void -texture_render_clip_ex(Texture *texture, SDL_Rect *box, SDL_Rect *clip, double angle, SDL_Point *point, SDL_RendererFlip flipType, Camera *cam) +texture_render_clip_ex(Texture *texture, SDL_Rect *box, SDL_Rect *clip, double angle, SDL_Point *point, + SDL_FlipMode flipType, Camera *cam) { if (!texture->texture) return; - SDL_RenderCopyEx(cam->renderer, + + SDL_FRect fbox; + SDL_FRect fclip; + SDL_FPoint fpoint; + + if (box) + SDL_RectToFRect(box, &fbox); + if (clip) + SDL_RectToFRect(clip, &fclip); + if (point) { + fpoint.x = (float) point->x; + fpoint.y = (float) point->y; + } + + SDL_RenderTextureRotated(cam->renderer, texture->texture, - clip, - box, + clip ? &fclip : NULL, + box ? &fbox : NULL, angle, - point, + point ? &fpoint : NULL, flipType); texture->lastAccess = SDL_GetTicks(); diff --git a/src/texture.h b/src/texture.h index 7fde51a..862bd6f 100644 --- a/src/texture.h +++ b/src/texture.h @@ -19,8 +19,8 @@ #ifndef TEXTURE_H_ #define TEXTURE_H_ -#include -#include +#include +#include #include "dimension.h" #include "position.h" #include "camera.h" @@ -92,7 +92,8 @@ void texture_render_clip(Texture*, SDL_Rect*, SDL_Rect*, Camera*); void -texture_render_clip_ex(Texture*, SDL_Rect*, SDL_Rect*, double angle, SDL_Point*, SDL_RendererFlip, Camera*); +texture_render_clip_ex(Texture*, SDL_Rect*, SDL_Rect*, double angle, SDL_Point*, + SDL_FlipMode, Camera*); void texture_destroy(Texture *texture); diff --git a/src/texturecache.c b/src/texturecache.c index 7efdc0f..35ae795 100644 --- a/src/texturecache.c +++ b/src/texturecache.c @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -#include +#include #include #include "texturecache.h" #include "hashtable.h" diff --git a/src/texturecache.h b/src/texturecache.h index e5ac78a..95c444e 100644 --- a/src/texturecache.h +++ b/src/texturecache.h @@ -19,7 +19,7 @@ #ifndef TEXTURECACHE_H_ #define TEXTURECACHE_H_ -#include +#include #include "texture.h" void diff --git a/src/timer.c b/src/timer.c index ea83d03..ccf3022 100644 --- a/src/timer.c +++ b/src/timer.c @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -#include +#include #include #include "util.h" #include "timer.h" @@ -43,7 +43,7 @@ bool timer_started(Timer *t) return t->startTime != 0; } -unsigned int timer_get_ticks(Timer *t) +Uint64 timer_get_ticks(Timer *t) { if (!t->startTime) return 0; diff --git a/src/timer.h b/src/timer.h index 9cb2788..fe950c4 100644 --- a/src/timer.h +++ b/src/timer.h @@ -20,16 +20,17 @@ #define TIMER_H_ #include +#include typedef struct Timer { - unsigned int startTime; + Uint64 startTime; } Timer; Timer* _timer_create(void); void timer_start(Timer*); void timer_stop(Timer*); bool timer_started(Timer*); -unsigned int timer_get_ticks(Timer*); +Uint64 timer_get_ticks(Timer*); void timer_destroy(Timer*); #endif // TIMER_H_ diff --git a/src/trap.c b/src/trap.c index 126221f..0396406 100644 --- a/src/trap.c +++ b/src/trap.c @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -#include +#include #include "trap.h" #include "util.h" #include "gui.h" diff --git a/test/test_input.c b/test/test_input.c index a57f89c..7b711a9 100644 --- a/test/test_input.c +++ b/test/test_input.c @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -#include +#include #include #include #include @@ -32,18 +32,24 @@ test_event_parse(void **state) input_init(&input); SDL_KeyboardEvent event; - event.type = SDL_KEYDOWN; - event.keysym = (SDL_Keysym) { SDL_SCANCODE_W, SDLK_w, KMOD_NONE, 0 }; + event.type = SDL_EVENT_KEY_DOWN; + event.scancode = SDL_SCANCODE_W; + event.key = SDLK_W; + event.mod = SDL_KMOD_NONE; input_handle_event(&input, (SDL_Event*) &event); - event.keysym = (SDL_Keysym) { SDL_SCANCODE_0, SDLK_0, KMOD_NONE, 0 }; + event.scancode = SDL_SCANCODE_0; + event.key = SDLK_0; + event.mod = SDL_KMOD_NONE; input_handle_event(&input, (SDL_Event*) &event); assert_true(input_key_is_pressed(&input, KEY_UP)); assert_true(input_key_is_pressed(&input, KEY_NUM0)); - event.type = SDL_KEYUP; - event.keysym = (SDL_Keysym) { SDL_SCANCODE_0, SDLK_0, KMOD_NONE, 0 }; + event.type = SDL_EVENT_KEY_UP; + event.scancode = SDL_SCANCODE_0; + event.key = SDLK_0; + event.mod = SDL_KMOD_NONE; input_handle_event(&input, (SDL_Event*) &event); assert_true(input_key_is_pressed(&input, KEY_UP)); @@ -95,7 +101,7 @@ test_mousebuttons(void **state) input_init(&input); SDL_MouseButtonEvent event; - event.type = SDL_MOUSEBUTTONDOWN; + event.type = SDL_EVENT_MOUSE_BUTTON_DOWN; event.button = SDL_BUTTON_LEFT; input_handle_event(&input, (SDL_Event*) &event);