@@ -1,17 +1,17 @@
#[derive(Clone, Debug)]
pub struct OrthographicHelper {
aspect_ratio: ::utils::Coord,
fov: ::utils::Coord,
znear: ::utils::Coord,
zfar: ::utils::Coord,
aspect_ratio: ::utils::GfxCoord,
fov: ::utils::GfxCoord,
znear: ::utils::GfxCoord,
zfar: ::utils::GfxCoord,
}

impl OrthographicHelper {
pub fn new(
aspect_ratio: ::utils::Coord,
fov: ::utils::Coord,
znear: ::utils::Coord,
zfar: ::utils::Coord
aspect_ratio: ::utils::GfxCoord,
fov: ::utils::GfxCoord,
znear: ::utils::GfxCoord,
zfar: ::utils::GfxCoord
) -> OrthographicHelper {
OrthographicHelper {
aspect_ratio: aspect_ratio,
@@ -21,31 +21,31 @@ impl OrthographicHelper {
}
}

pub fn set_aspect_ratio(&mut self, aspect_ratio: ::utils::Coord) {
pub fn set_aspect_ratio(&mut self, aspect_ratio: ::utils::GfxCoord) {
self.aspect_ratio = aspect_ratio;
}

pub fn get_aspect_ratio(&self) -> ::utils::Coord {
pub fn get_aspect_ratio(&self) -> ::utils::GfxCoord {
self.aspect_ratio
}

pub fn get_fov(&self) -> ::utils::Coord {
pub fn get_fov(&self) -> ::utils::GfxCoord {
self.fov
}

pub fn get_znear(&self) -> ::utils::Coord {
pub fn get_znear(&self) -> ::utils::GfxCoord {
self.znear
}

pub fn get_zfar(&self) -> ::utils::Coord {
pub fn get_zfar(&self) -> ::utils::GfxCoord {
self.zfar
}

pub fn get_view_depth(&self) -> ::utils::Coord {
pub fn get_view_depth(&self) -> ::utils::GfxCoord {
self.get_zfar() - self.get_znear()
}

pub fn build_matrix(&self) -> ::nalgebra::OrthographicMatrix3<::utils::Coord> {
pub fn build_matrix(&self) -> ::nalgebra::OrthographicMatrix3<::utils::GfxCoord> {
::nalgebra::OrthographicMatrix3::new_with_fov(self.get_aspect_ratio(), self.get_fov(), self.get_znear(), self.get_zfar())
}
}
@@ -51,7 +51,7 @@ impl System {
mouse_location: ::math::Point2,
screen_resolution: ::math::Point2,
ortho_helper: ::math::OrthographicHelper,
default_tint: [::utils::Coord; 4]
default_tint: [f32; 4]
) -> System
{
System {
@@ -177,7 +177,7 @@ impl ::specs::System<::utils::Delta> for System {
},
}
for &(width, height) in &self.resize {
self.ortho_helper.set_aspect_ratio(width as ::utils::Coord / height as ::utils::Coord);
self.ortho_helper.set_aspect_ratio(width as ::utils::GfxCoord / height as ::utils::GfxCoord);
c.set_proj(&self.ortho_helper);
self.screen_resolution = ::math::Point2::new(width as ::utils::Coord, height as ::utils::Coord);
}
@@ -14,8 +14,8 @@ impl ::specs::System<::utils::Delta> for System {
fn run(&mut self, arg: ::specs::RunArg, time: ::utils::Delta) {
use specs::Join;

let (physical, transform, clickable, mut dwarf, mut living) = arg.fetch(|w|
(w.read::<::comps::Physical>(), w.read::<::comps::Transform>(), w.read::<::comps::Clickable>(), w.write::<::comps::Dwarf>(), w.write::<::comps::Living>())
let (physical, transform, clickable, dwarf, mut living) = arg.fetch(|w|
(w.read::<::comps::Physical>(), w.read::<::comps::Transform>(), w.read::<::comps::Clickable>(), w.read::<::comps::Dwarf>(), w.write::<::comps::Living>())
);

let mut target_opt = None;
@@ -26,29 +26,16 @@ impl ::specs::System<::utils::Delta> for System {
}
}

for (mut d, mut l, t, p) in (&mut dwarf, &mut living, &transform, &physical).iter() {
for (d, mut l, t, p) in (&dwarf, &mut living, &transform, &physical).iter() {
if let Some(target) = target_opt.as_ref() {
*d.get_mut_target_tile_opt() = Some(target.clone() - t.get_pos()); //unwraps are ok because of this

if d.get_target_tile().unwrap().length() >= p.get_speed_break().length() {
let normal = {
let length = d.get_target_tile().unwrap().length();
if length < d.get_speed() * time {
l.walk_to(d.get_target_tile().unwrap().clone());
l.idle();
continue;
} else {
d.get_target_tile().unwrap().normalized() * d.get_speed()
}
};

if normal.is_finite() {
l.walk(normal);
} else {
debug!("non finite dwarf target tile: {}", normal);
}
} else {
let offset_from_target = target.clone() - t.get_pos();

if offset_from_target.length() < p.get_speed_break().length() {
l.idle();
} else if offset_from_target.length() < d.get_speed() * time {
l.walk_to(target.clone());
} else {
l.walk(offset_from_target.normalized() * d.get_speed());
}
} else {
l.idle();
@@ -21,18 +21,18 @@ impl ::specs::System<::utils::Delta> for System {
for (mut p, mut rd, mut l) in (&mut physical, &mut render_data, &mut living).iter() {
match l.get_state_pair() {
&(::comps::living::State::Idle, ::comps::living::StateData::Idle) => {

*p.get_mut_speed() = ::math::Point2::zero();
},
&(::comps::living::State::Walking, ::comps::living::StateData::Walking(ref dir)) => {
let mirror = dir.get_x().is_sign_positive();
if mirror != rd.get_mirror() {
if mirror != rd.get_mirror() && dir.get_x().abs() > 0.1 {
rd.set_mirror(mirror);
}
*p.get_mut_speed() = dir.clone();
},
&(::comps::living::State::Walking, ::comps::living::StateData::MoveTo(ref location)) => {
let mirror = location.get_x().is_sign_positive();
if mirror != rd.get_mirror() {
if mirror != rd.get_mirror() && location.get_x().abs() > 0.1 {
rd.set_mirror(mirror);
}
*p.get_mut_speed() = ::math::Point2::zero();
@@ -19,6 +19,11 @@ impl ::specs::System<::utils::Delta> for System {
);

for (mut t, mut p) in (&mut transform, &mut physical).iter() {
if let Some(move_to) = p.get_move_to() {
t.set_position(move_to);
continue;
}

if p.get_speed().is_zero() {
continue;
}
@@ -27,11 +32,6 @@ impl ::specs::System<::utils::Delta> for System {

*p.get_mut_speed() *= friction;

if let Some(move_to) = p.get_move_to() {
t.set_position(move_to);
continue;
}

let mut speed = p.get_speed();

if speed.length() < p.get_speed_break().length() {
@@ -4,8 +4,9 @@ extern crate env_logger;

pub mod fps_counter;

pub type Delta = f32;
pub type Coord = f32;
pub type Delta = f64;
pub type Coord = f64;
pub type GfxCoord = f32;

#[derive(Debug)]
pub enum Error {