private void ServerRemote_ApplyZoneModififications(IProtoZone protoZone, QuadTreeDiff diff) { var character = ServerRemoteContext.Character; var zoneInstance = protoZone.ServerZoneInstance; zoneInstance.ApplyDiff(diff); Logger.Important($"Zone quadtree diff applied: {diff} for {protoZone} by {character}"); }
public void ApplyClientChanges(bool forcePushChangesImmediately) { this.ValidateIsDataReceived(); var newSnapshot = this.quadTree.SaveQuadTree(); var diffDo = QuadTreeDiff.Create( newSnapshot, this.lastClientSnapshot); if (diffDo.IsEmpty) { // quad trees are equal return; } var redo = false; EditorClientSystem.DoAction( "Modify zone " + this.ProtoZone.Id, onDo: () => { if (redo) { this.quadTree.ApplyDiff(diffDo); } OnDiffApplied(diffDo); }, onUndo: () => { // set flag for next "do" call to make it "redo" redo = true; var diffRedo = diffDo.ReverseDiff(); this.quadTree.ApplyDiff(diffRedo); OnDiffApplied(diffRedo); }); // helper local function void OnDiffApplied(QuadTreeDiff appliedDiff) { this.isNeedSyncToServer = true; this.lastModificationTime = Api.Client.Core.ClientRealTime; this.lastClientSnapshot = this.quadTree.SaveQuadTree(); this.ZoneModified?.Invoke(appliedDiff); if (forcePushChangesImmediately) { this.SyncToServer(forceImmediate: true); } else { this.ScheduleSyncToServer(); } } }
private void SyncToServer(bool forceImmediate) { this.ValidateIsDataReceived(); if (!this.isNeedSyncToServer) { return; } if (!forceImmediate) { if (Api.Client.Core.ClientRealTime - this.lastModificationTime < CommitZoneChangesDelaySeconds) { // commit delay is not yet exceeded - schedule commit next time this.ScheduleSyncToServer(); return; } } this.isNeedSyncToServer = false; var newSnapshot = this.quadTree.SaveQuadTree(); var diff = QuadTreeDiff.Create(newSnapshot, this.lastServerSnapshot); if (diff.IsEmpty) { // quad trees are equal return; } this.lastServerSnapshot = newSnapshot; EditorZoneSystem.Instance.ClientSendZoneModifications(this.ProtoZone, diff); (EditorActiveToolManager.ActiveTool as EditorActiveToolZones)?.RefreshCurrentZonesList(); }
public void ClientSendZoneModifications(IProtoZone protoZone, QuadTreeDiff diff) { Logger.Important($"Zone quadtree diff sent: {diff} for {protoZone}"); this.CallServer(_ => _.ServerRemote_ApplyZoneModififications(protoZone, diff)); }