Skip to content

Commit 2aa71b2

Browse files
committed
at least it compiles now
1 parent 9fdc692 commit 2aa71b2

File tree

9 files changed

+57
-759
lines changed

9 files changed

+57
-759
lines changed

changelog.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ when upgrading from a version of sdl3 to another.
55

66
## v0.1.0 - SDL3 Migration
77

8-
- The barest rewrite to support libSDL3. Almost certainly broken in many ways but an attempt to jump-start SDL3 support in Rust.
8+
Full documentation on changes in SDL3: https://github.com/libsdl-org/SDL/blob/main/docs/README-migration.md
9+
10+
- The barest rewrite to support SDL3. Almost certainly broken in many ways but an attempt to jump-start SDL3 support in Rust.
911
- The Gamecontroller subsystem was renamed to Gamepad.
1012
- Most coordinates for rectangles and points now use f32 instead of u32.
1113
- New distinctions between screen and pixel size for scaled displays.

examples/animation.rs

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1-
extern crate sdl2;
1+
extern crate sdl3;
22
use std::path::Path;
33

4-
use sdl2::event::Event;
5-
use sdl2::keyboard::Keycode;
6-
use sdl2::rect::Point;
7-
use sdl2::rect::Rect;
4+
use sdl3::event::Event;
5+
use sdl3::keyboard::Keycode;
6+
use sdl3::rect::Point;
7+
use sdl3::rect::Rect;
8+
use sdl3::render::FPoint;
9+
use sdl3::render::FRect;
810
use std::time::Duration;
911

