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

feat: portable experiences #1354

Merged
merged 156 commits into from
Sep 13, 2024
Merged

feat: portable experiences #1354

merged 156 commits into from
Sep 13, 2024

Conversation

fcolarich
Copy link
Contributor

@fcolarich fcolarich commented Jul 2, 2024

What does this PR change?

In this PR we are adding the Portable Experiences functionality. It includes the API so scenes can trigger it and also enables temporarily the possibility to load the global PX that we will use for exploration minigames. This will be replaced with a connection to Unleash and downloading from there the PXs we want at the start of the session, but for now this is hardcoded.

Also, for now PX can only be started by using their ens, as I havent implemented loading from urns yet. It requires some further digging that for now is not needed for the exploration minigames.
The functionality of the PX is pretty non well defined, but basically they run all the time in all scenes and keep running even if players switch worlds.
So each PX is a new realm and also a new scene running on that realm using its own scene facade for it.
For now it looks practically the same as the normal scene facade, but as new functionality or compatibility is added to the PX, it will be changed.

Another thing that was not implemented as its not needed for now is disabling PXs when entering scenes that dont allow them. This will also be added further along the road when refining this and the exploration minigames shape is delivered.
...

How to test the changes?

The global PX will be loaded as soon as the game starts. I want to modify it so we can kill it by pressing a button on the PX UI, but that requires help from Pejo. So I hope tomorrow afternoon it can be done already.

Summary by CodeRabbit

  • New Features

    • Enhanced the management of portable experiences with a new controller interface.
    • Introduced chat commands for loading and unloading portable experiences dynamically.
    • Added centralized feature flag management for portable experiences, improving modularity.
    • Expanded debug settings to allow retrieval of portable experiences to load.
    • Updated scene management to handle portable experiences more effectively.
  • Bug Fixes

    • Improved logic for scene cache clearing to include portable experiences.
  • Documentation

    • Updated documentation to clarify the new functionalities related to portable experiences.
  • Style

    • Improved code readability and maintainability through consistent formatting.
  • Tests

    • Adjusted tests to accommodate changes in portable experience management and scene handling.

Copy link
Contributor

github-actions bot commented Jul 2, 2024

badge

Windows and Mac build successfull in Unity Cloud! You can find a link to the downloadable artifact below.

Name Link
Commit 9268d0c
Logs https://github.com/decentraland/unity-explorer/actions/runs/10852849210
Download Windows https://github.com/decentraland/unity-explorer/suites/28365538888/artifacts/1930942233
Download Mac https://github.com/decentraland/unity-explorer/suites/28365538888/artifacts/1930903556
Built on 2024-09-13T17:17:44Z

@m3taphysics m3taphysics changed the title Feat/portable experiences feat: portable experiences Jul 3, 2024
@fcolarich fcolarich requested review from mikhail-dcl, lorux0 and dalkia and removed request for mikhail-dcl and lorux0 July 14, 2024 21:50
@fcolarich fcolarich self-assigned this Jul 14, 2024
@fcolarich fcolarich marked this pull request as ready for review July 14, 2024 21:51
Copy link

@coderabbitai coderabbitai bot left a 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

Commits

Files that changed from the base of the PR and between 05ed346 and 13c1917.

Files selected for processing (6)
  • Explorer/Assets/Scripts/Global/Dynamic/Bootstraper.cs (2 hunks)
  • Explorer/Assets/Scripts/Global/Dynamic/ChatCommands/LoadPortableExperienceChatCommand.cs (1 hunks)
  • Explorer/Assets/Scripts/Global/Dynamic/ChatCommands/LoadPortableExperienceChatCommand.cs.meta (1 hunks)
  • Explorer/Assets/Scripts/Global/Dynamic/DynamicWorldContainer.cs (8 hunks)
  • Explorer/Assets/Scripts/Global/Dynamic/PortableExperiences/ECSPortableExperiencesController.cs (1 hunks)
  • Explorer/Assets/Scripts/Global/Dynamic/PortableExperiences/IPortableExperiencesController.cs (1 hunks)
Files skipped from review due to trivial changes (1)
  • Explorer/Assets/Scripts/Global/Dynamic/ChatCommands/LoadPortableExperienceChatCommand.cs.meta
Files skipped from review as they are similar to previous changes (3)
  • Explorer/Assets/Scripts/Global/Dynamic/DynamicWorldContainer.cs
  • Explorer/Assets/Scripts/Global/Dynamic/PortableExperiences/ECSPortableExperiencesController.cs
  • Explorer/Assets/Scripts/Global/Dynamic/PortableExperiences/IPortableExperiencesController.cs
Additional context used
Path-based instructions (2)
Explorer/Assets/Scripts/Global/Dynamic/ChatCommands/LoadPortableExperienceChatCommand.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/Bootstraper.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 (2)
Explorer/Assets/Scripts/Global/Dynamic/ChatCommands/LoadPortableExperienceChatCommand.cs (1)

