-
Notifications
You must be signed in to change notification settings - Fork 4
Getting started
Add this repository as a submodule:
git submodule add https://github.com/janfokke/MonoSync.git
git submodule update --init
add a reference to MonoSync.csproj
Install-Package MonoSync
Install Fody/PropertyChanged
MonoSync tracks changed, using the INotifyPropertyChanged.PropertyChanged
event.
And Fody/PropertyChanged automatically injects code which raises the PropertyChanged event, into property setters of classes which implement INotifyPropertyChanged.
Add Attributes to your Entities/GameWorld
[Synchronizable]
[AddINotifyPropertyChangedInterface]
internal class TestGameWorld
{
[Synchronize]
public ObservableDictionary<string, TestPlayer> Players { get; set; } =
new ObservableDictionary<string, TestPlayer>();
[Synchronize]
public int RandomIntProperty { get; set; }
}
[Synchronizable]
[AddINotifyPropertyChangedInterface]
internal class TestPlayer
{
[Synchronize]
public int Level { get; set; }
[Synchronize]
public int Health { get; set; }
}
Create a SyncSourceRoot Server-side
var sourceGameWorld = new TestGameWorld();
var sourceSynchronizerRoot = new SourceSynchronizerRoot(sourceGameWorld );
Initial Synchronization to new Clients
using (var writeSession = sourceSynchronizerRoot.BeginWrite())
{
byte[] fullSynchronization = writeSession.WriteFull();
foreach(Client client in _newClients)
{
client.SendWorldData(fullSynchronization);
}
// Sync existing clients here (See step 10)
// ...
// ...
}
Receive initial world data Client-Side and create a new SyncTargetRoot
var targetSynchronizerRoot = new TargetSynchronizerRoot<TestGameWorld>(fullSynchronization);
Write changes Server-Side
using (var writeSession = sourceSynchronizerRoot.BeginWrite())
{
// Sync new clients here (See step 5)
// ...
// ...
SynchronizationPacket changesWithoutTick = writeSession.WriteChanges();
foreach (var client in clients)
{
byte[] changesSynchronization = changesWithoutTick.SetTick(client.Tick);
client.SendWorldData(changesSynchronization);
}
}
Read changes client-side
targetSynchronizerRoot.Read(changesSynchronization);
Example project: https://github.com/janfokke/MonoSync/tree/master/samples/Tweening