1012
fn main() -> Result<(), String> {
11-
let sdl_context = sdl2::init()?;
13+
let sdl_context = sdl3::init()?;
1214
let video_subsystem = sdl_context.video()?;
1315

1416
let window = video_subsystem
15-
.window("SDL2", 640, 480)
17+
.window("sdl3", 640, 480)
1618
.position_centered()
1719
.build()
1820
.map_err(|e| e.to_string())?;
@@ -24,36 +26,36 @@ fn main() -> Result<(), String> {
2426
.map_err(|e| e.to_string())?;
2527
let texture_creator = canvas.texture_creator();
2628

27-
canvas.set_draw_color(sdl2::pixels::Color::RGBA(0, 0, 0, 255));
29+
canvas.set_draw_color(sdl3::pixels::Color::RGBA(0, 0, 0, 255));
2830

2931
let timer = sdl_context.timer()?;
3032

3133
let mut event_pump = sdl_context.event_pump()?;
3234

3335
// animation sheet and extras are available from
3436
// https://opengameart.org/content/a-platformer-in-the-forest
35-
let temp_surface = sdl2::surface::Surface::load_bmp(Path::new("assets/characters.bmp"))?;
37+
let temp_surface = sdl3::surface::Surface::load_bmp(Path::new("assets/characters.bmp"))?;
3638
let texture = texture_creator
3739
.create_texture_from_surface(&temp_surface)
3840
.map_err(|e| e.to_string())?;
3941

4042
let frames_per_anim = 4;
41-
let sprite_tile_size = (32, 32);
43+
let sprite_tile_size = (32., 32.);
4244

4345
// Baby - walk animation
44-
let mut source_rect_0 = Rect::new(0, 0, sprite_tile_size.0, sprite_tile_size.0);
45-
let mut dest_rect_0 = Rect::new(0, 0, sprite_tile_size.0 * 4, sprite_tile_size.0 * 4);
46-
dest_rect_0.center_on(Point::new(-64, 120));
46+
let mut source_rect_0 = FRect::new(0., 0., sprite_tile_size.0, sprite_tile_size.0);
47+
let mut dest_rect_0 = FRect::new(0., 0., sprite_tile_size.0 * 4., sprite_tile_size.0 * 4.);
48+
// dest_rect_0.center_on(FPoint::new(-64., 120.));
4749

4850
// King - walk animation
49-
let mut source_rect_1 = Rect::new(0, 32, sprite_tile_size.0, sprite_tile_size.0);
50-
let mut dest_rect_1 = Rect::new(0, 32, sprite_tile_size.0 * 4, sprite_tile_size.0 * 4);
51-
dest_rect_1.center_on(Point::new(0, 240));
51+
let mut source_rect_1 = FRect::new(0., 32., sprite_tile_size.0, sprite_tile_size.0);
52+
let mut dest_rect_1 = FRect::new(0., 32., sprite_tile_size.0 * 4., sprite_tile_size.0 * 4.);
53+
// dest_rect_1.center_on(FPoint::new(0., 240.));
5254

5355
// Soldier - walk animation
54-
let mut source_rect_2 = Rect::new(0, 64, sprite_tile_size.0, sprite_tile_size.0);
55-
let mut dest_rect_2 = Rect::new(0, 64, sprite_tile_size.0 * 4, sprite_tile_size.0 * 4);
56-
dest_rect_2.center_on(Point::new(440, 360));
56+
let mut source_rect_2 = FRect::new(0., 64., sprite_tile_size.0, sprite_tile_size.0);
57+
let mut dest_rect_2 = FRect::new(0., 64., sprite_tile_size.0 * 4., sprite_tile_size.0 * 4.);
58+
// dest_rect_2.center_on(Point::new(440, 360));
5759

5860
let mut running = true;
5961
while running {

examples/game-controller.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
extern crate sdl2;
1+
extern crate sdl3;
22

33
fn main() -> Result<(), String> {
44
// This is required for certain controllers to work on Windows without the
55
// video subsystem enabled:
6-
sdl2::hint::set("SDL_JOYSTICK_THREAD", "1");
6+
sdl3::hint::set("SDL_JOYSTICK_THREAD", "1");
77

88
let sdl_context = sdl2::init()?;
99
let game_controller_subsystem = sdl_context.game_controller()?;
@@ -44,8 +44,8 @@ fn main() -> Result<(), String> {
4444
let (mut lo_freq, mut hi_freq) = (0, 0);
4545

4646
for event in sdl_context.event_pump()?.wait_iter() {
47-
use sdl2::controller::Axis;
48-
use sdl2::event::Event;
47+
use sdl3::controller::Axis;
48+
use sdl3::event::Event;
4949

5050
match event {
5151
Event::ControllerAxisMotion {

src/sdl3/audio.rs

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -229,35 +229,35 @@ impl AudioSubsystem {
229229
#[derive(Copy, Clone, Eq, PartialEq, Debug, Hash)]
230230
pub enum AudioFormat {
231231
/// Unsigned 8-bit samples
232-
U8 = sys::AUDIO_U8 as i32,
232+
U8 = sys::SDL_AUDIO_U8 as i32,
233233
/// Signed 8-bit samples
234-
S8 = sys::AUDIO_S8 as i32,
234+
S8 = sys::SDL_AUDIO_S8 as i32,
235235
/// Signed 16-bit samples, little-endian
236-
S16LSB = sys::AUDIO_S16LSB as i32,
236+
S16LSB = sys::SDL_AUDIO_S16LSB as i32,
237237
/// Signed 16-bit samples, big-endian
238-
S16MSB = sys::AUDIO_S16MSB as i32,
238+
S16MSB = sys::SDL_AUDIO_S16MSB as i32,
239239
/// Signed 32-bit samples, little-endian
240-
S32LSB = sys::AUDIO_S32LSB as i32,
240+
S32LSB = sys::SDL_AUDIO_S32LSB as i32,
241241
/// Signed 32-bit samples, big-endian
242-
S32MSB = sys::AUDIO_S32MSB as i32,
242+
S32MSB = sys::SDL_AUDIO_S32MSB as i32,
243243
/// 32-bit floating point samples, little-endian
244-
F32LSB = sys::AUDIO_F32LSB as i32,
244+
F32LSB = sys::SDL_AUDIO_F32LSB as i32,
245245
/// 32-bit floating point samples, big-endian
246-
F32MSB = sys::AUDIO_F32MSB as i32,
246+
F32MSB = sys::SDL_AUDIO_F32MSB as i32,
247247
}
248248

249249
impl AudioFormat {
250250
fn from_ll(raw: sys::SDL_AudioFormat) -> Option<AudioFormat> {
251251
use self::AudioFormat::*;
252252
match raw as u32 {
253-
sys::AUDIO_U8 => Some(U8),
254-
sys::AUDIO_S8 => Some(S8),
255-
sys::AUDIO_S16LSB => Some(S16LSB),
256-
sys::AUDIO_S16MSB => Some(S16MSB),
257-
sys::AUDIO_S32LSB => Some(S32LSB),
258-
sys::AUDIO_S32MSB => Some(S32MSB),
259-
sys::AUDIO_F32LSB => Some(F32LSB),
260-
sys::AUDIO_F32MSB => Some(F32MSB),
253+
sys::SDL_AUDIO_U8 => Some(U8),
254+
sys::SDL_AUDIO_S8 => Some(S8),
255+
sys::SDL_AUDIO_S16LSB => Some(S16LSB),
256+
sys::SDL_AUDIO_S16MSB => Some(S16MSB),
257+
sys::SDL_AUDIO_S32LSB => Some(S32LSB),
258+
sys::SDL_AUDIO_S32MSB => Some(S32MSB),
259+
sys::SDL_AUDIO_F32LSB => Some(F32LSB),
260+
sys::SDL_AUDIO_F32MSB => Some(F32MSB),
261261
_ => None,
262262
}
263263
}
@@ -289,11 +289,6 @@ impl AudioFormat {
289289

290290
#[cfg(target_endian = "big")]
291291
impl AudioFormat {
292-
/// Unsigned 16-bit samples, native endian
293-
#[inline]
294-
pub const fn u16_sys() -> AudioFormat {
295-
AudioFormat::U16MSB
296-
}
297292
/// Signed 16-bit samples, native endian
298293
#[inline]
299294
pub const fn s16_sys() -> AudioFormat {

0 commit comments

Comments
 (0)