-
Notifications
You must be signed in to change notification settings - Fork 38
Simplify visibility logic #586
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
Conversation
It turns out that we're no longer need to track when the visibility is gained for an entity because it's enough to just check its tick. This allows us to get rid of the visibility enum entirely and heavily simplify the visibility logic.
0abce5d to
1a185ba
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #586 +/- ##
==========================================
- Coverage 78.21% 77.99% -0.23%
==========================================
Files 56 56
Lines 3245 3208 -37
==========================================
- Hits 2538 2502 -36
+ Misses 707 706 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
src/server.rs
Outdated
| // The entity is new for the client if it's mutation tick is not set. | ||
| // This value resets when the entity loses visibility or stops being replicated. | ||
| let new_entity = entity_cache.mutation_tick.is_none(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this to a method on the entity cache. gained_visibility. Also this variable should be gained_visibility, not new_entity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this! But I'm not sure about gained_visibility. How about is_new_for_client? Because it could be a new entity or an entity that just become visible. I pushed this change, let me know what you think.
src/server.rs
Outdated
| visibility_state == Visibility::Gained | ||
| || signature.is_added() | ||
| || ticks.mutation_tick(entity).is_none() | ||
| signature.is_added() || ticks.mutation_tick(entity).is_none() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| signature.is_added() || ticks.mutation_tick(entity).is_none() | |
| signature.is_added() || ticks.gained_visibility(entity, visibility.is_visible(entity)) |
Add gained_visibility method to ClientTicks.
It turns out that we're no longer need to track when the visibility is gained for an entity because it's enough to just check its tick.
This allows us to get rid of the visibility enum entirely and heavily simplify the visibility logic. I added a comment about it and right below we update this tick if the entity is new, so it should be clear from the code.