Merge branch 'master' into 'master'

Colour in figure shader and sphynx update

See merge request veloren/veloren!134

Former-commit-id: a1682becf03294a30e96b15afbd5fdf2c3d24028
This commit is contained in:
Joshua Barretto 2019-05-16 23:14:59 +00:00
commit dfb9e93052
6 changed files with 205 additions and 210 deletions

347
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -1,11 +1,20 @@
use crate::comp; use crate::{comp, state};
use serde_derive::{Deserialize, Serialize}; use serde_derive::{Deserialize, Serialize};
use std::marker::PhantomData; use std::marker::PhantomData;
// Automatically derive From<T> for Packet for each variant Packet::T(T) // Automatically derive From<T> for EcsResPacket for each variant EcsResPacket::T(T)
sphynx::sum_type! { sphynx::sum_type! {
#[derive(Clone, Debug, Serialize, Deserialize)] #[derive(Clone, Debug, Serialize, Deserialize)]
pub enum EcsPacket { pub enum EcsResPacket {
Time(state::Time),
TimeOfDay(state::TimeOfDay),
}
}
impl sphynx::ResPacket for EcsResPacket {}
// Automatically derive From<T> for EcsCompPacket for each variant EcsCompPacket::T(T)
sphynx::sum_type! {
#[derive(Clone, Debug, Serialize, Deserialize)]
pub enum EcsCompPacket {
Pos(comp::phys::Pos), Pos(comp::phys::Pos),
Vel(comp::phys::Vel), Vel(comp::phys::Vel),
Dir(comp::phys::Dir), Dir(comp::phys::Dir),
@ -14,10 +23,10 @@ sphynx::sum_type! {
Stats(comp::Stats), Stats(comp::Stats),
} }
} }
// Automatically derive From<T> for Phantom for each variant Phantom::T(PhantomData<T>) // Automatically derive From<T> for EcsCompPhantom for each variant EcsCompPhantom::T(PhantomData<T>)
sphynx::sum_type! { sphynx::sum_type! {
#[derive(Clone, Debug, Serialize, Deserialize)] #[derive(Clone, Debug, Serialize, Deserialize)]
pub enum EcsPhantom { pub enum EcsCompPhantom {
Pos(PhantomData<comp::phys::Pos>), Pos(PhantomData<comp::phys::Pos>),
Vel(PhantomData<comp::phys::Vel>), Vel(PhantomData<comp::phys::Vel>),
Dir(PhantomData<comp::phys::Dir>), Dir(PhantomData<comp::phys::Dir>),
@ -26,6 +35,6 @@ sphynx::sum_type! {
Stats(PhantomData<comp::Stats>), Stats(PhantomData<comp::Stats>),
} }
} }
impl sphynx::Packet for EcsPacket { impl sphynx::CompPacket for EcsCompPacket {
type Phantom = EcsPhantom; type Phantom = EcsCompPhantom;
} }

View File

@ -4,7 +4,7 @@ pub mod server;
// Reexports // Reexports
pub use self::client::ClientMsg; pub use self::client::ClientMsg;
pub use self::ecs_packet::EcsPacket; pub use self::ecs_packet::{EcsCompPacket, EcsResPacket};
pub use self::server::{RequestStateError, ServerMsg}; pub use self::server::{RequestStateError, ServerMsg};
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)] #[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]

View File

