Move Systems out of common into common_sys

This requires to move `State` into a own crate called `common_state` which depends on `common` and `common_sys`
This commit is contained in:
Marcel Märtens 2020-12-01 01:28:00 +01:00
parent e2fccd9694
commit add7922653
86 changed files with 404 additions and 255 deletions

36
Cargo.lock generated
View File

@ -5341,6 +5341,7 @@ dependencies = [
"uvth 3.1.1", "uvth 3.1.1",
"vek 0.12.0", "vek 0.12.0",
"veloren-common", "veloren-common",
"veloren_common_state",
"veloren_network", "veloren_network",
] ]
@ -5415,6 +5416,8 @@ dependencies = [
"vek 0.12.0", "vek 0.12.0",
"veloren-common", "veloren-common",
"veloren-world", "veloren-world",
"veloren_common_state",
"veloren_common_sys",
"veloren_network", "veloren_network",
] ]
@ -5496,6 +5499,8 @@ dependencies = [
"veloren-server", "veloren-server",
"veloren-voxygen-anim", "veloren-voxygen-anim",
"veloren-world", "veloren-world",
"veloren_common_state",
"veloren_common_sys",
"window_clipboard", "window_clipboard",
"winit", "winit",
"winres", "winres",
@ -5544,6 +5549,37 @@ dependencies = [
"veloren-common", "veloren-common",
] ]
[[package]]
name = "veloren_common_state"
version = "0.8.0"
dependencies = [
"hashbrown 0.7.2",
"indexmap",
"rand 0.7.3",
"rayon",
"slab",
"specs",
"tracing",
"tracy-client",
"vek 0.12.0",
"veloren-common",
"veloren_common_sys",
]
[[package]]
name = "veloren_common_sys"
version = "0.8.0"
dependencies = [
"rand 0.7.3",
"rayon",
"serde",
"specs",
"tracing",
"tracy-client",
"vek 0.12.0",
"veloren-common",
]
[[package]] [[package]]
name = "veloren_network" name = "veloren_network"
version = "0.2.0" version = "0.2.0"

View File

@ -3,6 +3,8 @@ cargo-features = ["named-profiles","profile-overrides"]
[workspace] [workspace]
members = [ members = [
"common", "common",
"common/state",
"common/sys",
"client", "client",
"chat-cli", "chat-cli",
"server", "server",

View File

@ -11,6 +11,7 @@ default = ["simd"]
[dependencies] [dependencies]
common = { package = "veloren-common", path = "../common", features = ["no-assets"] } common = { package = "veloren-common", path = "../common", features = ["no-assets"] }
common_state = { package = "veloren_common_state", path = "../common/state", default-features = false }
network = { package = "veloren_network", path = "../network", features = ["compression"], default-features = false } network = { package = "veloren_network", path = "../network", features = ["compression"], default-features = false }
byteorder = "1.3.2" byteorder = "1.3.2"

View File

@ -33,11 +33,11 @@ use common::{
outcome::Outcome, outcome::Outcome,
recipe::RecipeBook, recipe::RecipeBook,
span, span,
state::State,
sync::{Uid, UidAllocator, WorldSyncExt}, sync::{Uid, UidAllocator, WorldSyncExt},
terrain::{block::Block, neighbors, BiomeKind, SitesKind, TerrainChunk, TerrainChunkSize}, terrain::{block::Block, neighbors, BiomeKind, SitesKind, TerrainChunk, TerrainChunkSize},
vol::RectVolSize, vol::RectVolSize,
}; };
use common_state::State;
use comp::BuffKind; use comp::BuffKind;
use futures_executor::block_on; use futures_executor::block_on;
use futures_timer::Delay; use futures_timer::Delay;

View File

@ -6,10 +6,10 @@ use crate::{
Body, CharacterState, EnergySource, Gravity, LightEmitter, StateUpdate, Body, CharacterState, EnergySource, Gravity, LightEmitter, StateUpdate,
}, },
states::{ states::{
behavior::JoinData,
utils::{AbilityKey, StageSection}, utils::{AbilityKey, StageSection},
*, *,
}, },
sys::character_behavior::JoinData,
Knockback, Knockback,
}; };
use arraygen::Arraygen; use arraygen::Arraygen;

View File

@ -1,8 +1,7 @@
use crate::{ use crate::{
comp::{Energy, Ori, Pos, Vel}, comp::{Energy, Ori, Pos, Vel},
event::{LocalEvent, ServerEvent}, event::{LocalEvent, ServerEvent},
states::*, states::{behavior::JoinData, *},
sys::character_behavior::JoinData,
Damage, GroupTarget, Knockback, Damage, GroupTarget, Knockback,
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};

View File

@ -1,4 +1,4 @@
use crate::state::Time; use crate::resources::Time;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use specs::{Component, FlaggedStorage}; use specs::{Component, FlaggedStorage};
use specs_idvs::IdvStorage; use specs_idvs::IdvStorage;

View File

@ -1,3 +1,6 @@
// The limit on distance between the entity and a collectible (squared) // The limit on distance between the entity and a collectible (squared)
pub const MAX_PICKUP_RANGE: f32 = 8.0; pub const MAX_PICKUP_RANGE: f32 = 8.0;
pub const MAX_MOUNT_RANGE: f32 = 14.0; pub const MAX_MOUNT_RANGE: f32 = 14.0;
pub const GRAVITY: f32 = 9.81 * 5.0;
pub const FRIC_GROUND: f32 = 0.15;

View File

@ -40,13 +40,12 @@ pub mod path;
pub mod ray; pub mod ray;
pub mod recipe; pub mod recipe;
pub mod region; pub mod region;
pub mod resources;
pub mod rtsim; pub mod rtsim;
pub mod spiral; pub mod spiral;
pub mod state;
pub mod states; pub mod states;
pub mod store; pub mod store;
pub mod sync; pub mod sync;
pub mod sys;
pub mod terrain; pub mod terrain;
pub mod time; pub mod time;
pub mod typed; pub mod typed;

View File

@ -4,7 +4,8 @@ use crate::{
comp, comp,
outcome::Outcome, outcome::Outcome,
recipe::RecipeBook, recipe::RecipeBook,
state, sync, resources::TimeOfDay,
sync,
sync::Uid, sync::Uid,
terrain::{Block, TerrainChunk}, terrain::{Block, TerrainChunk},
}; };
@ -49,7 +50,7 @@ pub enum ServerInit {
TooManyPlayers, TooManyPlayers,
GameSync { GameSync {
entity_package: sync::EntityPackage<EcsCompPacket>, entity_package: sync::EntityPackage<EcsCompPacket>,
time_of_day: state::TimeOfDay, time_of_day: TimeOfDay,
max_group_size: u32, max_group_size: u32,
client_timeout: Duration, client_timeout: Duration,
world_map: crate::msg::world_msg::WorldMapMsg, world_map: crate::msg::world_msg::WorldMapMsg,
@ -110,7 +111,7 @@ pub enum ServerGeneral {
/// formatting the message and turning it into a speech bubble. /// formatting the message and turning it into a speech bubble.
ChatMsg(comp::ChatMsg), ChatMsg(comp::ChatMsg),
SetPlayerEntity(Uid), SetPlayerEntity(Uid),
TimeOfDay(state::TimeOfDay), TimeOfDay(TimeOfDay),
EntitySync(sync::EntitySyncPackage), EntitySync(sync::EntitySyncPackage),
CompSync(sync::CompSyncPackage<EcsCompPacket>), CompSync(sync::CompSyncPackage<EcsCompPacket>),
CreateEntity(sync::EntityPackage<EcsCompPacket>), CreateEntity(sync::EntityPackage<EcsCompPacket>),

13
common/src/resources.rs Normal file
View File

@ -0,0 +1,13 @@
use serde::{Deserialize, Serialize};
/// A resource that stores the time of day.
#[derive(Copy, Clone, Debug, Serialize, Deserialize, Default)]
pub struct TimeOfDay(pub f64);
/// A resource that stores the tick (i.e: physics) time.
#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize)]
pub struct Time(pub f64);
/// A resource that stores the time since the previous tick.
#[derive(Default)]
pub struct DeltaTime(pub f32);

View File

@ -1,9 +1,11 @@
use crate::{ use crate::{
comp::{beam, Body, CharacterState, EnergyChange, EnergySource, Ori, Pos, StateUpdate}, comp::{beam, Body, CharacterState, EnergyChange, EnergySource, Ori, Pos, StateUpdate},
event::ServerEvent, event::ServerEvent,
states::utils::*, states::{
behavior::{CharacterBehavior, JoinData},
utils::*,
},
sync::Uid, sync::Uid,
sys::character_behavior::{CharacterBehavior, JoinData},
Damage, DamageSource, GroupTarget, Damage, DamageSource, GroupTarget,
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};

View File

@ -1,7 +1,7 @@
use super::utils::*; use super::utils::*;
use crate::{ use crate::{
comp::StateUpdate, comp::StateUpdate,
sys::character_behavior::{CharacterBehavior, JoinData}, states::behavior::{CharacterBehavior, JoinData},
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};

View File

@ -1,7 +1,9 @@
use crate::{ use crate::{
comp::{Attacking, CharacterState, EnergyChange, EnergySource, StateUpdate}, comp::{Attacking, CharacterState, EnergyChange, EnergySource, StateUpdate},
states::utils::*, states::{
sys::character_behavior::{CharacterBehavior, JoinData}, behavior::{CharacterBehavior, JoinData},
utils::*,
},
Damage, DamageSource, GroupTarget, Knockback, Damage, DamageSource, GroupTarget, Knockback,
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};

View File

@ -1,8 +1,10 @@
use crate::{ use crate::{
comp::{Body, CharacterState, Gravity, LightEmitter, ProjectileConstructor, StateUpdate}, comp::{Body, CharacterState, Gravity, LightEmitter, ProjectileConstructor, StateUpdate},
event::ServerEvent, event::ServerEvent,
states::utils::*, states::{
sys::character_behavior::{CharacterBehavior, JoinData}, behavior::{CharacterBehavior, JoinData},
utils::*,
},
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::time::Duration; use std::time::Duration;

View File

@ -0,0 +1,109 @@
use crate::{
comp::{
Attacking, Beam, Body, CharacterState, ControlAction, Controller, ControllerInputs, Energy,
Health, Loadout, Ori, PhysicsState, Pos, StateUpdate, Vel,
},
resources::DeltaTime,
sync::Uid,
};
use specs::{
hibitset,
storage::{PairedStorage, SequentialRestriction},
Entity, FlaggedStorage, LazyUpdate,
};
use specs_idvs::IdvStorage;
pub trait CharacterBehavior {
fn behavior(&self, data: &JoinData) -> StateUpdate;
// Impl these to provide behavior for these inputs
fn swap_loadout(&self, data: &JoinData) -> StateUpdate { StateUpdate::from(data) }
fn wield(&self, data: &JoinData) -> StateUpdate { StateUpdate::from(data) }
fn glide_wield(&self, data: &JoinData) -> StateUpdate { StateUpdate::from(data) }
fn unwield(&self, data: &JoinData) -> StateUpdate { StateUpdate::from(data) }
fn sit(&self, data: &JoinData) -> StateUpdate { StateUpdate::from(data) }
fn dance(&self, data: &JoinData) -> StateUpdate { StateUpdate::from(data) }
fn sneak(&self, data: &JoinData) -> StateUpdate { StateUpdate::from(data) }
fn stand(&self, data: &JoinData) -> StateUpdate { StateUpdate::from(data) }
fn handle_event(&self, data: &JoinData, event: ControlAction) -> StateUpdate {
match event {
ControlAction::SwapLoadout => self.swap_loadout(data),
ControlAction::Wield => self.wield(data),
ControlAction::GlideWield => self.glide_wield(data),
ControlAction::Unwield => self.unwield(data),
ControlAction::Sit => self.sit(data),
ControlAction::Dance => self.dance(data),
ControlAction::Sneak => self.sneak(data),
ControlAction::Stand => self.stand(data),
}
}
// fn init(data: &JoinData) -> CharacterState;
}
/// Read-Only Data sent from Character Behavior System to behavior fn's
pub struct JoinData<'a> {
pub entity: Entity,
pub uid: &'a Uid,
pub character: &'a CharacterState,
pub pos: &'a Pos,
pub vel: &'a Vel,
pub ori: &'a Ori,
pub dt: &'a DeltaTime,
pub controller: &'a Controller,
pub inputs: &'a ControllerInputs,
pub health: &'a Health,
pub energy: &'a Energy,
pub loadout: &'a Loadout,
pub body: &'a Body,
pub physics: &'a PhysicsState,
pub attacking: Option<&'a Attacking>,
pub updater: &'a LazyUpdate,
}
type RestrictedMut<'a, C> = PairedStorage<
'a,
'a,
C,
&'a mut FlaggedStorage<C, IdvStorage<C>>,
&'a hibitset::BitSet,
SequentialRestriction,
>;
pub type JoinTuple<'a> = (
Entity,
&'a Uid,
RestrictedMut<'a, CharacterState>,
&'a mut Pos,
&'a mut Vel,
&'a mut Ori,
RestrictedMut<'a, Energy>,
RestrictedMut<'a, Loadout>,
&'a mut Controller,
&'a Health,
&'a Body,
&'a PhysicsState,
Option<&'a Attacking>,
Option<&'a Beam>,
);
impl<'a> JoinData<'a> {
pub fn new(j: &'a JoinTuple<'a>, updater: &'a LazyUpdate, dt: &'a DeltaTime) -> Self {
Self {
entity: j.0,
uid: j.1,
character: j.2.get_unchecked(),
pos: j.3,
vel: j.4,
ori: j.5,
energy: j.6.get_unchecked(),
loadout: j.7.get_unchecked(),
controller: j.8,
inputs: &j.8.inputs,
health: j.9,
body: j.10,
physics: j.11,
attacking: j.12,
updater,
dt,
}
}
}

View File

@ -1,7 +1,9 @@
use crate::{ use crate::{
comp::{CharacterState, StateUpdate}, comp::{CharacterState, StateUpdate},
states::utils::*, states::{
sys::character_behavior::{CharacterBehavior, JoinData}, behavior::{CharacterBehavior, JoinData},
utils::*,
},
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::time::Duration; use std::time::Duration;

View File

@ -1,7 +1,9 @@
use crate::{ use crate::{
comp::{Attacking, CharacterState, EnergyChange, EnergySource, StateUpdate}, comp::{Attacking, CharacterState, EnergyChange, EnergySource, StateUpdate},
states::utils::{StageSection, *}, states::{
sys::character_behavior::*, behavior::{CharacterBehavior, JoinData},
utils::{StageSection, *},
},
Damage, DamageSource, GroupTarget, Knockback, Damage, DamageSource, GroupTarget, Knockback,
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};

View File

@ -6,8 +6,10 @@ use crate::{
}, },
effect::BuffEffect, effect::BuffEffect,
event::ServerEvent, event::ServerEvent,
states::utils::*, states::{
sys::character_behavior::{CharacterBehavior, JoinData}, behavior::{CharacterBehavior, JoinData},
utils::*,
},
Damage, DamageSource, GroupTarget, Knockback, Damage, DamageSource, GroupTarget, Knockback,
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};

View File

@ -1,10 +1,8 @@
use crate::{ use crate::{
comp::{CharacterState, Climb, EnergySource, StateUpdate}, comp::{CharacterState, Climb, EnergySource, StateUpdate},
consts::GRAVITY,
event::LocalEvent, event::LocalEvent,
sys::{ states::behavior::{CharacterBehavior, JoinData},
character_behavior::{CharacterBehavior, JoinData},
phys::GRAVITY,
},
util::Dir, util::Dir,
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};

View File

@ -1,7 +1,9 @@
use crate::{ use crate::{
comp::{Attacking, CharacterState, EnergyChange, EnergySource, StateUpdate}, comp::{Attacking, CharacterState, EnergyChange, EnergySource, StateUpdate},
states::utils::*, states::{
sys::character_behavior::{CharacterBehavior, JoinData}, behavior::{CharacterBehavior, JoinData},
utils::*,
},
Damage, DamageSource, GroupTarget, Knockback, Damage, DamageSource, GroupTarget, Knockback,
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};

View File

@ -1,7 +1,7 @@
use super::utils::*; use super::utils::*;
use crate::{ use crate::{
comp::{CharacterState, StateUpdate}, comp::{CharacterState, StateUpdate},
sys::character_behavior::{CharacterBehavior, JoinData}, states::behavior::{CharacterBehavior, JoinData},
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};

View File

@ -1,7 +1,9 @@
use crate::{ use crate::{
comp::{Attacking, CharacterState, EnergyChange, EnergySource, StateUpdate}, comp::{Attacking, CharacterState, EnergyChange, EnergySource, StateUpdate},
states::utils::*, states::{
sys::character_behavior::{CharacterBehavior, JoinData}, behavior::{CharacterBehavior, JoinData},
utils::*,
},
Damage, DamageSource, GroupTarget, Knockback, Damage, DamageSource, GroupTarget, Knockback,
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};

View File

@ -1,7 +1,7 @@
use super::utils::*; use super::utils::*;
use crate::{ use crate::{
comp::{CharacterState, StateUpdate}, comp::{CharacterState, StateUpdate},
sys::character_behavior::{CharacterBehavior, JoinData}, states::behavior::{CharacterBehavior, JoinData},
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::time::Duration; use std::time::Duration;

View File

@ -1,13 +1,13 @@
use super::utils::handle_climb; use super::utils::handle_climb;
use crate::{ use crate::{
comp::{CharacterState, StateUpdate}, comp::{CharacterState, StateUpdate},
sys::character_behavior::{CharacterBehavior, JoinData}, states::behavior::{CharacterBehavior, JoinData},
util::Dir, util::Dir,
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use vek::Vec2; use vek::Vec2;
// Gravity is 9.81 * 4, so this makes gravity equal to .15 // Gravity is 9.81 * 4, so this makes gravity equal to .15
const GLIDE_ANTIGRAV: f32 = crate::sys::phys::GRAVITY * 0.90; const GLIDE_ANTIGRAV: f32 = crate::consts::GRAVITY * 0.90;
const GLIDE_ACCEL: f32 = 12.0; const GLIDE_ACCEL: f32 = 12.0;
const GLIDE_SPEED: f32 = 45.0; const GLIDE_SPEED: f32 = 45.0;

View File

@ -1,7 +1,7 @@
use super::utils::*; use super::utils::*;
use crate::{ use crate::{
comp::{CharacterState, StateUpdate}, comp::{CharacterState, StateUpdate},
sys::character_behavior::{CharacterBehavior, JoinData}, states::behavior::{CharacterBehavior, JoinData},
}; };
pub struct Data; pub struct Data;

View File

@ -1,7 +1,7 @@
use super::utils::*; use super::utils::*;
use crate::{ use crate::{
comp::StateUpdate, comp::StateUpdate,
sys::character_behavior::{CharacterBehavior, JoinData}, states::behavior::{CharacterBehavior, JoinData},
}; };
pub struct Data; pub struct Data;

View File

@ -1,7 +1,9 @@
use crate::{ use crate::{
comp::{Attacking, CharacterState, StateUpdate}, comp::{Attacking, CharacterState, StateUpdate},
states::utils::{StageSection, *}, states::{
sys::character_behavior::{CharacterBehavior, JoinData}, behavior::{CharacterBehavior, JoinData},
utils::{StageSection, *},
},
Damage, DamageSource, GroupTarget, Knockback, Damage, DamageSource, GroupTarget, Knockback,
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};

View File

@ -2,6 +2,7 @@ pub mod basic_beam;
pub mod basic_block; pub mod basic_block;
pub mod basic_melee; pub mod basic_melee;
pub mod basic_ranged; pub mod basic_ranged;
pub mod behavior;
pub mod boost; pub mod boost;
pub mod charged_melee; pub mod charged_melee;
pub mod charged_ranged; pub mod charged_ranged;

View File

@ -1,8 +1,10 @@
use crate::{ use crate::{
comp::{Body, CharacterState, Gravity, LightEmitter, ProjectileConstructor, StateUpdate}, comp::{Body, CharacterState, Gravity, LightEmitter, ProjectileConstructor, StateUpdate},
event::ServerEvent, event::ServerEvent,
states::utils::{StageSection, *}, states::{
sys::character_behavior::*, behavior::{CharacterBehavior, JoinData},
utils::{StageSection, *},
},
util::dir::*, util::dir::*,
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};

View File

@ -1,7 +1,9 @@
use crate::{ use crate::{
comp::{CharacterState, StateUpdate}, comp::{CharacterState, StateUpdate},
states::utils::*, states::{
sys::character_behavior::{CharacterBehavior, JoinData}, behavior::{CharacterBehavior, JoinData},
utils::*,
},
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::time::Duration; use std::time::Duration;

View File

@ -1,8 +1,10 @@
use crate::{ use crate::{
comp::{shockwave, CharacterState, StateUpdate}, comp::{shockwave, CharacterState, StateUpdate},
event::ServerEvent, event::ServerEvent,
states::utils::*, states::{
sys::character_behavior::{CharacterBehavior, JoinData}, behavior::{CharacterBehavior, JoinData},
utils::*,
},
Damage, DamageSource, GroupTarget, Knockback, Damage, DamageSource, GroupTarget, Knockback,
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};

View File

@ -1,7 +1,7 @@
use super::utils::*; use super::utils::*;
use crate::{ use crate::{
comp::{CharacterState, StateUpdate}, comp::{CharacterState, StateUpdate},
sys::character_behavior::{CharacterBehavior, JoinData}, states::behavior::{CharacterBehavior, JoinData},
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};

View File

@ -1,7 +1,7 @@
use super::utils::*; use super::utils::*;
use crate::{ use crate::{
comp::{CharacterState, StateUpdate}, comp::{CharacterState, StateUpdate},
sys::character_behavior::{CharacterBehavior, JoinData}, states::behavior::{CharacterBehavior, JoinData},
}; };
pub struct Data; pub struct Data;

View File

@ -1,9 +1,9 @@
use crate::{ use crate::{
comp::{Attacking, CharacterState, EnergyChange, EnergySource, StateUpdate}, comp::{Attacking, CharacterState, EnergyChange, EnergySource, StateUpdate},
states::utils::*, consts::GRAVITY,
sys::{ states::{
character_behavior::{CharacterBehavior, JoinData}, behavior::{CharacterBehavior, JoinData},
phys::GRAVITY, utils::*,
}, },
Damage, DamageSource, GroupTarget, Knockback, Damage, DamageSource, GroupTarget, Knockback,
}; };

View File

@ -3,12 +3,9 @@ use crate::{
item::{Hands, ItemKind, Tool}, item::{Hands, ItemKind, Tool},
quadruped_low, quadruped_medium, theropod, Body, CharacterState, StateUpdate, quadruped_low, quadruped_medium, theropod, Body, CharacterState, StateUpdate,
}, },
consts::{FRIC_GROUND, GRAVITY},
event::LocalEvent, event::LocalEvent,
states::*, states::{behavior::JoinData, *},
sys::{
character_behavior::JoinData,
phys::{FRIC_GROUND, GRAVITY},
},
util::Dir, util::Dir,
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};

View File

@ -1,7 +1,7 @@
use super::utils::*; use super::utils::*;
use crate::{ use crate::{
comp::{CharacterState, StateUpdate}, comp::{CharacterState, StateUpdate},
sys::character_behavior::{CharacterBehavior, JoinData}, states::behavior::{CharacterBehavior, JoinData},
}; };
pub struct Data; pub struct Data;

34
common/state/Cargo.toml Normal file
View File

@ -0,0 +1,34 @@
[package]
authors = ["Marcel Märtens <marcel.cochem@googlemail.com>"]
edition = "2018"
name = "veloren_common_state"
version = "0.8.0"
[lib]
name = "common_state"
[features]
tracy = ["tracy-client"]
simd = ["vek/platform_intrinsics"]
default = ["simd"]
[dependencies]
common = {package = "veloren-common", path = "../../common"}
common_sys = {package = "veloren_common_sys", path = "../../common/sys"}
rand = "0.7"
rayon = "1.3.0"
tracing = { version = "0.1", default-features = false }
vek = { version = "0.12.0", features = ["serde"] }
# Data structures
hashbrown = { version = "0.7.2", features = ["rayon", "serde", "nightly"] }
indexmap = "1.3.0"
slab = "0.4.2"
# ECS
specs = { git = "https://github.com/amethyst/specs.git", features = ["serde", "storage-event-control"], rev = "7a2e348ab2223818bad487695c66c43db88050a5" }
# Tracy
tracy-client = { version = "0.9.0", optional = true }

View File

@ -1,18 +1,17 @@
use crate::{ use common::{
comp, comp,
event::{EventBus, LocalEvent, ServerEvent}, event::{EventBus, LocalEvent, ServerEvent},
metrics::{PhysicsMetrics, SysMetrics}, metrics::{PhysicsMetrics, SysMetrics},
region::RegionMap, region::RegionMap,
resources::{DeltaTime, Time, TimeOfDay},
span, span,
sync::WorldSyncExt, sync::WorldSyncExt,
sys,
terrain::{Block, TerrainChunk, TerrainGrid}, terrain::{Block, TerrainChunk, TerrainGrid},
time::DayPeriod, time::DayPeriod,
vol::{ReadVol, WriteVol}, vol::{ReadVol, WriteVol},
}; };
use hashbrown::{HashMap, HashSet}; use hashbrown::{HashMap, HashSet};
use rayon::{ThreadPool, ThreadPoolBuilder}; use rayon::{ThreadPool, ThreadPoolBuilder};
use serde::{Deserialize, Serialize};
use specs::{ use specs::{
shred::{Fetch, FetchMut}, shred::{Fetch, FetchMut},
storage::{MaskedStorage as EcsMaskedStorage, Storage as EcsStorage}, storage::{MaskedStorage as EcsMaskedStorage, Storage as EcsStorage},
@ -25,18 +24,6 @@ use vek::*;
// TODO: Don't hard-code this. // TODO: Don't hard-code this.
const DAY_CYCLE_FACTOR: f64 = 24.0 * 2.0; const DAY_CYCLE_FACTOR: f64 = 24.0 * 2.0;
/// A resource that stores the time of day.
#[derive(Copy, Clone, Debug, Serialize, Deserialize, Default)]
pub struct TimeOfDay(pub f64);
/// A resource that stores the tick (i.e: physics) time.
#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize)]
pub struct Time(pub f64);
/// A resource that stores the time since the previous tick.
#[derive(Default)]
pub struct DeltaTime(pub f32);
/// At what point should we stop speeding up physics to compensate for lag? If /// At what point should we stop speeding up physics to compensate for lag? If
/// we speed physics up too fast, we'd skip important physics events like /// we speed physics up too fast, we'd skip important physics events like
/// collisions. This constant determines the upper limit. If delta time exceeds /// collisions. This constant determines the upper limit. If delta time exceeds
@ -380,7 +367,7 @@ impl State {
// Create and run a dispatcher for ecs systems. // Create and run a dispatcher for ecs systems.
let mut dispatch_builder = let mut dispatch_builder =
DispatcherBuilder::new().with_pool(Arc::clone(&self.thread_pool)); DispatcherBuilder::new().with_pool(Arc::clone(&self.thread_pool));
sys::add_local_systems(&mut dispatch_builder); common_sys::add_local_systems(&mut dispatch_builder);
// TODO: Consider alternative ways to do this // TODO: Consider alternative ways to do this
add_foreign_systems(&mut dispatch_builder); add_foreign_systems(&mut dispatch_builder);
// This dispatches all the systems in parallel. // This dispatches all the systems in parallel.

31
common/sys/Cargo.toml Normal file
View File

@ -0,0 +1,31 @@
[package]
authors = ["Marcel Märtens <marcel.cochem@googlemail.com>"]
edition = "2018"
name = "veloren_common_sys"
version = "0.8.0"
[lib]
name = "common_sys"
[features]
tracy = ["tracy-client"]
simd = ["vek/platform_intrinsics"]
default = ["simd"]
[dependencies]
common = {package = "veloren-common", path = "../../common"}
rand = "0.7"
rayon = "1.3.0"
tracing = { version = "0.1", default-features = false }
vek = { version = "0.12.0", features = ["serde"] }
# ECS
specs = { git = "https://github.com/amethyst/specs.git", features = ["serde", "storage-event-control"], rev = "7a2e348ab2223818bad487695c66c43db88050a5" }
# Serde
serde = { version = "1.0.110", features = ["derive"] }
# Tracy
tracy-client = { version = "0.9.0", optional = true }

View File

@ -1,4 +1,4 @@
use crate::{ use common::{
comp::{ comp::{
self, self,
agent::Activity, agent::Activity,
@ -15,8 +15,8 @@ use crate::{
event::{EventBus, ServerEvent}, event::{EventBus, ServerEvent},
metrics::SysMetrics, metrics::SysMetrics,
path::{Chaser, TraversalConfig}, path::{Chaser, TraversalConfig},
resources::{DeltaTime, Time, TimeOfDay},
span, span,
state::{DeltaTime, Time, TimeOfDay},
sync::{Uid, UidAllocator}, sync::{Uid, UidAllocator},
terrain::{Block, TerrainGrid}, terrain::{Block, TerrainGrid},
time::DayPeriod, time::DayPeriod,

View File

@ -1,10 +1,10 @@
use crate::{ use common::{
comp::{ comp::{
group, Beam, BeamSegment, Body, Energy, EnergyChange, EnergySource, Health, HealthChange, group, Beam, BeamSegment, Body, Energy, EnergyChange, EnergySource, Health, HealthChange,
HealthSource, Last, Loadout, Ori, Pos, Scale, HealthSource, Last, Loadout, Ori, Pos, Scale,
}, },
event::{EventBus, ServerEvent}, event::{EventBus, ServerEvent},
state::{DeltaTime, Time}, resources::{DeltaTime, Time},
sync::{Uid, UidAllocator}, sync::{Uid, UidAllocator},
GroupTarget, GroupTarget,
}; };

View File

@ -1,10 +1,10 @@
use crate::{ use common::{
comp::{ comp::{
BuffCategory, BuffChange, BuffEffect, BuffId, BuffSource, Buffs, Health, HealthChange, BuffCategory, BuffChange, BuffEffect, BuffId, BuffSource, Buffs, Health, HealthChange,
HealthSource, Loadout, ModifierKind, HealthSource, Loadout, ModifierKind,
}, },
event::{EventBus, ServerEvent}, event::{EventBus, ServerEvent},
state::DeltaTime, resources::DeltaTime,
DamageSource, DamageSource,
}; };
use specs::{Entities, Join, Read, ReadStorage, System, WriteStorage}; use specs::{Entities, Join, Read, ReadStorage, System, WriteStorage};

View File

@ -1,96 +1,20 @@
use crate::{ use common::{
comp::{ comp::{
Attacking, Beam, Body, CharacterState, ControlAction, Controller, ControllerInputs, Energy, Attacking, Beam, Body, CharacterState, Controller, Energy, Health, Loadout, Mounting, Ori,
Health, Loadout, Mounting, Ori, PhysicsState, Pos, StateUpdate, Vel, PhysicsState, Pos, StateUpdate, Vel,
}, },
event::{EventBus, LocalEvent, ServerEvent}, event::{EventBus, LocalEvent, ServerEvent},
metrics::SysMetrics, metrics::SysMetrics,
resources::DeltaTime,
span, span,
state::DeltaTime, states::{
states, self,
behavior::{CharacterBehavior, JoinData, JoinTuple},
},
sync::{Uid, UidAllocator}, sync::{Uid, UidAllocator},
}; };
use specs::{ use specs::{Entities, Join, LazyUpdate, Read, ReadExpect, ReadStorage, System, WriteStorage};
hibitset,
storage::{PairedStorage, SequentialRestriction},
Entities, Entity, FlaggedStorage, Join, LazyUpdate, Read, ReadExpect, ReadStorage, System,
WriteStorage,
};
use specs_idvs::IdvStorage;
// use std::collections::VecDeque;
pub trait CharacterBehavior {
fn behavior(&self, data: &JoinData) -> StateUpdate;
// Impl these to provide behavior for these inputs
fn swap_loadout(&self, data: &JoinData) -> StateUpdate { StateUpdate::from(data) }
fn wield(&self, data: &JoinData) -> StateUpdate { StateUpdate::from(data) }
fn glide_wield(&self, data: &JoinData) -> StateUpdate { StateUpdate::from(data) }
fn unwield(&self, data: &JoinData) -> StateUpdate { StateUpdate::from(data) }
fn sit(&self, data: &JoinData) -> StateUpdate { StateUpdate::from(data) }
fn dance(&self, data: &JoinData) -> StateUpdate { StateUpdate::from(data) }
fn sneak(&self, data: &JoinData) -> StateUpdate { StateUpdate::from(data) }
fn stand(&self, data: &JoinData) -> StateUpdate { StateUpdate::from(data) }
fn handle_event(&self, data: &JoinData, event: ControlAction) -> StateUpdate {
match event {
ControlAction::SwapLoadout => self.swap_loadout(data),
ControlAction::Wield => self.wield(data),
ControlAction::GlideWield => self.glide_wield(data),
ControlAction::Unwield => self.unwield(data),
ControlAction::Sit => self.sit(data),
ControlAction::Dance => self.dance(data),
ControlAction::Sneak => self.sneak(data),
ControlAction::Stand => self.stand(data),
}
}
// fn init(data: &JoinData) -> CharacterState;
}
/// Read-Only Data sent from Character Behavior System to behavior fn's
pub struct JoinData<'a> {
pub entity: Entity,
pub uid: &'a Uid,
pub character: &'a CharacterState,
pub pos: &'a Pos,
pub vel: &'a Vel,
pub ori: &'a Ori,
pub dt: &'a DeltaTime,
pub controller: &'a Controller,
pub inputs: &'a ControllerInputs,
pub health: &'a Health,
pub energy: &'a Energy,
pub loadout: &'a Loadout,
pub body: &'a Body,
pub physics: &'a PhysicsState,
pub attacking: Option<&'a Attacking>,
pub updater: &'a LazyUpdate,
}
type RestrictedMut<'a, C> = PairedStorage<
'a,
'a,
C,
&'a mut FlaggedStorage<C, IdvStorage<C>>,
&'a hibitset::BitSet,
SequentialRestriction,
>;
pub type JoinTuple<'a> = (
Entity,
&'a Uid,
RestrictedMut<'a, CharacterState>,
&'a mut Pos,
&'a mut Vel,
&'a mut Ori,
RestrictedMut<'a, Energy>,
RestrictedMut<'a, Loadout>,
&'a mut Controller,
&'a Health,
&'a Body,
&'a PhysicsState,
Option<&'a Attacking>,
Option<&'a Beam>,
);
fn incorporate_update(tuple: &mut JoinTuple, state_update: StateUpdate) { fn incorporate_update(tuple: &mut JoinTuple, state_update: StateUpdate) {
// TODO: if checking equality is expensive use optional field in StateUpdate // TODO: if checking equality is expensive use optional field in StateUpdate
@ -110,29 +34,6 @@ fn incorporate_update(tuple: &mut JoinTuple, state_update: StateUpdate) {
} }
} }
impl<'a> JoinData<'a> {
fn new(j: &'a JoinTuple<'a>, updater: &'a LazyUpdate, dt: &'a DeltaTime) -> Self {
Self {
entity: j.0,
uid: j.1,
character: j.2.get_unchecked(),
pos: j.3,
vel: j.4,
ori: j.5,
energy: j.6.get_unchecked(),
loadout: j.7.get_unchecked(),
controller: j.8,
inputs: &j.8.inputs,
health: j.9,
body: j.10,
physics: j.11,
attacking: j.12,
updater,
dt,
}
}
}
/// ## Character Behavior System /// ## Character Behavior System
/// Passes `JoinData` to `CharacterState`'s `behavior` handler fn's. Receives a /// Passes `JoinData` to `CharacterState`'s `behavior` handler fn's. Receives a
/// `StateUpdate` in return and performs updates to ECS Components from that. /// `StateUpdate` in return and performs updates to ECS Components from that.

View File

@ -1,12 +1,12 @@
use crate::{ use common::{
comp::{ comp::{
slot::{EquipSlot, Slot}, slot::{EquipSlot, Slot},
BuffChange, CharacterState, ControlEvent, Controller, InventoryManip, BuffChange, CharacterState, ControlEvent, Controller, InventoryManip,
}, },
event::{EventBus, LocalEvent, ServerEvent}, event::{EventBus, LocalEvent, ServerEvent},
metrics::SysMetrics, metrics::SysMetrics,
resources::DeltaTime,
span, span,
state::DeltaTime,
sync::{Uid, UidAllocator}, sync::{Uid, UidAllocator},
}; };
use specs::{ use specs::{

View File

@ -1,3 +1,5 @@
#![feature(label_break_value, bool_to_option)]
pub mod agent; pub mod agent;
mod beam; mod beam;
mod buff; mod buff;

View File

@ -1,4 +1,4 @@
use crate::{ use common::{
comp::{buff, group, Attacking, Body, CharacterState, Health, Loadout, Ori, Pos, Scale}, comp::{buff, group, Attacking, Body, CharacterState, Health, Loadout, Ori, Pos, Scale},
event::{EventBus, LocalEvent, ServerEvent}, event::{EventBus, LocalEvent, ServerEvent},
metrics::SysMetrics, metrics::SysMetrics,

View File

@ -1,4 +1,4 @@
use crate::{ use common::{
comp::{Controller, MountState, Mounting, Ori, Pos, Vel}, comp::{Controller, MountState, Mounting, Ori, Pos, Vel},
metrics::SysMetrics, metrics::SysMetrics,
span, span,
@ -66,12 +66,12 @@ impl<'a> System<'a> for Sys {
let _ = orientations.insert(mounter, ori); let _ = orientations.insert(mounter, ori);
let _ = velocities.insert(mounter, vel); let _ = velocities.insert(mounter, vel);
} }
controllers.get_mut(entity).map(|controller| { if let Some(controller) = controllers.get_mut(entity) {
*controller = Controller { *controller = Controller {
inputs, inputs,
..Default::default() ..Default::default()
} }
}); }
} else { } else {
*(mount_states.get_mut_unchecked()) = MountState::Unmounted; *(mount_states.get_mut_unchecked()) = MountState::Unmounted;
} }

View File

@ -1,12 +1,13 @@
use crate::{ use common::{
comp::{ comp::{
BeamSegment, CharacterState, Collider, Gravity, Mass, Mounting, Ori, PhysicsState, Pos, BeamSegment, CharacterState, Collider, Gravity, Mass, Mounting, Ori, PhysicsState, Pos,
PreviousVelDtCache, Projectile, Scale, Shockwave, Sticky, Vel, PreviousVelDtCache, Projectile, Scale, Shockwave, Sticky, Vel,
}, },
consts::{FRIC_GROUND, GRAVITY},
event::{EventBus, ServerEvent}, event::{EventBus, ServerEvent},
metrics::{PhysicsMetrics, SysMetrics}, metrics::{PhysicsMetrics, SysMetrics},
resources::DeltaTime,
span, span,
state::DeltaTime,
sync::Uid, sync::Uid,
terrain::{Block, TerrainGrid}, terrain::{Block, TerrainGrid},
vol::ReadVol, vol::ReadVol,
@ -18,7 +19,6 @@ use specs::{
use std::ops::Range; use std::ops::Range;
use vek::*; use vek::*;
pub const GRAVITY: f32 = 9.81 * 5.0;
pub const BOUYANCY: f32 = 1.0; pub const BOUYANCY: f32 = 1.0;
// Friction values used for linear damping. They are unitless quantities. The // Friction values used for linear damping. They are unitless quantities. The
// value of these quantities must be between zero and one. They represent the // value of these quantities must be between zero and one. They represent the
@ -26,7 +26,6 @@ pub const BOUYANCY: f32 = 1.0;
// friction is 0.01, and the speed is 1.0, then after 1/60th of a second the // friction is 0.01, and the speed is 1.0, then after 1/60th of a second the
// speed will be 0.99. after 1 second the speed will be 0.54, which is 0.99 ^ // speed will be 0.99. after 1 second the speed will be 0.54, which is 0.99 ^
// 60. // 60.
pub const FRIC_GROUND: f32 = 0.15;
pub const FRIC_AIR: f32 = 0.0125; pub const FRIC_AIR: f32 = 0.0125;
pub const FRIC_FLUID: f32 = 0.4; pub const FRIC_FLUID: f32 = 0.4;

View File

@ -1,4 +1,4 @@
use crate::{ use common::{
comp::{ comp::{
buff::{Buff, BuffChange, BuffSource}, buff::{Buff, BuffChange, BuffSource},
projectile, EnergyChange, EnergySource, Group, HealthSource, Loadout, Ori, PhysicsState, projectile, EnergyChange, EnergySource, Group, HealthSource, Loadout, Ori, PhysicsState,
@ -6,8 +6,8 @@ use crate::{
}, },
event::{EventBus, ServerEvent}, event::{EventBus, ServerEvent},
metrics::SysMetrics, metrics::SysMetrics,
resources::DeltaTime,
span, span,
state::DeltaTime,
sync::UidAllocator, sync::UidAllocator,
GroupTarget, GroupTarget,
}; };

View File

@ -1,10 +1,10 @@
use crate::{ use common::{
comp::{ comp::{
group, Body, Health, HealthSource, Last, Loadout, Ori, PhysicsState, Pos, Scale, Shockwave, group, Body, Health, HealthSource, Last, Loadout, Ori, PhysicsState, Pos, Scale, Shockwave,
ShockwaveHitEntities, ShockwaveHitEntities,
}, },
event::{EventBus, LocalEvent, ServerEvent}, event::{EventBus, LocalEvent, ServerEvent},
state::{DeltaTime, Time}, resources::{DeltaTime, Time},
sync::{Uid, UidAllocator}, sync::{Uid, UidAllocator},
util::Dir, util::Dir,
GroupTarget, GroupTarget,

View File

@ -1,9 +1,9 @@
use crate::{ use common::{
comp::{CharacterState, Energy, EnergyChange, EnergySource, Health, HealthSource, Stats}, comp::{CharacterState, Energy, EnergyChange, EnergySource, Health, HealthSource, Stats},
event::{EventBus, ServerEvent}, event::{EventBus, ServerEvent},
metrics::SysMetrics, metrics::SysMetrics,
resources::DeltaTime,
span, span,
state::DeltaTime,
}; };
use specs::{Entities, Join, Read, ReadExpect, ReadStorage, System, WriteStorage}; use specs::{Entities, Join, Read, ReadExpect, ReadStorage, System, WriteStorage};

View File

@ -12,6 +12,8 @@ default = ["worldgen", "simd"]
[dependencies] [dependencies]
common = { package = "veloren-common", path = "../common" } common = { package = "veloren-common", path = "../common" }
common_state = { package = "veloren_common_state", path = "../common/state" }
common_sys = { package = "veloren_common_sys", path = "../common/sys" }
world = { package = "veloren-world", path = "../world" } world = { package = "veloren-world", path = "../world" }
network = { package = "veloren_network", path = "../network", features = ["metrics", "compression"], default-features = false } network = { package = "veloren_network", path = "../network", features = ["metrics", "compression"], default-features = false }

View File

@ -14,7 +14,7 @@ use common::{
event::{EventBus, ServerEvent}, event::{EventBus, ServerEvent},
msg::{DisconnectReason, Notification, PlayerListUpdate, ServerGeneral}, msg::{DisconnectReason, Notification, PlayerListUpdate, ServerGeneral},
npc::{self, get_npc_name}, npc::{self, get_npc_name},
state::TimeOfDay, resources::TimeOfDay,
sync::{Uid, WorldSyncExt}, sync::{Uid, WorldSyncExt},
terrain::{Block, BlockKind, SpriteKind, TerrainChunkSize}, terrain::{Block, BlockKind, SpriteKind, TerrainChunkSize},
util::Dir, util::Dir,
@ -374,7 +374,10 @@ fn handle_home(
.is_some() .is_some()
{ {
let home_pos = server.state.ecs().read_resource::<SpawnPoint>().0; let home_pos = server.state.ecs().read_resource::<SpawnPoint>().0;
let time = *server.state.ecs().read_resource::<common::state::Time>(); let time = *server
.state
.ecs()
.read_resource::<common::resources::Time>();
server.state.write_component(target, comp::Pos(home_pos)); server.state.write_component(target, comp::Pos(home_pos));
server server

View File

@ -17,12 +17,12 @@ use common::{
msg::{PlayerListUpdate, ServerGeneral}, msg::{PlayerListUpdate, ServerGeneral},
outcome::Outcome, outcome::Outcome,
rtsim::RtSimEntity, rtsim::RtSimEntity,
state::BlockChange,
sync::{Uid, UidAllocator, WorldSyncExt}, sync::{Uid, UidAllocator, WorldSyncExt},
terrain::{Block, TerrainGrid}, terrain::{Block, TerrainGrid},
vol::ReadVol, vol::ReadVol,
Damage, DamageSource, Explosion, GroupTarget, RadiusEffect, Damage, DamageSource, Explosion, GroupTarget, RadiusEffect,
}; };
use common_state::BlockChange;
use comp::item::Reagent; use comp::item::Reagent;
use rand::prelude::*; use rand::prelude::*;
use specs::{join::Join, saveload::MarkerAllocator, Entity as EcsEntity, WorldExt}; use specs::{join::Join, saveload::MarkerAllocator, Entity as EcsEntity, WorldExt};

View File

@ -11,6 +11,7 @@ use common::{
util::find_dist::{self, FindDist}, util::find_dist::{self, FindDist},
vol::ReadVol, vol::ReadVol,
}; };
use common_state::State;
use comp::LightEmitter; use comp::LightEmitter;
use rand::Rng; use rand::Rng;
use specs::{join::Join, world::WorldExt, Builder, Entity as EcsEntity, WriteStorage}; use specs::{join::Join, world::WorldExt, Builder, Entity as EcsEntity, WriteStorage};
@ -39,7 +40,7 @@ pub fn handle_inventory(server: &mut Server, entity: EcsEntity, manip: comp::Inv
let mut dropped_items = Vec::new(); let mut dropped_items = Vec::new();
let mut thrown_items = Vec::new(); let mut thrown_items = Vec::new();
let get_cylinder = |state: &common::state::State, entity| { let get_cylinder = |state: &State, entity| {
let ecs = state.ecs(); let ecs = state.ecs();
let positions = ecs.read_storage::<comp::Pos>(); let positions = ecs.read_storage::<comp::Pos>();
let scales = ecs.read_storage::<comp::Scale>(); let scales = ecs.read_storage::<comp::Scale>();

View File

@ -8,9 +8,9 @@ use common::{
comp::{group, Player}, comp::{group, Player},
msg::{PlayerListUpdate, PresenceKind, ServerGeneral}, msg::{PlayerListUpdate, PresenceKind, ServerGeneral},
span, span,
state::State,
sync::{Uid, UidAllocator}, sync::{Uid, UidAllocator},
}; };
use common_state::State;
use futures_executor::block_on; use futures_executor::block_on;
use specs::{saveload::MarkerAllocator, Builder, Entity as EcsEntity, WorldExt}; use specs::{saveload::MarkerAllocator, Builder, Entity as EcsEntity, WorldExt};
use tracing::{debug, error, trace, warn}; use tracing::{debug, error, trace, warn};

View File

@ -56,12 +56,13 @@ use common::{
}, },
outcome::Outcome, outcome::Outcome,
recipe::default_recipe_book, recipe::default_recipe_book,
resources::TimeOfDay,
rtsim::RtSimEntity, rtsim::RtSimEntity,
state::{State, TimeOfDay},
sync::WorldSyncExt, sync::WorldSyncExt,
terrain::TerrainChunkSize, terrain::TerrainChunkSize,
vol::{ReadVol, RectVolSize}, vol::{ReadVol, RectVolSize},
}; };
use common_state::State;
use futures_executor::block_on; use futures_executor::block_on;
use metrics::{PhysicsMetrics, ServerMetrics, StateTickMetrics, TickMetrics}; use metrics::{PhysicsMetrics, ServerMetrics, StateTickMetrics, TickMetrics};
use network::{Network, Pid, ProtocolAddr}; use network::{Network, Pid, ProtocolAddr};
@ -806,40 +807,39 @@ impl Server {
let projectile_ns = res.projectile_ns.load(Ordering::Relaxed); let projectile_ns = res.projectile_ns.load(Ordering::Relaxed);
let melee_ns = res.melee_ns.load(Ordering::Relaxed); let melee_ns = res.melee_ns.load(Ordering::Relaxed);
c.with_label_values(&[common::sys::AGENT_SYS]) c.with_label_values(&[common_sys::AGENT_SYS])
.inc_by(agent_ns); .inc_by(agent_ns);
c.with_label_values(&[common::sys::MOUNT_SYS]) c.with_label_values(&[common_sys::MOUNT_SYS])
.inc_by(mount_ns); .inc_by(mount_ns);
c.with_label_values(&[common::sys::CONTROLLER_SYS]) c.with_label_values(&[common_sys::CONTROLLER_SYS])
.inc_by(controller_ns); .inc_by(controller_ns);
c.with_label_values(&[common::sys::CHARACTER_BEHAVIOR_SYS]) c.with_label_values(&[common_sys::CHARACTER_BEHAVIOR_SYS])
.inc_by(character_behavior_ns); .inc_by(character_behavior_ns);
c.with_label_values(&[common::sys::STATS_SYS]) c.with_label_values(&[common_sys::STATS_SYS])
.inc_by(stats_ns); .inc_by(stats_ns);
c.with_label_values(&[common::sys::PHYS_SYS]) c.with_label_values(&[common_sys::PHYS_SYS]).inc_by(phys_ns);
.inc_by(phys_ns); c.with_label_values(&[common_sys::PROJECTILE_SYS])
c.with_label_values(&[common::sys::PROJECTILE_SYS])
.inc_by(projectile_ns); .inc_by(projectile_ns);
c.with_label_values(&[common::sys::MELEE_SYS]) c.with_label_values(&[common_sys::MELEE_SYS])
.inc_by(melee_ns); .inc_by(melee_ns);
const NANOSEC_PER_SEC: f64 = Duration::from_secs(1).as_nanos() as f64; const NANOSEC_PER_SEC: f64 = Duration::from_secs(1).as_nanos() as f64;
let h = &self.state_tick_metrics.state_tick_time_hist; let h = &self.state_tick_metrics.state_tick_time_hist;
h.with_label_values(&[common::sys::AGENT_SYS]) h.with_label_values(&[common_sys::AGENT_SYS])
.observe(agent_ns as f64 / NANOSEC_PER_SEC); .observe(agent_ns as f64 / NANOSEC_PER_SEC);
h.with_label_values(&[common::sys::MOUNT_SYS]) h.with_label_values(&[common_sys::MOUNT_SYS])
.observe(mount_ns as f64 / NANOSEC_PER_SEC); .observe(mount_ns as f64 / NANOSEC_PER_SEC);
h.with_label_values(&[common::sys::CONTROLLER_SYS]) h.with_label_values(&[common_sys::CONTROLLER_SYS])
.observe(controller_ns as f64 / NANOSEC_PER_SEC); .observe(controller_ns as f64 / NANOSEC_PER_SEC);
h.with_label_values(&[common::sys::CHARACTER_BEHAVIOR_SYS]) h.with_label_values(&[common_sys::CHARACTER_BEHAVIOR_SYS])
.observe(character_behavior_ns as f64 / NANOSEC_PER_SEC); .observe(character_behavior_ns as f64 / NANOSEC_PER_SEC);
h.with_label_values(&[common::sys::STATS_SYS]) h.with_label_values(&[common_sys::STATS_SYS])
.observe(stats_ns as f64 / NANOSEC_PER_SEC); .observe(stats_ns as f64 / NANOSEC_PER_SEC);
h.with_label_values(&[common::sys::PHYS_SYS]) h.with_label_values(&[common_sys::PHYS_SYS])
.observe(phys_ns as f64 / NANOSEC_PER_SEC); .observe(phys_ns as f64 / NANOSEC_PER_SEC);
h.with_label_values(&[common::sys::PROJECTILE_SYS]) h.with_label_values(&[common_sys::PROJECTILE_SYS])
.observe(projectile_ns as f64 / NANOSEC_PER_SEC); .observe(projectile_ns as f64 / NANOSEC_PER_SEC);
h.with_label_values(&[common::sys::MELEE_SYS]) h.with_label_values(&[common_sys::MELEE_SYS])
.observe(melee_ns as f64 / NANOSEC_PER_SEC); .observe(melee_ns as f64 / NANOSEC_PER_SEC);
} }

View File

@ -11,7 +11,7 @@ use common::{
character::CharacterId, character::CharacterId,
comp::{item::tool::AbilityMap, Body as CompBody, Waypoint, *}, comp::{item::tool::AbilityMap, Body as CompBody, Waypoint, *},
loadout_builder, loadout_builder,
state::Time, resources::Time,
}; };
use core::{convert::TryFrom, num::NonZeroU64}; use core::{convert::TryFrom, num::NonZeroU64};
use itertools::{Either, Itertools}; use itertools::{Either, Itertools};

View File

@ -10,10 +10,10 @@ use self::{chunks::Chunks, entity::Entity};
use common::{ use common::{
comp, comp,
rtsim::{RtSimController, RtSimEntity, RtSimId}, rtsim::{RtSimController, RtSimEntity, RtSimId},
state::State,
terrain::TerrainChunk, terrain::TerrainChunk,
vol::RectRasterableVol, vol::RectRasterableVol,
}; };
use common_state::State;
use rand::prelude::*; use rand::prelude::*;
use slab::Slab; use slab::Slab;
use specs::{DispatcherBuilder, WorldExt}; use specs::{DispatcherBuilder, WorldExt};

View File

@ -4,7 +4,7 @@ use super::*;
use common::{ use common::{
comp, comp,
event::{EventBus, ServerEvent}, event::{EventBus, ServerEvent},
state::DeltaTime, resources::DeltaTime,
terrain::TerrainGrid, terrain::TerrainGrid,
}; };
use specs::{Join, Read, ReadExpect, ReadStorage, System, WriteExpect, WriteStorage}; use specs::{Join, Read, ReadExpect, ReadStorage, System, WriteExpect, WriteStorage};

View File

@ -7,10 +7,10 @@ use common::{
comp, comp,
effect::Effect, effect::Effect,
msg::{CharacterInfo, PlayerListUpdate, PresenceKind, ServerGeneral}, msg::{CharacterInfo, PlayerListUpdate, PresenceKind, ServerGeneral},
state::State,
sync::{Uid, UidAllocator, WorldSyncExt}, sync::{Uid, UidAllocator, WorldSyncExt},
util::Dir, util::Dir,
}; };
use common_state::State;
use rand::prelude::*; use rand::prelude::*;
use specs::{ use specs::{
saveload::MarkerAllocator, Builder, Entity as EcsEntity, EntityBuilder as EcsEntityBuilder, saveload::MarkerAllocator, Builder, Entity as EcsEntity, EntityBuilder as EcsEntityBuilder,

View File

@ -12,8 +12,8 @@ use common::{
msg::ServerGeneral, msg::ServerGeneral,
outcome::Outcome, outcome::Outcome,
region::{Event as RegionEvent, RegionMap}, region::{Event as RegionEvent, RegionMap},
resources::TimeOfDay,
span, span,
state::TimeOfDay,
sync::{CompSyncPackage, Uid}, sync::{CompSyncPackage, Uid},
terrain::TerrainChunkSize, terrain::TerrainChunkSize,
vol::RectVolSize, vol::RectVolSize,

View File

@ -4,8 +4,8 @@ use common::{
comp::{ChatMode, Player, UnresolvedChatMsg}, comp::{ChatMode, Player, UnresolvedChatMsg},
event::{EventBus, ServerEvent}, event::{EventBus, ServerEvent},
msg::{validate_chat_msg, ChatMsgValidationError, ClientGeneral, MAX_BYTES_CHAT_MSG}, msg::{validate_chat_msg, ChatMsgValidationError, ClientGeneral, MAX_BYTES_CHAT_MSG},
resources::Time,
span, span,
state::Time,
sync::Uid, sync::Uid,
}; };
use specs::{Entities, Join, Read, ReadExpect, ReadStorage, System, Write}; use specs::{Entities, Join, Read, ReadExpect, ReadStorage, System, Write};

View File

@ -5,10 +5,10 @@ use common::{
event::{EventBus, ServerEvent}, event::{EventBus, ServerEvent},
msg::{ClientGeneral, PresenceKind, ServerGeneral}, msg::{ClientGeneral, PresenceKind, ServerGeneral},
span, span,
state::BlockChange,
terrain::{TerrainChunkSize, TerrainGrid}, terrain::{TerrainChunkSize, TerrainGrid},
vol::{ReadVol, RectVolSize}, vol::{ReadVol, RectVolSize},
}; };
use common_state::BlockChange;
use specs::{Entities, Join, Read, ReadExpect, ReadStorage, System, Write, WriteStorage}; use specs::{Entities, Join, Read, ReadExpect, ReadStorage, System, Write, WriteStorage};
use tracing::{debug, trace}; use tracing::{debug, trace};

View File

@ -3,8 +3,8 @@ use crate::{client::Client, metrics::PlayerMetrics, Settings};
use common::{ use common::{
event::{EventBus, ServerEvent}, event::{EventBus, ServerEvent},
msg::PingMsg, msg::PingMsg,
resources::Time,
span, span,
state::Time,
}; };
use specs::{Entities, Join, Read, ReadExpect, ReadStorage, System, Write}; use specs::{Entities, Join, Read, ReadExpect, ReadStorage, System, Write};
use std::sync::atomic::Ordering; use std::sync::atomic::Ordering;

View File

@ -2,9 +2,8 @@ use common::{
comp::{HealthSource, Object, PhysicsState, Pos, Vel}, comp::{HealthSource, Object, PhysicsState, Pos, Vel},
effect::Effect, effect::Effect,
event::{EventBus, ServerEvent}, event::{EventBus, ServerEvent},
span, resources::DeltaTime,
state::DeltaTime, span, Damage, DamageSource, Explosion, RadiusEffect,
Damage, DamageSource, Explosion, RadiusEffect,
}; };
use specs::{Entities, Join, Read, ReadStorage, System, WriteStorage}; use specs::{Entities, Join, Read, ReadStorage, System, WriteStorage};

View File

@ -9,10 +9,10 @@ use common::{
msg::ServerGeneral, msg::ServerGeneral,
npc::NPC_NAMES, npc::NPC_NAMES,
span, span,
state::TerrainChanges,
terrain::TerrainGrid, terrain::TerrainGrid,
LoadoutBuilder, LoadoutBuilder,
}; };
use common_state::TerrainChanges;
use rand::Rng; use rand::Rng;
use specs::{Join, Read, ReadExpect, ReadStorage, System, Write, WriteExpect}; use specs::{Join, Read, ReadExpect, ReadStorage, System, Write, WriteExpect};
use std::sync::Arc; use std::sync::Arc;

View File

@ -1,6 +1,7 @@
use super::SysTimer; use super::SysTimer;
use crate::{client::Client, presence::Presence}; use crate::{client::Client, presence::Presence};
use common::{comp::Pos, msg::ServerGeneral, span, state::TerrainChanges, terrain::TerrainGrid}; use common::{comp::Pos, msg::ServerGeneral, span, terrain::TerrainGrid};
use common_state::TerrainChanges;
use specs::{Join, Read, ReadExpect, ReadStorage, System, Write}; use specs::{Join, Read, ReadExpect, ReadStorage, System, Write};
/// This systems sends new chunks to clients as well as changes to existing /// This systems sends new chunks to clients as well as changes to existing

View File

@ -3,8 +3,8 @@ use crate::client::Client;
use common::{ use common::{
comp::{Player, Pos, Waypoint, WaypointArea}, comp::{Player, Pos, Waypoint, WaypointArea},
msg::{Notification, ServerGeneral}, msg::{Notification, ServerGeneral},
resources::Time,
span, span,
state::Time,
}; };
use specs::{Entities, Join, Read, ReadStorage, System, Write, WriteStorage}; use specs::{Entities, Join, Read, ReadStorage, System, Write, WriteStorage};

View File

@ -21,6 +21,8 @@ default = ["gl", "singleplayer", "native-dialog", "simd"]
[dependencies] [dependencies]
client = {package = "veloren-client", path = "../client"} client = {package = "veloren-client", path = "../client"}
common = {package = "veloren-common", path = "../common"} common = {package = "veloren-common", path = "../common"}
common_sys = {package = "veloren_common_sys", path = "../common/sys"}
common_state = {package = "veloren_common_state", path = "../common/state"}
anim = {package = "veloren-voxygen-anim", path = "src/anim", default-features = false} anim = {package = "veloren-voxygen-anim", path = "src/anim", default-features = false}

View File

@ -4,7 +4,8 @@ use crate::{
scene::Camera, scene::Camera,
}; };
use client::Client; use client::Client;
use common::{assets, state::State, vol::ReadVol}; use common::{assets, vol::ReadVol};
use common_state::State;
use serde::Deserialize; use serde::Deserialize;
use std::time::Instant; use std::time::Instant;
use tracing::warn; use tracing::warn;

View File

@ -46,9 +46,9 @@ use crate::audio::{AudioFrontend, MusicChannelTag};
use client::Client; use client::Client;
use common::{ use common::{
assets, assets,
state::State,
terrain::{BiomeKind, SitesKind}, terrain::{BiomeKind, SitesKind},
}; };
use common_state::State;
use rand::{prelude::SliceRandom, thread_rng, Rng}; use rand::{prelude::SliceRandom, thread_rng, Rng};
use serde::Deserialize; use serde::Deserialize;
use std::time::Instant; use std::time::Instant;

View File

@ -11,10 +11,10 @@ use client::Client;
use common::{ use common::{
comp::Pos, comp::Pos,
spiral::Spiral2d, spiral::Spiral2d,
state::State,
terrain::TerrainChunk, terrain::TerrainChunk,
vol::{ReadVol, RectRasterableVol}, vol::{ReadVol, RectRasterableVol},
}; };
use common_state::State;
use hashbrown::HashMap; use hashbrown::HashMap;
use rand::{thread_rng, Rng}; use rand::{thread_rng, Rng};
use std::time::Instant; use std::time::Instant;

View File

@ -10,10 +10,10 @@ use super::EventMapper;
use client::Client; use client::Client;
use common::{ use common::{
comp::{object, Body, Pos}, comp::{object, Body, Pos},
state::State,
terrain::TerrainChunk, terrain::TerrainChunk,
vol::ReadVol, vol::ReadVol,
}; };
use common_state::State;
use hashbrown::HashMap; use hashbrown::HashMap;
use specs::{Entity as EcsEntity, Join, WorldExt}; use specs::{Entity as EcsEntity, Join, WorldExt};
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};

View File

@ -11,10 +11,10 @@ use super::EventMapper;
use client::Client; use client::Client;
use common::{ use common::{
comp::{item::ItemKind, CharacterAbilityType, CharacterState, Loadout, Pos}, comp::{item::ItemKind, CharacterAbilityType, CharacterState, Loadout, Pos},
state::State,
terrain::TerrainChunk, terrain::TerrainChunk,
vol::ReadVol, vol::ReadVol,
}; };
use common_state::State;
use hashbrown::HashMap; use hashbrown::HashMap;
use specs::{Entity as EcsEntity, Join, WorldExt}; use specs::{Entity as EcsEntity, Join, WorldExt};
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};

View File

@ -4,7 +4,8 @@ mod combat;
mod movement; mod movement;
use client::Client; use client::Client;
use common::{state::State, terrain::TerrainChunk}; use common::terrain::TerrainChunk;
use common_state::State;
use block::BlockEventMapper; use block::BlockEventMapper;
use campfire::CampfireEventMapper; use campfire::CampfireEventMapper;

View File

@ -10,10 +10,10 @@ use crate::{
use client::Client; use client::Client;
use common::{ use common::{
comp::{Body, CharacterState, PhysicsState, Pos, Vel}, comp::{Body, CharacterState, PhysicsState, Pos, Vel},
state::State,
terrain::{BlockKind, TerrainChunk}, terrain::{BlockKind, TerrainChunk},
vol::ReadVol, vol::ReadVol,
}; };
use common_state::State;
use hashbrown::HashMap; use hashbrown::HashMap;
use specs::{Entity as EcsEntity, Join, WorldExt}; use specs::{Entity as EcsEntity, Join, WorldExt};
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};

View File

@ -95,9 +95,9 @@ use common::{
object, Body, CharacterAbilityType, InventoryUpdateEvent, object, Body, CharacterAbilityType, InventoryUpdateEvent,
}, },
outcome::Outcome, outcome::Outcome,
state::State,
terrain::TerrainChunk, terrain::TerrainChunk,
}; };
use common_state::State;
use event_mapper::SfxEventMapper; use event_mapper::SfxEventMapper;
use hashbrown::HashMap; use hashbrown::HashMap;
use rand::prelude::*; use rand::prelude::*;

View File

@ -9,7 +9,7 @@ const INTERPOLATION_SYS: &str = "interpolation_voxygen_sys";
pub fn add_local_systems(dispatch_builder: &mut DispatcherBuilder) { pub fn add_local_systems(dispatch_builder: &mut DispatcherBuilder) {
dispatch_builder.add(interpolation::Sys, INTERPOLATION_SYS, &[ dispatch_builder.add(interpolation::Sys, INTERPOLATION_SYS, &[
common::sys::PHYS_SYS, common_sys::PHYS_SYS,
]); ]);
dispatch_builder.add(floater::Sys, FLOATER_SYS, &[INTERPOLATION_SYS]); dispatch_builder.add(floater::Sys, FLOATER_SYS, &[INTERPOLATION_SYS]);
} }

View File

@ -4,7 +4,7 @@ use crate::ecs::{
}; };
use common::{ use common::{
comp::{Health, HealthSource, Pos, Stats}, comp::{Health, HealthSource, Pos, Stats},
state::DeltaTime, resources::DeltaTime,
sync::Uid, sync::Uid,
}; };
use specs::{Entities, Join, Read, ReadExpect, ReadStorage, System, Write, WriteStorage}; use specs::{Entities, Join, Read, ReadExpect, ReadStorage, System, Write, WriteStorage};

View File

@ -1,7 +1,7 @@
use crate::ecs::comp::Interpolated; use crate::ecs::comp::Interpolated;
use common::{ use common::{
comp::{Ori, Pos, Vel}, comp::{Ori, Pos, Vel},
state::DeltaTime, resources::DeltaTime,
util::Dir, util::Dir,
}; };
use specs::{Entities, Join, Read, ReadStorage, System, WriteStorage}; use specs::{Entities, Join, Read, ReadStorage, System, WriteStorage};

View File

@ -10,7 +10,7 @@ use crate::{
Direction, GlobalState, PlayState, PlayStateResult, Direction, GlobalState, PlayState, PlayStateResult,
}; };
use client::{self, Client}; use client::{self, Client};
use common::{assets::Asset, comp, span, state::DeltaTime}; use common::{assets::Asset, comp, resources::DeltaTime, span};
use specs::WorldExt; use specs::WorldExt;
use std::{cell::RefCell, rc::Rc}; use std::{cell::RefCell, rc::Rc};
use tracing::error; use tracing::error;

View File

@ -31,12 +31,13 @@ use common::{
Body, CharacterState, Health, Item, Last, LightAnimation, LightEmitter, Loadout, Ori, Body, CharacterState, Health, Item, Last, LightAnimation, LightEmitter, Loadout, Ori,
PhysicsState, Pos, Scale, Vel, PhysicsState, Pos, Scale, Vel,
}, },
resources::DeltaTime,
span, span,
state::{DeltaTime, State},
states::utils::StageSection, states::utils::StageSection,
terrain::TerrainChunk, terrain::TerrainChunk,
vol::RectRasterableVol, vol::RectRasterableVol,
}; };
use common_state::State;
use core::{ use core::{
borrow::Borrow, borrow::Borrow,
convert::TryFrom, convert::TryFrom,

View File

@ -27,11 +27,12 @@ use client::Client;
use common::{ use common::{
comp, comp,
outcome::Outcome, outcome::Outcome,
resources::DeltaTime,
span, span,
state::{DeltaTime, State},
terrain::{BlockKind, TerrainChunk}, terrain::{BlockKind, TerrainChunk},
vol::ReadVol, vol::ReadVol,
}; };
use common_state::State;
use comp::item::Reagent; use comp::item::Reagent;
use num::traits::{Float, FloatConst}; use num::traits::{Float, FloatConst};
use specs::{Entity as EcsEntity, Join, WorldExt}; use specs::{Entity as EcsEntity, Join, WorldExt};

View File

@ -11,9 +11,9 @@ use common::{
comp::{item::Reagent, object, Body, CharacterState, Ori, Pos, Shockwave}, comp::{item::Reagent, object, Body, CharacterState, Ori, Pos, Shockwave},
figure::Segment, figure::Segment,
outcome::Outcome, outcome::Outcome,
resources::DeltaTime,
span, span,
spiral::Spiral2d, spiral::Spiral2d,
state::DeltaTime,
states::utils::StageSection, states::utils::StageSection,
terrain::TerrainChunk, terrain::TerrainChunk,
vol::{RectRasterableVol, SizedVol}, vol::{RectRasterableVol, SizedVol},