Files
sbox-public/engine/Sandbox.Engine/Systems/SceneSystem/IManagedCamera.cs
Lorenz Junglas 39aeaaeefc Editor viewport screen recording (#3999)
* IManagedCamera.GetSetMainCamera with SceneCamera.IsRecordingCamera flag

* Explicitly set RT for recording layers, fixes red border not drawing and issues with scene panels

* Keep recording when switching to play mode

Fix viewport size when switching to play mode while recoding, so we can keep going

https://files.facepunch.com/lolleko/2026/February/05_12-54-WelldocumentedSkua.mp4

* Make sure we can record in the menu too
2026-02-10 11:55:18 +01:00

71 lines
1.6 KiB
C#

using System.Threading;
namespace Sandbox;
/// <summary>
/// Used for c++ to make callbacks to a camera and be able to find it by id
/// </summary>
internal interface IManagedCamera
{
static Lock _directoryLock = new();
static Dictionary<int, WeakReference<IManagedCamera>> _directory = new();
static int _indexer = 1000;
/// <summary>
/// Called when entering a specific pipeline stage
/// </summary>
void OnRenderStage( Rendering.Stage renderStage );
/// <summary>
/// Allocate a camera id for this camera. This is used to find the camera in the c++ code.
/// </summary>
int AllocateCameraId()
{
Cleanup();
lock ( _directoryLock )
{
var cameraId = _indexer++;
// We treat 0 as invalid, so skip it
if ( cameraId == 0 ) cameraId = _indexer++;
_directory[cameraId] = new WeakReference<IManagedCamera>( this );
return cameraId;
}
}
/// <summary>
/// Find a camera by its id. This is used to find the camera by the calling c++ code. This is called
/// in the render thread, so it's important to be thread-safe.
/// </summary>
public static IManagedCamera FindById( int cameraId )
{
lock ( _directoryLock )
{
if ( !_directory.TryGetValue( cameraId, out var reference ) )
return null;
if ( !reference.TryGetTarget( out var cam ) )
return null;
return cam;
}
}
/// <summary>
/// keep the directory clean by trimming all the old ones
/// </summary>
static void Cleanup()
{
lock ( _directoryLock )
{
foreach ( var old in _directory.Where( x => !x.Value.TryGetTarget( out var _ ) ).Select( x => x.Key ).ToArray() )
{
_directory.Remove( old );
}
}
}
}