A prototype API for quill
, Feather's plugin API.
Concepts
- Feather is based on [the ECS architecture], an alternative to classic object-oriented game architecture which is generally more flexible and slightly more performant.
- Feather plugins compile to WebAssembly and are run in a sandboxed environment.
Example plugin
use quill::*;
// Initialize Quill FFI interfaces:
// * creates `_quill_setup` which calls the `setup` function
// * sets the global allocator to defer to host allocation APIs
#![quill::plugin]
struct Counter(u32);
// Called when the plugin is loaded.
pub fn setup(setup: &mut Setup) -> SysResult {
setup.resource(Counter(0))
.system(each_tick);
CommandBuilder::new("increment")
.build(on_increment, setup);
Ok(())
}
fn each_tick(state: &mut State) -> SysResult {
println!("Ticking");
println!("Command has been executed {} times", state.resource::<Counter>()?.0);
Ok(())
}
fn on_increment(state: &mut State, sender: EntityRef, args: &[&str]) -> SysResult {
state.resource_mut::<Counter>()?.0 += 1;
println("Command called with arguments {:?}", args);
Ok(())
}