Added longer day/night cycle, /time command

This commit is contained in:
Joshua Barretto 2019-06-21 09:42:16 +01:00
parent f3adf6ab5f
commit 9279611d6d
3 changed files with 41 additions and 9 deletions

View File

@ -20,11 +20,11 @@ use vek::*;
/// How much faster should an in-game day be compared to a real day?
// TODO: Don't hard-code this.
const DAY_CYCLE_FACTOR: f64 = 24.0 * 60.0;
const DAY_CYCLE_FACTOR: f64 = 24.0 * 2.0;
/// A resource that stores the time of day.
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct TimeOfDay(f64);
pub struct TimeOfDay(pub f64);
/// A resource that stores the tick (i.e: physics) time.
#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize)]

View File

@ -7,6 +7,7 @@ use common::{
comp,
msg::ServerMsg,
npc::{get_npc_name, NpcKind},
state::TimeOfDay,
};
use specs::{Builder, Entity as EcsEntity, Join};
use vek::*;
@ -59,37 +60,43 @@ lazy_static! {
"jump",
"{d} {d} {d}",
"/jump <dx> <dy> <dz> : Offset your current position",
handle_jump
handle_jump,
),
ChatCommand::new(
"goto",
"{d} {d} {d}",
"/goto <x> <y> <z> : Teleport to a position",
handle_goto
handle_goto,
),
ChatCommand::new(
"alias",
"{}",
"/alias <name> : Change your alias",
handle_alias
handle_alias,
),
ChatCommand::new(
"tp",
"{}",
"/tp <alias> : Teleport to another player",
handle_tp
handle_tp,
),
ChatCommand::new(
"kill",
"{}",
"/kill : Kill yourself",
handle_kill
handle_kill,
),
ChatCommand::new(
"time",
"{} {s}",
"/time : Set the time of day",
handle_time,
),
ChatCommand::new(
"spawn",
"{} {} {d}",
"/spawn <alignment> <entity> [amount] : Spawn a test entity",
handle_spawn
handle_spawn,
),
ChatCommand::new(
"help", "", "/help: Display this message", handle_help)
@ -143,6 +150,31 @@ fn handle_kill(server: &mut Server, entity: EcsEntity, _args: String, _action: &
.map(|s| s.hp.set_to(0, comp::HealthSource::Suicide));
}
fn handle_time(server: &mut Server, entity: EcsEntity, args: String, action: &ChatCommand) {
let time = scan_fmt!(&args, action.arg_fmt, String);
server
.state
.ecs_mut()
.write_resource::<TimeOfDay>()
.0 = match time.as_ref().map(|s| s.as_str()) {
Some("day") => 12.0 * 3600.0,
Some("night") => 24.0 * 3600.0,
Some("dawn") => 5.0 * 3600.0,
Some("dusk") => 17.0 * 3600.0,
Some(n) => match n.parse() {
Ok(n) => n,
Err(_) => {
server.clients.notify(entity, ServerMsg::Chat(format!("'{}' is not a time!", n)));
return;
},
},
None => {
server.clients.notify(entity, ServerMsg::Chat("You must specify a time!".to_string()));
return;
},
};
}
fn handle_alias(server: &mut Server, entity: EcsEntity, args: String, action: &ChatCommand) {
let opt_alias = scan_fmt!(&args, action.arg_fmt, String);
match opt_alias {

View File

@ -66,7 +66,7 @@ vec3 get_sky_color(vec3 dir, float time_of_day) {
vec3 sun_dir = get_sun_dir(time_of_day);
float sky_brightness = get_sun_brightness(sun_dir);
vec3 sun_halo = pow(max(dot(dir, -sun_dir) + 0.5, 0.0), 8.0) * SUN_HALO_COLOR;
vec3 sun_halo = pow(max(dot(dir, -sun_dir) + 0.1, 0.0), 8.0) * SUN_HALO_COLOR;
vec3 sun_surf = pow(max(dot(dir, -sun_dir) - 0.0045, 0.0), 1000.0) * SUN_SURF_COLOR;
vec3 sun_light = sun_halo + sun_surf;