Update to SDL3 (#1283)

This commit is contained in:
Gustavo Ribeiro Croscato
2026-08-22 12:09:53 -04:00
committed by GitHub
parent 75ceaec54e
commit a8cc0ec12a
68 changed files with 786 additions and 704 deletions
+6 -6
View File
@@ -121,7 +121,7 @@ jobs:
runs-on: windows-latest runs-on: windows-latest
env: env:
SDL_VERSION: 2.26.0 SDL_VERSION: 3.4.0
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
@@ -134,23 +134,23 @@ jobs:
env: env:
cache-name: cache-sdl cache-name: cache-sdl
with: with:
path: C:\SDL2-* path: C:\SDL3-*
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ env.SDL_VERSION }} key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ env.SDL_VERSION }}
- if: ${{ steps.cache-windows-sdl.outputs.cache-hit != 'true' }} - if: ${{ steps.cache-windows-sdl.outputs.cache-hit != 'true' }}
name: Download SDL if not cached name: Download SDL if not cached
run: | run: |
Invoke-WebRequest "https://github.com/libsdl-org/SDL/releases/download/release-$env:SDL_VERSION/SDL2-devel-$env:SDL_VERSION-VC.zip" -OutFile C:\SDL.zip Invoke-WebRequest "https://github.com/libsdl-org/SDL/releases/download/release-$env:SDL_VERSION/SDL3-devel-$env:SDL_VERSION-VC.zip" -OutFile C:\SDL.zip
Expand-Archive C:\SDL.zip -DestinationPath C:\ Expand-Archive C:\SDL.zip -DestinationPath C:\
- name: CMake initial configure/generate - name: CMake initial configure/generate
run: | run: |
mkdir $env:SRC_DIR_PATH/build mkdir $env:SRC_DIR_PATH/build
cd $env:SRC_DIR_PATH/build cd $env:SRC_DIR_PATH/build
$env:LDFLAGS = "/LIBPATH:C:\SDL2-$env:SDL_VERSION\lib\x86 " $env:LDFLAGS = "/LIBPATH:C:\SDL3-$env:SDL_VERSION\lib\x86 "
cmake -G "Visual Studio 18 2026" -A Win32 ` cmake -G "Visual Studio 18 2026" -A Win32 `
-DSDL2_INCLUDE_DIRS="C:\SDL2-$env:SDL_VERSION\include" ` -DSDL3_INCLUDE_DIRS="C:\SDL3-$env:SDL_VERSION\include" `
-DSDL2_LIBRARIES="SDL2;SDL2main" .. -DSDL3_LIBRARIES="SDL3" ..
- name: CMake configure (default version) - name: CMake configure (default version)
run: | run: |
+48 -43
View File
@@ -3,6 +3,8 @@
cmake_minimum_required(VERSION 2.8.12...3.5) cmake_minimum_required(VERSION 2.8.12...3.5)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# CMake Options # CMake Options
option(ENABLE_WARNINGS "Enable compilation warnings" ON) option(ENABLE_WARNINGS "Enable compilation warnings" ON)
option(ENABLE_WERROR "Treat compilation warnings as errors" OFF) option(ENABLE_WERROR "Treat compilation warnings as errors" OFF)
@@ -28,7 +30,6 @@ endif()
option(REMOVE_ABSOLUTE_PATHS "If supported by the compiler, replace all absolute paths to source directories compiled into the binary (if any) with relative paths" ON) option(REMOVE_ABSOLUTE_PATHS "If supported by the compiler, replace all absolute paths to source directories compiled into the binary (if any) with relative paths" ON)
# Architecture Flags # Architecture Flags
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
# Wow, Apple is a huge jerk these days huh? # Wow, Apple is a huge jerk these days huh?
@@ -131,7 +132,7 @@ set(VVV_C_SRC
src/VFormat.c src/VFormat.c
src/Vlogging.c src/Vlogging.c
src/Xoshiro.c src/Xoshiro.c
../third_party/physfs/extras/physfsrwops.c ../third_party/physfs/extras/physfssdl3.c
) )
if(STEAM) if(STEAM)
list(APPEND VVV_C_SRC src/SteamNetwork.c) list(APPEND VVV_C_SRC src/SteamNetwork.c)
@@ -225,7 +226,7 @@ set(FAUDIO_SRC
../third_party/FAudio/src/FAudio_internal.c ../third_party/FAudio/src/FAudio_internal.c
../third_party/FAudio/src/FAudio_internal_simd.c ../third_party/FAudio/src/FAudio_internal_simd.c
../third_party/FAudio/src/FAudio_operationset.c ../third_party/FAudio/src/FAudio_operationset.c
../third_party/FAudio/src/FAudio_platform_sdl2.c ../third_party/FAudio/src/FAudio_platform_sdl3.c
) )
set(PFS_SRC set(PFS_SRC
../third_party/physfs/src/physfs.c ../third_party/physfs/src/physfs.c
@@ -383,15 +384,19 @@ if(BUNDLE_DEPENDENCIES)
../third_party/FAudio/include ../third_party/FAudio/include
) )
# Disable FAudio debug stuff in release mode. This needs a generator expression for CMake reasons(TM) # Disable FAudio debug stuff in release mode. This needs a generator expression for CMake reasons(TM)
target_compile_definitions(faudio-static PRIVATE $<$<CONFIG:Release>:FAUDIO_DISABLE_DEBUGCONFIGURATION>) target_compile_definitions(faudio-static
PRIVATE
$<$<CONFIG:Release>:FAUDIO_DISABLE_DEBUGCONFIGURATION>
-DFAUDIO_SDL3_PLATFORM
)
target_link_libraries(VVVVVV ${STATIC_LIBRARIES}) target_link_libraries(VVVVVV PUBLIC ${STATIC_LIBRARIES})
else() else()
target_compile_definitions(VVVVVV PRIVATE target_compile_definitions(VVVVVV PRIVATE
${PNG_DEF} ${PNG_DEF}
-DSYSTEM_LODEPNG -DSYSTEM_LODEPNG
) )
target_link_libraries(VVVVVV ${STATIC_LIBRARIES} physfs tinyxml2 FAudio lodepng) target_link_libraries(VVVVVV PUBLIC ${STATIC_LIBRARIES} physfs tinyxml2 FAudio lodepng)
endif() endif()
@@ -444,54 +449,54 @@ foreach(static_library IN LISTS STATIC_LIBRARIES)
endforeach(static_library) endforeach(static_library)
# SDL2 Dependency (Detection pulled from FAudio) # SDL3 Dependency (Detection pulled from FAudio)
if(DEFINED SDL2_INCLUDE_DIRS AND DEFINED SDL2_LIBRARIES) if(DEFINED SDL3_INCLUDE_DIRS AND DEFINED SDL3_LIBRARIES)
message(STATUS "Using pre-defined SDL2 variables SDL2_INCLUDE_DIRS and SDL2_LIBRARIES") message(STATUS "Using pre-defined SDL3 variables SDL3_INCLUDE_DIRS and SDL3_LIBRARIES")
target_include_directories(VVVVVV SYSTEM PRIVATE "$<BUILD_INTERFACE:${SDL2_INCLUDE_DIRS}>") target_include_directories(VVVVVV SYSTEM PRIVATE "$<BUILD_INTERFACE:${SDL3_INCLUDE_DIRS}>")
target_link_libraries(VVVVVV ${SDL2_LIBRARIES}) target_link_libraries(VVVVVV PUBLIC ${SDL3_LIBRARIES})
if(BUNDLE_DEPENDENCIES) if(BUNDLE_DEPENDENCIES)
target_include_directories(faudio-static SYSTEM PRIVATE "$<BUILD_INTERFACE:${SDL2_INCLUDE_DIRS}>") target_include_directories(faudio-static SYSTEM PRIVATE "$<BUILD_INTERFACE:${SDL3_INCLUDE_DIRS}>")
target_link_libraries(faudio-static ${SDL2_LIBRARIES}) target_link_libraries(faudio-static ${SDL3_LIBRARIES})
endif() endif()
elseif (EMSCRIPTEN) elseif (EMSCRIPTEN)
message(STATUS "Using Emscripten SDL2") message(STATUS "Using Emscripten SDL3")
target_compile_options(VVVVVV PUBLIC -sUSE_SDL=2) target_compile_options(VVVVVV PUBLIC -sUSE_SDL=3)
target_link_libraries(VVVVVV -sUSE_SDL=2) target_link_libraries(VVVVVV PUBLIC -sUSE_SDL=3)
if(BUNDLE_DEPENDENCIES) if(BUNDLE_DEPENDENCIES)
target_compile_options(faudio-static PUBLIC -sUSE_SDL=2) target_compile_options(faudio-static PUBLIC -sUSE_SDL=3)
target_link_libraries(faudio-static -sUSE_SDL=2) target_link_libraries(faudio-static PUBLIC -sUSE_SDL=3)
endif() endif()
elseif(DEFINED SDL2_FRAMEWORK) elseif(DEFINED SDL3_FRAMEWORK)
message(STATUS "Using pre-defined SDL2 variable SDL2_FRAMEWORK") message(STATUS "Using pre-defined SDL3 variable SDL3_FRAMEWORK")
target_include_directories(VVVVVV SYSTEM PRIVATE "$<BUILD_INTERFACE:${SDL2_FRAMEWORK}/Headers>") target_include_directories(VVVVVV SYSTEM PRIVATE "$<BUILD_INTERFACE:${SDL3_FRAMEWORK}/Headers>")
target_link_libraries(VVVVVV ${SDL2_FRAMEWORK}) target_link_libraries(VVVVVV PUBLIC ${SDL3_FRAMEWORK})
if(BUNDLE_DEPENDENCIES) if(BUNDLE_DEPENDENCIES)
target_include_directories(faudio-static SYSTEM PRIVATE "$<BUILD_INTERFACE:${SDL2_FRAMEWORK}/Headers>") target_include_directories(faudio-static SYSTEM PRIVATE "$<BUILD_INTERFACE:${SDL3_FRAMEWORK}/Headers>")
target_link_libraries(faudio-static ${SDL2_FRAMEWORK}) target_link_libraries(faudio-static PUBLIC ${SDL3_FRAMEWORK})
endif() endif()
set_target_properties(VVVVVV PROPERTIES XCODE_EMBED_FRAMEWORKS ${SDL2_FRAMEWORK}) set_target_properties(VVVVVV PROPERTIES XCODE_EMBED_FRAMEWORKS ${SDL3_FRAMEWORK})
else() else()
# Only try to autodetect if both SDL2 variables aren't explicitly set # Only try to autodetect if both SDL3 variables aren't explicitly set
find_package(SDL2 CONFIG) find_package(SDL3 CONFIG)
if(TARGET SDL2::SDL2) if(TARGET SDL3::SDL3)
message(STATUS "Using TARGET SDL2::SDL2") message(STATUS "Using TARGET SDL3::SDL3")
target_link_libraries(VVVVVV SDL2::SDL2) target_link_libraries(VVVVVV PUBLIC SDL3::SDL3)
if(BUNDLE_DEPENDENCIES) if(BUNDLE_DEPENDENCIES)
target_link_libraries(faudio-static SDL2::SDL2) target_link_libraries(faudio-static PUBLIC SDL3::SDL3)
endif() endif()
elseif(TARGET SDL2) elseif(TARGET SDL3)
message(STATUS "Using TARGET SDL2") message(STATUS "Using TARGET SDL3")
target_link_libraries(VVVVVV SDL2) target_link_libraries(VVVVVV PUBLIC SDL3)
if(BUNDLE_DEPENDENCIES) if(BUNDLE_DEPENDENCIES)
target_link_libraries(faudio-static SDL2) target_link_libraries(faudio-static PUBLIC SDL3)
endif() endif()
else() else()
message(STATUS "No TARGET SDL2::SDL2, or SDL2, using variables") message(STATUS "No TARGET SDL3::SDL3, or SDL3, using variables")
target_include_directories(VVVVVV SYSTEM PRIVATE "$<BUILD_INTERFACE:${SDL2_INCLUDE_DIRS}>") target_include_directories(VVVVVV SYSTEM PRIVATE "$<BUILD_INTERFACE:${SDL3_INCLUDE_DIRS}>")
target_link_libraries(VVVVVV ${SDL2_LIBRARIES}) target_link_libraries(VVVVVV PUBLIC ${SDL3_LIBRARIES})
if(BUNDLE_DEPENDENCIES) if(BUNDLE_DEPENDENCIES)
target_include_directories(faudio-static SYSTEM PRIVATE "$<BUILD_INTERFACE:${SDL2_INCLUDE_DIRS}>") target_include_directories(faudio-static SYSTEM PRIVATE "$<BUILD_INTERFACE:${SDL3_INCLUDE_DIRS}>")
target_link_libraries(faudio-static ${SDL2_LIBRARIES}) target_link_libraries(faudio-static PUBLIC ${SDL3_LIBRARIES})
endif() endif()
endif() endif()
endif() endif()
@@ -500,15 +505,15 @@ endif()
if(APPLE) if(APPLE)
find_library(FOUNDATION NAMES Foundation) find_library(FOUNDATION NAMES Foundation)
find_library(IOKIT NAMES IOKit) find_library(IOKIT NAMES IOKit)
target_link_libraries(VVVVVV objc ${IOKIT} ${FOUNDATION}) target_link_libraries(VVVVVV PUBLIC objc ${IOKIT} ${FOUNDATION})
endif() endif()
# But hey, also some Haiku crap # But hey, also some Haiku crap
if(HAIKU) if(HAIKU)
find_library(BE_LIBRARY be) find_library(BE_LIBRARY be)
find_library(ROOT_LIBRARY root) find_library(ROOT_LIBRARY root)
target_link_libraries(VVVVVV ${BE_LIBRARY} ${ROOT_LIBRARY}) target_link_libraries(VVVVVV PUBLIC ${BE_LIBRARY} ${ROOT_LIBRARY})
endif() endif()
if(EMSCRIPTEN) if(EMSCRIPTEN)
# 256MB is enough for everybody # 256MB is enough for everybody
target_link_libraries(VVVVVV -sFORCE_FILESYSTEM=1 -sTOTAL_MEMORY=256MB) target_link_libraries(VVVVVV PUBLIC -sFORCE_FILESYSTEM=1 -sTOTAL_MEMORY=256MB)
endif() endif()
+17 -22
View File
@@ -1,31 +1,26 @@
FROM centos:7 FROM rockylinux:9
# run first to improve caching (other things update more often than SDL2) # run first to improve caching (other things update more often than SDL3)
WORKDIR /tmp WORKDIR /tmp
RUN curl -LJO https://github.com/libsdl-org/SDL/releases/download/release-2.24.0/SDL2-2.24.0.tar.gz RUN curl -LJO https://github.com/libsdl-org/SDL/releases/download/release-3.4.12/SDL3-3.4.12.tar.gz
RUN tar -xf SDL2-2.24.0.tar.gz RUN tar -xf SDL3-3.4.12.tar.gz
RUN mkdir SDL2-2.24.0/build RUN mkdir SDL3-3.4.12/build
# add EPEL (for SDL2)
RUN yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
# install dependencies # install dependencies
RUN yum -y install \ RUN dnf --assumeyes upgrade --refresh
# used below RUN dnf --assumeyes group install development
yum-utils \ RUN dnf --assumeyes install cmake
# VVVVVV dependencies RUN dnf --assumeyes install libX11-devel libICE-devel libSM-devel \
gcc-c++ cmake make libXScrnSaver-devel libXext-devel libXft-devel libXi-devel \
libXinerama-devel libXmu-devel libXp-devel libXpm-devel \
libXrandr-devel libXrender-devel libXt-devel libXtst-devel \
libXv-devel libXxf86dga-devel libxkbcommon-devel libXcursor-devel
RUN yum-builddep -y SDL2 WORKDIR /tmp/SDL3-3.4.12/build
RUN cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr ..
RUN yum clean all RUN cmake --build . --target install -- -j $(nproc)
WORKDIR /tmp/SDL2-2.24.0/build
RUN ../configure
RUN make -j $(nproc)
RUN make install
WORKDIR /tmp WORKDIR /tmp
RUN rm -rf SDL2-2.24.0.tar.gz SDL2-2.24.0/ RUN rm -rf SDL3-3.4.12.tar.gz SDL3-3.4.12/
WORKDIR / WORKDIR /
+1 -1
View File
@@ -1,6 +1,6 @@
#include "BinaryBlob.h" #include "BinaryBlob.h"
#include <SDL.h> #include <SDL3/SDL.h>
#ifdef VVV_COMPILEMUSIC #ifdef VVV_COMPILEMUSIC
#include <stdio.h> #include <stdio.h>
#endif #endif
+1 -1
View File
@@ -1,6 +1,6 @@
#include "BlockV.h" #include "BlockV.h"
#include <SDL_stdinc.h> #include <SDL3/SDL_stdinc.h>
#include "Script.h" #include "Script.h"
#include "Font.h" #include "Font.h"
+1 -1
View File
@@ -1,7 +1,7 @@
#ifndef BLOCKV_H #ifndef BLOCKV_H
#define BLOCKV_H #define BLOCKV_H
#include <SDL.h> #include <SDL3/SDL.h>
#include <stdint.h> #include <stdint.h>
#include <string> #include <string>
+14 -14
View File
@@ -1,6 +1,6 @@
#include "ButtonGlyphs.h" #include "ButtonGlyphs.h"
#include <SDL.h> #include <SDL3/SDL.h>
#include "Game.h" #include "Game.h"
#include "Localization.h" #include "Localization.h"
@@ -96,7 +96,7 @@ ButtonGlyphLayout;
/* SDL provides Xbox buttons, we'd like to show the correct /* SDL provides Xbox buttons, we'd like to show the correct
* (controller-specific) glyphs or labels for those... */ * (controller-specific) glyphs or labels for those... */
static const char* glyph_layout[LAYOUT_TOTAL][SDL_CONTROLLER_BUTTON_RIGHTSHOULDER + 1] = { static const char* glyph_layout[LAYOUT_TOTAL][SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER + 1] = {
{ // NINTENDO_SWITCH_PRO { // NINTENDO_SWITCH_PRO
glyph[GLYPH_NINTENDO_DECK_B], glyph[GLYPH_NINTENDO_DECK_A], glyph[GLYPH_NINTENDO_DECK_B], glyph[GLYPH_NINTENDO_DECK_A],
glyph[GLYPH_NINTENDO_DECK_Y], glyph[GLYPH_NINTENDO_DECK_X], glyph[GLYPH_NINTENDO_DECK_Y], glyph[GLYPH_NINTENDO_DECK_X],
@@ -178,10 +178,10 @@ bool BUTTONGLYPHS_keyboard_is_available(void)
return true; return true;
} }
#if defined(__ANDROID__) || TARGET_OS_IPHONE #if defined(SDL_PLATFORM_ANDROID) || TARGET_OS_IPHONE
return false; return false;
#else #else
return !SDL_GetHintBoolean("SteamDeck", SDL_FALSE); return !SDL_GetHintBoolean("SteamDeck", false);
#endif #endif
} }
@@ -197,10 +197,10 @@ void BUTTONGLYPHS_keyboard_set_active(bool active)
keyboard_is_active = active; keyboard_is_active = active;
} }
void BUTTONGLYPHS_update_layout(SDL_GameController *c) void BUTTONGLYPHS_update_layout(SDL_Gamepad *c)
{ {
Uint16 vendor = SDL_GameControllerGetVendor(c); Uint16 vendor = SDL_GetGamepadVendor(c);
Uint16 product = SDL_GameControllerGetProduct(c); Uint16 product = SDL_GetGamepadProduct(c);
if (vendor == 0x054c) if (vendor == 0x054c)
{ {
@@ -210,10 +210,10 @@ void BUTTONGLYPHS_update_layout(SDL_GameController *c)
{ {
/* Steam Virtual Gamepads can hypothetically tell us that the physical /* Steam Virtual Gamepads can hypothetically tell us that the physical
* device is a PlayStation controller, so try to catch that scenario */ * device is a PlayStation controller, so try to catch that scenario */
SDL_GameControllerType gct = SDL_GameControllerGetType(c); SDL_GamepadType gct = SDL_GetGamepadType(c);
if ( gct == SDL_CONTROLLER_TYPE_PS3 || if ( gct == SDL_GAMEPAD_TYPE_PS3 ||
gct == SDL_CONTROLLER_TYPE_PS4 || gct == SDL_GAMEPAD_TYPE_PS4 ||
gct == SDL_CONTROLLER_TYPE_PS5 ) gct == SDL_GAMEPAD_TYPE_PS5 )
{ {
layout = LAYOUT_PLAYSTATION; layout = LAYOUT_PLAYSTATION;
} }
@@ -272,9 +272,9 @@ const char* BUTTONGLYPHS_get_wasd_text(void)
return loc::gettext("Press left/right to move"); return loc::gettext("Press left/right to move");
} }
const char* BUTTONGLYPHS_sdlbutton_to_glyph(const SDL_GameControllerButton button) const char* BUTTONGLYPHS_sdlbutton_to_glyph(const SDL_GamepadButton button)
{ {
if (button < 0 || button > SDL_CONTROLLER_BUTTON_RIGHTSHOULDER) if (button < 0 || button > SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER)
{ {
SDL_assert(0 && "Unhandled button!"); SDL_assert(0 && "Unhandled button!");
return glyph[GLYPH_UNKNOWN]; return glyph[GLYPH_UNKNOWN];
@@ -284,7 +284,7 @@ const char* BUTTONGLYPHS_sdlbutton_to_glyph(const SDL_GameControllerButton butto
} }
static const char* glyph_for_vector( static const char* glyph_for_vector(
const std::vector<SDL_GameControllerButton>& buttons, const std::vector<SDL_GamepadButton>& buttons,
const int index const int index
) { ) {
if (index < 0 || index >= (int) buttons.size()) if (index < 0 || index >= (int) buttons.size())
+3 -3
View File
@@ -1,7 +1,7 @@
#ifndef BUTTONGLYPHS_H #ifndef BUTTONGLYPHS_H
#define BUTTONGLYPHS_H #define BUTTONGLYPHS_H
#include <SDL.h> #include <SDL3/SDL.h>
#include <stdbool.h> #include <stdbool.h>
#include "ActionSets.h" #include "ActionSets.h"
@@ -17,10 +17,10 @@ bool BUTTONGLYPHS_keyboard_is_available(void);
bool BUTTONGLYPHS_keyboard_is_active(void); bool BUTTONGLYPHS_keyboard_is_active(void);
void BUTTONGLYPHS_keyboard_set_active(bool active); void BUTTONGLYPHS_keyboard_set_active(bool active);
void BUTTONGLYPHS_update_layout(SDL_GameController *c); void BUTTONGLYPHS_update_layout(SDL_Gamepad *c);
const char* BUTTONGLYPHS_get_wasd_text(void); const char* BUTTONGLYPHS_get_wasd_text(void);
const char* BUTTONGLYPHS_sdlbutton_to_glyph(SDL_GameControllerButton button); const char* BUTTONGLYPHS_sdlbutton_to_glyph(SDL_GamepadButton button);
const char* BUTTONGLYPHS_get_button(ActionSet actionset, Action action, int binding); const char* BUTTONGLYPHS_get_button(ActionSet actionset, Action action, int binding);
char* BUTTONGLYPHS_get_all_gamepad_buttons( char* BUTTONGLYPHS_get_all_gamepad_buttons(
+1 -1
View File
@@ -1,6 +1,6 @@
#include "CWrappers.h" #include "CWrappers.h"
#include <SDL.h> #include <SDL3/SDL.h>
#include "Graphics.h" #include "Graphics.h"
#include "GraphicsUtil.h" #include "GraphicsUtil.h"
+1 -1
View File
@@ -1,7 +1,7 @@
#ifndef CWRAPPERS_H #ifndef CWRAPPERS_H
#define CWRAPPERS_H #define CWRAPPERS_H
#include <SDL_surface.h> #include <SDL3/SDL_surface.h>
#include <stdint.h> #include <stdint.h>
#ifdef __cplusplus #ifdef __cplusplus
+1 -1
View File
@@ -1,7 +1,7 @@
#ifndef CREDITS_H #ifndef CREDITS_H
#define CREDITS_H #define CREDITS_H
#include <SDL.h> #include <SDL3/SDL.h>
namespace Credits { namespace Credits {
+7 -4
View File
@@ -1337,7 +1337,7 @@ next:
if (name != NULL) if (name != NULL)
{ {
SDL_Colour colour; SDL_Color colour;
colour.r = r; colour.r = r;
colour.g = g; colour.g = g;
colour.b = b; colour.b = b;
@@ -1726,8 +1726,8 @@ void customlevelclass::generatecustomminimap(void)
{ {
for (int i2 = data.startx; i2 < data.startx + data.width; i2++) for (int i2 = data.startx; i2 < data.startx + data.width; i2++)
{ {
std::vector<SDL_Point> dark_points; std::vector<SDL_FPoint> dark_points;
std::vector<SDL_Point> light_points; std::vector<SDL_FPoint> light_points;
bool dark = getroomprop(i2, j2)->tileset == 1; bool dark = getroomprop(i2, j2)->tileset == 1;
@@ -1762,7 +1762,10 @@ void customlevelclass::generatecustomminimap(void)
if (tile >= 1) if (tile >= 1)
{ {
// Add this pixel // Add this pixel
SDL_Point point = { ((i2 - data.startx) * 12 * data.zoom) + i, ((j2 - data.starty) * 9 * data.zoom) + j }; SDL_FPoint point = {
static_cast<float>(((i2 - data.startx) * 12 * data.zoom) + i),
static_cast<float>(((j2 - data.starty) * 9 * data.zoom) + j)
};
if (dark) if (dark)
{ {
dark_points.push_back(point); dark_points.push_back(point);
+1 -1
View File
@@ -1,7 +1,7 @@
#ifndef CUSTOMLEVELS_H #ifndef CUSTOMLEVELS_H
#define CUSTOMLEVELS_H #define CUSTOMLEVELS_H
#include <SDL.h> #include <SDL3/SDL.h>
#include <string> #include <string>
#include <vector> #include <vector>
+1 -1
View File
@@ -1,6 +1,6 @@
#include "DeferCallbacks.h" #include "DeferCallbacks.h"
#include <SDL.h> #include <SDL3/SDL.h>
/* Callbacks to be deferred to the end of each sequence of gamestate functions /* Callbacks to be deferred to the end of each sequence of gamestate functions
* in main. Useful for fixing frame-flicker glitches when doing a state * in main. Useful for fixing frame-flicker glitches when doing a state
+35 -35
View File
@@ -41,13 +41,13 @@ editorclass::editorclass(void)
register_tool(EditorTool_MOVING_PLATFORMS, "Moving Platforms", "8", SDLK_8, false); register_tool(EditorTool_MOVING_PLATFORMS, "Moving Platforms", "8", SDLK_8, false);
register_tool(EditorTool_ENEMIES, "Enemies", "9", SDLK_9, false); register_tool(EditorTool_ENEMIES, "Enemies", "9", SDLK_9, false);
register_tool(EditorTool_GRAVITY_LINES, "Gravity Lines", "0", SDLK_0, false); register_tool(EditorTool_GRAVITY_LINES, "Gravity Lines", "0", SDLK_0, false);
register_tool(EditorTool_ROOMTEXT, "Roomtext", "R", SDLK_r, false); register_tool(EditorTool_ROOMTEXT, "Roomtext", "R", SDLK_R, false);
register_tool(EditorTool_TERMINALS, "Terminals", "T", SDLK_t, false); register_tool(EditorTool_TERMINALS, "Terminals", "T", SDLK_T, false);
register_tool(EditorTool_SCRIPTS, "Script Boxes", "Y", SDLK_y, false); register_tool(EditorTool_SCRIPTS, "Script Boxes", "Y", SDLK_Y, false);
register_tool(EditorTool_WARP_TOKENS, "Warp Tokens", "U", SDLK_u, false); register_tool(EditorTool_WARP_TOKENS, "Warp Tokens", "U", SDLK_U, false);
register_tool(EditorTool_WARP_LINES, "Warp Lines", "I", SDLK_i, false); register_tool(EditorTool_WARP_LINES, "Warp Lines", "I", SDLK_I, false);
register_tool(EditorTool_CREWMATES, "Crewmates", "O", SDLK_o, false); register_tool(EditorTool_CREWMATES, "Crewmates", "O", SDLK_O, false);
register_tool(EditorTool_START_POINT, "Start Point", "P", SDLK_p, false); register_tool(EditorTool_START_POINT, "Start Point", "P", SDLK_P, false);
static const short basic[] = { static const short basic[] = {
121, 121, 121, 121, 121, 121, 121, 160, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 160, 121, 121, 121, 121, 121, 121, 121,
@@ -425,7 +425,7 @@ void editorclass::show_note(const char* text)
note = text; note = text;
} }
void editorclass::register_tool(EditorTools tool, const char* name, const char* keychar, const SDL_KeyCode key, const bool shift) void editorclass::register_tool(EditorTools tool, const char* name, const char* keychar, const SDL_Keycode key, const bool shift)
{ {
tool_names[tool] = name; tool_names[tool] = name;
tool_key_chars[tool] = keychar; tool_key_chars[tool] = keychar;
@@ -1313,35 +1313,35 @@ static void draw_cursor(void)
{ {
top_left = false; top_left = false;
bottom_left = false; bottom_left = false;
SDL_RenderDrawLine(gameScreen.m_renderer, x * 8, y * 8, x * 8, y * 8 + 7); SDL_RenderLine(gameScreen.m_renderer, x * 8, y * 8, x * 8, y * 8 + 7);
} }
if (!check_point(connected, x + 1, y)) if (!check_point(connected, x + 1, y))
{ {
top_right = false; top_right = false;
bottom_right = false; bottom_right = false;
SDL_RenderDrawLine(gameScreen.m_renderer, x * 8 + 7, y * 8, x * 8 + 7, y * 8 + 7); SDL_RenderLine(gameScreen.m_renderer, x * 8 + 7, y * 8, x * 8 + 7, y * 8 + 7);
} }
if (!check_point(connected, x, y - 1)) if (!check_point(connected, x, y - 1))
{ {
top_left = false; top_left = false;
top_right = false; top_right = false;
SDL_RenderDrawLine(gameScreen.m_renderer, x * 8, y * 8, x * 8 + 7, y * 8); SDL_RenderLine(gameScreen.m_renderer, x * 8, y * 8, x * 8 + 7, y * 8);
} }
if (!check_point(connected, x, y + 1)) if (!check_point(connected, x, y + 1))
{ {
bottom_left = false; bottom_left = false;
bottom_right = false; bottom_right = false;
SDL_RenderDrawLine(gameScreen.m_renderer, x * 8, y * 8 + 7, x * 8 + 7, y * 8 + 7); SDL_RenderLine(gameScreen.m_renderer, x * 8, y * 8 + 7, x * 8 + 7, y * 8 + 7);
} }
if (!check_point(connected, x - 1, y - 1) && top_left) if (!check_point(connected, x - 1, y - 1) && top_left)
SDL_RenderDrawPoint(gameScreen.m_renderer, x * 8, y * 8); SDL_RenderPoint(gameScreen.m_renderer, x * 8, y * 8);
if (!check_point(connected, x - 1, y + 1) && top_right) if (!check_point(connected, x - 1, y + 1) && top_right)
SDL_RenderDrawPoint(gameScreen.m_renderer, x * 8, y * 8 + 7); SDL_RenderPoint(gameScreen.m_renderer, x * 8, y * 8 + 7);
if (!check_point(connected, x + 1, y - 1) && bottom_left) if (!check_point(connected, x + 1, y - 1) && bottom_left)
SDL_RenderDrawPoint(gameScreen.m_renderer, x * 8 + 7, y * 8); SDL_RenderPoint(gameScreen.m_renderer, x * 8 + 7, y * 8);
if (!check_point(connected, x + 1, y + 1) && bottom_right) if (!check_point(connected, x + 1, y + 1) && bottom_right)
SDL_RenderDrawPoint(gameScreen.m_renderer, x * 8 + 7, y * 8 + 7); SDL_RenderPoint(gameScreen.m_renderer, x * 8 + 7, y * 8 + 7);
} }
} }
else if (ed.b_modifier) graphics.draw_rect(x, 0, 8, 240, blue); // Vertical else if (ed.b_modifier) graphics.draw_rect(x, 0, 8, 240, blue); // Vertical
@@ -1414,7 +1414,7 @@ static void draw_tile_drawer(int tileset)
int texturewidth; int texturewidth;
int textureheight; int textureheight;
if (graphics.query_texture(graphics.grphx.im_tiles, NULL, NULL, &texturewidth, &textureheight) != 0) if (!graphics.query_texture(graphics.grphx.im_tiles, NULL, NULL, &texturewidth, &textureheight))
{ {
return; return;
} }
@@ -3201,20 +3201,20 @@ static void handle_draw_input()
} }
} }
if (key.keymap[SDLK_w]) if (key.keymap[SDLK_W])
{ {
commit_roomdata_change(); commit_roomdata_change();
ed.switch_warpdir(shift_down); ed.switch_warpdir(shift_down);
ed.keydelay = 6; ed.keydelay = 6;
} }
if (key.keymap[SDLK_e]) if (key.keymap[SDLK_E])
{ {
commit_roomdata_change(); commit_roomdata_change();
ed.keydelay = 6; ed.keydelay = 6;
ed.get_input_line(TEXT_ROOMNAME, "Enter new room name:", const_cast<std::string*>(&(cl.getroomprop(ed.levx, ed.levy)->roomname))); ed.get_input_line(TEXT_ROOMNAME, "Enter new room name:", const_cast<std::string*>(&(cl.getroomprop(ed.levx, ed.levy)->roomname)));
game.mapheld = true; game.mapheld = true;
} }
if (key.keymap[SDLK_g]) if (key.keymap[SDLK_G])
{ {
ed.keydelay = 6; ed.keydelay = 6;
ed.get_input_line(TEXT_GOTOROOM, "Enter room coordinates x,y:", NULL); ed.get_input_line(TEXT_GOTOROOM, "Enter room coordinates x,y:", NULL);
@@ -3222,27 +3222,27 @@ static void handle_draw_input()
} }
//Save and load //Save and load
if (key.keymap[SDLK_s]) if (key.keymap[SDLK_S])
{ {
ed.keydelay = 6; ed.keydelay = 6;
ed.get_input_line(TEXT_SAVE, "Enter map filename to save as:", &(ed.filename)); ed.get_input_line(TEXT_SAVE, "Enter map filename to save as:", &(ed.filename));
game.mapheld = true; game.mapheld = true;
} }
if (key.keymap[SDLK_l]) if (key.keymap[SDLK_L])
{ {
ed.keydelay = 6; ed.keydelay = 6;
ed.get_input_line(TEXT_LOAD, "Enter map filename to load:", &(ed.filename)); ed.get_input_line(TEXT_LOAD, "Enter map filename to load:", &(ed.filename));
game.mapheld = true; game.mapheld = true;
} }
ed.f_modifier = key.keymap[SDLK_f]; ed.f_modifier = key.keymap[SDLK_F];
ed.h_modifier = key.keymap[SDLK_h]; ed.h_modifier = key.keymap[SDLK_H];
ed.v_modifier = key.keymap[SDLK_v]; ed.v_modifier = key.keymap[SDLK_V];
ed.b_modifier = key.keymap[SDLK_b]; ed.b_modifier = key.keymap[SDLK_B];
ed.c_modifier = key.keymap[SDLK_c]; ed.c_modifier = key.keymap[SDLK_C];
ed.x_modifier = key.keymap[SDLK_x]; ed.x_modifier = key.keymap[SDLK_X];
ed.z_modifier = key.keymap[SDLK_z]; ed.z_modifier = key.keymap[SDLK_Z];
const int room = ed.levx + ed.levy * cl.maxwidth; const int room = ed.levx + ed.levy * cl.maxwidth;
const int plat_speed = cl.roomproperties[room].platv; const int plat_speed = cl.roomproperties[room].platv;
@@ -3486,10 +3486,10 @@ void editorinput(void)
ed.tilex = SDL_clamp(key.mousex, 0, SCREEN_WIDTH_PIXELS - 1) / 8; ed.tilex = SDL_clamp(key.mousex, 0, SCREEN_WIDTH_PIXELS - 1) / 8;
ed.tiley = SDL_clamp(key.mousey, 0, SCREEN_HEIGHT_PIXELS - 1) / 8; ed.tiley = SDL_clamp(key.mousey, 0, SCREEN_HEIGHT_PIXELS - 1) / 8;
bool up_pressed = key.isDown(SDLK_UP) || key.isDown(SDL_CONTROLLER_BUTTON_DPAD_UP); bool up_pressed = key.isDown(SDLK_UP) || key.isDown(SDL_GAMEPAD_BUTTON_DPAD_UP);
bool down_pressed = key.isDown(SDLK_DOWN) || key.isDown(SDL_CONTROLLER_BUTTON_DPAD_DOWN); bool down_pressed = key.isDown(SDLK_DOWN) || key.isDown(SDL_GAMEPAD_BUTTON_DPAD_DOWN);
bool left_pressed = key.isDown(SDLK_LEFT) || key.isDown(SDL_CONTROLLER_BUTTON_DPAD_LEFT); bool left_pressed = key.isDown(SDLK_LEFT) || key.isDown(SDL_GAMEPAD_BUTTON_DPAD_LEFT);
bool right_pressed = key.isDown(SDLK_RIGHT) || key.isDown(SDL_CONTROLLER_BUTTON_DPAD_RIGHT); bool right_pressed = key.isDown(SDLK_RIGHT) || key.isDown(SDL_GAMEPAD_BUTTON_DPAD_RIGHT);
game.press_left = false; game.press_left = false;
game.press_right = false; game.press_right = false;
@@ -3516,7 +3516,7 @@ void editorinput(void)
undo_pressed = true; undo_pressed = true;
} }
if (key.isDown(SDLK_y) && ctrl_down && (ed.keydelay == 0)) if (key.isDown(SDLK_Y) && ctrl_down && (ed.keydelay == 0))
{ {
ed.keydelay = 6; ed.keydelay = 6;
redo_pressed = true; redo_pressed = true;
@@ -3604,7 +3604,7 @@ void editorinput(void)
bool tiles1 = (cl.getroomprop(ed.levx, ed.levy)->tileset == 0); bool tiles1 = (cl.getroomprop(ed.levx, ed.levy)->tileset == 0);
if (graphics.query_texture(tiles1 ? graphics.grphx.im_tiles : graphics.grphx.im_tiles2, NULL, NULL, &texturewidth, &textureheight) != 0) if (!graphics.query_texture(tiles1 ? graphics.grphx.im_tiles : graphics.grphx.im_tiles2, NULL, NULL, &texturewidth, &textureheight))
return; return;
const int numtiles = (int)(texturewidth / 8) * (textureheight / 8); const int numtiles = (int)(texturewidth / 8) * (textureheight / 8);
+3 -3
View File
@@ -5,7 +5,7 @@
#include "CustomLevels.h" #include "CustomLevels.h"
#include <map> #include <map>
#include <SDL.h> #include <SDL3/SDL.h>
#include <string> #include <string>
#include <vector> #include <vector>
@@ -171,7 +171,7 @@ public:
void register_tilecol(EditorTilesets tileset, int index, const char* foreground_type, int foreground_base, const char* background_type, int background_base, bool direct); void register_tilecol(EditorTilesets tileset, int index, const char* foreground_type, int foreground_base, const char* background_type, int background_base, bool direct);
void register_tilecol(EditorTilesets tileset, int index, const char* foreground_type, int foreground_base, const char* background_type, int background_base); void register_tilecol(EditorTilesets tileset, int index, const char* foreground_type, int foreground_base, const char* background_type, int background_base);
void register_tool(EditorTools tool, const char* name, const char* keychar, SDL_KeyCode key, bool shift); void register_tool(EditorTools tool, const char* name, const char* keychar, SDL_Keycode key, bool shift);
void draw_tool(EditorTools tool, int x, int y); void draw_tool(EditorTools tool, int x, int y);
@@ -230,7 +230,7 @@ public:
const char* tool_names[NUM_EditorTools]; const char* tool_names[NUM_EditorTools];
const char* tool_key_chars[NUM_EditorTools]; const char* tool_key_chars[NUM_EditorTools];
SDL_KeyCode tool_keys[NUM_EditorTools]; SDL_Keycode tool_keys[NUM_EditorTools];
bool tool_requires_shift[NUM_EditorTools]; bool tool_requires_shift[NUM_EditorTools];
EditorTools current_tool; EditorTools current_tool;
+1 -1
View File
@@ -1,7 +1,7 @@
#ifndef ENT_H #ifndef ENT_H
#define ENT_H #define ENT_H
#include <SDL.h> #include <SDL3/SDL.h>
#define rn( rx, ry) ((rx) + ((ry) * 100)) #define rn( rx, ry) ((rx) + ((ry) * 100))
+1 -1
View File
@@ -1,7 +1,7 @@
#define OBJ_DEFINITION #define OBJ_DEFINITION
#include "Entity.h" #include "Entity.h"
#include <SDL.h> #include <SDL3/SDL.h>
#include "CustomLevels.h" #include "CustomLevels.h"
#include "Font.h" #include "Font.h"
+1 -1
View File
@@ -1,7 +1,7 @@
#ifndef ENTITY_H #ifndef ENTITY_H
#define ENTITY_H #define ENTITY_H
#include <SDL.h> #include <SDL3/SDL.h>
#include <string> #include <string>
#include <vector> #include <vector>
+1 -1
View File
@@ -1,7 +1,7 @@
#ifndef VVV_EXIT_H #ifndef VVV_EXIT_H
#define VVV_EXIT_H #define VVV_EXIT_H
#include <SDL_stdinc.h> #include <SDL3/SDL_stdinc.h>
SDL_NORETURN void VVV_exit(const int exit_code); SDL_NORETURN void VVV_exit(const int exit_code);
+20 -21
View File
@@ -1,8 +1,8 @@
#include "FileSystemUtils.h" #include "FileSystemUtils.h"
#include <physfs.h> #include <physfs.h>
#include <physfsrwops.h> #include <physfssdl3.h>
#include <SDL.h> #include <SDL3/SDL.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include <tinyxml2.h> #include <tinyxml2.h>
@@ -31,12 +31,12 @@ static int mkdir(char* path, int mode)
MultiByteToWideChar(CP_UTF8, 0, path, -1, utf16_path, MAX_PATH); MultiByteToWideChar(CP_UTF8, 0, path, -1, utf16_path, MAX_PATH);
return CreateDirectoryW(utf16_path, NULL); return CreateDirectoryW(utf16_path, NULL);
} }
#elif defined(__EMSCRIPTEN__) #elif defined(SDL_PLATFORM_EMSCRIPTEN)
#include <limits.h> #include <limits.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <emscripten.h> #include <emscripten.h>
#define MAX_PATH PATH_MAX #define MAX_PATH PATH_MAX
#elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__HAIKU__) || defined(__DragonFly__) || defined(__unix__) #elif defined(SDL_PLATFORM_LINUX) || defined(SDL_PLATFORM_APPLE) || defined(SDL_PLATFORM_FREEBSD) || defined(SDL_PLATFORM_OPENBSD) || defined(SDL_PLATFORM_HAIKU) || defined(__DragonFly__) || defined(SDL_PLATFORM_UNI)
#include <limits.h> #include <limits.h>
#include <sys/stat.h> #include <sys/stat.h>
#define MAX_PATH PATH_MAX #define MAX_PATH PATH_MAX
@@ -45,7 +45,7 @@ static int mkdir(char* path, int mode)
static bool isInit = false; static bool isInit = false;
static const char* pathSep = NULL; static const char* pathSep = NULL;
static char* basePath = NULL; static const char* basePath = NULL;
static char writeDir[MAX_PATH] = {'\0'}; static char writeDir[MAX_PATH] = {'\0'};
static char saveDir[MAX_PATH] = {'\0'}; static char saveDir[MAX_PATH] = {'\0'};
static char levelDir[MAX_PATH] = {'\0'}; static char levelDir[MAX_PATH] = {'\0'};
@@ -78,7 +78,7 @@ static const PHYSFS_Allocator allocator = {
SDL_free SDL_free
}; };
#ifndef __ANDROID__ #ifndef SDL_PLATFORM_ANDROID
static bool mount_pre_datazip( static bool mount_pre_datazip(
char* out_path, char* out_path,
const char* real_dirname, const char* real_dirname,
@@ -188,10 +188,10 @@ int FILESYSTEM_init(char *argvZero, char* baseDir, char *assetsPath, char* langD
PHYSFS_setAllocator(&allocator); PHYSFS_setAllocator(&allocator);
// Yes, this is actually how you're supposed to use PhysFS on Android. // Yes, this is actually how you're supposed to use PhysFS on Android.
#ifdef __ANDROID__ #ifdef SDL_PLATFORM_ANDROID
PHYSFS_AndroidInit androidInit; PHYSFS_AndroidInit androidInit;
androidInit.jnienv = SDL_AndroidGetJNIEnv(); androidInit.jnienv = SDL_GetAndroidJNIEnv();
androidInit.context = SDL_AndroidGetActivity(); androidInit.context = SDL_GetAndroidActivity();
argvZero = (char*) &androidInit; argvZero = (char*) &androidInit;
#endif #endif
@@ -292,7 +292,7 @@ int FILESYSTEM_init(char *argvZero, char* baseDir, char *assetsPath, char* langD
basePath = SDL_strdup("./"); basePath = SDL_strdup("./");
} }
#ifdef __ANDROID__ #ifdef SDL_PLATFORM_ANDROID
// This is kind of a mess, but that's not really solvable unless we expect the user to download the data.zip manually. // This is kind of a mess, but that's not really solvable unless we expect the user to download the data.zip manually.
if (!PHYSFS_mount(PHYSFS_getBaseDir(), "/apk", 1)) if (!PHYSFS_mount(PHYSFS_getBaseDir(), "/apk", 1))
{ {
@@ -348,10 +348,10 @@ int FILESYSTEM_init(char *argvZero, char* baseDir, char *assetsPath, char* langD
SDL_MessageBoxButtonData buttons[2]; SDL_MessageBoxButtonData buttons[2];
buttons[0].flags = SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT; buttons[0].flags = SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT;
buttons[0].flags |= SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT; buttons[0].flags |= SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT;
buttons[0].buttonid = 0; buttons[0].buttonID = 0;
buttons[0].text = "OK"; buttons[0].text = "OK";
buttons[1].flags = 0; buttons[1].flags = 0;
buttons[1].buttonid = 1; buttons[1].buttonID = 1;
buttons[1].text = "Open Download Page"; buttons[1].text = "Open Download Page";
messagebox.buttons = buttons; messagebox.buttons = buttons;
messagebox.colorScheme = NULL; messagebox.colorScheme = NULL;
@@ -368,7 +368,7 @@ int FILESYSTEM_init(char *argvZero, char* baseDir, char *assetsPath, char* langD
} }
SDL_snprintf(output, sizeof(output), "%s%s", basePath, "gamecontrollerdb.txt"); SDL_snprintf(output, sizeof(output), "%s%s", basePath, "gamecontrollerdb.txt");
if (SDL_GameControllerAddMappingsFromFile(output) < 0) if (SDL_AddGamepadMappingsFromFile(output) < 0)
{ {
vlog_info("gamecontrollerdb.txt not found!"); vlog_info("gamecontrollerdb.txt not found!");
} }
@@ -392,7 +392,6 @@ void FILESYSTEM_deinit(void)
PHYSFS_deinit(); PHYSFS_deinit();
} }
VVV_free(stdin_buffer); VVV_free(stdin_buffer);
VVV_free(basePath);
isInit = false; isInit = false;
} }
@@ -960,12 +959,12 @@ fail:
} }
} }
SDL_RWops* FILESYSTEM_loadAssetRWops(const char* name) SDL_IOStream* FILESYSTEM_loadAssetRWops(const char* name)
{ {
char path[MAX_PATH]; char path[MAX_PATH];
getMountedPath(path, sizeof(path), name); getMountedPath(path, sizeof(path), name);
return PHYSFSRWOPS_openRead(path); return PHYSFSSDL3_openRead(path);
} }
void FILESYSTEM_loadAssetToMemory( void FILESYSTEM_loadAssetToMemory(
@@ -1120,7 +1119,7 @@ bool FILESYSTEM_saveTiXml2Document(const char *name, tinyxml2::XMLDocument& doc,
PHYSFS_writeBytes(handle, printer.CStr(), printer.CStrSize() - 1); // subtract one because CStrSize includes terminating null PHYSFS_writeBytes(handle, printer.CStr(), printer.CStrSize() - 1); // subtract one because CStrSize includes terminating null
PHYSFS_close(handle); PHYSFS_close(handle);
#ifdef __EMSCRIPTEN__ #ifdef SDL_PLATFORM_EMSCRIPTEN
if (sync) if (sync)
{ {
EM_ASM(FS.syncfs(false, function(err) EM_ASM(FS.syncfs(false, function(err)
@@ -1348,8 +1347,8 @@ static int PLATFORM_getOSDirectory(char* output, const size_t output_size)
SDL_strlcat(output, "\\VVVVVV\\", MAX_PATH); SDL_strlcat(output, "\\VVVVVV\\", MAX_PATH);
mkdir(output, 0777); mkdir(output, 0777);
return 1; return 1;
#elif defined(__ANDROID__) #elif defined(SDL_PLATFORM_ANDROID)
const char* externalStoragePath = SDL_AndroidGetExternalStoragePath(); const char* externalStoragePath = SDL_GetAndroidExternalStoragePath();
if (externalStoragePath == NULL) if (externalStoragePath == NULL)
{ {
vlog_error( vlog_error(
@@ -1393,7 +1392,7 @@ bool FILESYSTEM_openDirectoryEnabled(void)
return !gameScreen.isForcedFullscreen(); return !gameScreen.isForcedFullscreen();
} }
#if defined(__EMSCRIPTEN__) #if defined(SDL_PLATFORM_EMSCRIPTEN)
bool FILESYSTEM_openDirectory(const char *dname) bool FILESYSTEM_openDirectory(const char *dname)
{ {
return false; return false;
@@ -1403,7 +1402,7 @@ bool FILESYSTEM_openDirectory(const char *dname)
{ {
char url[MAX_PATH]; char url[MAX_PATH];
SDL_snprintf(url, sizeof(url), "file://%s", dname); SDL_snprintf(url, sizeof(url), "file://%s", dname);
if (SDL_OpenURL(url) == -1) if (!SDL_OpenURL(url))
{ {
vlog_error("Error opening directory: %s", SDL_GetError()); vlog_error("Error opening directory: %s", SDL_GetError());
return false; return false;
+2 -2
View File
@@ -5,7 +5,7 @@
class binaryBlob; class binaryBlob;
#include <stddef.h> #include <stddef.h>
#include <SDL_rwops.h> #include <SDL3/SDL.h>
// Forward declaration, including the entirety of tinyxml2.h across all files this file is included in is unnecessary // Forward declaration, including the entirety of tinyxml2.h across all files this file is included in is unnecessary
namespace tinyxml2 { class XMLDocument; } namespace tinyxml2 { class XMLDocument; }
@@ -37,7 +37,7 @@ bool FILESYSTEM_saveFile(const char* name, const unsigned char* data, size_t len
void FILESYSTEM_loadFileToMemory(const char *name, unsigned char **mem, void FILESYSTEM_loadFileToMemory(const char *name, unsigned char **mem,
size_t *len); size_t *len);
SDL_RWops* FILESYSTEM_loadAssetRWops(const char* name); SDL_IOStream* FILESYSTEM_loadAssetRWops(const char* name);
void FILESYSTEM_loadAssetToMemory( void FILESYSTEM_loadAssetToMemory(
const char* name, const char* name,
unsigned char** mem, unsigned char** mem,
+1 -1
View File
@@ -438,7 +438,7 @@ static uint8_t load_font(FontContainer* container, const char* name)
add_glyphinfo(f, codepoint, codepoint); add_glyphinfo(f, codepoint, codepoint);
} }
VVV_freefunc(SDL_FreeSurface, temp_surface); VVV_freefunc(SDL_DestroySurface, temp_surface);
} }
} }
+1 -1
View File
@@ -26,7 +26,7 @@
#ifndef FONT_H #ifndef FONT_H
#define FONT_H #define FONT_H
#include <SDL.h> #include <SDL3/SDL.h>
#include <stdint.h> #include <stdint.h>
#include <string> #include <string>
+1 -1
View File
@@ -1,6 +1,6 @@
#include "FontBidi.h" #include "FontBidi.h"
#include <SDL.h> #include <SDL3/SDL.h>
#include <SheenBidi/SheenBidi.h> #include <SheenBidi/SheenBidi.h>
#include "Alloc.h" #include "Alloc.h"
+25 -25
View File
@@ -34,76 +34,76 @@
#include "Vlogging.h" #include "Vlogging.h"
#include "XMLUtils.h" #include "XMLUtils.h"
static bool GetButtonFromString(const char *pText, SDL_GameControllerButton *button) static bool GetButtonFromString(const char *pText, SDL_GamepadButton *button)
{ {
if (*pText == '0' || if (*pText == '0' ||
*pText == 'a' || *pText == 'a' ||
*pText == 'A') *pText == 'A')
{ {
*button = SDL_CONTROLLER_BUTTON_A; *button = SDL_GAMEPAD_BUTTON_SOUTH;
return true; return true;
} }
if (SDL_strcmp(pText, "1") == 0 || if (SDL_strcmp(pText, "1") == 0 ||
*pText == 'b' || *pText == 'b' ||
*pText == 'B') *pText == 'B')
{ {
*button = SDL_CONTROLLER_BUTTON_B; *button = SDL_GAMEPAD_BUTTON_EAST;
return true; return true;
} }
if (*pText == '2' || if (*pText == '2' ||
*pText == 'x' || *pText == 'x' ||
*pText == 'X') *pText == 'X')
{ {
*button = SDL_CONTROLLER_BUTTON_X; *button = SDL_GAMEPAD_BUTTON_WEST;
return true; return true;
} }
if (*pText == '3' || if (*pText == '3' ||
*pText == 'y' || *pText == 'y' ||
*pText == 'Y') *pText == 'Y')
{ {
*button = SDL_CONTROLLER_BUTTON_Y; *button = SDL_GAMEPAD_BUTTON_NORTH;
return true; return true;
} }
if (*pText == '4' || if (*pText == '4' ||
SDL_strcasecmp(pText, "BACK") == 0) SDL_strcasecmp(pText, "BACK") == 0)
{ {
*button = SDL_CONTROLLER_BUTTON_BACK; *button = SDL_GAMEPAD_BUTTON_BACK;
return true; return true;
} }
if (*pText == '5' || if (*pText == '5' ||
SDL_strcasecmp(pText, "GUIDE") == 0) SDL_strcasecmp(pText, "GUIDE") == 0)
{ {
*button = SDL_CONTROLLER_BUTTON_GUIDE; *button = SDL_GAMEPAD_BUTTON_GUIDE;
return true; return true;
} }
if (*pText == '6' || if (*pText == '6' ||
SDL_strcasecmp(pText, "START") == 0) SDL_strcasecmp(pText, "START") == 0)
{ {
*button = SDL_CONTROLLER_BUTTON_START; *button = SDL_GAMEPAD_BUTTON_START;
return true; return true;
} }
if (*pText == '7' || if (*pText == '7' ||
SDL_strcasecmp(pText, "LS") == 0) SDL_strcasecmp(pText, "LS") == 0)
{ {
*button = SDL_CONTROLLER_BUTTON_LEFTSTICK; *button = SDL_GAMEPAD_BUTTON_LEFT_STICK;
return true; return true;
} }
if (*pText == '8' || if (*pText == '8' ||
SDL_strcasecmp(pText, "RS") == 0) SDL_strcasecmp(pText, "RS") == 0)
{ {
*button = SDL_CONTROLLER_BUTTON_RIGHTSTICK; *button = SDL_GAMEPAD_BUTTON_RIGHT_STICK;
return true; return true;
} }
if (*pText == '9' || if (*pText == '9' ||
SDL_strcasecmp(pText, "LB") == 0) SDL_strcasecmp(pText, "LB") == 0)
{ {
*button = SDL_CONTROLLER_BUTTON_LEFTSHOULDER; *button = SDL_GAMEPAD_BUTTON_LEFT_SHOULDER;
return true; return true;
} }
if (SDL_strcmp(pText, "10") == 0 || if (SDL_strcmp(pText, "10") == 0 ||
SDL_strcasecmp(pText, "RB") == 0) SDL_strcasecmp(pText, "RB") == 0)
{ {
*button = SDL_CONTROLLER_BUTTON_RIGHTSHOULDER; *button = SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER;
return true; return true;
} }
return false; return false;
@@ -254,7 +254,7 @@ void Game::init(void)
levelpage=0; levelpage=0;
playcustomlevel=0; playcustomlevel=0;
gpmenu_lastbutton = SDL_CONTROLLER_BUTTON_INVALID; gpmenu_lastbutton = SDL_GAMEPAD_BUTTON_INVALID;
gpmenu_confirming = false; gpmenu_confirming = false;
gpmenu_showremove = false; gpmenu_showremove = false;
@@ -381,7 +381,7 @@ void Game::init(void)
screenshot_border_timer = 0; screenshot_border_timer = 0;
screenshot_saved_success = false; screenshot_saved_success = false;
#if defined(__ANDROID__) || TARGET_OS_IPHONE #if defined(SDL_PLATFORM_ANDROID) || TARGET_OS_IPHONE
checkpoint_saving = true; checkpoint_saving = true;
#else #else
checkpoint_saving = false; checkpoint_saving = false;
@@ -394,23 +394,23 @@ void Game::setdefaultcontrollerbuttons(void)
{ {
if (controllerButton_flip.size() < 1) if (controllerButton_flip.size() < 1)
{ {
controllerButton_flip.push_back(SDL_CONTROLLER_BUTTON_A); controllerButton_flip.push_back(SDL_GAMEPAD_BUTTON_SOUTH);
} }
if (controllerButton_map.size() < 1) if (controllerButton_map.size() < 1)
{ {
controllerButton_map.push_back(SDL_CONTROLLER_BUTTON_Y); controllerButton_map.push_back(SDL_GAMEPAD_BUTTON_NORTH);
} }
if (controllerButton_esc.size() < 1) if (controllerButton_esc.size() < 1)
{ {
controllerButton_esc.push_back(SDL_CONTROLLER_BUTTON_B); controllerButton_esc.push_back(SDL_GAMEPAD_BUTTON_EAST);
} }
if (controllerButton_restart.size() < 1) if (controllerButton_restart.size() < 1)
{ {
controllerButton_restart.push_back(SDL_CONTROLLER_BUTTON_RIGHTSHOULDER); controllerButton_restart.push_back(SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER);
} }
if (controllerButton_interact.size() < 1) if (controllerButton_interact.size() < 1)
{ {
controllerButton_interact.push_back(SDL_CONTROLLER_BUTTON_X); controllerButton_interact.push_back(SDL_GAMEPAD_BUTTON_WEST);
} }
/* If one of the arrays was empty, and others weren't, we might now have conflicts... /* If one of the arrays was empty, and others weren't, we might now have conflicts...
@@ -4898,7 +4898,7 @@ void Game::deserializesettings(tinyxml2::XMLElement* dataNode, struct ScreenSett
if (SDL_strcmp(pKey, "flipButton") == 0) if (SDL_strcmp(pKey, "flipButton") == 0)
{ {
SDL_GameControllerButton newButton; SDL_GamepadButton newButton;
if (GetButtonFromString(pText, &newButton)) if (GetButtonFromString(pText, &newButton))
{ {
controllerButton_flip.push_back(newButton); controllerButton_flip.push_back(newButton);
@@ -4907,7 +4907,7 @@ void Game::deserializesettings(tinyxml2::XMLElement* dataNode, struct ScreenSett
if (SDL_strcmp(pKey, "enterButton") == 0) if (SDL_strcmp(pKey, "enterButton") == 0)
{ {
SDL_GameControllerButton newButton; SDL_GamepadButton newButton;
if (GetButtonFromString(pText, &newButton)) if (GetButtonFromString(pText, &newButton))
{ {
controllerButton_map.push_back(newButton); controllerButton_map.push_back(newButton);
@@ -4916,7 +4916,7 @@ void Game::deserializesettings(tinyxml2::XMLElement* dataNode, struct ScreenSett
if (SDL_strcmp(pKey, "escButton") == 0) if (SDL_strcmp(pKey, "escButton") == 0)
{ {
SDL_GameControllerButton newButton; SDL_GamepadButton newButton;
if (GetButtonFromString(pText, &newButton)) if (GetButtonFromString(pText, &newButton))
{ {
controllerButton_esc.push_back(newButton); controllerButton_esc.push_back(newButton);
@@ -4925,7 +4925,7 @@ void Game::deserializesettings(tinyxml2::XMLElement* dataNode, struct ScreenSett
if (SDL_strcmp(pKey, "restartButton") == 0) if (SDL_strcmp(pKey, "restartButton") == 0)
{ {
SDL_GameControllerButton newButton; SDL_GamepadButton newButton;
if (GetButtonFromString(pText, &newButton)) if (GetButtonFromString(pText, &newButton))
{ {
controllerButton_restart.push_back(newButton); controllerButton_restart.push_back(newButton);
@@ -4934,7 +4934,7 @@ void Game::deserializesettings(tinyxml2::XMLElement* dataNode, struct ScreenSett
if (SDL_strcmp(pKey, "interactButton") == 0) if (SDL_strcmp(pKey, "interactButton") == 0)
{ {
SDL_GameControllerButton newButton; SDL_GamepadButton newButton;
if (GetButtonFromString(pText, &newButton)) if (GetButtonFromString(pText, &newButton))
{ {
controllerButton_interact.push_back(newButton); controllerButton_interact.push_back(newButton);
@@ -7985,7 +7985,7 @@ int Game::get_timestep(void)
if ((gamestate == GAMEMODE || (gamestate == TELEPORTERMODE && !useteleporter)) && if ((gamestate == GAMEMODE || (gamestate == TELEPORTERMODE && !useteleporter)) &&
level_debugger::is_active() && level_debugger::is_active() &&
!level_debugger::is_pausing() && !level_debugger::is_pausing() &&
key.isDown(SDLK_f)) key.isDown(SDLK_F))
{ {
return 1; return 1;
} }
+7 -7
View File
@@ -1,7 +1,7 @@
#ifndef GAME_H #ifndef GAME_H
#define GAME_H #define GAME_H
#include <SDL.h> #include <SDL3/SDL.h>
#include <map> #include <map>
#include <string> #include <string>
#include <vector> #include <vector>
@@ -404,7 +404,7 @@ public:
int creditposx, creditposy, creditposdelay; int creditposx, creditposy, creditposdelay;
int oldcreditposx; int oldcreditposx;
SDL_GameControllerButton gpmenu_lastbutton; SDL_GamepadButton gpmenu_lastbutton;
bool gpmenu_confirming; bool gpmenu_confirming;
bool gpmenu_showremove; bool gpmenu_showremove;
@@ -547,11 +547,11 @@ public:
std::map<std::string, int> customlevelstats; std::map<std::string, int> customlevelstats;
std::vector<SDL_GameControllerButton> controllerButton_map; std::vector<SDL_GamepadButton> controllerButton_map;
std::vector<SDL_GameControllerButton> controllerButton_flip; std::vector<SDL_GamepadButton> controllerButton_flip;
std::vector<SDL_GameControllerButton> controllerButton_esc; std::vector<SDL_GamepadButton> controllerButton_esc;
std::vector<SDL_GameControllerButton> controllerButton_restart; std::vector<SDL_GamepadButton> controllerButton_restart;
std::vector<SDL_GameControllerButton> controllerButton_interact; std::vector<SDL_GamepadButton> controllerButton_interact;
bool skipfakeload; bool skipfakeload;
bool ghostsenabled; bool ghostsenabled;
+2 -2
View File
@@ -1,7 +1,7 @@
#include "GlitchrunnerMode.h" #include "GlitchrunnerMode.h"
#include <SDL_assert.h> #include <SDL3/SDL_assert.h>
#include <SDL_stdinc.h> #include <SDL3/SDL_stdinc.h>
#define LOOKUP_TABLE \ #define LOOKUP_TABLE \
FOREACH_ENUM(GlitchrunnerNone, "") \ FOREACH_ENUM(GlitchrunnerNone, "") \
+191 -99
View File
@@ -1,7 +1,7 @@
#define GRAPHICS_DEFINITION #define GRAPHICS_DEFINITION
#include "Graphics.h" #include "Graphics.h"
#include <SDL.h> #include <SDL3/SDL.h>
#include "Alloc.h" #include "Alloc.h"
#include "Constants.h" #include "Constants.h"
@@ -157,7 +157,7 @@ void Graphics::destroy(void)
#define CLEAR_ARRAY(name) \ #define CLEAR_ARRAY(name) \
for (size_t i = 0; i < name.size(); i += 1) \ for (size_t i = 0; i < name.size(); i += 1) \
{ \ { \
VVV_freefunc(SDL_FreeSurface, name[i]); \ VVV_freefunc(SDL_DestroySurface, name[i]); \
} \ } \
name.clear(); name.clear();
@@ -200,12 +200,12 @@ void Graphics::create_buffers(void)
SDL_SetTextureScaleMode( SDL_SetTextureScaleMode(
gameTexture, gameTexture,
gameScreen.isFiltered ? SDL_ScaleModeLinear : SDL_ScaleModeNearest gameScreen.isFiltered ? SDL_SCALEMODE_LINEAR : SDL_SCALEMODE_NEAREST
); );
SDL_SetTextureScaleMode( SDL_SetTextureScaleMode(
tempShakeTexture, tempShakeTexture,
gameScreen.isFiltered ? SDL_ScaleModeLinear : SDL_ScaleModeNearest gameScreen.isFiltered ? SDL_SCALEMODE_LINEAR : SDL_SCALEMODE_NEAREST
); );
} }
@@ -221,10 +221,10 @@ void Graphics::destroy_buffers(void)
VVV_freefunc(SDL_DestroyTexture, tempScrollingTexture); VVV_freefunc(SDL_DestroyTexture, tempScrollingTexture);
VVV_freefunc(SDL_DestroyTexture, towerbg.texture); VVV_freefunc(SDL_DestroyTexture, towerbg.texture);
VVV_freefunc(SDL_DestroyTexture, titlebg.texture); VVV_freefunc(SDL_DestroyTexture, titlebg.texture);
VVV_freefunc(SDL_FreeSurface, tempFilterSrc); VVV_freefunc(SDL_DestroySurface, tempFilterSrc);
VVV_freefunc(SDL_FreeSurface, tempFilterDest); VVV_freefunc(SDL_DestroySurface, tempFilterDest);
VVV_freefunc(SDL_FreeSurface, tempScreenshot); VVV_freefunc(SDL_DestroySurface, tempScreenshot);
VVV_freefunc(SDL_FreeSurface, tempScreenshot2x); VVV_freefunc(SDL_DestroySurface, tempScreenshot2x);
} }
void Graphics::drawspritesetcol(int x, int y, int t, int c) void Graphics::drawspritesetcol(int x, int y, int t, int c)
@@ -446,79 +446,98 @@ void Graphics::print_level_creator(
font::print(print_flags, text_x, y, creator, r, g, b); font::print(print_flags, text_x, y, creator, r, g, b);
} }
int Graphics::set_render_target(SDL_Texture* texture) bool Graphics::set_render_target(SDL_Texture* texture)
{ {
const int result = SDL_SetRenderTarget(gameScreen.m_renderer, texture); const bool result = SDL_SetRenderTarget(gameScreen.m_renderer, texture);
if (result != 0) if (!result)
{ {
WHINE_ONCE_ARGS(("Could not set render target: %s", SDL_GetError())); WHINE_ONCE_ARGS(("Could not set render target: %s", SDL_GetError()));
} }
return result; return result;
} }
int Graphics::set_texture_color_mod(SDL_Texture* texture, const Uint8 r, const Uint8 g, const Uint8 b) bool Graphics::set_texture_color_mod(SDL_Texture* texture, const Uint8 r, const Uint8 g, const Uint8 b)
{ {
const int result = SDL_SetTextureColorMod(texture, r, g, b); const bool result = SDL_SetTextureColorMod(texture, r, g, b);
if (result != 0) if (!result)
{ {
WHINE_ONCE_ARGS(("Could not set texture color mod: %s", SDL_GetError())); WHINE_ONCE_ARGS(("Could not set texture color mod: %s", SDL_GetError()));
} }
return result; return result;
} }
int Graphics::set_texture_alpha_mod(SDL_Texture* texture, const Uint8 alpha) bool Graphics::set_texture_alpha_mod(SDL_Texture* texture, const Uint8 alpha)
{ {
const int result = SDL_SetTextureAlphaMod(texture, alpha); const bool result = SDL_SetTextureAlphaMod(texture, alpha);
if (result != 0) if (!result)
{ {
WHINE_ONCE_ARGS(("Could not set texture alpha mod: %s", SDL_GetError())); WHINE_ONCE_ARGS(("Could not set texture alpha mod: %s", SDL_GetError()));
} }
return result; return result;
} }
int Graphics::query_texture(SDL_Texture* texture, Uint32* format, int* access, int* w, int* h) bool Graphics::query_texture(SDL_Texture* texture, Uint32* format, int* access, int* w, int* h)
{ {
const int result = SDL_QueryTexture(texture, format, access, w, h); SDL_PropertiesID props = SDL_GetTextureProperties(texture);
if (result != 0)
if (props == 0)
{ {
WHINE_ONCE_ARGS(("Could not query texture: %s", SDL_GetError())); WHINE_ONCE_ARGS(("Could not query texture: %s", SDL_GetError()));
return false;
} }
return result;
if (format) {
*format = SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_FORMAT_NUMBER, 0);
}
if (access) {
*access = SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_ACCESS_NUMBER, 0);
}
if (w) {
*w = SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_WIDTH_NUMBER, 0);
}
if (h) {
*h = SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_HEIGHT_NUMBER, 0);
}
return true;
} }
int Graphics::set_blendmode(const SDL_BlendMode blendmode) bool Graphics::set_blendmode(const SDL_BlendMode blendmode)
{ {
const int result = SDL_SetRenderDrawBlendMode(gameScreen.m_renderer, blendmode); const bool result = SDL_SetRenderDrawBlendMode(gameScreen.m_renderer, blendmode);
if (result != 0) if (!result)
{ {
WHINE_ONCE_ARGS(("Could not set draw mode: %s", SDL_GetError())); WHINE_ONCE_ARGS(("Could not set draw mode: %s", SDL_GetError()));
} }
return result; return result;
} }
int Graphics::set_blendmode(SDL_Texture* texture, const SDL_BlendMode blendmode) bool Graphics::set_blendmode(SDL_Texture* texture, const SDL_BlendMode blendmode)
{ {
const int result = SDL_SetTextureBlendMode(texture, blendmode); const bool result = SDL_SetTextureBlendMode(texture, blendmode);
if (result != 0) if (!result)
{ {
WHINE_ONCE_ARGS(("Could not set texture blend mode: %s", SDL_GetError())); WHINE_ONCE_ARGS(("Could not set texture blend mode: %s", SDL_GetError()));
} }
return result; return result;
} }
int Graphics::clear(const int r, const int g, const int b, const int a) bool Graphics::clear(const int r, const int g, const int b, const int a)
{ {
set_color(r, g, b, a); set_color(r, g, b, a);
const int result = SDL_RenderClear(gameScreen.m_renderer); const bool result = SDL_RenderClear(gameScreen.m_renderer);
if (result != 0) if (!result)
{ {
WHINE_ONCE_ARGS(("Could not clear current render target: %s", SDL_GetError())); WHINE_ONCE_ARGS(("Could not clear current render target: %s", SDL_GetError()));
} }
return result; return result;
} }
int Graphics::clear(void) bool Graphics::clear(void)
{ {
return clear(0, 0, 0, 255); return clear(0, 0, 0, 255);
} }
@@ -566,12 +585,12 @@ void Graphics::post_substitute(SDL_Texture* subst)
set_texture_alpha_mod(subst, 255); set_texture_alpha_mod(subst, 255);
} }
int Graphics::copy_texture(SDL_Texture* texture, const SDL_Rect* src, const SDL_Rect* dest) bool Graphics::copy_texture(SDL_Texture* texture, const SDL_FRect* src, const SDL_FRect* dest)
{ {
bool is_substituted = substitute(&texture); bool is_substituted = substitute(&texture);
const int result = SDL_RenderCopy(gameScreen.m_renderer, texture, src, dest); const bool result = SDL_RenderTexture(gameScreen.m_renderer, texture, src, dest);
if (result != 0) if (!result)
{ {
WHINE_ONCE_ARGS(("Could not copy texture: %s", SDL_GetError())); WHINE_ONCE_ARGS(("Could not copy texture: %s", SDL_GetError()));
} }
@@ -584,12 +603,12 @@ int Graphics::copy_texture(SDL_Texture* texture, const SDL_Rect* src, const SDL_
return result; return result;
} }
int Graphics::copy_texture(SDL_Texture* texture, const SDL_Rect* src, const SDL_Rect* dest, const double angle, const SDL_Point* center, const SDL_RendererFlip flip) bool Graphics::copy_texture(SDL_Texture* texture, const SDL_FRect* src, const SDL_FRect* dest, const double angle, const SDL_FPoint* center, const SDL_FlipMode flip)
{ {
bool is_substituted = substitute(&texture); bool is_substituted = substitute(&texture);
const int result = SDL_RenderCopyEx(gameScreen.m_renderer, texture, src, dest, angle, center, flip); const bool result = SDL_RenderTextureRotated(gameScreen.m_renderer, texture, src, dest, angle, center, flip);
if (result != 0) if (!result)
{ {
WHINE_ONCE_ARGS(("Could not copy texture: %s", SDL_GetError())); WHINE_ONCE_ARGS(("Could not copy texture: %s", SDL_GetError()));
} }
@@ -602,141 +621,151 @@ int Graphics::copy_texture(SDL_Texture* texture, const SDL_Rect* src, const SDL_
return result; return result;
} }
int Graphics::set_color(const Uint8 r, const Uint8 g, const Uint8 b, const Uint8 a) bool Graphics::set_color(const Uint8 r, const Uint8 g, const Uint8 b, const Uint8 a)
{ {
const int result = SDL_SetRenderDrawColor(gameScreen.m_renderer, r, g, b, a); const bool result = SDL_SetRenderDrawColor(gameScreen.m_renderer, r, g, b, a);
if (result != 0) if (!result)
{ {
WHINE_ONCE_ARGS(("Could not set draw color: %s", SDL_GetError())); WHINE_ONCE_ARGS(("Could not set draw color: %s", SDL_GetError()));
} }
return result; return result;
} }
int Graphics::set_color(const Uint8 r, const Uint8 g, const Uint8 b) bool Graphics::set_color(const Uint8 r, const Uint8 g, const Uint8 b)
{ {
return set_color(r, g, b, 255); return set_color(r, g, b, 255);
} }
int Graphics::set_color(const SDL_Color color) bool Graphics::set_color(const SDL_Color color)
{ {
return set_color(color.r, color.g, color.b, color.a); return set_color(color.r, color.g, color.b, color.a);
} }
int Graphics::fill_rect(const SDL_Rect* rect) bool Graphics::fill_rect(const SDL_FRect* rect)
{ {
const int result = SDL_RenderFillRect(gameScreen.m_renderer, rect); const bool result = SDL_RenderFillRect(gameScreen.m_renderer, rect);
if (result != 0) if (!result)
{ {
WHINE_ONCE_ARGS(("Could not draw filled rectangle: %s", SDL_GetError())); WHINE_ONCE_ARGS(("Could not draw filled rectangle: %s", SDL_GetError()));
} }
return result; return result;
} }
int Graphics::fill_rect(const SDL_Rect* rect, const int r, const int g, const int b, const int a) bool Graphics::fill_rect(const SDL_FRect* rect, const int r, const int g, const int b, const int a)
{ {
set_color(r, g, b, a); set_color(r, g, b, a);
return fill_rect(rect); return fill_rect(rect);
} }
int Graphics::fill_rect(const SDL_Rect* rect, const int r, const int g, const int b) bool Graphics::fill_rect(const SDL_FRect* rect, const int r, const int g, const int b)
{ {
return fill_rect(rect, r, g, b, 255); return fill_rect(rect, r, g, b, 255);
} }
int Graphics::fill_rect(const int r, const int g, const int b) bool Graphics::fill_rect(const int r, const int g, const int b)
{ {
return fill_rect(NULL, r, g, b, 255); return fill_rect(NULL, r, g, b, 255);
} }
int Graphics::fill_rect(const SDL_Rect* rect, const SDL_Color color) bool Graphics::fill_rect(const SDL_FRect* rect, const SDL_Color color)
{ {
return fill_rect(rect, color.r, color.g, color.b, color.a); return fill_rect(rect, color.r, color.g, color.b, color.a);
} }
int Graphics::fill_rect(const int x, const int y, const int w, const int h, const int r, const int g, const int b, const int a) bool Graphics::fill_rect(const int x, const int y, const int w, const int h, const int r, const int g, const int b, const int a)
{ {
const SDL_Rect rect = {x, y, w, h}; const SDL_FRect rect = {
static_cast<float>(x),
static_cast<float>(y),
static_cast<float>(w),
static_cast<float>(h)
};
return fill_rect(&rect, r, g, b, a); return fill_rect(&rect, r, g, b, a);
} }
int Graphics::fill_rect(const int x, const int y, const int w, const int h, const int r, const int g, const int b) bool Graphics::fill_rect(const int x, const int y, const int w, const int h, const int r, const int g, const int b)
{ {
return fill_rect(x, y, w, h, r, g, b, 255); return fill_rect(x, y, w, h, r, g, b, 255);
} }
int Graphics::fill_rect(const SDL_Color color) bool Graphics::fill_rect(const SDL_Color color)
{ {
return fill_rect(NULL, color); return fill_rect(NULL, color);
} }
int Graphics::fill_rect(const int x, const int y, const int w, const int h, const SDL_Color color) bool Graphics::fill_rect(const int x, const int y, const int w, const int h, const SDL_Color color)
{ {
return fill_rect(x, y, w, h, color.r, color.g, color.b, color.a); return fill_rect(x, y, w, h, color.r, color.g, color.b, color.a);
} }
int Graphics::draw_rect(const SDL_Rect* rect) bool Graphics::draw_rect(const SDL_FRect* rect)
{ {
const int result = SDL_RenderDrawRect(gameScreen.m_renderer, rect); const bool result = SDL_RenderRect(gameScreen.m_renderer, rect);
if (result != 0) if (!result)
{ {
WHINE_ONCE_ARGS(("Could not draw rectangle: %s", SDL_GetError())); WHINE_ONCE_ARGS(("Could not draw rectangle: %s", SDL_GetError()));
} }
return result; return result;
} }
int Graphics::draw_rect(const SDL_Rect* rect, const int r, const int g, const int b, const int a) bool Graphics::draw_rect(const SDL_FRect* rect, const int r, const int g, const int b, const int a)
{ {
set_color(r, g, b, a); set_color(r, g, b, a);
return draw_rect(rect); return draw_rect(rect);
} }
int Graphics::draw_rect(const SDL_Rect* rect, const int r, const int g, const int b) bool Graphics::draw_rect(const SDL_FRect* rect, const int r, const int g, const int b)
{ {
return draw_rect(rect, r, g, b, 255); return draw_rect(rect, r, g, b, 255);
} }
int Graphics::draw_rect(const SDL_Rect* rect, const SDL_Color color) bool Graphics::draw_rect(const SDL_FRect* rect, const SDL_Color color)
{ {
return draw_rect(rect, color.r, color.g, color.b, color.a); return draw_rect(rect, color.r, color.g, color.b, color.a);
} }
int Graphics::draw_rect(const int x, const int y, const int w, const int h, const int r, const int g, const int b, const int a) bool Graphics::draw_rect(const int x, const int y, const int w, const int h, const int r, const int g, const int b, const int a)
{ {
const SDL_Rect rect = {x, y, w, h}; const SDL_FRect rect = {
static_cast<float>(x),
static_cast<float>(y),
static_cast<float>(w),
static_cast<float>(h)
};
return draw_rect(&rect, r, g, b, a); return draw_rect(&rect, r, g, b, a);
} }
int Graphics::draw_rect(const int x, const int y, const int w, const int h, const int r, const int g, const int b) bool Graphics::draw_rect(const int x, const int y, const int w, const int h, const int r, const int g, const int b)
{ {
return draw_rect(x, y, w, h, r, g, b, 255); return draw_rect(x, y, w, h, r, g, b, 255);
} }
int Graphics::draw_rect(const int x, const int y, const int w, const int h, const SDL_Color color) bool Graphics::draw_rect(const int x, const int y, const int w, const int h, const SDL_Color color)
{ {
return draw_rect(x, y, w, h, color.r, color.g, color.b, color.a); return draw_rect(x, y, w, h, color.r, color.g, color.b, color.a);
} }
int Graphics::draw_line(const int x, const int y, const int x2, const int y2) bool Graphics::draw_line(const int x, const int y, const int x2, const int y2)
{ {
const int result = SDL_RenderDrawLine(gameScreen.m_renderer, x, y, x2, y2); const bool result = SDL_RenderLine(gameScreen.m_renderer, x, y, x2, y2);
if (result != 0) if (!result)
{ {
WHINE_ONCE_ARGS(("Could not draw line: %s", SDL_GetError())); WHINE_ONCE_ARGS(("Could not draw line: %s", SDL_GetError()));
} }
return result; return result;
} }
int Graphics::draw_points(const SDL_Point* points, const int count) bool Graphics::draw_points(const SDL_FPoint* points, const int count)
{ {
const int result = SDL_RenderDrawPoints(gameScreen.m_renderer, points, count); const bool result = SDL_RenderPoints(gameScreen.m_renderer, points, count);
if (result != 0) if (!result)
{ {
WHINE_ONCE_ARGS(("Could not draw points: %s", SDL_GetError())); WHINE_ONCE_ARGS(("Could not draw points: %s", SDL_GetError()));
} }
return result; return result;
} }
int Graphics::draw_points(const SDL_Point* points, const int count, const int r, const int g, const int b) bool Graphics::draw_points(const SDL_FPoint* points, const int count, const int r, const int g, const int b)
{ {
set_color(r, g, b); set_color(r, g, b);
return draw_points(points, count); return draw_points(points, count);
@@ -761,10 +790,20 @@ void Graphics::scroll_texture(SDL_Texture* texture, SDL_Texture* temp, const int
{ {
SDL_Texture* target = SDL_GetRenderTarget(gameScreen.m_renderer); SDL_Texture* target = SDL_GetRenderTarget(gameScreen.m_renderer);
SDL_Rect texture_rect = {0, 0, 0, 0}; SDL_Rect texture_rect = {0, 0, 0, 0};
SDL_QueryTexture(texture, NULL, NULL, &texture_rect.w, &texture_rect.h); query_texture(texture, NULL, NULL, &texture_rect.w, &texture_rect.h);
const SDL_Rect src = {0, 0, texture_rect.w, texture_rect.h}; const SDL_FRect src = {
const SDL_Rect dest = {x, y, texture_rect.w, texture_rect.h}; 0.0f,
0.0f,
static_cast<float>(texture_rect.w),
static_cast<float>(texture_rect.h)
};
const SDL_FRect dest = {
static_cast<float>(x),
static_cast<float>(y),
static_cast<float>(texture_rect.w),
static_cast<float>(texture_rect.h)
};
set_render_target(temp); set_render_target(temp);
clear(); clear();
@@ -813,7 +852,7 @@ void Graphics::drawtile3(int x, int y, int t, int off, int height_subtract /*= 0
// so do the logic ourselves (except include height_subtract in the final call) // so do the logic ourselves (except include height_subtract in the final call)
int width; int width;
if (query_texture(grphx.im_tiles3, NULL, NULL, &width, NULL) != 0) if (!query_texture(grphx.im_tiles3, NULL, NULL, &width, NULL))
{ {
return; return;
} }
@@ -1120,7 +1159,7 @@ void Graphics::drawimagecol( int t, int xp, int yp, const SDL_Color ct, bool cen
trect.x = xp; trect.x = xp;
trect.y = yp; trect.y = yp;
if (query_texture(images[t], NULL, NULL, &trect.w, &trect.h) != 0) if (!query_texture(images[t], NULL, NULL, &trect.w, &trect.h))
{ {
return; return;
} }
@@ -1147,7 +1186,7 @@ void Graphics::drawimage( int t, int xp, int yp, bool cent/*=false*/ )
trect.x = xp; trect.x = xp;
trect.y = yp; trect.y = yp;
if (query_texture(images[t], NULL, NULL, &trect.w, &trect.h) != 0) if (!query_texture(images[t], NULL, NULL, &trect.w, &trect.h))
{ {
return; return;
} }
@@ -1173,19 +1212,29 @@ void Graphics::draw_texture(SDL_Texture* image, const int x, const int y)
{ {
int w, h; int w, h;
if (query_texture(image, NULL, NULL, &w, &h) != 0) if (!query_texture(image, NULL, NULL, &w, &h))
{ {
return; return;
} }
const SDL_Rect dstrect = {x, y, w, h}; const SDL_FRect dstrect = {
static_cast<float>(x),
static_cast<float>(y),
static_cast<float>(w),
static_cast<float>(h)
};
copy_texture(image, NULL, &dstrect); copy_texture(image, NULL, &dstrect);
} }
void Graphics::draw_texture_part(SDL_Texture* image, const int x, const int y, const int x2, const int y2, const int w, const int h, const int scalex, const int scaley) void Graphics::draw_texture_part(SDL_Texture* image, const int x, const int y, const int x2, const int y2, const int w, const int h, const int scalex, const int scaley)
{ {
const SDL_Rect srcrect = {x2, y2, w, h}; const SDL_FRect srcrect = {
static_cast<float>(x2),
static_cast<float>(y2),
static_cast<float>(w),
static_cast<float>(h)
};
int flip = SDL_FLIP_NONE; int flip = SDL_FLIP_NONE;
@@ -1198,16 +1247,21 @@ void Graphics::draw_texture_part(SDL_Texture* image, const int x, const int y, c
flip |= SDL_FLIP_VERTICAL; flip |= SDL_FLIP_VERTICAL;
} }
const SDL_Rect dstrect = {x, y, w * SDL_abs(scalex), h * SDL_abs(scaley)}; const SDL_FRect dstrect = {
static_cast<float>(x),
static_cast<float>(y),
static_cast<float>(w * SDL_abs(scalex)),
static_cast<float>(h * SDL_abs(scaley))
};
copy_texture(image, &srcrect, &dstrect, 0, NULL, (SDL_RendererFlip) flip); copy_texture(image, &srcrect, &dstrect, 0, NULL, (SDL_FlipMode) flip);
} }
void Graphics::draw_grid_tile(SDL_Texture* texture, const int t, const int x, const int y, const int width, const int height, const int scalex, const int scaley) void Graphics::draw_grid_tile(SDL_Texture* texture, const int t, const int x, const int y, const int width, const int height, const int scalex, const int scaley)
{ {
int tex_width; int tex_width;
if (query_texture(texture, NULL, NULL, &tex_width, NULL) != 0) if (!query_texture(texture, NULL, NULL, &tex_width, NULL))
{ {
return; return;
} }
@@ -2323,7 +2377,8 @@ void Graphics::drawbackground( int t )
fill_rect(0, 0, 0); fill_rect(0, 0, 0);
for (int i = 0; i < numstars; i++) for (int i = 0; i < numstars; i++)
{ {
SDL_Rect star_rect = stars[i]; SDL_FRect star_rect = {0};
SDL_RectToFRect(&stars[i], &star_rect);
star_rect.x = lerp(star_rect.x + starsspeed[i], star_rect.x); star_rect.x = lerp(star_rect.x + starsspeed[i], star_rect.x);
if (starsspeed[i] <= 6) if (starsspeed[i] <= 6)
{ {
@@ -2476,7 +2531,8 @@ void Graphics::drawbackground( int t )
break; break;
} }
SDL_Rect backboxrect = backboxes[i]; SDL_FRect backboxrect = {0};
SDL_RectToFRect(&backboxes[i], &backboxrect);
backboxrect.x = lerp(backboxes[i].x - backboxvx[i], backboxes[i].x); backboxrect.x = lerp(backboxes[i].x - backboxvx[i], backboxes[i].x);
backboxrect.y = lerp(backboxes[i].y - backboxvy[i], backboxes[i].y); backboxrect.y = lerp(backboxes[i].y - backboxvy[i], backboxes[i].y);
@@ -2494,7 +2550,12 @@ void Graphics::drawbackground( int t )
clear(); clear();
const int offset = (int) lerp(-3, 0); const int offset = (int) lerp(-3, 0);
const SDL_Rect srcRect = {8 + offset, 0, SCREEN_WIDTH_PIXELS, SCREEN_HEIGHT_PIXELS}; const SDL_FRect srcRect = {
8.0f + offset,
0.0f,
static_cast<float>(SCREEN_WIDTH_PIXELS),
static_cast<float>(SCREEN_HEIGHT_PIXELS)
};
copy_texture(backgroundTexture, &srcRect, NULL); copy_texture(backgroundTexture, &srcRect, NULL);
break; break;
@@ -2504,7 +2565,12 @@ void Graphics::drawbackground( int t )
clear(); clear();
const int offset = (int) lerp(-3, 0); const int offset = (int) lerp(-3, 0);
const SDL_Rect srcRect = {0, 8 + offset, SCREEN_WIDTH_PIXELS, SCREEN_HEIGHT_PIXELS}; const SDL_FRect srcRect = {
0.0f,
8.0f + offset,
static_cast<float>(SCREEN_WIDTH_PIXELS),
static_cast<float>(SCREEN_HEIGHT_PIXELS)
};
copy_texture(backgroundTexture, &srcRect, NULL); copy_texture(backgroundTexture, &srcRect, NULL);
break; break;
@@ -2554,7 +2620,12 @@ void Graphics::drawbackground( int t )
for (int i = 10; i >= 0; i--) for (int i = 10; i >= 0; i--)
{ {
const int temp = (i * 16) + backoffset; const int temp = (i * 16) + backoffset;
const SDL_Rect warprect = {160 - temp, 120 - temp, temp * 2, temp * 2}; const SDL_FRect warprect = {
160.0f - temp,
120.0f - temp,
temp * 2.0f,
temp * 2.0f
};
if (i % 2 == warpskip) if (i % 2 == warpskip)
{ {
fill_rect(&warprect, warpbcol); fill_rect(&warprect, warpbcol);
@@ -2571,7 +2642,8 @@ void Graphics::drawbackground( int t )
fill_rect(0, 0, 0); fill_rect(0, 0, 0);
for (int i = 0; i < numstars; i++) for (int i = 0; i < numstars; i++)
{ {
SDL_Rect star_rect = stars[i]; SDL_FRect star_rect = {0};
SDL_RectToFRect(&stars[i], &star_rect);
star_rect.y = lerp(star_rect.y + starsspeed[i], star_rect.y); star_rect.y = lerp(star_rect.y + starsspeed[i], star_rect.y);
if (starsspeed[i] <= 8) if (starsspeed[i] <= 8)
{ {
@@ -2903,7 +2975,12 @@ void Graphics::drawtowerbackground(const TowerBG& bg_obj)
clear(); clear();
const int offset = (int) lerp(-bg_obj.bscroll, 0); const int offset = (int) lerp(-bg_obj.bscroll, 0);
const SDL_Rect srcRect = {0, 8 + offset, SCREEN_WIDTH_PIXELS, SCREEN_HEIGHT_PIXELS}; const SDL_FRect srcRect = {
0.0f,
8.0f + offset,
static_cast<float>(SCREEN_WIDTH_PIXELS),
static_cast<float>(SCREEN_HEIGHT_PIXELS)
};
copy_texture(bg_obj.texture, &srcRect, NULL); copy_texture(bg_obj.texture, &srcRect, NULL);
} }
@@ -3184,15 +3261,20 @@ SDL_Color Graphics::getcol( int t )
void Graphics::menuoffrender(void) void Graphics::menuoffrender(void)
{ {
if (copy_texture(gameplayTexture, NULL, NULL) != 0) if (copy_texture(gameplayTexture, NULL, NULL) == 0)
{ {
return; return;
} }
const int offset = (int) lerp(oldmenuoffset, menuoffset); const int offset = (int) lerp(oldmenuoffset, menuoffset);
const SDL_Rect offsetRect = {0, offset, SCREEN_WIDTH_PIXELS, SCREEN_HEIGHT_PIXELS}; const SDL_FRect offsetRect = {
0.0f,
static_cast<float>(offset),
static_cast<float>(SCREEN_WIDTH_PIXELS),
static_cast<float>(SCREEN_HEIGHT_PIXELS)
};
if (copy_texture(menuTexture, NULL, &offsetRect) != 0) if (copy_texture(menuTexture, NULL, &offsetRect) == 0)
{ {
return; return;
} }
@@ -3458,7 +3540,12 @@ void Graphics::screenshake(void)
set_blendmode(SDL_BLENDMODE_NONE); set_blendmode(SDL_BLENDMODE_NONE);
clear(); clear();
const SDL_Rect shake = {screenshake_x, screenshake_y, SCREEN_WIDTH_PIXELS, SCREEN_HEIGHT_PIXELS}; const SDL_FRect shake = {
static_cast<float>(screenshake_x),
static_cast<float>(screenshake_y),
static_cast<float>(SCREEN_WIDTH_PIXELS),
static_cast<float>(SCREEN_HEIGHT_PIXELS)
};
copy_texture(gameTexture, NULL, &shake); copy_texture(gameTexture, NULL, &shake);
@@ -3478,7 +3565,7 @@ void Graphics::screenshake(void)
set_blendmode(SDL_BLENDMODE_NONE); set_blendmode(SDL_BLENDMODE_NONE);
draw_window_background(); draw_window_background();
SDL_Rect rect; SDL_FRect rect;
get_stretch_info(&rect); get_stretch_info(&rect);
copy_texture(tempShakeTexture, NULL, &rect, 0, NULL, flipmode ? SDL_FLIP_VERTICAL : SDL_FLIP_NONE); copy_texture(tempShakeTexture, NULL, &rect, 0, NULL, flipmode ? SDL_FLIP_VERTICAL : SDL_FLIP_NONE);
@@ -3495,7 +3582,7 @@ void Graphics::draw_window_background(void)
clear(); clear();
} }
void Graphics::get_stretch_info(SDL_Rect* rect) void Graphics::get_stretch_info(SDL_FRect* rect)
{ {
int width; int width;
int height; int height;
@@ -3563,7 +3650,7 @@ void Graphics::render(void)
draw_window_background(); draw_window_background();
SDL_Rect stretch_info; SDL_FRect stretch_info;
get_stretch_info(&stretch_info); get_stretch_info(&stretch_info);
ime_set_rect(&stretch_info); ime_set_rect(&stretch_info);
@@ -3637,7 +3724,12 @@ void Graphics::draw_screenshot_border(void)
return; return;
} }
const SDL_Rect rect_inner = {1, 1, width - 2, height - 2}; const SDL_FRect rect_inner = {
1.0f,
1.0f,
width - 2.0f,
height - 2.0f
};
if (game.screenshot_saved_success) if (game.screenshot_saved_success)
{ {
@@ -3699,7 +3791,7 @@ bool Graphics::checktexturesize(
) { ) {
int texturewidth; int texturewidth;
int textureheight; int textureheight;
if (query_texture(texture, NULL, NULL, &texturewidth, &textureheight) != 0) if (!query_texture(texture, NULL, NULL, &texturewidth, &textureheight))
{ {
/* Just give it the benefit of the doubt. */ /* Just give it the benefit of the doubt. */
vlog_warn( vlog_warn(
+34 -34
View File
@@ -248,52 +248,52 @@ public:
uint8_t b uint8_t b
); );
int set_render_target(SDL_Texture* texture); bool set_render_target(SDL_Texture* texture);
int set_texture_color_mod(SDL_Texture* texture, Uint8 r, Uint8 g, Uint8 b); bool set_texture_color_mod(SDL_Texture* texture, Uint8 r, Uint8 g, Uint8 b);
int set_texture_alpha_mod(SDL_Texture* texture, Uint8 alpha); bool set_texture_alpha_mod(SDL_Texture* texture, Uint8 alpha);
int query_texture(SDL_Texture* texture, Uint32* format, int* access, int* w, int* h); bool query_texture(SDL_Texture* texture, Uint32* format, int* access, int* w, int* h);
int set_blendmode(SDL_BlendMode blendmode); bool set_blendmode(SDL_BlendMode blendmode);
int set_blendmode(SDL_Texture* texture, SDL_BlendMode blendmode); bool set_blendmode(SDL_Texture* texture, SDL_BlendMode blendmode);
int clear(int r, int g, int b, int a); bool clear(int r, int g, int b, int a);
int clear(void); bool clear(void);
bool substitute(SDL_Texture** texture); bool substitute(SDL_Texture** texture);
void post_substitute(SDL_Texture* subst); void post_substitute(SDL_Texture* subst);
int copy_texture(SDL_Texture* texture, const SDL_Rect* src, const SDL_Rect* dest); bool copy_texture(SDL_Texture* texture, const SDL_FRect* src, const SDL_FRect* dest);
int copy_texture(SDL_Texture* texture, const SDL_Rect* src, const SDL_Rect* dest, double angle, const SDL_Point* center, SDL_RendererFlip flip); bool copy_texture(SDL_Texture* texture, const SDL_FRect* src, const SDL_FRect* dest, double angle, const SDL_FPoint* center, SDL_FlipMode flip);
int set_color(Uint8 r, Uint8 g, Uint8 b, Uint8 a); bool set_color(Uint8 r, Uint8 g, Uint8 b, Uint8 a);
int set_color(Uint8 r, Uint8 g, Uint8 b); bool set_color(Uint8 r, Uint8 g, Uint8 b);
int set_color(SDL_Color color); bool set_color(SDL_Color color);
int fill_rect(const SDL_Rect* rect); bool fill_rect(const SDL_FRect* rect);
int fill_rect(const SDL_Rect* rect, int r, int g, int b, int a); bool fill_rect(const SDL_FRect* rect, int r, int g, int b, int a);
int fill_rect(int x, int y, int w, int h, int r, int g, int b, int a); bool fill_rect(int x, int y, int w, int h, int r, int g, int b, int a);
int fill_rect(int x, int y, int w, int h, int r, int g, int b); bool fill_rect(int x, int y, int w, int h, int r, int g, int b);
int fill_rect(const SDL_Rect* rect, int r, int g, int b); bool fill_rect(const SDL_FRect* rect, int r, int g, int b);
int fill_rect(int r, int g, int b); bool fill_rect(int r, int g, int b);
int fill_rect(const SDL_Rect* rect, SDL_Color color); bool fill_rect(const SDL_FRect* rect, SDL_Color color);
int fill_rect(int x, int y, int w, int h, SDL_Color color); bool fill_rect(int x, int y, int w, int h, SDL_Color color);
int fill_rect(SDL_Color color); bool fill_rect(SDL_Color color);
int draw_rect(const SDL_Rect* rect); bool draw_rect(const SDL_FRect* rect);
int draw_rect(const SDL_Rect* rect, int r, int g, int b, int a); bool draw_rect(const SDL_FRect* rect, int r, int g, int b, int a);
int draw_rect(int x, int y, int w, int h, int r, int g, int b, int a); bool draw_rect(int x, int y, int w, int h, int r, int g, int b, int a);
int draw_rect(int x, int y, int w, int h, int r, int g, int b); bool draw_rect(int x, int y, int w, int h, int r, int g, int b);
int draw_rect(const SDL_Rect* rect, int r, int g, int b); bool draw_rect(const SDL_FRect* rect, int r, int g, int b);
int draw_rect(const SDL_Rect* rect, SDL_Color color); bool draw_rect(const SDL_FRect* rect, SDL_Color color);
int draw_rect(int x, int y, int w, int h, SDL_Color color); bool draw_rect(int x, int y, int w, int h, SDL_Color color);
int draw_line(int x, int y, int x2, int y2); bool draw_line(int x, int y, int x2, int y2);
int draw_points(const SDL_Point* points, int count); bool draw_points(const SDL_FPoint* points, int count);
int draw_points(const SDL_Point* points, int count, int r, int g, int b); bool draw_points(const SDL_FPoint* points, int count, int r, int g, int b);
void map_tab(int opt, const char* text, bool selected = false); void map_tab(int opt, const char* text, bool selected = false);
@@ -311,7 +311,7 @@ public:
void draw_window_background(void); void draw_window_background(void);
void get_stretch_info(SDL_Rect* rect); void get_stretch_info(SDL_FRect* rect);
void render(void); void render(void);
void renderwithscreeneffects(void); void renderwithscreeneffects(void);
@@ -412,7 +412,7 @@ public:
SDL_Rect sprites_rect; SDL_Rect sprites_rect;
SDL_Rect tele_rect; SDL_Rect tele_rect;
SDL_Rect footerrect; SDL_FRect footerrect;
int linestate, linedelay; int linestate, linedelay;
int backoffset; int backoffset;
+13 -18
View File
@@ -59,17 +59,13 @@ static SDL_Surface* LoadImageRaw(const char* filename, unsigned char** data)
return NULL; return NULL;
} }
loadedImage = SDL_CreateRGBSurfaceWithFormatFrom( loadedImage = SDL_CreateSurfaceFrom(width, height,
*data,
width,
height,
32,
width * 4,
#if SDL_BYTEORDER == SDL_BIG_ENDIAN #if SDL_BYTEORDER == SDL_BIG_ENDIAN
SDL_PIXELFORMAT_RGBA8888 SDL_PIXELFORMAT_RGBA8888
#else #else
SDL_PIXELFORMAT_ABGR8888 SDL_PIXELFORMAT_ABGR8888
#endif #endif
, *data, width * 4
); );
return loadedImage; return loadedImage;
@@ -77,10 +73,9 @@ static SDL_Surface* LoadImageRaw(const char* filename, unsigned char** data)
static SDL_Surface* LoadSurfaceFromRaw(SDL_Surface* loadedImage) static SDL_Surface* LoadSurfaceFromRaw(SDL_Surface* loadedImage)
{ {
SDL_Surface* optimizedImage = SDL_ConvertSurfaceFormat( SDL_Surface* optimizedImage = SDL_ConvertSurface(
loadedImage, loadedImage,
SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_ARGB8888
0
); );
SDL_SetSurfaceBlendMode(optimizedImage, SDL_BLENDMODE_BLEND); SDL_SetSurfaceBlendMode(optimizedImage, SDL_BLENDMODE_BLEND);
return optimizedImage; return optimizedImage;
@@ -95,7 +90,7 @@ SDL_Surface* LoadImageSurface(const char* filename)
SDL_Surface* optimizedImage = LoadSurfaceFromRaw(loadedImage); SDL_Surface* optimizedImage = LoadSurfaceFromRaw(loadedImage);
if (loadedImage != NULL) if (loadedImage != NULL)
{ {
VVV_freefunc(SDL_FreeSurface, loadedImage); VVV_freefunc(SDL_DestroySurface, loadedImage);
} }
VVV_free(data); VVV_free(data);
@@ -185,7 +180,7 @@ SDL_Texture* LoadImage(const char *filename, const TextureLoadType loadtype)
if (loadedImage != NULL) if (loadedImage != NULL)
{ {
VVV_freefunc(SDL_FreeSurface, loadedImage); VVV_freefunc(SDL_DestroySurface, loadedImage);
} }
VVV_free(data); VVV_free(data);
@@ -242,7 +237,7 @@ static void LoadVariants(const char* filename, SDL_Texture** colored, SDL_Textur
if (loadedImage != NULL) if (loadedImage != NULL)
{ {
VVV_freefunc(SDL_FreeSurface, loadedImage); VVV_freefunc(SDL_DestroySurface, loadedImage);
} }
VVV_free(data); VVV_free(data);
@@ -270,7 +265,7 @@ static void LoadSprites(const char* filename, SDL_Texture** texture, SDL_Surface
if (loadedImage != NULL) if (loadedImage != NULL)
{ {
VVV_freefunc(SDL_FreeSurface, loadedImage); VVV_freefunc(SDL_DestroySurface, loadedImage);
} }
VVV_free(data); VVV_free(data);
@@ -308,7 +303,7 @@ static void LoadSpritesTranslation(
SDL_Surface* loaded_image = LoadImageRaw(filename, &data); SDL_Surface* loaded_image = LoadImageRaw(filename, &data);
translated = LoadSurfaceFromRaw(loaded_image); translated = LoadSurfaceFromRaw(loaded_image);
VVV_freefunc(SDL_FreeSurface, loaded_image); VVV_freefunc(SDL_DestroySurface, loaded_image);
VVV_free(data); VVV_free(data);
} }
SDL_SetSurfaceBlendMode(translated, SDL_BLENDMODE_NONE); SDL_SetSurfaceBlendMode(translated, SDL_BLENDMODE_NONE);
@@ -344,8 +339,8 @@ static void LoadSpritesTranslation(
*texture = LoadTextureFromRaw(filename, working, TEX_WHITE); *texture = LoadTextureFromRaw(filename, working, TEX_WHITE);
VVV_freefunc(SDL_FreeSurface, translated); VVV_freefunc(SDL_DestroySurface, translated);
VVV_freefunc(SDL_FreeSurface, working); VVV_freefunc(SDL_DestroySurface, working);
} }
void GraphicsResources::init_translations(void) void GraphicsResources::init_translations(void)
@@ -510,8 +505,8 @@ void GraphicsResources::destroy(void)
} }
#undef CLEAR #undef CLEAR
VVV_freefunc(SDL_FreeSurface, im_sprites_surf); VVV_freefunc(SDL_DestroySurface, im_sprites_surf);
VVV_freefunc(SDL_FreeSurface, im_flipsprites_surf); VVV_freefunc(SDL_DestroySurface, im_flipsprites_surf);
} }
bool SaveImage(const SDL_Surface* surface, const char* filename) bool SaveImage(const SDL_Surface* surface, const char* filename)
+1 -1
View File
@@ -1,7 +1,7 @@
#ifndef GRAPHICSRESOURCES_H #ifndef GRAPHICSRESOURCES_H
#define GRAPHICSRESOURCES_H #define GRAPHICSRESOURCES_H
#include <SDL.h> #include <SDL3/SDL.h>
enum TextureLoadType enum TextureLoadType
{ {
+43 -44
View File
@@ -1,4 +1,4 @@
#include <SDL.h> #include <SDL3/SDL.h>
#include <stddef.h> #include <stddef.h>
#include <stdlib.h> #include <stdlib.h>
@@ -10,9 +10,6 @@
#include "UtilityClass.h" #include "UtilityClass.h"
#include "Vlogging.h" #include "Vlogging.h"
void setRect( SDL_Rect& _r, int x, int y, int w, int h ) void setRect( SDL_Rect& _r, int x, int y, int w, int h )
{ {
_r.x = x; _r.x = x;
@@ -21,6 +18,14 @@ void setRect( SDL_Rect& _r, int x, int y, int w, int h )
_r.h = h; _r.h = h;
} }
void setRect( SDL_FRect& _r, int x, int y, int w, int h )
{
_r.x = x;
_r.y = y;
_r.w = w;
_r.h = h;
}
static SDL_Surface* RecreateSurfaceWithDimensions( static SDL_Surface* RecreateSurfaceWithDimensions(
SDL_Surface* surface, SDL_Surface* surface,
const int width, const int width,
@@ -34,15 +39,10 @@ static SDL_Surface* RecreateSurfaceWithDimensions(
return NULL; return NULL;
} }
retval = SDL_CreateRGBSurface( retval = SDL_CreateSurface(
surface->flags,
width, width,
height, height,
surface->format->BitsPerPixel, surface->format
surface->format->Rmask,
surface->format->Gmask,
surface->format->Bmask,
surface->format->Amask
); );
if (retval == NULL) if (retval == NULL)
@@ -95,8 +95,9 @@ void DrawPixel(SDL_Surface* surface, const int x, const int y, const SDL_Color c
return; return;
} }
const SDL_PixelFormat* fmt = surface->format; const SDL_PixelFormat fmt = surface->format;
const int bpp = fmt->BytesPerPixel; const SDL_PixelFormatDetails *fmt_details = SDL_GetPixelFormatDetails(fmt);
const int bpp = fmt_details->bytes_per_pixel;
Uint8* pixel = (Uint8*) surface->pixels + y * surface->pitch + x * bpp; Uint8* pixel = (Uint8*) surface->pixels + y * surface->pitch + x * bpp;
Uint32* pixel32 = (Uint32*) pixel; Uint32* pixel32 = (Uint32*) pixel;
@@ -109,7 +110,7 @@ void DrawPixel(SDL_Surface* surface, const int x, const int y, const SDL_Color c
case 3: case 3:
{ {
const Uint32 single = SDL_MapRGB(fmt, color.r, color.g, color.b); const Uint32 single = SDL_MapSurfaceRGB(surface, color.r, color.g, color.b);
pixel[0] = (single & 0xFF0000) >> 16; pixel[0] = (single & 0xFF0000) >> 16;
pixel[1] = (single & 0x00FF00) >> 8; pixel[1] = (single & 0x00FF00) >> 8;
pixel[2] = (single & 0x0000FF) >> 0; pixel[2] = (single & 0x0000FF) >> 0;
@@ -117,7 +118,7 @@ void DrawPixel(SDL_Surface* surface, const int x, const int y, const SDL_Color c
} }
case 4: case 4:
*pixel32 = SDL_MapRGBA(fmt, color.r, color.g, color.b, color.a); *pixel32 = SDL_MapSurfaceRGBA(surface, color.r, color.g, color.b, color.a);
} }
} }
@@ -138,8 +139,9 @@ SDL_Color ReadPixel(const SDL_Surface* surface, const int x, const int y)
return color; return color;
} }
const SDL_PixelFormat* fmt = surface->format; const SDL_PixelFormat fmt = surface->format;
const int bpp = surface->format->BytesPerPixel; const SDL_PixelFormatDetails *fmt_details = SDL_GetPixelFormatDetails(fmt);
const int bpp = fmt_details->bytes_per_pixel;
const Uint8* pixel = (Uint8*) surface->pixels + y * surface->pitch + x * bpp; const Uint8* pixel = (Uint8*) surface->pixels + y * surface->pitch + x * bpp;
const Uint32* pixel32 = (Uint32*) pixel; const Uint32* pixel32 = (Uint32*) pixel;
@@ -153,13 +155,13 @@ SDL_Color ReadPixel(const SDL_Surface* surface, const int x, const int y)
case 3: case 3:
{ {
const Uint32 single = (pixel[0] << 16) | (pixel[1] << 8) | (pixel[2] << 0); const Uint32 single = (pixel[0] << 16) | (pixel[1] << 8) | (pixel[2] << 0);
SDL_GetRGB(single, fmt, &color.r, &color.g, &color.b); SDL_GetRGB(single, fmt_details, SDL_GetSurfacePalette((SDL_Surface *) surface), &color.r, &color.g, &color.b);
color.a = 255; color.a = 255;
break; break;
} }
case 4: case 4:
SDL_GetRGBA(*pixel32, fmt, &color.r, &color.g, &color.b, &color.a); SDL_GetRGBA(*pixel32, fmt_details, SDL_GetSurfacePalette((SDL_Surface *) surface), &color.r, &color.g, &color.b, &color.a);
} }
return color; return color;
@@ -206,11 +208,11 @@ void ApplyFilter(SDL_Surface** src, SDL_Surface** dest)
if (*src == NULL) if (*src == NULL)
{ {
*src = SDL_CreateRGBSurface(0, SCREEN_WIDTH_PIXELS, SCREEN_HEIGHT_PIXELS, 32, 0, 0, 0, 0); *src = SDL_CreateSurface(SCREEN_WIDTH_PIXELS, SCREEN_HEIGHT_PIXELS, SDL_GetPixelFormatForMasks(32, 0, 0, 0, 0));
} }
if (*dest == NULL) if (*dest == NULL)
{ {
*dest = SDL_CreateRGBSurface(0, SCREEN_WIDTH_PIXELS, SCREEN_HEIGHT_PIXELS, 32, 0, 0, 0, 0); *dest = SDL_CreateSurface(SCREEN_WIDTH_PIXELS, SCREEN_HEIGHT_PIXELS, SDL_GetPixelFormatForMasks(32, 0, 0, 0, 0));
} }
if (*src == NULL || *dest == NULL) if (*src == NULL || *dest == NULL)
{ {
@@ -218,16 +220,19 @@ void ApplyFilter(SDL_Surface** src, SDL_Surface** dest)
return; return;
} }
const int result = SDL_RenderReadPixels(gameScreen.m_renderer, NULL, 0, (*src)->pixels, (*src)->pitch); SDL_Surface *read_pixels = SDL_RenderReadPixels(gameScreen.m_renderer, NULL);
if (result != 0) if (read_pixels == NULL)
{ {
disabled_filter = true; disabled_filter = true;
VVV_freefunc(SDL_FreeSurface, *src); VVV_freefunc(SDL_DestroySurface, *src);
VVV_freefunc(SDL_FreeSurface, *dest); VVV_freefunc(SDL_DestroySurface, *dest);
WHINE_ONCE_ARGS(("Could not read pixels from renderer: %s", SDL_GetError())); WHINE_ONCE_ARGS(("Could not read pixels from renderer: %s", SDL_GetError()));
return; return;
} }
SDL_BlitSurface(read_pixels, NULL, *src, NULL);
SDL_DestroySurface(read_pixels);
const int red_offset = rand() % 4; const int red_offset = rand() % 4;
for (int x = 0; x < (*src)->w; x++) for (int x = 0; x < (*src)->w; x++)
@@ -294,17 +299,14 @@ bool TakeScreenshot(SDL_Surface** surface)
int width = 0; int width = 0;
int height = 0; int height = 0;
int result = graphics.query_texture( if (!graphics.query_texture(graphics.gameTexture, NULL, NULL, &width,
graphics.gameTexture, NULL, NULL, &width, &height &height)) {
); return false;
if (result != 0)
{
return false;
} }
if (*surface == NULL) if (*surface == NULL)
{ {
*surface = SDL_CreateRGBSurface(0, width, height, 24, 0, 0, 0, 0); *surface = SDL_CreateSurface(width, height, SDL_PIXELFORMAT_RGB24);
if (*surface == NULL) if (*surface == NULL)
{ {
WHINE_ONCE_ARGS( WHINE_ONCE_ARGS(
@@ -320,17 +322,13 @@ bool TakeScreenshot(SDL_Surface** surface)
return false; return false;
} }
result = graphics.set_render_target(graphics.gameTexture); if (!graphics.set_render_target(graphics.gameTexture))
if (result != 0)
{ {
return false; return false;
} }
result = SDL_RenderReadPixels( SDL_Surface *read_pixels = SDL_RenderReadPixels(gameScreen.m_renderer, NULL);
gameScreen.m_renderer, NULL, SDL_PIXELFORMAT_RGB24, if (read_pixels == NULL)
(*surface)->pixels, (*surface)->pitch
);
if (result != 0)
{ {
WHINE_ONCE_ARGS( WHINE_ONCE_ARGS(
("Could not read pixels from renderer: %s", SDL_GetError()) ("Could not read pixels from renderer: %s", SDL_GetError())
@@ -338,6 +336,9 @@ bool TakeScreenshot(SDL_Surface** surface)
return false; return false;
} }
SDL_BlitSurface(read_pixels, NULL, *surface, NULL);
SDL_DestroySurface(read_pixels);
/* Need to manually vertically reverse pixels in Flip Mode. */ /* Need to manually vertically reverse pixels in Flip Mode. */
if (graphics.flipmode) if (graphics.flipmode)
{ {
@@ -371,9 +372,7 @@ bool UpscaleScreenshot2x(SDL_Surface* src, SDL_Surface** dest)
if (*dest == NULL) if (*dest == NULL)
{ {
*dest = SDL_CreateRGBSurface( *dest = SDL_CreateSurface(src->w * 2, src->h * 2, src->format);
0, src->w * 2, src->h * 2, src->format->BitsPerPixel, 0, 0, 0, 0
);
if (*dest == NULL) if (*dest == NULL)
{ {
WHINE_ONCE_ARGS( WHINE_ONCE_ARGS(
@@ -383,8 +382,8 @@ bool UpscaleScreenshot2x(SDL_Surface* src, SDL_Surface** dest)
} }
} }
int result = SDL_BlitScaled(src, NULL, *dest, NULL); int result = SDL_BlitSurfaceScaled(src, NULL, *dest, NULL, SDL_SCALEMODE_PIXELART);
if (result != 0) if (result == 0)
{ {
WHINE_ONCE_ARGS(("Could not blit surface: %s", SDL_GetError())); WHINE_ONCE_ARGS(("Could not blit surface: %s", SDL_GetError()));
return false; return false;
+2 -1
View File
@@ -1,9 +1,10 @@
#ifndef GRAPHICSUTIL_H #ifndef GRAPHICSUTIL_H
#define GRAPHICSUTIL_H #define GRAPHICSUTIL_H
#include <SDL.h> #include <SDL3/SDL.h>
void setRect(SDL_Rect& _r, int x, int y, int w, int h); void setRect(SDL_Rect& _r, int x, int y, int w, int h);
void setRect(SDL_FRect& _r, int x, int y, int w, int h);
SDL_Surface* GetSubSurface( SDL_Surface* metaSurface, int x, int y, int width, int height ); SDL_Surface* GetSubSurface( SDL_Surface* metaSurface, int x, int y, int width, int height );
+15 -8
View File
@@ -1,19 +1,21 @@
#include <SDL.h> #include <SDL3/SDL.h>
#include "Constants.h" #include "Constants.h"
#include "Font.h" #include "Font.h"
#include "Graphics.h" #include "Graphics.h"
#include "KeyPoll.h" #include "KeyPoll.h"
#include "UTF8.h" #include "UTF8.h"
#include "Screen.h"
#include "GraphicsUtil.h"
static bool render_done = false; static bool render_done = false;
static SDL_Rect imebox; static SDL_FRect imebox;
void ime_render(void) void ime_render(void)
{ {
render_done = false; render_done = false;
if (!SDL_IsTextInputActive() || key.imebuffer == "") if (!SDL_TextInputActive(gameScreen.m_window) || key.imebuffer == "")
{ {
return; return;
} }
@@ -24,7 +26,7 @@ void ime_render(void)
imebox.w = font::len(PR_FONT_LEVEL, key.imebuffer.c_str()) + 1; imebox.w = font::len(PR_FONT_LEVEL, key.imebuffer.c_str()) + 1;
imebox.h = fontheight + 1; imebox.h = fontheight + 1;
SDL_Rect imebox_border = imebox; SDL_FRect imebox_border = imebox;
imebox_border.x -= 1; imebox_border.x -= 1;
imebox_border.y -= 1; imebox_border.y -= 1;
imebox_border.w += 2; imebox_border.w += 2;
@@ -74,7 +76,7 @@ void ime_render(void)
in_sel_pixels += 1; in_sel_pixels += 1;
} }
SDL_Rect selrect = imebox; SDL_FRect selrect = imebox;
selrect.x += before_sel_pixels + 1; selrect.x += before_sel_pixels + 1;
selrect.w = in_sel_pixels; selrect.w = in_sel_pixels;
graphics.fill_rect(&selrect, 128, 64, 0); graphics.fill_rect(&selrect, 128, 64, 0);
@@ -88,14 +90,19 @@ void ime_render(void)
render_done = true; render_done = true;
} }
void ime_set_rect(SDL_Rect* stretch_info) void ime_set_rect(SDL_FRect* stretch_info)
{ {
if (!render_done) if (!render_done)
{ {
return; return;
} }
SDL_Rect imebox_scaled = imebox; SDL_Rect imebox_scaled = {
static_cast<int>(imebox.x),
static_cast<int>(imebox.y),
static_cast<int>(imebox.w),
static_cast<int>(imebox.h)
};
float x_scale = (float) stretch_info->w / SCREEN_WIDTH_PIXELS; float x_scale = (float) stretch_info->w / SCREEN_WIDTH_PIXELS;
float y_scale = (float) stretch_info->h / SCREEN_HEIGHT_PIXELS; float y_scale = (float) stretch_info->h / SCREEN_HEIGHT_PIXELS;
imebox_scaled.x *= x_scale; imebox_scaled.x *= x_scale;
@@ -105,5 +112,5 @@ void ime_set_rect(SDL_Rect* stretch_info)
imebox_scaled.x += stretch_info->x; imebox_scaled.x += stretch_info->x;
imebox_scaled.y += stretch_info->y; imebox_scaled.y += stretch_info->y;
SDL_SetTextInputRect(&imebox_scaled); SDL_SetTextInputArea(gameScreen.m_window, &imebox_scaled, 0);
} }
+1 -1
View File
@@ -2,6 +2,6 @@
#define IMERENDER_H #define IMERENDER_H
void ime_render(void); void ime_render(void);
void ime_set_rect(SDL_Rect* stretch_info); void ime_set_rect(SDL_FRect* stretch_info);
#endif /* IMERENDER_H */ #endif /* IMERENDER_H */
+9 -6
View File
@@ -25,13 +25,14 @@
#include "Script.h" #include "Script.h"
#include "UtilityClass.h" #include "UtilityClass.h"
#include "Vlogging.h" #include "Vlogging.h"
#include "Alloc.h"
static void updatebuttonmappings(int bind) static void updatebuttonmappings(int bind)
{ {
for ( for (
SDL_GameControllerButton i = SDL_CONTROLLER_BUTTON_A; SDL_GamepadButton i = SDL_GAMEPAD_BUTTON_SOUTH;
i < SDL_CONTROLLER_BUTTON_DPAD_UP; i < SDL_GAMEPAD_BUTTON_DPAD_UP;
i = (SDL_GameControllerButton) (i + 1) i = (SDL_GamepadButton) (i + 1)
) { ) {
if (key.isDown(i)) if (key.isDown(i))
{ {
@@ -41,7 +42,7 @@ static void updatebuttonmappings(int bind)
game.gpmenu_lastbutton = i; game.gpmenu_lastbutton = i;
// Is this button already in the list for this action? // Is this button already in the list for this action?
std::vector<SDL_GameControllerButton>* vec = NULL; std::vector<SDL_GamepadButton>* vec = NULL;
switch (bind) switch (bind)
{ {
case 1: vec = &game.controllerButton_flip; break; case 1: vec = &game.controllerButton_flip; break;
@@ -1407,7 +1408,9 @@ static void menuactionpress(void)
else if (game.currentmenuoption == (int)game.menuoptions.size()-2) else if (game.currentmenuoption == (int)game.menuoptions.size()-2)
{ {
// play the cutscene, from clipboard // play the cutscene, from clipboard
game.cutscenetest_menu_play_id = std::string(SDL_GetClipboardText()); char *cutscene = SDL_GetClipboardText();
game.cutscenetest_menu_play_id = std::string(cutscene);
VVV_free(cutscene);
startmode(Start_CUTSCENETEST); startmode(Start_CUTSCENETEST);
} }
else if (game.currentmenuoption == (int)game.menuoptions.size()-1) else if (game.currentmenuoption == (int)game.menuoptions.size()-1)
@@ -3045,7 +3048,7 @@ void gameinput(void)
game.menupage = 30; // Pause screen game.menupage = 30; // Pause screen
} }
if (game.deathseq == -1 && (key.isDown(SDLK_r) || key.isDown(game.controllerButton_restart)) && !game.nodeathmode)// && map.custommode) //Have fun glitchrunners! if (game.deathseq == -1 && (key.isDown(SDLK_R) || key.isDown(game.controllerButton_restart)) && !game.nodeathmode)// && map.custommode) //Have fun glitchrunners!
{ {
game.deathseq = 30; game.deathseq = 30;
} }
+138 -157
View File
@@ -71,12 +71,12 @@ void KeyPoll::enabletextentry(void)
imebuffer = ""; imebuffer = "";
imebuffer_start = 0; imebuffer_start = 0;
imebuffer_length = 0; imebuffer_length = 0;
SDL_StartTextInput(); SDL_StartTextInput(gameScreen.m_window);
} }
void KeyPoll::disabletextentry(void) void KeyPoll::disabletextentry(void)
{ {
SDL_StopTextInput(); SDL_StopTextInput(gameScreen.m_window);
imebuffer = ""; imebuffer = "";
imebuffer_start = 0; imebuffer_start = 0;
imebuffer_length = 0; imebuffer_length = 0;
@@ -84,7 +84,7 @@ void KeyPoll::disabletextentry(void)
bool KeyPoll::textentry(void) bool KeyPoll::textentry(void)
{ {
return SDL_IsTextInputActive() == SDL_TRUE; return SDL_TextInputActive(gameScreen.m_window) == true;
} }
void KeyPoll::toggleFullscreen(void) void KeyPoll::toggleFullscreen(void)
@@ -106,8 +106,7 @@ static int changemousestate(
const bool show, const bool show,
const bool hide const bool hide
) { ) {
int prev; bool visible;
int new_;
if (timeout > 0) if (timeout > 0)
{ {
@@ -117,34 +116,28 @@ static int changemousestate(
/* If we want to both show and hide at the same time, prioritize showing */ /* If we want to both show and hide at the same time, prioritize showing */
if (show) if (show)
{ {
new_ = SDL_ENABLE; visible = true;
} }
else if (hide) else if (hide)
{ {
new_ = SDL_DISABLE; visible = false;
} }
else else
{ {
return timeout; return timeout;
} }
prev = SDL_ShowCursor(SDL_QUERY); if (SDL_CursorVisible() == visible)
if (prev == new_)
{ {
return timeout; return timeout;
} }
SDL_ShowCursor(new_); if (visible) {
SDL_ShowCursor();
switch (new_)
{
case SDL_DISABLE:
timeout = 0; timeout = 0;
break; } else {
case SDL_ENABLE: SDL_HideCursor();
timeout = 30; timeout = 30;
break;
} }
return timeout; return timeout;
@@ -228,7 +221,7 @@ void KeyPoll::Poll(void)
bool hidemouse = false; bool hidemouse = false;
bool altpressed = false; bool altpressed = false;
bool fullscreenkeybind = false; bool fullscreenkeybind = false;
SDL_GameController *controller = NULL; SDL_Gamepad *controller = NULL;
SDL_Event evt; SDL_Event evt;
bool should_recompute_textboxes = false; bool should_recompute_textboxes = false;
bool active_input_device_changed = false; bool active_input_device_changed = false;
@@ -238,29 +231,29 @@ void KeyPoll::Poll(void)
switch (evt.type) switch (evt.type)
{ {
/* Keyboard Input */ /* Keyboard Input */
case SDL_KEYDOWN: case SDL_EVENT_KEY_DOWN:
{ {
keymap[evt.key.keysym.sym] = true; keymap[evt.key.key] = true;
if (evt.key.keysym.sym == SDLK_BACKSPACE) if (evt.key.key == SDLK_BACKSPACE)
{ {
pressedbackspace = true; pressedbackspace = true;
} }
#ifdef __APPLE__ /* OSX prefers the command keys over the alt keys. -flibit */ #ifdef SDL_PLATFORM_APPLE /* OSX prefers the command keys over the alt keys. -flibit */
altpressed = keymap[SDLK_LGUI] || keymap[SDLK_RGUI]; altpressed = keymap[SDLK_LGUI] || keymap[SDLK_RGUI];
#else #else
altpressed = keymap[SDLK_LALT] || keymap[SDLK_RALT]; altpressed = keymap[SDLK_LALT] || keymap[SDLK_RALT];
#endif #endif
bool returnpressed = evt.key.keysym.sym == SDLK_RETURN; bool returnpressed = evt.key.key == SDLK_RETURN;
bool fpressed = evt.key.keysym.sym == SDLK_f; bool fpressed = evt.key.key == SDLK_F;
bool f11pressed = evt.key.keysym.sym == SDLK_F11; bool f11pressed = evt.key.key == SDLK_F11;
if ((altpressed && (returnpressed || fpressed)) || f11pressed) if ((altpressed && (returnpressed || fpressed)) || f11pressed)
{ {
fullscreenkeybind = true; fullscreenkeybind = true;
} }
if (loc::show_translator_menu && evt.key.keysym.sym == SDLK_F8 && !evt.key.repeat) if (loc::show_translator_menu && evt.key.key == SDLK_F8 && !evt.key.repeat)
{ {
if (keymap[SDLK_LCTRL]) if (keymap[SDLK_LCTRL])
{ {
@@ -276,7 +269,7 @@ void KeyPoll::Poll(void)
} }
} }
if (evt.key.keysym.sym == SDLK_F6 && !evt.key.repeat) if (evt.key.key == SDLK_F6 && !evt.key.repeat)
{ {
const bool success = SaveScreenshot(); const bool success = SaveScreenshot();
game.old_screenshot_border_timer = 255; game.old_screenshot_border_timer = 255;
@@ -288,7 +281,7 @@ void KeyPoll::Poll(void)
if (textentry()) if (textentry())
{ {
if (evt.key.keysym.sym == SDLK_BACKSPACE && !keybuffer.empty()) if (evt.key.key == SDLK_BACKSPACE && !keybuffer.empty())
{ {
keybuffer.erase(UTF8_backspace(keybuffer.c_str(), keybuffer.length())); keybuffer.erase(UTF8_backspace(keybuffer.c_str(), keybuffer.length()));
if (keybuffer.empty()) if (keybuffer.empty())
@@ -296,7 +289,7 @@ void KeyPoll::Poll(void)
linealreadyemptykludge = true; linealreadyemptykludge = true;
} }
} }
else if ( evt.key.keysym.sym == SDLK_v && else if ( evt.key.key == SDLK_V &&
keymap[SDLK_LCTRL] ) keymap[SDLK_LCTRL] )
{ {
char* text = SDL_GetClipboardText(); char* text = SDL_GetClipboardText();
@@ -306,10 +299,10 @@ void KeyPoll::Poll(void)
VVV_free(text); VVV_free(text);
} }
} }
else if ( evt.key.keysym.sym == SDLK_x && else if ( evt.key.key == SDLK_X &&
keymap[SDLK_LCTRL] ) keymap[SDLK_LCTRL] )
{ {
if (SDL_SetClipboardText(keybuffer.c_str()) == 0) if (SDL_SetClipboardText(keybuffer.c_str()))
{ {
keybuffer = ""; keybuffer = "";
} }
@@ -317,37 +310,31 @@ void KeyPoll::Poll(void)
} }
break; break;
} }
case SDL_KEYUP: case SDL_EVENT_KEY_UP:
keymap[evt.key.keysym.sym] = false; keymap[evt.key.key] = false;
if (evt.key.keysym.sym == SDLK_BACKSPACE) if (evt.key.key == SDLK_BACKSPACE)
{ {
pressedbackspace = false; pressedbackspace = false;
} }
break; break;
case SDL_TEXTINPUT: case SDL_EVENT_TEXT_INPUT:
if (!altpressed) if (!altpressed)
{ {
keybuffer += evt.text.text; keybuffer += evt.text.text;
} }
break; break;
case SDL_TEXTEDITING: case SDL_EVENT_TEXT_EDITING:
imebuffer = evt.edit.text; imebuffer = evt.edit.text;
imebuffer_start = evt.edit.start; imebuffer_start = evt.edit.start;
imebuffer_length = evt.edit.length; imebuffer_length = evt.edit.length;
break; break;
case SDL_TEXTEDITING_EXT:
imebuffer = evt.editExt.text;
imebuffer_start = evt.editExt.start;
imebuffer_length = evt.editExt.length;
SDL_free(evt.editExt.text);
break;
/* Mouse Input */ /* Mouse Input */
case SDL_MOUSEMOTION: case SDL_EVENT_MOUSE_MOTION:
raw_mousex = evt.motion.x; raw_mousex = evt.motion.x;
raw_mousey = evt.motion.y; raw_mousey = evt.motion.y;
break; break;
case SDL_MOUSEBUTTONDOWN: case SDL_EVENT_MOUSE_BUTTON_DOWN:
switch (evt.button.button) switch (evt.button.button)
{ {
case SDL_BUTTON_LEFT: case SDL_BUTTON_LEFT:
@@ -367,7 +354,7 @@ void KeyPoll::Poll(void)
break; break;
} }
break; break;
case SDL_MOUSEBUTTONUP: case SDL_EVENT_MOUSE_BUTTON_UP:
switch (evt.button.button) switch (evt.button.button)
{ {
case SDL_BUTTON_LEFT: case SDL_BUTTON_LEFT:
@@ -389,69 +376,69 @@ void KeyPoll::Poll(void)
break; break;
/* Controller Input */ /* Controller Input */
case SDL_CONTROLLERBUTTONDOWN: case SDL_EVENT_GAMEPAD_BUTTON_DOWN:
buttonmap[(SDL_GameControllerButton) evt.cbutton.button] = true; buttonmap[(SDL_GamepadButton) evt.gbutton.button] = true;
BUTTONGLYPHS_keyboard_set_active(false); BUTTONGLYPHS_keyboard_set_active(false);
controller = controllers[evt.cbutton.which]; controller = controllers[evt.gbutton.which];
BUTTONGLYPHS_update_layout(controller); BUTTONGLYPHS_update_layout(controller);
break; break;
case SDL_CONTROLLERBUTTONUP: case SDL_EVENT_GAMEPAD_BUTTON_UP:
buttonmap[(SDL_GameControllerButton) evt.cbutton.button] = false; buttonmap[(SDL_GamepadButton) evt.gbutton.button] = false;
break; break;
case SDL_CONTROLLERAXISMOTION: case SDL_EVENT_GAMEPAD_AXIS_MOTION:
{ {
const int threshold = getThreshold(); const int threshold = getThreshold();
switch (evt.caxis.axis) switch (evt.gaxis.axis)
{ {
case SDL_CONTROLLER_AXIS_LEFTX: case SDL_GAMEPAD_AXIS_LEFTX:
if ( evt.caxis.value > -threshold && if ( evt.gaxis.value > -threshold &&
evt.caxis.value < threshold ) evt.gaxis.value < threshold )
{ {
xVel = 0; xVel = 0;
} }
else else
{ {
xVel = (evt.caxis.value > 0) ? 1 : -1; xVel = (evt.gaxis.value > 0) ? 1 : -1;
} }
break; break;
case SDL_CONTROLLER_AXIS_LEFTY: case SDL_GAMEPAD_AXIS_LEFTY:
if ( evt.caxis.value > -threshold && if ( evt.gaxis.value > -threshold &&
evt.caxis.value < threshold ) evt.gaxis.value < threshold )
{ {
yVel = 0; yVel = 0;
} }
else else
{ {
yVel = (evt.caxis.value > 0) ? 1 : -1; yVel = (evt.gaxis.value > 0) ? 1 : -1;
} }
break; break;
} }
BUTTONGLYPHS_keyboard_set_active(false); BUTTONGLYPHS_keyboard_set_active(false);
controller = controllers[evt.caxis.which]; controller = controllers[evt.gaxis.which];
BUTTONGLYPHS_update_layout(controller); BUTTONGLYPHS_update_layout(controller);
break; break;
} }
case SDL_CONTROLLERDEVICEADDED: case SDL_EVENT_GAMEPAD_ADDED:
{ {
controller = SDL_GameControllerOpen(evt.cdevice.which); controller = SDL_OpenGamepad(evt.cdevice.which);
vlog_info( vlog_info(
"Opened SDL_GameController ID #%i, %s", "Opened SDL_Gamepad ID #%i, %s",
evt.cdevice.which, evt.cdevice.which,
SDL_GameControllerName(controller) SDL_GetGamepadName(controller)
); );
controllers[SDL_JoystickInstanceID(SDL_GameControllerGetJoystick(controller))] = controller; controllers[SDL_GetJoystickID(SDL_GetGamepadJoystick(controller))] = controller;
BUTTONGLYPHS_keyboard_set_active(false); BUTTONGLYPHS_keyboard_set_active(false);
BUTTONGLYPHS_update_layout(controller); BUTTONGLYPHS_update_layout(controller);
break; break;
} }
case SDL_CONTROLLERDEVICEREMOVED: case SDL_EVENT_GAMEPAD_REMOVED:
{ {
controller = controllers[evt.cdevice.which]; controller = controllers[evt.cdevice.which];
controllers.erase(evt.cdevice.which); controllers.erase(evt.cdevice.which);
vlog_info("Closing %s", SDL_GameControllerName(controller)); vlog_info("Closing %s", SDL_GetGamepadName(controller));
SDL_GameControllerClose(controller); SDL_CloseGamepad(controller);
if (controllers.empty()) if (controllers.empty())
{ {
BUTTONGLYPHS_keyboard_set_active(true); BUTTONGLYPHS_keyboard_set_active(true);
@@ -459,102 +446,96 @@ void KeyPoll::Poll(void)
break; break;
} }
case SDL_RENDER_TARGETS_RESET: case SDL_EVENT_RENDER_TARGETS_RESET:
gameScreen.recacheTextures(); gameScreen.recacheTextures();
break; break;
/* Window Events */ /* Window Resize */
case SDL_WINDOWEVENT: case SDL_EVENT_WINDOW_RESIZED:
switch (evt.window.event) if (SDL_GetWindowFlags(
SDL_GetWindowFromID(evt.window.windowID)
) & SDL_WINDOW_INPUT_FOCUS)
{ {
/* Window Resize */ resetWindow = true;
case SDL_WINDOWEVENT_RESIZED:
if (SDL_GetWindowFlags(
SDL_GetWindowFromID(evt.window.windowID)
) & SDL_WINDOW_INPUT_FOCUS)
{
resetWindow = true;
}
break;
/* Window Focus */
case SDL_WINDOWEVENT_FOCUS_GAINED:
if (!game.disablepause)
{
isActive = true;
if ((!game.disableaudiopause || !game.disabletemporaryaudiopause) && music.currentsong != -1)
{
music.resume();
music.resumeef();
}
}
if (SDL_strcmp(SDL_GetCurrentVideoDriver(), "x11") == 0)
{
if (wasFullscreen)
{
gameScreen.isWindowed = false;
SDL_SetWindowFullscreen(
SDL_GetWindowFromID(evt.window.windowID),
SDL_WINDOW_FULLSCREEN_DESKTOP
);
}
}
SDL_DisableScreenSaver();
break;
case SDL_WINDOWEVENT_FOCUS_LOST:
if (!game.disablepause)
{
isActive = false;
if (!game.disableaudiopause || !game.disabletemporaryaudiopause)
{
music.pause();
music.pauseef();
}
}
if (SDL_strcmp(SDL_GetCurrentVideoDriver(), "x11") == 0)
{
wasFullscreen = !gameScreen.isWindowed;
gameScreen.isWindowed = true;
SDL_SetWindowFullscreen(
SDL_GetWindowFromID(evt.window.windowID),
0
);
}
SDL_EnableScreenSaver();
break;
/* Mouse Focus */
case SDL_WINDOWEVENT_ENTER:
SDL_DisableScreenSaver();
break;
case SDL_WINDOWEVENT_LEAVE:
SDL_EnableScreenSaver();
break;
} }
break; break;
/* Window Focus */
case SDL_EVENT_WINDOW_FOCUS_GAINED:
if (!game.disablepause)
{
isActive = true;
if ((!game.disableaudiopause || !game.disabletemporaryaudiopause) && music.currentsong != -1)
{
music.resume();
music.resumeef();
}
}
if (SDL_strcmp(SDL_GetCurrentVideoDriver(), "x11") == 0)
{
if (wasFullscreen)
{
gameScreen.isWindowed = false;
SDL_SetWindowFullscreen(
SDL_GetWindowFromID(evt.window.windowID),
true
);
}
}
SDL_DisableScreenSaver();
break;
case SDL_EVENT_WINDOW_FOCUS_LOST:
if (!game.disablepause)
{
isActive = false;
if (!game.disableaudiopause || !game.disabletemporaryaudiopause)
{
music.pause();
music.pauseef();
}
}
if (SDL_strcmp(SDL_GetCurrentVideoDriver(), "x11") == 0)
{
wasFullscreen = !gameScreen.isWindowed;
gameScreen.isWindowed = true;
SDL_SetWindowFullscreen(
SDL_GetWindowFromID(evt.window.windowID),
false
);
}
SDL_EnableScreenSaver();
break;
/* Mouse Focus */
case SDL_EVENT_WINDOW_MOUSE_ENTER:
SDL_DisableScreenSaver();
break;
case SDL_EVENT_WINDOW_MOUSE_LEAVE:
SDL_EnableScreenSaver();
break;
/* Quit Event */ /* Quit Event */
case SDL_QUIT: case SDL_EVENT_QUIT:
VVV_exit(0); VVV_exit(0);
break; break;
} }
switch (evt.type) switch (evt.type)
{ {
case SDL_KEYDOWN: case SDL_EVENT_KEY_DOWN:
if (evt.key.repeat == 0) if (evt.key.repeat == 0)
{ {
hidemouse = true; hidemouse = true;
} }
break; break;
case SDL_TEXTINPUT: case SDL_EVENT_TEXT_INPUT:
case SDL_CONTROLLERBUTTONDOWN: case SDL_EVENT_GAMEPAD_BUTTON_DOWN:
case SDL_CONTROLLERAXISMOTION: case SDL_EVENT_GAMEPAD_AXIS_MOTION:
hidemouse = true; hidemouse = true;
break; break;
case SDL_MOUSEMOTION: case SDL_EVENT_MOUSE_MOTION:
case SDL_MOUSEBUTTONDOWN: case SDL_EVENT_MOUSE_BUTTON_DOWN:
showmouse = true; showmouse = true;
break; break;
} }
@@ -571,7 +552,7 @@ void KeyPoll::Poll(void)
toggleFullscreen(); toggleFullscreen();
} }
SDL_Rect rect; SDL_FRect rect;
graphics.get_stretch_info(&rect); graphics.get_stretch_info(&rect);
int window_width; int window_width;
@@ -602,7 +583,7 @@ bool KeyPoll::isDown(SDL_Keycode key)
return keymap[key]; return keymap[key];
} }
bool KeyPoll::isDown(std::vector<SDL_GameControllerButton> buttons) bool KeyPoll::isDown(std::vector<SDL_GamepadButton> buttons)
{ {
for (size_t i = 0; i < buttons.size(); i += 1) for (size_t i = 0; i < buttons.size(); i += 1)
{ {
@@ -614,7 +595,7 @@ bool KeyPoll::isDown(std::vector<SDL_GameControllerButton> buttons)
return false; return false;
} }
bool KeyPoll::isDown(SDL_GameControllerButton button) bool KeyPoll::isDown(SDL_GamepadButton button)
{ {
return buttonmap[button]; return buttonmap[button];
} }
@@ -622,9 +603,9 @@ bool KeyPoll::isDown(SDL_GameControllerButton button)
bool KeyPoll::controllerButtonDown(void) bool KeyPoll::controllerButtonDown(void)
{ {
for ( for (
SDL_GameControllerButton button = SDL_CONTROLLER_BUTTON_A; SDL_GamepadButton button = SDL_GAMEPAD_BUTTON_SOUTH;
button < SDL_CONTROLLER_BUTTON_DPAD_UP; button < SDL_GAMEPAD_BUTTON_DPAD_UP;
button = (SDL_GameControllerButton) (button + 1) button = (SDL_GamepadButton) (button + 1)
) { ) {
if (isDown(button)) if (isDown(button))
{ {
@@ -636,28 +617,28 @@ bool KeyPoll::controllerButtonDown(void)
bool KeyPoll::controllerWantsLeft(bool includeVert) bool KeyPoll::controllerWantsLeft(bool includeVert)
{ {
return ( buttonmap[SDL_CONTROLLER_BUTTON_DPAD_LEFT] || return ( buttonmap[SDL_GAMEPAD_BUTTON_DPAD_LEFT] ||
xVel < 0 || xVel < 0 ||
( includeVert && ( includeVert &&
( buttonmap[SDL_CONTROLLER_BUTTON_DPAD_UP] || ( buttonmap[SDL_GAMEPAD_BUTTON_DPAD_UP] ||
yVel < 0 ) ) ); yVel < 0 ) ) );
} }
bool KeyPoll::controllerWantsRight(bool includeVert) bool KeyPoll::controllerWantsRight(bool includeVert)
{ {
return ( buttonmap[SDL_CONTROLLER_BUTTON_DPAD_RIGHT] || return ( buttonmap[SDL_GAMEPAD_BUTTON_DPAD_RIGHT] ||
xVel > 0 || xVel > 0 ||
( includeVert && ( includeVert &&
( buttonmap[SDL_CONTROLLER_BUTTON_DPAD_DOWN] || ( buttonmap[SDL_GAMEPAD_BUTTON_DPAD_DOWN] ||
yVel > 0 ) ) ); yVel > 0 ) ) );
} }
bool KeyPoll::controllerWantsUp(void) bool KeyPoll::controllerWantsUp(void)
{ {
return buttonmap[SDL_CONTROLLER_BUTTON_DPAD_UP] || yVel < 0; return buttonmap[SDL_GAMEPAD_BUTTON_DPAD_UP] || yVel < 0;
} }
bool KeyPoll::controllerWantsDown(void) bool KeyPoll::controllerWantsDown(void)
{ {
return buttonmap[SDL_CONTROLLER_BUTTON_DPAD_DOWN] || yVel > 0; return buttonmap[SDL_GAMEPAD_BUTTON_DPAD_DOWN] || yVel > 0;
} }
+14 -14
View File
@@ -2,7 +2,7 @@
#define KEYPOLL_H #define KEYPOLL_H
#include <map> // FIXME: I should feel very bad for using C++ -flibit #include <map> // FIXME: I should feel very bad for using C++ -flibit
#include <SDL.h> #include <SDL3/SDL.h>
#include <string> #include <string>
#include <vector> #include <vector>
@@ -15,16 +15,16 @@ enum Kybrd
KEYBOARD_ENTER = SDLK_RETURN, KEYBOARD_ENTER = SDLK_RETURN,
KEYBOARD_SPACE = SDLK_SPACE, KEYBOARD_SPACE = SDLK_SPACE,
KEYBOARD_w = SDLK_w, KEYBOARD_w = SDLK_W,
KEYBOARD_s = SDLK_s, KEYBOARD_s = SDLK_S,
KEYBOARD_a = SDLK_a, KEYBOARD_a = SDLK_A,
KEYBOARD_d = SDLK_d, KEYBOARD_d = SDLK_D,
KEYBOARD_e = SDLK_e, KEYBOARD_e = SDLK_E,
KEYBOARD_m = SDLK_m, KEYBOARD_m = SDLK_M,
KEYBOARD_n = SDLK_n, KEYBOARD_n = SDLK_N,
KEYBOARD_v = SDLK_v, KEYBOARD_v = SDLK_V,
KEYBOARD_z = SDLK_z, KEYBOARD_z = SDLK_Z,
KEYBOARD_BACKSPACE = SDLK_BACKSPACE KEYBOARD_BACKSPACE = SDLK_BACKSPACE
}; };
@@ -54,8 +54,8 @@ public:
bool isDown(SDL_Keycode key); bool isDown(SDL_Keycode key);
bool isDown(std::vector<SDL_GameControllerButton> buttons); bool isDown(std::vector<SDL_GamepadButton> buttons);
bool isDown(SDL_GameControllerButton button); bool isDown(SDL_GamepadButton button);
bool controllerButtonDown(void); bool controllerButtonDown(void);
bool controllerWantsLeft(bool includeVert); bool controllerWantsLeft(bool includeVert);
bool controllerWantsRight(bool includeVert); bool controllerWantsRight(bool includeVert);
@@ -76,8 +76,8 @@ public:
bool linealreadyemptykludge; bool linealreadyemptykludge;
private: private:
std::map<SDL_JoystickID, SDL_GameController*> controllers; std::map<SDL_JoystickID, SDL_Gamepad*> controllers;
std::map<SDL_GameControllerButton, bool> buttonmap; std::map<SDL_GamepadButton, bool> buttonmap;
int xVel, yVel; int xVel, yVel;
Uint32 wasFullscreen; Uint32 wasFullscreen;
}; };
+2 -2
View File
@@ -63,7 +63,7 @@ namespace level_debugger
return; return;
} }
if (key.isDown(SDLK_y)) if (key.isDown(SDLK_Y))
{ {
if (!debug_held) if (!debug_held)
{ {
@@ -314,7 +314,7 @@ namespace level_debugger
int line = 0; int line = 0;
if (key.isDown(SDLK_u)) if (key.isDown(SDLK_U))
{ {
SDL_Color on = graphics.getRGB(220 - (help.glow), 220 - (help.glow), 255 - (help.glow / 2)); SDL_Color on = graphics.getRGB(220 - (help.glow), 220 - (help.glow), 255 - (help.glow / 2));
SDL_Color off = graphics.getRGB(220 / 1.5 - (help.glow), 220 / 1.5 - (help.glow), 255 / 1.5 - (help.glow / 2)); SDL_Color off = graphics.getRGB(220 / 1.5 - (help.glow), 220 / 1.5 - (help.glow), 255 / 1.5 - (help.glow / 2));
+1 -1
View File
@@ -1,7 +1,7 @@
#ifndef LEVELDEBUGGER_H #ifndef LEVELDEBUGGER_H
#define LEVELDEBUGGER_H #define LEVELDEBUGGER_H
#include <SDL.h> #include <SDL3/SDL.h>
namespace level_debugger namespace level_debugger
{ {
+27 -27
View File
@@ -1,7 +1,7 @@
#define MUSIC_DEFINITION #define MUSIC_DEFINITION
#include "Music.h" #include "Music.h"
#include <SDL.h> #include <SDL3/SDL.h>
#include <FAudio.h> #include <FAudio.h>
#include "Alloc.h" #include "Alloc.h"
@@ -45,7 +45,7 @@
#define assert SDL_assert #define assert SDL_assert
#define FILE SDL_RWops #define FILE SDL_IOStream
#ifdef SEEK_SET #ifdef SEEK_SET
#undef SEEK_SET #undef SEEK_SET
#endif #endif
@@ -58,16 +58,16 @@
#ifdef EOF #ifdef EOF
#undef EOF #undef EOF
#endif #endif
#define SEEK_SET 0 #define SEEK_SET SDL_IO_SEEK_SET
#define SEEK_CUR 1 #define SEEK_CUR SDL_IO_SEEK_CUR
#define SEEK_END 2 #define SEEK_END SDL_IO_SEEK_END
#define EOF -1 #define EOF -1
#define fopen(path, mode) SDL_RWFromFile(path, mode) #define fopen(path, mode) SDL_IOFromFile(path, mode)
#define fopen_s(io, path, mode) (!(*io = fopen(path, mode))) #define fopen_s(io, path, mode) (!(*io = fopen(path, mode)))
#define fclose(io) SDL_RWclose(io) #define fclose(io) SDL_CloseIO(io)
#define fread(dst, size, count, io) SDL_RWread(io, dst, size, count) #define fread(dst, size, count, io) SDL_ReadIO(io, dst, ((size) * (count)))
#define fseek(io, offset, whence) SDL_RWseek(io, offset, whence) #define fseek(io, offset, whence) SDL_SeekIO(io, offset, whence)
#define ftell(io) SDL_RWtell(io) #define ftell(io) SDL_TellIO(io)
#define FAudio_alloca(x) SDL_stack_alloc(uint8_t, x) #define FAudio_alloca(x) SDL_stack_alloc(uint8_t, x)
#define FAudio_dealloca(x) SDL_stack_free(x) #define FAudio_dealloca(x) SDL_stack_free(x)
@@ -125,9 +125,9 @@ public:
void LoadWAV(const char* fileName, unsigned char* mem, const size_t length) void LoadWAV(const char* fileName, unsigned char* mem, const size_t length)
{ {
SDL_AudioSpec spec; SDL_AudioSpec spec;
SDL_RWops *fileIn; SDL_IOStream *fileIn;
fileIn = SDL_RWFromConstMem(mem, length); fileIn = SDL_IOFromConstMem(mem, length);
if (SDL_LoadWAV_RW(fileIn, 1, &spec, &wav_buffer, &wav_length) == NULL) if (!SDL_LoadWAV_IO(fileIn, 1, &spec, &wav_buffer, &wav_length))
{ {
vlog_error("Unable to load WAV file %s", fileName); vlog_error("Unable to load WAV file %s", fileName);
goto end; goto end;
@@ -378,26 +378,26 @@ float SoundTrack::volume = 0.0f;
class MusicTrack class MusicTrack
{ {
public: public:
MusicTrack(SDL_RWops *rw, const char* _id, bool _loose_extra) MusicTrack(SDL_IOStream *rw, const char* _id, bool _loose_extra)
{ {
SDL_zerop(this); SDL_zerop(this);
id = SDL_strdup(_id); id = SDL_strdup(_id);
loose_extra = _loose_extra; loose_extra = _loose_extra;
if (rw->size(rw) <= 1) if (SDL_GetIOSize(rw) <= 1)
{ {
// Don't bother // Don't bother
vlog_debug("Skipping empty music track"); vlog_debug("Skipping empty music track");
goto end; goto end;
} }
read_buf = (Uint8*) SDL_malloc(rw->size(rw)); read_buf = (Uint8*) SDL_malloc(SDL_GetIOSize(rw));
SDL_RWread(rw, read_buf, rw->size(rw), 1); SDL_ReadIO(rw, read_buf, SDL_GetIOSize(rw));
int err; int err;
stb_vorbis_info vorbis_info; stb_vorbis_info vorbis_info;
stb_vorbis_comment vorbis_comment; stb_vorbis_comment vorbis_comment;
vorbis = stb_vorbis_open_memory(read_buf, rw->size(rw), &err, NULL); vorbis = stb_vorbis_open_memory(read_buf, SDL_GetIOSize(rw), &err, NULL);
if (vorbis == NULL) if (vorbis == NULL)
{ {
vlog_error("Unable to create Vorbis handle, error %d", err); vlog_error("Unable to create Vorbis handle, error %d", err);
@@ -426,7 +426,7 @@ public:
valid = true; valid = true;
end: end:
SDL_RWclose(rw); SDL_CloseIO(rw);
} }
void Dispose(void) void Dispose(void)
@@ -792,7 +792,7 @@ static void add_builtin_sound(const char* id)
soundTracks.push_back(SoundTrack(asset_filename, id, false)); soundTracks.push_back(SoundTrack(asset_filename, id, false));
} }
static void add_builtin_track(SDL_RWops* rw, const char* track_name) static void add_builtin_track(SDL_IOStream* rw, const char* track_name)
{ {
// Make an ID from the track name // Make an ID from the track name
char id[256]; char id[256];
@@ -896,7 +896,7 @@ void musicclass::init(void)
{ {
// If mmmmmm.vvv is invalid, or doesn't exist... // If mmmmmm.vvv is invalid, or doesn't exist...
SDL_RWops* rw; SDL_IOStream* rw;
if (pppppp_blob.unPackBinary("vvvvvvmusic.vvv")) if (pppppp_blob.unPackBinary("vvvvvvmusic.vvv"))
{ {
@@ -920,7 +920,7 @@ void musicclass::init(void)
index = blob.getIndex("data/" track_name); \ index = blob.getIndex("data/" track_name); \
if (index >= 0 && index < blob.max_headers) \ if (index >= 0 && index < blob.max_headers) \
{ \ { \
rw = SDL_RWFromConstMem(blob.getAddress(index), blob.getSize(index)); \ rw = SDL_IOFromConstMem(blob.getAddress(index), blob.getSize(index)); \
if (rw == NULL) \ if (rw == NULL) \
{ \ { \
vlog_error("Unable to read music file header: %s", SDL_GetError()); \ vlog_error("Unable to read music file header: %s", SDL_GetError()); \
@@ -968,7 +968,7 @@ void musicclass::init(void)
mmmmmm = true; mmmmmm = true;
int index; int index;
SDL_RWops* rw; SDL_IOStream* rw;
#define FOREACH_TRACK(blob, track_name) TRACK_LOAD_BLOB(blob, track_name) #define FOREACH_TRACK(blob, track_name) TRACK_LOAD_BLOB(blob, track_name)
@@ -979,7 +979,7 @@ void musicclass::init(void)
size_t index_ = 0; size_t index_ = 0;
while (mmmmmm_blob.nextExtra(&index_)) while (mmmmmm_blob.nextExtra(&index_))
{ {
rw = SDL_RWFromConstMem(mmmmmm_blob.getAddress(index_), mmmmmm_blob.getSize(index_)); rw = SDL_IOFromConstMem(mmmmmm_blob.getAddress(index_), mmmmmm_blob.getSize(index_));
add_builtin_track(rw, mmmmmm_blob.m_headers[index_].name); add_builtin_track(rw, mmmmmm_blob.m_headers[index_].name);
num_mmmmmm_tracks++; num_mmmmmm_tracks++;
@@ -997,11 +997,11 @@ void musicclass::init(void)
num_pppppp_tracks += musicTracks.size() - num_mmmmmm_tracks; num_pppppp_tracks += musicTracks.size() - num_mmmmmm_tracks;
SDL_RWops* rw; SDL_IOStream* rw;
size_t index_ = 0; size_t index_ = 0;
while (pppppp_blob.nextExtra(&index_)) while (pppppp_blob.nextExtra(&index_))
{ {
rw = SDL_RWFromConstMem(pppppp_blob.getAddress(index_), pppppp_blob.getSize(index_)); rw = SDL_IOFromConstMem(pppppp_blob.getAddress(index_), pppppp_blob.getSize(index_));
add_builtin_track(rw, pppppp_blob.m_headers[index_].name); add_builtin_track(rw, pppppp_blob.m_headers[index_].name);
num_pppppp_tracks++; num_pppppp_tracks++;
@@ -1035,7 +1035,7 @@ void musicclass::init(void)
} }
else else
{ {
rw = SDL_RWFromConstMem(mem, len); rw = SDL_IOFromConstMem(mem, len);
if (rw == NULL) if (rw == NULL)
{ {
vlog_error("Unable to read loose extra music file from memory: %s", SDL_GetError()); vlog_error("Unable to read loose extra music file from memory: %s", SDL_GetError());
+2 -2
View File
@@ -1,4 +1,4 @@
#include <SDL.h> #include <SDL3/SDL.h>
#include "ActionSets.h" #include "ActionSets.h"
#include "ButtonGlyphs.h" #include "ButtonGlyphs.h"
@@ -1873,7 +1873,7 @@ static void menurender(void)
{ {
if (game.currentmenuoption == 1) if (game.currentmenuoption == 1)
{ {
if (SDL_GetHintBoolean("SteamDeck", SDL_FALSE)) if (SDL_GetHintBoolean("SteamDeck", false))
{ {
font::print_wrap(PR_CEN, -1, 180, loc::gettext("The level editor is not currently supported on Steam Deck, as it requires a keyboard and mouse to use."), tr, tg, tb); font::print_wrap(PR_CEN, -1, 180, loc::gettext("The level editor is not currently supported on Steam Deck, as it requires a keyboard and mouse to use."), tr, tg, tb);
} }
+4 -4
View File
@@ -323,7 +323,7 @@ namespace roomname_translator
if (help_screen) if (help_screen)
{ {
if ((key.isDown(SDLK_LCTRL) || key.isDown(SDLK_RCTRL)) && key_pressed_once(SDLK_e, &held_e)) if ((key.isDown(SDLK_LCTRL) || key.isDown(SDLK_RCTRL)) && key_pressed_once(SDLK_E, &held_e))
{ {
expl_mode = !expl_mode; expl_mode = !expl_mode;
} }
@@ -386,7 +386,7 @@ namespace roomname_translator
edit_mode = !edit_mode; edit_mode = !edit_mode;
} }
if (key_pressed_once(SDLK_i, &held_i)) if (key_pressed_once(SDLK_I, &held_i))
{ {
if (game.intimetrial) if (game.intimetrial)
{ {
@@ -412,13 +412,13 @@ namespace roomname_translator
return true; return true;
} }
if ((key.isDown(SDLK_LCTRL) || key.isDown(SDLK_RCTRL)) && key_pressed_once(SDLK_e, &held_e)) if ((key.isDown(SDLK_LCTRL) || key.isDown(SDLK_RCTRL)) && key_pressed_once(SDLK_E, &held_e))
{ {
expl_mode = !expl_mode; expl_mode = !expl_mode;
return true; return true;
} }
if (key_pressed_once(SDLK_RETURN, &held_return) || key_pressed_once(SDLK_e, &held_e)) if (key_pressed_once(SDLK_RETURN, &held_return) || key_pressed_once(SDLK_E, &held_e))
{ {
if (map.roomname_special || map.roomname[0] == '\0') if (map.roomname_special || map.roomname[0] == '\0')
{ {
+1 -1
View File
@@ -1,7 +1,7 @@
#ifndef ROOMNAMETRANSLATOR_H #ifndef ROOMNAMETRANSLATOR_H
#define ROOMNAMETRANSLATOR_H #define ROOMNAMETRANSLATOR_H
#include <SDL.h> #include <SDL3/SDL.h>
namespace roomname_translator namespace roomname_translator
{ {
+4 -4
View File
@@ -3,9 +3,9 @@
*/ */
/* Include the SDL main definition header */ /* Include the SDL main definition header */
#include "SDL_main.h" #include <SDL3/SDL_main.h>
#if defined(__IPHONEOS__) || defined(__TVOS__) #if defined(SDL_PLATFORM_IOS) || defined(SDL_PLATFORM_TVOS)
#ifndef SDL_MAIN_HANDLED #ifndef SDL_MAIN_HANDLED
#ifdef main #ifdef main
@@ -14,10 +14,10 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
return SDL_UIKitRunApp(argc, argv, SDL_main); return SDL_RunApp(argc, argv, SDL_main, NULL);
} }
#endif /* !SDL_MAIN_HANDLED */ #endif /* !SDL_MAIN_HANDLED */
#endif /* __IPHONEOS__ || __TVOS__ */ #endif /* SDL_PLATFORM_IOS || SDL_PLATFORM_TVOS */
/* vi: set ts=4 sw=4 expandtab: */ /* vi: set ts=4 sw=4 expandtab: */
+30 -27
View File
@@ -1,7 +1,7 @@
#define GAMESCREEN_DEFINITION #define GAMESCREEN_DEFINITION
#include "Screen.h" #include "Screen.h"
#include <SDL.h> #include <SDL3/SDL.h>
#include "Alloc.h" #include "Alloc.h"
#include "Constants.h" #include "Constants.h"
@@ -12,7 +12,7 @@
#include "Game.h" #include "Game.h"
#include "Graphics.h" #include "Graphics.h"
#include "GraphicsUtil.h" #include "GraphicsUtil.h"
#ifndef __APPLE__ #ifndef SDL_PLATFORM_APPLE
#include "GraphicsResources.h" #include "GraphicsResources.h"
#endif #endif
#include "InterimVersion.h" #include "InterimVersion.h"
@@ -50,11 +50,9 @@ void Screen::init(const struct ScreenSettings* settings)
m_window = SDL_CreateWindow( m_window = SDL_CreateWindow(
"VVVVVV", "VVVVVV",
SDL_WINDOWPOS_CENTERED_DISPLAY(windowDisplay),
SDL_WINDOWPOS_CENTERED_DISPLAY(windowDisplay),
SCREEN_WIDTH_PIXELS * 2, SCREEN_WIDTH_PIXELS * 2,
SCREEN_HEIGHT_PIXELS * 2, SCREEN_HEIGHT_PIXELS * 2,
SDL_WINDOW_HIDDEN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI SDL_WINDOW_HIDDEN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIGH_PIXEL_DENSITY
); );
if (m_window == NULL) if (m_window == NULL)
@@ -63,7 +61,13 @@ void Screen::init(const struct ScreenSettings* settings)
VVV_exit(1); VVV_exit(1);
} }
m_renderer = SDL_CreateRenderer(m_window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE); SDL_SetWindowPosition(
m_window,
SDL_WINDOWPOS_CENTERED_DISPLAY(windowDisplay),
SDL_WINDOWPOS_CENTERED_DISPLAY(windowDisplay)
);
m_renderer = SDL_CreateRenderer(m_window, NULL);
if (m_renderer == NULL) if (m_renderer == NULL)
{ {
@@ -71,7 +75,9 @@ void Screen::init(const struct ScreenSettings* settings)
VVV_exit(1); VVV_exit(1);
} }
SDL_RenderSetVSync(m_renderer, (int) vsync); SDL_SetDefaultTextureScaleMode(m_renderer, SDL_SCALEMODE_NEAREST);
SDL_SetRenderVSync(m_renderer, (int) vsync);
#ifdef INTERIM_VERSION_EXISTS #ifdef INTERIM_VERSION_EXISTS
/* Branch name limits are ill-defined but on GitHub it's ~256 chars /* Branch name limits are ill-defined but on GitHub it's ~256 chars
@@ -100,7 +106,7 @@ void Screen::destroy(void)
void Screen::GetSettings(struct ScreenSettings* settings) void Screen::GetSettings(struct ScreenSettings* settings)
{ {
windowDisplay = SDL_GetWindowDisplayIndex(m_window); windowDisplay = SDL_GetDisplayForWindow(m_window);
if (windowDisplay < 0) if (windowDisplay < 0)
{ {
vlog_error("Error: could not get display index: %s", SDL_GetError()); vlog_error("Error: could not get display index: %s", SDL_GetError());
@@ -117,7 +123,7 @@ void Screen::GetSettings(struct ScreenSettings* settings)
settings->badSignal = badSignalEffect; settings->badSignal = badSignalEffect;
} }
#ifdef __APPLE__ #ifdef SDL_PLATFORM_APPLE
/* Apple doesn't like icons anymore... */ /* Apple doesn't like icons anymore... */
void Screen::LoadIcon(void) void Screen::LoadIcon(void)
{ {
@@ -132,13 +138,13 @@ void Screen::LoadIcon(void)
return; return;
} }
SDL_SetWindowIcon(m_window, icon); SDL_SetWindowIcon(m_window, icon);
VVV_freefunc(SDL_FreeSurface, icon); VVV_freefunc(SDL_DestroySurface, icon);
} }
#endif /* __APPLE__ */ #endif /* SDL_PLATFORM_APPLE */
void Screen::ResizeScreen(int x, int y) void Screen::ResizeScreen(int x, int y)
{ {
windowDisplay = SDL_GetWindowDisplayIndex(m_window); windowDisplay = SDL_GetDisplayForWindow(m_window);
if (windowDisplay < 0) if (windowDisplay < 0)
{ {
vlog_error("Error: could not get display index: %s", SDL_GetError()); vlog_error("Error: could not get display index: %s", SDL_GetError());
@@ -154,8 +160,7 @@ void Screen::ResizeScreen(int x, int y)
if (!isWindowed || isForcedFullscreen()) if (!isWindowed || isForcedFullscreen())
{ {
int result = SDL_SetWindowFullscreen(m_window, SDL_WINDOW_FULLSCREEN_DESKTOP); if (!SDL_SetWindowFullscreen(m_window, true))
if (result != 0)
{ {
vlog_error("Error: could not set the game to fullscreen mode: %s", SDL_GetError()); vlog_error("Error: could not set the game to fullscreen mode: %s", SDL_GetError());
return; return;
@@ -163,8 +168,7 @@ void Screen::ResizeScreen(int x, int y)
} }
else else
{ {
int result = SDL_SetWindowFullscreen(m_window, 0); if (!SDL_SetWindowFullscreen(m_window, false))
if (result != 0)
{ {
vlog_error("Error: could not set the game to windowed mode: %s", SDL_GetError()); vlog_error("Error: could not set the game to windowed mode: %s", SDL_GetError());
} }
@@ -182,15 +186,14 @@ void Screen::ResizeScreen(int x, int y)
static void constrain_to_desktop(int display_index, int* width, int* height) static void constrain_to_desktop(int display_index, int* width, int* height)
{ {
SDL_DisplayMode display_mode = {}; const SDL_DisplayMode *display_mode = SDL_GetDesktopDisplayMode(display_index);
int success = SDL_GetDesktopDisplayMode(display_index, &display_mode); if (display_mode == NULL)
if (success != 0)
{ {
vlog_error("Could not get desktop display mode: %s", SDL_GetError()); vlog_error("Could not get desktop display mode: %s", SDL_GetError());
return; return;
} }
while ((*width > display_mode.w || *height > display_mode.h) while ((*width > display_mode->w || *height > display_mode->h)
&& *width > SCREEN_WIDTH_PIXELS && *height > SCREEN_HEIGHT_PIXELS) && *width > SCREEN_WIDTH_PIXELS && *height > SCREEN_HEIGHT_PIXELS)
{ {
// We are too big, take away one multiple // We are too big, take away one multiple
@@ -257,7 +260,7 @@ void Screen::ResizeToNearestMultiple(void)
h = final_dimension; h = final_dimension;
} }
windowDisplay = SDL_GetWindowDisplayIndex(m_window); windowDisplay = SDL_GetDisplayForWindow(m_window);
if (windowDisplay < 0) if (windowDisplay < 0)
{ {
vlog_error("Could not get display index: %s", SDL_GetError()); vlog_error("Could not get display index: %s", SDL_GetError());
@@ -271,7 +274,7 @@ void Screen::ResizeToNearestMultiple(void)
void Screen::GetScreenSize(int* x, int* y) void Screen::GetScreenSize(int* x, int* y)
{ {
if (SDL_GetRendererOutputSize(m_renderer, x, y) != 0) if (!SDL_GetCurrentRenderOutputSize(m_renderer, x, y))
{ {
vlog_error("Could not get window size: %s", SDL_GetError()); vlog_error("Could not get window size: %s", SDL_GetError());
/* Initialize to safe defaults */ /* Initialize to safe defaults */
@@ -340,19 +343,19 @@ void Screen::toggleLinearFilter(void)
SDL_SetTextureScaleMode( SDL_SetTextureScaleMode(
graphics.gameTexture, graphics.gameTexture,
isFiltered ? SDL_ScaleModeLinear : SDL_ScaleModeNearest isFiltered ? SDL_SCALEMODE_LINEAR : SDL_SCALEMODE_NEAREST
); );
SDL_SetTextureScaleMode( SDL_SetTextureScaleMode(
graphics.tempShakeTexture, graphics.tempShakeTexture,
isFiltered ? SDL_ScaleModeLinear : SDL_ScaleModeNearest isFiltered ? SDL_SCALEMODE_LINEAR : SDL_SCALEMODE_NEAREST
); );
} }
void Screen::toggleVSync(void) void Screen::toggleVSync(void)
{ {
vsync = !vsync; vsync = !vsync;
SDL_RenderSetVSync(m_renderer, (int) vsync); SDL_SetRenderVSync(m_renderer, (int) vsync);
} }
void Screen::recacheTextures(void) void Screen::recacheTextures(void)
@@ -388,9 +391,9 @@ bool Screen::isForcedFullscreen(void)
* If you're working on a tenfoot-only build, add a def that always * If you're working on a tenfoot-only build, add a def that always
* returns true! * returns true!
*/ */
#if defined(__ANDROID__) || TARGET_OS_IPHONE #if defined(SDL_PLATFORM_ANDROID) || TARGET_OS_IPHONE
return true; return true;
#else #else
return SDL_GetHintBoolean("SteamTenfoot", SDL_FALSE); return SDL_GetHintBoolean("SteamTenfoot", false);
#endif #endif
} }
+1 -1
View File
@@ -1,7 +1,7 @@
#ifndef SCREEN_H #ifndef SCREEN_H
#define SCREEN_H #define SCREEN_H
#include <SDL.h> #include <SDL3/SDL.h>
#include "ScreenSettings.h" #include "ScreenSettings.h"
+2 -2
View File
@@ -2,7 +2,7 @@
#include "Script.h" #include "Script.h"
#include <limits.h> #include <limits.h>
#include <SDL_timer.h> #include <SDL3/SDL_timer.h>
#include "Alloc.h" #include "Alloc.h"
#include "Constants.h" #include "Constants.h"
@@ -3256,7 +3256,7 @@ void scriptclass::hardreset(void)
if (game.seed_use_sdl_getticks) if (game.seed_use_sdl_getticks)
{ {
/* The RNG is 32-bit. We don't _really_ need 64-bit... */ /* The RNG is 32-bit. We don't _really_ need 64-bit... */
xoshiro_seed((Uint32) SDL_GetTicks64()); xoshiro_seed((Uint32) SDL_GetTicks());
} }
else else
{ {
+1 -1
View File
@@ -2,7 +2,7 @@
#define SCRIPT_H #define SCRIPT_H
#include <map> #include <map>
#include <SDL.h> #include <SDL3/SDL.h>
#include <string> #include <string>
#include <vector> #include <vector>
+1 -1
View File
@@ -1,6 +1,6 @@
#include "Script.h" #include "Script.h"
#include <SDL.h> #include <SDL3/SDL.h>
bool scriptclass::load(const std::string& name) bool scriptclass::load(const std::string& name)
{ {
+7 -5
View File
@@ -3,7 +3,7 @@
#ifndef MAKEANDPLAY #ifndef MAKEANDPLAY
#include <stdint.h> #include <stdint.h>
#include <SDL.h> #include <SDL3/SDL.h>
#include "CWrappers.h" #include "CWrappers.h"
#include "Vlogging.h" #include "Vlogging.h"
@@ -18,9 +18,9 @@
#if defined(_WIN32) #if defined(_WIN32)
#define STEAM_LIBRARY "steam_api.dll" #define STEAM_LIBRARY "steam_api.dll"
#elif defined(__APPLE__) #elif defined(SDL_PLATFORM_APPLE)
#define STEAM_LIBRARY "libsteam_api.dylib" #define STEAM_LIBRARY "libsteam_api.dylib"
#elif defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__HAIKU__) || defined(__DragonFly__) #elif defined(SDL_PLATFORM_LINUX) || defined(SDL_PLATFORM_FREEBSD) || defined(SDL_PLATFORM_OPENBSD) || defined(SDL_PLATFORM_HAIKU) || defined(__DragonFly__)
#define STEAM_LIBRARY "libsteam_api.so" #define STEAM_LIBRARY "libsteam_api.so"
#else #else
#error STEAM_LIBRARY: Unrecognized platform! #error STEAM_LIBRARY: Unrecognized platform!
@@ -145,10 +145,12 @@ static void run_screenshot()
return; return;
} }
const SDL_PixelFormatDetails* details = SDL_GetPixelFormatDetails(surface2x->format);
SteamAPI_ISteamScreenshots_WriteScreenshot( SteamAPI_ISteamScreenshots_WriteScreenshot(
steamScreenshots, steamScreenshots,
surface2x->pixels, surface2x->pixels,
surface2x->w * surface2x->h * surface2x->format->BytesPerPixel, surface2x->w * surface2x->h * details->bytes_per_pixel,
surface2x->w, surface2x->w,
surface2x->h surface2x->h
); );
@@ -160,7 +162,7 @@ static int32_t steamPipe = 0;
int32_t STEAM_init(void) int32_t STEAM_init(void)
{ {
#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__HAIKU__) || defined(__DragonFly__) #if defined(SDL_PLATFORM_FREEBSD) || defined(SDL_PLATFORM_OPENBSD) || defined(SDL_PLATFORM_HAIKU) || defined(__DragonFly__)
return 0; return 0;
#endif #endif
struct ISteamClient *steamClient; struct ISteamClient *steamClient;
+1 -1
View File
@@ -1,6 +1,6 @@
#include "Script.h" #include "Script.h"
#include <SDL.h> #include <SDL3/SDL.h>
void scriptclass::loadother(const char* t) void scriptclass::loadother(const char* t)
{ {
+1 -1
View File
@@ -1,6 +1,6 @@
#include "Textbook.h" #include "Textbook.h"
#include <SDL.h> #include <SDL3/SDL.h>
#include "Alloc.h" #include "Alloc.h"
#include "Vlogging.h" #include "Vlogging.h"
+1 -1
View File
@@ -1,7 +1,7 @@
#ifndef TEXTBOOK_H #ifndef TEXTBOOK_H
#define TEXTBOOK_H #define TEXTBOOK_H
#include <SDL_stdinc.h> #include <SDL3/SDL_stdinc.h>
#include <stdbool.h> #include <stdbool.h>
#include <stddef.h> #include <stddef.h>
+1 -1
View File
@@ -1,6 +1,6 @@
#include "Textbox.h" #include "Textbox.h"
#include <SDL.h> #include <SDL3/SDL.h>
#include "Font.h" #include "Font.h"
#include "Localization.h" #include "Localization.h"
+1 -1
View File
@@ -1,4 +1,4 @@
#include <SDL_stdinc.h> #include <SDL3/SDL_stdinc.h>
#include "Alloc.h" #include "Alloc.h"
+1 -1
View File
@@ -1,6 +1,6 @@
#include "Tower.h" #include "Tower.h"
#include <SDL_stdinc.h> #include <SDL3/SDL_stdinc.h>
#include <stddef.h> #include <stddef.h>
#include "Constants.h" #include "Constants.h"
+1 -1
View File
@@ -1,7 +1,7 @@
#ifndef TOWERBG_H #ifndef TOWERBG_H
#define TOWERBG_H #define TOWERBG_H
#include <SDL.h> #include <SDL3/SDL.h>
struct TowerBG struct TowerBG
{ {
+2 -2
View File
@@ -1,13 +1,13 @@
#ifndef UNREACHABLE_H #ifndef UNREACHABLE_H
#define UNREACHABLE_H #define UNREACHABLE_H
#include <SDL_stdinc.h> #include <SDL3/SDL_stdinc.h>
SDL_NORETURN SDL_INLINE void VVV_unreachable(void) SDL_NORETURN SDL_INLINE void VVV_unreachable(void)
{ {
/* __builtin_unreachable() and __assume(0) execute undefined behavior. /* __builtin_unreachable() and __assume(0) execute undefined behavior.
* Otherwise, a noreturn function returning is also undefined behavior. */ * Otherwise, a noreturn function returning is also undefined behavior. */
#if _SDL_HAS_BUILTIN(__builtin_unreachable) #if SDL_HAS_BUILTIN(__builtin_unreachable)
__builtin_unreachable(); __builtin_unreachable();
#elif defined(_MSC_VER) #elif defined(_MSC_VER)
__assume(0); __assume(0);
+2 -2
View File
@@ -1,7 +1,7 @@
#define HELP_DEFINITION #define HELP_DEFINITION
#include "UtilityClass.h" #include "UtilityClass.h"
#include <SDL.h> #include <SDL3/SDL.h>
#include <sstream> #include <sstream>
#include "Constants.h" #include "Constants.h"
@@ -216,7 +216,7 @@ std::string UtilityClass::number_words(int _t, const char* number_class)
bool UtilityClass::intersects( SDL_Rect A, SDL_Rect B ) bool UtilityClass::intersects( SDL_Rect A, SDL_Rect B )
{ {
return (SDL_HasIntersection(&A, &B) == SDL_TRUE); return (SDL_HasRectIntersection(&A, &B) == true);
} }
void UtilityClass::updateglow(void) void UtilityClass::updateglow(void)
+1 -1
View File
@@ -1,7 +1,7 @@
#ifndef UTILITYCLASS_H #ifndef UTILITYCLASS_H
#define UTILITYCLASS_H #define UTILITYCLASS_H
#include <SDL.h> #include <SDL3/SDL.h>
#include <string> #include <string>
int ss_toi(const std::string& str); int ss_toi(const std::string& str);
+1 -1
View File
@@ -1,6 +1,6 @@
#include "VFormat.h" #include "VFormat.h"
#include <SDL.h> #include <SDL3/SDL.h>
#include <stdbool.h> #include <stdbool.h>
#include "Alloc.h" #include "Alloc.h"
+6 -6
View File
@@ -3,18 +3,18 @@
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#if defined(__ANDROID__) || TARGET_OS_IPHONE #if defined(SDL_PLATFORM_ANDROID) || TARGET_OS_IPHONE
// forward to SDL logging on Android, since stdout/stderr are /dev/null // forward to SDL logging on Android, since stdout/stderr are /dev/null
// they exist on iOS, but just get forwarded to the system log anyway, so might as well provide proper metadata // they exist on iOS, but just get forwarded to the system log anyway, so might as well provide proper metadata
#define VLOG_USE_SDL 1 #define VLOG_USE_SDL 1
#endif #endif
#ifdef VLOG_USE_SDL #ifdef VLOG_USE_SDL
# include <SDL_log.h> # include <SDL3/SDL_log.h>
#elif defined(_WIN32) #elif defined(_WIN32)
# define WIN32_LEAN_AND_MEAN # define WIN32_LEAN_AND_MEAN
# include <windows.h> # include <windows.h>
#elif defined(__unix__) || defined(__APPLE__) #elif defined(SDL_PLATFORM_UNI) || defined(SDL_PLATFORM_APPLE)
# include <unistd.h> # include <unistd.h>
#endif #endif
@@ -26,7 +26,7 @@
#define Color_BOLD_RED COLOR("\x1b[1;31m") #define Color_BOLD_RED COLOR("\x1b[1;31m")
#define Color_BOLD_GRAY COLOR("\x1b[1;90m") #define Color_BOLD_GRAY COLOR("\x1b[1;90m")
#ifdef __ANDROID__ #ifdef SDL_PLATFORM_ANDROID
const int color_supported = 0; const int color_supported = 0;
#else #else
static int color_supported = 0; static int color_supported = 0;
@@ -44,7 +44,7 @@ static void check_color_support(void);
void vlog_init(void) void vlog_init(void)
{ {
#ifdef VLOG_USE_SDL #ifdef VLOG_USE_SDL
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_VERBOSE); SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_VERBOSE);
#endif #endif
check_color_support(); check_color_support();
} }
@@ -285,7 +285,7 @@ static void check_color_support(void)
} }
color_supported = 1; color_supported = 1;
#elif (defined(__unix__) || defined(__APPLE__)) && !defined(VLOG_USE_SDL) #elif (defined(SDL_PLATFORM_UNI) || defined(SDL_PLATFORM_APPLE)) && !defined(VLOG_USE_SDL)
if (isatty(STDOUT_FILENO) && isatty(STDERR_FILENO)) if (isatty(STDOUT_FILENO) && isatty(STDERR_FILENO))
{ {
color_supported = 1; color_supported = 1;
+1 -1
View File
@@ -6,7 +6,7 @@ extern "C"
{ {
#endif #endif
#include <SDL_stdinc.h> #include <SDL3/SDL_stdinc.h>
void vlog_init(void); void vlog_init(void);
+1 -1
View File
@@ -1,4 +1,4 @@
#include <SDL.h> #include <SDL3/SDL.h>
#include <tinyxml2.h> #include <tinyxml2.h>
namespace xml namespace xml
+16 -19
View File
@@ -1,7 +1,9 @@
#include <SDL.h> #include <SDL3/SDL.h>
#ifdef __EMSCRIPTEN__ #ifdef SDL_PLATFORM_EMSCRIPTEN
#include <emscripten.h> #include <emscripten.h>
#include <emscripten/html5.h> #include <emscripten/html5.h>
#elif defined(SDL_PLATFORM_WINDOWS)
#include <SDL3/SDL_main.h>
#endif #endif
#include "ButtonGlyphs.h" #include "ButtonGlyphs.h"
@@ -67,7 +69,7 @@ static volatile Uint64 time_ = 0;
static volatile Uint64 timePrev = 0; static volatile Uint64 timePrev = 0;
static volatile Uint32 accumulator = 0; static volatile Uint32 accumulator = 0;
#ifndef __EMSCRIPTEN__ #ifndef SDL_PLATFORM_EMSCRIPTEN
static volatile Uint64 f_time = 0; static volatile Uint64 f_time = 0;
static volatile Uint64 f_timePrev = 0; static volatile Uint64 f_timePrev = 0;
#endif #endif
@@ -354,11 +356,11 @@ static void inline deltaloop(void);
static void cleanup(void); static void cleanup(void);
#ifdef __EMSCRIPTEN__ #ifdef SDL_PLATFORM_EMSCRIPTEN
static void emscriptenloop(void) static void emscriptenloop(void)
{ {
timePrev = time_; timePrev = time_;
time_ = SDL_GetTicks64(); time_ = SDL_GetTicks();
deltaloop(); deltaloop();
} }
#endif #endif
@@ -598,12 +600,7 @@ int main(int argc, char *argv[])
VVV_exit(0); VVV_exit(0);
} }
SDL_SetHintWithPriority(SDL_HINT_IME_SHOW_UI, "1", SDL_HINT_OVERRIDE); SDL_SetHintWithPriority(SDL_HINT_IME_IMPLEMENTED_UI, "1", SDL_HINT_OVERRIDE);
SDL_SetHintWithPriority(SDL_HINT_IME_SUPPORT_EXTENDED_TEXT, "1", SDL_HINT_OVERRIDE);
/* We already do the button swapping in ButtonGlyphs, disable SDL's swapping */
SDL_SetHintWithPriority(SDL_HINT_GAMECONTROLLER_USE_BUTTON_LABELS, "0", SDL_HINT_OVERRIDE);
SDL_SetHintWithPriority(SDL_HINT_ORIENTATIONS, "LandscapeLeft LandscapeRight", SDL_HINT_OVERRIDE); SDL_SetHintWithPriority(SDL_HINT_ORIENTATIONS, "LandscapeLeft LandscapeRight", SDL_HINT_OVERRIDE);
if(!FILESYSTEM_init(argv[0], baseDir, assetsPath, langDir, fontsDir)) if(!FILESYSTEM_init(argv[0], baseDir, assetsPath, langDir, fontsDir))
@@ -617,11 +614,11 @@ int main(int argc, char *argv[])
SDL_INIT_VIDEO | SDL_INIT_VIDEO |
SDL_INIT_AUDIO | SDL_INIT_AUDIO |
SDL_INIT_JOYSTICK | SDL_INIT_JOYSTICK |
SDL_INIT_GAMECONTROLLER SDL_INIT_GAMEPAD
); );
if (SDL_IsTextInputActive() == SDL_TRUE) if (SDL_TextInputActive(gameScreen.m_window) == true)
{ {
SDL_StopTextInput(); SDL_StopTextInput(gameScreen.m_window);
} }
NETWORK_init(); NETWORK_init();
@@ -861,12 +858,12 @@ int main(int argc, char *argv[])
gamestate_funcs = get_gamestate_funcs(game.gamestate, &num_gamestate_funcs); gamestate_funcs = get_gamestate_funcs(game.gamestate, &num_gamestate_funcs);
loop_assign_active_funcs(); loop_assign_active_funcs();
#ifdef __EMSCRIPTEN__ #ifdef SDL_PLATFORM_EMSCRIPTEN
emscripten_set_main_loop(emscriptenloop, 0, 0); emscripten_set_main_loop(emscriptenloop, 0, 0);
#else #else
while (true) while (true)
{ {
f_time = SDL_GetTicks64(); f_time = SDL_GetTicks();
const Uint64 f_timetaken = f_time - f_timePrev; const Uint64 f_timetaken = f_time - f_timePrev;
const int timestep = game.get_timestep(); const int timestep = game.get_timestep();
@@ -874,13 +871,13 @@ int main(int argc, char *argv[])
{ {
const volatile Uint64 f_delay = timestep - f_timetaken; const volatile Uint64 f_delay = timestep - f_timetaken;
SDL_Delay((Uint32) f_delay); SDL_Delay((Uint32) f_delay);
f_time = SDL_GetTicks64(); f_time = SDL_GetTicks();
} }
f_timePrev = f_time; f_timePrev = f_time;
timePrev = time_; timePrev = time_;
time_ = SDL_GetTicks64(); time_ = SDL_GetTicks();
deltaloop(); deltaloop();
} }
@@ -1010,7 +1007,7 @@ static void unfocused_run(void)
} }
graphics.render(); graphics.render();
//We are minimised, so lets put a bit of a delay to save CPU //We are minimised, so lets put a bit of a delay to save CPU
#ifndef __EMSCRIPTEN__ #ifndef SDL_PLATFORM_EMSCRIPTEN
SDL_Delay(100); SDL_Delay(100);
#endif #endif
} }