Add pub use phys:: and remove most pub mods

This commit is contained in:
timokoesters 2019-06-14 17:27:05 +02:00
parent 955c20fa61
commit 7deb3da1af
No known key found for this signature in database
GPG Key ID: CD80BE9AAEE78097
18 changed files with 86 additions and 128 deletions

View File

@ -153,7 +153,7 @@ impl Client {
pub fn current_chunk(&self) -> Option<Arc<TerrainChunk>> {
let chunk_pos = Vec2::from(
self.state
.read_storage::<comp::phys::Pos>()
.read_storage::<comp::Pos>()
.get(self.entity)
.cloned()?
.0,
@ -218,7 +218,7 @@ impl Client {
// 5) Terrain
let pos = self
.state
.read_storage::<comp::phys::Pos>()
.read_storage::<comp::Pos>()
.get(self.entity)
.cloned();
if let (Some(pos), Some(view_distance)) = (pos, self.view_distance) {

View File

@ -1,30 +1,18 @@
pub mod actor;
pub mod agent;
pub mod animation;
pub mod controller;
pub mod inputs;
pub mod phys;
pub mod player;
pub mod stats;
mod agent;
mod animation;
mod controller;
mod inputs;
mod phys;
mod player;
mod stats;
// Reexports
pub use actor::Actor;
pub use actor::Body;
pub use actor::HumanoidBody;
pub use actor::QuadrupedBody;
pub use actor::QuadrupedMediumBody;
pub use actor::{Actor, Body, HumanoidBody, QuadrupedBody, QuadrupedMediumBody};
pub use agent::Agent;
pub use animation::Animation;
pub use animation::AnimationInfo;
pub use animation::{Animation, AnimationInfo};
pub use controller::Controller;
pub use inputs::Attacking;
pub use inputs::Gliding;
pub use inputs::Jumping;
pub use inputs::MoveDir;
pub use inputs::OnGround;
pub use inputs::Respawning;
pub use inputs::Rolling;
pub use inputs::{Attacking, Gliding, Jumping, MoveDir, OnGround, Respawning, Rolling};
pub use phys::{ForceUpdate, Ori, Pos, Vel};
pub use player::Player;
pub use stats::Dying;
pub use stats::HealthSource;
pub use stats::Stats;
pub use stats::{Dying, HealthSource, Stats};

View File

@ -2,7 +2,6 @@ use specs::{Component, NullStorage, VecStorage};
use vek::*;
// Position
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
pub struct Pos(pub Vec3<f32>);
@ -11,7 +10,6 @@ impl Component for Pos {
}
// Velocity
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
pub struct Vel(pub Vec3<f32>);
@ -20,7 +18,6 @@ impl Component for Vel {
}
// Orientation
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
pub struct Ori(pub Vec3<f32>);
@ -29,7 +26,6 @@ impl Component for Ori {
}
// ForceUpdate
#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize)]
pub struct ForceUpdate;

View File

@ -19,9 +19,9 @@ pub enum ClientMsg {
Chat(String),
PlayerAnimation(comp::AnimationInfo),
PlayerPhysics {
pos: comp::phys::Pos,
vel: comp::phys::Vel,
ori: comp::phys::Ori,
pos: comp::Pos,
vel: comp::Vel,
ori: comp::Ori,
},
TerrainChunkRequest {
key: Vec2<i32>,

View File

@ -17,9 +17,9 @@ impl sphynx::ResPacket for EcsResPacket {}
sphynx::sum_type! {
#[derive(Clone, Debug, Serialize, Deserialize)]
pub enum EcsCompPacket {
Pos(comp::phys::Pos),
Vel(comp::phys::Vel),
Ori(comp::phys::Ori),
Pos(comp::Pos),
Vel(comp::Vel),
Ori(comp::Ori),
Actor(comp::Actor),
Player(comp::Player),
Stats(comp::Stats),
@ -33,9 +33,9 @@ sphynx::sum_type! {
sphynx::sum_type! {
#[derive(Clone, Debug, Serialize, Deserialize)]
pub enum EcsCompPhantom {
Pos(PhantomData<comp::phys::Pos>),
Vel(PhantomData<comp::phys::Vel>),
Ori(PhantomData<comp::phys::Ori>),
Pos(PhantomData<comp::Pos>),
Vel(PhantomData<comp::Vel>),
Ori(PhantomData<comp::Ori>),
Actor(PhantomData<comp::Actor>),
Player(PhantomData<comp::Player>),
Stats(PhantomData<comp::Stats>),

View File

@ -32,9 +32,9 @@ pub enum ServerMsg {
EcsSync(sphynx::SyncPackage<EcsCompPacket, EcsResPacket>),
EntityPhysics {
entity: u64,
pos: comp::phys::Pos,
vel: comp::phys::Vel,
ori: comp::phys::Ori,
pos: comp::Pos,
vel: comp::Vel,
ori: comp::Ori,
},
EntityAnimation {
entity: u64,

View File

@ -104,12 +104,12 @@ impl State {
ecs.register_synced::<comp::Stats>();
ecs.register_synced::<comp::Attacking>(); // TODO: Don't send this to the client?
ecs.register_synced::<comp::Rolling>(); // TODO: Don't send this to the client?
ecs.register::<comp::phys::ForceUpdate>();
ecs.register::<comp::ForceUpdate>();
// Register components synced by other means
ecs.register::<comp::phys::Pos>();
ecs.register::<comp::phys::Vel>();
ecs.register::<comp::phys::Ori>();
ecs.register::<comp::Pos>();
ecs.register::<comp::Vel>();
ecs.register::<comp::Ori>();
ecs.register::<comp::MoveDir>();
ecs.register::<comp::OnGround>();
ecs.register::<comp::AnimationInfo>();

View File

@ -1,4 +1,4 @@
use crate::comp::{phys::Pos, Agent, Attacking, Controller, Jumping};
use crate::comp::{Agent, Attacking, Controller, Jumping, Pos};
use log::warn;
use rand::{seq::SliceRandom, thread_rng};
use specs::{Entities, Join, ReadStorage, System, WriteStorage};

View File

@ -1,5 +1,8 @@
use crate::{
comp::{phys, Animation, AnimationInfo, Attacking, Gliding, Jumping, OnGround, Rolling},
comp::{
Animation, AnimationInfo, Attacking, ForceUpdate, Gliding, Jumping, OnGround, Ori, Pos,
Rolling, Vel,
},
state::DeltaTime,
};
use specs::{Entities, Join, Read, ReadStorage, System, WriteStorage};
@ -10,7 +13,7 @@ impl<'a> System<'a> for Sys {
type SystemData = (
Entities<'a>,
Read<'a, DeltaTime>,
ReadStorage<'a, phys::Vel>,
ReadStorage<'a, Vel>,
ReadStorage<'a, OnGround>,
ReadStorage<'a, Jumping>,
ReadStorage<'a, Gliding>,

View File

@ -1,7 +1,6 @@
use crate::{
comp::{
phys::{ForceUpdate, Ori, Pos, Vel},
Attacking, HealthSource, Stats,
Attacking, HealthSource, Stats, {ForceUpdate, Ori, Pos, Vel},
},
state::{DeltaTime, Uid},
};

View File

@ -1,8 +1,7 @@
use crate::{
comp::{
phys::{ForceUpdate, Ori, Pos, Vel},
Animation, AnimationInfo, Attacking, Controller, Gliding, HealthSource, Jumping, MoveDir,
OnGround, Respawning, Rolling, Stats,
OnGround, Respawning, Rolling, Stats, {ForceUpdate, Ori, Pos, Vel},
},
state::DeltaTime,
};

View File

@ -1,8 +1,5 @@
use crate::{
comp::{
phys::{Ori, Pos, Vel},
Gliding, Jumping, MoveDir, OnGround, Rolling, Stats,
},
comp::{Gliding, Jumping, MoveDir, OnGround, Ori, Pos, Rolling, Stats, Vel},
state::DeltaTime,
terrain::TerrainMap,
vol::{ReadVol, Vox},

View File

@ -100,18 +100,12 @@ fn handle_jump(server: &mut Server, entity: EcsEntity, args: String, action: &Ch
let (opt_x, opt_y, opt_z) = scan_fmt!(&args, action.arg_fmt, f32, f32, f32);
match (opt_x, opt_y, opt_z) {
(Some(x), Some(y), Some(z)) => {
match server
.state
.read_component_cloned::<comp::phys::Pos>(entity)
{
match server.state.read_component_cloned::<comp::Pos>(entity) {
Some(current_pos) => {
server.state.write_component(
entity,
comp::phys::Pos(current_pos.0 + Vec3::new(x, y, z)),
);
server
.state
.write_component(entity, comp::phys::ForceUpdate);
.write_component(entity, comp::Pos(current_pos.0 + Vec3::new(x, y, z)));
server.state.write_component(entity, comp::ForceUpdate);
}
None => server.clients.notify(
entity,
@ -131,10 +125,8 @@ fn handle_goto(server: &mut Server, entity: EcsEntity, args: String, action: &Ch
(Some(x), Some(y), Some(z)) => {
server
.state
.write_component(entity, comp::phys::Pos(Vec3::new(x, y, z)));
server
.state
.write_component(entity, comp::phys::ForceUpdate);
.write_component(entity, comp::Pos(Vec3::new(x, y, z)));
server.state.write_component(entity, comp::ForceUpdate);
}
_ => server
.clients
@ -173,20 +165,15 @@ fn handle_tp(server: &mut Server, entity: EcsEntity, args: String, action: &Chat
match opt_alias {
Some(alias) => {
let ecs = server.state.ecs();
let opt_player = (&ecs.entities(), &ecs.read_storage::<comp::player::Player>())
let opt_player = (&ecs.entities(), &ecs.read_storage::<comp::Player>())
.join()
.find(|(_, player)| player.alias == alias)
.map(|(entity, _)| entity);
match opt_player {
Some(player) => match server
.state
.read_component_cloned::<comp::phys::Pos>(player)
{
Some(player) => match server.state.read_component_cloned::<comp::Pos>(player) {
Some(pos) => {
server.state.write_component(entity, pos);
server
.state
.write_component(entity, comp::phys::ForceUpdate);
server.state.write_component(entity, comp::ForceUpdate);
}
None => server.clients.notify(
entity,
@ -222,10 +209,7 @@ fn handle_spawn(server: &mut Server, entity: EcsEntity, args: String, action: &C
match (opt_agent, opt_id, opt_amount) {
(Some(agent), Some(id), Some(amount)) => {
match server
.state
.read_component_cloned::<comp::phys::Pos>(entity)
{
match server.state.read_component_cloned::<comp::Pos>(entity) {
Some(mut pos) => {
pos.0.x += 1.0; // Temp fix TODO: Solve NaN issue with positions of pets
let body = kind_to_body(id);

View File

@ -135,7 +135,7 @@ impl Server {
#[allow(dead_code)]
pub fn create_npc(
&mut self,
pos: comp::phys::Pos,
pos: comp::Pos,
name: String,
body: comp::Body,
) -> EcsEntityBuilder {
@ -143,13 +143,13 @@ impl Server {
.ecs_mut()
.create_entity_synced()
.with(pos)
.with(comp::phys::Vel(Vec3::zero()))
.with(comp::phys::Ori(Vec3::unit_y()))
.with(comp::Vel(Vec3::zero()))
.with(comp::Ori(Vec3::unit_y()))
.with(comp::Controller::default())
.with(comp::AnimationInfo::default())
.with(comp::Actor::Character { name, body })
.with(comp::Stats::default())
.with(comp::phys::ForceUpdate)
.with(comp::ForceUpdate)
}
pub fn create_player_character(
@ -165,11 +165,11 @@ impl Server {
state.write_component(entity, comp::Stats::default());
state.write_component(entity, comp::AnimationInfo::default());
state.write_component(entity, comp::Controller::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::Ori(Vec3::unit_y()));
state.write_component(entity, comp::Pos(spawn_point));
state.write_component(entity, comp::Vel(Vec3::zero()));
state.write_component(entity, comp::Ori(Vec3::unit_y()));
// Make sure physics are accepted.
state.write_component(entity, comp::phys::ForceUpdate);
state.write_component(entity, comp::ForceUpdate);
// Tell the client its request was successful.
client.allow_state(ClientState::Character);
@ -246,9 +246,8 @@ impl Server {
// Actually kill them
for entity in todo_kill {
if let Some(client) = self.clients.get_mut(&entity) {
self.state
.write_component(entity, comp::phys::Vel(Vec3::zero()));
self.state.write_component(entity, comp::phys::ForceUpdate);
self.state.write_component(entity, comp::Vel(Vec3::zero()));
self.state.write_component(entity, comp::ForceUpdate);
client.force_state(ClientState::Dead);
} else {
if let Err(err) = self.state.ecs_mut().delete_entity_synced(entity) {
@ -273,12 +272,11 @@ impl Server {
self.state.write_component(entity, comp::Stats::default());
self.state
.ecs_mut()
.write_storage::<comp::phys::Pos>()
.write_storage::<comp::Pos>()
.get_mut(entity)
.map(|pos| pos.0.z += 100.0);
self.state
.write_component(entity, comp::phys::Vel(Vec3::zero()));
self.state.write_component(entity, comp::phys::ForceUpdate);
self.state.write_component(entity, comp::Vel(Vec3::zero()));
self.state.write_component(entity, comp::ForceUpdate);
}
}
@ -289,7 +287,7 @@ impl Server {
for (entity, view_distance, pos) in (
&self.state.ecs().entities(),
&self.state.ecs().read_storage::<comp::Player>(),
&self.state.ecs().read_storage::<comp::phys::Pos>(),
&self.state.ecs().read_storage::<comp::Pos>(),
)
.join()
.filter_map(|(entity, player, pos)| {
@ -324,7 +322,7 @@ impl Server {
// For each player with a position, calculate the distance.
for (player, pos) in (
&self.state.ecs().read_storage::<comp::Player>(),
&self.state.ecs().read_storage::<comp::phys::Pos>(),
&self.state.ecs().read_storage::<comp::Pos>(),
)
.join()
{
@ -632,9 +630,9 @@ impl Server {
// Sync physics
for (&uid, &pos, &vel, &ori) in (
&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::Ori>(),
&state.ecs().read_storage::<comp::Pos>(),
&state.ecs().read_storage::<comp::Vel>(),
&state.ecs().read_storage::<comp::Ori>(),
)
.join()
{
@ -673,13 +671,10 @@ impl Server {
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::Ori>(),
self.state
.ecs()
.read_storage::<comp::phys::ForceUpdate>()
.maybe(),
&self.state.ecs().read_storage::<comp::Pos>(),
&self.state.ecs().read_storage::<comp::Vel>(),
&self.state.ecs().read_storage::<comp::Ori>(),
self.state.ecs().read_storage::<comp::ForceUpdate>().maybe(),
)
.join()
{
@ -695,7 +690,7 @@ impl Server {
let in_vd = |entity| {
// Get client position.
let client_pos = match state.ecs().read_storage::<comp::phys::Pos>().get(entity) {
let client_pos = match state.ecs().read_storage::<comp::Pos>().get(entity) {
Some(pos) => pos.0,
None => return false,
};
@ -726,10 +721,7 @@ impl Server {
&self.state.ecs().entities(),
&self.state.ecs().read_storage::<Uid>(),
&self.state.ecs().read_storage::<comp::AnimationInfo>(),
self.state
.ecs()
.read_storage::<comp::phys::ForceUpdate>()
.maybe(),
self.state.ecs().read_storage::<comp::ForceUpdate>().maybe(),
)
.join()
{
@ -748,7 +740,7 @@ impl Server {
// Remove all force flags.
self.state
.ecs_mut()
.write_storage::<comp::phys::ForceUpdate>()
.write_storage::<comp::ForceUpdate>()
.clear();
}

View File

@ -103,7 +103,7 @@ font_ids! {
pub struct DebugInfo {
pub tps: f64,
pub ping_ms: f64,
pub coordinates: Option<comp::phys::Pos>,
pub coordinates: Option<comp::Pos>,
}
pub enum Event {
@ -312,7 +312,7 @@ impl Hud {
if self.show.ingame {
let ecs = client.state().ecs();
let actor = ecs.read_storage::<comp::Actor>();
let pos = ecs.read_storage::<comp::phys::Pos>();
let pos = ecs.read_storage::<comp::Pos>();
let stats = ecs.read_storage::<comp::Stats>();
let player = ecs.read_storage::<comp::Player>();
let entities = ecs.entities();
@ -322,7 +322,7 @@ impl Hud {
let player_pos = client
.state()
.ecs()
.read_storage::<comp::phys::Pos>()
.read_storage::<comp::Pos>()
.get(client.entity())
.map_or(Vec3::zero(), |pos| pos.0);
let mut name_id_walker = self.ids.name_tags.walk();

View File

@ -477,15 +477,15 @@ impl FigureMgr {
let player_pos = client
.state()
.ecs()
.read_storage::<comp::phys::Pos>()
.read_storage::<comp::Pos>()
.get(client.entity())
.map_or(Vec3::zero(), |pos| pos.0);
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::Ori>(),
&ecs.read_storage::<comp::Pos>(),
&ecs.read_storage::<comp::Vel>(),
&ecs.read_storage::<comp::Ori>(),
&ecs.read_storage::<comp::Actor>(),
&ecs.read_storage::<comp::AnimationInfo>(),
ecs.read_storage::<comp::Stats>().maybe(),
@ -676,15 +676,15 @@ impl FigureMgr {
let player_pos = client
.state()
.ecs()
.read_storage::<comp::phys::Pos>()
.read_storage::<comp::Pos>()
.get(client.entity())
.map_or(Vec3::zero(), |pos| pos.0);
for (entity, _, _, _, actor, _, _) in (
&ecs.entities(),
&ecs.read_storage::<comp::phys::Pos>(),
&ecs.read_storage::<comp::phys::Vel>(),
&ecs.read_storage::<comp::phys::Ori>(),
&ecs.read_storage::<comp::Pos>(),
&ecs.read_storage::<comp::Vel>(),
&ecs.read_storage::<comp::Ori>(),
&ecs.read_storage::<comp::Actor>(),
&ecs.read_storage::<comp::AnimationInfo>(),
ecs.read_storage::<comp::Stats>().maybe(),

View File

@ -110,7 +110,7 @@ impl Scene {
let player_pos = client
.state()
.ecs()
.read_storage::<comp::phys::Pos>()
.read_storage::<comp::Pos>()
.get(client.entity())
.map_or(Vec3::zero(), |pos| pos.0);

View File

@ -8,7 +8,7 @@ use crate::{
Direction, Error, GlobalState, PlayState, PlayStateResult,
};
use client::{self, Client};
use common::{clock::Clock, comp, comp::phys::Pos, msg::ClientState};
use common::{clock::Clock, comp, comp::Pos, msg::ClientState};
use log::{error, warn};
use std::{cell::RefCell, rc::Rc, time::Duration};
use vek::*;