Fewer hitches: regular save-game pull only when something changed since the last save (saving freezes the game briefly), default interval 10 min
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -40,6 +40,12 @@ public sealed class WorldState
|
||||
public const int MaxDestroyed = 5000;
|
||||
|
||||
public bool Dirty { get; private set; }
|
||||
/// <summary>
|
||||
/// Änderungen, die im Spielstand landen (Aktionen, Fahrzeugwerte, Geld, Türen, Käufe ...) seit dem letzten hochgeladenen
|
||||
/// Spielstand. 0 = der regelmäßige Spielstand-Abruf kann ausfallen (Speichern lässt das Spiel kurz hängen).
|
||||
/// </summary>
|
||||
[System.Text.Json.Serialization.JsonIgnore]
|
||||
public int ChangesSinceSave { get; set; } = 1;
|
||||
|
||||
static readonly JsonSerializerOptions Options = new() { WriteIndented = false };
|
||||
|
||||
@@ -64,6 +70,7 @@ public sealed class WorldState
|
||||
/// </summary>
|
||||
public void ResetForNewSave()
|
||||
{
|
||||
ChangesSinceSave = 0;
|
||||
Objects.Clear();
|
||||
Events.Clear();
|
||||
MoneyDelta = 0f;
|
||||
@@ -141,6 +148,7 @@ public sealed class WorldState
|
||||
|
||||
public void ApplyMoney(byte[] payload)
|
||||
{
|
||||
ChangesSinceSave++;
|
||||
if (payload.Length < 4) return;
|
||||
MoneyDelta += BitConverter.ToSingle(payload, 0);
|
||||
Dirty = true;
|
||||
@@ -148,6 +156,7 @@ public sealed class WorldState
|
||||
|
||||
public void ApplyDoor(byte[] payload)
|
||||
{
|
||||
ChangesSinceSave++;
|
||||
using var r = new BinaryReader(new MemoryStream(payload));
|
||||
string key = r.ReadString();
|
||||
Doors[key] = r.ReadString();
|
||||
@@ -156,6 +165,7 @@ public sealed class WorldState
|
||||
|
||||
public void ApplyVars(byte[] payload)
|
||||
{
|
||||
ChangesSinceSave++;
|
||||
using var r = new BinaryReader(new MemoryStream(payload));
|
||||
int count = r.ReadInt32();
|
||||
if (count < 0 || count > 10000) return;
|
||||
@@ -187,6 +197,7 @@ public sealed class WorldState
|
||||
|
||||
public void AddAppeared(byte[] payload)
|
||||
{
|
||||
ChangesSinceSave++;
|
||||
if (Appeared.Count >= MaxAppeared) return;
|
||||
Appeared.Add(Convert.ToBase64String(payload));
|
||||
Dirty = true;
|
||||
@@ -194,6 +205,7 @@ public sealed class WorldState
|
||||
|
||||
public void AddDestroyed(int id)
|
||||
{
|
||||
ChangesSinceSave++;
|
||||
if (Destroyed.Count >= MaxDestroyed || Destroyed.Contains(id)) return;
|
||||
Destroyed.Add(id);
|
||||
Objects.Remove(id);
|
||||
@@ -203,6 +215,7 @@ public sealed class WorldState
|
||||
public void AddFsmEvent(byte[] payload)
|
||||
{
|
||||
if (Events.Count >= MaxEvents) return;
|
||||
ChangesSinceSave++;
|
||||
Events.Add(Convert.ToBase64String(payload));
|
||||
Dirty = true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user