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

Conversation

CWMlolzlz
Copy link
Contributor

@CWMlolzlz CWMlolzlz commented Apr 20, 2022

Based on the feature request #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

  • Coloring each player's rendered tools
  • Sync default/idle tool
  • Sync net tool
  • Sync building tool
  • Sync prop tool
  • Sync zoning tool
  • Sync bulldoze tool
  • Sync tree tool
  • 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

  • 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 CWMlolzlz changed the title Synchronise Synchronise player tools and focus between clients Apr 20, 2022
@CWMlolzlz
Copy link
Contributor Author

@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

@kaenganxt kaenganxt marked this pull request as draft April 20, 2022 13:33
@kaenganxt
Copy link
Member

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

CWMlolzlz and others added 24 commits August 21, 2022 16:59
… local render passes.`

- Fixes issue where the default NetTool's angle label is rendered over other client tools
@RuisSoftware
Copy link

Please continue working on this pull request :)

@kaenganxt
Copy link
Member

kaenganxt commented Mar 12, 2023

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 kaenganxt marked this pull request as ready for review March 12, 2023 21:40
@DominicMaas
Copy link
Member

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

@DominicMaas
Copy link
Member

Updated the assemblies, lets see how this goes

src/api/Networking/Player.cs Outdated Show resolved Hide resolved
src/basegame/Injections/Tools/DistrictToolHandler.cs Outdated Show resolved Hide resolved
src/csm/CSM.cs Outdated Show resolved Hide resolved
src/csm/Networking/MultiplayerManager.cs Outdated Show resolved Hide resolved
@kaenganxt kaenganxt merged commit 4c0ae86 into CitiesSkylinesMultiplayer:master Apr 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants