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

Synchronise player tools and focus between clients #274

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
e123d88
Added mechanism to sync tool states between players and render them o…
CWMlolzlz Apr 17, 2022
44f1808
Turned ToolSimulator into a Singleton
CWMlolzlz Apr 18, 2022
f48220e
Created BaseToolHandler to abstract common tasks when sending and rec…
CWMlolzlz Apr 18, 2022
81a052c
Added NetTool support with some limitations present
CWMlolzlz Apr 18, 2022
f7786cb
Added zone tool support
CWMlolzlz Apr 18, 2022
5872afc
Added prop tool support
CWMlolzlz Apr 18, 2022
b95c4e4
Added support for TransportTool
CWMlolzlz Apr 18, 2022
fe79f7e
Fixed DefaultTool not syncing and NPE in NetToolHandler
CWMlolzlz Apr 19, 2022
5ee74c1
Refactored and removed redundant code
CWMlolzlz Apr 20, 2022
9874a0e
Added support for terrain tool and ToolController configuration
CWMlolzlz Apr 20, 2022
cc9ca60
Fixed NetTool helper lines not render for other client NetTools
CWMlolzlz Apr 21, 2022
917040c
Change other client tool rendering to prefix rather than post fix the…
CWMlolzlz Apr 21, 2022
5bf9420
Added cursor display to player tags in UI
CWMlolzlz Apr 24, 2022
f8361d3
Fixed ToolCommandBase fields not being sent over the wire
CWMlolzlz Apr 25, 2022
dea4833
Cleaned up player indicator UI
CWMlolzlz Apr 25, 2022
4d5b5ec
Fixed synced positions defaulting to (0,0,0) when the client hovers o…
CWMlolzlz May 2, 2022
9ea43f6
Fixed NPE if CursorInfo couldn't load
CWMlolzlz May 2, 2022
fa5d54f
Disabled overlay rendering for Transport Tool due to transport manage…
CWMlolzlz May 2, 2022
8c53506
Refactored cursor management files
CWMlolzlz May 2, 2022
732e9a1
Added removal of player cursors when they disconnect
CWMlolzlz May 2, 2022
0106e20
Fixed player cursors not rendering on the UI correctly when facing aw…
CWMlolzlz Jun 6, 2022
194bdc8
Added advanced option to skip mod checking on the host side
CWMlolzlz Jun 7, 2022
057f9a7
Added bulldoze tool and fixed overlays not rendering
CWMlolzlz Jun 7, 2022
c11be44
Work in progress improvements
kaenganxt Sep 14, 2022
576d3f1
Merge branch 'master' into tool-sync
kaenganxt Mar 11, 2023
fa05684
Finish player tools implementation, add district tool
kaenganxt Mar 12, 2023
acdcfa3
Remove old player pointer logic, make tool commands non-transactional
kaenganxt Mar 12, 2023
e3235fa
Don't use the color red for other players
kaenganxt Mar 12, 2023
ece2e5a
Fix unused imports and formatting
kaenganxt Apr 9, 2023
c3771fa
Merge branch 'master' into tool-sync
kaenganxt Apr 9, 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
Prev Previous commit
Next Next commit
Created BaseToolHandler to abstract common tasks when sending and rec…
…eiving commands
  • Loading branch information
CWMlolzlz authored and kaenganxt committed Aug 21, 2022
commit f48220e9d53cbebd1a9c8b7ab41781075228b8b3
3 changes: 2 additions & 1 deletion src/csm/CSM.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
<Compile Include="Injections\Tools\BuildingToolHandler.cs" />
<Compile Include="Injections\Tools\DefaultToolHandler.cs" />
<Compile Include="Injections\Tools\ToolManagerOverlayRenderer.cs" />
<Compile Include="Injections\Tools\BaseToolHandler.cs" />
<Compile Include="Models\ColorSurrogate.cs" />
<Compile Include="Models\QuaternionSurrogate.cs" />
<Compile Include="Models\ControlPointSurrogate.cs" />
Expand Down Expand Up @@ -180,4 +181,4 @@
<PostBuildEvent Condition="$([MSBuild]::IsOsPlatform('linux'))">pwsh "$(SolutionDir)scripts/build.ps1" -OutputDirectory "$(TargetDir)" -Install</PostBuildEvent>
<PostBuildEvent Condition="$([MSBuild]::IsOsPlatform('osx'))">pwsh "$(SolutionDir)scripts/build.ps1" -OutputDirectory "$(TargetDir)" -Install</PostBuildEvent>
</PropertyGroup>
</Project>
</Project>
32 changes: 32 additions & 0 deletions src/csm/Injections/Tools/BaseToolHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using CSM.API;
using CSM.API.Commands;
using CSM.Networking;
using CSM.BaseGame.Helpers;
using CSM.API.Helpers;
using ColossalFramework;
using ICities;
using CSM.BaseGame;
using CSM.Helpers;
using UnityEngine;

namespace CSM.Injections.Tools
{
public abstract class BaseToolCommandHandler<Command, Tool> : CommandHandler<Command> where Command: CommandBase where Tool: ToolBase
{

protected override void Handle(Command command)
{
if (!MultiplayerManager.Instance.IsConnected())
{
// Ignore packets while not connected
return;
}
var buildingTool = Singleton<ToolSimulator>.instance.GetTool<Tool>(command.SenderId);

Configure(buildingTool, command);

}

protected abstract void Configure(Tool tool, Command command);
}
}
51 changes: 15 additions & 36 deletions src/csm/Injections/Tools/BuildingToolHandler.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System.Xml.Serialization;
using System.Collections.ObjectModel;
using System;
using CSM.API.Commands;
using CSM.Networking;
Expand Down Expand Up @@ -39,7 +37,6 @@ public static void Postfix(BuildingTool __instance, Vector3 ___m_cachedPosition,
// Send info to all clients
var newCommand = new PlayerBuildingToolCommandHandler.Command
{
PlayerName = playerName,
Prefab = (ushort)Mathf.Clamp(__instance.m_prefab.m_prefabDataIndex, 0, 65535),
Relocating = __instance.m_relocate,
Position = ___m_cachedPosition,
Expand All @@ -56,64 +53,46 @@ public static void Postfix(BuildingTool __instance, Vector3 ___m_cachedPosition,
}
}

public class PlayerBuildingToolCommandHandler : CommandHandler<PlayerBuildingToolCommandHandler.Command>
public class PlayerBuildingToolCommandHandler : BaseToolCommandHandler<PlayerBuildingToolCommandHandler.Command, BuildingTool>
{

[ProtoContract]
public class Command : CommandBase, IEquatable<Command>
{
[ProtoMember(1)]
public string PlayerName { get; set; }
[ProtoMember(2)]
public ushort Prefab { get; set; }
[ProtoMember(3)]
[ProtoMember(2)]
public int Relocating { get; set; }
[ProtoMember(4)]
[ProtoMember(3)]
public Vector3 Position { get; set; }
[ProtoMember(5)]
[ProtoMember(4)]
public float Angle { get; set; }
[ProtoMember(6)]
[ProtoMember(5)]
public Segment3 Segment { get; set; }
[ProtoMember(7)]
[ProtoMember(6)]
public int Elevation { get; set; }


public bool Equals(Command other)
{
return object.Equals(this.PlayerName, other.PlayerName) &&
object.Equals(this.Prefab, other.Prefab) &&
return object.Equals(this.Prefab, other.Prefab) &&
object.Equals(this.Relocating, other.Relocating) &&
object.Equals(this.Position, other.Position) &&
object.Equals(this.Segment, other.Segment) &&
object.Equals(this.Angle, other.Angle) &&
object.Equals(this.Segment, other.Segment) &&
object.Equals(this.Elevation, other.Elevation);
}

}

public PlayerBuildingToolCommandHandler()
{
TransactionCmd = false;
}

protected override void Handle(Command command)
{
if (!MultiplayerManager.Instance.IsConnected())
{
// Ignore packets while not connected
return;
}
var buildingTool = ToolSimulator.GetTool<BuildingTool>(command.SenderId);

protected override void Configure(BuildingTool tool, Command command) {
BuildingInfo prefab = PrefabCollection<BuildingInfo>.GetPrefab(command.Prefab);

ReflectionHelper.SetAttr(buildingTool, "m_prefab", prefab);
ReflectionHelper.SetAttr(buildingTool, "m_relocate", command.Relocating);
ReflectionHelper.SetAttr(buildingTool, "m_cachedPosition", command.Position);
ReflectionHelper.SetAttr(buildingTool, "m_cachedAngle", command.Angle);
ReflectionHelper.SetAttr(buildingTool, "m_cachedSegment", command.Segment);
ReflectionHelper.SetAttr(buildingTool, "m_elevation", command.Elevation);

ReflectionHelper.SetAttr(tool, "m_prefab", prefab);
ReflectionHelper.SetAttr(tool, "m_relocate", command.Relocating);
ReflectionHelper.SetAttr(tool, "m_cachedPosition", command.Position);
ReflectionHelper.SetAttr(tool, "m_cachedAngle", command.Angle);
ReflectionHelper.SetAttr(tool, "m_cachedSegment", command.Segment);
ReflectionHelper.SetAttr(tool, "m_elevation", command.Elevation);
}
}

Expand Down
5 changes: 0 additions & 5 deletions src/csm/Injections/Tools/DefaultToolHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,6 @@ public class Command : CommandBase

}

public PlayerDefaultToolCommandHandler()
{
TransactionCmd = false;
}

protected override void Handle(Command command)
{
if (!MultiplayerManager.Instance.IsConnected())
Expand Down