stevenarella/src/entity/mod.rs

201 lines
3.7 KiB
Rust
Raw Normal View History

2022-09-24 04:46:44 -04:00
use steven_blocks as block;
use steven_protocol::protocol::packet;
2016-04-04 17:08:24 -04:00
pub mod block_entity;
pub mod player;
use crate::ecs;
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);
2022-09-24 04:46:44 -04:00
let sys = systems::ApplyDigging::new(m);
m.add_render_system(sys);
2016-04-04 17:08:24 -04:00
block_entity::add_systems(m);
}
/// 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,
}
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,
}
}
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>,
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),
lerp_amount: 0.2,
2016-04-07 14:30:42 -04:00
}
}
pub fn zero() -> TargetPosition {
TargetPosition::new(0.0, 0.0, 0.0)
}
}
/// 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 { yaw, pitch }
}
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 { yaw, pitch }
2016-04-07 14:30:42 -04:00
}
pub fn zero() -> TargetRotation {
TargetRotation::new(0.0, 0.0)
}
}
#[derive(Default)]
pub struct Gravity {
pub on_ground: bool,
}
impl Gravity {
pub fn new() -> Gravity {
Default::default()
}
}
pub struct Bounds {
pub bounds: Aabb3<f64>,
}
impl Bounds {
pub fn new(bounds: Aabb3<f64>) -> Bounds {
Bounds { bounds }
}
}
#[derive(Default)]
pub struct GameInfo {
pub delta: f64,
}
impl GameInfo {
pub fn new() -> GameInfo {
Default::default()
}
}
2016-04-08 06:08:21 -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 {
pub fn new() -> Light {
Default::default()
}
2016-04-08 06:08:21 -04:00
}
2022-09-24 04:46:44 -04:00
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct DiggingState {
pub block: block::Block,
pub position: shared::Position,
pub face: shared::Direction,
pub start: std::time::Instant,
pub finished: bool,
}
#[derive(Default)]
pub struct Digging {
pub last: Option<DiggingState>,
pub current: Option<DiggingState>,
}
impl Digging {
pub fn new() -> Self {
Default::default()
}
}
#[derive(Default)]
pub struct MouseButtons {
pub left: bool,
pub right: bool,
}
impl MouseButtons {
pub fn new() -> Self {
Default::default()
}
2022-10-24 12:08:30 -04:00
}