railroader-physics-optimizer/Main.cs
Seton Carmichael 5414fd8979 Initial commit - Physics Overhaul v0.1.1
Features:
- ConsistLOD: fast-path Bezier position update for distant cars (PositionAccuracy
  matched, LocationF/R synced, OnPosition fired, culler sphere kept current)
- ConsistFreezer: per-consist auto-freeze replacing stock all-or-nothing optimizer
- PhysicsTimer: stacked ring buffers (render, FixedUpdate, Tick, PosCars) + report
- PhysicsOverlayGUI: draggable stacked-area chart, reference lines always visible,
  ON/OFF toggles with persistence, opacity control
- Settings: JSON persistence, full UMM settings panel with auto-save
- ConsoleCommands: /rpf with freeze/unfreeze/dump/timing/overlay/forceactive/lod
2026-06-16 12:24:56 -04:00

49 lines
1.9 KiB
C#

using HarmonyLib;
using UnityEngine;
using UnityModManagerNet;
namespace RailroaderPhysicsOverhaul;
public static class Main
{
internal static UnityModManager.ModEntry ModEntry { get; private set; }
public static ModSettings Settings { get; private set; }
public static bool Load(UnityModManager.ModEntry modEntry)
{
ModEntry = modEntry;
// Load persisted settings (creates defaults if Settings.xml doesn't exist yet).
Settings = ModSettings.Load(modEntry);
// Apply settings to runtime state before any patches run.
ConsistLOD.Enabled = Settings.OptimizerEnabled;
ConsistLOD.DistanceThreshold = Settings.DistanceThreshold;
ConsistLOD.ResyncInterval = Settings.ResyncInterval;
ConsistLOD.BlacklistEnabled = Settings.BlacklistEnabled;
ConsistLOD.IsBlacklist = Settings.IsBlacklist;
foreach (string name in Settings.RoadNumberList)
ConsistLOD.RoadNumberList.Add(name);
ConsistFreezer.AutoFreezeEnabled = Settings.AutoFreezeEnabled;
ConsistFreezer.AutoFreezeDistance = Settings.AutoFreezeDistance;
ConsistFreezer.AutoFreezeSpeedThreshold = Settings.AutoFreezeSpeedThreshold;
var harmony = new Harmony(modEntry.Info.Id);
harmony.PatchAll();
PhysicsTimer.TryPatchPositionCars(harmony, modEntry.Logger);
var go = new GameObject("RailroaderPhysicsOverhaul.Overlay");
Object.DontDestroyOnLoad(go);
var overlay = go.AddComponent<PhysicsOverlayGUI>();
overlay.Visible = Settings.ShowOverlay;
overlay.Opacity = Settings.OverlayOpacity;
// UMM settings panel callbacks.
modEntry.OnGUI = entry => SettingsGUI.Draw(entry, Settings);
modEntry.OnSaveGUI = entry => Settings.Save(entry);
modEntry.Logger.Log("RailroaderPhysicsOverhaul loaded.");
return true;
}
}