Merge pull request #2466 from kacpherek/fix/autosave-indicator
🤖 Agent: Gate check by Ludovic's AI agent (Claude). Checked against 26.3: `Gui.renderSavingIndicator` (the fade in and out around the autosave), as here. Gate: this wave's 50 PRs merged on main in one tree (union 9033a9c3b): fmt and clippy `-D warnings` clean, the horizon-client (1136 lib plus the integration tests), horizon-client-core (37), horizon-world (165) and horizon-protocol (100) tests pass, the fast build links, and the 140 harnesses `parity.py` picks for the tree's changed files pass on playhorizon (remote_fireworks, a known load flake there, passed on a rerun on a quiet Mac mini). `lan_e2e.py` passes 14 checks with the host on its server thread and in-frame (chest, xp, damage, kills, projectiles, mobs, drops, body, stopsound, digging, instant_digging, books, knockback, barter); `hurt` fails on main too when run after `damage` (check-order dependency, not this wave). Thanks @kacpherek!
This commit is contained in:
@@ -1445,6 +1445,10 @@ struct Game<'a> {
|
||||
titles: titles::Titles,
|
||||
/// `Hud.toolHighlightTimer`: the selected item name.
|
||||
tool_highlight: horizon_client::hud_overlays::ToolHighlight,
|
||||
/// `Hud.autosaveIndicatorValue`.
|
||||
saving_indicator: horizon_client::hud_overlays::SavingIndicator,
|
||||
/// This game's world is autosaving this tick (`MinecraftServer.isSaving`).
|
||||
autosaving: bool,
|
||||
applied_modifiers: Vec<(String, String)>,
|
||||
experience: Experience,
|
||||
orbs: Vec<ExperienceOrb>,
|
||||
@@ -4496,7 +4500,11 @@ impl Game<'_> {
|
||||
self.world.weather.tick_levels();
|
||||
self.tick_weather_effects();
|
||||
}
|
||||
if self.ticks.is_multiple_of(6000) {
|
||||
self.autosaving = self.ticks.is_multiple_of(6000);
|
||||
if let Some(serving) = &self.serving {
|
||||
serving.set_saving(self.autosaving);
|
||||
}
|
||||
if self.autosaving {
|
||||
self.save_game_with(false)?;
|
||||
}
|
||||
if running {
|
||||
@@ -5541,6 +5549,7 @@ impl Game<'_> {
|
||||
Screen::Mod => self.draw_mod_screen(&mut batch),
|
||||
Screen::Playing | Screen::Options | Screen::Win => {}
|
||||
}
|
||||
self.draw_saving_indicator(&mut batch);
|
||||
self.draw_toasts(&mut batch);
|
||||
self.draw_pack_toasts(&mut batch);
|
||||
self.remote_hud(&mut batch);
|
||||
@@ -12883,6 +12892,8 @@ impl<'a> Game<'a> {
|
||||
command_source: None,
|
||||
titles: Default::default(),
|
||||
tool_highlight: Default::default(),
|
||||
saving_indicator: Default::default(),
|
||||
autosaving: false,
|
||||
applied_modifiers: Vec::new(),
|
||||
experience: Experience::default(),
|
||||
orbs: Vec::new(),
|
||||
|
||||
@@ -52,6 +52,8 @@ struct Flags {
|
||||
/// server follows while it runs (IntegratedServer.tickServer).
|
||||
render_distance: AtomicI32,
|
||||
simulation_distance: AtomicI32,
|
||||
/// `MinecraftServer.isCurrentlySaving`: the server is autosaving.
|
||||
saving: AtomicBool,
|
||||
}
|
||||
|
||||
/// Work the window hands its server thread (`MinecraftServer.execute`).
|
||||
@@ -69,6 +71,10 @@ impl Integrated {
|
||||
pub fn smoothed_tick_ms(&self) -> f32 {
|
||||
f32::from_bits(self.flags.smoothed_tick_ms.load(Ordering::Relaxed))
|
||||
}
|
||||
/// `MinecraftServer.isCurrentlySaving`.
|
||||
pub fn is_saving(&self) -> bool {
|
||||
self.flags.saving.load(Ordering::Relaxed)
|
||||
}
|
||||
/// `IntegratedServer.tickServer` skips the world while the game is paused.
|
||||
pub fn set_paused(&self, paused: bool) {
|
||||
self.flags.paused.store(paused, Ordering::Relaxed);
|
||||
@@ -148,6 +154,12 @@ pub(super) struct Serving {
|
||||
/// is out of its place: applied after the tick.
|
||||
pending: Option<Publish>,
|
||||
}
|
||||
impl Serving {
|
||||
/// The window reads this as `MinecraftServer.isCurrentlySaving`.
|
||||
pub(super) fn set_saving(&self, saving: bool) {
|
||||
self.flags.saving.store(saving, Ordering::Relaxed);
|
||||
}
|
||||
}
|
||||
enum Publish {
|
||||
Open(TcpListener, LanSettings),
|
||||
Close,
|
||||
|
||||
@@ -21,6 +21,22 @@ impl Game<'_> {
|
||||
draws.extend(self.titles.title(w, h, partial, font, background));
|
||||
hud_layout::paint(batch, &self.gui.atlas, &draws);
|
||||
}
|
||||
/// `Hud.extractSavingIndicator`, under the screens: the option, then the
|
||||
/// fading "Saving world" text.
|
||||
pub(super) fn draw_saving_indicator(&self, batch: &mut HudBatch) {
|
||||
if !self.settings.autosave_indicator {
|
||||
return;
|
||||
}
|
||||
let draws = self.saving_indicator.draw(
|
||||
batch.width as i32,
|
||||
batch.height as i32,
|
||||
self.clock.fraction() as f32,
|
||||
&self.gui.atlas.font,
|
||||
Text::literal(self.translate("menu.savingLevel", "Saving world")),
|
||||
self.settings.text_background(0.0),
|
||||
);
|
||||
hud_layout::paint(batch, &self.gui.atlas, &draws);
|
||||
}
|
||||
/// The selected stack as `Hud.tick` compares it for the name highlight.
|
||||
fn held_name(&self) -> Option<HeldName> {
|
||||
let stack = self.inventory.get(self.selected)?.as_ref()?;
|
||||
@@ -44,6 +60,12 @@ impl Game<'_> {
|
||||
/// The title, action bar and selected-item parts of `Hud.tick`.
|
||||
pub(super) fn tick_hud(&mut self) {
|
||||
self.titles.tick();
|
||||
// `MinecraftServer.isCurrentlySaving` of single player's server.
|
||||
let saving = self
|
||||
.integrated
|
||||
.as_ref()
|
||||
.map_or(self.autosaving, |server| server.is_saving());
|
||||
self.saving_indicator.tick(saving);
|
||||
let held = self.held_name();
|
||||
self.tool_highlight
|
||||
.tick(held, f64::from(self.settings.notification_display_time));
|
||||
|
||||
@@ -191,6 +191,53 @@ pub fn effects(w: i32, demo: bool, effects: &[EffectIcon]) -> Vec<GuiDraw> {
|
||||
out
|
||||
}
|
||||
|
||||
/// The saving indicator: `Hud.tickAutosaveIndicator` fades a value towards 1
|
||||
/// while the server is saving and `extractSavingIndicator` draws the text.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq)]
|
||||
pub struct SavingIndicator {
|
||||
last: f32,
|
||||
value: f32,
|
||||
}
|
||||
impl SavingIndicator {
|
||||
/// `Hud.tickAutosaveIndicator`: `Mth.lerp(0.2F, value, saving ? 1 : 0)`.
|
||||
pub fn tick(&mut self, saving: bool) {
|
||||
self.last = self.value;
|
||||
self.value += (if saving { 1.0 } else { 0.0 } - self.value) * 0.2;
|
||||
}
|
||||
/// `Hud.extractSavingIndicator` without the option check: the text in the
|
||||
/// bottom right corner.
|
||||
pub fn draw(
|
||||
&self,
|
||||
w: i32,
|
||||
h: i32,
|
||||
partial: f32,
|
||||
font: &Font,
|
||||
label: Text,
|
||||
background: u32,
|
||||
) -> Vec<GuiDraw> {
|
||||
let mut out = Vec::new();
|
||||
if self.value <= 0.0 && self.last <= 0.0 {
|
||||
return out;
|
||||
}
|
||||
let fade = (self.last + (self.value - self.last) * partial).clamp(0.0, 1.0);
|
||||
let alpha = (255.0 * fade).floor() as u32;
|
||||
if alpha > 0 {
|
||||
let label_width = width(font, &label);
|
||||
let color = crate::hud_layout::argb(alpha, 255, 255, 255);
|
||||
text_with_backdrop(
|
||||
&mut out,
|
||||
label,
|
||||
w - label_width - 5,
|
||||
h - 9 - 5,
|
||||
label_width,
|
||||
color,
|
||||
background,
|
||||
);
|
||||
}
|
||||
out
|
||||
}
|
||||
}
|
||||
|
||||
/// Titles and the action bar: `Hud.title`, `subtitle`, `titleTime`, the
|
||||
/// fade times and `overlayMessageString` / `overlayMessageTime`.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
|
||||
Reference in New Issue
Block a user