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 5 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
36 changes: 30 additions & 6 deletions source/Missions/Missions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,23 @@
<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="Polly, Version=7.0.0.0, Culture=neutral, PublicKeyToken=c8a3ffc3f8f825cc, processorArchitecture=MSIL">
<HintPath>..\packages\Polly.7.2.3\lib\net472\Polly.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 +91,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 +157,11 @@
</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\Movement.cs" />
<Compile Include="Services\Agents\Messages\MovementInputVectorChanged.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
33 changes: 33 additions & 0 deletions source/Missions/Services/Agents/Messages/ActionDataChanged.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
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>
public sealed class ActionDataChanged : Movement
Ciel1996 marked this conversation as resolved.
Show resolved Hide resolved
{
/// <summary>
/// The changed <see cref="AgentActionData"/> propagated by this <see cref="IEvent"/>.
/// </summary>
public AgentActionData AgentActionData { get; }

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

/// <inheritdoc />
public override MovementPacket ToMovementPacket()
{
return new MovementPacket(Guid, new AgentData(Agent, AgentActionData));
}
}
}
33 changes: 33 additions & 0 deletions source/Missions/Services/Agents/Messages/LookDirectionChanged.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using Missions.Services.Agents.Packets;
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>
public sealed class LookDirectionChanged : Movement
garrettluskey marked this conversation as resolved.
Show resolved Hide resolved
{
/// <summary>
/// The changed vector representing the look direction.
/// </summary>
public Vec3 LookDirection { get; }

/// <summary>
/// Constructor
/// </summary>
/// <param name="agent"></param>
public LookDirectionChanged(Agent agent, Guid guid) : base(agent, guid)
{
LookDirection = agent.LookDirection;
}

/// <inheritdoc />
public override MovementPacket ToMovementPacket()
{
return new MovementPacket(Guid, new AgentData(Agent, LookDirection));
}
}
}
33 changes: 33 additions & 0 deletions source/Missions/Services/Agents/Messages/MountDataChanged.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
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>
public sealed class MountDataChanged : Movement
Ciel1996 marked this conversation as resolved.
Show resolved Hide resolved
{
/// <summary>
/// The changed <see cref="AgentMountData"/> propagated by this <see cref="IEvent"/>.
/// </summary>
public AgentMountData AgentMountData { get; }

/// <summary>
/// Constructor
/// </summary>
/// <param name="agent"></param>
/// <param name="agentMountData"></param>
public MountDataChanged(Agent agent, AgentMountData agentMountData, Guid guid) : base(agent, guid)
{
AgentMountData = agentMountData;
}

/// <inheritdoc />
public override MovementPacket ToMovementPacket()
{
return new MovementPacket(Guid, new AgentData(Agent, AgentMountData));
}
}
}
39 changes: 39 additions & 0 deletions source/Missions/Services/Agents/Messages/Movement.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using Common.Messaging;
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 an <see cref="Agent"/>.
/// </summary>
public abstract class Movement : IEvent
Ciel1996 marked this conversation as resolved.
Show resolved Hide resolved
{
/// <summary>
/// The <see cref="Agent"/> this <see cref="IEvent"/> is for.
/// </summary>
public Agent Agent { get; }

/// <summary>
/// The <paramref name="Agent"/>'s <see cref="Guid"/>.
/// </summary>
public Guid Guid { get; }
Ciel1996 marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// Constructor
/// </summary>
/// <param name="agent"></param>
public Movement(Agent agent, Guid guid)
{
Agent = agent;
Guid = guid;
}
Ciel1996 marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// Converts the <see cref="IEvent"/> to a <see cref="MovementPacket"/>.
/// </summary>
/// <returns></returns>
public abstract MovementPacket ToMovementPacket();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using Missions.Services.Agents.Packets;
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>
public sealed class MovementInputVectorChanged : Movement
{
/// <summary>
/// The changed input vector.
/// </summary>
public Vec2 InputVector { get; }

/// <summary>
/// Constructor
/// </summary>
/// <param name="agent"></param>
public MovementInputVectorChanged(Agent agent, Guid guid) : base(agent, guid)
{
InputVector = agent.MovementInputVector;
}

/// <inheritdoc />
public override MovementPacket ToMovementPacket()
{
return new MovementPacket(Guid, new AgentData(Agent, InputVector));
}
}
Ciel1996 marked this conversation as resolved.
Show resolved Hide resolved
}
36 changes: 35 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,40 @@ 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 AgentData(Agent agent, Vec2 movementDirection) :
garrettluskey marked this conversation as resolved.
Show resolved Hide resolved
this(Vec3.Invalid, movementDirection, Vec3.Invalid, Vec2.Invalid, new AgentEquipmentData(agent), null, null)
{ }

public AgentData(Agent agent, Vec3 lookDirection) :
this(Vec3.Invalid, Vec2.Invalid, lookDirection, Vec2.Invalid, new AgentEquipmentData(agent), null, null)
{ }

public AgentData(Agent agent, AgentActionData actionData) :
this(Vec3.Invalid, Vec2.Invalid, Vec3.Invalid, Vec2.Invalid, new AgentEquipmentData(agent), actionData, null)
{ }

public AgentData(Agent agent, AgentMountData mountData) :
this(Vec3.Invalid, Vec2.Invalid, Vec3.Invalid, Vec2.Invalid, new AgentEquipmentData(agent), null, mountData)
{ }

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 +117,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