Skip to content

Commit b00e889

Browse files
committed
Introducing bindgen
1 parent 5623630 commit b00e889

File tree

165 files changed

+37923
-4873
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

165 files changed

+37923
-4873
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ optional = true
3535

3636
[features]
3737

38-
default = []
38+
default = ["use-pkgconfig"]
3939
ttf = []
4040
image = []
4141
gfx = ["c_vec"]
4242
mixer = []
4343

44-
use-pkgconfig = [ "sdl2-sys/use-pkgconfig" ]
44+
use-pkgconfig = ["sdl2-sys/use-pkgconfig"]
4545
use_mac_framework = ["sdl2-sys/use_mac_framework"]

clippy.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
too-many-arguments-threshold = 10

examples/audio-queue-squarewave.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ use std::time::Duration;
66

77
fn gen_wave(bytes_to_write: i32) -> Vec<i16> {
88
// Generate a square wave
9-
let tone_volume = 1000i16;
10-
let period = 48000 / 256;
9+
let tone_volume = 1_000i16;
10+
let period = 48_000 / 256;
1111
let sample_count = bytes_to_write;
1212
let mut result = Vec::new();
13-
13+
1414
for x in 0..sample_count {
1515
result.push(
1616
if (x / period) % 2 == 0 {
@@ -29,23 +29,23 @@ fn main() {
2929
let audio_subsystem = sdl_context.audio().unwrap();
3030

3131
let desired_spec = AudioSpecDesired {
32-
freq: Some(48000),
32+
freq: Some(48_000),
3333
channels: Some(2),
3434
// mono -
35-
samples: Some(4)
36-
// default sample size
35+
samples: Some(4)
36+
// default sample size
3737
};
3838

3939
let device = audio_subsystem.open_queue::<i16, _>(None, &desired_spec).unwrap();
4040

41-
let target_bytes = 48000 * 4;
41+
let target_bytes = 48_000 * 4;
4242
let wave = gen_wave(target_bytes);
4343
device.queue(&wave);
44-
// Start playback
44+
// Start playback
4545
device.resume();
4646

47-
// Play for 2 seconds
48-
std::thread::sleep(Duration::from_millis(2000));
47+
// Play for 2 seconds
48+
std::thread::sleep(Duration::from_millis(2_000));
4949

50-
// Device is automatically closed when dropped
50+
// Device is automatically closed when dropped
5151
}

examples/audio-squarewave.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@ impl AudioCallback for SquareWave {
1515
fn callback(&mut self, out: &mut [f32]) {
1616
// Generate a square wave
1717
for x in out.iter_mut() {
18-
*x = match self.phase {
19-
0.0...0.5 => self.volume,
20-
_ => -self.volume
21-
};
18+
*x = if self.phase <= 0.5 { self.volume } else { -self.volume };
2219
self.phase = (self.phase + self.phase_inc) % 1.0;
2320
}
2421
}
@@ -29,7 +26,7 @@ fn main() {
2926
let audio_subsystem = sdl_context.audio().unwrap();
3027

3128
let desired_spec = AudioSpecDesired {
32-
freq: Some(44100),
29+
freq: Some(44_100),
3330
channels: Some(1), // mono
3431
samples: None // default sample size
3532
};
@@ -50,7 +47,7 @@ fn main() {
5047
device.resume();
5148

5249
// Play for 2 seconds
53-
std::thread::sleep(Duration::from_millis(2000));
50+
std::thread::sleep(Duration::from_millis(2_000));
5451

5552
// Device is automatically closed when dropped
5653
}

examples/audio-wav.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::time::Duration;
55
use std::borrow::Cow;
66
use std::path::{PathBuf, Path};
77

8-
// NOTE: You probably want to investigate the
8+
// NOTE: You probably want to investigate the
99
// mixer feature for real use cases.
1010

1111
struct Sound {
@@ -34,7 +34,7 @@ fn main() {
3434
let audio_subsystem = sdl_context.audio().unwrap();
3535

3636
let desired_spec = AudioSpecDesired {
37-
freq: Some(44100),
37+
freq: Some(44_100),
3838
channels: Some(1), // mono
3939
samples: None // default
4040
};
@@ -62,7 +62,7 @@ fn main() {
6262
device.resume();
6363

6464
// Play for a second
65-
std::thread::sleep(Duration::from_millis(1000));
65+
std::thread::sleep(Duration::from_millis(1_000));
6666

6767
// Device is automatically closed when dropped
6868
}

examples/audio-whitenoise.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fn main() {
2626
let audio_subsystem = sdl_context.audio().unwrap();
2727

2828
let desired_spec = AudioSpecDesired {
29-
freq: Some(44100),
29+
freq: Some(44_100),
3030
channels: Some(1), // mono
3131
samples: None, // default sample size
3232
};
@@ -43,7 +43,7 @@ fn main() {
4343
device.resume();
4444

4545
// Play for 1 second
46-
std::thread::sleep(Duration::from_millis(1000));
46+
std::thread::sleep(Duration::from_millis(1_000));
4747

4848
{
4949
// Acquire a lock. This lets us read and modify callback data.
@@ -53,7 +53,7 @@ fn main() {
5353
}
5454

5555
// Play for another second
56-
std::thread::sleep(Duration::from_millis(1000));
56+
std::thread::sleep(Duration::from_millis(1_000));
5757

5858
// Device is automatically closed when dropped
5959
}

examples/game-controller.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ fn main() {
5252
// Axis motion is an absolute value in the range
5353
// [-32768, 32767]. Let's simulate a very rough dead
5454
// zone to ignore spurious events.
55-
let dead_zone = 10000;
55+
let dead_zone = 10_000;
5656
if val > dead_zone || val < -dead_zone {
5757
println!("Axis {:?} moved to {}", axis, val);
5858
}

examples/game-of-life.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ mod game_of_life {
7676

7777
pub fn update(&mut self) {
7878
let mut new_playground = self.playground;
79-
for (u, mut square) in new_playground.iter_mut().enumerate() {
79+
for (u, square) in new_playground.iter_mut().enumerate() {
8080
let u = u as u32;
8181
let x = u % PLAYGROUND_WIDTH;
8282
let y = u / PLAYGROUND_WIDTH;
@@ -191,7 +191,7 @@ fn dummy_texture<'a>(canvas: &mut Canvas<Window>, texture_creator: &'a TextureCr
191191
pub fn main() {
192192
let sdl_context = sdl2::init().unwrap();
193193
let video_subsystem = sdl_context.video().unwrap();
194-
194+
195195
// the window is the representation of a window in your operating system,
196196
// however you can only manipulate properties of that window, like its size, whether it's
197197
// fullscreen, ... but you cannot change its content without using a Canvas or using the
@@ -244,7 +244,7 @@ pub fn main() {
244244
let x = (x as u32) / SQUARE_SIZE;
245245
let y = (y as u32) / SQUARE_SIZE;
246246
match game.get_mut(x as i32, y as i32) {
247-
Some(mut square) => {*square = !(*square);},
247+
Some(square) => {*square = !(*square);},
248248
None => {panic!()}
249249
};
250250
},
@@ -268,7 +268,7 @@ pub fn main() {
268268
&square_texture2
269269
};
270270
if *unit {
271-
canvas.copy(&square_texture,
271+
canvas.copy(square_texture,
272272
None,
273273
Rect::new(((i % PLAYGROUND_WIDTH) * SQUARE_SIZE) as i32,
274274
((i / PLAYGROUND_WIDTH) * SQUARE_SIZE) as i32,

examples/haptic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ fn main() {
4444
// Axis motion is an absolute value in the range
4545
// [-32768, 32767]. Let's simulate a very rough dead
4646
// zone to ignore spurious events.
47-
let dead_zone = 10000;
47+
let dead_zone = 10_000;
4848
if val > dead_zone || val < -dead_zone {
4949
println!("Axis {} moved to {}", axis_idx, val);
5050
}

examples/joystick.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ fn main() {
3939
// Axis motion is an absolute value in the range
4040
// [-32768, 32767]. Let's simulate a very rough dead
4141
// zone to ignore spurious events.
42-
let dead_zone = 10000;
42+
let dead_zone = 10_000;
4343
if val > dead_zone || val < -dead_zone {
4444
println!("Axis {} moved to {}", axis_idx, val);
4545
}

0 commit comments

Comments
 (0)