refactor(runtime): own canonical action state
Move selection, combat, and interaction target mode under one Runtime owner; make plugins, retained UI, session routing, and typed runtime views borrow its exact children; and add failure-safe reset, instance isolation, source ownership, and normalized checkpoint coverage without changing retail ordering. Co-authored-by: Codex <codex@openai.com>
This commit is contained in:
parent
bb45afef33
commit
b298f99f91
38 changed files with 711 additions and 93 deletions
|
|
@ -42,6 +42,7 @@ public sealed class CurrentGameRuntimeAdapterTests
|
|||
Assert.Equal(new RuntimeGenerationToken(1), start.Generation);
|
||||
Assert.Equal(Harness.PlayerGuid, harness.Identity.ServerGuid);
|
||||
Assert.Equal(RuntimeLifecycleState.InWorld, harness.Runtime.Lifecycle.State);
|
||||
Assert.Same(harness.Actions.View, harness.Runtime.Actions);
|
||||
|
||||
LiveEntityRecord liveRecord =
|
||||
harness.Entities.RegisterAndMaterializeProjection(Spawn(
|
||||
|
|
@ -117,6 +118,10 @@ public sealed class CurrentGameRuntimeAdapterTests
|
|||
Assert.Equal(1, checkpoint.ChatCount);
|
||||
Assert.Equal(1L, checkpoint.ChatRevision);
|
||||
Assert.Equal(1UL, checkpoint.FrameNumber);
|
||||
Assert.Equal(
|
||||
Harness.TargetGuid,
|
||||
checkpoint.Actions.SelectedObjectId);
|
||||
Assert.Equal(1, checkpoint.Actions.SelectionRevision);
|
||||
Assert.Equal(RuntimePortalKind.Portal, checkpoint.Portal.Kind);
|
||||
Assert.Equal(0x12340001u, checkpoint.Portal.DestinationCell);
|
||||
Assert.True(checkpoint.Portal.IsReady);
|
||||
|
|
@ -676,7 +681,7 @@ public sealed class CurrentGameRuntimeAdapterTests
|
|||
EntityObjects);
|
||||
Objects = EntityObjects.Objects;
|
||||
Communication = new RuntimeCommunicationState();
|
||||
Selection = new SelectionState();
|
||||
Actions = new RuntimeActionState();
|
||||
MovementInput = new DispatcherMovementInputSource();
|
||||
GameplayInput = new GameplayInputFrameController(
|
||||
dispatcher: null,
|
||||
|
|
@ -697,6 +702,7 @@ public sealed class CurrentGameRuntimeAdapterTests
|
|||
_items = new ItemInteractionController(
|
||||
Objects,
|
||||
InventoryState.Transactions,
|
||||
Actions.Interaction,
|
||||
() => PlayerGuid,
|
||||
sendUse: null,
|
||||
sendUseWithTarget: null,
|
||||
|
|
@ -726,10 +732,10 @@ public sealed class CurrentGameRuntimeAdapterTests
|
|||
InventoryState,
|
||||
Character,
|
||||
Communication,
|
||||
Actions,
|
||||
new LocalPlayerControllerSlot(),
|
||||
WorldReveal,
|
||||
Clock,
|
||||
Selection,
|
||||
selectionController,
|
||||
GameplayInput,
|
||||
Combat);
|
||||
|
|
@ -744,7 +750,8 @@ public sealed class CurrentGameRuntimeAdapterTests
|
|||
public ClientObjectTable Objects { get; }
|
||||
public RuntimeCommunicationState Communication { get; }
|
||||
public ChatLog Chat => Communication.Chat;
|
||||
public SelectionState Selection { get; }
|
||||
public RuntimeActionState Actions { get; }
|
||||
public SelectionState Selection => Actions.Selection;
|
||||
public DispatcherMovementInputSource MovementInput { get; }
|
||||
public GameplayInputFrameController GameplayInput { get; }
|
||||
public RecordingCombatCommand Combat { get; }
|
||||
|
|
@ -763,6 +770,7 @@ public sealed class CurrentGameRuntimeAdapterTests
|
|||
Communication.Dispose();
|
||||
_session.Dispose();
|
||||
_items.Dispose();
|
||||
Actions.Dispose();
|
||||
Entities.Clear();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
159
tests/AcDream.App.Tests/Runtime/RuntimeActionOwnershipTests.cs
Normal file
159
tests/AcDream.App.Tests/Runtime/RuntimeActionOwnershipTests.cs
Normal file
|
|
@ -0,0 +1,159 @@
|
|||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace AcDream.App.Tests.Runtime;
|
||||
|
||||
public sealed class RuntimeActionOwnershipTests
|
||||
{
|
||||
[Fact]
|
||||
public void ProductionConstructsOneCanonicalActionOwner()
|
||||
{
|
||||
string root = FindRepositoryRoot();
|
||||
string gameWindow = ReadAppSource(
|
||||
root,
|
||||
"Rendering",
|
||||
"GameWindow.cs");
|
||||
string program = ReadAppSource(root, "Program.cs");
|
||||
|
||||
Assert.Contains(
|
||||
"private readonly RuntimeActionState _runtimeActions = new();",
|
||||
gameWindow,
|
||||
StringComparison.Ordinal);
|
||||
Assert.Contains(
|
||||
"_runtimeActions.Selection;",
|
||||
gameWindow,
|
||||
StringComparison.Ordinal);
|
||||
Assert.Contains(
|
||||
"_runtimeActions.Combat;",
|
||||
gameWindow,
|
||||
StringComparison.Ordinal);
|
||||
Assert.Contains(
|
||||
"window.Selection,",
|
||||
program,
|
||||
StringComparison.Ordinal);
|
||||
|
||||
string[] productionFiles = Directory
|
||||
.EnumerateFiles(
|
||||
Path.Combine(root, "src", "AcDream.App"),
|
||||
"*.cs",
|
||||
SearchOption.AllDirectories)
|
||||
.Where(static path =>
|
||||
!path.Contains(
|
||||
$"{Path.DirectorySeparatorChar}Studio{Path.DirectorySeparatorChar}",
|
||||
StringComparison.Ordinal))
|
||||
.ToArray();
|
||||
string production = string.Join(
|
||||
"\n",
|
||||
productionFiles.Select(File.ReadAllText));
|
||||
|
||||
Assert.Empty(Regex.Matches(
|
||||
production,
|
||||
@"\bnew\s+(?:AcDream\.Core\.Selection\.)?SelectionState\s*\("));
|
||||
Assert.Empty(Regex.Matches(
|
||||
production,
|
||||
@"\bnew\s+(?:AcDream\.Core\.Combat\.)?CombatState\s*\("));
|
||||
Assert.Empty(Regex.Matches(
|
||||
production,
|
||||
@"\bnew\s+(?:AcDream\.Runtime\.Gameplay\.)?InteractionState\s*\("));
|
||||
Assert.Equal(
|
||||
1,
|
||||
Regex.Matches(
|
||||
production,
|
||||
@"\bnew\s+RuntimeActionState\s*\(").Count
|
||||
+ Regex.Matches(
|
||||
production,
|
||||
@"RuntimeActionState\s+\w+\s*=\s*new\s*\(\s*\)").Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UiSessionRuntimeAndShutdownBorrowTheExactActionChildren()
|
||||
{
|
||||
string root = FindRepositoryRoot();
|
||||
string ui = ReadAppSource(
|
||||
root,
|
||||
"Composition",
|
||||
"InteractionRetainedUiComposition.cs");
|
||||
string session = ReadAppSource(
|
||||
root,
|
||||
"Composition",
|
||||
"SessionPlayerComposition.cs");
|
||||
string liveSession = ReadAppSource(
|
||||
root,
|
||||
"Net",
|
||||
"LiveSessionRuntimeFactory.cs");
|
||||
string commands = ReadAppSource(
|
||||
root,
|
||||
"Runtime",
|
||||
"CurrentGameRuntimeCommandAdapter.cs");
|
||||
string itemInteraction = ReadAppSource(
|
||||
root,
|
||||
"UI",
|
||||
"ItemInteractionController.cs");
|
||||
string shutdown = ReadAppSource(
|
||||
root,
|
||||
"Rendering",
|
||||
"GameWindowLifetime.cs");
|
||||
|
||||
Assert.Contains("d.Actions.Interaction,", ui, StringComparison.Ordinal);
|
||||
Assert.Contains("d.Actions.Selection", ui, StringComparison.Ordinal);
|
||||
Assert.Contains("d.Actions.Combat", ui, StringComparison.Ordinal);
|
||||
Assert.Contains("d.Actions.Selection", session, StringComparison.Ordinal);
|
||||
Assert.Contains("d.Actions.Combat", session, StringComparison.Ordinal);
|
||||
Assert.Contains("_domain.Actions.Combat", liveSession, StringComparison.Ordinal);
|
||||
Assert.Contains("_actions.Selection", commands, StringComparison.Ordinal);
|
||||
Assert.Contains(
|
||||
"InteractionState interactionState,",
|
||||
itemInteraction,
|
||||
StringComparison.Ordinal);
|
||||
Assert.DoesNotContain(
|
||||
"new InteractionState",
|
||||
itemInteraction,
|
||||
StringComparison.Ordinal);
|
||||
Assert.Contains(
|
||||
"\"runtime action state\"",
|
||||
shutdown,
|
||||
StringComparison.Ordinal);
|
||||
AssertAppearsInOrder(
|
||||
shutdown,
|
||||
"\"runtime inventory state\"",
|
||||
"\"runtime action state\"",
|
||||
"\"runtime entity/object lifetime\"");
|
||||
Assert.False(File.Exists(Path.Combine(
|
||||
root,
|
||||
"src",
|
||||
"AcDream.App",
|
||||
"UI",
|
||||
"InteractionState.cs")));
|
||||
}
|
||||
|
||||
private static string ReadAppSource(string root, params string[] relative) =>
|
||||
File.ReadAllText(Path.Combine(
|
||||
[root, "src", "AcDream.App", .. relative]));
|
||||
|
||||
private static string FindRepositoryRoot()
|
||||
{
|
||||
var current = new DirectoryInfo(AppContext.BaseDirectory);
|
||||
while (current is not null)
|
||||
{
|
||||
if (File.Exists(Path.Combine(current.FullName, "AcDream.slnx")))
|
||||
return current.FullName;
|
||||
current = current.Parent;
|
||||
}
|
||||
throw new DirectoryNotFoundException("AcDream.slnx was not found.");
|
||||
}
|
||||
|
||||
private static void AssertAppearsInOrder(
|
||||
string source,
|
||||
params string[] fragments)
|
||||
{
|
||||
int cursor = 0;
|
||||
foreach (string fragment in fragments)
|
||||
{
|
||||
int index = source.IndexOf(
|
||||
fragment,
|
||||
cursor,
|
||||
StringComparison.Ordinal);
|
||||
Assert.True(index >= 0, $"Missing source fragment: {fragment}");
|
||||
cursor = index + fragment.Length;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue