Skip to content

Introducing bindgen #695

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Oct 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ image = []
gfx = ["c_vec"]
mixer = []

use-pkgconfig = [ "sdl2-sys/use-pkgconfig" ]
use-bindgen = ["sdl2-sys/use-bindgen"]
use-pkgconfig = ["sdl2-sys/use-pkgconfig"]
use_mac_framework = ["sdl2-sys/use_mac_framework"]

[[example]]
Expand Down
1 change: 1 addition & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
too-many-arguments-threshold = 10
22 changes: 11 additions & 11 deletions examples/audio-queue-squarewave.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ use std::time::Duration;

fn gen_wave(bytes_to_write: i32) -> Vec<i16> {
// Generate a square wave
let tone_volume = 1000i16;
let period = 48000 / 256;
let tone_volume = 1_000i16;
let period = 48_000 / 256;
let sample_count = bytes_to_write;
let mut result = Vec::new();

for x in 0..sample_count {
result.push(
if (x / period) % 2 == 0 {
Expand All @@ -29,23 +29,23 @@ fn main() {
let audio_subsystem = sdl_context.audio().unwrap();

let desired_spec = AudioSpecDesired {
freq: Some(48000),
freq: Some(48_000),
channels: Some(2),
// mono -
samples: Some(4)
// default sample size
samples: Some(4)
// default sample size
};

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

let target_bytes = 48000 * 4;
let target_bytes = 48_000 * 4;
let wave = gen_wave(target_bytes);
device.queue(&wave);
// Start playback
// Start playback
device.resume();

// Play for 2 seconds
std::thread::sleep(Duration::from_millis(2000));
// Play for 2 seconds
std::thread::sleep(Duration::from_millis(2_000));

// Device is automatically closed when dropped
// Device is automatically closed when dropped
}
6 changes: 3 additions & 3 deletions examples/audio-squarewave.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ impl AudioCallback for SquareWave {
fn callback(&mut self, out: &mut [f32]) {
// Generate a square wave
for x in out.iter_mut() {
*x = if self.phase < 0.5 { self.volume } else { -self.volume };
*x = if self.phase <= 0.5 { self.volume } else { -self.volume };
self.phase = (self.phase + self.phase_inc) % 1.0;
}
}
Expand All @@ -26,7 +26,7 @@ fn main() {
let audio_subsystem = sdl_context.audio().unwrap();

let desired_spec = AudioSpecDesired {
freq: Some(44100),
freq: Some(44_100),
channels: Some(1), // mono
samples: None // default sample size
};
Expand All @@ -47,7 +47,7 @@ fn main() {
device.resume();

// Play for 2 seconds
std::thread::sleep(Duration::from_millis(2000));
std::thread::sleep(Duration::from_millis(2_000));

// Device is automatically closed when dropped
}
6 changes: 3 additions & 3 deletions examples/audio-wav.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::time::Duration;
use std::borrow::Cow;
use std::path::{PathBuf, Path};

// NOTE: You probably want to investigate the
// NOTE: You probably want to investigate the
// mixer feature for real use cases.

struct Sound {
Expand Down Expand Up @@ -34,7 +34,7 @@ fn main() {
let audio_subsystem = sdl_context.audio().unwrap();

let desired_spec = AudioSpecDesired {
freq: Some(44100),
freq: Some(44_100),
channels: Some(1), // mono
samples: None // default
};
Expand Down Expand Up @@ -62,7 +62,7 @@ fn main() {
device.resume();

// Play for a second
std::thread::sleep(Duration::from_millis(1000));
std::thread::sleep(Duration::from_millis(1_000));

// Device is automatically closed when dropped
}
6 changes: 3 additions & 3 deletions examples/audio-whitenoise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn main() {
let audio_subsystem = sdl_context.audio().unwrap();

let desired_spec = AudioSpecDesired {
freq: Some(44100),
freq: Some(44_100),
channels: Some(1), // mono
samples: None, // default sample size
};
Expand All @@ -43,7 +43,7 @@ fn main() {
device.resume();

// Play for 1 second
std::thread::sleep(Duration::from_millis(1000));
std::thread::sleep(Duration::from_millis(1_000));

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

// Play for another second
std::thread::sleep(Duration::from_millis(1000));
std::thread::sleep(Duration::from_millis(1_000));

// Device is automatically closed when dropped
}
2 changes: 1 addition & 1 deletion examples/game-controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fn main() {
// Axis motion is an absolute value in the range
// [-32768, 32767]. Let's simulate a very rough dead
// zone to ignore spurious events.
let dead_zone = 10000;
let dead_zone = 10_000;
if val > dead_zone || val < -dead_zone {
println!("Axis {:?} moved to {}", axis, val);
}
Expand Down
4 changes: 2 additions & 2 deletions examples/game-of-life-unsafe-textures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ mod game_of_life {

pub fn update(&mut self) {
let mut new_playground = self.playground;
for (u, mut square) in new_playground.iter_mut().enumerate() {
for (u, square) in new_playground.iter_mut().enumerate() {
let u = u as u32;
let x = u % PLAYGROUND_WIDTH;
let y = u / PLAYGROUND_WIDTH;
Expand Down Expand Up @@ -252,7 +252,7 @@ pub fn main() {
let x = (x as u32) / SQUARE_SIZE;
let y = (y as u32) / SQUARE_SIZE;
match game.get_mut(x as i32, y as i32) {
Some(mut square) => {*square = !(*square);},
Some(square) => {*square = !(*square);},
None => {panic!()}
};
},
Expand Down
8 changes: 4 additions & 4 deletions examples/game-of-life.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ mod game_of_life {

pub fn update(&mut self) {
let mut new_playground = self.playground;
for (u, mut square) in new_playground.iter_mut().enumerate() {
for (u, square) in new_playground.iter_mut().enumerate() {
let u = u as u32;
let x = u % PLAYGROUND_WIDTH;
let y = u / PLAYGROUND_WIDTH;
Expand Down Expand Up @@ -191,7 +191,7 @@ fn dummy_texture<'a>(canvas: &mut Canvas<Window>, texture_creator: &'a TextureCr
pub fn main() {
let sdl_context = sdl2::init().unwrap();
let video_subsystem = sdl_context.video().unwrap();

// the window is the representation of a window in your operating system,
// however you can only manipulate properties of that window, like its size, whether it's
// fullscreen, ... but you cannot change its content without using a Canvas or using the
Expand Down Expand Up @@ -244,7 +244,7 @@ pub fn main() {
let x = (x as u32) / SQUARE_SIZE;
let y = (y as u32) / SQUARE_SIZE;
match game.get_mut(x as i32, y as i32) {
Some(mut square) => {*square = !(*square);},
Some(square) => {*square = !(*square);},
None => {panic!()}
};
},
Expand All @@ -268,7 +268,7 @@ pub fn main() {
&square_texture2
};
if *unit {
canvas.copy(&square_texture,
canvas.copy(square_texture,
None,
Rect::new(((i % PLAYGROUND_WIDTH) * SQUARE_SIZE) as i32,
((i / PLAYGROUND_WIDTH) * SQUARE_SIZE) as i32,
Expand Down
2 changes: 1 addition & 1 deletion examples/haptic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fn main() {
// Axis motion is an absolute value in the range
// [-32768, 32767]. Let's simulate a very rough dead
// zone to ignore spurious events.
let dead_zone = 10000;
let dead_zone = 10_000;
if val > dead_zone || val < -dead_zone {
println!("Axis {} moved to {}", axis_idx, val);
}
Expand Down
2 changes: 1 addition & 1 deletion examples/joystick.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fn main() {
// Axis motion is an absolute value in the range
// [-32768, 32767]. Let's simulate a very rough dead
// zone to ignore spurious events.
let dead_zone = 10000;
let dead_zone = 10_000;
if val > dead_zone || val < -dead_zone {
println!("Axis {} moved to {}", axis_idx, val);
}
Expand Down
18 changes: 9 additions & 9 deletions examples/mixer-demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ fn demo(music_file: &Path, sound_file: Option<&Path>) {
INIT_MODPLUG | INIT_OGG)
.unwrap();

let frequency = 44100;
let frequency = 44_100;
let format = AUDIO_S16LSB; // signed 16 bit samples, in little-endian byte order
let channels = DEFAULT_CHANNELS; // Stereo
let chunk_size = 1024;
let chunk_size = 1_024;
sdl2::mixer::open_audio(frequency, format, channels, chunk_size).unwrap();

// Number of mixing channels available for sound effect `Chunk`s to play
Expand Down Expand Up @@ -83,7 +83,7 @@ fn demo(music_file: &Path, sound_file: Option<&Path>) {
// This delay is needed because when the `Chunk` goes out of scope,
// the sound effect stops playing. Delay long enough to hear the
// sound.
timer.delay(5000);
timer.delay(5_000);

match play_res {
Ok(_) => println!("played sound"),
Expand All @@ -94,18 +94,18 @@ fn demo(music_file: &Path, sound_file: Option<&Path>) {
}
}

timer.delay(10000);
timer.delay(10_000);

println!("fading out ... {:?}", sdl2::mixer::Music::fade_out(4000));
println!("fading out ... {:?}", sdl2::mixer::Music::fade_out(4_000));

timer.delay(5000);
timer.delay(5_000);

println!("fading in from pos ... {:?}",
music.fade_in_from_pos(1, 10000, 100.0));
music.fade_in_from_pos(1, 10_000, 100.0));

timer.delay(5000);
timer.delay(5_000);
sdl2::mixer::Music::halt();
timer.delay(1000);
timer.delay(1_000);

println!("quitting sdl");
}
2 changes: 1 addition & 1 deletion examples/window-properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub fn main() {

{
// Update the window title.
let mut window = canvas.window_mut();
let window = canvas.window_mut();

let position = window.position();
let size = window.size();
Expand Down
9 changes: 5 additions & 4 deletions sdl2-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@ build = "build.rs"
name = "sdl2_sys"
path = "src/lib.rs"

[dependencies]
libc = "0.2"
[build-dependencies.bindgen]
version = "0.30"
optional = true

[build-dependencies.pkg-config]
version = "0.3"
version = "0.3.9"
optional = true

[features]

default = []
use-pkgconfig = ["pkg-config"]
no_std = []
use-bindgen = ["bindgen"]
use_mac_framework = []
Loading