Compare commits

...

3 Commits

Author SHA1 Message Date
Zach Bacon
7d0b47e4eb SDL3: Still slowly migrating the most common functions to their SDL3 counterparts
This is still a work in progress, once that is done, I'll make a detailed report on some
other functions that got redesigned upstream that needs to be implemented.

Signed-off-by: Zach Bacon <zachbacon@vba-m.com>
2023-11-22 17:04:09 -05:00
Zach Bacon
895687cd61 SoundSDL.cpp: This should resolve some of the issue
But since I've yet to get a full working build yet
It's not really bound to be fleshed out properly yet.

Signed-off-by: Zach Bacon <zachbacon@vba-m.com>
2023-11-22 16:02:30 -05:00
Zach Bacon
1757f1f39b SDL3: Bringing sdl3 compatibility for vba-m
Still dealing with understanding on the new updated api
and deprecation, beginning with soundsdl and the changes
sdl3 brings

https://github.com/libsdl-org/SDL/blob/main/docs/README-migration.md

Signed-off-by: Zach Bacon <zachbacon@vba-m.com>
2023-11-22 16:02:30 -05:00
6 changed files with 61 additions and 57 deletions

View File

@@ -45,7 +45,7 @@ if(TAG_RELEASE)
include(MakeReleaseCommitAndTag)
endif()
set(VCPKG_DEPS pkgconf zlib sdl2 gettext wxwidgets)
set(VCPKG_DEPS pkgconf zlib SDL3 gettext wxwidgets)
set(VCPKG_DEPS_OPTIONAL
sfml ENABLE_LINK
@@ -121,7 +121,7 @@ endif()
option(VBAM_STATIC "Try to link all libraries statically" ${VBAM_STATIC_DEFAULT})
if(VBAM_STATIC)
set(SDL2_STATIC ON)
set(SDL3_STATIC ON)
set(SFML_STATIC_LIBRARIES ON)
set(FFMPEG_STATIC ON)
set(SSP_STATIC ON)
@@ -427,10 +427,10 @@ if(CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
endif()
find_package(OpenGL REQUIRED)
find_package(SDL2 REQUIRED)
find_package(SDL3 REQUIRED)
if(WIN32)
set(SDL2_LIBRARY ${SDL2_LIBRARY} setupapi winmm)
set(SDL3_LIBRARY ${SDL3_LIBRARY} setupapi winmm)
endif()
# set the standard libraries all ports use
@@ -438,7 +438,7 @@ set(
VBAMCORE_LIBS
vbamcore
fex
${SDL2_LIBRARY}
${SDL3_LIBRARY}
${SFML_LIBRARIES}
${OPENGL_LIBRARIES}
${ZLIB_LIBRARY}
@@ -1151,7 +1151,7 @@ set(
include_directories(
${ZLIB_INCLUDE_DIR}
fex
${SDL2_INCLUDE_DIR}
${SDL3_INCLUDE_DIR}
third_party/include
third_party/include/stb
)
@@ -1213,7 +1213,7 @@ if((NOT TRANSLATIONS_ONLY) AND ENABLE_SDL)
)
if(WIN32)
target_link_libraries(vbam ${SDL2MAIN_LIBRARY})
target_link_libraries(vbam ${SDL3MAIN_LIBRARY})
endif()
install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/vbam${CMAKE_EXECUTABLE_SUFFIX} DESTINATION ${CMAKE_INSTALL_FULL_BINDIR})

View File

@@ -17,7 +17,7 @@
#include <cmath>
#include <iostream>
#include <SDL_events.h>
#include <SDL3/SDL_events.h>
#include "SoundSDL.h"
#include "../gba/Globals.h"
#include "../gba/Sound.h"
@@ -62,7 +62,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;
}
@@ -73,7 +73,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) {
@@ -82,8 +82,10 @@ 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_GetAudioDeviceStatus has been removed in SDL3 and replaced with SDL_IsAudioDevicePaused()
if (SDL_IsAudioDevicePaused(sound_device) != SDL_TRUE)
//still need to deal with below
SDL_PauseAudioDevice(sound_device);
std::size_t samples = length / 4;
std::size_t avail;
@@ -96,10 +98,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;
@@ -116,21 +118,21 @@ void SoundSDL::write(uint16_t * finalWave, int length) {
bool SoundSDL::init(long sampleRate) {
if (initialized) deinit();
SDL_AudioSpec audio;
SDL_memset(&audio, 0, sizeof(audio));
const SDL_AudioSpec audio = { SDL_AUDIO_S16SYS, 2, 2048 };
//SDL_memset(&audio, 0, sizeof(audio));
// for "no throttle" use regular rate, audio is just dropped
audio.freq = current_rate ? static_cast<int>(sampleRate * (current_rate / 100.0)) : sampleRate;
//audio.freq = current_rate ? static_cast<int>(sampleRate * (current_rate / 100.0)) : sampleRate;
audio.format = AUDIO_S16SYS;
audio.channels = 2;
audio.samples = 2048;
audio.callback = soundCallback;
audio.userdata = this;
//audio.format = SDL_AUDIO_S16SYS, 2, 2048;
//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);
SDL_AudioStream *sound_device = SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_OUTPUT, &audio, NULL, 0);
if(sound_device == 0) {
std::cerr << "Failed to open audio: " << SDL_GetError() << std::endl;
@@ -144,9 +146,9 @@ 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);
#if SDL_VERSION_ATLEAST(3, 0, 0)
SDL_EventEnabled(SDL_EVENT_AUDIO_DEVICE_ADDED);
SDL_EventEnabled(SDL_EVENT_AUDIO_DEVICE_REMOVED);
#endif
return initialized = true;
@@ -161,8 +163,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

@@ -21,7 +21,7 @@
#include "ringbuffer.h"
#include "SoundDriver.h"
#include "SDL.h"
#include <SDL3/SDL.h>
class SoundSDL : public SoundDriver {
public:
@@ -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

@@ -43,7 +43,7 @@
#include "../common/version_cpp.h"
#include "SDL.h"
#include <SDL3/SDL.h>
#include "../Util.h"
#include "../common/Patch.h"
@@ -795,7 +795,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;
}
@@ -815,12 +815,12 @@ static void sdlResizeVideo()
}
if (surface)
SDL_FreeSurface(surface);
SDL_DestroySurface(surface);
if (texture)
SDL_DestroyTexture(texture);
if (!openGL) {
surface = SDL_CreateRGBSurface(0, destWidth, destHeight, 32,
surface = SDL_CreateSurface(0, destWidth, destHeight, 32,
0x00FF0000, 0x0000FF00,
0x000000FF, 0xFF000000);
texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888,
@@ -845,8 +845,10 @@ void sdlInitVideo()
destWidth = filter_enlarge * sizeX;
destHeight = filter_enlarge * sizeY;
flags = fullScreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0;
//This bit will need to be checked
//flags = fullScreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0;
flags = fullScreen ? SDL_WINDOW_FULLSCREEN : 0;
if (openGL) {
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
flags |= SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE;

View File

@@ -105,18 +105,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:
@@ -347,18 +347,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;
}
@@ -374,7 +374,7 @@ void inputInitJoysticks()
joypad[PAD_MAIN][i] = joypad[PAD_DEFAULT][i];
}
sdlNumDevices = SDL_NumJoysticks();
sdlNumDevices = SDL_GetJoysticks();
if (sdlNumDevices)
sdlDevices = (SDL_Joystick**)calloc(1, sdlNumDevices * sizeof(SDL_Joystick**));
@@ -390,7 +390,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]);
@@ -415,7 +415,7 @@ void inputInitJoysticks()
if (sdlDevices) {
if (dev < sdlNumDevices) {
if (sdlDevices[dev] == NULL) {
sdlDevices[dev] = SDL_JoystickOpen(dev);
sdlDevices[dev] = SDL_SetJoystickEventsEnabled(dev);
}
ok = sdlCheckJoyKey(motion[i]);
@@ -439,26 +439,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

@@ -18,7 +18,7 @@
#ifndef VBAM_SDL_INPUT_H
#define VBAM_SDL_INPUT_H
#include "SDL.h"
#include <SDL3/SDL.h>
enum EKey {
KEY_LEFT,