1-60: LGTM!

The code for the LoadPortableExperienceChatCommand class is well-structured, follows best practices, and effectively implements the chat command functionality for loading portable experiences.

Some key observations:

  1. The command syntax is clearly defined using a regular expression pattern, which is well-documented with an example.
  2. The ExecuteAsync method handles the command execution asynchronously, providing appropriate error handling and user feedback.
  3. The code uses the IPortableExperiencesController to create the portable experience, promoting a modular and decoupled design.
  4. The code does not contain any obvious performance issues or potential runtime allocations.

Overall, the code changes are approved.

Explorer/Assets/Scripts/Global/Dynamic/Bootstraper.cs (1)

125-125: LGTM!

The addition of staticContainer.PortableExperiencesController as an argument to the DynamicWorldContainer.CreateAsync method is approved.

This change allows the DynamicWorldContainer to access the PortableExperiencesController during its creation, enabling the integration of portable experiences functionality into the dynamic world container.

The modification is consistent with the overall structure and purpose of the LoadDynamicWorldContainerAsync method.

Copy link

@coderabbitai coderabbitai bot left a 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, codebase verification and nitpick comments (1)
Explorer/Assets/Scripts/Global/Dynamic/ChatCommands/KillPortableExperienceChatCommand.cs (1)

26-43: Consider avoiding runtime allocations.

The ExecuteAsync method is allocating a new ENS object on every invocation. Consider reusing the ENS object to avoid runtime allocations.

You can apply this diff to avoid runtime allocations:

-var response = portableExperiencesController.UnloadPortableExperienceByEns(new ENS(pxName));
+var ens = new ENS(pxName);
+var response = portableExperiencesController.UnloadPortableExperienceByEns(ens);
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 13c1917 and cee46bd.

Files selected for processing (4)
  • Explorer/Assets/Scripts/Global/Dynamic/ChatCommands/KillPortableExperienceChatCommand.cs (1 hunks)
  • Explorer/Assets/Scripts/Global/Dynamic/ChatCommands/KillPortableExperienceChatCommand.cs.meta (1 hunks)
  • Explorer/Assets/Scripts/Global/Dynamic/ChatCommands/LoadPortableExperienceChatCommand.cs (1 hunks)
  • Explorer/Assets/Scripts/Global/Dynamic/DynamicWorldContainer.cs (8 hunks)
Files skipped from review due to trivial changes (1)
  • Explorer/Assets/Scripts/Global/Dynamic/ChatCommands/KillPortableExperienceChatCommand.cs.meta
Files skipped from review as they are similar to previous changes (2)
  • Explorer/Assets/Scripts/Global/Dynamic/ChatCommands/LoadPortableExperienceChatCommand.cs
  • Explorer/Assets/Scripts/Global/Dynamic/DynamicWorldContainer.cs
Additional context used
Path-based instructions (1)
Explorer/Assets/Scripts/Global/Dynamic/ChatCommands/KillPortableExperienceChatCommand.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 (2)
Explorer/Assets/Scripts/Global/Dynamic/ChatCommands/KillPortableExperienceChatCommand.cs (2)

10-44: LGTM!

The KillPortableExperienceChatCommand class is correctly implementing the IChatCommand interface and injecting the IPortableExperiencesController dependency.


26-43: LGTM!

The ExecuteAsync method is correctly handling the CancellationToken and returning appropriate messages. It is also correctly calling the UnloadPortableExperienceByEns method of the IPortableExperiencesController to unload a portable experience.

Copy link

@coderabbitai coderabbitai bot left a 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, codebase verification and nitpick comments (1)
Explorer/Assets/Scripts/ECS/SceneLifeCycle/SceneDefinition/Components/SceneDefinitionComponent.cs (1)

15-22: LGTM! Consider using auto-properties for brevity.

The changes to the SceneDefinitionComponent struct look good:

  • Changing fields to properties with getters improves encapsulation.
  • The new constructor provides more flexibility in initializing the struct.
  • The IsPortableExperience property is a useful addition.

Consider using auto-properties for brevity:

-public SceneEntityDefinition Definition { get; }
+public SceneEntityDefinition Definition { get; init; }

This can be applied to all the properties in the struct.

Also applies to: 26-41

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 529f438 and 309ab03.

Files selected for processing (3)
  • Explorer/Assets/Scripts/ECS/SceneLifeCycle/SceneDefinition/Components/SceneDefinitionComponent.cs (1 hunks)
  • Explorer/Assets/Scripts/ECS/SceneLifeCycle/Systems/LoadPortableExperiencePointersSystem.cs (1 hunks)
  • Explorer/Assets/Scripts/ECS/SceneLifeCycle/Systems/LoadScenePointerSystemBase.cs (2 hunks)
