-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Description
What problem does this solve or what need does it fill?
This is something I've run into in my reactive experiments, but it is also directly relevant to @cart 's discussion on next-gen UI. I want to be able to have a reactive context that depends on an Asset, and be able to treat this the same way that I depend on an ECS component or resource. Specifically, given a (possibly type-erased) asset handle, I want to be able to poll for changes using the change tick by comparing it against the current world tick.
Currently assets have an event-based change detection system that is very different from the change detection on components and resources. This difference makes it a challenge to have a unified approach that integrates changes from all the various kinds of data dependencies.
What solution would you like?
The solution that I am considering seems fairly straightforward: within the asset server, the entry which holds an asset (and which asset handles refer to) would add a ticks field, just like components and resources have; and this field would be updated whenever the asset was loaded, reloaded or otherwise changed state. Just as there are APIs for getting the current asset load state, there would be corresponding APIs for getting the change ticks.
I could then use the return value to poll whether an asset had changed.
This new API would not replace the old event-based change detection system, but would augment it.
What alternative(s) have you considered?
I've considered alternate approaches but they are all quite complex and have non-trivial performance impact. For example, one could keep a separate hash map of all asset handles, which then maps to a tick count, and then keep that map up to date by listening to all asset load events. Conversely, one might be able to make a map of only the assets one is interested in, but this requires inventing some kind of "handle-to-a-handle" so that entries from the map can be dropped when there's no longer interest in watching them. Both of these approaches are highly problematic.
Another approach is to copy the asset you want to depend on into a resource, and then have your reactive UI depend on the resource. The obvious problem here is that it introduces considerable extra boilerplate.