mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-07 02:08:17 +02:00
* Replace PhysicsMapComponent - Dumb idea - Lots of book-keeping and perf overhead. - Much saner this way. * stuff * More work * Purge * Fixes * Eh? * Fixes * Also this * weh * Fixes * ice-cream * Fix * Fix stacking / gravity * Gravity query * MoveBuffer optimisations * Fixes for test * World gravity * Fix build * Avoid some transform resolves for contactless ents * Less getcomps * Fix contact caching * Possibly less copies * reh * bulldoze * Test "fix" * seikrets * a * I saw this but now I decideded against it * true
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 class VirtualController : EntitySystem
|
|
{
|
|
[Dependency] protected readonly SharedPhysicsSystem PhysicsSystem = default!;
|
|
[Dependency] protected readonly 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) {}
|
|
}
|
|
}
|