Vixen
02b45cc4
csharp
public sealed class PlayModeController

Play, pause, step and stop, with the scene put back exactly as it was.

No guide page documents this yet — the page shows what the code says about itself.

Remarks

In-process, which is the default of doc 11's two topologies. The game runs in the viewport against the world the editor was editing, and a snapshot taken on entry is restored on exit. What makes that affordable is the ECS layout — WorldSnapshot says how — and what makes it correct is that the restore clears first, so nothing a script created survives.

The hazard is state that is not in the world. A static field, a native allocation, a subscription to an event that outlives the session: none of them are in a snapshot and all of them make the second play-through behave differently from the first. Doc 11's answer is that a play-stop which leaks should fail rather than degrade silently, so the tracked-object count is compared across the session and Leaks is what it found. A test asserts it is empty; the editor shows it as a notification.

⚠ The selection is translated, not kept. Every entity gets a new handle on restore. The controller does the translation for whatever it was handed, because a caller that forgot would have a selection naming whatever landed in those slots — which looks like a rendering fault and is not one.

Fields and properties (4)

  • public PlayState State

    What the editor is doing.

  • public bool IsPlaying

    Whether the game is running, paused or not.

  • public int PendingSteps

    How many frames Step still owes.

  • public IReadOnlyList<PlayLeak> Leaks

    What was still live after the last session that was not live before it.

Events (2)

Methods (8)

  • public PlayModeController(World world)

    Drives play mode over a world.

  • public bool Play()

    Enters play mode, taking a snapshot first.

  • public IReadOnlyList<Entity> Stop(IEnumerable<Entity>? selection = null)

    Stops the game and puts the scene back.

  • public bool Pause()

    Stops stepping without leaving play mode.

  • public bool Resume()

    Starts stepping again.

  • public void Step(int frames = 1)

    Runs a number of frames while paused.

  • public bool ShouldTick()

    Whether the game loop should run this frame, and consumes a step if it does.

  • public void Dispose()

    Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

Used by (3)

  • EditorApplicationVixen.Editor.App
  • SceneDocumentTestsVixen.Editor.SceneView.Tests
  • SceneTestsVixen.Editor.SceneView.Tests