This commit is contained in:
ZakatTeamI2P 2026-03-30 20:46:24 +04:00
parent d41739ce26
commit 1f06d5ecf1
3 changed files with 59 additions and 61 deletions

View File

@ -22,19 +22,19 @@
#include "aldatasource.h" #include "aldatasource.h"
#include "exception.h" #include "exception.h"
#include <SDL_sound.h> #include <SDL3_sound/SDL_sound.h>
struct SDLSoundSource : ALDataSource struct SDLSoundSource : ALDataSource
{ {
Sound_Sample *sample; Sound_Sample *sample;
SDL_RWops &srcOps; SDL_IOStream &srcOps;
uint8_t sampleSize; uint8_t sampleSize;
bool looped; bool looped;
ALenum alFormat; ALenum alFormat;
ALsizei alFreq; ALsizei alFreq;
SDLSoundSource(SDL_RWops &ops, SDLSoundSource(SDL_IOStream &ops,
const char *extension, const char *extension,
uint32_t maxBufSize, uint32_t maxBufSize,
bool looped) bool looped)
@ -45,7 +45,7 @@ struct SDLSoundSource : ALDataSource
if (!sample) if (!sample)
{ {
SDL_RWclose(&ops); SDL_CloseIO(&ops);
throw Exception(Exception::SDLError, "SDL_sound: %s", Sound_GetError()); throw Exception(Exception::SDLError, "SDL_sound: %s", Sound_GetError());
} }
@ -121,7 +121,7 @@ struct SDLSoundSource : ALDataSource
} }
}; };
ALDataSource *createSDLSource(SDL_RWops &ops, ALDataSource *createSDLSource(SDL_IOStream &ops,
const char *extension, const char *extension,
uint32_t maxBufSize, uint32_t maxBufSize,
bool looped) bool looped)

View File

@ -25,7 +25,7 @@
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
#include <SDL_endian.h> #include <SDL3/SDL_endian.h>
#if SDL_BYTEORDER != SDL_LIL_ENDIAN #if SDL_BYTEORDER != SDL_LIL_ENDIAN
#error "Non little endian systems not supported" #error "Non little endian systems not supported"

View File

