RobustToolbox
RobustToolbox copied to clipboard
Timed Event System
Proof of concept
Todo:
- [x] Pausing
- [ ] Serializing
what about pausing
todo I guess
This should really just be a component on entities instead...
It can't really work per component. The advantage of this system is how it is orders of magnitude faster then what systems are currently doing. Most systems that are keeping track of time are looping through each component, incrementing a value, and checking if a time elapsed. That method has several disadvantages. It is O(N) on speed, and memory, and it adds a lot of boiler plate code to systems. This method in contrast will use almost no resources for bookkeeping each update, regardless of the number of components that exist, and is very easy to add to a system. Many systems will be able to switch from checking every update to only running on events.
This wouldn't be serializable
I think it could be changed to be serializable. It would require a little bit of transforming, and it would need to tap into the map serialization. Would maybe be stored as a component on the map that serialized as a list of (Id, ComponentType, Key, Duration).
You shouldn't store references to components.
There are advantages to having the component reference:
- They don't need to be looked up.
- If the component gets replaced on the entity, I don't want the timer to fire on a different component.
- I can add a check for the lifecycle of the component later.
Storing data in systems is bad
I could make it into a manager class, but I'm not sure that would improve the code.
This wouldn't be serializable
I think it could be changed to be serializable. It would require a little bit of transforming, and it would need to tap into the map serialization. Would maybe be stored as a component on the map that serialized as a list of (Id, ComponentType, Key, Duration).
That idea didn't work. Putting components all over everything is going to suck.
(I am still keen)