Get SDL2 and SDL2 Image to work together.

New event pump logic.
This commit is contained in:
2015-04-08 16:52:00 +02:00
parent 02e8dfec78
commit d14951e53a
3 changed files with 73 additions and 31 deletions

67
Cargo.lock generated
View File

@@ -2,42 +2,79 @@
name = "super-matte-bros" name = "super-matte-bros"
version = "0.0.1" version = "0.0.1"
dependencies = [ dependencies = [
"sdl2 0.0.20 (git+https://github.com/AngryLawyer/rust-sdl2)", "sdl2 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"sdl2_image 0.0.1-alpha.1 (git+https://github.com/fgeldenhuys/rust-sdl2_image)", "sdl2_image 0.0.33 (git+https://github.com/logaritmisk/rust-sdl2_image.git)",
] ]
[[package]] [[package]]
name = "bitflags" name = "bitflags"
version = "0.1.0" version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "pkg-config" name = "libc"
version = "0.1.7" version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "log"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "num"
version = "0.1.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"rand 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.12 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rand"
version = "0.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rustc-serialize"
version = "0.3.12"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "sdl2" name = "sdl2"
version = "0.0.20" version = "0.1.0"
source = "git+https://github.com/AngryLawyer/rust-sdl2#8dc3659d5ac413f046785bcbae23ab8479e0ea22" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"bitflags 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"sdl2-sys 0.0.20 (git+https://github.com/AngryLawyer/rust-sdl2)", "libc 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"num 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
"sdl2-sys 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]] [[package]]
name = "sdl2-sys" name = "sdl2-sys"
version = "0.0.20" version = "0.1.0"
source = "git+https://github.com/AngryLawyer/rust-sdl2#8dc3659d5ac413f046785bcbae23ab8479e0ea22" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"pkg-config 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"num 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]] [[package]]
name = "sdl2_image" name = "sdl2_image"
version = "0.0.1-alpha.1" version = "0.0.33"
source = "git+https://github.com/fgeldenhuys/rust-sdl2_image#21bf12fed5d6f6a8ae49fbd20637921f97d17fe6" source = "git+https://github.com/logaritmisk/rust-sdl2_image.git#404ccefedd74862d01e7462ea3fe696caa9f1e9f"
dependencies = [ dependencies = [
"sdl2 0.0.20 (git+https://github.com/AngryLawyer/rust-sdl2)", "bitflags 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"sdl2 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"sdl2-sys 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
] ]

View File

@@ -3,11 +3,11 @@ name = "super-matte-bros"
version = "0.0.1" version = "0.0.1"
authors = ["logaritmisk <anders.e.olsson@gmail.com>"] authors = ["logaritmisk <anders.e.olsson@gmail.com>"]
[dependencies.sdl2] [dependencies]
git = "https://github.com/AngryLawyer/rust-sdl2" sdl2 = "0.1.0"
[dependencies.sdl2_image] [dependencies.sdl2_image]
git = "https://github.com/fgeldenhuys/rust-sdl2_image" git = "https://github.com/logaritmisk/rust-sdl2_image"
[[bin]] [[bin]]
name = "super-matte-bros" name = "super-matte-bros"

View File

@@ -5,7 +5,6 @@ extern crate sdl2_image;
use std::num::Float; use std::num::Float;
use sdl2::video::{Window, WindowPos, OPENGL}; use sdl2::video::{Window, WindowPos, OPENGL};
use sdl2::event::{poll_event, Event};
use sdl2::timer::{get_ticks, delay}; use sdl2::timer::{get_ticks, delay};
use sdl2::rect::Rect; use sdl2::rect::Rect;
use sdl2::keycode::KeyCode; use sdl2::keycode::KeyCode;
@@ -206,6 +205,8 @@ fn main() {
let mut previous : usize = get_ticks(); let mut previous : usize = get_ticks();
let mut lag : usize = 0; let mut lag : usize = 0;
let mut event_pump = sdl_context.event_pump();
'main : loop { 'main : loop {
current = get_ticks(); current = get_ticks();
elapsed = current - previous; elapsed = current - previous;
@@ -215,18 +216,22 @@ fn main() {
keyboard.clear(); keyboard.clear();
'event : loop { 'event : loop {
match poll_event() { for event in event_pump.poll_iter() {
Event::Quit(_) => break 'main, use sdl2::event::Event;
Event::KeyDown(_, _, key, _, _, repeat) => {
if repeat == false { match event {
keyboard.key_down(key); Event::Quit(_) => break 'main,
} Event::KeyDown(_, _, key, _, _, repeat) => {
}, if repeat == false {
Event::KeyUp(_, _, key, _, _, _) => { keyboard.key_down(key);
keyboard.key_up(key); }
}, },
Event::None => break 'event, Event::KeyUp(_, _, key, _, _, _) => {
_ => (), keyboard.key_up(key);
},
Event::None => break 'event,
_ => (),
}
} }
} }