Files skipped from review as they are similar to previous changes (2)
  • Explorer/Assets/Scripts/ECS/SceneLifeCycle/Systems/LoadPortableExperiencePointersSystem.cs
  • Explorer/Assets/Scripts/ECS/SceneLifeCycle/Systems/LoadScenePointerSystemBase.cs
Additional context used
Path-based instructions (1)
Explorer/Assets/Scripts/ECS/SceneLifeCycle/SceneDefinition/Components/SceneDefinitionComponent.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 (4)
Explorer/Assets/Scripts/ECS/SceneLifeCycle/SceneDefinition/Components/SceneDefinitionComponent.cs (4)

47-60: Verify the hardcoded values for portable experiences.

The new constants and static readonly fields related to portable experiences have hardcoded values.

Please ensure that these values are correct and will not need to change in the future. If there's a possibility of these values changing, consider moving them to a configuration file.


62-65: LGTM!

The changes to the CreateFromDefinition method look good. Introducing a factory method pattern for creating SceneDefinitionComponent instances based on the SceneEntityDefinition is a nice way to encapsulate the initialization logic for different scenarios.


67-77: LGTM!

The new CreatePortableExperienceSceneDefinitionComponent method looks good. It encapsulates the logic for creating a SceneDefinitionComponent specifically for portable experiences, using the predefined PORTABLE_EXPERIENCES_PARCEL_CORNERS and PORTABLE_EXPERIENCES_SCENE_GEOMETRY fields for initialization.


86-104: LGTM!

The changes to the CreateEmpty method look good. Utilizing the CreateSceneDefinitionComponent factory method for creating a SceneDefinitionComponent helps centralize the creation logic. Constructing the SceneEntityDefinition within the method and passing it to the factory method is a nice way to encapsulate the initialization logic.

Copy link
Collaborator

@mikhail-dcl mikhail-dcl left a comment

Choose a reason for hiding this comment

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

GJ!
I have several proposals but overall looks good 👍

Copy link

@coderabbitai coderabbitai bot left a 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/Scripts/Global/Dynamic/MainSceneLoader.cs (2)

Line range hint 216-266: Consider avoiding runtime allocations.

The code creates new instances of ENS and IPortableExperiencesController.SpawnResponse for each portable experience. Consider reusing existing instances or object pooling to avoid unnecessary allocations at runtime.


Line range hint 216-266: Consider Unity engine optimizations.

The code uses foreach loops to iterate over the portable experiences. Consider using for loops or IJobParallelFor for better performance, especially if the number of portable experiences is large.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 33b11a9 and a153154.

Files selected for processing (4)
  • Explorer/Assets/Scripts/Global/Dynamic/ChatCommands/LoadPortableExperienceChatCommand.cs (1 hunks)
  • Explorer/Assets/Scripts/Global/Dynamic/MainSceneLoader.cs (8 hunks)
  • Explorer/Assets/Scripts/Global/Dynamic/PortableExperiences/ECSPortableExperiencesController.cs (1 hunks)
  • Explorer/Assets/Scripts/Global/Dynamic/PortableExperiences/IPortableExperiencesController.cs (1 hunks)
Files skipped from review as they are similar to previous changes (3)
  • Explorer/Assets/Scripts/Global/Dynamic/ChatCommands/LoadPortableExperienceChatCommand.cs
  • Explorer/Assets/Scripts/Global/Dynamic/PortableExperiences/ECSPortableExperiencesController.cs
  • Explorer/Assets/Scripts/Global/Dynamic/PortableExperiences/IPortableExperiencesController.cs
Additional context used
Path-based instructions (1)
Explorer/Assets/Scripts/Global/Dynamic/MainSceneLoader.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 (6)
Explorer/Assets/Scripts/Global/Dynamic/MainSceneLoader.cs (6)

31-31: LGTM!

The new property follows the coding conventions and is correctly defined.


40-40: LGTM!

The new property follows the coding conventions and is correctly defined.


60-63: LGTM!

The new fields follow the coding conventions and are correctly defined. The tooltips provide useful information.


78-82: LGTM!

The modifications to the Release method correctly provide default values for the new fields.


86-87: LGTM!

The new properties follow the existing pattern for debug settings and are correctly implemented.


Line range hint 216-266: LGTM!

The code changes are well-structured and follow the existing coding conventions. The loading of portable experiences is implemented correctly based on the debug settings and feature flags.

@fcolarich fcolarich enabled auto-merge (squash) September 13, 2024 16:39
@fcolarich fcolarich merged commit 075845e into main Sep 13, 2024
5 checks passed
@fcolarich fcolarich deleted the feat/portable_experiences branch September 13, 2024 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants