Skip to content

Feat/lifetime component - #52

Open
vercws wants to merge 6 commits into
mainfrom
feat/lifetime-component
Open

vercws wants to merge 6 commits into
mainfrom
feat/lifetime-component

Conversation

@vercws

@vercws vercws commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Open points

  1. An object re-activated in the same frame it expires.
    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)?

  1. The constructor assumes SceneObject::getEvent("deactivate") is never null.
    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?

@MichalSzandar MichalSzandar left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall well done, but I think Event Listener may not be the best fit here

Comment on lines +63 to +74
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;
};

@MichalSzandar MichalSzandar Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +79 to +82
DropCountdown dropCountdown{this};
// Declared after the listener it points to, so it unsubscribes first.
std::optional<Subscription> deactivateSubscription;
};

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

@MichalSzandar

MichalSzandar commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Question: is that enough, or should the constructor throw std::logic_error when the event is missing?

It is safe to assume that activate and deactivate event is never null, because by design SceneObject should always have it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants