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
Added prop tool support
  • Loading branch information
CWMlolzlz authored and kaenganxt committed Aug 21, 2022
commit 5872afc7a4b7b266010973ec5bbfaa1b54f9bda3
1 change: 1 addition & 0 deletions src/csm/CSM.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
<Compile Include="Injections\Tools\ToolManagerOverlayRenderer.cs" />
<Compile Include="Injections\Tools\BaseToolHandler.cs" />
<Compile Include="Injections\Tools\NetToolHandler.cs" />
<Compile Include="Injections\Tools\PropToolHandler.cs" />
<Compile Include="Injections\Tools\ZoneToolHandler.cs" />
<Compile Include="Models\ColorSurrogate.cs" />
<Compile Include="Models\QuaternionSurrogate.cs" />
Expand Down
91 changes: 91 additions & 0 deletions src/csm/Injections/Tools/PropToolHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
using System.Linq;
using System.Collections.Generic;
using System.Net.NetworkInformation;
using System;
using CSM.API.Commands;
using CSM.Networking;
using ICities;
using ColossalFramework;
using ColossalFramework.Math;
using ProtoBuf;
using HarmonyLib;
using UnityEngine;
using CSM.BaseGame.Helpers;
using CSM.API.Helpers;

namespace CSM.Injections.Tools
{
[HarmonyPatch(typeof(PropTool))]
[HarmonyPatch("OnToolLateUpdate")]
public class PropToolHandler {

private static PlayerPropToolCommandHandler.Command lastCommand;

public static void Postfix(PropTool __instance, PropInfo ___m_propInfo, Vector3 ___m_cachedPosition, float ___m_cachedAngle, Randomizer ___m_randomizer)
{
if (MultiplayerManager.Instance.CurrentRole != MultiplayerRole.None) {

// Send info to all clients
var newCommand = new PlayerPropToolCommandHandler.Command
{
Prop = (uint) ___m_propInfo.m_prefabDataIndex,
Mode = (int) __instance.m_mode,
Position = ___m_cachedPosition,
Angle = ___m_cachedAngle,
RandomizerSeed = ___m_randomizer.seed
};
if(!object.Equals(newCommand, lastCommand)) {
lastCommand = newCommand;
Command.SendToAll(newCommand);
}

}
}
}

public class PlayerPropToolCommandHandler : BaseToolCommandHandler<PlayerPropToolCommandHandler.Command, PropTool>
{

[ProtoContract]
public class Command : CommandBase, IEquatable<Command>
{
[ProtoMember(1)]
public uint Prop { get; set; }
[ProtoMember(2)]
public int Mode { get; set; }
[ProtoMember(3)]
public Vector3 Position { get; set; }
[ProtoMember(4)]
public float Angle { get; set; }
[ProtoMember(5)]
public ulong RandomizerSeed { get; set; }

// TODO: Transmit brush info for clients to render. See PropTool::OnToolUpdate
// TODO: Transmit placement errors

public bool Equals(Command other)
{
return object.Equals(this.Prop, other.Prop) &&
object.Equals(this.Mode, other.Mode) &&
object.Equals(this.Position, other.Position) &&
object.Equals(this.Angle, other.Angle) &&
object.Equals(this.RandomizerSeed, other.RandomizerSeed);
}

}

protected override void Configure(PropTool tool, Command command) {
// Note: Some private fields are already initialised by the ToolSimulator
// These fields here are the important ones to transmit between game sessions

ReflectionHelper.SetAttr(tool, "m_propInfo", PrefabCollection<PropInfo>.GetPrefab(command.Prop));
tool.m_mode = (PropTool.Mode) Enum.GetValues(typeof(PropTool.Mode)).GetValue(command.Mode);
ReflectionHelper.SetAttr(tool, "m_cachedPosition", command.Position);
ReflectionHelper.SetAttr(tool, "m_cachedAngle", command.Angle);
ReflectionHelper.SetAttr(tool, "m_randomizer", new Randomizer(command.RandomizerSeed));

}
}


}