Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Systems_Once

Okay if you actually followed the previous page, then you should have an lib.rs that looks like this:

srclib.rs
use engine::prelude::*;
mod ffi;

#[system_once]
fn hello() {
    log::info!("hello!");
}

The astute among you will notice the big ol' attribute macro #[system_once] before our hello function, and may even connect it to the title of this page! If you did not notice that, then you may need more coffee or to familiarize yourself more with Rust before continuing on.

Putting the S in ECS

In an ECS framework, the system is the thing that actually manipulates entities and their components. In Bloop, they're also your entry point to your game. If you ran your game as is currently with the command ./bloop -g <path_to_your_project_dir>, then you probably saw it output hello! in the log. That's because every system in lib.rs runs automatically, in order, from top to bottom.

You hopefully only saw one hello! output from your game. That's because the hello function is a system_once, meaning it runs only one time. What would happen if you changed it to #[system] instead?

hello!
hello!
hello!
hello!
hello!
hello!
hello!
hello!
hello!
hello!
hello!
hello!
hello!
hello!
hello!
hello!
hello!
hello!
hello!
hello!
hello!
hello!
hello!
hello!
hello!
hello!
hello!
hello!
hello!
hello!
hello!
hello!
hello!
hello!
hello!
hello!
hello!
hello!
hello!
hello!
hello!
hello!
hello!
hello!
hello!
hello!
hello!
hello!
hello!
hello!
hello!
hello!
hello!
hello!
hello!
hello!
hello!
hello!
hello!
hello!
hello!
hello!
hello!
hello!
hello!

That's right, if a system is just tagged with #[system] it runs every frame.

I for one, am sick of seeing that word, so I'm changing my lib.rs to look like this before we hop to the next page, and I recommend you do too:

srclib.rs
use engine::prelude::*;
mod ffi;

Ah, beautiful silence. Let's now get to work and spawn something!