ten3roberts / flax

Batteries included ECS library for rust with entity relations and much more
78 stars 5 forks source link

Plan for resources? #2

Closed bayou-brogrammer closed 1 year ago

bayou-brogrammer commented 2 years ago

Coming from specs, legion, and bevy they usually have some sort of Resource management within their ECS, is this on the roadmap for Flax?

ten3roberts commented 2 years ago

Yes.

I have deliberately not included a builtin resources mechanism.

The reasoning is that it is easy to accidentally overwrite resources in different systems or libraries to conflict with each other for shared components/resources.

The preferred way of doing it is to create a static resource entity, which holds resources which are scoped and private to your crate, or however you choose to expose the resource entity.

use

flax::component! {
    /// Holds the game resources
    resources,
}

The resources can then have components added and removed to it.

You can use the world.entity() to use an entry level api for the components, or use a query with QueryBorrow::get on a query with the desired resources for the system

ten3roberts commented 2 years ago

The plan for the next release is to include an easier one-off fetch, to get a AtomicRef<(components)>, rather than having to keep the query alive for the lock. This would make resource handling easier