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

Convert movement packets #492

Open
wants to merge 36 commits into
base: arena-vertical-slice
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
1361bda
Initial look at movement packet
Ciel1996 Jan 18, 2023
0365c30
- Added Movement event and subclasses with ToMovementPacket() - method
Ciel1996 Jan 19, 2023
9fa4901
- Using IMemoryCache with a TTL of 1s to rate limit packets sent
Ciel1996 Jan 20, 2023
e75fde8
Removed unused using
Ciel1996 Jan 20, 2023
5f81436
- Replaced IMemoryCache with Policy.RateLimit
Ciel1996 Jan 21, 2023
eac1ace
Reworking the message-to-packet logic
Ciel1996 Jan 30, 2023
6a354a8
- Using Timer to send packets regularly
Ciel1996 Feb 3, 2023
fc7a3b1
- removed Polly
Ciel1996 Feb 4, 2023
b361719
Refactored according to feedback
Ciel1996 Feb 7, 2023
2a5e918
forgot to save Missions.csproj
Ciel1996 Feb 7, 2023
de88af5
Made ProtoBuf compatible; Introduced test to proof ProtoBuf serializa…
Ciel1996 Feb 15, 2023
4cdfb51
Merge branch 'arena-vertical-slice' into convert-movement-packets
Ciel1996 Feb 15, 2023
ad1e0e7
Fixing lost updates from merge
Ciel1996 Feb 15, 2023
d207a43
Merge branch 'arena-vertical-slice' into convert-movement-packets
Ciel1996 Feb 15, 2023
f304081
Merge branch 'arena-vertical-slice' into convert-movement-packets
Ciel1996 Feb 15, 2023
aff8ce5
Merge branch 'convert-movement-packets' of https://github.com/Bannerl…
Ciel1996 Feb 15, 2023
1e2cef6
Fixed some more issues found in review and replaced MovementPacket wi…
Ciel1996 Feb 17, 2023
1567365
Update ClientDebug.csproj.user
Ciel1996 Feb 17, 2023
b1ecc6e
- Removed AgentData
Ciel1996 Feb 19, 2023
7a535cd
Merge branch 'arena-vertical-slice' into convert-movement-packets
Ciel1996 Feb 19, 2023
80def62
Removed unused code
garrettluskey Feb 24, 2023
b470870
removed unused code
garrettluskey Feb 24, 2023
3c916fc
- Added AgentPublisher polling Agent.Main regularly for movement changes
Ciel1996 Feb 25, 2023
38535bd
Merge branch 'convert-movement-packets' of https://github.com/Bannerl…
garrettluskey Feb 25, 2023
808a1af
Merge branch 'arena-vertical-slice' into convert-movement-packets
Ciel1996 Feb 25, 2023
a81cdd1
Merge branch 'arena-vertical-slice' into convert-movement-packets
Ciel1996 Mar 2, 2023
29a8dfc
Merge branch 'arena-vertical-slice' into convert-movement-packets
Ciel1996 Mar 7, 2023
da38f71
Merge branch 'arena-vertical-slice' into convert-movement-packets
garrettluskey Mar 20, 2023
77fa062
Fixed some namespaces
Ciel1996 Mar 20, 2023
c3b42ca
replaced async method by Timer as suggested;
Ciel1996 Mar 31, 2023
ee38d75
added AgentPublisherConfig
Ciel1996 Apr 3, 2023
089729c
Merge branch 'arena-vertical-slice' into convert-movement-packets
Ciel1996 Apr 3, 2023
aab1634
Used DI for relevant classes and interfaces
Ciel1996 Apr 3, 2023
2fcaeb9
Fixed dependencies
Ciel1996 Apr 4, 2023
771d502
Movements are received by the message broker now.
Ciel1996 Apr 8, 2023
425952e
Merge branch 'arena-vertical-slice' into convert-movement-packets
Ciel1996 Apr 28, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions source/MissionTestMod/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
<assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.0.1" newVersion="4.2.0.1" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Bcl.AsyncInterfaces" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.4.1" newVersion="4.0.4.1" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
8 changes: 8 additions & 0 deletions source/MissionTests/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
<assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.0.1" newVersion="4.2.0.1" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Bcl.AsyncInterfaces" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.4.1" newVersion="4.0.4.1" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
34 changes: 28 additions & 6 deletions source/Missions/Missions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,20 @@
<Reference Include="LiteNetLib, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\LiteNetLib.0.9.5.2\lib\net35\LiteNetLib.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Bcl.AsyncInterfaces.1.1.0\lib\net461\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
<Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=7.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Bcl.AsyncInterfaces.7.0.0\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Extensions.DependencyInjection.Abstractions, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Extensions.DependencyInjection.Abstractions.7.0.0\lib\net462\Microsoft.Extensions.DependencyInjection.Abstractions.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Extensions.Logging.Abstractions, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Extensions.Logging.Abstractions.7.0.0\lib\net462\Microsoft.Extensions.Logging.Abstractions.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Extensions.Options, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Extensions.Options.7.0.0\lib\net462\Microsoft.Extensions.Options.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Extensions.Primitives, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Extensions.Primitives.7.0.0\lib\net462\Microsoft.Extensions.Primitives.dll</HintPath>
</Reference>
<Reference Include="protobuf-net, Version=3.0.0.0, Culture=neutral, PublicKeyToken=257b51d87d2e4d67, processorArchitecture=MSIL">
<HintPath>..\packages\protobuf-net.3.1.22\lib\net462\protobuf-net.dll</HintPath>
Expand Down Expand Up @@ -76,25 +88,29 @@
<Reference Include="System.Collections.Immutable, Version=1.2.5.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Collections.Immutable.1.7.1\lib\net461\System.Collections.Immutable.dll</HintPath>
</Reference>
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Diagnostics.DiagnosticSource, Version=4.0.5.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Diagnostics.DiagnosticSource.4.7.1\lib\net46\System.Diagnostics.DiagnosticSource.dll</HintPath>
</Reference>
<Reference Include="System.IO.Compression" />
<Reference Include="System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Memory.4.5.4\lib\net461\System.Memory.dll</HintPath>
<Reference Include="System.Memory, Version=4.0.1.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Memory.4.5.5\lib\net461\System.Memory.dll</HintPath>
</Reference>
<Reference Include="System.Numerics" />
<Reference Include="System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
</Reference>
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.5.3\lib\net461\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
</Reference>
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll</HintPath>
</Reference>
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
Expand Down Expand Up @@ -138,6 +154,12 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Services\Agents\Messages\ActionDataChanged.cs" />
<Compile Include="Services\Agents\Messages\LookDirectionChanged.cs" />
<Compile Include="Services\Agents\Messages\MountDataChanged.cs" />
<Compile Include="Services\Agents\Messages\IMovementEvent.cs" />
<Compile Include="Services\Agents\Messages\MovementInputVectorChanged.cs" />
<Compile Include="Services\Agents\Messages\AgentMovementDelta.cs" />
<Compile Include="Services\Arena\ArenaTestGameManager.cs" />
<Compile Include="Services\BoardGames\Messages\BoardGameMoveMessage.cs" />
<Compile Include="Services\BoardGames\Messages\OnSetPawnCapturedMessage.cs" />
Expand Down
4 changes: 2 additions & 2 deletions source/Missions/Services/Agents/Extensions/AgentExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using TaleWorlds.MountAndBlade;
using Missions.Services.Network;
using Missions.Services.Network;
using TaleWorlds.MountAndBlade;

