mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-02 10:07:15 +02:00
* [Dependency] source generator No more reflection, no more codegen at runtime Also various changes to Roslyn helpers to make this easier to write. Requires all types with dependencies to be partial and not have readonly dependency fields. An analyzer enforces this at warning level, the previous injection strategies have remained in the code *for now* as a fallback. No fallback is available for [field: Dependency] properties, due to a Roslyn bug. Code Fixes exist. We love Roslyn * Apply dependencies generator changes to all code * Release notes * Preprocessor got hands * Handle nullable dependencies These are bad but gotta deal with it. * Apply suggestions from code review Co-authored-by: Moony <moony@hellomouse.net> * Fine, let's not use collection expressions --------- Co-authored-by: Moony <moony@hellomouse.net>
79 lines
2.6 KiB
C#
79 lines
2.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using JetBrains.Annotations;
|
|
using Prometheus;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.IoC;
|
|
using Robust.Shared.Physics.Dynamics;
|
|
using Robust.Shared.Physics.Systems;
|
|
using Robust.Shared.Timing;
|
|
|
|
namespace Robust.Shared.Physics.Controllers
|
|
{
|
|
[MeansImplicitUse]
|
|
public abstract partial class VirtualController : EntitySystem
|
|
{
|
|
[Dependency] protected SharedPhysicsSystem PhysicsSystem = default!;
|
|
[Dependency] protected SharedTransformSystem TransformSystem = default!;
|
|
|
|
private static readonly Stopwatch Stopwatch = new();
|
|
|
|
public Histogram.Child BeforeMonitor = default!;
|
|
public Histogram.Child AfterMonitor = default!;
|
|
|
|
#region Boilerplate
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
BeforeMonitor = SharedPhysicsSystem.TickUsageControllerBeforeSolveHistogram.WithLabels(GetType().Name);
|
|
AfterMonitor = SharedPhysicsSystem.TickUsageControllerAfterSolveHistogram.WithLabels(GetType().Name);
|
|
|
|
var updatesBefore = UpdatesBefore.ToArray();
|
|
var updatesAfter = UpdatesAfter.ToArray();
|
|
|
|
SubscribeLocalEvent<PhysicsUpdateBeforeSolveEvent>(OnBeforeSolve, updatesBefore, updatesAfter);
|
|
SubscribeLocalEvent<PhysicsUpdateAfterSolveEvent>(OnAfterSolve, updatesBefore, updatesAfter);
|
|
}
|
|
|
|
private void OnBeforeSolve(ref PhysicsUpdateBeforeSolveEvent ev)
|
|
{
|
|
if(PhysicsSystem.MetricsEnabled)
|
|
Stopwatch.Restart();
|
|
|
|
UpdateBeforeSolve(ev.Prediction, ev.DeltaTime);
|
|
|
|
if(PhysicsSystem.MetricsEnabled)
|
|
BeforeMonitor.Observe(Stopwatch.Elapsed.TotalSeconds);
|
|
}
|
|
|
|
private void OnAfterSolve(ref PhysicsUpdateAfterSolveEvent ev)
|
|
{
|
|
if(PhysicsSystem.MetricsEnabled)
|
|
Stopwatch.Restart();
|
|
|
|
UpdateAfterSolve(ev.Prediction, ev.DeltaTime);
|
|
|
|
if(PhysicsSystem.MetricsEnabled)
|
|
AfterMonitor.Observe(Stopwatch.Elapsed.TotalSeconds);
|
|
}
|
|
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// Run before any map processing starts.
|
|
/// </summary>
|
|
/// <param name="prediction"></param>
|
|
/// <param name="frameTime"></param>
|
|
public virtual void UpdateBeforeSolve(bool prediction, float frameTime) {}
|
|
|
|
/// <summary>
|
|
/// Run after all map processing has finished.
|
|
/// </summary>
|
|
/// <param name="prediction"></param>
|
|
/// <param name="frameTime"></param>
|
|
public virtual void UpdateAfterSolve(bool prediction, float frameTime) {}
|
|
}
|
|
}
|