Skip to main content

crcbl_ecs/
system.rs

1use std::collections::HashMap;
2use std::fmt;
3use std::hash::Hasher;
4
5use crcbl_reflect::Reflect;
6
7use crate::access::Access;
8use crate::component_hash::ComponentHash;
9use crate::entity::Entity;
10
11/// Stub struct for debug-draw context.
12///
13/// Empty for now; this is the hook point for future visualization tooling.
14/// Systems with a debug-draw callback receive a `&DebugCtx` each tick so they
15/// can push lines, labels, or shapes to a shared draw list without depending
16/// on any renderer crate.
17#[derive(Debug)]
18pub struct DebugCtx;
19
20/// Callback type for per-system debug drawing.
21///
22/// Set via [`System::set_debug_draw`]; called once per tick with a
23/// [`&DebugCtx`](DebugCtx). `Send` because the [`System`] holding it is a
24/// [`SystemTrait`], which a schedule may tick on another thread.
25pub type DebugDrawFn = Box<dyn FnMut(&DebugCtx) + Send>;
26
27// ---------------------------------------------------------------------------
28// Object-safe trait
29// ---------------------------------------------------------------------------
30
31/// Object-safe trait every system in the [`Schedule`](crate::Schedule) must
32/// implement.
33///
34/// The concrete [`System<T>`] implements this automatically; custom systems
35/// (e.g. systems that tick multiple arrays at once) implement it directly.
36///
37/// **`Send`**, because a [`Schedule`](crate::Schedule) given a pool ticks the
38/// systems of one stage on the pool's threads
39/// ([`Schedule::set_pool`](crate::Schedule::set_pool)). A system holding an
40/// `Rc` or a `RefCell` handle shares it with something on another thread, and
41/// the bound is what makes that a compile error rather than a race.
42pub trait SystemTrait: Send {
43    /// Human-readable name for the inspector / debug overlay.
44    fn name(&self) -> &str;
45
46    /// Called once per tick by the schedule.
47    ///
48    /// `dt` is the schedule's fixed timestep in seconds — the real tick
49    /// period, not an assumed one. A system that integrates over time must
50    /// use it, or its simulated speed becomes a function of the tick rate.
51    /// See [`World::set_tick_dt`](crate::World::set_tick_dt).
52    fn tick(&mut self, dt: f64);
53
54    /// The [`Shared`](crate::Shared) resources this system's
55    /// [`tick`](Self::tick) reads and writes — everything it touches beyond
56    /// its own arrays.
57    ///
58    /// **Required, with no default**, so that no system inherits "touches
59    /// nothing" by forgetting to answer: a schedule that took a missing answer
60    /// for independence would order nothing and say so confidently. A system
61    /// whose tick works on its own arrays alone answers [`Access::none`].
62    ///
63    /// Asked once, when the system is registered
64    /// ([`Schedule::add_system`](crate::Schedule::add_system)): the schedule
65    /// refuses a name not registered with it, derives the system's conflicts
66    /// with those registered before it, and in debug builds panics if the
67    /// tick touches a resource the answer left out.
68    fn access(&self) -> Access;
69
70    /// Number of entities currently registered with this system.
71    fn entity_count(&self) -> usize;
72
73    /// Remove every entity listed in `dead` from this system.
74    ///
75    /// Called once per tick, after `tick`, with the set of entities that were
76    /// despawned during this tick.
77    fn sweep(&mut self, dead: &[Entity]);
78
79    /// Called once per tick so the system can emit debug-draw primitives.
80    ///
81    /// The default implementation is a no-op; override this rather than
82    /// setting a callback if the system needs access to its own data.
83    fn debug_draw(&mut self, ctx: &DebugCtx);
84
85    /// Hash the system's component state into `hasher`.
86    ///
87    /// The default implementation is a no-op.  Override this to feed
88    /// per-entity component data into a determinism hash (used by
89    /// `crcbl-server`'s sim-hash harness).
90    fn hash_state(&self, _hasher: &mut dyn Hasher) {}
91
92    /// Whether this system's `SystemTrait::hash_state` contributes
93    /// component data to the determinism hash.
94    ///
95    /// Returns `false` by default — systems that override `hash_state`
96    /// must also override this to return `true`, otherwise the
97    /// determinism harness will warn that they are not contributing.
98    /// The concrete [`System<T>`] returns `true`.
99    fn contributes_to_hash(&self) -> bool {
100        false
101    }
102
103    /// Serialise this system's per-entity component data for replication.
104    ///
105    /// Appends `(entity_bits: u64, data_len: u32, data: [u8])` triples — all
106    /// little-endian — to `out`, one per replicated entity. Returns `true`
107    /// if any data was written.
108    ///
109    /// The default returns `false` (system not replicated); the server then
110    /// emits only the entity count for this system. Custom systems that own
111    /// their component arrays (e.g. `crcbl-phys`' `PhysicsSystem`) override
112    /// this to publish real state.
113    fn replicate(&self, _out: &mut Vec<u8>) -> bool {
114        false
115    }
116
117    /// What this system holds for `entity`, for a debug overlay to show.
118    ///
119    /// A selected entity is described by every system that answers `Some`
120    /// here, one section each, with the overlay walking the value's
121    /// [`Reflect::fields`] — so a system describes itself through data, and
122    /// this crate never names a UI. `None` when the system holds nothing for
123    /// `entity`, and always from this default.
124    ///
125    /// **The default is not a check that passes by doing nothing**: nothing is
126    /// verified through this method, and a system that does not override it is
127    /// one the overlay lists no section for — the same complete answer
128    /// [`SystemTrait::replicate`]'s `false` gives the server. The concrete
129    /// [`System<T>`] answers when it was built with [`System::reflected`]; a
130    /// custom system lends whichever of its rows it has a [`Reflect`] value
131    /// for.
132    fn debug_fields(&self, _entity: Entity) -> Option<&dyn Reflect> {
133        None
134    }
135
136    /// Downcast support for callers that hold `&mut dyn SystemTrait` (e.g.
137    /// through [`Schedule::iter_mut`](crate::Schedule::iter_mut)) and need the
138    /// concrete system type.
139    /// Implementations are the one-liner `self`.
140    fn as_any_mut(&mut self) -> &mut dyn std::any::Any;
141}
142
143impl fmt::Debug for dyn SystemTrait {
144    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
145        f.debug_struct("dyn SystemTrait")
146            .field("name", &self.name())
147            .field("entity_count", &self.entity_count())
148            .finish()
149    }
150}
151
152// ---------------------------------------------------------------------------
153// Concrete System<T>
154// ---------------------------------------------------------------------------
155
156/// A system that owns a dense `Vec<T>` of component data plus a sparse
157/// entity→index map.
158///
159/// # Layout
160///
161/// * `data: Vec<T>` — the values, stored contiguously for cache-friendly
162///   iteration.
163/// * `index_to_entity: Vec<Entity>` — parallel to `data`; `index_to_entity[i]`
164///   is the entity that owns `data[i]`.
165/// * `entity_to_index: HashMap<Entity, usize>` — inverse of the above; answers
166///   "where is this entity's data?" in O(1).
167///
168/// Removal uses swap-remove on both vectors and updates the moved entity's
169/// mapping, so removal is O(1) but does not preserve insertion order.
170pub struct System<T> {
171    name: String,
172    data: Vec<T>,
173    entity_to_index: HashMap<Entity, usize>,
174    index_to_entity: Vec<Entity>,
175    debug_draw_fn: Option<DebugDrawFn>,
176    /// How a row is lent to [`SystemTrait::debug_fields`]: set by
177    /// [`System::reflected`], `None` from [`System::new`].
178    reflect: Option<ReflectRow<T>>,
179}
180
181/// A row seen as [`Reflect`]; see [`System::reflected`] for why it is a stored
182/// function rather than a bound.
183type ReflectRow<T> = fn(&T) -> &dyn Reflect;
184
185/// [`ReflectRow`] for a `T` that is [`Reflect`]: the unsizing coercion, named
186/// so it can be stored as a function pointer.
187fn reflect_row<T: Reflect>(row: &T) -> &dyn Reflect {
188    row
189}
190
191impl<T> System<T> {
192    /// Creates an empty system with the given human-readable `name`.
193    #[must_use]
194    pub fn new(name: impl Into<String>) -> Self {
195        Self {
196            name: name.into(),
197            data: Vec::new(),
198            entity_to_index: HashMap::new(),
199            index_to_entity: Vec::new(),
200            debug_draw_fn: None,
201            reflect: None,
202        }
203    }
204
205    /// The system's name (same as [`SystemTrait::name`]).
206    #[must_use]
207    pub fn name(&self) -> &str {
208        &self.name
209    }
210
211    // -- registration -------------------------------------------------------
212
213    /// Registers `entity` with this system, storing `data`.
214    ///
215    /// If `entity` is already registered, its existing data is overwritten
216    /// in-place. Otherwise a new entry is pushed.
217    ///
218    /// `entity` must be alive. A system owns no entity pool and so cannot
219    /// check: attaching a handle that [`World::sweep`](crate::World::sweep)
220    /// has already retired stores data that nothing will ever remove, and it
221    /// counts towards [`SystemTrait::entity_count`] and
222    /// [`SystemTrait::hash_state`] for the rest of the run.
223    pub fn attach(&mut self, entity: Entity, data: T) {
224        if let Some(&index) = self.entity_to_index.get(&entity) {
225            self.data[index] = data;
226        } else {
227            let index = self.data.len();
228            self.data.push(data);
229            self.index_to_entity.push(entity);
230            self.entity_to_index.insert(entity, index);
231        }
232    }
233
234    /// Removes `entity` from this system, returning its data if it was
235    /// registered.
236    ///
237    /// Uses swap-remove: O(1) but may reorder the remaining entries.
238    pub fn detach(&mut self, entity: Entity) -> Option<T> {
239        let index = self.entity_to_index.remove(&entity)?;
240        let last = self.data.len() - 1;
241        if index != last {
242            self.data.swap(index, last);
243            self.index_to_entity.swap(index, last);
244            let moved_entity = self.index_to_entity[index];
245            self.entity_to_index.insert(moved_entity, index);
246        }
247        self.index_to_entity.pop();
248        Some(self.data.pop().unwrap())
249    }
250
251    // -- lookup ---------------------------------------------------------------
252
253    /// Borrows the data for `entity`, or `None` if it isn't registered.
254    #[must_use]
255    pub fn get(&self, entity: Entity) -> Option<&T> {
256        let &index = self.entity_to_index.get(&entity)?;
257        Some(&self.data[index])
258    }
259
260    /// Mutably borrows the data for `entity`.
261    #[must_use]
262    pub fn get_mut(&mut self, entity: Entity) -> Option<&mut T> {
263        let &index = self.entity_to_index.get(&entity)?;
264        Some(&mut self.data[index])
265    }
266
267    // -- iteration -----------------------------------------------------------
268
269    /// Iterates all component data in storage order (contiguous, cache-friendly).
270    pub fn iter(&self) -> impl Iterator<Item = &T> {
271        self.data.iter()
272    }
273
274    /// Mutably iterates all component data in storage order.
275    pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut T> {
276        self.data.iter_mut()
277    }
278
279    /// Iterates `(entity, &data)` pairs.
280    pub fn iter_entities(&self) -> impl Iterator<Item = (Entity, &T)> {
281        self.index_to_entity.iter().copied().zip(self.data.iter())
282    }
283
284    // -- debug draw ----------------------------------------------------------
285
286    /// Sets a callback invoked each tick by [`SystemTrait::debug_draw`].
287    ///
288    /// Pass `None` to clear a previously-set callback.
289    pub fn set_debug_draw(&mut self, f: Option<DebugDrawFn>) {
290        self.debug_draw_fn = f;
291    }
292}
293
294impl<T: Reflect> System<T> {
295    /// [`System::new`], for a component a debug overlay can read: this
296    /// system's [`SystemTrait::debug_fields`] answers with the entity's row.
297    ///
298    /// **A constructor rather than a bound**, because the bound cannot be
299    /// added: `SystemTrait` is implemented for every `System<T>` whose `T` is
300    /// [`ComponentHash`], tuples and `char` among them, and neither of those is
301    /// [`Reflect`]. Bounding that impl on `Reflect` would stop every such
302    /// system from being registered at all, and stable Rust has no
303    /// specialisation to answer differently for the `T` that is. So the choice
304    /// is made where `T` is known to be `Reflect` — here — and kept as the one
305    /// function pointer that coercion needs.
306    #[must_use]
307    pub fn reflected(name: impl Into<String>) -> Self {
308        Self {
309            reflect: Some(reflect_row::<T>),
310            ..Self::new(name)
311        }
312    }
313}
314
315impl<T: ComponentHash + Send + 'static> SystemTrait for System<T> {
316    fn name(&self) -> &str {
317        &self.name
318    }
319
320    fn tick(&mut self, _dt: f64) {
321        // Default: no-op. Users that need per-tick logic iterate the system
322        // directly or implement `SystemTrait` on their own type.
323    }
324
325    /// Nothing shared: the tick does nothing, and the arrays are its own.
326    fn access(&self) -> Access {
327        Access::none()
328    }
329
330    fn entity_count(&self) -> usize {
331        self.data.len()
332    }
333
334    fn sweep(&mut self, dead: &[Entity]) {
335        for &entity in dead {
336            self.detach(entity);
337        }
338    }
339
340    fn debug_draw(&mut self, ctx: &DebugCtx) {
341        if let Some(ref mut f) = self.debug_draw_fn {
342            f(ctx);
343        }
344    }
345
346    /// Hashes `(entity, component)` pairs in ascending entity order.
347    ///
348    /// Storage order is not canonical — `detach` swap-removes, so two systems
349    /// holding the same logical state reach different `data` orders from
350    /// different attach/detach histories. Sorting by entity makes the hash a
351    /// function of the state alone.
352    fn hash_state(&self, hasher: &mut dyn Hasher) {
353        let mut order: Vec<usize> = (0..self.data.len()).collect();
354        order.sort_unstable_by_key(|&i| self.index_to_entity[i].to_bits());
355        for i in order {
356            hasher.write(&self.index_to_entity[i].to_bits().to_le_bytes());
357            self.data[i].hash_component(hasher);
358        }
359    }
360
361    fn contributes_to_hash(&self) -> bool {
362        true
363    }
364
365    /// The entity's row, when this system was built with
366    /// [`System::reflected`].
367    fn debug_fields(&self, entity: Entity) -> Option<&dyn Reflect> {
368        let reflect = self.reflect?;
369        self.get(entity).map(reflect)
370    }
371
372    fn as_any_mut(&mut self) -> &mut dyn std::any::Any {
373        self
374    }
375}
376
377impl<T> fmt::Debug for System<T> {
378    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
379        f.debug_struct("System")
380            .field("name", &self.name)
381            .field("entity_count", &self.data.len())
382            .finish()
383    }
384}
385
386// ---------------------------------------------------------------------------
387// Tests
388// ---------------------------------------------------------------------------
389
390#[cfg(test)]
391mod tests {
392    use std::sync::Arc;
393    use std::sync::atomic::{AtomicBool, Ordering};
394
395    use super::*;
396
397    fn e(idx: u32) -> Entity {
398        crate::test_entity(idx, 1)
399    }
400
401    #[test]
402    fn a_component_attached_to_an_entity_is_what_get_answers_with() {
403        let mut sys = System::<i32>::new("test");
404        let ent = e(1);
405        sys.attach(ent, 42);
406        assert_eq!(sys.get(ent), Some(&42));
407    }
408
409    #[test]
410    fn attaching_twice_to_one_entity_replaces_the_value_without_adding_a_row() {
411        let mut sys = System::<i32>::new("test");
412        let ent = e(1);
413        sys.attach(ent, 10);
414        sys.attach(ent, 99);
415        assert_eq!(sys.entity_count(), 1);
416        assert_eq!(sys.get(ent), Some(&99));
417    }
418
419    #[test]
420    fn detach_removes_and_reorders() {
421        let mut sys = System::<i32>::new("test");
422        let a = e(1);
423        let b = e(2);
424        let c = e(3);
425        sys.attach(a, 1);
426        sys.attach(b, 2);
427        sys.attach(c, 3);
428
429        assert_eq!(sys.detach(b), Some(2));
430        assert_eq!(sys.entity_count(), 2);
431        assert_eq!(sys.get(b), None);
432        // a and c must still be present
433        assert!(sys.get(a).is_some());
434        assert!(sys.get(c).is_some());
435    }
436
437    #[test]
438    fn detach_unknown_returns_none() {
439        let mut sys = System::<i32>::new("test");
440        let ent = e(42);
441        assert_eq!(sys.detach(ent), None);
442    }
443
444    #[test]
445    fn double_detach_is_safe() {
446        let mut sys = System::<i32>::new("test");
447        let ent = e(1);
448        sys.attach(ent, 7);
449        assert_eq!(sys.detach(ent), Some(7));
450        assert_eq!(sys.detach(ent), None);
451        assert_eq!(sys.entity_count(), 0);
452    }
453
454    #[test]
455    fn iter_yields_all_values() {
456        let mut sys = System::<i32>::new("test");
457        sys.attach(e(1), 10);
458        sys.attach(e(2), 20);
459        let mut sum = 0;
460        for v in sys.iter() {
461            sum += *v;
462        }
463        assert_eq!(sum, 30);
464    }
465
466    #[test]
467    fn iter_mut_allows_mutation() {
468        let mut sys = System::<i32>::new("test");
469        let a = e(1);
470        let b = e(2);
471        sys.attach(a, 1);
472        sys.attach(b, 2);
473        for v in sys.iter_mut() {
474            *v *= 10;
475        }
476        assert_eq!(sys.get(a), Some(&10));
477        assert_eq!(sys.get(b), Some(&20));
478    }
479
480    #[test]
481    fn iter_entities_yields_pairs() {
482        let mut sys = System::<&str>::new("test");
483        let a = e(10);
484        let b = e(20);
485        sys.attach(a, "alpha");
486        sys.attach(b, "beta");
487
488        let mut pairs: Vec<_> = sys.iter_entities().map(|(ent, d)| (ent, *d)).collect();
489        pairs.sort_by_key(|(ent, _)| ent.to_bits());
490        assert_eq!(pairs, vec![(a, "alpha"), (b, "beta")]);
491    }
492
493    #[test]
494    fn sweep_removes_dead_entities() {
495        let mut sys = System::<i32>::new("test");
496        let a = e(1);
497        let b = e(2);
498        let c = e(3);
499        sys.attach(a, 1);
500        sys.attach(b, 2);
501        sys.attach(c, 3);
502
503        sys.sweep(&[b, c]);
504        assert_eq!(sys.entity_count(), 1);
505        assert!(sys.get(a).is_some());
506        assert!(sys.get(b).is_none());
507        assert!(sys.get(c).is_none());
508    }
509
510    #[test]
511    fn sweep_empty_dead_list_is_noop() {
512        let mut sys = System::<i32>::new("test");
513        sys.attach(e(1), 42);
514        sys.sweep(&[]);
515        assert_eq!(sys.entity_count(), 1);
516    }
517
518    #[test]
519    fn sweep_unknown_entity_is_noop() {
520        let mut sys = System::<i32>::new("test");
521        sys.attach(e(1), 42);
522        let ghost = e(999);
523        sys.sweep(&[ghost]);
524        assert_eq!(sys.entity_count(), 1);
525    }
526
527    #[test]
528    fn debug_draw_callback_is_called() {
529        let mut sys = System::<i32>::new("test");
530        let called = Arc::new(AtomicBool::new(false));
531        let called2 = Arc::clone(&called);
532        sys.set_debug_draw(Some(Box::new(move |_ctx| {
533            called2.store(true, Ordering::SeqCst);
534        })));
535        sys.debug_draw(&DebugCtx);
536        assert!(called.load(Ordering::SeqCst));
537    }
538
539    /// The neighbour above proves the hook is called when one is set; this is
540    /// the other half, and it used to be spelled as "must not panic" — which a
541    /// `debug_draw` that called a *stale* callback would also satisfy.
542    #[test]
543    fn debug_draw_without_a_callback_calls_nothing() {
544        let mut sys = System::<i32>::new("test");
545        let called = Arc::new(AtomicBool::new(false));
546        let called2 = Arc::clone(&called);
547        sys.set_debug_draw(Some(Box::new(move |_ctx| {
548            called2.store(true, Ordering::SeqCst);
549        })));
550        sys.set_debug_draw(None);
551
552        sys.debug_draw(&DebugCtx);
553        assert!(
554            !called.load(Ordering::SeqCst),
555            "a callback that has been taken away must not still run"
556        );
557    }
558
559    #[test]
560    fn hash_state_ignores_attach_and_detach_history() {
561        use std::collections::hash_map::DefaultHasher;
562
563        fn hash(sys: &System<i32>) -> u64 {
564            let mut h = DefaultHasher::new();
565            sys.hash_state(&mut h);
566            h.finish()
567        }
568
569        let (a, b, c) = (e(1), e(2), e(3));
570
571        // Same logical state, reached two ways.  The second system's `data`
572        // ends up in swap-remove order, which is not ascending entity order.
573        let mut direct = System::<i32>::new("s");
574        direct.attach(a, 10);
575        direct.attach(b, 20);
576        direct.attach(c, 30);
577
578        let mut churned = System::<i32>::new("s");
579        churned.attach(c, 30);
580        churned.attach(e(4), 40);
581        churned.attach(a, 10);
582        churned.detach(e(4));
583        churned.attach(b, 20);
584
585        assert_eq!(hash(&direct), hash(&churned));
586
587        // The hash still tracks the state itself.
588        let mut changed = System::<i32>::new("s");
589        changed.attach(a, 10);
590        changed.attach(b, 20);
591        changed.attach(c, 31);
592        assert_ne!(hash(&direct), hash(&changed));
593    }
594
595    #[test]
596    fn a_system_reports_the_name_it_was_built_with() {
597        let sys = System::<i32>::new("physics");
598        assert_eq!(sys.name(), "physics");
599    }
600
601    /// A component an overlay can read, with a field the reflection is
602    /// checked against by name and by value.
603    #[derive(crcbl_reflect::Reflect, Clone, Copy, Debug, PartialEq)]
604    struct Health {
605        current: i32,
606        #[reflect(name = "Max")]
607        max: i32,
608    }
609
610    impl ComponentHash for Health {
611        fn hash_component(&self, hasher: &mut dyn Hasher) {
612            self.current.hash_component(hasher);
613            self.max.hash_component(hasher);
614        }
615    }
616
617    #[test]
618    fn a_reflected_system_lends_the_entitys_own_row_and_nothing_for_others() {
619        use crcbl_reflect::{Value, get_path};
620
621        let (held, other, absent) = (e(1), e(2), e(3));
622        let mut sys = System::<Health>::reflected("health");
623        sys.attach(other, Health { current: 1, max: 2 });
624        sys.attach(held, Health { current: 7, max: 9 });
625
626        let row = sys
627            .debug_fields(held)
628            .expect("the system holds this entity");
629        assert_eq!(row.type_name(), "Health");
630        assert_eq!(row.fields()[1].label, "Max");
631        assert_eq!(
632            get_path(row, "current"),
633            Ok(Value::Int(7)),
634            "the row is this entity's, not the first one stored"
635        );
636        assert_eq!(get_path(row, "max"), Ok(Value::Int(9)));
637
638        assert!(
639            sys.debug_fields(absent).is_none(),
640            "an entity the system does not hold has no row to lend"
641        );
642    }
643
644    #[test]
645    fn a_system_that_lends_nothing_answers_none() {
646        struct Silent;
647        impl SystemTrait for Silent {
648            fn name(&self) -> &str {
649                "silent"
650            }
651            fn access(&self) -> Access {
652                Access::none()
653            }
654            fn tick(&mut self, _dt: f64) {}
655            fn entity_count(&self) -> usize {
656                1
657            }
658            fn sweep(&mut self, _dead: &[Entity]) {}
659            fn debug_draw(&mut self, _ctx: &DebugCtx) {}
660            fn as_any_mut(&mut self) -> &mut dyn std::any::Any {
661                self
662            }
663        }
664        assert!(
665            Silent.debug_fields(e(1)).is_none(),
666            "the default lends nothing, whatever the system holds"
667        );
668
669        // `System::new` keeps the rows to itself even for a `T` that is
670        // `Reflect`: only `System::reflected` opts in.
671        let mut plain = System::<Health>::new("plain");
672        plain.attach(e(1), Health { current: 1, max: 1 });
673        assert!(plain.debug_fields(e(1)).is_none());
674    }
675
676    #[test]
677    fn a_systems_debug_output_names_it_and_reports_its_entity_count() {
678        let mut sys = System::<i32>::new("render");
679        sys.attach(e(7), 1);
680        let s = format!("{sys:?}");
681        assert!(s.contains("render"));
682        assert!(s.contains("entity_count: 1"));
683    }
684}