namespace Missions.Services.Agents.Extensions
{
Expand Down
32 changes: 32 additions & 0 deletions source/Missions/Services/Agents/Messages/ActionDataChanged.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Missions.Services.Agents.Packets;
using System;
using TaleWorlds.MountAndBlade;

namespace Missions.Services.Agents.Messages
{
/// <summary>
/// An <see cref="IEvent"/> used to propagate movement related changes of <see cref="AgentActionData"/> of an <see cref="Agent"/>.
/// </summary>
internal readonly struct ActionDataChanged : IMovementEvent
{
/// <summary>
/// The changed <see cref="AgentActionData"/> propagated by this <see cref="IEvent"/>.
/// </summary>
public AgentActionData AgentActionData { get; }

/// <inheritdoc />
public Agent Agent { get; }

/// <summary>
/// Constructor
/// </summary>
/// <param name="agent"></param>
/// <param name="agentActionData"></param>
public ActionDataChanged(Agent agent, AgentActionData agentActionData)
{
Agent = agent;
AgentActionData = agentActionData;
}

}
}
101 changes: 101 additions & 0 deletions source/Missions/Services/Agents/Messages/AgentMovementDelta.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
using Missions.Services.Agents.Packets;
using System;
using TaleWorlds.Library;
using TaleWorlds.MountAndBlade;

namespace Missions.Services.Agents.Messages
{
/// <summary>
/// Represents the delta of an agent's movement between the time it was created and the time it was last updated.
/// </summary>
internal sealed class AgentMovementDelta
Ciel1996 marked this conversation as resolved.
Show resolved Hide resolved
{
private Vec3 _lookDirectionDelta = Vec3.Zero;
private Vec2 _inputVectorDelta = Vec2.Zero;

private AgentActionData _actionDataDelta;
private AgentMountData _mountDataDelta;

private Vec3 _currentPosition;

/// <summary>
/// Guid of the associated <see cref="Agent"/>.
/// </summary>
public Guid Guid { get; }
Ciel1996 marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// The <see cref="Agent"/> whose movement is about to be updated.
/// </summary>
public Agent Agent { get; }
Ciel1996 marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// Constructor
/// </summary>
/// <param name="agent"></param>
/// <param name="guid"></param>
public AgentMovementDelta(Agent agent, Guid guid)
{
Guid = guid;
Agent = agent;
_currentPosition = agent.Position;

_actionDataDelta = new AgentActionData(agent);
_mountDataDelta = new AgentMountData(agent);
}

/// <summary>
/// Re-calculate this <see cref="AgentMovementDelta"/>.
/// </summary>
/// <param name="change"></param>
public void CalculateMovement(LookDirectionChanged change)
{
_lookDirectionDelta = change.LookDirection;
}

/// <summary>
/// Re-calculate this <see cref="AgentMovementDelta"/>.
/// </summary>
/// <param name="change"></param>
public void CalculateMovement(MovementInputVectorChanged change)
{
_inputVectorDelta = change.InputVector;
}

/// <summary>
/// Re-calculate this <see cref="AgentMovementDelta"/>.
/// </summary>
/// <param name="change"></param>
public void CalculateMovement(ActionDataChanged change)
{
_actionDataDelta = change.AgentActionData;
}

/// <summary>
/// Re-calculate this <see cref="AgentMovementDelta"/>.
/// </summary>
/// <param name="change"></param>
public void CalculateMovement(MountDataChanged change)
{
_mountDataDelta = change.AgentMountData;
}

/// <summary>
/// Generate a <see cref="MovementPacket"/> from this <see cref="AgentMovementDelta"/>.
/// </summary>
/// <returns></returns>
public MovementPacket GetPacket()
{
return new MovementPacket(
Guid,
new AgentData(
_currentPosition,
Agent.GetMovementDirection(),
_lookDirectionDelta,
_inputVectorDelta,
new AgentEquipmentData(Agent),
_actionDataDelta,
_mountDataDelta)
);
}
}
}
17 changes: 17 additions & 0 deletions source/Missions/Services/Agents/Messages/IMovementEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Common.Messaging;
using System;
using TaleWorlds.MountAndBlade;

namespace Missions.Services.Agents.Messages
{
/// <summary>
/// An <see cref="IEvent"/> used to propagate movement related changes of an <see cref="Agent"/>.
/// </summary>
interface IMovementEvent : IEvent
{
/// <summary>
/// The <see cref="Agent"/> this <see cref="IEvent"/> is for.
/// </summary>
Agent Agent { get; }
}
}
30 changes: 30 additions & 0 deletions source/Missions/Services/Agents/Messages/LookDirectionChanged.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using TaleWorlds.Library;
using TaleWorlds.MountAndBlade;

namespace Missions.Services.Agents.Messages
{
/// <summary>
/// An <see cref="IEvent"/> propagating the <see cref="Agent"/>'s change in look direction.
/// </summary>
internal readonly struct LookDirectionChanged : IMovementEvent
{
/// <summary>
/// The changed vector representing the look direction.
/// </summary>
public Vec3 LookDirection { get; }

/// <inheritdoc />
public Agent Agent { get; }

/// <summary>
/// Constructor
/// </summary>
/// <param name="agent"></param>
public LookDirectionChanged(Agent agent)
{
Agent = agent;
LookDirection = agent.LookDirection;
}
}
}
32 changes: 32 additions & 0 deletions source/Missions/Services/Agents/Messages/MountDataChanged.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Missions.Services.Agents.Packets;
using System;
using TaleWorlds.MountAndBlade;

namespace Missions.Services.Agents.Messages
{
/// <summary>
/// An <see cref="IEvent"/> used to propagate movement related changes of <see cref="AgentMountData"/> of an <see cref="Agent"/>.
/// </summary>
internal readonly struct MountDataChanged : IMovementEvent
{
/// <summary>
/// The changed <see cref="AgentMountData"/> propagated by this <see cref="IEvent"/>.
/// </summary>
public AgentMountData AgentMountData { get; }

/// <inheritdoc />
public Agent Agent { get; }


/// <summary>
/// Constructor
/// </summary>
/// <param name="agent"></param>
/// <param name="agentMountData"></param>
public MountDataChanged(Agent agent, AgentMountData agentMountData)
{
Agent = agent;
AgentMountData = agentMountData;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using TaleWorlds.Library;
using TaleWorlds.MountAndBlade;

namespace Missions.Services.Agents.Messages
{
/// <summary>
/// An <see cref="IEvent"/> propagating that the <see cref="Agent"/>'s input vector has changed.
/// </summary>
internal readonly struct MovementInputVectorChanged : IMovementEvent
{
/// <summary>
/// The changed input vector.
/// </summary>
public Vec2 InputVector { get; }

/// <inheritdoc />
public Agent Agent { get; }

/// <summary>
/// Constructor
/// </summary>
/// <param name="agent"></param>
public MovementInputVectorChanged(Agent agent)
{
Agent = agent;
InputVector = agent.MovementInputVector;
}
}
}
20 changes: 19 additions & 1 deletion source/Missions/Services/Agents/Packets/AgentData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,24 @@ public AgentData(Agent agent)
}
}

public AgentData(
Vec3 position,
Vec2 movementDirection,
Vec3 lookDirection,
Vec2 inputVector,
AgentEquipmentData agentEquipment,
AgentActionData agentActionData,
AgentMountData agentMountData)
{
Position = position;
MovementDirection = movementDirection;
LookDirection = lookDirection;
InputVector = inputVector;
AgentEquipment = agentEquipment;
ActionData = agentActionData;
MountData = agentMountData;
}

public void Apply(Agent agent)
Ciel1996 marked this conversation as resolved.
Show resolved Hide resolved
{
// if the player is dead, dont sync anything
Expand Down Expand Up @@ -83,7 +101,7 @@ public void Apply(Agent agent)
[ProtoMember(5)]
public AgentEquipmentData AgentEquipment { get; }
[ProtoMember(6)]
public AgentActionData ActionData { get; }
public AgentActionData ActionData { get;}
[ProtoMember(7)]
public AgentMountData MountData { get; }
}
Expand Down
Loading