Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ghost life cycle edge cases #29

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Fix ghost life cycle edge cases #29

wants to merge 2 commits into from

Conversation

Popax21
Copy link
Collaborator

@Popax21 Popax21 commented May 24, 2022

This fixes a few edge cases related to ghost life cycles, which can cause ghosts to become invisible, frozen, or not rendered.

@RedFlames
Copy link
Collaborator

There seems to be a conflict between the loop for LastFrames in OnPlayerAdded being moved into scene.OnEndOfFrame += () ...


and the fact that newly created Ghosts also do level.OnEndOfFrame += () => ghost.Active = true; with the result that a lot of spawned Ghosts are permanently disabled, presumably after being created inside this aforementioned loop.
This is because you can't add to OnEndOfFrame from within itself, because Scene.AfterUpdate sets its OnEndOfFrame = null right after executing it, removing any newly added event handlers.

One fix that seems to work is to keep the new OnEndOfFrame but remove the one in CreateGhost, leaving new Ghosts disabled:

level.OnEndOfFrame += () => ghost.Active = true;

and then doing this within CelesteNetMainComponent.Update:

            foreach (Ghost g in Ghosts.Values)
                if (g != null)
                    g.Active = true;

I don't know if this would need a flag on the Ghosts to only activate them once or if doing it unconditionally is fine.

@@ -908,6 +881,22 @@ public CelesteNetMainComponent(CelesteNetClientContext context, Game game)

#endregion

public void ResetState(Player player = null, Session ses = null) {
// Clear ghosts if the scene changed
if (player?.Scene != Player?.Scene) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh I can add these types of comments too, eh.

Forgot to mention this line probably needs to be changed to something like:

if (player != null && player.Scene != Player?.Scene) {

just so we don't delete all Ghosts just because Player is null, probably happens somewhere during respawning.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually my suggestion would change/break Cleanup() behavior, which sets Player to null and removes all Ghosts -- with my suggestion, the Ghost removal wouldn't happen anymore...
Maybe we should seperate the Ghost removal from ResetState?

RedFlames added a commit to RedFlames/CelesteNet that referenced this pull request Sep 30, 2022
RedFlames added a commit to RedFlames/CelesteNet that referenced this pull request Oct 31, 2022
RedFlames added a commit to RedFlames/CelesteNet that referenced this pull request Nov 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants