khora_data/ecs/systems/ecs_maintenance.rs
1// Copyright 2025 eraflo
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! ECS maintenance — drains the queued cleanup / vacuum work each frame.
16//!
17//! Replaces the previous hardcoded `gw.tick_maintenance()` call in the
18//! engine tick. The [`EcsMaintenance`] state lives in the
19//! [`ServiceRegistry`] (inserted at engine init) so the system can fetch
20//! and tick it without any wiring.
21
22use std::sync::{Arc, Mutex};
23
24use khora_core::lane::OutputDeck;
25use khora_core::Runtime;
26
27use crate::ecs::{DataSystemRegistration, EcsMaintenance, TickPhase, World};
28
29fn ecs_maintenance_system(world: &mut World, runtime: &Runtime, _deck: &mut OutputDeck) {
30 let Some(maintenance) = runtime.resources.get::<Arc<Mutex<EcsMaintenance>>>() else {
31 return;
32 };
33 if let Ok(mut guard) = maintenance.lock() {
34 guard.tick(world);
35 }
36}
37
38inventory::submit! {
39 DataSystemRegistration {
40 name: "ecs_maintenance",
41 phase: TickPhase::Maintenance,
42 run: ecs_maintenance_system,
43 order_hint: 0,
44 runs_after: &[],
45 }
46}