mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Merge branch 'imbris/spiff-up' into 'master'
Fix some things See merge request veloren/veloren!1541
This commit is contained in:
commit
36efb11b03
@ -32,6 +32,7 @@ use common::{
|
|||||||
},
|
},
|
||||||
outcome::Outcome,
|
outcome::Outcome,
|
||||||
recipe::RecipeBook,
|
recipe::RecipeBook,
|
||||||
|
span,
|
||||||
state::State,
|
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},
|
||||||
@ -935,6 +936,7 @@ impl Client {
|
|||||||
dt: Duration,
|
dt: Duration,
|
||||||
add_foreign_systems: impl Fn(&mut DispatcherBuilder),
|
add_foreign_systems: impl Fn(&mut DispatcherBuilder),
|
||||||
) -> Result<Vec<Event>, Error> {
|
) -> Result<Vec<Event>, Error> {
|
||||||
|
span!(_guard, "tick", "Client::tick");
|
||||||
// This tick function is the centre of the Veloren universe. Most client-side
|
// This tick function is the centre of the Veloren universe. Most client-side
|
||||||
// things are managed from here, and as such it's important that it
|
// things are managed from here, and as such it's important that it
|
||||||
// stays organised. Please consult the core developers before making
|
// stays organised. Please consult the core developers before making
|
||||||
|
@ -3,6 +3,7 @@ use crate::{
|
|||||||
event::{EventBus, LocalEvent, ServerEvent},
|
event::{EventBus, LocalEvent, ServerEvent},
|
||||||
metrics::{PhysicsMetrics, SysMetrics},
|
metrics::{PhysicsMetrics, SysMetrics},
|
||||||
region::RegionMap,
|
region::RegionMap,
|
||||||
|
span,
|
||||||
sync::WorldSyncExt,
|
sync::WorldSyncExt,
|
||||||
sys,
|
sys,
|
||||||
terrain::{Block, TerrainChunk, TerrainGrid},
|
terrain::{Block, TerrainChunk, TerrainGrid},
|
||||||
@ -329,6 +330,7 @@ impl State {
|
|||||||
|
|
||||||
// Run RegionMap tick to update entity region occupancy
|
// Run RegionMap tick to update entity region occupancy
|
||||||
pub fn update_region_map(&self) {
|
pub fn update_region_map(&self) {
|
||||||
|
span!(_guard, "update_region_map", "State::update_region_map");
|
||||||
self.ecs.write_resource::<RegionMap>().tick(
|
self.ecs.write_resource::<RegionMap>().tick(
|
||||||
self.ecs.read_storage::<comp::Pos>(),
|
self.ecs.read_storage::<comp::Pos>(),
|
||||||
self.ecs.read_storage::<comp::Vel>(),
|
self.ecs.read_storage::<comp::Vel>(),
|
||||||
@ -338,6 +340,11 @@ impl State {
|
|||||||
|
|
||||||
// Apply terrain changes
|
// Apply terrain changes
|
||||||
pub fn apply_terrain_changes(&self) {
|
pub fn apply_terrain_changes(&self) {
|
||||||
|
span!(
|
||||||
|
_guard,
|
||||||
|
"apply_terrain_changes",
|
||||||
|
"State::apply_terrain_changes"
|
||||||
|
);
|
||||||
let mut terrain = self.ecs.write_resource::<TerrainGrid>();
|
let mut terrain = self.ecs.write_resource::<TerrainGrid>();
|
||||||
let mut modified_blocks =
|
let mut modified_blocks =
|
||||||
std::mem::take(&mut self.ecs.write_resource::<BlockChange>().blocks);
|
std::mem::take(&mut self.ecs.write_resource::<BlockChange>().blocks);
|
||||||
@ -354,6 +361,7 @@ impl State {
|
|||||||
add_foreign_systems: impl Fn(&mut DispatcherBuilder),
|
add_foreign_systems: impl Fn(&mut DispatcherBuilder),
|
||||||
update_terrain_and_regions: bool,
|
update_terrain_and_regions: bool,
|
||||||
) {
|
) {
|
||||||
|
span!(_guard, "tick", "State::tick");
|
||||||
// Change the time accordingly.
|
// Change the time accordingly.
|
||||||
self.ecs.write_resource::<TimeOfDay>().0 += dt.as_secs_f64() * DAY_CYCLE_FACTOR;
|
self.ecs.write_resource::<TimeOfDay>().0 += dt.as_secs_f64() * DAY_CYCLE_FACTOR;
|
||||||
self.ecs.write_resource::<Time>().0 += dt.as_secs_f64();
|
self.ecs.write_resource::<Time>().0 += dt.as_secs_f64();
|
||||||
@ -367,6 +375,7 @@ impl State {
|
|||||||
self.update_region_map();
|
self.update_region_map();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
span!(guard, "create dispatcher");
|
||||||
// Run systems to update the world.
|
// Run systems to update the world.
|
||||||
// Create and run a dispatcher for ecs systems.
|
// Create and run a dispatcher for ecs systems.
|
||||||
let mut dispatch_builder =
|
let mut dispatch_builder =
|
||||||
@ -375,15 +384,22 @@ impl State {
|
|||||||
// 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.
|
||||||
dispatch_builder.build().dispatch(&self.ecs);
|
let mut dispatcher = dispatch_builder.build();
|
||||||
|
drop(guard);
|
||||||
|
span!(guard, "run systems");
|
||||||
|
dispatcher.dispatch(&self.ecs);
|
||||||
|
drop(guard);
|
||||||
|
|
||||||
|
span!(guard, "maintain ecs");
|
||||||
self.ecs.maintain();
|
self.ecs.maintain();
|
||||||
|
drop(guard);
|
||||||
|
|
||||||
if update_terrain_and_regions {
|
if update_terrain_and_regions {
|
||||||
self.apply_terrain_changes();
|
self.apply_terrain_changes();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process local events
|
// Process local events
|
||||||
|
span!(guard, "process local events");
|
||||||
let events = self.ecs.read_resource::<EventBus<LocalEvent>>().recv_all();
|
let events = self.ecs.read_resource::<EventBus<LocalEvent>>().recv_all();
|
||||||
for event in events {
|
for event in events {
|
||||||
let mut velocities = self.ecs.write_storage::<comp::Vel>();
|
let mut velocities = self.ecs.write_storage::<comp::Vel>();
|
||||||
@ -424,10 +440,12 @@ impl State {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
drop(guard);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Clean up the state after a tick.
|
/// Clean up the state after a tick.
|
||||||
pub fn cleanup(&mut self) {
|
pub fn cleanup(&mut self) {
|
||||||
|
span!(_guard, "cleanup", "State::cleanup");
|
||||||
// Clean up data structures from the last tick.
|
// Clean up data structures from the last tick.
|
||||||
self.ecs.write_resource::<TerrainChanges>().clear();
|
self.ecs.write_resource::<TerrainChanges>().clear();
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ use crate::{
|
|||||||
tui_runner::{Message, Tui},
|
tui_runner::{Message, Tui},
|
||||||
};
|
};
|
||||||
use clap::{App, Arg, SubCommand};
|
use clap::{App, Arg, SubCommand};
|
||||||
use common::clock::Clock;
|
use common::{clock::Clock, span};
|
||||||
use server::{Event, Input, Server};
|
use server::{Event, Input, Server};
|
||||||
use std::{
|
use std::{
|
||||||
io,
|
io,
|
||||||
@ -144,11 +144,7 @@ fn main() -> io::Result<()> {
|
|||||||
// Wait for a tick so we don't start with a zero dt
|
// Wait for a tick so we don't start with a zero dt
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
#[cfg(feature = "tracy")]
|
span!(guard, "work");
|
||||||
common::util::tracy_client::finish_continuous_frame!();
|
|
||||||
#[cfg(feature = "tracy")]
|
|
||||||
let frame = common::util::tracy_client::start_noncontinuous_frame!("work");
|
|
||||||
|
|
||||||
// Terminate the server if instructed to do so by the shutdown coordinator
|
// Terminate the server if instructed to do so by the shutdown coordinator
|
||||||
if shutdown_coordinator.check(&mut server, &settings) {
|
if shutdown_coordinator.check(&mut server, &settings) {
|
||||||
break;
|
break;
|
||||||
@ -195,10 +191,11 @@ fn main() -> io::Result<()> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "tracy")]
|
drop(guard);
|
||||||
drop(frame);
|
|
||||||
// Wait for the next tick.
|
// Wait for the next tick.
|
||||||
clock.tick();
|
clock.tick();
|
||||||
|
#[cfg(feature = "tracy")]
|
||||||
|
common::util::tracy_client::finish_continuous_frame!();
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -559,7 +559,7 @@ fn within_pickup_range<S: FindDist<find_dist::Cylinder>>(
|
|||||||
) -> bool {
|
) -> bool {
|
||||||
entity_cylinder
|
entity_cylinder
|
||||||
.and_then(|entity_cylinder| {
|
.and_then(|entity_cylinder| {
|
||||||
shape_fn().map(|shape| dbg!(shape.min_distance(entity_cylinder)) < MAX_PICKUP_RANGE)
|
shape_fn().map(|shape| shape.min_distance(entity_cylinder) < MAX_PICKUP_RANGE)
|
||||||
})
|
})
|
||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
}
|
}
|
||||||
|
@ -2471,6 +2471,10 @@ impl Hud {
|
|||||||
}
|
}
|
||||||
true
|
true
|
||||||
},
|
},
|
||||||
|
WinEvent::ScaleFactorChanged(scale_factor) => {
|
||||||
|
self.ui.scale_factor_changed(scale_factor);
|
||||||
|
false
|
||||||
|
},
|
||||||
WinEvent::InputUpdate(GameInput::ToggleInterface, true) if !self.typing() => {
|
WinEvent::InputUpdate(GameInput::ToggleInterface, true) if !self.typing() => {
|
||||||
self.show.toggle_ui();
|
self.show.toggle_ui();
|
||||||
true
|
true
|
||||||
|
@ -39,7 +39,7 @@ use crate::{
|
|||||||
settings::Settings,
|
settings::Settings,
|
||||||
window::{Event, Window},
|
window::{Event, Window},
|
||||||
};
|
};
|
||||||
use common::{assets::watch, clock::Clock};
|
use common::{assets::watch, clock::Clock, span};
|
||||||
|
|
||||||
/// A type used to store state that is shared between all play states.
|
/// A type used to store state that is shared between all play states.
|
||||||
pub struct GlobalState {
|
pub struct GlobalState {
|
||||||
@ -63,7 +63,10 @@ impl GlobalState {
|
|||||||
self.window.needs_refresh_resize();
|
self.window.needs_refresh_resize();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn maintain(&mut self, dt: std::time::Duration) { self.audio.maintain(dt); }
|
pub fn maintain(&mut self, dt: std::time::Duration) {
|
||||||
|
span!(_guard, "maintain", "GlobalState::maintain");
|
||||||
|
self.audio.maintain(dt);
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(feature = "singleplayer")]
|
#[cfg(feature = "singleplayer")]
|
||||||
pub fn paused(&self) -> bool {
|
pub fn paused(&self) -> bool {
|
||||||
|
@ -12,7 +12,7 @@ use std::{
|
|||||||
thread,
|
thread,
|
||||||
time::Duration,
|
time::Duration,
|
||||||
};
|
};
|
||||||
use tracing::{debug, trace, warn};
|
use tracing::{trace, warn};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
@ -107,7 +107,7 @@ impl ClientInit {
|
|||||||
));
|
));
|
||||||
break 'tries;
|
break 'tries;
|
||||||
} else {
|
} else {
|
||||||
debug!("Cannot connect to server: Timeout (retrying...)");
|
warn!(?e, "Failed to connect to the server. Retrying...");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
@ -171,19 +171,19 @@ fn handle_main_events_cleared(
|
|||||||
.swap_buffers()
|
.swap_buffers()
|
||||||
.expect("Failed to swap window buffers!");
|
.expect("Failed to swap window buffers!");
|
||||||
drop(guard);
|
drop(guard);
|
||||||
#[cfg(feature = "tracy")]
|
|
||||||
common::util::tracy_client::finish_continuous_frame!();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !exit {
|
if !exit {
|
||||||
// Wait for the next tick.
|
// Wait for the next tick.
|
||||||
span!(_guard, "Main thread sleep");
|
span!(guard, "Main thread sleep");
|
||||||
global_state.clock.set_target_dt(Duration::from_secs_f64(
|
global_state.clock.set_target_dt(Duration::from_secs_f64(
|
||||||
1.0 / global_state.settings.graphics.max_fps as f64,
|
1.0 / global_state.settings.graphics.max_fps as f64,
|
||||||
));
|
));
|
||||||
global_state.clock.tick();
|
global_state.clock.tick();
|
||||||
|
drop(guard);
|
||||||
|
#[cfg(feature = "tracy")]
|
||||||
|
common::util::tracy_client::finish_continuous_frame!();
|
||||||
|
|
||||||
span!(_guard, "Maintain global state");
|
|
||||||
// Maintain global state.
|
// Maintain global state.
|
||||||
global_state.maintain(global_state.clock.dt());
|
global_state.maintain(global_state.clock.dt());
|
||||||
}
|
}
|
||||||
|
@ -115,6 +115,8 @@ pub struct Ui {
|
|||||||
ingame_locals: Vec<Consts<UiLocals>>,
|
ingame_locals: Vec<Consts<UiLocals>>,
|
||||||
// Window size for updating scaling
|
// Window size for updating scaling
|
||||||
window_resized: Option<Vec2<f64>>,
|
window_resized: Option<Vec2<f64>>,
|
||||||
|
// Scale factor changed
|
||||||
|
scale_factor_changed: Option<f64>,
|
||||||
// Used to delay cache resizing until after current frame is drawn
|
// Used to delay cache resizing until after current frame is drawn
|
||||||
need_cache_resize: bool,
|
need_cache_resize: bool,
|
||||||
// Scaling of the ui
|
// Scaling of the ui
|
||||||
@ -153,6 +155,7 @@ impl Ui {
|
|||||||
default_globals: renderer.create_consts(&[Globals::default()])?,
|
default_globals: renderer.create_consts(&[Globals::default()])?,
|
||||||
ingame_locals: Vec::new(),
|
ingame_locals: Vec::new(),
|
||||||
window_resized: None,
|
window_resized: None,
|
||||||
|
scale_factor_changed: None,
|
||||||
need_cache_resize: false,
|
need_cache_resize: false,
|
||||||
scale,
|
scale,
|
||||||
tooltip_manager,
|
tooltip_manager,
|
||||||
@ -169,6 +172,10 @@ impl Ui {
|
|||||||
self.ui.handle_event(Input::Resize(w, h));
|
self.ui.handle_event(Input::Resize(w, h));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn scale_factor_changed(&mut self, scale_factor: f64) {
|
||||||
|
self.scale_factor_changed = Some(scale_factor);
|
||||||
|
}
|
||||||
|
|
||||||
// Get a copy of Scale
|
// Get a copy of Scale
|
||||||
pub fn scale(&self) -> Scale { self.scale }
|
pub fn scale(&self) -> Scale { self.scale }
|
||||||
|
|
||||||
@ -284,8 +291,15 @@ impl Ui {
|
|||||||
self.tooltip_manager
|
self.tooltip_manager
|
||||||
.maintain(self.ui.global_input(), self.scale.scale_factor_logical());
|
.maintain(self.ui.global_input(), self.scale.scale_factor_logical());
|
||||||
|
|
||||||
|
// Handle scale factor changing
|
||||||
|
let need_resize = if let Some(scale_factor) = self.scale_factor_changed.take() {
|
||||||
|
self.scale.scale_factor_changed(scale_factor)
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
};
|
||||||
|
|
||||||
// Handle window resizing.
|
// Handle window resizing.
|
||||||
if let Some(new_dims) = self.window_resized.take() {
|
let need_resize = if let Some(new_dims) = self.window_resized.take() {
|
||||||
let (old_w, old_h) = self.scale.scaled_resolution().into_tuple();
|
let (old_w, old_h) = self.scale.scaled_resolution().into_tuple();
|
||||||
self.scale.window_resized(new_dims);
|
self.scale.window_resized(new_dims);
|
||||||
let (w, h) = self.scale.scaled_resolution().into_tuple();
|
let (w, h) = self.scale.scaled_resolution().into_tuple();
|
||||||
@ -296,7 +310,13 @@ impl Ui {
|
|||||||
// Somewhat inefficient for elements that won't change size after a window
|
// Somewhat inefficient for elements that won't change size after a window
|
||||||
// resize
|
// resize
|
||||||
let res = renderer.get_resolution();
|
let res = renderer.get_resolution();
|
||||||
self.need_cache_resize = res.x > 0 && res.y > 0 && !(old_w == w && old_h == h);
|
res.x > 0 && res.y > 0 && !(old_w == w && old_h == h)
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
} || need_resize;
|
||||||
|
|
||||||
|
if need_resize {
|
||||||
|
self.need_cache_resize = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.need_cache_resize {
|
if self.need_cache_resize {
|
||||||
|
Loading…
Reference in New Issue
Block a user