Non-Realtime collaboration using modified CSM¶
Non-Realtime collaboration using modified CSM
Preface:¶
In this task, we try creating a version control system for CSL using a modified version of CSM.
We use CSM because it already implements all the needed event listeners that we need in order to serialize a city.
Background:¶
How CSM works:¶
In-game events:¶
CSM uses a C# assembly patching library called Harmony, Which is basically a library used for patching methods that are already compiled in an assembly. It allows you to execute code before and after a certain function is called. By using Harmony, CSM is able to add event listeners on all the relevant events in the game and serialize them into “Commands”.
For example, when we create a road segment in the game, a method called NetManager.CreateSegment is called with the corresponding parameters, CSM uses Harmony to listen to this event and serialize it along with the parameters in a class called SegmentCreateCommand.
Network handling:¶
In a CSM game, there is a player who acts as the “server” while all other players are “clients”.
At the beginning of the game, whenever a player connects the server sends the current CRP file to the client.
To update the game in realtime, CSM uses the event listeners and callbacks to send the command to the server which in turn applies the change to the running game and forwards the command to all other connected clients to do the same.
COSVC:¶
CitiesOS Version Control (COSVC) is a modified version of CSM which uses the core functionality of CSM to serialize a game into a text file.
How it works:¶
COSVC uses the event listeners and callbacks used by CSM along with command wrapper classes. The basic idea is instead of sending the command over the network to other players we simply convert the command into a JSON string and append it as a new line in a text file.
Advantages¶
This gives us a pretty readable changelog and an easy way to track changes using git.
This also solves the problem of having to download large CRP files every time you rejoin collaborating on a large city.
Future work¶
- Splitting the save file into multiple save files with corresponding aspects of the game
(e.g. Network, Buildings, Economy, etc…)
- This mod could be integrated with CSM to shorten loading times.