Skip to content

Commit 2a85cd1

Browse files
committed
all: support SDL2 v2.30.0
1 parent e0a6bff commit 2a85cd1

18 files changed

+381
-103
lines changed

.github/workflows/ci.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
timeout-minutes: 30
1515
env:
1616
VFLAGS: -cc tcc -no-retry-compilation
17-
SDL2_VERSION: 2.28.0
17+
SDL2_VERSION: 2.30.0
1818
steps:
1919
- name: Install dependencies
2020
run: |
@@ -81,7 +81,7 @@ jobs:
8181
runs-on: macos-11
8282
timeout-minutes: 30
8383
env:
84-
SDL2_VERSION: 2.28.0
84+
SDL2_VERSION: 2.30.0
8585
steps:
8686
- name: Checkout V
8787
uses: actions/checkout@v2
@@ -150,7 +150,7 @@ jobs:
150150
timeout-minutes: 30
151151
env:
152152
VFLAGS: -cc gcc -no-retry-compilation
153-
SDL2_VERSION: 2.28.0
153+
SDL2_VERSION: 2.30.0
154154
steps:
155155
- name: Install V
156156
uses: vlang/setup-v@v1
@@ -185,7 +185,7 @@ jobs:
185185
timeout-minutes: 30
186186
env:
187187
VFLAGS: -cc tcc -no-retry-compilation
188-
SDL2_VERSION: 2.28.0
188+
SDL2_VERSION: 2.30.0
189189
steps:
190190

191191
- name: Install V

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ This will create a directory called "thirdparty" which will be used to download
119119
To successfully run a provided example or your own projects, the sdl dlls must be copied to the main application directory.
120120
e.g.:
121121
```bash
122-
copy thirdparty\SDL2-2.28.0\lib\x64\SDL2.dll examples\basic_window\
122+
copy thirdparty\SDL2-2.30.0\lib\x64\SDL2.dll examples\basic_window\
123123
cd ..
124124
v run sdl\examples\basic_window\main.v
125125
```

