From f14a4962d08b47fe31722401808ca3e0603ef401 Mon Sep 17 00:00:00 2001 From: Monty Date: Sat, 13 Mar 2021 19:51:36 +0100 Subject: [PATCH] WIP --- common/src/cmd.rs | 8 +++++++- common/src/resources.rs | 5 +++++ common/sys/src/state.rs | 4 ++-- server/src/cmd.rs | 38 ++++++++++++++++++++++++++++++++++++++ server/src/settings.rs | 10 ++++++++++ 5 files changed, 62 insertions(+), 3 deletions(-) diff --git a/common/src/cmd.rs b/common/src/cmd.rs index f6771bdcd3..ea8b31dd0b 100644 --- a/common/src/cmd.rs +++ b/common/src/cmd.rs @@ -84,6 +84,7 @@ pub enum ChatCommand { Waypoint, Whitelist, World, + DayCycleSpeed, } // Thank you for keeping this sorted alphabetically :-) @@ -131,6 +132,7 @@ pub static CHAT_COMMANDS: &[ChatCommand] = &[ ChatCommand::Sudo, ChatCommand::Tell, ChatCommand::Time, + ChatCommand::DayCycleSpeed, ChatCommand::Tp, ChatCommand::Unban, ChatCommand::Version, @@ -146,7 +148,7 @@ lazy_static! { ('r', ChatCommand::Region), ('s', ChatCommand::Say), ('t', ChatCommand::Tell), - ('w', ChatCommand::World), + ('w', ChatCommand::World), ].iter().cloned().collect(); static ref ALIGNMENTS: Vec = vec!["wild", "enemy", "npc", "pet"] @@ -385,6 +387,9 @@ impl ChatCommand { ChatCommand::SetMotd => { cmd(vec![Message(Optional)], "Set the server description", Admin) }, + ChatCommand::DayCycleSpeed => { + cmd(vec![Message(Optional)], "Set the number of days passing per hour", Admin) + }, ChatCommand::SkillPoint => cmd( vec![ Enum("skill tree", SKILL_TREES.clone(), Required), @@ -497,6 +502,7 @@ impl ChatCommand { ChatCommand::Waypoint => "waypoint", ChatCommand::Whitelist => "whitelist", ChatCommand::World => "world", + ChatCommand::DayCycleSpeed => "days_per_hour", } } diff --git a/common/src/resources.rs b/common/src/resources.rs index 73810234c8..24c78f7ec1 100644 --- a/common/src/resources.rs +++ b/common/src/resources.rs @@ -1,4 +1,5 @@ use serde::{Deserialize, Serialize}; +use editable::EditableSetting; /// A resource that stores the time of day. #[derive(Copy, Clone, Debug, Serialize, Deserialize, Default)] @@ -8,6 +9,10 @@ pub struct TimeOfDay(pub f64); #[derive(Copy, Clone, Debug, Default, Serialize, Deserialize)] pub struct Time(pub f64); +// A resource that stores the ingame days per real life hour. +#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize)] +pub struct DayCycleSpeed(pub f64); + /// A resource that stores the time since the previous tick. #[derive(Default)] pub struct DeltaTime(pub f32); diff --git a/common/sys/src/state.rs b/common/sys/src/state.rs index 3d15d4e3ff..f57ffd6562 100644 --- a/common/sys/src/state.rs +++ b/common/sys/src/state.rs @@ -6,7 +6,7 @@ use common::{ comp, event::{EventBus, LocalEvent, ServerEvent}, region::RegionMap, - resources::{DeltaTime, GameMode, Time, TimeOfDay}, + resources::{DeltaTime, GameMode, Time, TimeOfDay, DayCycleSpeed}, terrain::{Block, TerrainChunk, TerrainGrid}, time::DayPeriod, trade::Trades, @@ -414,7 +414,7 @@ impl State { ) { span!(_guard, "tick", "State::tick"); // Change the time accordingly. - self.ecs.write_resource::().0 += dt.as_secs_f64() * DAY_CYCLE_FACTOR; + self.ecs.write_resource::().0 += dt.as_secs_f64() * self.ecs.read_resource::().0; self.ecs.write_resource::