mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Persist TimeOfDay with rtsim
This commit is contained in:
parent
64c56f544d
commit
e204789ce9
@ -8,6 +8,7 @@ pub use self::{
|
|||||||
nature::Nature,
|
nature::Nature,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use common::resources::TimeOfDay;
|
||||||
use enum_map::{EnumMap, EnumArray, enum_map};
|
use enum_map::{EnumMap, EnumArray, enum_map};
|
||||||
use serde::{Serialize, Deserialize, ser, de};
|
use serde::{Serialize, Deserialize, ser, de};
|
||||||
use std::{
|
use std::{
|
||||||
@ -29,7 +30,7 @@ pub struct Data {
|
|||||||
pub npcs: Npcs,
|
pub npcs: Npcs,
|
||||||
pub sites: Sites,
|
pub sites: Sites,
|
||||||
|
|
||||||
pub time: f64,
|
pub time_of_day: TimeOfDay,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type ReadError = rmp_serde::decode::Error;
|
pub type ReadError = rmp_serde::decode::Error;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use common::resources::Time;
|
use common::resources::{Time, TimeOfDay};
|
||||||
use world::{World, IndexRef};
|
use world::{World, IndexRef};
|
||||||
use super::{Rule, RtState};
|
use super::{Rule, RtState};
|
||||||
|
|
||||||
@ -18,7 +18,8 @@ impl Event for OnSetup {}
|
|||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct OnTick {
|
pub struct OnTick {
|
||||||
|
pub time_of_day: TimeOfDay,
|
||||||
|
pub time: Time,
|
||||||
pub dt: f32,
|
pub dt: f32,
|
||||||
pub time: f64,
|
|
||||||
}
|
}
|
||||||
impl Event for OnTick {}
|
impl Event for OnTick {}
|
||||||
|
@ -26,7 +26,7 @@ impl Data {
|
|||||||
npcs: Npcs { npcs: Default::default() },
|
npcs: Npcs { npcs: Default::default() },
|
||||||
sites: Sites { sites: Default::default() },
|
sites: Sites { sites: Default::default() },
|
||||||
|
|
||||||
time: 0.0,
|
time_of_day: Default::default(),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Register sites with rtsim
|
// Register sites with rtsim
|
||||||
@ -47,7 +47,7 @@ impl Data {
|
|||||||
.with_z(world.sim().get_alt_approx(wpos2d).unwrap_or(0.0))
|
.with_z(world.sim().get_alt_approx(wpos2d).unwrap_or(0.0))
|
||||||
};
|
};
|
||||||
for _ in 0..10 {
|
for _ in 0..10 {
|
||||||
|
|
||||||
this.npcs.create(Npc::new(rng.gen(), rand_wpos(&mut rng)).with_home(site_id).with_profession(match rng.gen_range(0..10) {
|
this.npcs.create(Npc::new(rng.gen(), rand_wpos(&mut rng)).with_home(site_id).with_profession(match rng.gen_range(0..10) {
|
||||||
0 => Profession::Hunter,
|
0 => Profession::Hunter,
|
||||||
1..=4 => Profession::Farmer,
|
1..=4 => Profession::Farmer,
|
||||||
|
@ -10,6 +10,7 @@ pub use self::{
|
|||||||
event::{Event, EventCtx, OnTick},
|
event::{Event, EventCtx, OnTick},
|
||||||
rule::{Rule, RuleError},
|
rule::{Rule, RuleError},
|
||||||
};
|
};
|
||||||
|
use common::resources::{Time, TimeOfDay};
|
||||||
use world::{World, IndexRef};
|
use world::{World, IndexRef};
|
||||||
use anymap2::SendSyncAnyMap;
|
use anymap2::SendSyncAnyMap;
|
||||||
use tracing::{info, error};
|
use tracing::{info, error};
|
||||||
@ -110,9 +111,9 @@ impl RtState {
|
|||||||
.for_each(|f| f(self, world, index, &e)));
|
.for_each(|f| f(self, world, index, &e)));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn tick(&mut self, world: &World, index: IndexRef, dt: f32) {
|
pub fn tick(&mut self, world: &World, index: IndexRef, time_of_day: TimeOfDay, time: Time, dt: f32) {
|
||||||
self.data_mut().time += dt as f64;
|
self.data_mut().time_of_day = time_of_day;
|
||||||
let event = OnTick { dt, time: self.data().time };
|
let event = OnTick { time_of_day, time, dt };
|
||||||
self.emit(event, world, index);
|
self.emit(event, world, index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,8 +53,8 @@ impl Rule for NpcAi {
|
|||||||
npc.target = Some((
|
npc.target = Some((
|
||||||
npc.wpos
|
npc.wpos
|
||||||
+ Vec3::new(
|
+ Vec3::new(
|
||||||
ctx.event.time.sin() as f32 * 16.0,
|
ctx.event.time.0.sin() as f32 * 16.0,
|
||||||
ctx.event.time.cos() as f32 * 16.0,
|
ctx.event.time.0.cos() as f32 * 16.0,
|
||||||
0.0,
|
0.0,
|
||||||
),
|
),
|
||||||
1.0,
|
1.0,
|
||||||
|
@ -66,7 +66,6 @@ use crate::{
|
|||||||
login_provider::LoginProvider,
|
login_provider::LoginProvider,
|
||||||
persistence::PersistedComponents,
|
persistence::PersistedComponents,
|
||||||
presence::{Presence, RegionSubscription, RepositionOnChunkLoad},
|
presence::{Presence, RegionSubscription, RepositionOnChunkLoad},
|
||||||
// rtsim::RtSim,
|
|
||||||
state_ext::StateExt,
|
state_ext::StateExt,
|
||||||
sys::sentinel::DeletedEntities,
|
sys::sentinel::DeletedEntities,
|
||||||
};
|
};
|
||||||
@ -567,7 +566,10 @@ impl Server {
|
|||||||
#[cfg(feature = "worldgen")]
|
#[cfg(feature = "worldgen")]
|
||||||
{
|
{
|
||||||
match rtsim2::RtSim::new(index.as_index_ref(), &world, data_dir.to_owned()) {
|
match rtsim2::RtSim::new(index.as_index_ref(), &world, data_dir.to_owned()) {
|
||||||
Ok(rtsim) => state.ecs_mut().insert(rtsim),
|
Ok(rtsim) => {
|
||||||
|
state.ecs_mut().insert(rtsim.state().data().time_of_day);
|
||||||
|
state.ecs_mut().insert(rtsim);
|
||||||
|
},
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
error!("Failed to load rtsim: {}", err);
|
error!("Failed to load rtsim: {}", err);
|
||||||
return Err(Error::RtsimError(err));
|
return Err(Error::RtsimError(err));
|
||||||
|
@ -44,7 +44,7 @@ impl RtSim {
|
|||||||
pub fn new(index: IndexRef, world: &World, data_dir: PathBuf) -> Result<Self, ron::Error> {
|
pub fn new(index: IndexRef, world: &World, data_dir: PathBuf) -> Result<Self, ron::Error> {
|
||||||
let file_path = Self::get_file_path(data_dir);
|
let file_path = Self::get_file_path(data_dir);
|
||||||
|
|
||||||
info!("Looking for rtsim data in {}...", file_path.display());
|
info!("Looking for rtsim data at {}...", file_path.display());
|
||||||
let data = 'load: {
|
let data = 'load: {
|
||||||
if std::env::var("RTSIM_NOLOAD").map_or(true, |v| v != "1") {
|
if std::env::var("RTSIM_NOLOAD").map_or(true, |v| v != "1") {
|
||||||
match File::open(&file_path) {
|
match File::open(&file_path) {
|
||||||
|
@ -6,7 +6,7 @@ use common::{
|
|||||||
comp::{self, inventory::loadout::Loadout, skillset::skills},
|
comp::{self, inventory::loadout::Loadout, skillset::skills},
|
||||||
event::{EventBus, ServerEvent},
|
event::{EventBus, ServerEvent},
|
||||||
generation::{BodyBuilder, EntityConfig, EntityInfo},
|
generation::{BodyBuilder, EntityConfig, EntityInfo},
|
||||||
resources::{DeltaTime, Time},
|
resources::{DeltaTime, Time, TimeOfDay},
|
||||||
rtsim::{RtSimController, RtSimEntity},
|
rtsim::{RtSimController, RtSimEntity},
|
||||||
slowjob::SlowJobPool,
|
slowjob::SlowJobPool,
|
||||||
LoadoutBuilder,
|
LoadoutBuilder,
|
||||||
@ -24,6 +24,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
type SystemData = (
|
type SystemData = (
|
||||||
Read<'a, DeltaTime>,
|
Read<'a, DeltaTime>,
|
||||||
Read<'a, Time>,
|
Read<'a, Time>,
|
||||||
|
Read<'a, TimeOfDay>,
|
||||||
Read<'a, EventBus<ServerEvent>>,
|
Read<'a, EventBus<ServerEvent>>,
|
||||||
WriteExpect<'a, RtSim>,
|
WriteExpect<'a, RtSim>,
|
||||||
ReadExpect<'a, Arc<world::World>>,
|
ReadExpect<'a, Arc<world::World>>,
|
||||||
@ -43,6 +44,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
(
|
(
|
||||||
dt,
|
dt,
|
||||||
time,
|
time,
|
||||||
|
time_of_day,
|
||||||
mut server_event_bus,
|
mut server_event_bus,
|
||||||
mut rtsim,
|
mut rtsim,
|
||||||
world,
|
world,
|
||||||
@ -56,7 +58,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
let mut emitter = server_event_bus.emitter();
|
let mut emitter = server_event_bus.emitter();
|
||||||
let rtsim = &mut *rtsim;
|
let rtsim = &mut *rtsim;
|
||||||
|
|
||||||
rtsim.state.tick(&world, index.as_index_ref(), dt.0);
|
rtsim.state.tick(&world, index.as_index_ref(), *time_of_day, *time, dt.0);
|
||||||
|
|
||||||
if rtsim
|
if rtsim
|
||||||
.last_saved
|
.last_saved
|
||||||
|
Loading…
Reference in New Issue
Block a user