@ -21,11 +21,11 @@
#include "settingsmenu.h" #include "settingsmenu.h"
#include <SDL_video.h> #include <SDL3/SDL_video.h>
#include <SDL_ttf.h> #include <SDL3_ttf/SDL_ttf.h>
#include <SDL_surface.h> #include <SDL3/SDL_surface.h>
#include <SDL_keyboard.h> #include <SDL3/SDL_keyboard.h>
#include <SDL_rect.h> #include <SDL3/SDL_rect.h>
#include "keybindings.h" #include "keybindings.h"
#include "eventthread.h" #include "eventthread.h"
@ -164,29 +164,29 @@ std::string sourceDescString(const SourceDesc &src)
case CAxis: case CAxis:
switch (src.d.ja.axis) { switch (src.d.ja.axis) {
case SDL_CONTROLLER_AXIS_LEFTX: case SDL_GAMEPAD_AXIS_LEFTX:
if (src.d.ja.dir == Negative) if (src.d.ja.dir == Negative)
return findtext(TRSTR_KEYBIND_LSTICKL, "Left Stick (Left)"); return findtext(TRSTR_KEYBIND_LSTICKL, "Left Stick (Left)");
else else
return findtext(TRSTR_KEYBIND_LSTICKR, "Left Stick (Right)"); return findtext(TRSTR_KEYBIND_LSTICKR, "Left Stick (Right)");
case SDL_CONTROLLER_AXIS_LEFTY: case SDL_GAMEPAD_AXIS_LEFTY:
if (src.d.ja.dir == Negative) if (src.d.ja.dir == Negative)
return findtext(TRSTR_KEYBIND_LSTICKU, "Left Stick (Up)"); return findtext(TRSTR_KEYBIND_LSTICKU, "Left Stick (Up)");
else else
return findtext(TRSTR_KEYBIND_LSTICKD, "Left Stick (Down)"); return findtext(TRSTR_KEYBIND_LSTICKD, "Left Stick (Down)");
case SDL_CONTROLLER_AXIS_RIGHTX: case SDL_GAMEPAD_AXIS_RIGHTX:
if (src.d.ja.dir == Negative) if (src.d.ja.dir == Negative)
return findtext(TRSTR_KEYBIND_RSTICKL, "Right Stick (Left)"); return findtext(TRSTR_KEYBIND_RSTICKL, "Right Stick (Left)");
else else
return findtext(TRSTR_KEYBIND_RSTICKR, "Right Stick (Right)"); return findtext(TRSTR_KEYBIND_RSTICKR, "Right Stick (Right)");
case SDL_CONTROLLER_AXIS_RIGHTY: case SDL_GAMEPAD_AXIS_RIGHTY:
if (src.d.ja.dir == Negative) if (src.d.ja.dir == Negative)
return findtext(TRSTR_KEYBIND_RSTICKU, "Right Stick (Up)"); return findtext(TRSTR_KEYBIND_RSTICKU, "Right Stick (Up)");
else else
return findtext(TRSTR_KEYBIND_RSTICKD, "Right Stick (Down)"); return findtext(TRSTR_KEYBIND_RSTICKD, "Right Stick (Down)");
case SDL_CONTROLLER_AXIS_TRIGGERLEFT: case SDL_GAMEPAD_AXIS_TRIGGERLEFT:
return findtext(TRSTR_KEYBIND_LTRIGGER, "Left Trigger"); return findtext(TRSTR_KEYBIND_LTRIGGER, "Left Trigger");
case SDL_CONTROLLER_AXIS_TRIGGERRIGHT: case SDL_GAMEPAD_AXIS_TRIGGERRIGHT:
return findtext(TRSTR_KEYBIND_RTRIGGER, "Right Trigger"); return findtext(TRSTR_KEYBIND_RTRIGGER, "Right Trigger");
} }
return ""; return "";
@ -395,15 +395,14 @@ struct SettingsMenuPrivate
{ {
int bpp; int bpp;
Uint32 rMask, gMask, bMask, aMask; Uint32 rMask, gMask, bMask, aMask;
SDL_PixelFormatEnumToMasks(SDL_PIXELFORMAT_ABGR8888, SDL_GetMasksForPixelFormat(SDL_PIXELFORMAT_ABGR8888,
&bpp, &rMask, &gMask, &bMask, &aMask); &bpp, &rMask, &gMask, &bMask, &aMask);
//SDL_Surface *surface = SDL_CreateSurface(32, 32, SDL_PIXELFORMAT_INDEX8);
return SDL_CreateRGBSurface(0, w, h, bpp, rMask, gMask, bMask, 0); return SDL_CreateRGBSurface(w, h, rMask, gMask, bMask, 0);
} }
void fillSurface(SDL_Surface *surf, uint8_t grey) void fillSurface(SDL_Surface *surf, uint8_t grey){
{ SDL_FillSurfaceRect(surf, 0, SDL_MapRGBA(rgb, grey, grey, grey, 255));
SDL_FillRect(surf, 0, SDL_MapRGBA(rgb, grey, grey, grey, 255));
} }
void fillRect(SDL_Surface *surf, void fillRect(SDL_Surface *surf,
@ -485,14 +484,14 @@ struct SettingsMenuPrivate
SDL_Color c = { cText, cText, cText, 255 }; SDL_Color c = { cText, cText, cText, 255 };
applyFontStyle(bold); applyFontStyle(bold);
return TTF_RenderUTF8_Blended(font, str, c); return TTF_RenderText_Blended(font, str, c);
} }
SDL_Surface *createTextSurface(const char *str, SDL_Color c, SDL_Surface *createTextSurface(const char *str, SDL_Color c,
bool bold) bool bold)
{ {
applyFontStyle(bold); applyFontStyle(bold);
return TTF_RenderUTF8_Blended(font, str, c); return TTF_RenderText_Blended(font, str, c);
} }
/* Horizontally centered */ /* Horizontally centered */
@ -541,7 +540,7 @@ struct SettingsMenuPrivate
SDL_Surface *txt = createTextSurface(str, c, bold); SDL_Surface *txt = createTextSurface(str, c, bold);
if (txt) { if (txt) {
blitTextSurf(surf, x, y, alignW, txt, just); blitTextSurf(surf, x, y, alignW, txt, just);
SDL_FreeSurface(txt); SDL_DestroySurface(txt);
} }
} }
@ -661,8 +660,8 @@ struct SettingsMenuPrivate
SDL_BlitSurface(txt, 0, winSurf, &fill); SDL_BlitSurface(txt, 0, winSurf, &fill);
SDL_FreeSurface(txt); SDL_DestroySurface(txt);
SDL_FreeSurface(dark); SDL_DestroySurface(dark);
} }
SDL_UpdateWindowSurface(window); SDL_UpdateWindowSurface(window);
@ -725,7 +724,7 @@ struct SettingsMenuPrivate
switch (event.type) switch (event.type)
{ {
case SDL_KEYDOWN: case SDL_EVENT_KEY_DOWN:
desc.type = Key; desc.type = Key;
desc.d.scan = event.key.keysym.scancode; desc.d.scan = event.key.keysym.scancode;
@ -738,12 +737,12 @@ struct SettingsMenuPrivate
break; break;
case SDL_CONTROLLERBUTTONDOWN: case SDL_EVENT_GAMEPAD_BUTTON_DOWN:
desc.type = CButton; desc.type = CButton;
desc.d.jb = event.cbutton.button; desc.d.jb = event.cbutton.button;
break; break;
case SDL_CONTROLLERAXISMOTION: case SDL_EVENT_GAMEPAD_AXIS_MOTION:
{ {
int v = event.caxis.value; int v = event.caxis.value;
@ -757,12 +756,12 @@ struct SettingsMenuPrivate
break; break;
} }
case SDL_JOYBUTTONDOWN: case SDL_EVENT_JOYSTICK_BUTTON_DOWN:
desc.type = JButton; desc.type = JButton;
desc.d.jb = event.cbutton.button; desc.d.jb = event.cbutton.button;
break; break;
case SDL_JOYHATMOTION: case SDL_EVENT_JOYSTICK_HAT_MOTION:
{ {
int v = event.jhat.value; int v = event.jhat.value;
@ -777,7 +776,7 @@ struct SettingsMenuPrivate
break; break;
} }
case SDL_JOYAXISMOTION: case SDL_EVENT_JOYSTICK_AXIS_MOTION:
{ {
int v = event.jaxis.value; int v = event.jaxis.value;
@ -1075,7 +1074,6 @@ SettingsMenu::SettingsMenu(RGSSThreadData &rtData)
p->destroyReq = false; p->destroyReq = false;
p->window = SDL_CreateWindow(findtext(TRSTR_KEYBIND_TITLE, "Key bindings"), p->window = SDL_CreateWindow(findtext(TRSTR_KEYBIND_TITLE, "Key bindings"),
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
winSize.x, winSize.y, SDL_WINDOW_INPUT_FOCUS); winSize.x, winSize.y, SDL_WINDOW_INPUT_FOCUS);
p->winSurf = SDL_GetWindowSurface(p->window); p->winSurf = SDL_GetWindowSurface(p->window);
p->winID = SDL_GetWindowID(p->window); p->winID = SDL_GetWindowID(p->window);
@ -1160,24 +1158,24 @@ bool SettingsMenu::onEvent(const SDL_Event &event,
switch (event.type) switch (event.type)
{ {
case SDL_WINDOWEVENT : case SDL_WINDOWEVENT :
case SDL_MOUSEBUTTONDOWN : case SDL_EVENT_MOUSE_BUTTON_DOWN :
case SDL_MOUSEBUTTONUP : case SDL_EVENT_MOUSE_BUTTON_UP :
case SDL_MOUSEMOTION : case SDL_EVENT_MOUSE_MOTION :
case SDL_KEYDOWN : case SDL_EVENT_KEY_DOWN :
case SDL_KEYUP : case SDL_EVENT_KEY_UP :
/* We can do this because windowID has the same /* We can do this because windowID has the same
* struct offset in all these event types */ * struct offset in all these event types */
if (event.window.windowID != p->winID) if (event.window.windowID != p->winID)
return false; return false;
break; break;
case SDL_CONTROLLERBUTTONDOWN: case SDL_EVENT_GAMEPAD_BUTTON_DOWN:
case SDL_CONTROLLERBUTTONUP: case SDL_EVENT_GAMEPAD_BUTTON_UP:
case SDL_CONTROLLERAXISMOTION: case SDL_EVENT_GAMEPAD_AXIS_MOTION:
case SDL_JOYBUTTONDOWN : case SDL_EVENT_JOYSTICK_BUTTON_DOWN :
case SDL_JOYBUTTONUP : case SDL_EVENT_JOYSTICK_BUTTON_UP :
case SDL_JOYHATMOTION : case SDL_EVENT_JOYSTICK_HAT_MOTION :
case SDL_JOYAXISMOTION : case SDL_EVENT_JOYSTICK_AXIS_MOTION :
if (!p->hasFocus) if (!p->hasFocus)
return false; return false;
break; break;
@ -1198,20 +1196,20 @@ bool SettingsMenu::onEvent(const SDL_Event &event,
case SDL_WINDOWEVENT : case SDL_WINDOWEVENT :
switch (event.window.event) switch (event.window.event)
{ {
case SDL_WINDOWEVENT_SHOWN : // SDL is bugged and doesn't give us a first FOCUS_GAINED event case SDL_EVENT_WINDOW_SHOWN : // SDL is bugged and doesn't give us a first FOCUS_GAINED event
case SDL_WINDOWEVENT_FOCUS_GAINED : case SDL_EVENT_WINDOW_FOCUS_GAINED :
p->hasFocus = true; p->hasFocus = true;
break; break;
case SDL_WINDOWEVENT_FOCUS_LOST : case SDL_EVENT_WINDOW_FOCUS_LOST :
p->hasFocus = false; p->hasFocus = false;
break; break;
case SDL_WINDOWEVENT_EXPOSED : case SDL_EVENT_WINDOW_EXPOSED :
SDL_UpdateWindowSurface(p->window); SDL_UpdateWindowSurface(p->window);
break; break;
case SDL_WINDOWEVENT_LEAVE: case SDL_EVENT_WINDOW_MOUSE_LEAVE:
if (p->hovered) if (p->hovered)
{ {
p->hovered->leave(); p->hovered->leave();
@ -1219,17 +1217,17 @@ bool SettingsMenu::onEvent(const SDL_Event &event,
} }
break; break;
case SDL_WINDOWEVENT_CLOSE: case SDL_EVENT_WINDOW_CLOSE_REQUESTED:
p->onCancel(); p->onCancel();
} }
return true; return true;
case SDL_MOUSEMOTION: case SDL_EVENT_MOUSE_MOTION:
p->onMotion(event.motion); p->onMotion(event.motion);
return true; return true;
case SDL_KEYDOWN: case SDL_EVENT_KEY_DOWN:
if (p->state != AwaitingInput) if (p->state != AwaitingInput)
{ {
if (event.key.keysym.sym == SDLK_RETURN) if (event.key.keysym.sym == SDLK_RETURN)
@ -1253,32 +1251,32 @@ bool SettingsMenu::onEvent(const SDL_Event &event,
} }
break; break;
case SDL_CONTROLLERBUTTONDOWN: case SDL_EVENT_GAMEPAD_BUTTON_DOWN:
case SDL_CONTROLLERAXISMOTION: case SDL_EVENT_GAMEPAD_AXIS_MOTION:
if (p->state != AwaitingInput) if (p->state != AwaitingInput)
return true; return true;
break; break;
case SDL_JOYBUTTONDOWN: case SDL_EVENT_JOYSTICK_BUTTON_DOWN:
if (p->state != AwaitingInput) if (p->state != AwaitingInput)
return true; return true;
if (joysticks.find(event.jbutton.which) == joysticks.end()) if (joysticks.find(event.jbutton.which) == joysticks.end())
return true; return true;
break; break;
case SDL_JOYHATMOTION: case SDL_EVENT_JOYSTICK_HAT_MOTION:
if (p->state != AwaitingInput) if (p->state != AwaitingInput)
return true; return true;
if (joysticks.find(event.jhat.which) == joysticks.end()) if (joysticks.find(event.jhat.which) == joysticks.end())
return true; return true;
break; break;
case SDL_JOYAXISMOTION: case SDL_EVENT_JOYSTICK_AXIS_MOTION:
if (p->state != AwaitingInput) if (p->state != AwaitingInput)
return true; return true;
if (joysticks.find(event.jaxis.which) == joysticks.end()) if (joysticks.find(event.jaxis.which) == joysticks.end())
return true; return true;
break; break;
case SDL_MOUSEBUTTONDOWN: case SDL_EVENT_MOUSE_BUTTON_DOWN:
p->onClick(event.button); p->onClick(event.button);
return true; return true;
default: default: