From 8f1270d90779e9553012639a409dcaae033084b4 Mon Sep 17 00:00:00 2001 From: Mukund Lakshman Date: Sat, 13 Jan 2024 16:45:15 -0800 Subject: [PATCH] Update ASSETS_LOADED one frame later so users can skip the placeholder. --- comfy-core/src/global_state.rs | 8 +++++++- comfy/src/update_stages.rs | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/comfy-core/src/global_state.rs b/comfy-core/src/global_state.rs index 5c86bb6..fbf344c 100644 --- a/comfy-core/src/global_state.rs +++ b/comfy-core/src/global_state.rs @@ -24,6 +24,7 @@ static UNPAUSED_TIME: AtomicU64 = static ASSETS_QUEUED: AtomicUsize = AtomicUsize::new(0); static ASSETS_LOADED: AtomicUsize = AtomicUsize::new(0); +static ASSETS_LOADED_THIS_FRAME: AtomicUsize = AtomicUsize::new(0); /// Returns the total number of assets queued for loading /// by the parallel asset loader. @@ -46,9 +47,14 @@ pub fn assets_loaded() -> usize { } pub fn inc_assets_loaded(newly_loaded_count: usize) { - ASSETS_LOADED.fetch_add(newly_loaded_count, Ordering::SeqCst); + ASSETS_LOADED_THIS_FRAME.fetch_add(newly_loaded_count, Ordering::SeqCst); } +pub fn apply_assets_loaded_this_frame() { + let assets_loaded_this_frame = + ASSETS_LOADED_THIS_FRAME.swap(0, Ordering::SeqCst); + ASSETS_LOADED.fetch_add(assets_loaded_this_frame, Ordering::SeqCst); +} pub fn frame_time() -> f32 { f32::from_bits(FRAME_TIME.load(Ordering::SeqCst)) diff --git a/comfy/src/update_stages.rs b/comfy/src/update_stages.rs index ad3b758..85013ba 100644 --- a/comfy/src/update_stages.rs +++ b/comfy/src/update_stages.rs @@ -55,6 +55,7 @@ fn run_mid_update_stages(c: &mut EngineContext) { // TODO: Some of the ordering in the update stages is definitely incorrect. pub(crate) fn run_late_update_stages(c: &mut EngineContext, delta: f32) { + apply_assets_loaded_this_frame(); update_animated_sprites(c); update_trails(c); update_drawables(c);