-
Notifications
You must be signed in to change notification settings - Fork 11
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: avatar turning with compression, no floaty avatars #2033
Conversation
WalkthroughThe pull request introduces several modifications across multiple files related to the multiplayer movement system. Key changes include renaming parameters for clarity, refactoring compression and decompression logic, and enhancing data structures to optimize memory usage. The Changes
Possibly related PRs
Suggested labels
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Windows and Mac build successfull in Unity Cloud! You can find a link to the downloadable artifact below.
|
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.
Actionable comments posted: 0
Outside diff range and nitpick comments (2)
Explorer/Assets/DCL/Multiplayer/Movement/Systems/csc.rsp (1)
1-1
: Consider enabling nullable only for new code to avoid overwhelming warnings.Enabling nullable reference types is a good practice as it helps prevent null reference exceptions and improves code quality. However, enabling this option for the entire project might lead to many warnings in existing code that hasn't been updated to use nullable reference types.
Consider using
#nullable enable
and#nullable disable
directives to enable nullable reference types only for new code. This way, you can gradually update the existing codebase to use nullable reference types without being overwhelmed by warnings.Explorer/Assets/DCL/Multiplayer/Movement/Encoder/NetworkMessageEncoder.cs (1)
97-132
: LGTM!The redefined
CompressMovementData
method enhances the clarity and maintainability of the code while ensuring that velocity data is accurately represented. The safety check for small velocity magnitudes and the refactored velocity compression logic are great improvements.Consider avoiding the allocation of a new
Vector2
object on lines 103-106 by using thex
andz
components of theposition
vector directly:-var relativePosition = new Vector2( - position.x - (parcel.x * ParcelMathHelper.PARCEL_SIZE), - position.z - (parcel.y * ParcelMathHelper.PARCEL_SIZE) // Y is Z in this case -); +float relativeX = position.x - (parcel.x * ParcelMathHelper.PARCEL_SIZE); +float relativeZ = position.z - (parcel.y * ParcelMathHelper.PARCEL_SIZE); -int compressedX = FloatQuantizer.Compress(relativePosition.x, 0, ParcelMathHelper.PARCEL_SIZE, xzBits); -int compressedZ = FloatQuantizer.Compress(relativePosition.y, 0, ParcelMathHelper.PARCEL_SIZE, xzBits); +int compressedX = FloatQuantizer.Compress(relativeX, 0, ParcelMathHelper.PARCEL_SIZE, xzBits); +int compressedZ = FloatQuantizer.Compress(relativeZ, 0, ParcelMathHelper.PARCEL_SIZE, xzBits);
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (14)
- Explorer/Assets/DCL/Multiplayer/Movement/Encoder/FloatQuantizer.cs (1 hunks)
- Explorer/Assets/DCL/Multiplayer/Movement/Encoder/NetworkMessageEncoder.cs (4 hunks)
- Explorer/Assets/DCL/Multiplayer/Movement/NetworkMovementMessage.cs (1 hunks)
- Explorer/Assets/DCL/Multiplayer/Movement/Settings/MessageEncodingSettings.cs (1 hunks)
- Explorer/Assets/DCL/Multiplayer/Movement/Systems/MultiplayerMovementMessageBus.cs (2 hunks)
- Explorer/Assets/DCL/Multiplayer/Movement/Systems/PlayerMovementNetSendSystem.cs (3 hunks)
- Explorer/Assets/DCL/Multiplayer/Movement/Systems/csc.rsp (1 hunks)
- Explorer/Assets/DCL/Multiplayer/Movement/Systems/csc.rsp.meta (1 hunks)
- Explorer/Assets/DCL/Multiplayer/Movement/Tests/MovementMessageCompressionTests.cs (7 hunks)
- Explorer/Assets/DCL/Multiplayer/Movement/Tests/csc.rsp (1 hunks)
- Explorer/Assets/DCL/Multiplayer/Movement/Tests/csc.rsp.meta (1 hunks)
- Explorer/Assets/DCL/Multiplayer/Movement/csc.rsp (1 hunks)
- Explorer/Assets/DCL/Multiplayer/Movement/csc.rsp.meta (1 hunks)
- Explorer/Assets/Scripts/Global/Dynamic/DynamicWorldContainer.cs (1 hunks)
Files skipped from review due to trivial changes (4)
- Explorer/Assets/DCL/Multiplayer/Movement/Encoder/FloatQuantizer.cs
- Explorer/Assets/DCL/Multiplayer/Movement/Systems/csc.rsp.meta
- Explorer/Assets/DCL/Multiplayer/Movement/Tests/csc.rsp.meta
- Explorer/Assets/DCL/Multiplayer/Movement/csc.rsp.meta
Additional context used
Path-based instructions (7)
Explorer/Assets/DCL/Multiplayer/Movement/Settings/MessageEncodingSettings.cs (2)
Pattern
**/*.cs
: Review the code for heap allocations and suggest potential improvements to avoid runtime allocations.
Pattern
**/*.cs
: Review the code for specific unity engine optimizations and suggest potential improvements.Explorer/Assets/DCL/Multiplayer/Movement/NetworkMovementMessage.cs (2)
Pattern
**/*.cs
: Review the code for heap allocations and suggest potential improvements to avoid runtime allocations.
Pattern
**/*.cs
: Review the code for specific unity engine optimizations and suggest potential improvements.Explorer/Assets/DCL/Multiplayer/Movement/Systems/MultiplayerMovementMessageBus.cs (2)
Pattern
**/*.cs
: Review the code for heap allocations and suggest potential improvements to avoid runtime allocations.
Pattern
**/*.cs
: Review the code for specific unity engine optimizations and suggest potential improvements.Explorer/Assets/DCL/Multiplayer/Movement/Systems/PlayerMovementNetSendSystem.cs (2)
Pattern
**/*.cs
: Review the code for heap allocations and suggest potential improvements to avoid runtime allocations.
Pattern
**/*.cs
: Review the code for specific unity engine optimizations and suggest potential improvements.Explorer/Assets/DCL/Multiplayer/Movement/Encoder/NetworkMessageEncoder.cs (2)
Pattern
**/*.cs
: Review the code for heap allocations and suggest potential improvements to avoid runtime allocations.
Pattern
**/*.cs
: Review the code for specific unity engine optimizations and suggest potential improvements.Explorer/Assets/DCL/Multiplayer/Movement/Tests/MovementMessageCompressionTests.cs (2)
Pattern
**/*.cs
: Review the code for heap allocations and suggest potential improvements to avoid runtime allocations.
Pattern
**/*.cs
: Review the code for specific unity engine optimizations and suggest potential improvements.Explorer/Assets/Scripts/Global/Dynamic/DynamicWorldContainer.cs (2)
Pattern
**/*.cs
: Review the code for heap allocations and suggest potential improvements to avoid runtime allocations.
Pattern
**/*.cs
: Review the code for specific unity engine optimizations and suggest potential improvements.
Additional comments not posted (33)
Explorer/Assets/DCL/Multiplayer/Movement/Tests/csc.rsp (1)
1-1
: Enabling nullable reference types is a good practice, but be prepared to address warnings.Enabling nullable reference types using the
-nullable:enable
compiler option is a good practice as it helps prevent null reference exceptions and improves code quality by enforcing null-safety.However, enabling this feature might lead to new warnings in the existing codebase. Be prepared to address these warnings by updating the code to properly handle null values and adding necessary null checks.
Also, ensure that all team members are aware of this change and understand how to work with nullable reference types effectively.
Explorer/Assets/DCL/Multiplayer/Movement/csc.rsp (1)
1-1
: Ensure project compatibility with nullable reference types.Enabling nullable reference types is a good practice to improve code quality and catch potential null reference exceptions at compile time. However, please ensure that the rest of the project is updated to properly annotate nullable and non-nullable reference types to avoid compilation errors.
Verification successful
Project is compatible with nullable reference types.
The codebase contains multiple files with the
#nullable enable
directive, and no related compilation errors were found. This suggests that the project is compatible with nullable reference types. Ensure ongoing code updates maintain this compatibility.
- Files with
#nullable enable
directive:
Explorer/Assets/Scripts/SceneRunner/Tests/SceneFacadeShould.cs
Explorer/Assets/Scripts/ECS/TestSuite/TestWebRequestController.cs
Explorer/Assets/Scripts/ECS/Unity/Materials/Pooling/MaterialsPool.cs
Explorer/Assets/Scripts/ECS/StreamableLoading/Tests/Urns/UrnsTest.cs
Explorer/Assets/Scripts/ECS/ComponentsPooling/Systems/FinalizeWorldSystemExtensions.cs
Explorer/Assets/DCL/WebRequests/WebContentSizes/ContentLengthBasedWebContentSizes.cs
Explorer/Assets/DCL/WebRequests/WebContentSizes/SeveralWebContentSizes.cs
Explorer/Assets/DCL/WebRequests/WebContentSizes/RangeBasedWebContentSizes.cs
Explorer/Assets/DCL/WebRequests/WebContentSizes/Playground/WebContentsSizesPlayground.cs
Explorer/Assets/DCL/Tests/Editor/CodeConventionTests.cs
Explorer/Assets/DCL/Tests/Editor/ValidationTests.cs
Explorer/Assets/DCL/SDKComponents/AudioSources/AudioSourceExtensions.cs
Explorer/Assets/DCL/SDKComponents/AudioSources/AudioUtils.cs
Explorer/Assets/DCL/SDKComponents/AudioSources/Components/AudioSourceComponent.cs
Explorer/Assets/DCL/Profiles/DataModels/ProfileJsonDto.cs
Explorer/Assets/DCL/PlacesAPIService/IPlacesAPIService.cs
Explorer/Assets/Plugins/SocketIO/SocketIOClient/Transport/WebSockets/DefaultClientWebSocket.cs
Explorer/Assets/Plugins/SocketIO/SocketIOClient/Transport/WebSockets/WebSocketReceiveResult.cs
Explorer/Assets/DCL/PerformanceAndDiagnostics/Optimization/PerformanceBudgeting/Memory/MemoryBudget.cs
Explorer/Assets/DCL/PerformanceAndDiagnostics/Optimization/PerformanceBudgeting/FrameTimeCapBudget.cs
Explorer/Assets/DCL/PerformanceAndDiagnostics/Analytics/AnalyticsController.cs
Explorer/Assets/DCL/PerformanceAndDiagnostics/Analytics/IAnalyticsController.cs
Explorer/Assets/DCL/Multiplayer/Movement/Components/RemotePlayerMovementComponent.cs
Explorer/Assets/DCL/Input/Utils/InteractionCache.cs
Explorer/Assets/DCL/AvatarRendering/Wearables/Helpers/WearablesConstants.cs
Explorer/Assets/DCL/AvatarRendering/AvatarShape/ComputeShader/FixedComputeBufferHandler.cs
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify if the project compiles successfully with nullable reference types enabled. # Test: Search for compilation errors related to nullable reference types. rg --type cs $'#nullable enable' -A 10 | rg $'error CS8600|error CS8602|error CS8603|error CS8604|error CS8618|error CS8625'Length of output: 124
Script:
#!/bin/bash # Description: Verify the presence of `#nullable enable` directives and check for related errors in the codebase. # Search for files with `#nullable enable` directive. rg --type cs '#nullable enable' > nullable_files.txt # Check for nullable reference type errors in the identified files. if [ -s nullable_files.txt ]; then rg --file nullable_files.txt -A 10 | rg 'error CS8600|error CS8602|error CS8603|error CS8604|error CS8618|error CS8625' else echo "No files with #nullable enable directive found." fiLength of output: 187
Script:
#!/bin/bash # Description: List files containing the `#nullable enable` directive. # List files with `#nullable enable` directive. rg --type cs '#nullable enable' --files-with-matchesLength of output: 2030
Explorer/Assets/DCL/Multiplayer/Movement/Settings/MessageEncodingSettings.cs (1)
57-76
: LGTM!The changes improve the encapsulation of the
MovementEncodingConfig
class by:
- Making the fields private and adding the
SerializeField
attribute to allow serialization by Unity.- Introducing public properties to provide read-only access to the private fields.
These changes align with the best practices of object-oriented programming and do not introduce any issues. The code segment does not involve any heap allocations or require any Unity engine-specific optimizations.
Explorer/Assets/DCL/Multiplayer/Movement/NetworkMovementMessage.cs (4)
23-24
: LGTM!The change from
int
tobyte
for thevelocityTier
field is a good optimization to reduce memory usage. The declaration looks good.
25-38
: LGTM!The constructor update to include the new
velocityTier
parameter looks good. The initialization of all the fields in the constructor is correct.
41-42
: LGTM!The usage of the null-forgiving operator in the
ToString
method is a good indication that the JSON serialization is guaranteed to not yield a null result. The change looks good.
43-69
: LGTM!The updates to the
GetHashCode
andEquals
methods look good:
- Including the new
velocityTier
field in theGetHashCode
method ensures that hash codes are unique and account for all relevant data.- The additional comparisons in the
Equals
method improve the accuracy of equality checks between instances of the struct.The implementation of both methods is correct.
Explorer/Assets/DCL/Multiplayer/Movement/Systems/MultiplayerMovementMessageBus.cs (5)
21-21
: LGTM!The
null!
operator is correctly used to suppress the null-state warning for themessageEncoder
field, which is later initialized in theInitializeEncoder
method.
Line range hint
27-37
: LGTM!The constructor has been correctly simplified by removing the
scheme
parameter and associated logic for handling different message compression schemes. The changes align with the PR objective of focusing on a single message format.
80-82
: LGTM!The
WriteAndSend
method has been correctly refactored to remove the conditional logic for handling uncompressed and compressed messages. The changes align with the PR objective of focusing on a single message format.
Line range hint
85-90
: LGTM!The
WriteToProto
method has been correctly updated to accept aCompressedNetworkMovementMessage
, reflecting the new focus on compressed messages. The change aligns with the PR objective.
Line range hint
1-115
: No issues found related to heap allocations or Unity engine optimizations.I reviewed the code for potential heap allocation improvements and Unity engine optimizations as per the additional instructions. Here are my findings:
- Heap allocations:
- The code does not appear to have any unnecessary heap allocations.
- The
CompressedNetworkMovementMessage
object is created using object initializer syntax, which does not cause additional heap allocations.
- Unity engine optimizations:
- The code does not directly interact with Unity engine APIs, so there are no specific Unity engine optimizations to suggest.
Overall, the code looks good from the perspective of heap allocations and Unity engine optimizations.
Explorer/Assets/DCL/Multiplayer/Movement/Systems/PlayerMovementNetSendSystem.cs (2)
Line range hint
115-125
: LGTM!The refactoring of the velocity tier calculation logic into the
VelocityTierFromSpeed
method improves code readability and modularity. The functionality remains unchanged, and the naming convention is consistent.
157-164
: LGTM!The
VelocityTierFromSpeed
method encapsulates the velocity tier calculation logic, which improves code readability and modularity. The implementation using a while loop is simple and efficient, and it does not allocate any memory on the heap, which is good for performance.Explorer/Assets/DCL/Multiplayer/Movement/Encoder/NetworkMessageEncoder.cs (11)
24-25
: LGTM!The changes to the
Compress
method and the refactoredCompressMovementData
method improve the accuracy and maintainability of the movement data compression logic.
62-63
: LGTM!The change improves the readability of the code for extracting the
movementKind
from the compressed temporal data.
64-65
: LGTM!The change improves the readability of the code by assigning the decompressed velocity to a new variable
correctedVelocity
.
68-69
: LGTM!The change aligns with the updated compression logic that uses
velocityTier
instead oftier
.
72-73
: LGTM!The change aligns with the updated decompression logic that assigns the decompressed velocity to a new variable
correctedVelocity
.
78-78
: LGTM!The change aligns with the updated decompression logic that extracts the
movementKind
from the compressed temporal data using a bitwise operation and a mask.
139-143
: LGTM!The change aligns with the updated decompression logic that uses the
settings
object to retrieve the encoding configuration.
146-147
: LGTM!The change aligns with the updated decompression logic that uses the
settings
object to retrieve the encoding configuration.
170-172
: LGTM!The change aligns with the updated decompression logic that handles the sign of the velocity and its absolute value separately using the new
DecompressedVelocity
method.
177-185
: LGTM!The new
CompressedVelocity
method enhances the clarity and maintainability of the code while ensuring that velocity data is accurately represented by handling the sign of the velocity and its absolute value separately.
187-200
: LGTM!The new
DecompressedVelocity
method enhances the clarity and maintainability of the code while ensuring that velocity data is accurately decompressed by handling the sign of the velocity and its absolute value separately. TheNegativeSignFlag
helper method also improves the readability of the code.Explorer/Assets/DCL/Multiplayer/Movement/Tests/MovementMessageCompressionTests.cs (7)
Line range hint
131-145
: LGTM!The test case method looks good and aligns with the updated property name
XZ__BITS
in thesettings.tier3
object.
148-154
: LGTM!The method looks good and aligns with the updated property name
Y__MAX
in theSettings.tier3
object.
167-173
: LGTM!The test case method looks good and aligns with the updated property name
Y__MAX
in thesettings.tier3
object.
181-181
: LGTM!The assertion statement looks good and aligns with the updated property name
Y__MAX
in thesettings.tier3
object.
188-191
: LGTM!The method looks good and aligns with the updated property name
MAX__VELOCITY
in theSettings.tier3
object.
203-212
: LGTM!The test case method looks good and aligns with the updated property name
MAX__VELOCITY
in thesettings.tier3
object.
241-272
: LGTM!The new test case method
FloatCompressDecompress
and the corresponding test case data generator methodFloatCompressDecompressTestCases
look good. They enhance the test suite by providing coverage for the compression logic using theFloatQuantizer
class.Explorer/Assets/Scripts/Global/Dynamic/DynamicWorldContainer.cs (1)
438-438
: Verify the implications of using the default scheme for MultiplayerMovementMessageBus.Removing the
MultiplayerMovementMessageBus.Scheme.Uncompressed
parameter suggests the intention is to use compression for theMultiplayerMovementMessageBus
. This change could impact:
- Network bandwidth usage
- CPU overhead for compressing/decompressing messages
Please verify if this change aligns with the expected behavior and performance requirements.
Run the following script to verify if compression is being used and assess the performance impact:
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.
🟢 Reviewed by QA
What does this PR change?
Fixed FloatQuantizer for approx zero values.
What's the issue was: the issue was in the way how Encoder compresses velocity. Previously it worked like: Encoder takes velocity and clamps it between range (for example -40 and 40) but Quantizer has a precision loss in the compression. When the value is '0' it cannot be encoded as '0', the compression step won't allow it (for example step is 0.33). And it encoded it as 0.33 instead of 0 what caused a constant movement of the avatar in the one direction by 3 axis. And it's the reason why avatars floated in the sky: the value was always positive and unprecised.
It's solved by the setting range from 0 to MaxValue and using one bit as a negative sign, [0; 40] in this example. So when value is actually 0 it's encoded as 0 because it's the closest value. And Encoder uses a sign bit to support negative vectors.
How to test the changes?
Our Code Review Standards
https://github.com/decentraland/unity-renderer/blob/master/docs/code-review-standards.md
Summary by CodeRabbit
Release Notes
New Features
velocityTier
field for better categorization of movement data.Improvements
NetworkMovementMessage
struct for optimized memory usage.MultiplayerMovementMessageBus
.Bug Fixes
Documentation
Tests