mirror of
https://github.com/visualboyadvance-m/visualboyadvance-m
synced 2025-10-05 23:52:49 +02:00
Compare commits
3 Commits
game-contr
...
SDL3
Author | SHA1 | Date | |
---|---|---|---|
|
7d0b47e4eb | ||
|
895687cd61 | ||
|
1757f1f39b |
@@ -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})
|
||||
|
@@ -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);
|
||||
|
@@ -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;
|
||||
|
@@ -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;
|
||||
|
@@ -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);
|
||||
|
@@ -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,
|
||||
|
Reference in New Issue
Block a user