Changes the physics misnomer Direction to Orientation and adjusts some ECS read_storage names.

This commit is contained in:
Cody 2019-05-31 14:45:16 -04:00
parent b05eb2b861
commit 75ca605f5d
No known key found for this signature in database
GPG Key ID: 4953DADF9B6AD3C8
14 changed files with 69 additions and 69 deletions

View File

@ -271,9 +271,9 @@ impl Client {
self.state.read_storage().get(self.entity).cloned(),
self.state.read_storage().get(self.entity).cloned(),
) {
(Some(pos), Some(vel), Some(dir)) => {
(Some(pos), Some(vel), Some(ori)) => {
self.postbox
.send_message(ClientMsg::PlayerPhysics { pos, vel, dir });
.send_message(ClientMsg::PlayerPhysics { pos, vel, ori });
}
_ => {}
}
@ -341,12 +341,12 @@ impl Client {
entity,
pos,
vel,
dir,
ori,
} => match self.state.ecs().entity_from_uid(entity) {
Some(entity) => {
self.state.write_component(entity, pos);
self.state.write_component(entity, vel);
self.state.write_component(entity, dir);
self.state.write_component(entity, ori);
}
None => {}
},

View File

@ -19,12 +19,12 @@ impl Component for Vel {
type Storage = VecStorage<Self>;
}
// Direction
// Orientation
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
pub struct Dir(pub Vec3<f32>);
pub struct Ori(pub Vec3<f32>);
impl Component for Dir {
impl Component for Ori {
type Storage = VecStorage<Self>;
}

View File

@ -22,7 +22,7 @@ pub enum ClientMsg {
PlayerPhysics {
pos: comp::phys::Pos,
vel: comp::phys::Vel,
dir: comp::phys::Dir,
ori: comp::phys::Ori,
},
TerrainChunkRequest {
key: Vec2<i32>,

View File

@ -19,7 +19,7 @@ sphynx::sum_type! {
pub enum EcsCompPacket {
Pos(comp::phys::Pos),
Vel(comp::phys::Vel),
Dir(comp::phys::Dir),
Ori(comp::phys::Ori),
Actor(comp::Actor),
Player(comp::Player),
Stats(comp::Stats),
@ -33,7 +33,7 @@ sphynx::sum_type! {
pub enum EcsCompPhantom {
Pos(PhantomData<comp::phys::Pos>),
Vel(PhantomData<comp::phys::Vel>),
Dir(PhantomData<comp::phys::Dir>),
Ori(PhantomData<comp::phys::Ori>),
Actor(PhantomData<comp::Actor>),
Player(PhantomData<comp::Player>),
Stats(PhantomData<comp::Stats>),

View File

@ -27,7 +27,7 @@ pub enum ServerMsg {
entity: u64,
pos: comp::phys::Pos,
vel: comp::phys::Vel,
dir: comp::phys::Dir,
ori: comp::phys::Ori,
},
EntityAnimation {
entity: u64,

View File

@ -109,7 +109,7 @@ impl State {
// Register components synced by other means
ecs.register::<comp::phys::Pos>();
ecs.register::<comp::phys::Vel>();
ecs.register::<comp::phys::Dir>();
ecs.register::<comp::phys::Ori>();
ecs.register::<comp::AnimationInfo>();
// Register client-local components

View File

@ -5,7 +5,7 @@ use vek::*;
// Crate
use crate::{
comp::{
phys::{Dir, Pos, Vel},
phys::{Ori, Pos, Vel},
Animation, AnimationInfo, Attacking,
},
state::DeltaTime,
@ -23,12 +23,12 @@ impl<'a> System<'a> for Sys {
WriteStorage<'a, Attacking>,
);
fn run(&mut self, (entities, dt, mut attackings): Self::SystemData) {
for (entity, attacking) in (&entities, &mut attackings).join() {
attacking.time += dt.0;
fn run(&mut self, (entities, dt, mut attacks): Self::SystemData) {
for (entity, attack) in (&entities, &mut attacks).join() {
attack.time += dt.0;
}
let finished_attack = (&entities, &mut attackings)
let finished_attacks = (&entities, &mut attacks)
.join()
.filter(|(e, a)| {
a.time > 0.25 // TODO: constant
@ -36,8 +36,8 @@ impl<'a> System<'a> for Sys {
.map(|(e, a)| e)
.collect::<Vec<_>>();
for entity in finished_attack {
attackings.remove(entity);
for entity in finished_attacks {
attacks.remove(entity);
}
}
}

View File

@ -25,7 +25,7 @@ impl<'a> System<'a> for Sys {
fn run(
&mut self,
(time, entities, mut agents, positions, mut controls, mut jumpings, mut attackings): Self::SystemData,
(time, entities, mut agents, positions, mut controls, mut jumps, mut attacks): Self::SystemData,
) {
for (entity, agent, pos, control) in
(&entities, &mut agents, &positions, &mut controls).join()
@ -42,13 +42,13 @@ impl<'a> System<'a> for Sys {
}
}
Agent::Pet { target, offset } => {
// Run towards target
// Run towards target.
match positions.get(*target) {
Some(tgt_pos) => {
let tgt_pos = tgt_pos.0 + *offset;
if tgt_pos.z > pos.0.z + 1.0 {
jumpings.insert(entity, Jumping);
jumps.insert(entity, Jumping);
}
// Move towards the target.
@ -79,7 +79,7 @@ impl<'a> System<'a> for Sys {
control.move_dir = Vec2::zero();
if rand::random::<f32>() < 0.2 {
attackings.insert(entity, Attacking::start());
attacks.insert(entity, Attacking::start());
}
false

View File

@ -5,7 +5,7 @@ use vek::*;
// Crate
use crate::{
comp::{
phys::{Dir, ForceUpdate, Pos, Vel},
phys::{Ori, ForceUpdate, Pos, Vel},
Animation, AnimationInfo, Attacking, Control, Gliding, HealthSource, Jumping, Respawning,
Stats,
},
@ -26,7 +26,7 @@ impl<'a> System<'a> for Sys {
ReadExpect<'a, TerrainMap>,
ReadStorage<'a, Pos>,
WriteStorage<'a, Vel>,
WriteStorage<'a, Dir>,
WriteStorage<'a, Ori>,
WriteStorage<'a, AnimationInfo>,
WriteStorage<'a, Stats>,
ReadStorage<'a, Control>,
@ -47,23 +47,23 @@ impl<'a> System<'a> for Sys {
terrain,
positions,
mut velocities,
mut directions,
mut orientations,
mut animation_infos,
mut stats,
mut controls,
mut jumpings,
mut respawnings,
mut glidings,
mut attackings,
mut jumps,
mut respawns,
mut glides,
mut attacks,
mut force_updates,
): Self::SystemData,
) {
for (entity, pos, control, stats, mut dir, mut vel) in (
for (entity, pos, control, stats, mut ori, mut vel) in (
&entities,
&positions,
&controls,
&stats,
&mut directions,
&mut orientations,
&mut velocities,
)
.join()
@ -85,7 +85,7 @@ impl<'a> System<'a> for Sys {
// Apply physics to the player: acceleration and non-linear deceleration.
vel.0 += Vec2::broadcast(dt.0) * control.move_dir * 200.0;
if jumpings.get(entity).is_some() {
if jumps.get(entity).is_some() {
vel.0.z += 16.0;
}
@ -95,7 +95,7 @@ impl<'a> System<'a> for Sys {
// Apply physics to the player: acceleration and non-linear deceleration.
vel.0 += Vec2::broadcast(dt.0) * control.move_dir * 10.0;
if glidings.get(entity).is_some() && vel.0.z < 0.0 {
if glides.get(entity).is_some() && vel.0.z < 0.0 {
// TODO: Don't hard-code this.
let anti_grav = 9.81 * 3.95 + vel.0.z.powf(2.0) * 0.2;
vel.0.z +=
@ -118,18 +118,18 @@ impl<'a> System<'a> for Sys {
* Vec3::new(1.0, 1.0, 0.0);
if vel.0.magnitude_squared() != 0.0 {
dir.0 = vel.0.normalized() * Vec3::new(1.0, 1.0, 0.0);
ori.0 = vel.0.normalized() * Vec3::new(1.0, 1.0, 0.0);
}
let animation = if on_ground {
if control.move_dir.magnitude() > 0.01 {
Animation::Run
} else if attackings.get(entity).is_some() {
} else if attacks.get(entity).is_some() {
Animation::Attack
} else {
Animation::Idle
}
} else if glidings.get(entity).is_some() {
} else if glides.get(entity).is_some() {
Animation::Gliding
} else {
Animation::Jump
@ -151,8 +151,8 @@ impl<'a> System<'a> for Sys {
);
}
for (entity, &uid, pos, dir, attacking) in
(&entities, &uids, &positions, &directions, &mut attackings).join()
for (entity, &uid, pos, ori, attacking) in
(&entities, &uids, &positions, &orientations, &mut attacks).join()
{
if !attacking.applied {
for (b, pos_b, mut stat_b, mut vel_b) in
@ -162,7 +162,7 @@ impl<'a> System<'a> for Sys {
if entity != b
&& !stat_b.is_dead
&& pos.0.distance_squared(pos_b.0) < 50.0
&& dir.0.angle_between(pos_b.0 - pos.0).to_degrees() < 70.0
&& ori.0.angle_between(pos_b.0 - pos.0).to_degrees() < 70.0
{
// Deal damage
stat_b.hp.change_by(-10, HealthSource::Attack { by: uid }); // TODO: variable damage and weapon

View File

@ -145,7 +145,7 @@ impl Server {
.create_entity_synced()
.with(pos)
.with(comp::phys::Vel(Vec3::zero()))
.with(comp::phys::Dir(Vec3::unit_y()))
.with(comp::phys::Ori(Vec3::unit_y()))
.with(comp::Control::default())
.with(comp::AnimationInfo::default())
.with(comp::Actor::Character { name, body })
@ -167,7 +167,7 @@ impl Server {
state.write_component(entity, comp::AnimationInfo::default());
state.write_component(entity, comp::phys::Pos(spawn_point));
state.write_component(entity, comp::phys::Vel(Vec3::zero()));
state.write_component(entity, comp::phys::Dir(Vec3::unit_y()));
state.write_component(entity, comp::phys::Ori(Vec3::unit_y()));
// Make sure physics are accepted.
state.write_component(entity, comp::phys::ForceUpdate);
@ -524,11 +524,11 @@ impl Server {
_ => client.error_state(RequestStateError::Impossible),
}
}
ClientMsg::PlayerPhysics { pos, vel, dir } => match client.client_state {
ClientMsg::PlayerPhysics { pos, vel, ori } => match client.client_state {
ClientState::Character => {
state.write_component(entity, pos);
state.write_component(entity, vel);
state.write_component(entity, dir);
state.write_component(entity, ori);
}
// Only characters can send positions.
_ => client.error_state(RequestStateError::Impossible),
@ -629,12 +629,12 @@ impl Server {
state.write_component(entity, player);
// Sync physics
for (entity, &uid, &pos, &vel, &dir) in (
for (entity, &uid, &pos, &vel, &ori) in (
&state.ecs().entities(),
&state.ecs().read_storage::<Uid>(),
&state.ecs().read_storage::<comp::phys::Pos>(),
&state.ecs().read_storage::<comp::phys::Vel>(),
&state.ecs().read_storage::<comp::phys::Dir>(),
&state.ecs().read_storage::<comp::phys::Ori>(),
)
.join()
{
@ -642,7 +642,7 @@ impl Server {
entity: uid.into(),
pos,
vel,
dir,
ori,
});
}
@ -671,12 +671,12 @@ impl Server {
.notify_registered(ServerMsg::EcsSync(self.state.ecs_mut().next_sync_package()));
// Sync physics
for (entity, &uid, &pos, &vel, &dir, force_update) in (
for (entity, &uid, &pos, &vel, &ori, force_update) in (
&self.state.ecs().entities(),
&self.state.ecs().read_storage::<Uid>(),
&self.state.ecs().read_storage::<comp::phys::Pos>(),
&self.state.ecs().read_storage::<comp::phys::Vel>(),
&self.state.ecs().read_storage::<comp::phys::Dir>(),
&self.state.ecs().read_storage::<comp::phys::Ori>(),
self.state
.ecs()
.read_storage::<comp::phys::ForceUpdate>()
@ -688,7 +688,7 @@ impl Server {
entity: uid.into(),
pos,
vel,
dir,
ori,
};
let state = &self.state;

View File

@ -36,7 +36,7 @@ impl Animation for AttackAnimation {
let wave_stop = (anim_time as f32 * 6.0).min(PI / 2.0).sin();
let wave_stop_alt = (anim_time as f32 * 28.0).min(PI / 2.0).sin();
let wave_stop_quick = (anim_time as f32 * 16.0).min(PI / 2.0).sin();
let peakwave = 1.0 - (anim_time as f32 * 1.0).cos();
let peak_wave = 1.0 - (anim_time as f32 * 1.0).cos();
let head_look = Vec2::new(
((global_time + anim_time) as f32 / 8.0)

View File

@ -483,11 +483,11 @@ impl FigureMgr {
.get(client.entity())
.map_or(Vec3::zero(), |pos| pos.0);
for (entity, pos, vel, dir, actor, animation_info, stats) in (
for (entity, pos, vel, ori, actor, animation_info, stats) in (
&ecs.entities(),
&ecs.read_storage::<comp::phys::Pos>(),
&ecs.read_storage::<comp::phys::Vel>(),
&ecs.read_storage::<comp::phys::Dir>(),
&ecs.read_storage::<comp::phys::Ori>(),
&ecs.read_storage::<comp::Actor>(),
&ecs.read_storage::<comp::AnimationInfo>(),
ecs.read_storage::<comp::Stats>().maybe(),
@ -568,7 +568,7 @@ impl FigureMgr {
};
state.skeleton.interpolate(&target_skeleton);
state.update(renderer, pos.0, dir.0, col);
state.update(renderer, pos.0, ori.0, col);
}
Body::Quadruped(body) => {
let state = self.quadruped_states.entry(entity).or_insert_with(|| {
@ -597,7 +597,7 @@ impl FigureMgr {
};
state.skeleton.interpolate(&target_skeleton);
state.update(renderer, pos.0, dir.0, col);
state.update(renderer, pos.0, ori.0, col);
}
Body::QuadrupedMedium(body) => {
let state =
@ -633,7 +633,7 @@ impl FigureMgr {
};
state.skeleton.interpolate(&target_skeleton);
state.update(renderer, pos.0, dir.0, col);
state.update(renderer, pos.0, ori.0, col);
}
},
// TODO: Non-character actors
@ -671,7 +671,7 @@ impl FigureMgr {
&ecs.entities(),
&ecs.read_storage::<comp::phys::Pos>(),
&ecs.read_storage::<comp::phys::Vel>(),
&ecs.read_storage::<comp::phys::Dir>(),
&ecs.read_storage::<comp::phys::Ori>(),
&ecs.read_storage::<comp::Actor>(),
&ecs.read_storage::<comp::AnimationInfo>(),
ecs.read_storage::<comp::Stats>().maybe(),
@ -737,12 +737,12 @@ impl<S: Skeleton> FigureState<S> {
&mut self,
renderer: &mut Renderer,
pos: Vec3<f32>,
dir: Vec3<f32>,
ori: Vec3<f32>,
col: Rgba<f32>,
) {
let mat = Mat4::<f32>::identity()
* Mat4::translation_3d(pos)
* Mat4::rotation_z(-dir.x.atan2(dir.y)); // + f32::consts::PI / 2.0);
* Mat4::rotation_z(-ori.x.atan2(ori.y)); // + f32::consts::PI / 2.0);
let locals = FigureLocals::new(mat, col);
renderer.update_consts(&mut self.locals, &[locals]).unwrap();

View File

@ -238,11 +238,11 @@ impl FigureMgr {
pub fn maintain(&mut self, renderer: &mut Renderer, client: &Client) {
let time = client.state().get_time();
let ecs = client.state().ecs();
for (entity, pos, vel, dir, actor, animation_history) in (
for (entity, pos, vel, ori, actor, animation_history) in (
&ecs.entities(),
&ecs.read_storage::<comp::phys::Pos>(),
&ecs.read_storage::<comp::phys::Vel>(),
&ecs.read_storage::<comp::phys::Dir>(),
&ecs.read_storage::<comp::phys::Ori>(),
&ecs.read_storage::<comp::Actor>(),
&ecs.read_storage::<comp::AnimationHistory>(),
)
@ -275,7 +275,7 @@ impl FigureMgr {
state.skeleton.interpolate(&target_skeleton);
state.update(renderer, pos.0, dir.0);
state.update(renderer, pos.0, ori.0);
} // TODO: Non-humanoid bodies.
},
// TODO: Non-character actors.
@ -333,10 +333,10 @@ impl<S: Skeleton> FigureState<S> {
}
}
pub fn update(&mut self, renderer: &mut Renderer, pos: Vec3<f32>, dir: Vec3<f32>) {
pub fn update(&mut self, renderer: &mut Renderer, pos: Vec3<f32>, ori: Vec3<f32>) {
let mat = Mat4::<f32>::identity()
* Mat4::translation_3d(pos)
* Mat4::rotation_z(-dir.x.atan2(dir.y)); // + f32::consts::PI / 2.0);
* Mat4::rotation_z(-ori.x.atan2(ori.y)); // + f32::consts::PI / 2.0);
let locals = FigureLocals::new(mat);
renderer.update_consts(&mut self.locals, &[locals]).unwrap();

View File

@ -180,11 +180,11 @@ impl FigureMgr {
pub fn maintain(&mut self, renderer: &mut Renderer, client: &Client) {
let time = client.state().get_time();
let ecs = client.state().ecs();
for (entity, pos, vel, dir, actor, animation_history) in (
for (entity, pos, vel, ori, actor, animation_history) in (
&ecs.entities(),
&ecs.read_storage::<comp::phys::Pos>(),
&ecs.read_storage::<comp::phys::Vel>(),
&ecs.read_storage::<comp::phys::Dir>(),
&ecs.read_storage::<comp::phys::Ori>(),
&ecs.read_storage::<comp::Actor>(),
&ecs.read_storage::<comp::AnimationHistory>(),
)
@ -205,7 +205,7 @@ impl FigureMgr {
state.skeleton.interpolate(&target_skeleton);
state.update(renderer, pos.0, dir.0);
state.update(renderer, pos.0, ori.0);
} // TODO: Non-humanoid bodies
},
// TODO: Non-character actors
@ -263,10 +263,10 @@ impl<S: Skeleton> FigureState<S> {
}
}
pub fn update(&mut self, renderer: &mut Renderer, pos: Vec3<f32>, dir: Vec3<f32>) {
pub fn update(&mut self, renderer: &mut Renderer, pos: Vec3<f32>, ori: Vec3<f32>) {
let mat = Mat4::<f32>::identity()
* Mat4::translation_3d(pos)
* Mat4::rotation_z(-dir.x.atan2(dir.y)); // + f32::consts::PI / 2.0);
* Mat4::rotation_z(-ori.x.atan2(ori.y)); // + f32::consts::PI / 2.0);
let locals = FigureLocals::new(mat);
renderer.update_consts(&mut self.locals, &[locals]).unwrap();