2016-03-26 18:21:47 -04:00
|
|
|
|
|
|
|
pub mod player;
|
2016-04-04 17:08:24 -04:00
|
|
|
pub mod block_entity;
|
2016-03-26 18:21:47 -04:00
|
|
|
|
2018-11-04 14:48:03 -05:00
|
|
|
use crate::ecs;
|
2016-03-26 18:21:47 -04:00
|
|
|
use cgmath::Vector3;
|
|
|
|
use collision::Aabb3;
|
|
|
|
|
|
|
|
mod systems;
|
|
|
|
|
|
|
|
pub fn add_systems(m: &mut ecs::Manager) {
|
|
|
|
let sys = systems::UpdateLastPosition::new(m);
|
|
|
|
m.add_system(sys);
|
|
|
|
|
|
|
|
player::add_systems(m);
|
|
|
|
|
|
|
|
let sys = systems::ApplyVelocity::new(m);
|
|
|
|
m.add_system(sys);
|
|
|
|
let sys = systems::ApplyGravity::new(m);
|
|
|
|
m.add_system(sys);
|
2016-04-07 14:30:42 -04:00
|
|
|
let sys = systems::LerpPosition::new(m);
|
|
|
|
m.add_render_system(sys);
|
|
|
|
let sys = systems::LerpRotation::new(m);
|
|
|
|
m.add_render_system(sys);
|
2016-04-08 06:08:21 -04:00
|
|
|
let sys = systems::LightEntity::new(m);
|
|
|
|
m.add_render_system(sys);
|
2016-04-04 17:08:24 -04:00
|
|
|
|
|
|
|
block_entity::add_systems(m);
|
2016-03-26 18:21:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Location of an entity in the world.
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct Position {
|
|
|
|
pub position: Vector3<f64>,
|
|
|
|
pub last_position: Vector3<f64>,
|
2016-03-28 09:15:21 -04:00
|
|
|
pub moved: bool,
|
2016-03-26 18:21:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Position {
|
|
|
|
pub fn new(x: f64, y: f64, z: f64) -> Position {
|
|
|
|
Position {
|
|
|
|
position: Vector3::new(x, y, z),
|
|
|
|
last_position: Vector3::new(x, y, z),
|
2016-03-28 09:15:21 -04:00
|
|
|
moved: false,
|
2016-03-26 18:21:47 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn zero() -> Position {
|
|
|
|
Position::new(0.0, 0.0, 0.0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-07 14:30:42 -04:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct TargetPosition {
|
|
|
|
pub position: Vector3<f64>,
|
2016-04-08 20:11:33 -04:00
|
|
|
pub lerp_amount: f64,
|
2016-04-07 14:30:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
impl TargetPosition {
|
|
|
|
pub fn new(x: f64, y: f64, z: f64) -> TargetPosition {
|
|
|
|
TargetPosition {
|
|
|
|
position: Vector3::new(x, y, z),
|
2016-04-08 20:11:33 -04:00
|
|
|
lerp_amount: 0.2,
|
2016-04-07 14:30:42 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn zero() -> TargetPosition {
|
|
|
|
TargetPosition::new(0.0, 0.0, 0.0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-26 18:21:47 -04:00
|
|
|
/// Velocity of an entity in the world.
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct Velocity {
|
|
|
|
pub velocity: Vector3<f64>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Velocity {
|
|
|
|
pub fn new(x: f64, y: f64, z: f64) -> Velocity {
|
|
|
|
Velocity {
|
|
|
|
velocity: Vector3::new(x, y, z),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn zero() -> Velocity {
|
|
|
|
Velocity::new(0.0, 0.0, 0.0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Rotation of an entity in the world
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct Rotation {
|
|
|
|
pub yaw: f64,
|
|
|
|
pub pitch: f64,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Rotation {
|
|
|
|
pub fn new(yaw: f64, pitch: f64) -> Rotation {
|
|
|
|
Rotation {
|
2018-11-04 16:43:30 -05:00
|
|
|
yaw,
|
|
|
|
pitch,
|
2016-03-26 18:21:47 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn zero() -> Rotation {
|
|
|
|
Rotation::new(0.0, 0.0)
|
|
|
|
}
|
|
|
|
}
|
2016-04-07 14:30:42 -04:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct TargetRotation {
|
|
|
|
pub yaw: f64,
|
|
|
|
pub pitch: f64,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TargetRotation {
|
|
|
|
pub fn new(yaw: f64, pitch: f64) -> TargetRotation {
|
|
|
|
TargetRotation {
|
2018-11-04 16:43:30 -05:00
|
|
|
yaw,
|
|
|
|
pitch,
|
2016-04-07 14:30:42 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn zero() -> TargetRotation {
|
|
|
|
TargetRotation::new(0.0, 0.0)
|
|
|
|
}
|
|
|
|
}
|
2016-03-26 18:21:47 -04:00
|
|
|
|
2016-09-15 10:15:52 -04:00
|
|
|
#[derive(Default)]
|
2016-03-26 18:21:47 -04:00
|
|
|
pub struct Gravity {
|
|
|
|
pub on_ground: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Gravity {
|
2016-09-15 10:15:52 -04:00
|
|
|
pub fn new() -> Gravity { Default::default() }
|
2016-03-26 18:21:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
pub struct Bounds {
|
|
|
|
pub bounds: Aabb3<f64>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Bounds {
|
|
|
|
pub fn new(bounds: Aabb3<f64>) -> Bounds {
|
|
|
|
Bounds {
|
2018-11-04 16:43:30 -05:00
|
|
|
bounds,
|
2016-03-26 18:21:47 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-15 10:15:52 -04:00
|
|
|
#[derive(Default)]
|
2016-03-26 18:21:47 -04:00
|
|
|
pub struct GameInfo {
|
|
|
|
pub delta: f64,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl GameInfo {
|
2016-09-15 10:15:52 -04:00
|
|
|
pub fn new() -> GameInfo { Default::default() }
|
2016-03-26 18:21:47 -04:00
|
|
|
}
|
2016-04-08 06:08:21 -04:00
|
|
|
|
2016-09-15 10:15:52 -04:00
|
|
|
#[derive(Default)]
|
2016-04-08 06:08:21 -04:00
|
|
|
pub struct Light {
|
|
|
|
pub block_light: f32,
|
|
|
|
pub sky_light: f32,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Light {
|
2016-09-15 10:15:52 -04:00
|
|
|
pub fn new() -> Light { Default::default() }
|
2016-04-08 06:08:21 -04:00
|
|
|
}
|