mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-08-01 08:18:20 -04:00
Just some easy wins, without touching any of the gizmo API surface.
MSC main scene gizmo time went went from 55ms to 19ms
* Actually cache GizmoDetails / GizmoHandles
Before the cache flag `handleBuilt` was never actually set to true 🫠 , so `BuilldGizmodDetails` would rerun every frame resulting in the majority of our Gizmo frame time.
* Gizmo pool vertex arrays
* Gizmo scene object pool uses struct keys instead of strings
* Gizmo cache vertex object render config, skip redundant native sets
* Cull decal direction arrow gizmo at distance
* Skip gizmo scope for components that don't draw gizmos
* Slim down decal direction arrow gizmo
25 lines
787 B
C#
25 lines
787 B
C#
using System.Reflection;
|
|
|
|
namespace Sandbox;
|
|
|
|
public abstract partial class Component
|
|
{
|
|
/// <summary>
|
|
/// Called in the editor to draw things like bounding boxes etc
|
|
/// </summary>
|
|
protected virtual void DrawGizmos() { }
|
|
|
|
static readonly ReflectionCache<Type, bool> _typeOverridesDrawGizmos = new(
|
|
t => t.GetMethod( nameof( DrawGizmos ), BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public, null, Type.EmptyTypes, null )?.DeclaringType != typeof( Component ) );
|
|
|
|
bool? _overridesDrawGizmos;
|
|
|
|
internal bool OverridesDrawGizmos => _overridesDrawGizmos ??= _typeOverridesDrawGizmos[GetType()];
|
|
|
|
internal void DrawGizmosInternal()
|
|
{
|
|
try { DrawGizmos(); }
|
|
catch ( System.Exception e ) { Log.Error( e, $"Exception when calling 'DrawGizmos' on {this}" ); }
|
|
}
|
|
}
|