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

Make status effect networking not use TryAddStatusEffect #28766

Merged
merged 3 commits into from
Sep 19, 2024

Conversation

ElectroJr
Copy link
Member

@ElectroJr ElectroJr commented Jun 8, 2024

This PR is meant to try stop client side errors like this one:

image

A side effect is that this no longer raises status effect add & remove events during state handling, under the assumption that the effects that those events would normally have would result in modifying networked components (i.e., the state handling should already apply those effects). If that's not the case, like for non-networked client side effects (i.e. flashbang), they can just associate a component and use comp add/remove events.

@ElectroJr ElectroJr added the S: DO NOT MERGE Status: Open item that should NOT be merged. DNM. Allows test to run unlike draft. label Jun 8, 2024
@slarticodefast
Copy link
Member

slarticodefast commented Jun 9, 2024

This does not work with flashes due to prediction issues. Your solution in FlashSystem.cs is the same I tried first when changing it to use the status effect system, but prediction causes the callback in state.Viewport.Viewport.Screenshot(...) in the ReceiveFlash() function to be used multiple times, sometimes even after the status effect alread has disappeared, causing it to use a wrong screenshot. Note that this cannot be observed when using breakpoints, but only when logging to the console with sawmill.

I have an alternative idea to completely get rid of imagesharp in the overlay and use RequestScreenTexture instead. Because this is quite costly performance-wise, an engine change would be needed to allow changing that bool to true only when needed.

@ElectroJr
Copy link
Member Author

ElectroJr commented Jun 9, 2024

But prediction causes the callback in state.Viewport.Viewport.Screenshot(...) in the ReceiveFlash() function to be used multiple times

The same thing happens with the the old status effect event - it should get raised repeatedly whenever the client predicts that an effect started or ended. So AFAIK this shouldn't change the behaviour at all.

A way to fix it might be to have the flash system capture or clear the screenshot during a frameupdate, so that it only happens during the first frame after the component was added, but I'd say reworking that is outside of the scope of this PR

Edit:
Actually it seems like the event handler was only firing once, but was only doing so accidentally due to incidental behaviour of the order in which the state handler applies game states. The even handler was subscribing with the FlashedComponent, which only gets added after the status effect gets added and the after the StatusEffectAddedEvent has already been raised. It just so happens that client state handling adds all new components before applying all comp states for that tick. So the exact kind of subscription on a server-side system wouldn't ever work, and and generally couldn't be used on the client for any predicted effects that the status effect should have. I,.e. subscriptions to StatusEffectAddedEvent shouldn't use the component that gets added by the status effect unless status effects are reworked to change the order in which the comp gets added & the event gets raised.

@slarticodefast
Copy link
Member

Having it done in the frame update is not that simple because the callback takes a few frames. It would need some extra logic to ensure only one screenshot is taken. Sometimes lag even causes the screenshot to be taken even after the component and overlay have been removed.

I don't know how urgent this is, but I can do a separate PR in the next few days to get rid of the the callback completely, which should solve this problem.

@ElectroJr
Copy link
Member Author

I don't know how urgent this is

I don't think its all that urgent? It is the first time I've seen the error reported, and I don't even know what caused it.

@slarticodefast
Copy link
Member

@ElectroJr Done!
#28930

@slarticodefast
Copy link
Member

This will need to be adjusted now that #28930 is merged. No idea why GitHub did not trigger a merge conflict.

@slarticodefast slarticodefast added the S: Awaiting Changes Status: Changes are required before another review can happen label Aug 6, 2024
@ElectroJr ElectroJr added S: Needs Review Status: Requires additional reviews before being fully accepted and removed S: DO NOT MERGE Status: Open item that should NOT be merged. DNM. Allows test to run unlike draft. S: Awaiting Changes Status: Changes are required before another review can happen labels Sep 6, 2024
@metalgearsloth metalgearsloth merged commit bdd0561 into space-wizards:master Sep 19, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S: Needs Review Status: Requires additional reviews before being fully accepted
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants