Crate palkia

source
Expand description

§Palkia

An Entity-Component-Message architecture crate.

§What’s an Entity-Component-Message architecture?

Here’s an excert from the blog post I wrote on it:

Like in ECS, under ECM you have entities, which are lists of components. But, instead of linking behavior of different components with systems, you do it by passing messages.

When you implement Component for a struct, you implement a method that registers that struct with different message types. Then, from a message handler, you can fire messages to other entities.

When an entity gets a message, it runs through its components in order, and if that component type registers a handler for that message type, it runs the handler and passes the updated value to the next component, and so on … and then finally returns the modified message to the caller.

And there’s a method on World to pass a message to all entities, as your entrypoint.

Check out the tests or examples for more, I guess.

§Why is it called Palkia?

I’ve been naming the helper crates for Foxfire after Pokemon, just because there’s a lot of them and I don’t want to spend tons of time coming up with names. I picked Palkia specifically because the crate provides a method of organizing data, and Palkia controls space.


Re-exports§

Modules§

  • Traits abstracting over different types of accessors and their capabilities.
  • Lazy and unlazy entity builders.
  • Run code when spawning or despawning an entity with a given component type.
  • Data attachable to entities that control its behavior by listening to messages.
  • Lightweight handles to lists of resources.
  • Blueprint-based entity instantiation loaded from KDL, inspired by Caves of Qud. This used to be a separate crate, dialga.
  • Data sent to an entity and forwarded to each of its components, mutated along the way.
  • Handy module to glob-import and get a bunch of stuff in the crate. It omits some stuff that’s more useful internally, as well as error enum variants (because, tbh, I usually just unwrap everything.)
  • Get components off of entities directly, in a more lightweight way than message passing.
  • Singleton data stored on the world.
  • Serializing and deserializing worlds.
  • The place all the entities, resources, and components live, at the heart of your project.

Macros§

  • Longhand component register macro. You can call this as manually_register_component(MyComponent) if you’re allergic to attribute macros for some reason.
  • Longhand resource register macro. You can call this as manually_register_resource(MyResource) if you’re allergic to attribute macros for some reason.

Structs§

  • Wrapper for a TypeId that also stores the name of the type, to aid in debugging and for nicer error messages.