use bevy_ecs::prelude::*;
use bevy_ecs::schedule::*;
#[derive(Resource, Default, Debug)]
pub struct FrameCount(pub u32);
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)]
pub struct Input;
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)]
pub struct Update;
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)]
pub struct PreLayout;
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)]
pub struct Layout;
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)]
pub struct PostLayout;
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)]
pub struct UISetup;
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)]
pub struct GraphicsSetup;
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)]
pub struct Draw;
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)]
pub struct PreRenderSurface;
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)]
pub struct RenderSurface;
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)]
pub struct Composition;
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)]
pub struct CommitComposition;
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)]
pub struct FrameFinalize;
#[cfg(test)]
mod tests {
use super::*;
use std::collections::hash_map::DefaultHasher;
use std::hash::{Hash, Hasher};
#[test]
fn test_frame_count_default_is_zero() {
assert_eq!(FrameCount::default().0, 0);
}
#[test]
fn test_frame_count_stores_inner_value() {
assert_eq!(FrameCount(42).0, 42);
assert_eq!(FrameCount(u32::MAX).0, u32::MAX);
}
fn hash_of<T: Hash>(value: &T) -> u64 {
let mut hasher = DefaultHasher::new();
value.hash(&mut hasher);
hasher.finish()
}
#[test]
fn test_schedule_labels_equal_themselves() {
assert_eq!(Input, Input);
assert_eq!(Update, Update);
assert_eq!(PreLayout, PreLayout);
assert_eq!(Layout, Layout);
assert_eq!(PostLayout, PostLayout);
assert_eq!(UISetup, UISetup);
assert_eq!(GraphicsSetup, GraphicsSetup);
assert_eq!(Draw, Draw);
assert_eq!(PreRenderSurface, PreRenderSurface);
assert_eq!(RenderSurface, RenderSurface);
assert_eq!(Composition, Composition);
assert_eq!(CommitComposition, CommitComposition);
assert_eq!(FrameFinalize, FrameFinalize);
}
#[test]
fn test_schedule_labels_clone_preserves_equality() {
assert_eq!(Input.clone(), Input);
assert_eq!(Layout.clone(), Layout);
assert_eq!(FrameFinalize.clone(), FrameFinalize);
}
#[test]
fn test_schedule_labels_hash_is_consistent_with_eq() {
assert_eq!(hash_of(&Input), hash_of(&Input));
assert_eq!(hash_of(&Update), hash_of(&Update));
assert_eq!(hash_of(&FrameFinalize), hash_of(&FrameFinalize));
}
#[test]
fn test_schedule_labels_debug_contains_type_name() {
assert_eq!(format!("{:?}", Input), "Input");
assert_eq!(format!("{:?}", Update), "Update");
assert_eq!(format!("{:?}", PreLayout), "PreLayout");
assert_eq!(format!("{:?}", Layout), "Layout");
assert_eq!(format!("{:?}", PostLayout), "PostLayout");
assert_eq!(format!("{:?}", UISetup), "UISetup");
assert_eq!(format!("{:?}", GraphicsSetup), "GraphicsSetup");
assert_eq!(format!("{:?}", Draw), "Draw");
assert_eq!(format!("{:?}", PreRenderSurface), "PreRenderSurface");
assert_eq!(format!("{:?}", RenderSurface), "RenderSurface");
assert_eq!(format!("{:?}", Composition), "Composition");
assert_eq!(format!("{:?}", CommitComposition), "CommitComposition");
assert_eq!(format!("{:?}", FrameFinalize), "FrameFinalize");
}
#[test]
fn test_distinct_schedule_labels_are_not_equal_as_dyn() {
let input: Box<dyn ScheduleLabel> = Box::new(Input);
let update: Box<dyn ScheduleLabel> = Box::new(Update);
let input2: Box<dyn ScheduleLabel> = Box::new(Input);
assert!(input != update, "Input と Update は別ラベル");
assert!(input == input2, "同一バリアントの dyn ラベルは等価");
}
}