@ -1,4 +1,4 @@
use super::{ClientState, EcsPacket}; use super::{ClientState, EcsCompPacket, EcsResPacket};
use crate::{comp, terrain::TerrainChunk}; use crate::{comp, terrain::TerrainChunk};
use vek::*; use vek::*;
@ -13,7 +13,7 @@ pub enum RequestStateError {
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub enum ServerMsg { pub enum ServerMsg {
InitialSync { InitialSync {
ecs_state: sphynx::StatePackage<EcsPacket>, ecs_state: sphynx::StatePackage<EcsCompPacket, EcsResPacket>,
entity_uid: u64, entity_uid: u64,
}, },
StateAnswer(Result<ClientState, (RequestStateError, ClientState)>), StateAnswer(Result<ClientState, (RequestStateError, ClientState)>),
@ -22,7 +22,7 @@ pub enum ServerMsg {
Pong, Pong,
Chat(String), Chat(String),
SetPlayerEntity(u64), SetPlayerEntity(u64),
EcsSync(sphynx::SyncPackage<EcsPacket>), EcsSync(sphynx::SyncPackage<EcsCompPacket, EcsResPacket>),
EntityPhysics { EntityPhysics {
entity: u64, entity: u64,
pos: comp::phys::Pos, pos: comp::phys::Pos,

View File

@ -3,11 +3,12 @@ pub use sphynx::Uid;
use crate::{ use crate::{
comp, comp,
msg::EcsPacket, msg::{EcsCompPacket, EcsResPacket},
sys, sys,
terrain::{TerrainChunk, TerrainMap}, terrain::{TerrainChunk, TerrainMap},
}; };
use rayon::{ThreadPool, ThreadPoolBuilder}; use rayon::{ThreadPool, ThreadPoolBuilder};
use serde_derive::{Deserialize, Serialize};
use specs::{ use specs::{
saveload::{MarkedBuilder, MarkerAllocator}, saveload::{MarkedBuilder, MarkerAllocator},
shred::{Fetch, FetchMut}, shred::{Fetch, FetchMut},
@ -23,10 +24,12 @@ use vek::*;
const DAY_CYCLE_FACTOR: f64 = 24.0 * 60.0; const DAY_CYCLE_FACTOR: f64 = 24.0 * 60.0;
/// A resource to store the time of day /// A resource to store the time of day
struct TimeOfDay(f64); #[derive(Clone, Debug, Serialize, Deserialize)]
pub struct TimeOfDay(f64);
/// A resource to store the tick (i.e: physics) time /// A resource to store the tick (i.e: physics) time
struct Time(f64); #[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Time(f64);
/// A resource used to store the time since the last tick /// A resource used to store the time since the last tick
#[derive(Default)] #[derive(Default)]
@ -63,7 +66,7 @@ impl Changes {
/// A type used to represent game state stored on both the client and the server. This includes /// A type used to represent game state stored on both the client and the server. This includes
/// things like entity components, terrain data, and global state like weather, time of day, etc. /// things like entity components, terrain data, and global state like weather, time of day, etc.
pub struct State { pub struct State {
ecs: sphynx::World<EcsPacket>, ecs: sphynx::World<EcsCompPacket, EcsResPacket>,
// Avoid lifetime annotation by storing a thread pool instead of the whole dispatcher // Avoid lifetime annotation by storing a thread pool instead of the whole dispatcher
thread_pool: Arc<ThreadPool>, thread_pool: Arc<ThreadPool>,
changes: Changes, changes: Changes,
@ -80,7 +83,9 @@ impl State {
} }
/// Create a new `State` from an ECS state package /// Create a new `State` from an ECS state package
pub fn from_state_package(state_package: sphynx::StatePackage<EcsPacket>) -> Self { pub fn from_state_package(
state_package: sphynx::StatePackage<EcsCompPacket, EcsResPacket>,
) -> Self {
Self { Self {
ecs: sphynx::World::from_state_package( ecs: sphynx::World::from_state_package(
specs::World::new(), specs::World::new(),
@ -93,7 +98,7 @@ impl State {
} }
// Create a new Sphynx ECS world // Create a new Sphynx ECS world
fn setup_sphynx_world(ecs: &mut sphynx::World<EcsPacket>) { fn setup_sphynx_world(ecs: &mut sphynx::World<EcsCompPacket, EcsResPacket>) {
// Register synced components // Register synced components
ecs.register_synced::<comp::Actor>(); ecs.register_synced::<comp::Actor>();
ecs.register_synced::<comp::Player>(); ecs.register_synced::<comp::Player>();
@ -107,9 +112,11 @@ impl State {
ecs.register::<comp::Agent>(); ecs.register::<comp::Agent>();
ecs.register::<comp::Control>(); ecs.register::<comp::Control>();
// Register resources used by the ECS // Register synced resources used by the ECS
ecs.add_resource(TimeOfDay(0.0)); ecs.add_resource_synced(TimeOfDay(0.0));
ecs.add_resource(Time(0.0)); ecs.add_resource_synced(Time(0.0));
// Register unsynced resources used by the ECS
ecs.add_resource(DeltaTime(0.0)); ecs.add_resource(DeltaTime(0.0));
ecs.add_resource(TerrainMap::new().unwrap()); ecs.add_resource(TerrainMap::new().unwrap());
} }
@ -139,12 +146,12 @@ impl State {
} }
/// Get a reference to the internal ECS world /// Get a reference to the internal ECS world
pub fn ecs(&self) -> &sphynx::World<EcsPacket> { pub fn ecs(&self) -> &sphynx::World<EcsCompPacket, EcsResPacket> {
&self.ecs &self.ecs
} }
/// Get a mutable reference to the internal ECS world /// Get a mutable reference to the internal ECS world
pub fn ecs_mut(&mut self) -> &mut sphynx::World<EcsPacket> { pub fn ecs_mut(&mut self) -> &mut sphynx::World<EcsCompPacket, EcsResPacket> {
&mut self.ecs &mut self.ecs
} }

View File

@ -396,6 +396,14 @@ impl FigureMgr {
.map(|(change_by, change_time)| Rgba::new(1.0, 0.7, 0.7, 1.0)) .map(|(change_by, change_time)| Rgba::new(1.0, 0.7, 0.7, 1.0))
.unwrap_or(Rgba::broadcast(1.0)); .unwrap_or(Rgba::broadcast(1.0));
// Change in health as color!
let col = stats
.and_then(|stats| stats.hp.last_change)
.map(|(change_by, change_time)| Rgba::new(1.0, 0.7, 0.7, 1.0))
.unwrap_or(Rgba::broadcast(1.0));
state.update(renderer, pos.0, dir.0, col);
state.update(renderer, pos.0, dir.0, col); state.update(renderer, pos.0, dir.0, col);
} }
}, },