-
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
Refactor: initial state sync #1936
Conversation
WalkthroughThe changes involve a substantial refactoring of the communication systems within the project. Key updates include the addition of new GUIDs to assembly definitions, modifications to method signatures for improved clarity, and the introduction of new properties and methods to enhance data encapsulation. The overall structure aims to streamline communication processes and clarify the roles of various components in the system. Changes
Sequence Diagram(s)sequenceDiagram
participant A as Client
participant B as SceneCommunicationPipe
participant C as SDKObservableEventsEngineApiWrapper
A->>B: Send message
B->>C: Process message
C->>B: Acknowledge receipt
B->>A: Confirm delivery
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 (
|
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
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (27)
- Explorer/Assets/DCL/Multiplayer/Connections/DCL.Multiplayer.Connections.asmdef (1 hunks)
- Explorer/Assets/DCL/Multiplayer/Connections/Messaging/Hubs/MessagePipesHub.cs (1 hunks)
- Explorer/Assets/DCL/Multiplayer/Connections/Messaging/Pipe/IMessagePipe.cs (1 hunks)
- Explorer/Assets/Scripts/CrdtEcsBridge/JsModulesImplementation/Communications/CommunicationsControllerAPIImplementation.cs (3 hunks)
- Explorer/Assets/Scripts/CrdtEcsBridge/JsModulesImplementation/Communications/CommunicationsControllerAPIImplementationBase.cs (5 hunks)
- Explorer/Assets/Scripts/CrdtEcsBridge/JsModulesImplementation/Communications/ISceneCommunicationPipe.cs (2 hunks)
- Explorer/Assets/Scripts/CrdtEcsBridge/JsModulesImplementation/Communications/SDKMessageBus/SDKMessageBusCommsAPIImplementation.cs (1 hunks)
- Explorer/Assets/Scripts/CrdtEcsBridge/JsModulesImplementation/Communications/SceneCommunicationPipe.cs (2 hunks)
- Explorer/Assets/Scripts/CrdtEcsBridge/JsModulesImplementation/SDKObservableEventsEngineAPIImplementation.cs (8 hunks)
- Explorer/Assets/Scripts/CrdtEcsBridge/JsModulesImplementation/Tests/CommunicationControllerAPIImplementationShould.cs (5 hunks)
- Explorer/Assets/Scripts/Global/Dynamic/DynamicWorldContainer.cs (1 hunks)
- Explorer/Assets/Scripts/Global/SceneSharedContainer.cs (1 hunks)
- Explorer/Assets/Scripts/SceneRunner/EmptyScene/EmptySceneFacade.cs (2 hunks)
- Explorer/Assets/Scripts/SceneRunner/Scene/ISceneFacade.cs (1 hunks)
- Explorer/Assets/Scripts/SceneRunner/SceneFactory.cs (2 hunks)
- Explorer/Assets/Scripts/SceneRunner/SceneInstanceDeps.cs (3 hunks)
- Explorer/Assets/Scripts/SceneRunner/Tests/SceneFacadeShould.cs (1 hunks)
- Explorer/Assets/Scripts/SceneRunner/Tests/SceneFactoryShould.cs (1 hunks)
- Explorer/Assets/Scripts/SceneRuntime/Apis/Modules/CommunicationsControllerApi/SDKMessageBus/ISDKMessageBusCommsControllerAPI.cs (1 hunks)
- Explorer/Assets/Scripts/SceneRuntime/Apis/Modules/EngineApi/EngineApiWrapper.cs (1 hunks)
- Explorer/Assets/Scripts/SceneRuntime/Apis/Modules/EngineApi/SDKObservableEvents/Events/SDKObservableEvents.cs (2 hunks)
- Explorer/Assets/Scripts/SceneRuntime/Apis/Modules/EngineApi/SDKObservableEvents/Events/csc.rsp (1 hunks)
- Explorer/Assets/Scripts/SceneRuntime/Apis/Modules/EngineApi/SDKObservableEvents/Events/csc.rsp.meta (1 hunks)
- Explorer/Assets/Scripts/SceneRuntime/Apis/Modules/EngineApi/SDKObservableEvents/ISDKObservableEventsEngineApi.cs (1 hunks)
- Explorer/Assets/Scripts/SceneRuntime/Apis/Modules/EngineApi/SDKObservableEvents/SDKObservableEventsEngineApiWrapper.cs (3 hunks)
- Explorer/Assets/Scripts/SceneRuntime/Factory/SceneRuntimeFactory.cs (1 hunks)
- Explorer/Assets/Scripts/SceneRuntime/SceneRuntimeImpl.cs (2 hunks)
Files skipped from review due to trivial changes (5)
- Explorer/Assets/DCL/Multiplayer/Connections/Messaging/Hubs/MessagePipesHub.cs
- Explorer/Assets/DCL/Multiplayer/Connections/Messaging/Pipe/IMessagePipe.cs
- Explorer/Assets/Scripts/Global/Dynamic/DynamicWorldContainer.cs
- Explorer/Assets/Scripts/SceneRuntime/Apis/Modules/EngineApi/SDKObservableEvents/Events/csc.rsp
- Explorer/Assets/Scripts/SceneRuntime/Apis/Modules/EngineApi/SDKObservableEvents/Events/csc.rsp.meta
Additional comments not posted (70)
Explorer/Assets/Scripts/SceneRuntime/Apis/Modules/CommunicationsControllerApi/SDKMessageBus/ISDKMessageBusCommsControllerAPI.cs (1)
8-8
: LGTM!Changing the return type of
SceneCommsMessages
fromList<CommsPayload>
toIReadOnlyList<CommsPayload>
is a good practice. It promotes immutability and encapsulation by preventing external modification of the list while still allowing read access.Explorer/Assets/Scripts/SceneRuntime/Apis/Modules/EngineApi/SDKObservableEvents/ISDKObservableEventsEngineApi.cs (6)
8-8
: LGTM!The code changes are approved.
10-10
: LGTM!The code changes are approved.
14-14
: LGTM!The code changes are approved.
16-16
: LGTM!The code changes are approved.
18-18
: LGTM!The code changes are approved.
20-20
: LGTM!The code changes are approved.
Explorer/Assets/Scripts/CrdtEcsBridge/JsModulesImplementation/Communications/ISceneCommunicationPipe.cs (3)
8-8
: LGTM: The interface name change improves code readability.The new name
ISceneCommunicationPipe
better reflects the purpose of the interface, which is to handle scene communication. This change enhances code readability and maintainability.
20-20
: LGTM: The field name change improves code readability.The new name
FromWalletId
provides a clearer context that the wallet ID is the source of the message. This change enhances code readability and reduces ambiguity.
26-26
: LGTM!The code changes are approved.
Explorer/Assets/DCL/Multiplayer/Connections/DCL.Multiplayer.Connections.asmdef (1)
19-22
: LGTM!The code changes are approved. Adding new GUID references to the assembly definition is a valid change.
Explorer/Assets/Scripts/SceneRunner/Scene/ISceneFacade.cs (1)
17-17
: LGTM!The new property
SceneData
is a good addition to theISceneFacade
interface. It provides a clear and consistent way for implementations of the interface to expose scene-related data, which aligns with the PR objectives.The property is read-only, which is appropriate for an interface, and the name and type are clear and descriptive. The property is also added at an appropriate location within the interface, maintaining the code structure.
Explorer/Assets/Scripts/CrdtEcsBridge/JsModulesImplementation/Communications/SDKMessageBus/SDKMessageBusCommsAPIImplementation.cs (5)
13-13
: LGTM!The code segment is approved for the following reasons:
- The field is properly encapsulated by making it private.
- The readonly modifier ensures that the reference cannot be changed after initialization, which is a good practice.
- The field is initialized with an empty list, which is also a good practice.
15-15
: LGTM!The code segment is approved for the following reasons:
- The property provides read-only access to the
messages
field, which is a good practice for encapsulation.- The property is of type
IReadOnlyList<CommsPayload>
, which is a good choice as it prevents modification of the list from outside the class.
17-17
: LGTM!The code segment is approved for the following reasons:
- The constructor parameters are of appropriate types and follow the interface segregation principle.
- The constructor properly calls the base class constructor with the required parameters.
19-21
: LGTM!The code segment is approved for the following reasons:
- The method provides a way to clear the
messages
field, which is a useful functionality.- The method is properly named and follows the naming convention.
30-39
: LGTM!The code segment is approved for the following reasons:
- The method properly overrides the base class method with the required parameters.
- The method correctly handles the received message by checking the
messageType
and processing onlyMsgType.String
messages.- The method properly decodes the
decodedMessage
usingEncoding.UTF8.GetString
and adds a newCommsPayload
object to themessages
field with the correct properties.Explorer/Assets/Scripts/CrdtEcsBridge/JsModulesImplementation/Communications/CommunicationsControllerAPIImplementation.cs (2)
Line range hint
28-47
: LGTM! Verify the method usage in the codebase.The changes to the
OnMessageReceived
method look good:
- The method signature has been simplified by accepting
MsgType messageType
,ReadOnlySpan<byte> decodedMessage
, andstring fromWalletId
parameters directly.- The method now checks the
messageType
againstMsgType.Uint8Array
and uses thefromWalletId
parameter directly, which enhances clarity and efficiency.Please verify that the
OnMessageReceived
method is called correctly from other parts of the codebase.Run the following script to verify the method usage:
Verification successful
Verification Successful: Method Usage Consistent
The
OnMessageReceived
method with the new signature is correctly defined and overridden in the codebase. The method is used consistently with the new parameters across the relevant files.
CommunicationsControllerAPIImplementationBase.cs
: Abstract method definition.SDKMessageBusCommsAPIImplementation.cs
: Method overridden with the new signature.CommunicationsControllerAPIImplementation.cs
: Method overridden with the new signature.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the usage of `OnMessageReceived` method in the codebase. # Test: Search for the method usage in the codebase. Expect: Only occurrences with the new signature. rg --type cs -A 5 $'OnMessageReceived\(MsgType messageType, ReadOnlySpan<byte> decodedMessage, string fromWalletId\)'Length of output: 2639
16-16
: LGTM! Verify the interface usage in the codebase.The change in the constructor parameter type from
ICommunicationControllerHub
toISceneCommunicationPipe
for themessagePipesHub
parameter looks good.Please verify that the
ISceneCommunicationPipe
interface is implemented correctly and the rest of the codebase is updated to use the new interface.Run the following script to verify the interface usage:
Verification successful
Interface Usage Verified: Refactoring Complete
The
ISceneCommunicationPipe
interface is correctly implemented and used in the codebase. The transition fromICommunicationControllerHub
toISceneCommunicationPipe
has been successfully completed.
ISceneCommunicationPipe
is declared inExplorer/Assets/Scripts/CrdtEcsBridge/JsModulesImplementation/Communications/ISceneCommunicationPipe.cs
.- Implemented by
SceneCommunicationPipe
inExplorer/Assets/Scripts/CrdtEcsBridge/JsModulesImplementation/Communications/SceneCommunicationPipe.cs
.- The old interface
ICommunicationControllerHub
is no longer present in the codebase.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the usage of `ISceneCommunicationPipe` interface in the codebase. # Test 1: Search for the interface declaration. Expect: Only one occurrence. rg --type cs -c $'interface ISceneCommunicationPipe' # Test 2: Search for classes implementing the interface. Expect: At least one implementation. rg --type cs -A 5 $'class \w+ : ISceneCommunicationPipe' # Test 3: Search for the interface usage in the codebase. Expect: No occurrences of the old interface. rg --type cs -c $'ICommunicationControllerHub'Length of output: 2212
Explorer/Assets/Scripts/CrdtEcsBridge/JsModulesImplementation/Communications/SceneCommunicationPipe.cs (6)
16-16
: LGTM!The class name change from
CommunicationControllerHub
toSceneCommunicationPipe
and the interface change fromICommunicationControllerHub
toISceneCommunicationPipe
are consistent and reflect a shift in the class's role within the architecture, likely enhancing clarity regarding its purpose in scene communication.
18-18
: LGTM!The private field
onSceneMessage
type change fromAction<ICommunicationControllerHub.SceneMessage>?
toAction<ISceneCommunicationPipe.SceneMessage>?
is consistent with the class's interface change and ensures that the message handling logic is coherent with the new class structure.
21-21
: LGTM!The constructor change is consistent with the class name change from
CommunicationControllerHub
toSceneCommunicationPipe
and maintains its dependency onIMessagePipesHub
.
33-33
: LGTM!The method
RemoveSceneMessageHandler
parameter type change fromAction<ICommunicationControllerHub.SceneMessage>
toAction<ISceneCommunicationPipe.SceneMessage>
is consistent with the class's interface change and reinforces the class's focus on scene-related messages.
38-38
: LGTM!The method
SetSceneMessageHandler
parameter type change fromAction<ICommunicationControllerHub.SceneMessage>
toAction<ISceneCommunicationPipe.SceneMessage>
is consistent with the class's interface change and reinforces the class's focus on scene-related messages.
30-30
: LGTM!The method
InvokeCurrentHandler
change to invoke the updatedonSceneMessage
with the new message typeISceneCommunicationPipe.SceneMessage
is consistent with the class's interface change and ensures that the message handling logic is coherent with the new class structure.Explorer/Assets/Scripts/SceneRunner/EmptyScene/EmptySceneFacade.cs (1)
29-29
: LGTM!The addition of the read-only
SceneData
property is a good enhancement to theEmptySceneFacade
class. It provides access to scene data while preventing unintended modifications. The property is initialized with a reasonable default value, and the change introduces new capabilities for managing scene-related information without affecting the overall control flow.Explorer/Assets/Scripts/SceneRuntime/Apis/Modules/EngineApi/EngineApiWrapper.cs (1)
73-73
: Verify the impact of the nullable return type on the derived classes and the consumers.The change looks good as it introduces nullability to the return type and provides a consistent default implementation.
However, please ensure that:
- The derived classes that override this method return the correct type.
- The consumers of this method handle the potential null return value appropriately.
Run the following script to verify the impact:
Verification successful
Nullable return type is handled correctly in the derived class and its usage.
The
SendBatch
method's nullable return type is consistently used in theSDKObservableEventsEngineApiWrapper
class, and the potential null return value is appropriately handled with a null check. No other usages were found that might be affected by this change.
- The overridden method in
SDKObservableEventsEngineApiWrapper
uses the nullable return type.- The method usage includes a null check to handle the potential null return value.
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the impact of the nullable return type of `SendBatch` method. # Test 1: Search for the overrides of the method. Expect: Consistent return type. ast-grep --lang csharp --pattern $'class $_ : EngineApiWrapper { $$$ public override ScriptableSDKObservableEventArray? SendBatch() { $$$ } $$$ }' # Test 2: Search for the usages of the method. Expect: Null checks before accessing the return value. rg --type csharp -A 5 $'SendBatch\(\)'Length of output: 2196
Explorer/Assets/Scripts/SceneRuntime/Apis/Modules/EngineApi/SDKObservableEvents/SDKObservableEventsEngineApiWrapper.cs (8)
26-26
: LGTM!The code change is an improvement as it uses a more semantic method name to check for subscriptions.
28-28
: LGTM!The code change is an improvement as it uses a more semantic method name to clear the events.
29-29
: LGTM!The code change is an improvement as it uses a more semantic method name to clear the messages.
52-52
: LGTM!The code change is an improvement as it uses a more semantic method name to check for the subscription.
58-58
: LGTM!The code change is an improvement as it uses a more semantic method name to create the event.
60-60
: LGTM!The code change is an improvement as it uses a more semantic method name to clear the messages.
66-66
: LGTM!The code change is an improvement as it uses a more semantic method name to add the subscription.
72-72
: LGTM!The code change is an improvement as it uses a more semantic method name to remove the subscription.
Explorer/Assets/Scripts/SceneRuntime/Apis/Modules/EngineApi/SDKObservableEvents/Events/SDKObservableEvents.cs (2)
26-26
: LGTM!The code changes are approved.
39-40
: LGTM!The code changes are approved.
Explorer/Assets/Scripts/Global/SceneSharedContainer.cs (1)
69-69
: The change is consistent with the interface renaming and may impact message handling.The change replaces the creation of a
CommunicationControllerHub
object with aSceneCommunicationPipe
object, which is consistent with the interface renaming fromICommunicationControllerHub
toISceneCommunicationPipe
mentioned in the list of alterations.As explained in the AI-generated summary, this change suggests a shift in the underlying communication mechanism utilized by the
SceneSharedContainer
, potentially impacting how messages are handled or routed within the scene.The change is localized and does not introduce any apparent issues.
Explorer/Assets/Scripts/CrdtEcsBridge/JsModulesImplementation/Communications/CommunicationsControllerAPIImplementationBase.cs (7)
13-13
: Good design decision to make the class abstract.Making the
CommunicationsControllerAPIImplementationBase
class abstract enforces it to be subclassed and prevents it from being instantiated directly. This aligns well with the class's purpose of serving as a base for communication controller implementations.
15-15
: ChangingMsgType
enum to public improves usability.Making the
MsgType
enum public allows it to be accessed from outside the assembly. This change enhances the usability of the message types across different components that interact with the communications API.
22-28
: Field changes improve encapsulation and clarity.The changes in the fields are beneficial for the following reasons:
- Changing
cancellationTokenSource
to private encapsulates its usage within the class, which is a good practice.- The removal of
messagePipesHub
and introduction ofsceneCommunicationPipe
align with the constructor's changes and the new communication structure.- The new fields
sceneData
,sceneStateProvider
,jsOperations
, andonMessageReceivedCached
provide necessary dependencies and improve the clarity of the class.
55-57
: Consistent usage of the new communication structure.Updating the
OnSceneIsCurrentChanged
method to utilize the newsceneCommunicationPipe
for setting and removing message handlers ensures that the new communication structure is consistently applied throughout the class. The changes align well with the overall refactoring of the communication mechanism.
66-67
: Good practice to avoid sending empty messages.Checking if the
poolable
length is greater than 0 before sending the message is a good practice to avoid unnecessary processing of empty messages. The code segment is small and focused, making it easy to understand and maintain.
86-91
: Refactoring improves flexibility and maintainability.The refactoring of
SendMessage
intoEncodeAndSendMessage
with aMsgType
parameter improves the flexibility of message encoding based on the type. Making the method protected aligns with the abstract nature of the class and its intended usage by subclasses. Streamlining the encoding logic enhances the clarity and maintainability of the code.
101-112
: New methods improve message handling and promote separation of responsibilities.The introduction of the private
OnMessageReceived
method enhances the class's ability to handle different message formats and improves the clarity of the message processing logic. The method effectively decouples the message decoding logic from the actual message handling, which is delegated to the subclasses through the abstractOnMessageReceived
method.Declaring the abstract
OnMessageReceived
method enforces subclasses to provide their own implementation for handling received messages, promoting a clear separation of responsibilities. This design choice aligns well with the abstract nature of the class and encourages a modular and extensible architecture.Explorer/Assets/Scripts/SceneRunner/Tests/SceneFactoryShould.cs (1)
69-69
: LGTM!The code change aligns the test setup with the refactored communication interface
ISceneCommunicationPipe
, which seems to be a more appropriate substitute for the test context. This change is consistent with the overall refactoring effort to improve the separation of concerns and clarity in the codebase.Explorer/Assets/Scripts/CrdtEcsBridge/JsModulesImplementation/Tests/CommunicationControllerAPIImplementationShould.cs (7)
25-25
: LGTM!The change is consistent with the refactoring effort to replace the communication hub with a communication pipe.
33-33
: LGTM!The change is consistent with the refactoring effort to replace the communication hub with a communication pipe.
42-42
: LGTM!The change is consistent with the refactoring effort to replace the communication hub with a communication pipe.
61-61
: LGTM!The change is consistent with the refactoring effort to replace the communication hub with a communication pipe.
76-76
: LGTM!The change is consistent with the refactoring effort to replace the communication hub with a communication pipe.
104-104
: LGTM!The change is consistent with the refactoring effort to replace the communication hub with a communication pipe.
107-107
: LGTM!The changes are consistent with the refactoring effort to replace the communication hub with a communication pipe.
Also applies to: 109-111, 114-116
Explorer/Assets/Scripts/SceneRuntime/SceneRuntimeImpl.cs (1)
Line range hint
32-43
: Refactoring to simplify the constructor and reduce dependencies.The removal of the
IInstancePoolsProvider
andV8EngineFactory
dependencies from the constructor is a significant refactoring effort to simplify the class's responsibilities and reduce coupling. This change suggests that the class no longer directly manages instance pools or the engine factory.Please verify if the removed dependencies are still required and handled appropriately elsewhere in the codebase. Run the following script to search for usages of
IInstancePoolsProvider
andV8EngineFactory
:Verification successful
Refactoring confirmed: Dependencies are managed elsewhere.
The removal of
IInstancePoolsProvider
andV8EngineFactory
fromSceneRuntimeImpl
is part of a refactoring effort to simplify the class and reduce coupling. These dependencies are still actively used and managed in other parts of the codebase, indicating a shift in design to delegate responsibilities to more appropriate components.
IInstancePoolsProvider
is used in various components, includingCrdtEcsBridge
andSceneRuntime
.V8EngineFactory
is utilized inSceneRuntimeFactory
and related tests.This refactoring aligns with best practices for modularity and separation of concerns.
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Search for usages of `IInstancePoolsProvider` and `V8EngineFactory` in the codebase. # Test 1: Search for `IInstancePoolsProvider` usage. Expect: No results or usage in appropriate components. rg --type cs $'IInstancePoolsProvider' # Test 2: Search for `V8EngineFactory` usage. Expect: No results or usage in appropriate components. rg --type cs $'V8EngineFactory'Length of output: 8607
Explorer/Assets/Scripts/SceneRunner/SceneFactory.cs (2)
53-53
: LGTM!The change in the field type from
ICommunicationControllerHub
toISceneCommunicationPipe
improves clarity and suggests a more specialized interface for scene-related communication.
73-73
: LGTM!The constructor parameter type change for
messagePipesHub
fromICommunicationControllerHub
toISceneCommunicationPipe
aligns with the updated field type, ensuring consistency.Explorer/Assets/Scripts/CrdtEcsBridge/JsModulesImplementation/SDKObservableEventsEngineAPIImplementation.cs (10)
23-24
: LGTM!The code changes are approved.
25-25
: LGTM!The code changes are approved.
35-44
: LGTM!The code changes are approved.
47-53
: LGTM!The code changes are approved.
55-59
: LGTM!The code changes are approved.
61-64
: LGTM!The code changes are approved.
66-69
: LGTM!The code changes are approved.
84-91
: LGTM!The code changes are approved.
105-105
: LGTM!The code changes are approved.
Line range hint
120-227
: LGTM!The code changes are approved.
Explorer/Assets/Scripts/SceneRunner/SceneInstanceDeps.cs (3)
229-229
: LGTM!The change in the interface name from
ICommunicationControllerHub
toISceneCommunicationPipe
for the parametermessagePipesHub
is consistent with the PR objective of renaming the interface for better clarity.
254-254
: LGTM!The change in the constructor parameter type from
ICommunicationControllerHub
toISceneCommunicationPipe
formessagePipesHub
is consistent with the change made in the base class constructor. This ensures that the new interface is used consistently across the class hierarchy.
273-273
: LGTM!The change in the constructor parameter type from
ICommunicationControllerHub
toISceneCommunicationPipe
formessagePipesHub
is consistent with the change made in the base class constructor. This ensures that the new interface is used consistently across the class hierarchy.Explorer/Assets/Scripts/SceneRunner/Tests/SceneFacadeShould.cs (1)
109-109
: LGTM!The change is consistent with the list of alterations. The new interface name
ISceneCommunicationPipe
provides better context about its purpose compared to the old name.
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.
Another small refactoring should be done #1991
But for now, as this refactoring was produced as a side product of other fixes, we can approve it and merge
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
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
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (6)
- Explorer/Assets/Scripts/CrdtEcsBridge/JsModulesImplementation/Communications/CommunicationsControllerAPIImplementation.cs (3 hunks)
- Explorer/Assets/Scripts/CrdtEcsBridge/JsModulesImplementation/Communications/CommunicationsControllerAPIImplementationBase.cs (4 hunks)
- Explorer/Assets/Scripts/CrdtEcsBridge/JsModulesImplementation/Communications/SDKMessageBus/SDKMessageBusCommsAPIImplementation.cs (1 hunks)
- Explorer/Assets/Scripts/CrdtEcsBridge/JsModulesImplementation/Tests/CommunicationControllerAPIImplementationShould.cs (5 hunks)
- Explorer/Assets/Scripts/SceneRunner/SceneFactory.cs (2 hunks)
- Explorer/Assets/Scripts/SceneRunner/SceneInstanceDeps.cs (3 hunks)
Files skipped from review as they are similar to previous changes (2)
- Explorer/Assets/Scripts/CrdtEcsBridge/JsModulesImplementation/Communications/SDKMessageBus/SDKMessageBusCommsAPIImplementation.cs
- Explorer/Assets/Scripts/SceneRunner/SceneFactory.cs
Additional context used
Path-based instructions (4)
Explorer/Assets/Scripts/CrdtEcsBridge/JsModulesImplementation/Communications/CommunicationsControllerAPIImplementation.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/CrdtEcsBridge/JsModulesImplementation/Tests/CommunicationControllerAPIImplementationShould.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/CrdtEcsBridge/JsModulesImplementation/Communications/CommunicationsControllerAPIImplementationBase.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/SceneRunner/SceneInstanceDeps.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 (13)
Explorer/Assets/Scripts/CrdtEcsBridge/JsModulesImplementation/Communications/CommunicationsControllerAPIImplementation.cs (2)
32-32
: RefactoredOnMessageReceived
method.The method now directly accepts message type and content parameters, which simplifies the handling process and improves performance. Verify that all derived classes correctly implement the new method signature.
Run the following script to verify the method's implementation across derived classes:
Also applies to: 34-34, 38-40
Verification successful
Verified: Consistent implementation of
OnMessageReceived
method.The
OnMessageReceived
method with the new signature is correctly implemented in the relevant derived classes. The abstract method inCommunicationsControllerAPIImplementationBase.cs
ensures compliance across implementations. Other instances ofOnMessageReceived
in the codebase are unrelated to this change.
CommunicationsControllerAPIImplementationBase.cs
: Abstract method definition.SDKMessageBusCommsAPIImplementation.cs
: Correct override.CommunicationsControllerAPIImplementation.cs
: Correct override.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the new method signature is implemented correctly in all derived classes. # Test: Search for the method signature in derived classes. Expect: Correct implementation. rg --type cs "OnMessageReceived"Length of output: 4123
19-19
: Constructor parameter type updated.The change from
ICommunicationControllerHub
toISceneCommunicationPipe
is aligned with the PR's objectives to streamline communication handling. Ensure all instances where the old interface was used are updated to the new interface.Run the following script to verify the interface usage:
Verification successful
Transition to
ISceneCommunicationPipe
is complete and consistent.The codebase has been thoroughly updated to use
ISceneCommunicationPipe
instead ofICommunicationControllerHub
. This change is reflected across multiple files, including implementations and tests, ensuring a consistent and comprehensive integration.
ISceneCommunicationPipe
is implemented inSceneCommunicationPipe
.- It is used in various constructors and methods across the codebase.
- Test files reference
ISceneCommunicationPipe
, indicating that the new interface is being tested.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify all references to `ICommunicationControllerHub` have been updated. # Test: Search for the old interface usage. Expect: No occurrences. rg --type cs "ICommunicationControllerHub"Length of output: 42
Script:
#!/bin/bash # Description: Verify the usage of the new interface `ISceneCommunicationPipe`. # Search for the new interface usage to ensure it is implemented and used correctly. rg --type cs "ISceneCommunicationPipe" -A 5Length of output: 18048
Explorer/Assets/Scripts/CrdtEcsBridge/JsModulesImplementation/Tests/CommunicationControllerAPIImplementationShould.cs (3)
65-65
: Updated assertions inSendBinary
test method.The assertions now correctly reference
sceneCommunicationPipe.sendMessageCalls
, ensuring they are aligned with the updated communication handling architecture. Verify that the new assertions correctly check the expected outcomes.Run the following script to verify the correctness of the new assertions:
Verification successful
Verification of assertion change in
SendBinary
test method.The assertion now correctly references
sceneCommunicationPipe.sendMessageCalls
, aligning with the updated communication handling architecture. Ensure thatexpectedCalls
is correctly defined and populated in the test setup to verify the correctness of the new assertions.
- File:
Explorer/Assets/Scripts/CrdtEcsBridge/JsModulesImplementation/Tests/CommunicationControllerAPIImplementationShould.cs
- Line: 65
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the new assertions check the expected outcomes. # Test: Search for the assertion usage in the test suite. Expect: Correct implementation. rg --type cs "CollectionAssert.AreEqual"Length of output: 3199
26-26
: Updated test setup to useTestSceneCommunicationPipe
.The test setup now correctly initializes and uses the new
TestSceneCommunicationPipe
, aligning with the updated communication handling architecture. Verify that the new test component is correctly initialized and used throughout the test suite.Run the following script to verify the test component's initialization and usage:
Also applies to: 34-34, 46-46
Verification successful
Test component
TestSceneCommunicationPipe
is correctly initialized and used.The
TestSceneCommunicationPipe
is properly initialized and actively used in the test suite, confirming its integration into the test logic. The component is involved in assertions and method invocations, ensuring that the tests align with the updated communication handling architecture.
- Initialization:
sceneCommunicationPipe = new TestSceneCommunicationPipe();
- Usage: Involved in assertions and method calls within the test methods.
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the new test component is correctly initialized and used. # Test: Search for the test component usage in the test suite. Expect: Correct initialization and usage. rg --type cs "TestSceneCommunicationPipe"Length of output: 608
Script:
#!/bin/bash # Description: Verify the usage of the test component within the test file. # Test: Search for method calls or interactions involving `sceneCommunicationPipe`. rg --type cs "sceneCommunicationPipe" -A 3Length of output: 8239
80-80
: Updated event invocation inOnMessageReceived
test method.The event invocation now correctly uses
sceneCommunicationPipe.onSceneMessage.Invoke
, ensuring it is aligned with the updated communication handling architecture. Verify that the new event invocation is correctly implemented.Run the following script to verify the correctness of the new event invocation:
Verification successful
Event invocation correctly implemented and verified in test setup.
The
sceneCommunicationPipe
andonSceneMessage
are correctly initialized and used in the test setup. The event invocation is aligned with the updated communication handling architecture and is verified through the test. No further action is required.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the new event invocation is correctly implemented. # Test: Search for the event invocation usage in the test suite. Expect: Correct implementation. rg --type cs "onSceneMessage.Invoke"Length of output: 276
Script:
#!/bin/bash # Description: Check the initialization and usage of `sceneCommunicationPipe` and `onSceneMessage` in the test setup. # Search for the initialization of `sceneCommunicationPipe` in the test file. rg --type cs "sceneCommunicationPipe" -A 5 # Search for the setup or initialization of `onSceneMessage` in the test file. rg --type cs "onSceneMessage" -A 5Length of output: 19120
Explorer/Assets/Scripts/CrdtEcsBridge/JsModulesImplementation/Communications/CommunicationsControllerAPIImplementationBase.cs (5)
16-16
: Class declaration updated toabstract
.The change to declare
CommunicationsControllerAPIImplementationBase
asabstract
enforces a structured inheritance model and prevents direct instantiation. Verify that all derived classes correctly extend this abstract class.Run the following script to verify the class's usage in derived classes:
Verification successful
Derived classes correctly extend the abstract class.
The classes
CommunicationsControllerAPIImplementation
andSDKMessageBusCommsAPIImplementation
correctly extend theCommunicationsControllerAPIImplementationBase
abstract class, ensuring the intended inheritance model is followed. No issues found with the class hierarchy.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the abstract class is correctly extended in all derived classes. # Test: Search for the class usage in derived classes. Expect: Correct extension. rg --type cs "CommunicationsControllerAPIImplementationBase"Length of output: 1504
108-108
: RefactoredSendMessage
intoEncodeAndSendMessage
.The method now allows for more flexible message encoding based on the type and enhances clarity in message handling. Verify that
EncodeAndSendMessage
is correctly implemented and used by subclasses.Run the following script to verify the method's implementation and usage:
Also applies to: 110-113
Verification successful
Verified:
EncodeAndSendMessage
is correctly implemented and used by subclasses.The method is utilized in
SDKMessageBusCommsAPIImplementation.cs
, confirming its intended use for flexible message encoding and sending. No further issues found.
CommunicationsControllerAPIImplementationBase.cs
: Method definition and usage.SDKMessageBusCommsAPIImplementation.cs
: Subclass usage.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the new method is correctly implemented and used by subclasses. # Test: Search for the method's usage in subclasses. Expect: Correct implementation and usage. rg --type cs "EncodeAndSendMessage"Length of output: 651
25-25
: Field visibility and type updated.The changes to the fields, including the modification of
cancellationTokenSource
toprivate
and the introduction ofsceneCommunicationPipe
, enhance encapsulation and align with the architectural adjustments. Verify that the new fields are correctly used within the class and do not introduce any regressions.Run the following script to verify the fields' usage within the class:
Also applies to: 26-26, 44-44
Verification successful
Field usage verified and encapsulation appropriate.
The
cancellationTokenSource
andsceneCommunicationPipe
fields inCommunicationsControllerAPIImplementationBase.cs
are used correctly within the class. The changes enhance encapsulation and align with the intended functionality without introducing regressions.
cancellationTokenSource
is used for managing asynchronous operations safely.sceneCommunicationPipe
is used for handling scene communication effectively.No further action is required.
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the new fields are correctly used within the class. # Test: Search for the fields' usage within the class. Expect: Correct usage. rg --type cs "cancellationTokenSource|sceneCommunicationPipe"Length of output: 26205
123-123
: Introduced newOnMessageReceived
method.The new method processes incoming messages based on their type, enhancing the class's message handling capabilities. Verify that
OnMessageReceived
is correctly implemented and used by subclasses.Run the following script to verify the method's implementation and usage:
Also applies to: 125-132
Verification successful
Verification successful for
OnMessageReceived
method.The
OnMessageReceived
method is correctly implemented and used by subclasses, enhancing the class's message handling capabilities as intended. No issues were found regarding its implementation or usage.
CommunicationsControllerAPIImplementation.cs
: OverridesOnMessageReceived
.SDKMessageBusCommsAPIImplementation.cs
: OverridesOnMessageReceived
.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the new method is correctly implemented and used by subclasses. # Test: Search for the method's usage in subclasses. Expect: Correct implementation and usage. rg --type cs "OnMessageReceived"Length of output: 4123
69-69
: UpdatedOnSceneIsCurrentChanged
method to usesceneCommunicationPipe
.The method now correctly utilizes the new
sceneCommunicationPipe
for setting and removing message handlers, aligning with the updated communication handling architecture. Verify that the method is correctly implemented and does not introduce any regressions.Run the following script to verify the method's implementation:
Also applies to: 71-71
Verification successful
Verified Implementation of
OnSceneIsCurrentChanged
MethodThe
OnSceneIsCurrentChanged
method inCommunicationsControllerAPIImplementationBase.cs
is correctly implemented. It appropriately manages the setting and removal of scene message handlers based on theisCurrent
flag, ensuring alignment with the updated communication handling architecture. No regressions are introduced by this change.
- The method checks
IgnoreIsCurrentScene()
and exits early if true.- It sets or removes the scene message handler using
sceneCommunicationPipe
based on theisCurrent
flag.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the method is correctly implemented. # Test: Search for the method's implementation. Expect: Correct implementation. rg --type cs "OnSceneIsCurrentChanged"Length of output: 3666
Script:
#!/bin/bash # Extract the implementation of OnSceneIsCurrentChanged in CommunicationsControllerAPIImplementationBase.cs ast-grep --lang c_sharp --pattern $'class CommunicationsControllerAPIImplementationBase { $$$ public void OnSceneIsCurrentChanged(bool isCurrent) { $$$ } $$$ }'Length of output: 288
Script:
#!/bin/bash # Use rg to extract the implementation of OnSceneIsCurrentChanged in CommunicationsControllerAPIImplementationBase.cs rg --type cs -A 10 "public void OnSceneIsCurrentChanged" --word-regexpLength of output: 11134
Explorer/Assets/Scripts/SceneRunner/SceneInstanceDeps.cs (3)
254-254
: Verify the implementation and usage ofISceneCommunicationPipe
in this context.The constructor now uses
ISceneCommunicationPipe
. Ensure that the implementation and usage of this new interface are correct and that it integrates well with existing systems in this specific context.Verification successful
Implementation and Usage of
ISceneCommunicationPipe
VerifiedThe
ISceneCommunicationPipe
interface is correctly implemented and integrated within the codebase. It is used appropriately in the constructor ofSceneInstanceDeps.cs
, and its functionality is supported by both production code and unit tests.
- The interface is implemented in
SceneCommunicationPipe.cs
.- It is used in various classes, including
SceneFactory.cs
andSceneInstanceDeps.cs
.- Unit tests effectively mock the interface to ensure its functionality.
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the implementation and usage of `ISceneCommunicationPipe` in the context of `WithRuntimeAndJsAPI`. # Test: Search for the interface implementation and usage. Expect: Correct implementation and usage patterns. rg --type cs -A 5 $'ISceneCommunicationPipe'Length of output: 18048
229-229
: Verify the implementation and usage ofISceneCommunicationPipe
.The constructor now uses
ISceneCommunicationPipe
instead ofICommunicationControllerHub
. Ensure that the implementation and usage of this new interface are correct and that it integrates well with existing systems.Verification successful
Verified: Correct implementation and usage of
ISceneCommunicationPipe
.The
ISceneCommunicationPipe
interface is properly defined and implemented by theSceneCommunicationPipe
class. It is used consistently across the codebase, and its functionality is covered by tests, ensuring correct integration and usage.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the implementation and usage of `ISceneCommunicationPipe`. # Test: Search for the interface implementation and usage. Expect: Correct implementation and usage patterns. rg --type cs -A 5 $'ISceneCommunicationPipe'Length of output: 18048
273-273
: Verify the implementation and usage ofISceneCommunicationPipe
in this context.The constructor now uses
ISceneCommunicationPipe
. Ensure that the implementation and usage of this new interface are correct and that it integrates well with existing systems in this specific context.Verification successful
Implementation and Usage of
ISceneCommunicationPipe
VerifiedThe
ISceneCommunicationPipe
interface is correctly implemented and integrated within the codebase, including theWithRuntimeJsAndSDKObservablesEngineAPI
constructor. The presence of concrete implementations and test cases further supports its proper usage. No issues were found regarding its integration.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the implementation and usage of `ISceneCommunicationPipe` in the context of `WithRuntimeJsAndSDKObservablesEngineAPI`. # Test: Search for the interface implementation and usage. Expect: Correct implementation and usage patterns. rg --type cs -A 5 $'ISceneCommunicationPipe'Length of output: 18048
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
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (3)
- Explorer/Assets/Scripts/CrdtEcsBridge/JsModulesImplementation/Communications/CommunicationsControllerAPIImplementationBase.cs (5 hunks)
- Explorer/Assets/Scripts/CrdtEcsBridge/JsModulesImplementation/Communications/SDKMessageBus/SDKMessageBusCommsAPIImplementation.cs (1 hunks)
- Explorer/Assets/Scripts/CrdtEcsBridge/JsModulesImplementation/Tests/CommunicationControllerAPIImplementationShould.cs (5 hunks)
Files not reviewed due to server errors (3)
- Explorer/Assets/Scripts/CrdtEcsBridge/JsModulesImplementation/Communications/SDKMessageBus/SDKMessageBusCommsAPIImplementation.cs
- Explorer/Assets/Scripts/CrdtEcsBridge/JsModulesImplementation/Tests/CommunicationControllerAPIImplementationShould.cs
- Explorer/Assets/Scripts/CrdtEcsBridge/JsModulesImplementation/Communications/CommunicationsControllerAPIImplementationBase.cs
Additional context used
Path-based instructions (3)
Explorer/Assets/Scripts/CrdtEcsBridge/JsModulesImplementation/Communications/SDKMessageBus/SDKMessageBusCommsAPIImplementation.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/CrdtEcsBridge/JsModulesImplementation/Tests/CommunicationControllerAPIImplementationShould.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/CrdtEcsBridge/JsModulesImplementation/Communications/CommunicationsControllerAPIImplementationBase.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.
78a4315
to
be1b682
Compare
# Conflicts: # Explorer/Assets/Scripts/CrdtEcsBridge/JsModulesImplementation/Communications/CommunicationsControllerAPIImplementation.cs # Explorer/Assets/Scripts/CrdtEcsBridge/JsModulesImplementation/Communications/CommunicationsControllerAPIImplementationBase.cs # Explorer/Assets/Scripts/CrdtEcsBridge/JsModulesImplementation/Communications/SDKMessageBus/SDKMessageBusCommsAPIImplementation.cs # Explorer/Assets/Scripts/CrdtEcsBridge/JsModulesImplementation/Tests/CommunicationControllerAPIImplementationShould.cs # Explorer/Assets/Scripts/SceneRunner/SceneFactory.cs
What does this PR change?
During the network issue research I made a refactor
CommunicationsControllerAPIImplementationBase
and it's no more duplicated in both derived classesCommunicationsControllerAPIImplementationBase
many fields turned to private, to reduce the scope of their possible usageEncodeAndSendMessage
extracted toCommunicationsControllerAPIImplementationBase
and reusedWalletId
renamed toFromWalletId
to give more context of supposed usage of itICommunicationControllerHub
renamed toISceneCommunicationPipe
as it better describes the concern of the objectISDKMessageBusCommsControllerAPI
EngineApiWrapper
ISDKObservableEventsEngineApi
simplified, the spread logic fromSDKObservableEventsEngineApiWrapper
is moved toSDKObservableEventsEngineApi
SceneRuntimeImpl
...
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
New Features
Improvements
ISceneCommunicationPipe
, enhancing clarity and functionality across multiple components.SDKMessageBusCommsAPIImplementation
.Bug Fixes
Tests