Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wii: Add SDL2 support #3332

Merged
merged 3 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 81 additions & 54 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,10 @@ elseif(NINTENDO_SWITCH)
elseif(VITA)
set(PLAYER_TARGET_PLATFORM "psvita" CACHE STRING "Platform to compile for.")
elseif(NINTENDO_WII)
set(PLAYER_TARGET_PLATFORM "wii" CACHE STRING "Platform to compile for.")
set(PLAYER_TARGET_PLATFORM "SDL2" CACHE STRING "Platform to compile for. Options: SDL2 SDL1")
set(PLAYER_AUDIO_BACKEND "AESND" CACHE STRING "Audio system to use. Options: SDL2 SDL1 AESND OFF")
set_property(CACHE PLAYER_TARGET_PLATFORM PROPERTY STRINGS SDL2 SDL1)
set_property(CACHE PLAYER_AUDIO_BACKEND PROPERTY STRINGS SDL2 SDL1 AESND)
elseif(NINTENDO_WIIU)
set(PLAYER_TARGET_PLATFORM "SDL2" CACHE STRING "Platform to compile for.")
elseif(AMIGA)
Expand All @@ -578,8 +581,6 @@ endif()

if(${PLAYER_TARGET_PLATFORM} STREQUAL "SDL2")
target_sources(${PROJECT_NAME} PRIVATE
src/platform/sdl/sdl_audio.cpp
src/platform/sdl/sdl_audio.h
src/platform/sdl/sdl2_ui.cpp
src/platform/sdl/sdl2_ui.h)
target_compile_definitions(${PROJECT_NAME} PUBLIC USE_SDL=2)
Expand All @@ -597,9 +598,12 @@ if(${PLAYER_TARGET_PLATFORM} STREQUAL "SDL2")

if(ANDROID)
set(PLAYER_BUILD_EXECUTABLE OFF)
endif()

if(NINTENDO_WIIU)
elseif(NINTENDO_WII)
target_compile_definitions(${PROJECT_NAME} PUBLIC PLAYER_NINTENDO)
target_sources(${PROJECT_NAME} PRIVATE
src/platform/wii/clock.h
src/platform/wii/input_buttons.cpp)
elseif(NINTENDO_WIIU)
target_compile_definitions(${PROJECT_NAME} PUBLIC PLAYER_NINTENDO)
target_sources(${PROJECT_NAME} PRIVATE
src/platform/wiiu/main.h
Expand All @@ -610,15 +614,25 @@ if(${PLAYER_TARGET_PLATFORM} STREQUAL "SDL2")
target_link_libraries(${PROJECT_NAME} "Dwmapi")
endif()
elseif(${PLAYER_TARGET_PLATFORM} STREQUAL "SDL1")
if(NINTENDO_WII)
find_package(SDL REQUIRED)
target_compile_definitions(${PROJECT_NAME} PUBLIC PLAYER_NINTENDO)
target_include_directories(${PROJECT_NAME} PUBLIC ${SDL_INCLUDE_DIR})
target_sources(${PROJECT_NAME} PRIVATE
src/platform/wii/clock.h
src/platform/wii/input_buttons.cpp)
else()
player_find_package(NAME SDL1 TARGET SDL::SDLmain REQUIRED)
endif()

target_sources(${PROJECT_NAME} PRIVATE
src/platform/sdl/sdl_audio.cpp
src/platform/sdl/sdl_audio.h
src/platform/sdl/axis.h
src/platform/sdl/sdl_ui.cpp
src/platform/sdl/sdl_ui.h)
target_compile_definitions(${PROJECT_NAME} PUBLIC USE_SDL=1)

player_find_package(NAME SDL1 TARGET SDL::SDLmain REQUIRED)
target_compile_definitions(${PROJECT_NAME} PUBLIC
USE_SDL=1
EASYRPG_CONFIG_NAME="config_sdl1.ini"
)
elseif(${PLAYER_TARGET_PLATFORM} STREQUAL "libretro")
target_compile_definitions(${PROJECT_NAME} PUBLIC PLAYER_UI=LibretroUi USE_LIBRETRO=1)
set(PLAYER_BUILD_EXECUTABLE OFF)
Expand Down Expand Up @@ -682,31 +696,63 @@ elseif(${PLAYER_TARGET_PLATFORM} STREQUAL "switch")
src/platform/switch/ui.cpp
src/platform/switch/ui.h)
target_link_libraries(${PROJECT_NAME} switch-assets)
elseif(${PLAYER_TARGET_PLATFORM} STREQUAL "wii")
find_package(SDL REQUIRED)
target_compile_definitions(${PROJECT_NAME} PUBLIC USE_SDL=1 PLAYER_NINTENDO)
target_include_directories(${PROJECT_NAME} PUBLIC ${SDL_INCLUDE_DIR})
else()
message(FATAL_ERROR "Invalid target platform")
endif()