blendmode.c.v

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ pub enum BlendMode {
2222
// BlendOperation is C.SDL_BlendOperation
2323
pub enum BlendOperation {
2424
add = C.SDL_BLENDOPERATION_ADD // 0x1, dst + src: supported by all renderers
25-
subtract = C.SDL_BLENDOPERATION_SUBTRACT // 0x2, dst - src : supported by D3D9, D3D11, OpenGL, OpenGLES
26-
rev_subtract = C.SDL_BLENDOPERATION_REV_SUBTRACT // 0x3, src - dst : supported by D3D9, D3D11, OpenGL, OpenGLES
25+
subtract = C.SDL_BLENDOPERATION_SUBTRACT // 0x2, src - dst : supported by D3D9, D3D11, OpenGL, OpenGLES
26+
rev_subtract = C.SDL_BLENDOPERATION_REV_SUBTRACT // 0x3, dst - src : supported by D3D9, D3D11, OpenGL, OpenGLES
2727
minimum = C.SDL_BLENDOPERATION_MINIMUM // 0x4, min(dst, src) : supported by D3D9, D3D11
2828
maximum = C.SDL_BLENDOPERATION_MAXIMUM // 0x5 max(dst, src) : supported by D3D9, D3D11
2929
}

c/sdl.c.v

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ $if !windows {
2626
#flag -DSDL_DISABLE_IMMINTRIN_H
2727

2828
$if x64 {
29-
#flag windows -L @VMODROOT/thirdparty/SDL2-2.28.0/lib/x64
29+
#flag windows -L @VMODROOT/thirdparty/SDL2-2.30.0/lib/x64
3030
} $else {
31-
#flag windows -L @VMODROOT/thirdparty/SDL2-2.28.0/lib/x86
31+
#flag windows -L @VMODROOT/thirdparty/SDL2-2.30.0/lib/x86
3232
}
33-
#flag windows -I @VMODROOT/thirdparty/SDL2-2.28.0/include
33+
#flag windows -I @VMODROOT/thirdparty/SDL2-2.30.0/include
3434
#flag windows -Dmain=SDL_main
3535
#flag windows -lSDL2main -lSDL2
3636

events.c.v

+62-70
Original file line numberDiff line numberDiff line change
@@ -40,100 +40,102 @@ pub type EventFilter = fn (userdata voidptr, event &Event)
4040

4141
// EventType is C.SDL_EventType
4242
pub enum EventType {
43-
firstevent = C.SDL_FIRSTEVENT // Unused (do not remove)
44-
quit = C.SDL_QUIT // 0x100 User-requested quit
43+
firstevent = C.SDL_FIRSTEVENT // Unused (do not remove)
44+
quit = C.SDL_QUIT // 0x100 User-requested quit
4545
// These application events have special meaning on iOS, see README-ios.md in SDL for details
4646
// The application is being terminated by the OS
4747
// Called on iOS in applicationWillTerminate()
4848
// Called on Android in onDestroy()
49-
app_terminating = C.SDL_APP_TERMINATING
49+
app_terminating = C.SDL_APP_TERMINATING
5050
// The application is low on memory, free memory if possible.
5151
// Called on iOS in applicationDidReceiveMemoryWarning()
5252
// Called on Android in onLowMemory()
53-
app_lowmemory = C.SDL_APP_LOWMEMORY
53+
app_lowmemory = C.SDL_APP_LOWMEMORY
5454
// The application is about to enter the background
5555
// Called on iOS in applicationWillResignActive()
5656
// Called on Android in onPause()
57-
app_willenterbackground = C.SDL_APP_WILLENTERBACKGROUND
57+
app_willenterbackground = C.SDL_APP_WILLENTERBACKGROUND
5858
// The application did enter the background and may not get CPU for some time
5959
// Called on iOS in applicationDidEnterBackground()
6060
// Called on Android in onPause()
61-
app_didenterbackground = C.SDL_APP_DIDENTERBACKGROUND
61+
app_didenterbackground = C.SDL_APP_DIDENTERBACKGROUND
6262
// The application is about to enter the foreground
6363
// Called on iOS in applicationWillEnterForeground()
6464
// Called on Android in onResume()
65-
app_willenterforeground = C.SDL_APP_WILLENTERFOREGROUND
65+
app_willenterforeground = C.SDL_APP_WILLENTERFOREGROUND
6666
// The application is now interactive
6767
// Called on iOS in applicationDidBecomeActive()
6868
// Called on Android in onResume()
69-
app_didenterforeground = C.SDL_APP_DIDENTERFOREGROUND
70-
localechanged = C.SDL_LOCALECHANGED // The user's locale preferences have changed.
69+
app_didenterforeground = C.SDL_APP_DIDENTERFOREGROUND
70+
localechanged = C.SDL_LOCALECHANGED // The user's locale preferences have changed.
7171
// Display events
72-
displayevent = C.SDL_DISPLAYEVENT // 0x150 Display state change
72+
displayevent = C.SDL_DISPLAYEVENT // 0x150 Display state change
7373
// Window events
74-
windowevent = C.SDL_WINDOWEVENT // 0x200 Window state change
75-
syswmevent = C.SDL_SYSWMEVENT
74+
windowevent = C.SDL_WINDOWEVENT // 0x200 Window state change
75+
syswmevent = C.SDL_SYSWMEVENT
7676
// Keyboard events
77-
keydown = C.SDL_KEYDOWN // 0x300, Key pressed
78-
keyup = C.SDL_KEYUP // Key released
79-
textediting = C.SDL_TEXTEDITING // Keyboard text editing (composition)
80-
textinput = C.SDL_TEXTINPUT // Keyboard text input
81-
keymapchanged = C.SDL_KEYMAPCHANGED // Keymap changed due to a system event such as an input language or keyboard layout change.
82-
textediting_ext = C.SDL_TEXTEDITING_EXT // Extended keyboard text editing (composition)
77+
keydown = C.SDL_KEYDOWN // 0x300, Key pressed
78+
keyup = C.SDL_KEYUP // Key released
79+
textediting = C.SDL_TEXTEDITING // Keyboard text editing (composition)
80+
textinput = C.SDL_TEXTINPUT // Keyboard text input
81+
keymapchanged = C.SDL_KEYMAPCHANGED // Keymap changed due to a system event such as an input language or keyboard layout change.
82+
textediting_ext = C.SDL_TEXTEDITING_EXT // Extended keyboard text editing (composition)
8383
// Mouse events
84-
mousemotion = C.SDL_MOUSEMOTION // 0x400, Mouse moved
85-
mousebuttondown = C.SDL_MOUSEBUTTONDOWN // Mouse button pressed
86-
mousebuttonup = C.SDL_MOUSEBUTTONUP // Mouse button released
87-
mousewheel = C.SDL_MOUSEWHEEL // Mouse wheel motion
84+
mousemotion = C.SDL_MOUSEMOTION // 0x400, Mouse moved
85+
mousebuttondown = C.SDL_MOUSEBUTTONDOWN // Mouse button pressed
86+
mousebuttonup = C.SDL_MOUSEBUTTONUP // Mouse button released
87+
mousewheel = C.SDL_MOUSEWHEEL // Mouse wheel motion
8888
// Joystick events
89-
joyaxismotion = C.SDL_JOYAXISMOTION // 0x600, Joystick axis motion
90-
joyballmotion = C.SDL_JOYBALLMOTION // Joystick trackball motion
91-
joyhatmotion = C.SDL_JOYHATMOTION // Joystick hat position change
92-
joybuttondown = C.SDL_JOYBUTTONDOWN // Joystick button pressed
93-
joybuttonup = C.SDL_JOYBUTTONUP // Joystick button released
94-
joydeviceadded = C.SDL_JOYDEVICEADDED // A new joystick has been inserted into the system
95-
joydeviceremoved = C.SDL_JOYDEVICEREMOVED // An opened joystick has been removed
96-
joybatteryupdated = C.SDL_JOYBATTERYUPDATED // Joystick battery level change
89+
joyaxismotion = C.SDL_JOYAXISMOTION // 0x600, Joystick axis motion
90+
joyballmotion = C.SDL_JOYBALLMOTION // Joystick trackball motion
91+
joyhatmotion = C.SDL_JOYHATMOTION // Joystick hat position change
92+
joybuttondown = C.SDL_JOYBUTTONDOWN // Joystick button pressed
93+
joybuttonup = C.SDL_JOYBUTTONUP // Joystick button released
94+
joydeviceadded = C.SDL_JOYDEVICEADDED // A new joystick has been inserted into the system
95+
joydeviceremoved = C.SDL_JOYDEVICEREMOVED // An opened joystick has been removed
96+
joybatteryupdated = C.SDL_JOYBATTERYUPDATED // Joystick battery level change
9797
// Game controller events
98-
controlleraxismotion = C.SDL_CONTROLLERAXISMOTION // 0x650, Game controller axis motion
99-
controllerbuttondown = C.SDL_CONTROLLERBUTTONDOWN // Game controller button pressed
100-
controllerbuttonup = C.SDL_CONTROLLERBUTTONUP // Game controller button released
101-
controllerdeviceadded = C.SDL_CONTROLLERDEVICEADDED // A new Game controller has been inserted into the system
102-
controllerdeviceremoved = C.SDL_CONTROLLERDEVICEREMOVED // An opened Game controller has been removed
103-
controllerdeviceremapped = C.SDL_CONTROLLERDEVICEREMAPPED // The controller mapping was updated
104-
controllertouchpaddown = C.SDL_CONTROLLERTOUCHPADDOWN // Game controller touchpad was touched
105-
controllertouchpadmotion = C.SDL_CONTROLLERTOUCHPADMOTION // Game controller touchpad finger was moved
106-
controllertouchpadup = C.SDL_CONTROLLERTOUCHPADUP // Game controller touchpad finger was lifted
107-
controllersensorupdate = C.SDL_CONTROLLERSENSORUPDATE // Game controller sensor was updated
98+
controlleraxismotion = C.SDL_CONTROLLERAXISMOTION // 0x650, Game controller axis motion
99+
controllerbuttondown = C.SDL_CONTROLLERBUTTONDOWN // Game controller button pressed
100+
controllerbuttonup = C.SDL_CONTROLLERBUTTONUP // Game controller button released
101+
controllerdeviceadded = C.SDL_CONTROLLERDEVICEADDED // A new Game controller has been inserted into the system
102+
controllerdeviceremoved = C.SDL_CONTROLLERDEVICEREMOVED // An opened Game controller has been removed
103+
controllerdeviceremapped = C.SDL_CONTROLLERDEVICEREMAPPED // The controller mapping was updated
104+
controllertouchpaddown = C.SDL_CONTROLLERTOUCHPADDOWN // Game controller touchpad was touched
105+
controllertouchpadmotion = C.SDL_CONTROLLERTOUCHPADMOTION // Game controller touchpad finger was moved
106+
controllertouchpadup = C.SDL_CONTROLLERTOUCHPADUP // Game controller touchpad finger was lifted
107+
controllersensorupdate = C.SDL_CONTROLLERSENSORUPDATE // Game controller sensor was updated
108+
controllerupdatecomplete_reserved_for_sdl3 = C.SDL_CONTROLLERUPDATECOMPLETE_RESERVED_FOR_SDL3
109+
controllersteamhandleupdated = C.SDL_CONTROLLERSTEAMHANDLEUPDATED // Game controller Steam handle has changed
108110
// Touch events
109-
fingerdown = C.SDL_FINGERDOWN // 0x700
110-
fingerup = C.SDL_FINGERUP
111-
fingermotion = C.SDL_FINGERMOTION
111+
fingerdown = C.SDL_FINGERDOWN // 0x700
112+
fingerup = C.SDL_FINGERUP
113+
fingermotion = C.SDL_FINGERMOTION
112114
// Gesture events
113-
dollargesture = C.SDL_DOLLARGESTURE // 0x800
114-
dollarrecord = C.SDL_DOLLARRECORD
115-
multigesture = C.SDL_MULTIGESTURE
115+
dollargesture = C.SDL_DOLLARGESTURE // 0x800
116+
dollarrecord = C.SDL_DOLLARRECORD
117+
multigesture = C.SDL_MULTIGESTURE
116118
// Clipboard events
117-
clipboardupdate = C.SDL_CLIPBOARDUPDATE // 0x900 The clipboard or primary selection changed
119+
clipboardupdate = C.SDL_CLIPBOARDUPDATE // 0x900 The clipboard or primary selection changed
118120
// Drag and drop events
119-
dropfile = C.SDL_DROPFILE // 0x1000 The system requests a file open
120-
droptext = C.SDL_DROPTEXT // text/plain drag-and-drop event
121-
dropbegin = C.SDL_DROPBEGIN // A new set of drops is beginning (NULL filename)
122-
dropcomplete = C.SDL_DROPCOMPLETE // Current set of drops is now complete (NULL filename)
121+
dropfile = C.SDL_DROPFILE // 0x1000 The system requests a file open
122+
droptext = C.SDL_DROPTEXT // text/plain drag-and-drop event
123+
dropbegin = C.SDL_DROPBEGIN // A new set of drops is beginning (NULL filename)
124+
dropcomplete = C.SDL_DROPCOMPLETE // Current set of drops is now complete (NULL filename)
123125
// Audio hotplug events
124-
audiodeviceadded = C.SDL_AUDIODEVICEADDED // 0x1100 A new audio device is available
125-
audiodeviceremoved = C.SDL_AUDIODEVICEREMOVED // An audio device has been removed.
126+
audiodeviceadded = C.SDL_AUDIODEVICEADDED // 0x1100 A new audio device is available
127+
audiodeviceremoved = C.SDL_AUDIODEVICEREMOVED // An audio device has been removed.
126128
// Sensor events
127-
sensorupdate = C.SDL_SENSORUPDATE // 0x1200 A sensor was updated
129+
sensorupdate = C.SDL_SENSORUPDATE // 0x1200 A sensor was updated
128130
// Render events
129-
render_targets_reset = C.SDL_RENDER_TARGETS_RESET // 0x2000 The render targets have been reset and their contents need to be updated
130-
render_device_reset = C.SDL_RENDER_DEVICE_RESET // The device has been reset and all textures need to be recreated
131+
render_targets_reset = C.SDL_RENDER_TARGETS_RESET // 0x2000 The render targets have been reset and their contents need to be updated
132+
render_device_reset = C.SDL_RENDER_DEVICE_RESET // The device has been reset and all textures need to be recreated
131133
// Internal events
132-
pollsentinel = C.SDL_POLLSENTINEL // 0x7F00, Signals the end of an event poll cycle
134+
pollsentinel = C.SDL_POLLSENTINEL // 0x7F00, Signals the end of an event poll cycle
133135
// Events ::SDL_USEREVENT through ::SDL_LASTEVENT are for your use, and should be allocated with SDL_RegisterEvents()
134-
userevent = C.SDL_USEREVENT
136+
userevent = C.SDL_USEREVENT
135137
// This last event is only for bounding internal arrays
136-
lastevent = C.SDL_LASTEVENT // 0xFFFF
138+
lastevent = C.SDL_LASTEVENT // 0xFFFF
137139
}
138140

139141
// CommonEvent is fields shared by every event
@@ -416,7 +418,7 @@ pub type ControllerButtonEvent = C.SDL_ControllerButtonEvent
416418
@[typedef]
417419
pub struct C.SDL_ControllerDeviceEvent {
418420
pub:
419-
@type EventType // ::SDL_CONTROLLERDEVICEADDED, ::SDL_CONTROLLERDEVICEREMOVED, or ::SDL_CONTROLLERDEVICEREMAPPED
421+
@type EventType // ::SDL_CONTROLLERDEVICEADDED, ::SDL_CONTROLLERDEVICEREMOVED, ::SDL_CONTROLLERDEVICEREMAPPED, or ::SDL_CONTROLLERSTEAMHANDLEUPDATED
420422
timestamp u32 // In milliseconds, populated using SDL_GetTicks()
421423
which int // The joystick device index for the ADDED event, instance id for the REMOVED or REMAPPED event
422424
}
@@ -557,16 +559,6 @@ pub:
557559

558560
pub type QuitEvent = C.SDL_QuitEvent
559561

560-
// OSEvent is an OS Specific event
561-
@[typedef]
562-
pub struct C.SDL_OSEvent {
563-
pub:
564-
@type EventType // ::SDL_QUIT
565-
timestamp u32 // In milliseconds, populated using SDL_GetTicks()
566-
}
567-
568-
pub type OSEvent = C.SDL_OSEvent
569-
570562
// UserEvent is an user-defined event type (event.user.*)
571563
@[typedef]
572564
pub struct C.SDL_UserEvent {

filesystem.c.v

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ fn C.SDL_GetBasePath() &char
3535
// directory of the application as it is uncommon to store resources outside
3636
// the executable. As such it is not a writable directory.
3737
//
38-
// The returned path is guaranteed to end with a path separator ('\' on
38+
// The returned path is guaranteed to end with a path separator ('\\' on
3939
// Windows, '/' on most other platforms).
4040
//
4141
// The pointer returned is owned by the caller. Please call SDL_free() on the
@@ -93,7 +93,7 @@ fn C.SDL_GetPrefPath(const_org &char, const_app &char) &char
9393
// - ...only use letters, numbers, and spaces. Avoid punctuation like "Game
9494
// Name 2: Bad Guy's Revenge!" ... "Game Name 2" is sufficient.
9595
//
96-
// The returned path is guaranteed to end with a path separator ('\' on
96+
// The returned path is guaranteed to end with a path separator ('\\' on
9797
// Windows, '/' on most other platforms).
9898
//
9999
// The pointer returned is owned by the caller. Please call SDL_free() on the

gamecontroller.c.v

+26-3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ pub enum GameControllerType {
3939
nintendo_switch_joycon_left = C.SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_JOYCON_LEFT
4040
nintendo_switch_joycon_right = C.SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_JOYCON_RIGHT
4141
nintendo_switch_joycon_pair = C.SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_JOYCON_PAIR
42+
max = C.SDL_CONTROLLER_TYPE_MAX
4243
}
4344

4445
// GameControllerBindType is C.SDL_GameControllerBindType
@@ -544,6 +545,21 @@ pub fn game_controller_get_serial(gamecontroller &GameController) &char {
544545
return C.SDL_GameControllerGetSerial(gamecontroller)
545546
}
546547

548+
fn C.SDL_GameControllerGetSteamHandle(gamecontroller &GameController) u64
549+
550+
// Get the Steam Input handle of an opened controller, if available.
551+
//
552+
// Returns an InputHandle_t for the controller that can be used with Steam Input API:
553+
// https://partner.steamgames.com/doc/api/ISteamInput
554+
//
555+
// `gamecontroller` the game controller object to query.
556+
// returns the gamepad handle, or 0 if unavailable.
557+
//
558+
// NOTE This function is available since SDL 2.30.0.
559+
pub fn game_controller_get_steam_handle(gamecontroller &GameController) u64 {
560+
return C.SDL_GameControllerGetSteamHandle(gamecontroller)
561+
}
562+
547563
fn C.SDL_GameControllerGetAttached(gamecontroller &C.SDL_GameController) bool
548564

549565
// game_controller_get_attached checks if a controller has been opened and is currently connected.
@@ -625,7 +641,9 @@ pub fn game_controller_update() {
625641
// and are centered within ~8000 of zero, though advanced UI will allow users to set
626642
// or autodetect the dead zone, which varies between controllers.
627643
//
628-
// Trigger axis values range from 0 to SDL_JOYSTICK_AXIS_MAX.
644+
// Trigger axis values range from 0 (released) to SDL_JOYSTICK_AXIS_MAX
645+
// (fully pressed) when reported by SDL_GameControllerGetAxis(). Note that this is not the
646+
// same range that will be reported by the lower-level SDL_GetJoystickAxis().
629647
//
630648
// GameControllerAxis is C.SDL_GameControllerAxis
631649
pub enum GameControllerAxis {
@@ -720,8 +738,13 @@ fn C.SDL_GameControllerGetAxis(gamecontroller &C.SDL_GameController, axis C.SDL_
720738
//
721739
// The axis indices start at index 0.
722740
//
723-
// The state is a value ranging from -32768 to 32767. Triggers, however, range
724-
// from 0 to 32767 (they never return a negative value).
741+
// For thumbsticks, the state is a value ranging from -32768 (up/left)
742+
// to 32767 (down/right).
743+
//
744+
// Triggers range from 0 when released to 32767 when fully pressed, and
745+
// never return a negative value. Note that this differs from the value
746+
// reported by the lower-level SDL_GetJoystickAxis(), which normally uses
747+
// the full range.
725748
//
726749
// `gamecontroller` a game controller
727750
// `axis` an axis index (one of the SDL_GameControllerAxis values)

0 commit comments

Comments
 (0)