Implement proper actor/component lifecycle #9

Closed
opened 3 months ago by keith · 3 comments
keith commented 3 months ago
Owner

Currently, the lifecycle described in Scene-Actor-Component model is not actually properly implemented. Specifically, (resume) and (activate) are not called as described during initialization.

To implement this lifecycle, actors should not be properly added to their scenes (via [scene (add-actor)]) immediately after they are created. Instead, a new function should be called to properly initialize them, after all their components and children have been attached.

Currently, the lifecycle described in [Scene-Actor-Component model](https://bytes.keithhacks.cyou/keith/wh-engine/wiki/Scene-Actor-Component-model#lifecycle) is not actually properly implemented. Specifically, `(resume)` and `(activate)` are not called as described during initialization. To implement this lifecycle, actors should *not* be properly added to their scenes (via `[scene (add-actor)]`) immediately after they are created. Instead, a new function should be called to properly initialize them, after all their components and children have been attached.
keith added the
missing
label 3 months ago
keith self-assigned this 3 months ago
Poster
Owner

The (attach-actor-to-world) functionality can probably be done in [scene (add-actor)] instead?

Also, (parent-activated) and (parent-deactivated) should be rolled into the standard (activate)/(deactivate) methods, with some parameter to specify whether it's being called manually or due to a parent changing activation state.

The `(attach-actor-to-world)` functionality can probably be done in `[scene (add-actor)]` instead? Also, `(parent-activated)` and `(parent-deactivated)` should be rolled into the standard `(activate)`/`(deactivate)` methods, with some parameter to specify whether it's being called manually or due to a parent changing activation state.
Poster
Owner

Actually, (attach-actor-to-world) can't really be moved into [scene (add-actor)] because that would also be called when moving an already-initialized actor between scenes.

Actually, `(attach-actor-to-world)` can't really be moved into `[scene (add-actor)]` because that would also be called when moving an already-initialized actor between scenes.
Poster
Owner

Okay so there's an unpredictable bug where (weak-pointer-value child-ptr) will return nil in #[actor (apply-to-tree)]. This happens when garbage collection occurs after the actors have been created in memory, but before (initialize-actors-in) has completed. During this time, the child actors are only referenced by a weak-pointer in their parent, so they are garbage collected. Not entirely sure how to fix this.

Okay so there's an unpredictable bug where `(weak-pointer-value child-ptr)` will return `nil` in `#[actor (apply-to-tree)]`. This happens when garbage collection occurs after the actors have been created in memory, but before `(initialize-actors-in)` has completed. During this time, the child actors are only referenced by a weak-pointer in their parent, so they are garbage collected. Not entirely sure how to fix this.
keith closed this issue 3 months ago
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date

No due date set.

Dependencies

This issue currently doesn't have any dependencies.

Loading…
There is no content yet.