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"
version = "0.0.1"
dependencies = [
"sdl2 0.0.20 (git+https://github.com/AngryLawyer/rust-sdl2)",
"sdl2_image 0.0.1-alpha.1 (git+https://github.com/fgeldenhuys/rust-sdl2_image)",
"sdl2 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"sdl2_image 0.0.33 (git+https://github.com/logaritmisk/rust-sdl2_image.git)",
]
[[package]]
name = "bitflags"
version = "0.1.0"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "pkg-config"
version = "0.1.7"
name = "libc"
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"
[[package]]
name = "sdl2"
version = "0.0.20"
source = "git+https://github.com/AngryLawyer/rust-sdl2#8dc3659d5ac413f046785bcbae23ab8479e0ea22"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bitflags 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"sdl2-sys 0.0.20 (git+https://github.com/AngryLawyer/rust-sdl2)",
"bitflags 0.1.1 (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)",
"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]]
name = "sdl2-sys"
version = "0.0.20"
source = "git+https://github.com/AngryLawyer/rust-sdl2#8dc3659d5ac413f046785bcbae23ab8479e0ea22"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
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]]
name = "sdl2_image"
version = "0.0.1-alpha.1"
source = "git+https://github.com/fgeldenhuys/rust-sdl2_image#21bf12fed5d6f6a8ae49fbd20637921f97d17fe6"
version = "0.0.33"
source = "git+https://github.com/logaritmisk/rust-sdl2_image.git#404ccefedd74862d01e7462ea3fe696caa9f1e9f"
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"
authors = ["logaritmisk <anders.e.olsson@gmail.com>"]
[dependencies.sdl2]
git = "https://github.com/AngryLawyer/rust-sdl2"
[dependencies]
sdl2 = "0.1.0"
[dependencies.sdl2_image]
git = "https://github.com/fgeldenhuys/rust-sdl2_image"
git = "https://github.com/logaritmisk/rust-sdl2_image"
[[bin]]
name = "super-matte-bros"

View File

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