Performance: time-sliced checks for idle objects, fewer allocations, rarer damage checks for parked cars

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-09-27 15:03:45 +02:00
co-authored by Claude Opus 5.5
parent 2eb15f2166
commit 9b8c64d0c6
3 changed files with 21 additions and 4 deletions
+6 -2
View File
@@ -14,7 +14,8 @@ namespace MSCO
public class DamageSync
{
const float ScanInterval = 10f;
const float CheckInterval = 1f;
const float CheckInterval = 1f; // Fahrzeuge, die wir fahren
const float FreeCheckInterval = 5f; // geparkte Fahrzeuge (Unfall nur durch Anstoßen) seltener
const float MinMove = 0.002f;
const int MaxPerMessage = 4000;
@@ -31,7 +32,7 @@ namespace MSCO
readonly Dictionary<int, DamageMesh> meshes = new Dictionary<int, DamageMesh>();
readonly HashSet<MeshFilter> seen = new HashSet<MeshFilter>();
readonly List<int> changed = new List<int>();
float nextScan, nextCheck;
float nextScan, nextCheck, nextFreeCheck;
static List<Type> types;
public int Count { get { return meshes.Count; } }
@@ -52,12 +53,15 @@ namespace MSCO
}
if (Time.time < nextCheck) return;
nextCheck = Time.time + CheckInterval;
bool checkFree = Time.time >= nextFreeCheck;
if (checkFree) nextFreeCheck = Time.time + FreeCheckInterval;
foreach (DamageMesh m in meshes.Values)
{
if (m.Filter == null) continue;
int owner = objects.VehicleOwner(m.Root);
if (owner != SyncedBody.NoOwner && owner != localId) continue; // der Fahrer schickt die Schäden
if (owner == SyncedBody.NoOwner && !checkFree) continue;
Mesh mesh = m.Filter.sharedMesh;
if (mesh == null) continue;