Trait System

Source
pub trait System<'a> {
    type SystemData: SystemData<'a>;

    const NAME: &'static str;
    const PHASE: Phase;
    const ORIGIN: Origin;

    // Required method
    fn run(job: &mut Job<Self>, data: Self::SystemData);

    // Provided method
    fn sys_name() -> String { ... }
}
Expand description

This trait wraps around specs::System and does additional veloren tasks like metrics collection

use specs::Read;
pub use veloren_common_ecs::{Job, Origin, ParMode, Phase, System};
pub struct Sys;
impl<'a> System<'a> for Sys {
    type SystemData = (Read<'a, ()>, Read<'a, ()>);

    const NAME: &'static str = "example";
    const ORIGIN: Origin = Origin::Frontend("voxygen");
    const PHASE: Phase = Phase::Create;

    fn run(job: &mut Job<Self>, (_read, _read2): Self::SystemData) {
        std::thread::sleep(Duration::from_millis(100));
        job.cpu_stats.measure(ParMode::Rayon);
        std::thread::sleep(Duration::from_millis(500));
        job.cpu_stats.measure(ParMode::Single);
        std::thread::sleep(Duration::from_millis(40));
    }
}

Required Associated Constants§

Source

const NAME: &'static str

Source

const PHASE: Phase

Source

const ORIGIN: Origin

Required Associated Types§

Source

type SystemData: SystemData<'a>

Required Methods§

Source

fn run(job: &mut Job<Self>, data: Self::SystemData)

Provided Methods§

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§