CSM icon indicating copy to clipboard operation
CSM copied to clipboard

Synchronise player tools and focus between clients

Open CWMlolzlz opened this issue 2 years ago • 2 comments

Based on the feature request https://github.com/CitiesSkylinesMultiplayer/CSM/issues/198

Overview

This feature aims to synchronize each clients tool state with other player so players can see actions other players are performing. From some early attempts it is possible to share the internal state of each player's active tool and hook it into render loop of the game. There is no need to reimplement the render logic for each tool and only the state required for rendering each tool needs to be shared.

Features

  • [x] Coloring each player's rendered tools
  • [x] Sync default/idle tool
  • [x] Sync net tool
  • [x] Sync building tool
  • [x] Sync prop tool
  • [x] Sync zoning tool
  • [x] Sync bulldoze tool
  • [x] Sync tree tool
  • [x] Sync terrain tool
  • [ ] Sync district tool
  • [ ] Sync disaster tool
  • [ ] Sync transport tool
  • [ ] Sync resource tool? ^
  • [ ] Sync water tool? ^
  • [ ] Sync surface tool? ^
  • [ ] Sync snapshot tool? ^
  • [ ] Sync game area tool? ^^

^ These tools aren't normally available within the normal game. We would want to support it so if a mod exposes it in gameplay it will be synced. ^^ Doesn't have dedicated rendering logic.

Future Ideas

  • Render other player cursors over their current position. This helps convey information that overlay rendering doesn't reveal. Super important for zoning tool and terrain tool.
  • Drawing tool. Allow users to draw onto terrain temporarily for communication. Achievable with LineRenderer
  • Pinging. Lets users ping a location to notify others

Bugs

  • [x] NetTool overlays from other clients are rendered if they too are in the NetTool

Technical notes

ToolSimulator

The ToolSimulator is the critical component that is responsible for holding onto the synced state of each tool. I have made this implement the Singleton<T> class so it exists as a GameObject in the Unity engine. Very useful for debugging with ModTools.

Maintenance

Since this mod is reading and writing from private fields within the game's tools there is a risk that a change in a field name can break the syncing of tools. it would likely be on a tool-by-tool basis.

CWMlolzlz avatar Apr 20 '22 08:04 CWMlolzlz

@kaenganxt I accidentally created this without setting it to draft. Would you be able to change this to a draft, I don't think I have permission

CWMlolzlz avatar Apr 20 '22 09:04 CWMlolzlz

What's the state on this? Are only the three remaining tools missing before this is ready?

kaenganxt avatar Jul 16 '22 19:07 kaenganxt

Please continue working on this pull request :)

RuisSoftware avatar Jan 09 '23 01:01 RuisSoftware

I changed/implemented the following things in my new commits:

  • Move tool handlers to basegame project
  • Implement the district tool
  • Fix some default cursors
  • Remove old player pointer logic
  • Make tool commands non-transactional
  • Remove some debug code
  • Add some null checks to UI logic
  • Don't use the color red for other players
  • Display brushes correctly
  • Fix packet equality checks to prevent spamming
  • Fix net tool showing angles forever
  • Destroy old cursor objects to prevent exceptions on unload

The transport tool implementation is still not working correctly, but this is caused by the basic transport line synchronisation being bugged when two players build lines at the same time.

The disaster tool will be looked at when implementing DLC features. So I think this PR is ready for merging at this point.

The PR should build correctly once the Cities assemblies are up to date.

kaenganxt avatar Mar 12 '23 21:03 kaenganxt

I'll update the assemblies when I get home this afternoon

DominicMaas avatar Mar 13 '23 22:03 DominicMaas

Updated the assemblies, lets see how this goes

DominicMaas avatar Mar 14 '23 07:03 DominicMaas