SDL3 update

Rename most functions to their SDL3 equivelants first

Signed-off-by: Zach Bacon <zachbacon@vba-m.com>
This commit is contained in:
Zach Bacon 2024-03-23 16:09:33 -04:00
parent 68adb14b07
commit bf30d0aa98
8 changed files with 111 additions and 119 deletions

View File

@ -15,7 +15,7 @@ if(TAG_RELEASE)
include(MakeReleaseCommitAndTag)
endif()
set(VCPKG_DEPS pkgconf zlib pthreads "sdl2[samplerate]" gettext wxwidgets)
set(VCPKG_DEPS pkgconf zlib pthreads "sdl3[samplerate]" gettext wxwidgets)
set(VCPKG_DEPS_OPTIONAL
sfml ENABLE_LINK
@ -194,10 +194,10 @@ if(CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
endif()
find_package(OpenGL REQUIRED)
find_package(SDL2 REQUIRED)
find_package(SDL3 REQUIRED CONFIG REQUIRED COMPONENTS SDL3)
# Add libsamplerate to SDL2 with vcpkg
unset(SDL2_LIBRARY_TEMP)
#unset(SDL2_LIBRARY_TEMP)
if(CMAKE_TOOLCHAIN_FILE MATCHES "vcpkg")
if(WIN32)
unset(arch_suffix)
@ -210,13 +210,13 @@ if(CMAKE_TOOLCHAIN_FILE MATCHES "vcpkg")
endif()
set(installed_prefix ${_VCPKG_INSTALLED_DIR}/${WINARCH}-windows${arch_suffix}/${path_prefix})
SET(SDL2_LIBRARY_TEMP ${SDL2_LIBRARY_TEMP} ${installed_prefix}/lib/samplerate.lib)
else()
SET(SDL2_LIBRARY_TEMP ${SDL2_LIBRARY_TEMP} -lsamplerate)
#SET(SDL2_LIBRARY_TEMP ${SDL2_LIBRARY_TEMP} ${installed_prefix}/lib/samplerate.lib)
#else()
#SET(SDL2_LIBRARY_TEMP ${SDL2_LIBRARY_TEMP} -lsamplerate)
endif()
endif()
set(VBAM_SDL2_LIBS SDL2::SDL2 ${SDL2_LIBRARY_TEMP})
set(VBAM_SDL3_LIBS SDL3::SDL3)
set(VBAM_GENERATED_DIR ${CMAKE_BINARY_DIR}/generated)

View File

@ -6,9 +6,9 @@ target_sources(vbam-components-audio-sdl
)
target_include_directories(vbam-components-audio-sdl
PUBLIC ${SDL2_INCLUDE_DIRS}
PUBLIC ${SDL3_INCLUDE_DIRS}
)
target_link_libraries(vbam-components-audio-sdl
PUBLIC vbam-core-base ${VBAM_SDL2_LIBS}
PUBLIC vbam-core-base ${VBAM_SDL3_LIBS}
)

View File

@ -37,10 +37,6 @@ SoundSDL::SoundSDL():
initialized(false)
{}
void SoundSDL::soundCallback(void* data, uint8_t* stream, int len) {
reinterpret_cast<SoundSDL*>(data)->read(reinterpret_cast<uint16_t*>(stream), len);
}
bool SoundSDL::should_wait() {
return emulating && !coreOptions.speedup && current_rate && !gba_joybus_active;
}
@ -65,7 +61,7 @@ void SoundSDL::read(uint16_t* stream, int length) {
if (!buffer_size()) {
if (should_wait())
SDL_SemWait(data_available);
SDL_WaitSemaphore(data_available);
else
return;
}
@ -76,7 +72,7 @@ void SoundSDL::read(uint16_t* stream, int length) {
SDL_UnlockMutex(mutex);
SDL_SemPost(data_read);
SDL_PostSemaphore(data_read);
}
void SoundSDL::write(uint16_t * finalWave, int length) {
@ -85,8 +81,7 @@ void SoundSDL::write(uint16_t * finalWave, int length) {
SDL_LockMutex(mutex);
if (SDL_GetAudioDeviceStatus(sound_device) != SDL_AUDIO_PLAYING)
SDL_PauseAudioDevice(sound_device, 0);
SDL_PauseAudioDevice(sound_device);
std::size_t samples = length / 4;
std::size_t avail;
@ -99,10 +94,10 @@ void SoundSDL::write(uint16_t * finalWave, int length) {
SDL_UnlockMutex(mutex);
SDL_SemPost(data_available);
SDL_PostSemaphore(data_available);
if (should_wait())
SDL_SemWait(data_read);
SDL_WaitSemaphore(data_read);
else
// Drop the remainder of the audio data
return;
@ -124,21 +119,18 @@ bool SoundSDL::init(long sampleRate) {
// for "no throttle" use regular rate, audio is just dropped
audio.freq = current_rate ? static_cast<int>(sampleRate * (current_rate / 100.0)) : sampleRate;
audio.format = AUDIO_S16SYS;
audio.format = SDL_AUDIO_S16;
audio.channels = 2;
audio.samples = 2048;
audio.callback = soundCallback;
audio.userdata = this;
if (!SDL_WasInit(SDL_INIT_AUDIO)) SDL_Init(SDL_INIT_AUDIO);
sound_device = SDL_OpenAudioDevice(NULL, 0, &audio, NULL, 0);
//This needs to be better flushed out especially where callback and userdata since that's done differently now
//SDL_OpenAudioDevice(deviceID (which can be SDL_AUDIO_DEVICE_DEFAULT_OUTPUT), AudioSpec, callback, userdata) So I need to flesh this out properly.
//sound_device needs to be an SDL_AudioStream, but this most probably not the best way to go just yet
if(sound_device == 0) {
std::cerr << "Failed to open audio: " << SDL_GetError() << std::endl;
return false;
}
SDL_AudioStream *sound_device = SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_OUTPUT, &audio, NULL, NULL);
samples_buf.reset(static_cast<size_t>(std::ceil(buftime * sampleRate * 2)));
@ -147,10 +139,10 @@ bool SoundSDL::init(long sampleRate) {
data_read = SDL_CreateSemaphore(1);
// turn off audio events because we are not processing them
#if SDL_VERSION_ATLEAST(2, 0, 4)
SDL_EventState(SDL_AUDIODEVICEADDED, SDL_IGNORE);
SDL_EventState(SDL_AUDIODEVICEREMOVED, SDL_IGNORE);
#endif
//#if SDL_VERSION_ATLEAST(2, 0, 4)
// SDL_EventState(SDL_EVENT_AUDIO_DEVICE_ADDED);
// SDL_EventState(SDL_EVENT_AUDIO_DEVICE_REMOVED);
//#endif
return initialized = true;
}
@ -164,8 +156,8 @@ void SoundSDL::deinit() {
SDL_LockMutex(mutex);
int is_emulating = emulating;
emulating = 0;
SDL_SemPost(data_available);
SDL_SemPost(data_read);
SDL_PostSemaphore(data_available);
SDL_PostSemaphore(data_read);
SDL_UnlockMutex(mutex);
SDL_Delay(100);

View File

@ -47,9 +47,9 @@ private:
SDL_AudioDeviceID sound_device = 0;
SDL_mutex* mutex;
SDL_sem* data_available;
SDL_sem* data_read;
SDL_Mutex* mutex;
SDL_Semaphore* data_available;
SDL_Semaphore* data_read;
SDL_AudioSpec audio_spec;
unsigned short current_rate;

View File

@ -50,7 +50,7 @@ target_link_libraries(vbam
)
if(WIN32)
target_link_libraries(vbam ${SDL2_LIBRARY} ${SDL2MAIN_LIBRARY})
target_link_libraries(vbam SDL3::SDL3)
endif()
if(ENABLE_LIRC)
@ -59,7 +59,7 @@ if(ENABLE_LIRC)
endif()
if(WIN32)
target_link_libraries(vbam wsock32 ws2_32 winmm version imm32 ${SDL2MAIN_LIBRARY})
target_link_libraries(vbam wsock32 ws2_32 winmm version imm32)
endif()
# Installation scripts.

View File

@ -809,7 +809,7 @@ void sdlReadDesktopVideoMode()
{
if (window) {
SDL_DisplayMode dm;
SDL_GetDesktopDisplayMode(SDL_GetWindowDisplayIndex(window), &dm);
SDL_GetDesktopDisplayMode(SDL_GetDisplayForWindow(window), &dm);
desktopWidth = dm.w;
desktopHeight = dm.h;
}
@ -829,7 +829,7 @@ static void sdlResizeVideo()
}
if (surface)
SDL_FreeSurface(surface);
SDL_DestroySurface(surface);
if (texture)
SDL_DestroyTexture(texture);
@ -924,13 +924,13 @@ void sdlInitVideo()
}
#ifndef KMOD_META
#define KMOD_META KMOD_GUI
#define KMOD_META SDL_KMOD_GUI
#endif
#define MOD_KEYS (KMOD_CTRL | KMOD_SHIFT | KMOD_ALT | KMOD_META)
#define MOD_NOCTRL (KMOD_SHIFT | KMOD_ALT | KMOD_META)
#define MOD_NOALT (KMOD_CTRL | KMOD_SHIFT | KMOD_META)
#define MOD_NOSHIFT (KMOD_CTRL | KMOD_ALT | KMOD_META)
#define MOD_KEYS (SDL_KMOD_CTRL | SDL_KMOD_SHIFT | SDL_KMOD_ALT | KMOD_META)
#define MOD_NOCTRL (SDL_KMOD_SHIFT | SDL_KMOD_ALT | KMOD_META)
#define MOD_NOALT (SDL_KMOD_CTRL | SDL_KMOD_SHIFT | KMOD_META)
#define MOD_NOSHIFT (SDL_KMOD_CTRL | SDL_KMOD_ALT | KMOD_META)
/*
* 04.02.2008 (xKiv): factored out from sdlPollEvents
@ -1052,12 +1052,12 @@ void sdlPollEvents()
SDL_Event event;
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_QUIT:
case SDL_EVENT_QUIT:
emulating = 0;
break;
case SDL_WINDOWEVENT:
switch (event.window.event) {
case SDL_WINDOWEVENT_FOCUS_GAINED:
case SDL_EVENT_WINDOW_FOCUS_GAINED:
if (pauseWhenInactive)
if (paused) {
if (emulating) {
@ -1066,7 +1066,7 @@ void sdlPollEvents()
}
}
break;
case SDL_WINDOWEVENT_FOCUS_LOST:
case SDL_EVENT_WINDOW_FOCUS_LOST:
if (pauseWhenInactive) {
wasPaused = true;
if (emulating) {
@ -1077,31 +1077,31 @@ void sdlPollEvents()
memset(delta, 255, delta_size);
}
break;
case SDL_WINDOWEVENT_RESIZED:
case SDL_EVENT_WINDOW_RESIZED:
if (openGL)
sdlOpenGLScaleWithAspect(event.window.data1, event.window.data2);
break;
}
break;
case SDL_MOUSEMOTION:
case SDL_MOUSEBUTTONUP:
case SDL_MOUSEBUTTONDOWN:
case SDL_EVENT_MOUSE_MOTION:
case SDL_EVENT_MOUSE_BUTTON_UP:
case SDL_EVENT_MOUSE_BUTTON_DOWN:
if (fullScreen) {
SDL_ShowCursor(SDL_ENABLE);
mouseCounter = 120;
}
break;
case SDL_JOYHATMOTION:
case SDL_JOYBUTTONDOWN:
case SDL_JOYBUTTONUP:
case SDL_JOYAXISMOTION:
case SDL_KEYDOWN:
case SDL_EVENT_JOYSTICK_HAT_MOTION:
case SDL_EVENT_JOYSTICK_BUTTON_DOWN:
case SDL_EVENT_JOYSTICK_BUTTON_UP:
case SDL_EVENT_JOYSTICK_AXIS_MOTION:
case SDL_EVENT_KEY_DOWN:
inputProcessSDLEvent(event);
break;
case SDL_KEYUP:
case SDL_EVENT_KEY_UP:
switch (event.key.keysym.sym) {
case SDLK_r:
if (!(event.key.keysym.mod & MOD_NOCTRL) && (event.key.keysym.mod & KMOD_CTRL)) {
if (!(event.key.keysym.mod & MOD_NOCTRL) && (event.key.keysym.mod & SDL_KMOD_CTRL)) {
if (emulating) {
emulator.emuReset();
@ -1110,30 +1110,30 @@ void sdlPollEvents()
}
break;
case SDLK_b:
if (!(event.key.keysym.mod & MOD_NOCTRL) && (event.key.keysym.mod & KMOD_CTRL))
if (!(event.key.keysym.mod & MOD_NOCTRL) && (event.key.keysym.mod & SDL_KMOD_CTRL))
change_rewind(-1);
break;
case SDLK_v:
if (!(event.key.keysym.mod & MOD_NOCTRL) && (event.key.keysym.mod & KMOD_CTRL))
if (!(event.key.keysym.mod & MOD_NOCTRL) && (event.key.keysym.mod & SDL_KMOD_CTRL))
change_rewind(+1);
break;
case SDLK_h:
if (!(event.key.keysym.mod & MOD_NOCTRL) && (event.key.keysym.mod & KMOD_CTRL))
if (!(event.key.keysym.mod & MOD_NOCTRL) && (event.key.keysym.mod & SDL_KMOD_CTRL))
change_rewind(0);
break;
case SDLK_j:
if (!(event.key.keysym.mod & MOD_NOCTRL) && (event.key.keysym.mod & KMOD_CTRL))
if (!(event.key.keysym.mod & MOD_NOCTRL) && (event.key.keysym.mod & SDL_KMOD_CTRL))
change_rewind((rewindTopPos - rewindPos) * ((rewindTopPos > rewindPos) ? +1 : -1));
break;
case SDLK_e:
if (!(event.key.keysym.mod & MOD_NOCTRL) && (event.key.keysym.mod & KMOD_CTRL)) {
if (!(event.key.keysym.mod & MOD_NOCTRL) && (event.key.keysym.mod & SDL_KMOD_CTRL)) {
coreOptions.cheatsEnabled = !coreOptions.cheatsEnabled;
systemConsoleMessage(coreOptions.cheatsEnabled ? "Cheats on" : "Cheats off");
}
break;
case SDLK_s:
if (!(event.key.keysym.mod & MOD_NOCTRL) && (event.key.keysym.mod & KMOD_CTRL)) {
if (!(event.key.keysym.mod & MOD_NOCTRL) && (event.key.keysym.mod & SDL_KMOD_CTRL)) {
if (sdlSoundToggledOff) { // was off
// restore saved state
soundSetEnable(sdlSoundToggledOff);
@ -1196,7 +1196,7 @@ void sdlPollEvents()
break;
case SDLK_p:
if (!(event.key.keysym.mod & MOD_NOCTRL) && (event.key.keysym.mod & KMOD_CTRL)) {
if (!(event.key.keysym.mod & MOD_NOCTRL) && (event.key.keysym.mod & SDL_KMOD_CTRL)) {
paused = !paused;
if (paused)
soundPause();
@ -1211,7 +1211,7 @@ void sdlPollEvents()
emulating = 0;
break;
case SDLK_f:
if (!(event.key.keysym.mod & MOD_NOCTRL) && (event.key.keysym.mod & KMOD_CTRL)) {
if (!(event.key.keysym.mod & MOD_NOCTRL) && (event.key.keysym.mod & SDL_KMOD_CTRL)) {
fullScreen = !fullScreen;
SDL_SetWindowFullscreen(window, fullScreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
if (openGL) {
@ -1224,7 +1224,7 @@ void sdlPollEvents()
}
break;
case SDLK_g:
if (!(event.key.keysym.mod & MOD_NOCTRL) && (event.key.keysym.mod & KMOD_CTRL)) {
if (!(event.key.keysym.mod & MOD_NOCTRL) && (event.key.keysym.mod & SDL_KMOD_CTRL)) {
filterFunction = 0;
while (!filterFunction) {
filter = (Filter)((filter + 1) % kInvalidFilter);
@ -1256,7 +1256,7 @@ void sdlPollEvents()
case SDLK_F6:
case SDLK_F7:
case SDLK_F8:
if (!(event.key.keysym.mod & MOD_NOSHIFT) && (event.key.keysym.mod & KMOD_SHIFT)) {
if (!(event.key.keysym.mod & MOD_NOSHIFT) && (event.key.keysym.mod & SDL_KMOD_SHIFT)) {
sdlHandleSavestateKey(event.key.keysym.sym - SDLK_F1, 1); // with SHIFT
} else if (!(event.key.keysym.mod & MOD_KEYS)) {
sdlHandleSavestateKey(event.key.keysym.sym - SDLK_F1, 0); // without SHIFT
@ -1281,7 +1281,7 @@ void sdlPollEvents()
case SDLK_2:
case SDLK_3:
case SDLK_4:
if (!(event.key.keysym.mod & MOD_NOALT) && (event.key.keysym.mod & KMOD_ALT)) {
if (!(event.key.keysym.mod & MOD_NOALT) && (event.key.keysym.mod & SDL_KMOD_ALT)) {
const char* disableMessages[4] = { "autofire A disabled",
"autofire B disabled",
"autofire R disabled",
@ -1306,7 +1306,7 @@ void sdlPollEvents()
} else {
systemScreenMessage(disableMessages[event.key.keysym.sym - SDLK_1]);
}
} else if (!(event.key.keysym.mod & MOD_NOCTRL) && (event.key.keysym.mod & KMOD_CTRL)) {
} else if (!(event.key.keysym.mod & MOD_NOCTRL) && (event.key.keysym.mod & SDL_KMOD_CTRL)) {
int mask = 0x0100 << (event.key.keysym.sym - SDLK_1);
coreOptions.layerSettings ^= mask;
coreOptions.layerEnable = DISPCNT & coreOptions.layerSettings;
@ -1317,14 +1317,14 @@ void sdlPollEvents()
case SDLK_6:
case SDLK_7:
case SDLK_8:
if (!(event.key.keysym.mod & MOD_NOCTRL) && (event.key.keysym.mod & KMOD_CTRL)) {
if (!(event.key.keysym.mod & MOD_NOCTRL) && (event.key.keysym.mod & SDL_KMOD_CTRL)) {
int mask = 0x0100 << (event.key.keysym.sym - SDLK_1);
coreOptions.layerSettings ^= mask;
coreOptions.layerEnable = DISPCNT & coreOptions.layerSettings;
}
break;
case SDLK_n:
if (!(event.key.keysym.mod & MOD_NOCTRL) && (event.key.keysym.mod & KMOD_CTRL)) {
if (!(event.key.keysym.mod & MOD_NOCTRL) && (event.key.keysym.mod & SDL_KMOD_CTRL)) {
if (paused)
paused = false;
pauseNextFrame = true;
@ -2062,7 +2062,7 @@ void systemDrawScreen()
} else {
SDL_UnlockSurface(surface);
SDL_UpdateTexture(texture, NULL, surface->pixels, surface->pitch);
SDL_RenderCopy(renderer, texture, NULL, NULL);
SDL_RenderTexture(renderer, texture, NULL, NULL);
SDL_RenderPresent(renderer);
}
}

View File

@ -106,18 +106,18 @@ static uint32_t sdlGetAxisCode(const SDL_Event& event)
uint32_t inputGetEventCode(const SDL_Event& event)
{
switch (event.type) {
case SDL_KEYDOWN:
case SDL_KEYUP:
case SDL_EVENT_KEY_DOWN:
case SDL_EVENT_KEY_UP:
return event.key.keysym.sym;
break;
case SDL_JOYHATMOTION:
case SDL_EVENT_JOYSTICK_HAT_MOTION:
return sdlGetHatCode(event);
break;
case SDL_JOYBUTTONDOWN:
case SDL_JOYBUTTONUP:
case SDL_EVENT_JOYSTICK_BUTTON_DOWN:
case SDL_EVENT_JOYSTICK_BUTTON_UP:
return sdlGetButtonCode(event);
break;
case SDL_JOYAXISMOTION:
case SDL_EVENT_JOYSTICK_AXIS_MOTION:
return sdlGetAxisCode(event);
break;
default:
@ -348,18 +348,18 @@ static bool sdlCheckJoyKey(int key)
// joystick button
int button = what - 128;
if (button >= SDL_JoystickNumButtons(sdlDevices[dev]))
if (button >= SDL_GetNumJoystickButtons(sdlDevices[dev]))
return false;
} else if (what < 0x20) {
// joystick axis
what >>= 1;
if (what >= SDL_JoystickNumAxes(sdlDevices[dev]))
if (what >= SDL_GetNumJoystickAxes(sdlDevices[dev]))
return false;
} else if (what < 0x30) {
// joystick hat
what = (what & 15);
what >>= 2;
if (what >= SDL_JoystickNumHats(sdlDevices[dev]))
if (what >= SDL_GetNumJoystickHats(sdlDevices[dev]))
return false;
}
@ -391,7 +391,7 @@ void inputInitJoysticks()
if (sdlDevices) {
if (dev < sdlNumDevices) {
if (sdlDevices[dev] == NULL) {
sdlDevices[dev] = SDL_JoystickOpen(dev);
sdlDevices[dev] = SDL_OpenJoystick(dev);
}
ok = sdlCheckJoyKey(joypad[j][i]);
@ -416,7 +416,7 @@ void inputInitJoysticks()
if (sdlDevices) {
if (dev < sdlNumDevices) {
if (sdlDevices[dev] == NULL) {
sdlDevices[dev] = SDL_JoystickOpen(dev);
sdlDevices[dev] = SDL_OpenJoystick(dev);
}
ok = sdlCheckJoyKey(motion[i]);
@ -440,26 +440,26 @@ void inputProcessSDLEvent(const SDL_Event& event)
// fprintf(stdout, "%x\n", inputGetEventCode(event));
switch (event.type) {
case SDL_KEYDOWN:
case SDL_EVENT_KEY_DOWN:
if (!event.key.keysym.mod)
sdlUpdateKey(event.key.keysym.sym, true);
break;
case SDL_KEYUP:
case SDL_EVENT_KEY_UP:
if (!event.key.keysym.mod)
sdlUpdateKey(event.key.keysym.sym, false);
break;
case SDL_JOYHATMOTION:
case SDL_EVENT_JOYSTICK_HAT_MOTION:
sdlUpdateJoyHat(event.jhat.which,
event.jhat.hat,
event.jhat.value);
break;
case SDL_JOYBUTTONDOWN:
case SDL_JOYBUTTONUP:
case SDL_EVENT_JOYSTICK_BUTTON_DOWN:
case SDL_EVENT_JOYSTICK_BUTTON_UP:
sdlUpdateJoyButton(event.jbutton.which,
event.jbutton.button,
event.jbutton.state == SDL_PRESSED);
break;
case SDL_JOYAXISMOTION:
case SDL_EVENT_JOYSTICK_AXIS_MOTION:
sdlUpdateJoyAxis(event.jaxis.which,
event.jaxis.axis,
event.jaxis.value);

View File

@ -55,7 +55,7 @@ wxJoyControl HatStatusToJoyControl(const uint8_t status) {
} // namespace
// For testing a GameController as a Joystick:
//#define SDL_IsGameController(x) false
//#define SDL_IsGamepad(x) false
// static
wxJoystick wxJoystick::Invalid() {
@ -148,7 +148,7 @@ private:
SDL_JoystickID joystick_id_;
// The SDL GameController instance.
SDL_GameController* game_controller_ = nullptr;
SDL_Gamepad* game_controller_ = nullptr;
// The SDL Joystick instance.
SDL_Joystick* sdl_joystick_ = nullptr;
@ -171,21 +171,21 @@ wxSDLJoyState::wxSDLJoyState(int sdl_index)
wxSDLJoyState::wxSDLJoyState(wxJoystick joystick) : wx_joystick_(joystick) {
int sdl_index = wx_joystick_.sdl_index_;
if (SDL_IsGameController(sdl_index)) {
game_controller_ = SDL_GameControllerOpen(sdl_index);
if (SDL_IsGamepad(sdl_index)) {
game_controller_ = SDL_GamepadOpen(sdl_index);
if (game_controller_)
sdl_joystick_ = SDL_GameControllerGetJoystick(game_controller_);
sdl_joystick_ = SDL_GamepadGetJoystick(game_controller_);
} else {
sdl_joystick_ = SDL_JoystickOpen(sdl_index);
sdl_joystick_ = SDL_OpenJoystick(sdl_index);
}
if (!sdl_joystick_)
return;
joystick_id_ = SDL_JoystickInstanceID(sdl_joystick_);
joystick_id_ = SDL_GetJoystickInstanceID(sdl_joystick_);
systemScreenMessage(
wxString::Format(_("Connected %s: %s"),
wx_joystick_.ToString(), SDL_JoystickNameForIndex(sdl_index)));
wx_joystick_.ToString(), SDL_GetJoystickNameForIndex(sdl_index)));
}
wxSDLJoyState::~wxSDLJoyState() {
@ -194,9 +194,9 @@ wxSDLJoyState::~wxSDLJoyState() {
return;
if (game_controller_)
SDL_GameControllerClose(game_controller_);
SDL_GamepadClose(game_controller_);
else
SDL_JoystickClose(sdl_joystick_);
SDL_CloseJoystick(sdl_joystick_);
systemScreenMessage(
wxString::Format(_("Disconnected %s"), wx_joystick_.ToString()));
@ -322,11 +322,11 @@ void wxSDLJoyState::SetRumble(bool activate_rumble) {
return;
if (rumbling_) {
SDL_GameControllerRumble(game_controller_, 0xFFFF, 0xFFFF, 300);
SDL_GamepadRumble(game_controller_, 0xFFFF, 0xFFFF, 300);
if (!IsRunning())
Start(150);
} else {
SDL_GameControllerRumble(game_controller_, 0, 0, 0);
SDL_GamepadRumble(game_controller_, 0, 0, 0);
Stop();
}
#endif
@ -339,8 +339,8 @@ void wxSDLJoyState::Notify() {
wxJoyPoller::wxJoyPoller() {
// Start up joystick if not already started
// FIXME: check for errors
SDL_Init(SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER);
SDL_GameControllerEventState(SDL_ENABLE);
SDL_Init(SDL_INIT_JOYSTICK | SDL_INIT_GAMEPAD);
SDL_GamepadEventState(SDL_ENABLE);
SDL_JoystickEventState(SDL_ENABLE);
}
@ -348,7 +348,7 @@ wxJoyPoller::~wxJoyPoller() {
// It is necessary to free all SDL resources before quitting SDL.
joystick_states_.clear();
SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
SDL_QuitSubSystem(SDL_INIT_GAMECONTROLLER);
SDL_QuitSubSystem(SDL_INIT_GAMEPAD);
}
void wxJoyPoller::Poll() {
@ -357,8 +357,8 @@ void wxJoyPoller::Poll() {
while (SDL_PollEvent(&e)) {
switch (e.type) {
case SDL_CONTROLLERBUTTONDOWN:
case SDL_CONTROLLERBUTTONUP:
case SDL_EVENT_GAMEPAD_BUTTON_DOWN:
case SDL_EVENT_GAMEPAD_BUTTON_UP:
joy_state = FindJoyState(e.cbutton.which);
if (joy_state) {
joy_state->ProcessButtonEvent(
@ -366,7 +366,7 @@ void wxJoyPoller::Poll() {
}
break;
case SDL_CONTROLLERAXISMOTION:
case SDL_EVENT_GAMEPAD_AXIS_MOTION:
joy_state = FindJoyState(e.caxis.which);
if (joy_state) {
joy_state->ProcessAxisEvent(
@ -374,15 +374,15 @@ void wxJoyPoller::Poll() {
}
break;
case SDL_CONTROLLERDEVICEADDED:
case SDL_CONTROLLERDEVICEREMOVED:
case SDL_EVENT_GAMEPAD_ADDED:
case SDL_EVENT_GAMEPAD_REMOVED:
// Do nothing. This will be handled with JOYDEVICEADDED and
// JOYDEVICEREMOVED events.
break;
// Joystick events for non-GameControllers.
case SDL_JOYBUTTONDOWN:
case SDL_JOYBUTTONUP:
case SDL_EVENT_JOYSTICK_BUTTON_DOWN:
case SDL_EVENT_JOYSTICK_BUTTON_UP:
joy_state = FindJoyState(e.jbutton.which);
if (joy_state && !joy_state->is_game_controller()) {
joy_state->ProcessButtonEvent(
@ -390,7 +390,7 @@ void wxJoyPoller::Poll() {
}
break;
case SDL_JOYAXISMOTION:
case SDL_EVENT_JOYSTICK_AXIS_MOTION:
joy_state = FindJoyState(e.jaxis.which);
if (joy_state && !joy_state->is_game_controller()) {
joy_state->ProcessAxisEvent(
@ -398,7 +398,7 @@ void wxJoyPoller::Poll() {
}
break;
case SDL_JOYHATMOTION:
case SDL_EVENT_JOYSTICK_HAT_MOTION:
joy_state = FindJoyState(e.jhat.which);
if (joy_state && !joy_state->is_game_controller()) {
joy_state->ProcessHatEvent(
@ -406,12 +406,12 @@ void wxJoyPoller::Poll() {
}
break;
case SDL_JOYDEVICEADDED:
case SDL_EVENT_JOYSTICK_ADDED:
// Always remap all controllers.
RemapControllers();
break;
case SDL_JOYDEVICEREMOVED:
case SDL_EVENT_JOYSTICK_REMOVED:
joystick_states_.erase(e.jdevice.which);
break;
}