Skip to content
This repository has been archived by the owner on Mar 26, 2024. It is now read-only.

Commit

Permalink
Apply review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
TrueDoctor committed Jan 2, 2021
1 parent c6ad61e commit f89bdab
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 45 deletions.
5 changes: 1 addition & 4 deletions rask-engine/src/engine/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ pub struct Animation {
}
#[derive(Debug, Clone, Component)]
#[storage(VecStorage)]
pub struct Scale {
pub scale_x: f32,
pub scale_y: f32,
}
pub struct Scale(pub Vec2);

#[derive(Debug, Clone, Component)]
#[storage(VecStorage)]
Expand Down
11 changes: 3 additions & 8 deletions rask-engine/src/engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,25 +65,20 @@ impl GameEngine for RaskEngine {
.with(Sprite {
id: registry::EMPTY.id,
})
.with(Scale {
scale_x: 1.0,
scale_y: 1.0,
})
.with(Scale(Vec2::new(1.0, 1.0)))
.with(Static)
.build();
let _char = world
.create_entity()
.with(Pos(Vec2::new(0.0, -0.8)))
.with(Vel(Vec2::new(0.0, 0.0)))
.with(Speed(0.2))
.with(Animation {
id: registry::CHAR.id,
animation: "walking".to_string(),
start: 0.0,
})
.with(Scale {
scale_x: 1.0,
scale_y: 1.0,
})
.with(Scale(Vec2::new(1.0, 1.0)))
.with(Static)
.build();
Self {
Expand Down
25 changes: 12 additions & 13 deletions rask-engine/src/engine/systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::EngineError;
use specs::prelude::*;

lazy_static::lazy_static! {
pub static ref KEYBOARD: Keyboard= Keyboard::new();
pub static ref KEYBOARD: Keyboard= Keyboard::new();
}

pub struct EventSystem;
Expand Down Expand Up @@ -66,7 +66,7 @@ impl<'a> System<'a> for UpdateAnimationSystem {
animation.animation.as_str(),
elapsed.0.as_secs_f32() - animation.start,
0.0,
0.2,
0.2, // fade time TODO make adjustable
)
.unwrap();
animation.start = elapsed.0.as_secs_f32();
Expand Down Expand Up @@ -95,8 +95,7 @@ impl<'a> System<'a> for RenderSystem {
let mut sprites = Vec::new();
for (pos, sprite, scale, _) in (&pos, &sprite, &scale, &present).join() {
sprites.push(resources::Sprite::new(
Mat3::translation(pos.0.x(), pos.0.y())
* Mat3::scaling(scale.scale_x, scale.scale_y),
Mat3::translation(pos.0.x(), pos.0.y()) * Mat3::scaling(scale.0.x(), scale.0.y()),
sprite.id,
0,
))
Expand All @@ -106,7 +105,7 @@ impl<'a> System<'a> for RenderSystem {
let cha: Result<&Box<resources::Character>, EngineError> = res.get(anim.id as usize);
if let Ok(cha) = cha {
let trans = Mat3::translation(pos.0.x(), pos.0.y());
let scale = Mat3::scaling(scale.scale_x, scale.scale_y);
let scale = Mat3::scaling(scale.0.x(), scale.0.y());

match cha.interpolate(elapsed.0.as_secs_f32() - anim.start) {
Ok(sps) => {
Expand Down Expand Up @@ -139,23 +138,23 @@ impl<'a> System<'a> for RenderSystem {
impl<'a> System<'a> for MovementSystem {
type SystemData = (
WriteStorage<'a, Animation>,
WriteStorage<'a, Pos>,
WriteStorage<'a, Vel>,
WriteStorage<'a, Scale>,
ReadStorage<'a, Speed>,
Read<'a, DeltaTime>,
);

fn run(&mut self, (mut anim, mut pos, mut scale, speed, delta_time): Self::SystemData) {
for (anim, pos, scale, speed) in (&mut anim, &mut pos, &mut scale, &speed).join() {
fn run(&mut self, (mut anim, mut vel, mut scale, speed): Self::SystemData) {
for (anim, vel, scale, speed) in (&mut anim, &mut vel, &mut scale, &speed).join() {
anim.animation = if KEYBOARD.get(Key::ARROW_RIGHT) {
scale.scale_x = 1.0;
pos.0 += Vec2::new(delta_time.0.as_secs_f32() * speed.0, 0.0);
scale.0 = Vec2::new(1.0, scale.0.y());
vel.0 = Vec2::new(speed.0, 0.0);
"walking".to_owned()
} else if KEYBOARD.get(Key::ARROW_LEFT) {
scale.scale_x = -1.0;
pos.0 -= Vec2::new(delta_time.0.as_secs_f32() * speed.0, 0.0);
scale.0 = Vec2::new(-1.0, scale.0.y());
vel.0 = Vec2::new(-speed.0, 0.0);
"walking".to_owned()
} else {
vel.0 = Vec2::new(0.0, 0.0);
"standing".to_owned()
};
}
Expand Down
40 changes: 20 additions & 20 deletions rask-engine/src/events.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
#![allow(clippy::unreadable_literal)]
//! this module contains The game input/output event definition
use std::collections::HashMap;
use std::sync::atomic::AtomicBool;
use std::sync::atomic::{AtomicBool, Ordering};

#[rustfmt::skip]
lazy_static::lazy_static! {
/// This is an example for using doc comment attributes
static ref MAPPING: HashMap<u32, u32> = [
(977763216, 0),(977535019, 1),(251549619, 2),(930625636, 3),(4247333604, 4),
(2823983839, 5),(2897055625, 6),(3915039450, 7),(12763084, 8),(3908895692, 9),
(759638320, 10),(2079612435, 11),(1564800910, 12),(83829, 13),(80085222, 14),
(67114680, 15),(3357475935, 16),(2691421945, 17),(3357357270, 18),(79966557, 19),
(2387108321, 20),(65290933, 21),(1289876625, 22),(78401116, 23),(1149837940, 24),
(1422382255, 25),(74348624, 26),(67204884, 27),(923631601, 28),(2383081898, 29),
(1318883673, 30),(2255103, 31),(69819, 32),(2195042009, 33),(2043376075, 34),
(2046924995, 35),(2046924996, 36),(2046924997, 37),(2046924998, 38),(2046924999, 39),
(2046925000, 40),(2046925001, 41),(2046925002, 42),(2046925003, 43),(2046925004, 44),
(2335202, 45),(2335203, 46),(2335204, 47),(2335205, 48),(2335206, 49),
(2335207, 50),(2335208, 51),(2335209, 52),(2335210, 53),(2335211, 54),
(2335212, 55),(2335213, 56),(2335214, 57),(2335215, 58),(2335216, 59),
(2335217, 60),(2335218, 61),(2335219, 62),(2335220, 63),(2335221, 64),
(2335222, 65),(2335223, 66),(2335224, 67),(2335225, 68),(2335226, 69),
(2335227, 70),(2219, 71),(2220, 72),(2221, 73),(2222, 74),
(2223, 75),(2224, 76),(2225, 77),(2226, 78),(2227, 79),
(68837, 80),(68838, 81),(68839, 82)].iter().copied().collect();
(977763216, 0), (977535019, 1), (251549619, 2), (930625636, 3), (4247333604, 4),
(2823983839, 5), (2897055625, 6), (3915039450, 7), (12763084, 8), (3908895692, 9),
(759638320, 10), (2079612435, 11), (1564800910, 12), (83829, 13), (80085222, 14),
(67114680, 15), (3357475935, 16), (2691421945, 17), (3357357270, 18), (79966557, 19),
(2387108321, 20), (65290933, 21), (1289876625, 22), (78401116, 23), (1149837940, 24),
(1422382255, 25), (74348624, 26), (67204884, 27), (923631601, 28), (2383081898, 29),
(1318883673, 30), (2255103, 31), (69819, 32), (2195042009, 33), (2043376075, 34),
(2046924995, 35), (2046924996, 36), (2046924997, 37), (2046924998, 38), (2046924999, 39),
(2046925000, 40), (2046925001, 41), (2046925002, 42), (2046925003, 43), (2046925004, 44),
(2335202, 45), (2335203, 46), (2335204, 47), (2335205, 48), (2335206, 49),
(2335207, 50), (2335208, 51), (2335209, 52), (2335210, 53), (2335211, 54),
(2335212, 55), (2335213, 56), (2335214, 57), (2335215, 58), (2335216, 59),
(2335217, 60), (2335218, 61), (2335219, 62), (2335220, 63), (2335221, 64),
(2335222, 65), (2335223, 66), (2335224, 67), (2335225, 68), (2335226, 69),
(2335227, 70), (2219, 71), (2220, 72), (2221, 73), (2222, 74),
(2223, 75), (2224, 76), (2225, 77), (2226, 78), (2227, 79),
(68837, 80), (68838, 81), (68839, 82)].iter().copied().collect();
}

#[derive(Debug, Clone, Copy, Eq, PartialEq)]
Expand Down Expand Up @@ -139,12 +139,12 @@ impl Keyboard {

pub fn set(&self, key: Key, value: bool) {
assert!((key.0 as usize) < self.0.len());
self.0[key.0 as usize].store(value, std::sync::atomic::Ordering::Relaxed);
self.0[key.0 as usize].store(value, Ordering::Relaxed);
}

pub fn get(&self, key: Key) -> bool {
assert!((key.0 as usize) < self.0.len());
self.0[key.0 as usize].load(std::sync::atomic::Ordering::Relaxed)
self.0[key.0 as usize].load(Ordering::Relaxed)
}
}

Expand Down

0 comments on commit f89bdab

Please sign in to comment.