RobustToolbox icon indicating copy to clipboard operation
RobustToolbox copied to clipboard

Timed Event System

Open wrexbe opened this issue 3 years ago • 4 comments

Proof of concept

Todo:

  • [x] Pausing
  • [ ] Serializing

wrexbe avatar Jul 26 '22 03:07 wrexbe

what about pausing

metalgearsloth avatar Jul 26 '22 03:07 metalgearsloth

todo I guess

wrexbe avatar Jul 26 '22 03:07 wrexbe

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.

wrexbe avatar Jul 26 '22 13:07 wrexbe

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.

wrexbe avatar Jul 27 '22 02:07 wrexbe

(I am still keen)

metalgearsloth avatar Sep 14 '22 09:09 metalgearsloth