Upgrade to lastes Piston and made it compile with Rust 1.0.0
This commit is contained in:
commit
3bae715c93
7 changed files with 413 additions and 55 deletions
329
Cargo.lock
generated
Normal file
329
Cargo.lock
generated
Normal file
|
|
@ -0,0 +1,329 @@
|
||||||
|
[root]
|
||||||
|
name = "rust-2048"
|
||||||
|
version = "0.0.0"
|
||||||
|
dependencies = [
|
||||||
|
"piston 0.1.1 (git+https://github.com/pistondevelopers/piston)",
|
||||||
|
"piston2d-graphics 0.0.46 (git+https://github.com/pistondevelopers/graphics)",
|
||||||
|
"piston2d-opengl_graphics 0.0.16 (git+https://github.com/pistondevelopers/opengl_graphics)",
|
||||||
|
"pistoncore-sdl2_window 0.0.13 (git+https://github.com/pistondevelopers/sdl2_window)",
|
||||||
|
"rand 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"rustc-serialize 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bitflags"
|
||||||
|
version = "0.1.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "byteorder"
|
||||||
|
version = "0.3.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "clock_ticks"
|
||||||
|
version = "0.0.5"
|
||||||
|
source = "git+https://github.com/tomaka/clock_ticks#462848731d99ed2f800e2e5a19e2d8ca3b11c90c"
|
||||||
|
dependencies = [
|
||||||
|
"libc 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "draw_state"
|
||||||
|
version = "0.0.7"
|
||||||
|
source = "git+https://github.com/gfx-rs/draw_state#44a0aed11abccbf970fc7efbe84b6482f0548248"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "enum_primitive"
|
||||||
|
version = "0.0.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"num 0.1.24 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "freetype-rs"
|
||||||
|
version = "0.0.9"
|
||||||
|
source = "git+https://github.com/PistonDevelopers/freetype-rs.git#686a4d7ff99eddfc64fbe7d2c3a19832ee564614"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"freetype-sys 0.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"libc 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "freetype-sys"
|
||||||
|
version = "0.0.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"libc 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"libz-sys 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"pkg-config 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "gl"
|
||||||
|
version = "0.0.12"
|
||||||
|
source = "git+https://github.com/bjz/gl-rs#62b66a85e4c2c0d88fb916040bc462702c8e0346"
|
||||||
|
dependencies = [
|
||||||
|
"gl_common 0.0.4 (git+https://github.com/bjz/gl-rs)",
|
||||||
|
"gl_generator 0.0.25 (git+https://github.com/bjz/gl-rs)",
|
||||||
|
"khronos_api 0.0.5 (git+https://github.com/bjz/gl-rs)",
|
||||||
|
"libc 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "gl_common"
|
||||||
|
version = "0.0.4"
|
||||||
|
source = "git+https://github.com/bjz/gl-rs#62b66a85e4c2c0d88fb916040bc462702c8e0346"
|
||||||
|
dependencies = [
|
||||||
|
"libc 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "gl_generator"
|
||||||
|
version = "0.0.25"
|
||||||
|
source = "git+https://github.com/bjz/gl-rs#62b66a85e4c2c0d88fb916040bc462702c8e0346"
|
||||||
|
dependencies = [
|
||||||
|
"khronos_api 0.0.5 (git+https://github.com/bjz/gl-rs)",
|
||||||
|
"log 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"xml-rs 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "image"
|
||||||
|
version = "0.3.9"
|
||||||
|
source = "git+https://github.com/pistondevelopers/image#75f9b791d6b030bc975ec737e9a2d78de39331af"
|
||||||
|
dependencies = [
|
||||||
|
"byteorder 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"enum_primitive 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"num 0.1.24 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "interpolation"
|
||||||
|
version = "0.0.5"
|
||||||
|
source = "git+https://github.com/PistonDevelopers/interpolation#c0c9e970e42a48402514285a5608e4729cf83298"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "khronos_api"
|
||||||
|
version = "0.0.5"
|
||||||
|
source = "git+https://github.com/bjz/gl-rs#62b66a85e4c2c0d88fb916040bc462702c8e0346"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "khronos_api"
|
||||||
|
version = "0.0.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libc"
|
||||||
|
version = "0.1.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libz-sys"
|
||||||
|
version = "0.1.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"libc 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"pkg-config 0.3.4 (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.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num"
|
||||||
|
version = "0.1.24"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"rand 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"rustc-serialize 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "piston"
|
||||||
|
version = "0.1.1"
|
||||||
|
source = "git+https://github.com/pistondevelopers/piston#e4b588cf22275acb230a4d6baace2567ea66391a"
|
||||||
|
dependencies = [
|
||||||
|
"pistoncore-event 0.1.3 (git+https://github.com/pistondevelopers/event)",
|
||||||
|
"pistoncore-input 0.0.9 (git+https://github.com/pistondevelopers/input)",
|
||||||
|
"pistoncore-window 0.1.2 (git+https://github.com/pistondevelopers/window)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "piston-float"
|
||||||
|
version = "0.0.1"
|
||||||
|
source = "git+https://github.com/pistondevelopers/float#2c73a3e34c384c79e95b35c069d5a69dda3a0cc4"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "piston-shaders_graphics2d"
|
||||||
|
version = "0.0.0"
|
||||||
|
source = "git+https://github.com/pistondevelopers/shaders#a2cbd6c63b5cb6852f2bef9e28e04301bca96efe"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "piston-texture"
|
||||||
|
version = "0.0.1"
|
||||||
|
source = "git+https://github.com/pistondevelopers/texture#3cc4cddc3f8c51c36ea11dd2f63d70aa887f53fb"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "piston-viewport"
|
||||||
|
version = "0.0.2"
|
||||||
|
source = "git+https://github.com/pistondevelopers/viewport#3819edeb0982d2552669e03ad9c0317e75340510"
|
||||||
|
dependencies = [
|
||||||
|
"piston-float 0.0.1 (git+https://github.com/pistondevelopers/float)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "piston2d-graphics"
|
||||||
|
version = "0.0.46"
|
||||||
|
source = "git+https://github.com/pistondevelopers/graphics#e5885956fd49bafa968f85976b153b341a473389"
|
||||||
|
dependencies = [
|
||||||
|
"draw_state 0.0.7 (git+https://github.com/gfx-rs/draw_state)",
|
||||||
|
"interpolation 0.0.5 (git+https://github.com/PistonDevelopers/interpolation)",
|
||||||
|
"piston-texture 0.0.1 (git+https://github.com/pistondevelopers/texture)",
|
||||||
|
"piston-viewport 0.0.2 (git+https://github.com/pistondevelopers/viewport)",
|
||||||
|
"read_color 0.0.2 (git+https://github.com/PistonDevelopers/read_color)",
|
||||||
|
"vecmath 0.0.22 (git+https://github.com/PistonDevelopers/vecmath)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "piston2d-opengl_graphics"
|
||||||
|
version = "0.0.16"
|
||||||
|
source = "git+https://github.com/pistondevelopers/opengl_graphics#c5d22694c53d58290b9e58e3411053d39250da89"
|
||||||
|
dependencies = [
|
||||||
|
"freetype-rs 0.0.9 (git+https://github.com/PistonDevelopers/freetype-rs.git)",
|
||||||
|
"gl 0.0.12 (git+https://github.com/bjz/gl-rs)",
|
||||||
|
"image 0.3.9 (git+https://github.com/pistondevelopers/image)",
|
||||||
|
"khronos_api 0.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"libc 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"piston-shaders_graphics2d 0.0.0 (git+https://github.com/pistondevelopers/shaders)",
|
||||||
|
"piston-texture 0.0.1 (git+https://github.com/pistondevelopers/texture)",
|
||||||
|
"piston2d-graphics 0.0.46 (git+https://github.com/pistondevelopers/graphics)",
|
||||||
|
"shader_version 0.0.6 (git+https://github.com/pistondevelopers/shader_version)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pistoncore-event"
|
||||||
|
version = "0.1.3"
|
||||||
|
source = "git+https://github.com/pistondevelopers/event#c51e721f4b346fe7cc8a4c0e2658a70d257202ce"
|
||||||
|
dependencies = [
|
||||||
|
"pistoncore-event_loop 0.1.5 (git+https://github.com/PistonDevelopers/event_loop)",
|
||||||
|
"pistoncore-input 0.0.9 (git+https://github.com/pistondevelopers/input)",
|
||||||
|
"pistoncore-window 0.1.2 (git+https://github.com/pistondevelopers/window)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pistoncore-event_loop"
|
||||||
|
version = "0.1.5"
|
||||||
|
source = "git+https://github.com/PistonDevelopers/event_loop#d7541e44e33016b0584579e800879120cf982639"
|
||||||
|
dependencies = [
|
||||||
|
"clock_ticks 0.0.5 (git+https://github.com/tomaka/clock_ticks)",
|
||||||
|
"piston-viewport 0.0.2 (git+https://github.com/pistondevelopers/viewport)",
|
||||||
|
"pistoncore-window 0.1.2 (git+https://github.com/pistondevelopers/window)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pistoncore-input"
|
||||||
|
version = "0.0.9"
|
||||||
|
source = "git+https://github.com/pistondevelopers/input#cb0615041f0dd1e4cd1cfc6d4e0e4bae0a575a8e"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"num 0.1.24 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"rustc-serialize 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pistoncore-sdl2_window"
|
||||||
|
version = "0.0.13"
|
||||||
|
source = "git+https://github.com/pistondevelopers/sdl2_window#d9dd95cadd5c8de09ddb163812761738b999b3f4"
|
||||||
|
dependencies = [
|
||||||
|
"gl 0.0.12 (git+https://github.com/bjz/gl-rs)",
|
||||||
|
"num 0.1.24 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"piston 0.1.1 (git+https://github.com/pistondevelopers/piston)",
|
||||||
|
"sdl2 0.2.3 (git+https://github.com/AngryLawyer/rust-sdl2)",
|
||||||
|
"shader_version 0.0.6 (git+https://github.com/pistondevelopers/shader_version)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pistoncore-window"
|
||||||
|
version = "0.1.2"
|
||||||
|
source = "git+https://github.com/pistondevelopers/window#73314c130ce0b8fc22e47fc636a4724b6e02a365"
|
||||||
|
dependencies = [
|
||||||
|
"libc 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"pistoncore-input 0.0.9 (git+https://github.com/pistondevelopers/input)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pkg-config"
|
||||||
|
version = "0.3.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand"
|
||||||
|
version = "0.3.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"libc 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "read_color"
|
||||||
|
version = "0.0.2"
|
||||||
|
source = "git+https://github.com/PistonDevelopers/read_color#568723fb7d9a69833e1d5a5ec79ded8ce9562920"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rustc-serialize"
|
||||||
|
version = "0.3.14"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "sdl2"
|
||||||
|
version = "0.2.3"
|
||||||
|
source = "git+https://github.com/AngryLawyer/rust-sdl2#f270e9879cd91324a3adc7c0367971e7cda27b9c"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"libc 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"num 0.1.24 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"rand 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"sdl2-sys 0.2.2 (git+https://github.com/AngryLawyer/rust-sdl2)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "sdl2-sys"
|
||||||
|
version = "0.2.2"
|
||||||
|
source = "git+https://github.com/AngryLawyer/rust-sdl2#f270e9879cd91324a3adc7c0367971e7cda27b9c"
|
||||||
|
dependencies = [
|
||||||
|
"libc 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"num 0.1.24 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "shader_version"
|
||||||
|
version = "0.0.6"
|
||||||
|
source = "git+https://github.com/pistondevelopers/shader_version#14aa73be33b6d23d6b3cb27f94426545372df287"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "vecmath"
|
||||||
|
version = "0.0.22"
|
||||||
|
source = "git+https://github.com/PistonDevelopers/vecmath#d6bb5cf609b51cae8f296945e179bd42a74c9a51"
|
||||||
|
dependencies = [
|
||||||
|
"piston-float 0.0.1 (git+https://github.com/pistondevelopers/float)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "xml-rs"
|
||||||
|
version = "0.1.25"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
@ -100,7 +100,7 @@ impl<'a> App<'a> {
|
||||||
let w_bg_col = self.window_background_color;
|
let w_bg_col = self.window_background_color;
|
||||||
let ref nr = self.number_renderer;
|
let ref nr = self.number_renderer;
|
||||||
|
|
||||||
gl.draw([0,0,args.width as i32, args.height as i32], |_, gl| {
|
gl.draw(args.viewport(), |_, gl| {
|
||||||
clear(w_bg_col, gl);
|
clear(w_bg_col, gl);
|
||||||
self.render_ui(c, gl);
|
self.render_ui(c, gl);
|
||||||
self.board.render(nr.iter().next().unwrap(), c, gl);
|
self.board.render(nr.iter().next().unwrap(), c, gl);
|
||||||
|
|
|
||||||
42
src/board.rs
42
src/board.rs
|
|
@ -1,10 +1,10 @@
|
||||||
|
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::iter::range_step_inclusive;
|
// use std::iter::range_step_inclusive;
|
||||||
use rand::random;
|
use rand::random;
|
||||||
use graphics::*;
|
use graphics::*;
|
||||||
use opengl_graphics::{
|
use opengl_graphics::{
|
||||||
Gl,
|
GlGraphics,
|
||||||
};
|
};
|
||||||
use number_renderer::NumberRenderer;
|
use number_renderer::NumberRenderer;
|
||||||
use settings::Settings;
|
use settings::Settings;
|
||||||
|
|
@ -18,7 +18,6 @@ fn rgb2rgba(c: [f32; 3]) -> [f32; 4] { [c[0], c[1], c[2], 1.0] }
|
||||||
pub struct Board<'a> {
|
pub struct Board<'a> {
|
||||||
tiles: Vec<Tile<'a>>,
|
tiles: Vec<Tile<'a>>,
|
||||||
score: i32,
|
score: i32,
|
||||||
|
|
||||||
settings: &'a Settings,
|
settings: &'a Settings,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -88,13 +87,16 @@ impl<'a> Board<'a> {
|
||||||
tiles.push(self.tiles[i].clone());
|
tiles.push(self.tiles[i].clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tiles.append(&mut tiles_need_added);
|
// better but unstable: tiles.append(&mut tiles_need_added);
|
||||||
|
while let Some(tile_to_add) = tiles_need_added.pop() {
|
||||||
|
tiles.push(tile_to_add);
|
||||||
|
}
|
||||||
self.tiles = tiles;
|
self.tiles = tiles;
|
||||||
self.add_score(score_to_added);
|
self.add_score(score_to_added);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn render(&self, number_renderer: &NumberRenderer, c: &Context, gl: &mut Gl) {
|
pub fn render(&self, number_renderer: &NumberRenderer, c: &Context, gl: &mut GlGraphics) {
|
||||||
number_renderer.render(
|
number_renderer.render(
|
||||||
self.score as u32,
|
self.score as u32,
|
||||||
self.settings.best_rect[0] + self.settings.best_rect[2] / 2.0,
|
self.settings.best_rect[0] + self.settings.best_rect[2] / 2.0,
|
||||||
|
|
@ -118,14 +120,22 @@ impl<'a> Board<'a> {
|
||||||
|
|
||||||
fn merge_col(&mut self, y_start: i32, y_end: i32, y_step: i32) {
|
fn merge_col(&mut self, y_start: i32, y_end: i32, y_step: i32) {
|
||||||
if self.is_locking() {
|
if self.is_locking() {
|
||||||
|
println!("return");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut need_generate = false;
|
let mut need_generate = false;
|
||||||
|
let mut steps: Vec<i32> = Vec::with_capacity(self.settings.tile_height as usize);
|
||||||
|
let mut next_step = y_start;
|
||||||
|
if y_step < 0 {
|
||||||
|
while next_step > y_end { steps.push(next_step); next_step += y_step }
|
||||||
|
} else {
|
||||||
|
while next_step < y_end { steps.push(next_step); next_step += y_step }
|
||||||
|
};
|
||||||
loop {
|
loop {
|
||||||
// move all tiles to right place
|
// move all tiles to right place
|
||||||
for col in 0 .. self.settings.tile_width {
|
for col in 0 .. self.settings.tile_width {
|
||||||
for row in range_step_inclusive(y_start, y_end, y_step) {
|
// TODO: replace steps by (y_start .. y_end).step_by(y_step) if step_by becomes stable
|
||||||
|
for row in steps.to_vec() {
|
||||||
match self.get_mut_tile(col, row) {
|
match self.get_mut_tile(col, row) {
|
||||||
None => {
|
None => {
|
||||||
match self.get_mut_next_tile(col, row, 0, y_step) {
|
match self.get_mut_next_tile(col, row, 0, y_step) {
|
||||||
|
|
@ -150,7 +160,7 @@ impl<'a> Board<'a> {
|
||||||
let mut sy = 0;
|
let mut sy = 0;
|
||||||
let mut dx = 0;
|
let mut dx = 0;
|
||||||
let mut dy = 0;
|
let mut dy = 0;
|
||||||
for row in range_step_inclusive(y_start, y_end, y_step) {
|
for row in steps.to_vec() {
|
||||||
match self.get_tile(col, row) {
|
match self.get_tile(col, row) {
|
||||||
Some(ref d_tile) => {
|
Some(ref d_tile) => {
|
||||||
match self.get_next_tile(col, row, 0, y_step) {
|
match self.get_next_tile(col, row, 0, y_step) {
|
||||||
|
|
@ -206,10 +216,18 @@ impl<'a> Board<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut need_generate = false;
|
let mut need_generate = false;
|
||||||
|
let mut steps: Vec<i32> = Vec::with_capacity(self.settings.tile_width as usize);
|
||||||
|
let mut next_step = x_start;
|
||||||
|
if x_step < 0 {
|
||||||
|
while next_step > x_end { steps.push(next_step); next_step += x_step }
|
||||||
|
} else {
|
||||||
|
while next_step < x_end { steps.push(next_step); next_step += x_step }
|
||||||
|
};
|
||||||
loop {
|
loop {
|
||||||
// move all tiles to right place
|
// move all tiles to right place
|
||||||
for row in 0..self.settings.tile_height {
|
for row in 0..self.settings.tile_height {
|
||||||
for col in range_step_inclusive(x_start, x_end, x_step) {
|
for col in steps.to_vec() {
|
||||||
|
|
||||||
match self.get_mut_tile(col, row) {
|
match self.get_mut_tile(col, row) {
|
||||||
None => {
|
None => {
|
||||||
match self.get_mut_next_tile(col, row, x_step, 0) {
|
match self.get_mut_next_tile(col, row, x_step, 0) {
|
||||||
|
|
@ -234,7 +252,7 @@ impl<'a> Board<'a> {
|
||||||
let mut sy = 0;
|
let mut sy = 0;
|
||||||
let mut dx = 0;
|
let mut dx = 0;
|
||||||
let mut dy = 0;
|
let mut dy = 0;
|
||||||
for col in range_step_inclusive(x_start, x_end, x_step) {
|
for col in steps.to_vec() {
|
||||||
match self.get_tile(col, row) {
|
match self.get_tile(col, row) {
|
||||||
Some(ref d_tile) => {
|
Some(ref d_tile) => {
|
||||||
match self.get_next_tile(col, row, x_step, 0) {
|
match self.get_next_tile(col, row, x_step, 0) {
|
||||||
|
|
@ -350,7 +368,7 @@ impl<'a> Board<'a> {
|
||||||
count
|
count
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_board(&self, c: &Context, gl: &mut Gl) {
|
fn render_board(&self, c: &Context, gl: &mut GlGraphics) {
|
||||||
Rectangle::new(rgb2rgba(self.settings.label_color))
|
Rectangle::new(rgb2rgba(self.settings.label_color))
|
||||||
.draw([self.settings.board_padding,
|
.draw([self.settings.board_padding,
|
||||||
self.settings.board_padding + self.settings.board_offset_y,
|
self.settings.board_padding + self.settings.board_offset_y,
|
||||||
|
|
@ -377,7 +395,7 @@ impl<'a> Board<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_tiles(&self, number_renderer: &NumberRenderer, c: &Context, gl: &mut Gl) {
|
fn render_tiles(&self, number_renderer: &NumberRenderer, c: &Context, gl: &mut GlGraphics) {
|
||||||
for tile in self.tiles.iter() {
|
for tile in self.tiles.iter() {
|
||||||
tile.render(number_renderer, c, gl);
|
tile.render(number_renderer, c, gl);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,3 @@
|
||||||
|
|
||||||
#![feature(core,collections,path_ext)]
|
|
||||||
|
|
||||||
extern crate rustc_serialize;
|
extern crate rustc_serialize;
|
||||||
extern crate rand;
|
extern crate rand;
|
||||||
|
|
||||||
|
|
@ -45,15 +42,15 @@ fn main() {
|
||||||
|
|
||||||
for e in window.events() {
|
for e in window.events() {
|
||||||
use piston::event::{ RenderEvent, PressEvent };
|
use piston::event::{ RenderEvent, PressEvent };
|
||||||
|
|
||||||
if let Some(ref args) = e.render_args() {
|
if let Some(ref args) = e.render_args() {
|
||||||
app.render(args, &mut gl);
|
app.render(args, &mut gl);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(ref args) = e.update_args() {
|
if let Some(ref args) = e.update_args() {
|
||||||
|
// TODO: only update if necessary
|
||||||
|
// println!("update");
|
||||||
app.update(args);
|
app.update(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(ref args) = e.press_args() {
|
if let Some(ref args) = e.press_args() {
|
||||||
app.key_press(args);
|
app.key_press(args);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use graphics::*;
|
use graphics::*;
|
||||||
use opengl_graphics::{
|
use opengl_graphics::{
|
||||||
Gl,
|
GlGraphics,
|
||||||
Texture,
|
Texture,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -21,7 +21,7 @@ impl NumberRenderer {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn render(&self, number: u32, center_x: f64, center_y: f64, max_width: f64,
|
pub fn render(&self, number: u32, center_x: f64, center_y: f64, max_width: f64,
|
||||||
color: [f32; 3], c: &Context, gl: &mut Gl) {
|
color: [f32; 3], c: &Context, gl: &mut GlGraphics) {
|
||||||
let digits = number_to_digits(number);
|
let digits = number_to_digits(number);
|
||||||
let total_width = DIGITS_WIDTH * digits.len() as f64;
|
let total_width = DIGITS_WIDTH * digits.len() as f64;
|
||||||
let total_width = if total_width > max_width {
|
let total_width = if total_width > max_width {
|
||||||
|
|
@ -36,7 +36,7 @@ impl NumberRenderer {
|
||||||
|
|
||||||
for digit in digits.iter() {
|
for digit in digits.iter() {
|
||||||
Image::new_colored([color[0], color[1], color[2], 1.0])
|
Image::new_colored([color[0], color[1], color[2], 1.0])
|
||||||
.src_rect([(*digit * DIGITS_WIDTH as u32) as i32, 0, (*digit * DIGITS_WIDTH as u32) as i32 + DIGITS_WIDTH as i32, DIGITS_HEIGHT as i32])
|
.src_rect([(*digit * DIGITS_WIDTH as u32) as i32, 0, DIGITS_WIDTH as i32, DIGITS_HEIGHT as i32])
|
||||||
.rect([x, y, width, height])
|
.rect([x, y, width, height])
|
||||||
.draw(&self.image,
|
.draw(&self.image,
|
||||||
default_draw_state(),
|
default_draw_state(),
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
use std::env::current_exe;
|
use std::env::current_exe;
|
||||||
use std::io::{BufWriter, BufReader, Write};
|
use std::io::{BufWriter, BufReader, Write};
|
||||||
use std::fs::{File,PathExt};
|
use std::fs::{File};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use rustc_serialize::{
|
use rustc_serialize::{
|
||||||
json,
|
json,
|
||||||
|
|
@ -219,7 +219,8 @@ impl SettingsInJson {
|
||||||
let mut exe_path = exe_path.unwrap();
|
let mut exe_path = exe_path.unwrap();
|
||||||
exe_path.pop();
|
exe_path.pop();
|
||||||
let path = exe_path.join(Path::new(SETTING_FILENAME));
|
let path = exe_path.join(Path::new(SETTING_FILENAME));
|
||||||
if !path.as_path().exists() || !path.is_file() {
|
// FIXME: use this if possible (.exists() is unstable in Rust 1.0.0)
|
||||||
|
/* if !path.as_path().exists() || !path.is_file() {
|
||||||
println!("Configuration file not found. Generating a default one.");
|
println!("Configuration file not found. Generating a default one.");
|
||||||
let default = SettingsInJson::default_settings();
|
let default = SettingsInJson::default_settings();
|
||||||
default.save();
|
default.save();
|
||||||
|
|
@ -227,6 +228,19 @@ impl SettingsInJson {
|
||||||
}
|
}
|
||||||
let file = File::open(&path).unwrap();
|
let file = File::open(&path).unwrap();
|
||||||
let mut reader = BufReader::new(file);
|
let mut reader = BufReader::new(file);
|
||||||
|
*/
|
||||||
|
let file = File::open(&path);
|
||||||
|
match file {
|
||||||
|
Err(e) => {
|
||||||
|
println!("Configuration file can't be open ({}). Try to generate a default one.", e);
|
||||||
|
let default = SettingsInJson::default_settings();
|
||||||
|
default.save();
|
||||||
|
return default;
|
||||||
|
},
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
let mut reader = BufReader::new(file.unwrap());
|
||||||
|
// End FIXME
|
||||||
let mut decoder = json::Decoder::new(json::Json::from_reader(&mut reader).unwrap());
|
let mut decoder = json::Decoder::new(json::Json::from_reader(&mut reader).unwrap());
|
||||||
Decodable::decode(&mut decoder).unwrap()
|
Decodable::decode(&mut decoder).unwrap()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
|
|
||||||
use graphics::*;
|
use graphics::*;
|
||||||
use opengl_graphics::Gl;
|
use opengl_graphics::GlGraphics;
|
||||||
use number_renderer::NumberRenderer;
|
use number_renderer::NumberRenderer;
|
||||||
use settings::Settings;
|
use settings::Settings;
|
||||||
|
|
||||||
|
|
@ -103,7 +103,7 @@ impl<'a> Tile<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn render(&self, number_renderer: &NumberRenderer, c: &Context, gl: &mut Gl) {
|
pub fn render(&self, number_renderer: &NumberRenderer, c: &Context, gl: &mut GlGraphics) {
|
||||||
let mut pos = self.tile_to_pos(self.tile_x, self.tile_y);
|
let mut pos = self.tile_to_pos(self.tile_x, self.tile_y);
|
||||||
let mut size = (self.settings.tile_size, self.settings.tile_size);
|
let mut size = (self.settings.tile_size, self.settings.tile_size);
|
||||||
match self.status {
|
match self.status {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue