Skip to content

Commit

Permalink
feat: block player movement (#1777)
Browse files Browse the repository at this point in the history
* Pointed to feature branch on Protocol. Generated new class for the new component and Registered it in ComponentsContainer.

* Added proto-squad suggested approach to player freeze. Orinal or this one will be deleted after testing and choosing one.

* Updated protocol, introduced barebones PlayerMovement component and plugin. Added custom movement handling in CalculateCharacterVelocitySystem

* Removed initial approach from CalculateCharacterVelocitySystem. Added PlayerInputMovementHandlerSystem. Added PBPlayerInputMovement to IDirtyMarker.cs. Small cleanup in ComponentContainer. Barebone setup in PlayerInputMovementPlugin

* Fixed assembly dependencies. Refactored PlayerInputMovementPlugin and HandlerSystem to test quering over entities with the new component and change the input (WIP)

* Merged the behavior of the new component with the existing MovementBlocker and CameraBlocker. Renamed MovementBlocker and PlayerInputMovement to InputModifier. Added InputModifierComponent to PlayerEntity. TODO: Fix compile error due to assemblies references issues

* Move `InputBlock` into `DCL.Plugins` assembly (it contained cross references to other assemblies)

* updated sdk and protocol

* Renamed PlayerInputMovement to InputModifier. Removed camera block for now (will be re-introduced in this PR)

* updated protocol to remove disableCamera property

* Re-introduced CameraBlockerComponent

* Added disableEmote logic. Added helper getters in InputModifierComponent. Improved disable value set in InputModifierHandlerSystem. Small code cleanup.

* Added check for current scene. Added filter to only work with the PlayerEntity and filter other entities with InputModifierComponent from the SDK

* Improved handling of motion fallbacks. Added system to IsCurrentListeners. Small code clean up

* Small optimization

* Refactored disable combinations to properly handle all cases.

* Fixed wrong update group being used for the system

* Fast-forward Protocol

* Create player entity properly

* Forgot to commit new files from the updated protocol

* Fixed failing tests

* updated protocol to next release

---------

Co-authored-by: Mikhail Agapov <[email protected]>
  • Loading branch information
AlejandroAlvarezMelucciDCL and mikhail-dcl authored Sep 6, 2024
1 parent 5cd0270 commit b3ac653
Show file tree
Hide file tree
Showing 71 changed files with 6,952 additions and 285 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,21 @@
using DCL.SceneLoadingScreens.SplashScreen;
using DCL.UI;
using DCL.Utilities;
using DCL.Web3;
using DCL.Web3.Authenticators;
using DCL.Web3.Identities;
using MVC;
using System;
using System.Collections.Generic;
using System.Threading;
using UnityEngine;
using UnityEngine.Assertions;
using UnityEngine.Localization.SmartFormat.PersistentVariables;
using UnityEngine.UI;
using Utility;

#if !UNITY_EDITOR
using DCL.Web3;
using System.Collections.Generic;
#endif

namespace DCL.AuthenticationScreenFlow
{
public class AuthenticationScreenController : ControllerBase<AuthenticationScreenView>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using DCL.Input;
using DCL.Multiplayer.Emotes;
using DCL.Profiles;
using DCL.SDKComponents.InputModifier.Components;
using ECS.Abstract;
using MVC;
using System;
Expand All @@ -22,6 +23,7 @@ namespace DCL.AvatarRendering.Emotes
[UpdateInGroup(typeof(InputGroup))]
public partial class UpdateEmoteInputSystem : BaseUnityLoopSystem
{
private const int AFTER_WHEEL_WAS_CLOSED_FRAMES_DELAY = 30;
private readonly Dictionary<string, int> actionNameById = new ();
private readonly IEmotesMessageBus messageBus;
private readonly IMVCManager mvcManager;
Expand All @@ -32,7 +34,7 @@ public partial class UpdateEmoteInputSystem : BaseUnityLoopSystem
private bool isWheelBlocked;
private int framesAfterWheelWasClosed;

public UpdateEmoteInputSystem(World world, DCLInput dclInput, IEmotesMessageBus messageBus,
private UpdateEmoteInputSystem(World world, DCLInput dclInput, IEmotesMessageBus messageBus,
IMVCManager mvcManager) : base(world)
{
shortcuts = dclInput.Shortcuts;
Expand Down Expand Up @@ -76,7 +78,7 @@ protected override void Update(float t)
if (shortcuts.EmoteWheel.WasReleasedThisFrame()
// Close and open actions conflicts each other since they are assigned to the same input key
// we need to avoid opening it again after it has been recently closed
// We also have to consider race conditions so i see no other way than setting a delay
// We also have to consider race conditions, so I see no other way than setting a delay
&& framesAfterWheelWasClosed == 0)
{
if (!isWheelBlocked)
Expand All @@ -100,8 +102,10 @@ private void TriggerEmoteBySlotIntent(in Entity entity, ref TriggerEmoteBySlotIn
[Query]
[All(typeof(PlayerComponent))]
[None(typeof(CharacterEmoteIntent))]
private void TriggerEmote([Data] int emoteIndex, in Entity entity, in Profile profile)
private void TriggerEmote([Data] int emoteIndex, in Entity entity, in Profile profile, in InputModifierComponent inputModifier)
{
if(inputModifier.DisableEmote) return;

IReadOnlyList<URN> emotes = profile.Avatar.Emotes;
if (emoteIndex < 0 || emoteIndex >= emotes.Count) return;

Expand Down Expand Up @@ -151,7 +155,7 @@ private void OpenEmoteWheel() =>
private void OnEmoteWheelClosed(IController obj)
{
if (obj is not EmotesWheelController) return;
framesAfterWheelWasClosed = 30;
framesAfterWheelWasClosed = AFTER_WHEEL_WAS_CLOSED_FRAMES_DELAY;
}
}
}
4 changes: 2 additions & 2 deletions Explorer/Assets/DCL/Backpack/BackpackSearchController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ public BackpackSearchController(SearchBarView view,

private void RestoreInput(string text)
{
inputBlock.Enable(InputMapComponent.Kind.Shortcuts);
inputBlock.Enable(InputMapComponent.Kind.SHORTCUTS);
}

private void DisableShortcutsInput(string text)
{
inputBlock.Disable(InputMapComponent.Kind.Shortcuts);
inputBlock.Disable(InputMapComponent.Kind.SHORTCUTS);
}

private void OnSearchEvent(string searchString)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
using DCL.CharacterCamera;
using DCL.CharacterCamera.Components;
using DCL.CharacterCamera.Settings;
using DCL.CharacterMotion.Components;
using DCL.Input;
using DCL.Input.Component;
using DCL.Input.Systems;
using ECS.Abstract;
using UnityEngine;

Expand Down Expand Up @@ -128,14 +128,14 @@ private void SetActiveCamera(CameraMode targetCameraMode, ICinemachinePreset cin
if (targetCameraMode != CameraMode.Free && currentCameraMode == CameraMode.Free)
{
ref InputMapComponent inputMapComponent = ref inputMap.GetInputMapComponent(World);
inputMapComponent.UnblockInput(InputMapComponent.Kind.Player);
inputMapComponent.BlockInput(InputMapComponent.Kind.FreeCamera);
inputMapComponent.UnblockInput(InputMapComponent.Kind.PLAYER);
inputMapComponent.BlockInput(InputMapComponent.Kind.FREE_CAMERA);
}
else if (targetCameraMode == CameraMode.Free && currentCameraMode != CameraMode.Free)
{
ref InputMapComponent inputMapComponent = ref inputMap.GetInputMapComponent(World);
inputMapComponent.UnblockInput(InputMapComponent.Kind.FreeCamera);
inputMapComponent.BlockInput(InputMapComponent.Kind.Player);
inputMapComponent.UnblockInput(InputMapComponent.Kind.FREE_CAMERA);
inputMapComponent.BlockInput(InputMapComponent.Kind.PLAYER);
}

switch (camera.Mode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using Arch.SystemGroups;
using DCL.Character.CharacterCamera.Components;
using DCL.CharacterCamera.Components;
using DCL.CharacterMotion.Components;
using DCL.Input;
using DCL.Input.Systems;
using UnityEngine;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void CreateCameraSetup()
cinemachinePreset.DefaultCameraMode.Returns(CameraMode.ThirdPerson);
cinemachineCameraAudioSettings = Substitute.For<ICinemachineCameraAudioSettings>();
system = new ControlCinemachineVirtualCameraSystem(world, cinemachineCameraAudioSettings);
world.Create(new InputMapComponent(InputMapComponent.Kind.Player | InputMapComponent.Kind.Camera | InputMapComponent.Kind.Shortcuts));
world.Create(new InputMapComponent(InputMapComponent.Kind.PLAYER | InputMapComponent.Kind.CAMERA | InputMapComponent.Kind.SHORTCUTS));

entity = world.Create(cinemachinePreset, new CameraComponent(camera), new CinemachineCameraState(), new CameraInput(), new CursorComponent());

Expand All @@ -91,7 +91,7 @@ public void DisposeCameraSetup()
[Test]
public void InitInputMapComponent()
{
Assert.That(inputMap.GetInputMapComponent(world).Active, Is.EqualTo(InputMapComponent.Kind.Player | InputMapComponent.Kind.Camera | InputMapComponent.Kind.Shortcuts));
Assert.That(inputMap.GetInputMapComponent(world).Active, Is.EqualTo(InputMapComponent.Kind.PLAYER | InputMapComponent.Kind.CAMERA | InputMapComponent.Kind.SHORTCUTS));
Assert.That(world.Get<CinemachineCameraState>(entity).CurrentCamera, Is.EqualTo(thirdPersonCameraData.Camera));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using DCL.CharacterMotion.Settings;
using DCL.DebugUtilities;
using DCL.DebugUtilities.UIBindings;
using DCL.Input;
using DCL.Time.Systems;
using ECS.Abstract;
using UnityEngine;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using DCL.Character.Components;
using DCL.Input;
using DCL.Input.Systems;
using DCL.SDKComponents.InputModifier.Components;
using ECS.Abstract;
using UnityEngine.InputSystem;

Expand Down Expand Up @@ -33,9 +34,9 @@ protected override void Update(float t)
}

[Query]
private void UpdateInput([Data] int tickValue, ref JumpInputComponent inputToUpdate)
private void UpdateInput([Data] int tickValue, ref JumpInputComponent inputToUpdate, in InputModifierComponent inputModifierComponent)
{
if (!inputAction.enabled) return;
if(inputModifierComponent.DisableJump || !inputAction.enabled) return;

if (inputAction.WasPressedThisFrame())
inputToUpdate.Trigger.TickWhenJumpOccurred = tickValue + 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using DCL.CharacterMotion.Components;
using DCL.Input;
using DCL.Input.Systems;
using DCL.SDKComponents.InputModifier.Components;
using UnityEngine;
using UnityEngine.InputSystem;

Expand Down Expand Up @@ -32,32 +33,67 @@ protected override void Update(float t)
}

[Query]
private void UpdateInput(ref MovementInputComponent inputToUpdate)
private void UpdateInput(ref MovementInputComponent inputToUpdate, in InputModifierComponent inputModifierComponent)
{
if (!movementAxis.enabled)
if (!movementAxis.enabled || inputModifierComponent is { DisableAll: true } or { DisableWalk: true, DisableJog: true, DisableRun: true })
{
inputToUpdate.Axes = Vector2.zero;
return;
}

inputToUpdate.Axes = movementAxis.ReadValue<Vector2>();

if (autoWalkAction.WasPerformedThisFrame()) { inputToUpdate.AutoWalk = !inputToUpdate.AutoWalk; }
if (!inputModifierComponent.DisableWalk && autoWalkAction.WasPerformedThisFrame())
inputToUpdate.AutoWalk = !inputToUpdate.AutoWalk;

if (inputToUpdate.Axes.sqrMagnitude > 0.1f) { inputToUpdate.AutoWalk = false; }

// Running action wins over walking
inputToUpdate.Kind = sprintAction.IsPressed() ? MovementKind.RUN :
walkAction.IsPressed() ? MovementKind.WALK : MovementKind.JOG;
if (inputToUpdate is { AutoWalk: true, Axes: { sqrMagnitude: > 0.1f } })
inputToUpdate.AutoWalk = false;

if (inputToUpdate.Axes == Vector2.zero)
inputToUpdate.Kind = MovementKind.IDLE;
else
{
bool runPressed = sprintAction.IsPressed();
bool walkPressed = walkAction.IsPressed();

inputToUpdate.Kind = ProcessInputMovementKind(inputModifierComponent, runPressed, walkPressed);
}

if (inputToUpdate.AutoWalk)
{
inputToUpdate.Axes = new Vector2(0, 1);
inputToUpdate.Kind = MovementKind.WALK;
}
}

private static MovementKind ProcessInputMovementKind(InputModifierComponent inputModifierComponent, bool runPressed, bool walkPressed)
{
// Running action wins over walking
if (runPressed)
{
if (inputModifierComponent.DisableRun)
return inputModifierComponent.DisableJog ? MovementKind.WALK : MovementKind.JOG;

return MovementKind.RUN;
}

if (walkPressed)
{
if (inputModifierComponent.DisableWalk)
return inputModifierComponent.DisableJog ? MovementKind.RUN : MovementKind.JOG;

return MovementKind.WALK;
}

if (inputModifierComponent.DisableJog)
{
if (inputModifierComponent.DisableWalk)
return MovementKind.RUN;

return MovementKind.WALK;
}

return MovementKind.JOG;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using DCL.CharacterMotion.Components;
using DCL.CharacterMotion.Settings;
using DCL.CharacterMotion.Systems;
using DCL.SDKComponents.InputModifier.Components;
using DCL.Time;
using DCL.Time.Systems;
using ECS.Abstract;
Expand All @@ -31,7 +32,11 @@ public void SetUp()
ICharacterControllerSettings controllerSettings = Substitute.For<ICharacterControllerSettings>();
controllerSettings.LongJumpTime.Returns(1f);

playerEntity = world.Create(new PlayerComponent(), controllerSettings, new CharacterRigidTransform { IsGrounded = true });
playerEntity = world.Create(
new PlayerComponent(),
controllerSettings,
new CharacterRigidTransform { IsGrounded = true },
new InputModifierComponent());

updatePhysicsTickSystem = new UpdatePhysicsTickSystem(world, new PhysicsTickProvider());
updateInputJumpSystem = new UpdateInputJumpSystem(world, dlcInput.Player.Jump);
Expand Down
3 changes: 0 additions & 3 deletions Explorer/Assets/DCL/Character/MovementBlocker.meta

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

11 changes: 7 additions & 4 deletions Explorer/Assets/DCL/Character/Plugin/CharacterContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using DCL.PluginSystem.Global;
using DCL.PluginSystem.World;
using DCL.PluginSystem.World.Dependencies;
using DCL.SDKComponents.InputModifier.Components;
using ECS.LifeCycle;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -79,12 +80,14 @@ public GlobalPlugin CreateGlobalPlugin() =>
public UniTask InitializeAsync(NoExposedPluginSettings settings, CancellationToken ct) =>
UniTask.CompletedTask;

public Entity CreatePlayerEntity(World world) =>
world.Create(
new CRDTEntity(SpecialEntitiesID.PLAYER_ENTITY),
public void InitializePlayerEntity(World world, Entity playerEntity)
{
world.Add(playerEntity,
new PlayerComponent(characterObject.Value.CameraFocus),
new CharacterTransform(characterObject.Value.Transform),
new PlayerMovementNetworkComponent(characterObject.Value.Controller));
new PlayerMovementNetworkComponent(characterObject.Value.Controller)
, new InputModifierComponent());
}

public class GlobalPlugin : IDCLGlobalPluginWithoutSettings
{
Expand Down
4 changes: 2 additions & 2 deletions Explorer/Assets/DCL/Chat/Chat.asmdef
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"GUID:e56a0d6a94c144c784012e63b6043100",
"GUID:5ab29fa8ae5769b49ab29e390caca7a4",
"GUID:101b8b6ebaf64668909b49c4b7a1420d",
"GUID:4e9911d3faa34ce3ad61855f4f549665",
"GUID:4794e238ed0f65142a4aea5848b513e5",
"GUID:1b8e1e1bd01505f478f0369c04a4fb2f",
"GUID:ac3295688c7c22745a96e6ac34718181",
Expand All @@ -29,7 +28,8 @@
"GUID:7175400a68914a45acecc9fb068de3b8",
"GUID:875a5d5129614170bd769ed012c2eb3d",
"GUID:f4a0f40a2545482b8929d4c3c642f50a",
"GUID:ca4e81cdd6a34d1aa54c32ad41fc5b3b"
"GUID:ca4e81cdd6a34d1aa54c32ad41fc5b3b",
"GUID:54660b0fae444b4cbfdafa9d68108f04"
],
"includePlatforms": [],
"excludePlatforms": [],
Expand Down
Loading

0 comments on commit b3ac653

Please sign in to comment.