# Sound system to use
if(PLAYER_AUDIO_BACKEND)
# already set earlier in the platform config
elseif(${PLAYER_TARGET_PLATFORM} STREQUAL "SDL2")
set(PLAYER_AUDIO_BACKEND "SDL2" CACHE STRING "Audio system to use. Options: SDL2 OFF")
set_property(CACHE PLAYER_AUDIO_BACKEND PROPERTY STRINGS SDL2 OFF)

if(${PLAYER_AUDIO_BACKEND} STREQUAL "SDL2_mixer")
message(FATAL_ERROR "SDL2_mixer is not supported anymore. Use SDL2 instead.")
endif()
elseif(${PLAYER_TARGET_PLATFORM} STREQUAL "SDL1")
set(PLAYER_AUDIO_BACKEND "SDL1" CACHE STRING "Audio system to use. Options: SDL1 OFF")
set_property(CACHE PLAYER_AUDIO_BACKEND PROPERTY STRINGS SDL1 OFF)
else()
# Assuming that all platforms not targeting SDL have only one audio backend
set(PLAYER_AUDIO_BACKEND ${PLAYER_TARGET_PLATFORM} CACHE STRING "Audio system to use. Options: ${PLAYER_TARGET_PLATFORM} OFF")
set_property(CACHE PLAYER_AUDIO_BACKEND PROPERTY STRINGS ${PLAYER_TARGET_PLATFORM} OFF)
endif()

set(PLAYER_HAS_AUDIO ON)
if(${PLAYER_AUDIO_BACKEND} STREQUAL "SDL1")
target_sources(${PROJECT_NAME} PRIVATE
src/platform/sdl/sdl_audio.cpp
src/platform/sdl/sdl_audio.h)
elseif(${PLAYER_AUDIO_BACKEND} STREQUAL "SDL2")
target_sources(${PROJECT_NAME} PRIVATE
src/platform/sdl/sdl_audio.cpp
src/platform/sdl/sdl_audio.h)
elseif(${PLAYER_AUDIO_BACKEND} STREQUAL "AESND")
target_sources(${PROJECT_NAME} PRIVATE
src/platform/wii/audio.cpp
src/platform/wii/audio.h
src/platform/wii/clock.h
src/platform/wii/input_buttons.cpp
src/platform/sdl/axis.h
src/platform/sdl/sdl_ui.cpp
src/platform/sdl/sdl_ui.h)
src/platform/wii/audio.h)
target_compile_definitions(${PROJECT_NAME} PUBLIC AUDIO_AESND=1)
elseif(${PLAYER_AUDIO_BACKEND} STREQUAL ${PLAYER_TARGET_PLATFORM})

elseif(${PLAYER_AUDIO_BACKED} STREQUAL "OFF")
set(PLAYER_HAS_AUDIO OFF)
else()
message(FATAL_ERROR "Invalid target platform")
message(FATAL_ERROR "Invalid Audio Backend ${PLAYER_AUDIO_BACKEND}")
endif()

# Shared by homebrew platforms
if(${PLAYER_TARGET_PLATFORM} MATCHES "^(3ds|psvita|switch|wii)$" OR NINTENDO_WIIU)
if(NINTENDO_3DS OR NINTENDO_WII OR NINTENDO_WIIU OR NINTENDO_WIIU OR NINTENDO_SWITCH OR VITA)
target_compile_options(${PROJECT_NAME} PUBLIC -fno-exceptions -fno-rtti)
set(CMAKE_DL_LIBS "") # hack4icu!
set(PLAYER_ENABLE_TESTS OFF)
option(PLAYER_VERSIONED_PACKAGES "Create zip packages with versioned name (for internal use)" ON)
set(PLAYER_CONSOLE_PORT ON)
else()
set(PLAYER_CONSOLE_PORT OFF)
endif()
# Make content available (romfs/wuhb bundle)
if(${PLAYER_TARGET_PLATFORM} MATCHES "^(3ds|switch)$" OR NINTENDO_WIIU)
if(NINTENDO_3DS OR NINTENDO_WIIU OR NINTENDO_SWITCH)
option(PLAYER_BUNDLE "Embed a directory in the executable" OFF)
set(PLAYER_BUNDLE_PATH "content" CACHE PATH "Directory to include in executable")
set(BUNDLE_ARG "_IGNORE_ME")
Expand Down Expand Up @@ -851,8 +897,7 @@ target_link_libraries(${PROJECT_NAME} PIXMAN::PIXMAN)

# Always enable Wine registry support on non-Windows, but not for console ports
if(NOT CMAKE_SYSTEM_NAME STREQUAL "Windows"
AND NOT ${PLAYER_TARGET_PLATFORM} MATCHES "^(psvita|3ds|switch|wii)$"
AND NOT NINTENDO_WIIU)
AND NOT PLAYER_CONSOLE)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PLAYER_CONSOLE vs. PLAYER_CONSOLE_PORT.

target_compile_definitions(${PROJECT_NAME} PUBLIC HAVE_WINE=1)
endif()

Expand Down Expand Up @@ -903,26 +948,8 @@ else()
)
endif()

# Sound system to use
if(${PLAYER_TARGET_PLATFORM} STREQUAL "SDL2")
set(PLAYER_AUDIO_BACKEND "SDL2" CACHE STRING "Audio system to use. Options: SDL2 OFF")
set_property(CACHE PLAYER_AUDIO_BACKEND PROPERTY STRINGS SDL2 OFF)

if(${PLAYER_AUDIO_BACKEND} STREQUAL "SDL2_mixer")
message(FATAL_ERROR "SDL2_mixer is not supported anymore. Use SDL2 instead.")
endif()
elseif(${PLAYER_TARGET_PLATFORM} STREQUAL "SDL1")
set(PLAYER_AUDIO_BACKEND "SDL1" CACHE STRING "Audio system to use. Options: SDL1 OFF")
set_property(CACHE PLAYER_AUDIO_BACKEND PROPERTY STRINGS SDL1 OFF)
else()
# Assuming that all platforms not targeting SDL have only one audio backend
set(PLAYER_AUDIO_BACKEND "Default" CACHE STRING "Audio system to use. Options: Default OFF")
set_property(CACHE PLAYER_AUDIO_BACKEND PROPERTY STRINGS Default OFF)
endif()

# Configure Audio backends
if(${PLAYER_AUDIO_BACKEND} MATCHES "^(SDL[12]|Default)$")
set(PLAYER_HAS_AUDIO ON)
if(PLAYER_HAS_AUDIO)
target_compile_definitions(${PROJECT_NAME} PUBLIC SUPPORT_AUDIO=1)

if(${PLAYER_TARGET_PLATFORM} STREQUAL "libretro")
Expand Down Expand Up @@ -964,10 +991,6 @@ if(${PLAYER_AUDIO_BACKEND} MATCHES "^(SDL[12]|Default)$")
if(PLAYER_ENABLE_FMMIDI)
target_compile_definitions(${PROJECT_NAME} PUBLIC WANT_FMMIDI=1)
endif()
elseif(NOT PLAYER_AUDIO_BACKEND)
set(PLAYER_HAS_AUDIO OFF)
else()
message(FATAL_ERROR "Invalid Audio Backend ${PLAYER_AUDIO_BACKEND}")
endif()

CMAKE_DEPENDENT_OPTION(PLAYER_WITH_MPG123 "Play MP3 audio with libmpg123" ON "PLAYER_HAS_AUDIO" OFF)
Expand All @@ -980,7 +1003,7 @@ CMAKE_DEPENDENT_OPTION(PLAYER_WITH_FLUIDLITE "Play MIDI audio with fluidlite" ON
CMAKE_DEPENDENT_OPTION(PLAYER_WITH_XMP "Play MOD audio with libxmp" ON "PLAYER_HAS_AUDIO" OFF)
CMAKE_DEPENDENT_OPTION(PLAYER_ENABLE_DRWAV "Play WAV audio with dr_wav (built-in). Unsupported files are played by libsndfile." ON "PLAYER_HAS_AUDIO" OFF)

if(${PLAYER_AUDIO_BACKEND} MATCHES "^(SDL[12]|Default)$")
if(PLAYER_HAS_AUDIO)
set(PLAYER_AUDIO_RESAMPLER "Auto" CACHE STRING "Audio resampler to use. Options: Auto speexdsp samplerate OFF")
set_property(CACHE PLAYER_AUDIO_RESAMPLER PROPERTY STRINGS Auto speexdsp samplerate OFF)

Expand Down Expand Up @@ -1096,7 +1119,7 @@ if(${PLAYER_AUDIO_BACKEND} MATCHES "^(SDL[12]|Default)$")
endif()

# Executable
if(${PLAYER_BUILD_EXECUTABLE} AND ${PLAYER_TARGET_PLATFORM} MATCHES "^SDL[12]$" AND NOT NINTENDO_WIIU)
if(${PLAYER_BUILD_EXECUTABLE} AND ${PLAYER_TARGET_PLATFORM} MATCHES "^SDL.*$" AND NOT PLAYER_CONSOLE_PORT)
if(APPLE)
set(EXE_NAME "EasyRPG-Player.app")
set_source_files_properties(${${PROJECT_NAME}_BUNDLE_ICON} PROPERTIES MACOSX_PACKAGE_LOCATION "Resources")
Expand Down Expand Up @@ -1198,7 +1221,7 @@ if(${PLAYER_BUILD_EXECUTABLE} AND ${PLAYER_TARGET_PLATFORM} MATCHES "^SDL[12]$"
endif()
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PLAYER_JS_OUTPUT_NAME}.wasm DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
elseif(${PLAYER_TARGET_PLATFORM} MATCHES "^(psvita|3ds|switch|wii)$" OR NINTENDO_WIIU)
elseif(PLAYER_CONSOLE_PORT)
set(CPACK_PLATFORM "${PLAYER_TARGET_PLATFORM}")
if(NINTENDO_3DS)
add_executable(easyrpg-player src/platform/3ds/main.cpp)
Expand Down Expand Up @@ -1240,6 +1263,10 @@ elseif(${PLAYER_TARGET_PLATFORM} MATCHES "^(psvita|3ds|switch|wii)$" OR NINTENDO
-laesnd
-lfat
-lwiikeyboard)
if(TARGET SDL2::SDL2main)
# Missing dependency?
target_link_libraries(SDL2::SDL2main INTERFACE -lfat)
endif()
ogc_create_dol(easyrpg-player)
string(TIMESTAMP WII_DATE "%Y%m%d000000")
configure_file(resources/wii/meta.xml.in resources/wii/meta.xml @ONLY)
Expand Down Expand Up @@ -1299,7 +1326,7 @@ elseif(${PLAYER_TARGET_PLATFORM} MATCHES "^(psvita|3ds|switch|wii)$" OR NINTENDO
endif()
install(TARGETS easyrpg-player RUNTIME DESTINATION . COMPONENT debug)
# debug information
if(${PLAYER_TARGET_PLATFORM} MATCHES "^(3ds|switch|wii)$" OR NINTENDO_WIIU)
if(NINTENDO_3DS OR NINTENDO_WII OR NINTENDO_WIIU OR NINTENDO_SWITCH)
dkp_target_generate_symbol_list(easyrpg-player)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/easyrpg-player.map
${CMAKE_CURRENT_BINARY_DIR}/easyrpg-player.lst
Expand Down Expand Up @@ -1506,7 +1533,7 @@ if(PLAYER_BUILD_LIBLCF)
endif()

message(STATUS "Audio backend: ${PLAYER_AUDIO_BACKEND}")
if(${PLAYER_AUDIO_BACKEND} MATCHES "^(SDL[12]|Default)$")
if(PLAYER_HAS_AUDIO)
message(STATUS "")

set(WAV_LIBS)
Expand Down
9 changes: 8 additions & 1 deletion src/decoder_oggvorbis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,14 @@ int OggVorbisDecoder::FillBuffer(uint8_t* buffer, int length) {
#ifdef HAVE_TREMOR
read = ov_read(ovf, reinterpret_cast<char*>(buffer + length - to_read), to_read, &section);
#else
read = ov_read(ovf, reinterpret_cast<char*>(buffer + length - to_read), to_read, 0/*LE*/, 2/*16bit*/, 1/*signed*/, &section);
# if defined(__WIIU__)
// FIXME: This is the endianess of the audio and not of the host but the byteswapping in ov_read does
// not sound like it works
int byte_order = 1; // BE
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had this kind of problems when porting as well. Somehow the endianess is broken in the toolchain or the build scripts.

# else
int byte_order = 0; // LE
#endif
read = ov_read(ovf, reinterpret_cast<char*>(buffer + length - to_read), to_read, byte_order, 2/*16bit*/, 1/*signed*/, &section);
#endif
// stop decoding when error or end of file
if (read <= 0)
Expand Down
8 changes: 6 additions & 2 deletions src/game_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ namespace {
std::string config_path;
std::string soundfont_path;
std::string font_path;
StringView config_name = "config.ini";
#if USE_SDL == 1
// For SDL1 hardcode a different config file because it uses a completely different mapping for gamepads
StringView config_name = "config_sdl1.ini";
#else
StringView config_name = EASYRPG_CONFIG_NAME;
#endif
}

void Game_ConfigPlayer::Hide() {
Expand Down Expand Up @@ -93,7 +98,6 @@ Game_Config Game_Config::Create(CmdlineParser& cp) {
cfg.input.gamepad_swap_ab_and_xy.Set(true);
#endif


cp.Rewind();

config_path = GetConfigPath(cp);
Expand Down
6 changes: 6 additions & 0 deletions src/game_interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4041,6 +4041,12 @@ bool Game_Interpreter::CommandToggleFullscreen(lcf::rpg::EventCommand const& /*
return true;
}

auto cfg = DisplayUi->GetConfig();
if (!cfg.fullscreen.IsOptionVisible() || cfg.fullscreen.IsLocked()) {
Output::Debug("ToggleFullscreen: Not supported on this platform");
return true;
}

DisplayUi->ToggleFullscreen();
return true;
}
Expand Down
4 changes: 4 additions & 0 deletions src/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@
#define INI_NAME "RPG_RT.ini"
#define EASYRPG_INI_NAME "EasyRPG.ini"

#ifndef EASYRPG_CONFIG_NAME
# define EASYRPG_CONFIG_NAME "config.ini"
#endif

/** Prefix for .ldb and .lmt files; used when guessing non-standard extensions. */
#define RPG_RT_PREFIX "RPG_RT"
#define EASY_RT_PREFIX "EASY_RT"
Expand Down
17 changes: 13 additions & 4 deletions src/platform/sdl/sdl2_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@
#endif

#ifdef SUPPORT_AUDIO
# include "sdl_audio.h"
# if AUDIO_AESND
# include "platform/wii/audio.h"
# else
# include "sdl_audio.h"
# endif

AudioInterface& Sdl2Ui::GetAudio() {
return *audio_;
Expand Down Expand Up @@ -198,10 +202,11 @@ Sdl2Ui::Sdl2Ui(long width, long height, const Game_Config& cfg) : BaseUi(cfg)
#endif

#ifdef SUPPORT_AUDIO
if (!Player::no_audio_flag) {
# ifdef AUDIO_AESND
audio_ = std::make_unique<WiiAudio>(cfg.audio);
# else
audio_ = std::make_unique<SdlAudio>(cfg.audio);
return;
}
# endif
#endif
}

Expand Down Expand Up @@ -1263,6 +1268,8 @@ int FilterUntilFocus(const SDL_Event* evnt) {
void Sdl2Ui::vGetConfig(Game_ConfigVideo& cfg) const {
#ifdef EMSCRIPTEN
cfg.renderer.Lock("SDL2 (Software, Emscripten)");
#elif defined(__wii__)
cfg.renderer.Lock("SDL2 (Software, Wii)");
#elif defined(__WIIU__)
cfg.renderer.Lock("SDL2 (Software, Wii U)");
#else
Expand Down Expand Up @@ -1296,6 +1303,8 @@ void Sdl2Ui::vGetConfig(Game_ConfigVideo& cfg) const {
cfg.vsync.SetOptionVisible(false);
cfg.pause_when_focus_lost.Lock(false);
cfg.pause_when_focus_lost.SetOptionVisible(false);
#elif defined(__wii__)
cfg.fullscreen.SetOptionVisible(false);
#elif defined(__WIIU__)
// Only makes the screen flicker
cfg.fullscreen.SetOptionVisible(false);
Expand Down
4 changes: 2 additions & 2 deletions src/platform/sdl/sdl_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "bitmap.h"

#ifdef SUPPORT_AUDIO
# ifdef __wii__
# if AUDIO_AESND
# include "platform/wii/audio.h"
# else
# include "sdl_audio.h"
Expand Down Expand Up @@ -167,7 +167,7 @@ SdlUi::SdlUi(long width, long height, const Game_Config& cfg) : BaseUi(cfg)

#ifdef SUPPORT_AUDIO
if (!Player::no_audio_flag) {
# ifdef __wii__
# ifdef AUDIO_AESND
audio_ = std::make_unique<WiiAudio>(cfg.audio);
# else
audio_ = std::make_unique<SdlAudio>(cfg.audio);
Expand Down
6 changes: 4 additions & 2 deletions src/platform/wii/audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,18 @@ static void VoiceStreamCallback(AESNDPB *pb, u32 state) {

static void *AudioThread (void *) {
while (!stopaudio) {
instance->LockMutex();

// clear old data
memset(buffer[cur_buf], 0, SNDBUFFERSIZE);

instance->LockMutex();
instance->Decode(buffer[cur_buf], SNDBUFFERSIZE);
instance->UnlockMutex();

// make sure data is in main memory
DCFlushRange(buffer[cur_buf], SNDBUFFERSIZE);

instance->UnlockMutex();

LWP_ThreadSleep(audioqueue);
}
return nullptr;
Expand Down
Loading
Loading