Repository navigation
Conversation
MichalSzandar
left a comment
There was a problem hiding this comment.
Overall well done, but I think Event Listener may not be the best fit here
| class DropCountdown : public EventListener { | ||
| public: | ||
| explicit DropCountdown(LifetimeComponent* lifetime) : lifetime(lifetime) {} | ||
|
|
||
| void onEventTriggered(const Context& context) override { | ||
| (void)context; | ||
| lifetime->elapsedSeconds = 0.0; | ||
| } | ||
|
|
||
| private: | ||
| LifetimeComponent* lifetime; | ||
| }; |
There was a problem hiding this comment.
This seems unnecessary. Maybe it would be a better idea to replace this nested EventListener with a direct call from the owner? Delegate/EventListener is for links between objects, set up by name from the experiment file, where the source doesn't know its listeners (e.g. MarkerEmitter's MarkerEventLink, or planned scriptComponent using obj.on("deactivate", ...)). Lifetime is one of its owner's components, so the owner can just call it.
| DropCountdown dropCountdown{this}; | ||
| // Declared after the listener it points to, so it unsubscribes first. | ||
| std::optional<Subscription> deactivateSubscription; | ||
| }; |
It is safe to assume that activate and deactivate event is never null, because by design SceneObject should always have it. |
Open points
Lifetime hides the object, resets its countdown and fires expire. If something later in the same frame (e.g. a script on another object) turns the object back on, SceneObject::dispatchActivateStatusChange sees no net change, so deactivate does not fire while expire did. The object then gets the full duration again, as the spec asks, but expire and deactivate no longer come together in that case. There is no test for it yet.
Question: is that acceptable, or should deactivate fire here too (that would be a change in SceneObject)?
LifetimeComponent subscribes to it in its constructor without a null check. Today SceneObject always returns it. If that ever changed, the constructor would dereference a null pointer instead of reporting an error. Every Lifetime test constructs a component, so such a change would fail the tests right away.
Question: is that enough, or should the constructor throw std::logic_error when the event is missing?