Snapshot for release 2026.10.23.1 (internal 4204305)
This commit is contained in:
parent
2be3668232
commit
539a7a3e64
69 changed files with 5385 additions and 107 deletions
|
|
@ -924,11 +924,18 @@ internal static unsafe class Program
|
|||
fixed (byte* p = d)
|
||||
{
|
||||
for (int i = 0; i < 2000; i++) c.OnDatagram(outbound, p, d.Length); // warm up
|
||||
long before = GC.GetAllocatedBytesForCurrentThread();
|
||||
long t0 = Stopwatch.GetTimestamp();
|
||||
for (int i = 0; i < n; i++) c.OnDatagram(outbound, p, d.Length);
|
||||
long ticks = Stopwatch.GetTimestamp() - t0;
|
||||
long alloc = GC.GetAllocatedBytesForCurrentThread() - before;
|
||||
// Up to three tries, the fewest bytes counted: a one-off allocation on this thread inside
|
||||
// the timed loop (tiered JIT settling: 5296 bytes in one of four runs, 2026-10-23) is not
|
||||
// the hot path's. An allocation per datagram shows in every try (n of them).
|
||||
long alloc = long.MaxValue, ticks = 0;
|
||||
for (int attempt = 0; attempt < 3 && alloc != 0; attempt++)
|
||||
{
|
||||
long before = GC.GetAllocatedBytesForCurrentThread();
|
||||
long t0 = Stopwatch.GetTimestamp();
|
||||
for (int i = 0; i < n; i++) c.OnDatagram(outbound, p, d.Length);
|
||||
ticks = Stopwatch.GetTimestamp() - t0;
|
||||
alloc = Math.Min(alloc, GC.GetAllocatedBytesForCurrentThread() - before);
|
||||
}
|
||||
double ns = ticks * 1e9 / Stopwatch.Frequency / n;
|
||||
Console.WriteLine($" {what,-44} {ns,7:0} ns/datagram, {alloc} bytes allocated over {n}");
|
||||
_case = "cost";
|
||||
|
|
|
|||
27
tools/KeymapTests/KeymapTests.csproj
Normal file
27
tools/KeymapTests/KeymapTests.csproj
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<!--
|
||||
Offline checks for changing a key in AC's keymap file (Tom 2026-10-22: the item bar's keys are the
|
||||
player's retail keys and change together with the retail toolbar's). src\RynthCore.Engine\
|
||||
Compatibility\AcKeymapText.cs is compiled in as is, with Hotkeys\HotkeyModel.cs: reading the
|
||||
groups and bindings, the modifier bits from MetaKeys, key names (AC's spellings, aliases matched),
|
||||
binding a key so it comes off every other action in the game's groups (never the text-editing
|
||||
ones), unbinding, a new group when there is none, and the CRLF text round trip. Also runs on a
|
||||
copy of the player's own Normal.keymap in memory when there is one; never writes it.
|
||||
Run: dotnet run -c Release (exit 0 = pass, 1 = fail)
|
||||
-->
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<InvariantGlobalization>true</InvariantGlobalization>
|
||||
<RootNamespace>KeymapTests</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="..\..\src\RynthCore.Engine\Hotkeys\HotkeyModel.cs" Link="Engine\HotkeyModel.cs" />
|
||||
<Compile Include="..\..\src\RynthCore.Engine\Compatibility\AcKeymapText.cs" Link="Engine\AcKeymapText.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
296
tools/KeymapTests/Program.cs
Normal file
296
tools/KeymapTests/Program.cs
Normal file
|
|
@ -0,0 +1,296 @@
|
|||
// Offline checks for AcKeymapText (see KeymapTests.csproj).
|
||||
using RynthCore.Engine.Compatibility;
|
||||
using RynthCore.Engine.Hotkeys;
|
||||
|
||||
namespace KeymapTests;
|
||||
|
||||
internal static class Program
|
||||
{
|
||||
private static int _failed, _passed;
|
||||
|
||||
private static void Check(bool ok, string what)
|
||||
{
|
||||
if (ok) { _passed++; return; }
|
||||
_failed++;
|
||||
Console.WriteLine("FAIL: " + what);
|
||||
}
|
||||
|
||||
private static void Eq<T>(T actual, T expected, string what) =>
|
||||
Check(EqualityComparer<T>.Default.Equals(actual, expected), $"{what}: got '{actual}', expected '{expected}'");
|
||||
|
||||
// The shape AC writes (CRLF, two-space groups, four-space bindings), cut down.
|
||||
private static readonly string Sample = string.Join("\r\n", new[]
|
||||
{
|
||||
"#Asheron's Call: Throne of Destiny Keymap File",
|
||||
"\"User Defined Keymap\" [ 0000003B-02D0-0000-4002-000016000000 ]",
|
||||
"",
|
||||
"Devices",
|
||||
"[",
|
||||
" Keyboard [ GUID_SysKeyboard ]",
|
||||
" Mouse [ GUID_SysMouse ]",
|
||||
"]",
|
||||
"",
|
||||
"MetaKeys",
|
||||
"[",
|
||||
" 1 [ 0 DIK_LSHIFT ]",
|
||||
" 2 [ 0 DIK_LCONTROL ]",
|
||||
" 2 [ 0 DIK_RCONTROL ]",
|
||||
" 3 [ 0 DIK_LMENU ]",
|
||||
" 3 [ 0 DIK_RALT ]",
|
||||
" 5 [ 1 DIMOFS_BUTTON3 ]",
|
||||
"]",
|
||||
"",
|
||||
"Bindings",
|
||||
"[",
|
||||
" MovementCommands",
|
||||
" [",
|
||||
" MovementForward [ \"\" [ 0 DIK_W ] ]",
|
||||
" MovementForward [ \"\" [ 0 DIK_UPARROW ] ]",
|
||||
" ]",
|
||||
"",
|
||||
" UICommands",
|
||||
" [",
|
||||
" ToggleSpellbookPanel [ \"\" [ 0 DIK_F5 ] ]",
|
||||
" ToggleOptionsPanel [ \"\" [ 0 DIK_F11 ] ]",
|
||||
" TogglePluginManager [ \"\" [ 0 DIK_F1 ] 0x00000003 ]",
|
||||
" ]",
|
||||
"",
|
||||
" QuickslotCommands",
|
||||
" [",
|
||||
" UseQuickSlot_1 [ \"\" [ 0 DIK_1 ] ]",
|
||||
" UseQuickSlot_5 [ \"\" [ 0 DIK_5 ] ]",
|
||||
" UseQuickSlot_14 [ \"\" [ 0 DIK_5 ] 0x00000004 ]",
|
||||
" CreateShortcut [ \"\" [ 0 DIK_0 ] ]",
|
||||
" UseQuickSlot_1 [ \"\" [ 0 DIK_1 ] 0x00000002 ]",
|
||||
" ]",
|
||||
"",
|
||||
" ToggleChatEntry",
|
||||
"",
|
||||
" MouseCommands",
|
||||
" [",
|
||||
" SelectLeft [ \"\" [ 1 DIMOFS_BUTTON0 ] ]",
|
||||
" ]",
|
||||
"",
|
||||
" EditControls",
|
||||
" [",
|
||||
" CursorStartOfLine [ \"\" [ 0 DIK_HOME ] ]",
|
||||
" CursorPreviousPage [ \"\" [ 0 DIK_PGUP ] ]",
|
||||
" ]",
|
||||
"",
|
||||
" CopyAndPasteControls",
|
||||
" [",
|
||||
" CopyText [ \"\" [ 0 DIK_C ] 0x00000002 ]",
|
||||
" ]",
|
||||
"]",
|
||||
"",
|
||||
});
|
||||
|
||||
private static List<string> Lines(string text = "") => AcKeymapText.Split(text.Length > 0 ? text : Sample, out _);
|
||||
|
||||
private static List<AcKeymapText.Line> Of(List<string> lines, string action) =>
|
||||
AcKeymapText.Bindings(lines).FindAll(l => l.Action == action);
|
||||
|
||||
private static int Main()
|
||||
{
|
||||
Reading();
|
||||
Names();
|
||||
Meta();
|
||||
BindTakes();
|
||||
BindKeepsTextGroups();
|
||||
BindAlready();
|
||||
BindNewSlot();
|
||||
BindMissingGroup();
|
||||
BindEmptyGroup();
|
||||
BindUnknownAction();
|
||||
Unbind();
|
||||
RoundTrip();
|
||||
Describe();
|
||||
RealFile();
|
||||
Console.WriteLine($"{_passed} passed, {_failed} failed.");
|
||||
return _failed == 0 ? 0 : 1;
|
||||
}
|
||||
|
||||
private static void Reading()
|
||||
{
|
||||
List<string> lines = Lines();
|
||||
List<AcKeymapText.Line> all = AcKeymapText.Bindings(lines);
|
||||
Eq(all.Count, 14, "binding lines read");
|
||||
List<AcKeymapText.Line> slot1 = Of(lines, "UseQuickSlot_1");
|
||||
Eq(slot1.Count, 2, "UseQuickSlot_1 lines");
|
||||
Check(slot1.TrueForAll(l => l.Group == "QuickslotCommands"), "UseQuickSlot_1 in QuickslotCommands");
|
||||
Eq(slot1[1].Meta, 2u, "Ctrl+1's mask");
|
||||
Eq(Of(lines, "MovementForward")[1].Dik, "DIK_UPARROW", "an alias read as its one name");
|
||||
Eq(Of(lines, "SelectLeft")[0].Device, 1, "the mouse is device 1");
|
||||
Eq(Of(lines, "CursorPreviousPage")[0].Group, "EditControls", "group after an empty group");
|
||||
Eq(AcKeymapText.Uses(lines, 0, "DIK_F5", 0).Count, 1, "F5 used once");
|
||||
Eq(AcKeymapText.Uses(lines, 0, "DIK_HOME", 0).Count, 0, "Home in a text group isn't a game use");
|
||||
Eq(AcKeymapText.Uses(lines, 0, "DIK_5", 4).Count, 1, "Alt+5 used");
|
||||
}
|
||||
|
||||
private static void Names()
|
||||
{
|
||||
Eq(AcKeymapText.DikForVk('A'), "DIK_A", "A");
|
||||
Eq(AcKeymapText.DikForVk('7'), "DIK_7", "7");
|
||||
Eq(AcKeymapText.DikForVk(0x7A), "DIK_F11", "F11");
|
||||
Eq(AcKeymapText.DikForVk(0x7E), "DIK_F15", "F15");
|
||||
Eq(AcKeymapText.DikForVk(0x7F), (string?)null, "F16: AC has none");
|
||||
Eq(AcKeymapText.DikForVk(0x21), "DIK_PGUP", "PageUp as AC writes it");
|
||||
Eq(AcKeymapText.DikForVk(0x26), "DIK_UPARROW", "Up as AC writes it");
|
||||
Eq(AcKeymapText.DikForVk(0x65), "DIK_NUMPAD5", "Num5");
|
||||
Eq(AcKeymapText.DikForVk(0x6A), "DIK_NUMPADSTAR", "Num*");
|
||||
Eq(AcKeymapText.DikForVk(0xC0), "DIK_GRAVE", "`");
|
||||
Eq(AcKeymapText.Canonical("dik_prior"), "DIK_PGUP", "PRIOR is PGUP");
|
||||
Eq(AcKeymapText.Canonical("DIK_UP"), "DIK_UPARROW", "UP is UPARROW");
|
||||
Eq(AcKeymapText.Canonical("DIK_LEFTARROW"), "DIK_LEFT", "LEFTARROW is LEFT");
|
||||
Eq(AcKeymapText.Canonical("DIK_F3"), "DIK_F3", "a plain name");
|
||||
}
|
||||
|
||||
private static void Meta()
|
||||
{
|
||||
List<string> lines = Lines();
|
||||
Check(AcKeymapText.TryMeta(lines, HotkeyMods.None, out uint m0, out _) && m0 == 0, "no modifiers: 0");
|
||||
Check(AcKeymapText.TryMeta(lines, HotkeyMods.Ctrl, out uint m1, out _) && m1 == 2, "Ctrl: 0x2");
|
||||
Check(AcKeymapText.TryMeta(lines, HotkeyMods.Alt, out uint m2, out _) && m2 == 4, "Alt: 0x4 (metakey 3)");
|
||||
Check(AcKeymapText.TryMeta(lines, HotkeyMods.Ctrl | HotkeyMods.Shift, out uint m3, out _) && m3 == 3, "Ctrl+Shift: 0x3");
|
||||
List<string> noAlt = Lines(Sample.Replace(" 3 [ 0 DIK_LMENU ]\r\n", "").Replace(" 3 [ 0 DIK_RALT ]\r\n", ""));
|
||||
Check(!AcKeymapText.TryMeta(noAlt, HotkeyMods.Alt, out _, out string err) && err.Contains("Alt"), "no Alt metakey: an error naming it");
|
||||
}
|
||||
|
||||
private static void BindTakes()
|
||||
{
|
||||
List<string> lines = Lines();
|
||||
Check(AcKeymapText.Bind(lines, "UseQuickSlot_10", 0, "DIK_F11", 0, out var taken, out _), "bind slot 10 to F11");
|
||||
Eq(taken.Count, 1, "one action had F11");
|
||||
Eq(taken.Count > 0 ? taken[0].Action : "", "ToggleOptionsPanel", "taken from Options");
|
||||
Eq(Of(lines, "ToggleOptionsPanel").Count, 0, "Options lost F11");
|
||||
List<AcKeymapText.Line> s10 = Of(lines, "UseQuickSlot_10");
|
||||
Check(s10.Count == 1 && s10[0].Group == "QuickslotCommands" && s10[0].Dik == "DIK_F11" && s10[0].Meta == 0, "slot 10 has F11 in QuickslotCommands");
|
||||
Check(s10.Count == 1 && lines[s10[0].Index] == " UseQuickSlot_10 [ \"\" [ 0 DIK_F11 ] ]", "written as AC writes it: " + (s10.Count == 1 ? lines[s10[0].Index] : ""));
|
||||
// Taking Ctrl+1 for slot 2: only the Ctrl one goes.
|
||||
Check(AcKeymapText.Bind(lines, "UseQuickSlot_2", 0, "DIK_1", 2, out taken, out _), "bind slot 2 to Ctrl+1");
|
||||
Check(taken.Count == 1 && taken[0].Action == "UseQuickSlot_1" && taken[0].Meta == 2, "Ctrl+1 taken from slot 1");
|
||||
List<AcKeymapText.Line> s1 = Of(lines, "UseQuickSlot_1");
|
||||
Check(s1.Count == 1 && s1[0].Meta == 0, "slot 1 keeps plain 1");
|
||||
List<AcKeymapText.Line> s2 = Of(lines, "UseQuickSlot_2");
|
||||
Check(s2.Count == 1 && lines[s2[0].Index].EndsWith("[ 0 DIK_1 ] 0x00000002 ]"), "slot 2 has Ctrl+1");
|
||||
// An alias in the file is the same key: PRIOR takes PGUP's other game use, not EditControls'.
|
||||
Check(AcKeymapText.Bind(lines, "UseQuickSlot_3", 0, "DIK_PRIOR", 0, out taken, out _) && taken.Count == 0, "PgUp: only a text group has it");
|
||||
Eq(Of(lines, "CursorPreviousPage").Count, 1, "the chat box keeps PgUp");
|
||||
}
|
||||
|
||||
private static void BindKeepsTextGroups()
|
||||
{
|
||||
List<string> lines = Lines();
|
||||
Check(AcKeymapText.Bind(lines, "UseQuickSlot_4", 0, "DIK_C", 2, out var taken, out _), "bind slot 4 to Ctrl+C");
|
||||
Eq(taken.Count, 0, "Ctrl+C isn't taken from copy");
|
||||
Eq(Of(lines, "CopyText").Count, 1, "copy keeps Ctrl+C");
|
||||
Check(AcKeymapText.Bind(lines, "UseQuickSlot_6", 0, "DIK_HOME", 0, out _, out _), "bind slot 6 to Home");
|
||||
Eq(Of(lines, "CursorStartOfLine").Count, 1, "the chat box keeps Home");
|
||||
}
|
||||
|
||||
private static void BindAlready()
|
||||
{
|
||||
List<string> lines = Lines();
|
||||
int before = lines.Count;
|
||||
Check(AcKeymapText.Bind(lines, "UseQuickSlot_5", 0, "DIK_5", 0, out var taken, out _) && taken.Count == 0, "slot 5 already has 5");
|
||||
Eq(lines.Count, before, "nothing added");
|
||||
Eq(Of(lines, "UseQuickSlot_5").Count, 1, "still one line");
|
||||
}
|
||||
|
||||
private static void BindNewSlot()
|
||||
{
|
||||
List<string> lines = Lines();
|
||||
Check(AcKeymapText.Bind(lines, "UseQuickSlot_12", 0, "DIK_F12", 0, out _, out _), "slot 12, no line yet");
|
||||
List<AcKeymapText.Line> s = Of(lines, "UseQuickSlot_12");
|
||||
Check(s.Count == 1 && s[0].Group == "QuickslotCommands", "goes in QuickslotCommands");
|
||||
// At the end of the group, before its ']'.
|
||||
Check(s.Count == 1 && lines[s[0].Index + 1].Trim() == "]", "at the group's end");
|
||||
// A second key goes right after the slot's own line.
|
||||
Check(AcKeymapText.Bind(lines, "UseQuickSlot_12", 0, "DIK_F12", 1, out _, out _), "slot 12, Shift+F12 too");
|
||||
s = Of(lines, "UseQuickSlot_12");
|
||||
Check(s.Count == 2 && s[1].Index == s[0].Index + 1, "next to the first");
|
||||
}
|
||||
|
||||
private static void BindMissingGroup()
|
||||
{
|
||||
string text = Sample.Replace(" QuickslotCommands\r\n [\r\n", " OldSlots\r\n [\r\n");
|
||||
List<string> lines = Lines(text);
|
||||
// The slot's existing lines are in OldSlots: a new key goes beside them.
|
||||
Check(AcKeymapText.Bind(lines, "UseQuickSlot_1", 0, "DIK_F3", 0, out _, out _), "slot 1 beside its lines");
|
||||
Check(Of(lines, "UseQuickSlot_1").TrueForAll(l => l.Group == "OldSlots"), "stays in its group");
|
||||
// A slot with no line and no QuickslotCommands: the group is made at the end of Bindings.
|
||||
Check(AcKeymapText.Bind(lines, "UseQuickSlot_9", 0, "DIK_9", 0, out _, out _), "slot 9, no group");
|
||||
List<AcKeymapText.Line> s9 = Of(lines, "UseQuickSlot_9");
|
||||
Check(s9.Count == 1 && s9[0].Group == "QuickslotCommands", "QuickslotCommands made");
|
||||
Eq(AcKeymapText.Bindings(lines).Count, 16, "every line still read");
|
||||
}
|
||||
|
||||
private static void BindEmptyGroup()
|
||||
{
|
||||
// ToggleChatEntry is a name with no [ ] block: a binding there gets one.
|
||||
string text = Sample.Replace(" QuickslotCommands", " QuickslotCommandsX").Replace(" ToggleChatEntry", " QuickslotCommands");
|
||||
List<string> lines = Lines(text);
|
||||
Check(AcKeymapText.Bind(lines, "UseQuickSlot_11", 0, "DIK_F2", 0, out _, out _), "bind into an empty group");
|
||||
List<AcKeymapText.Line> s = Of(lines, "UseQuickSlot_11");
|
||||
Check(s.Count == 1 && s[0].Group == "QuickslotCommands", "in the empty group, now with a block");
|
||||
Eq(Of(lines, "SelectLeft").Count, 1, "the next group still read");
|
||||
}
|
||||
|
||||
private static void BindUnknownAction()
|
||||
{
|
||||
List<string> lines = Lines();
|
||||
int before = lines.Count;
|
||||
Check(!AcKeymapText.Bind(lines, "SomeNewAction", 0, "DIK_F7", 0, out _, out string err) && err.Length > 0, "no group for an unknown action");
|
||||
Eq(lines.Count, before, "nothing changed");
|
||||
}
|
||||
|
||||
private static void Unbind()
|
||||
{
|
||||
List<string> lines = Lines();
|
||||
Check(AcKeymapText.Unbind(lines, "UseQuickSlot_1", 0, "DIK_1", 2), "Ctrl+1 off slot 1");
|
||||
List<AcKeymapText.Line> s1 = Of(lines, "UseQuickSlot_1");
|
||||
Check(s1.Count == 1 && s1[0].Meta == 0, "plain 1 stays");
|
||||
Check(!AcKeymapText.Unbind(lines, "UseQuickSlot_1", 0, "DIK_1", 2), "again: nothing to remove");
|
||||
Check(AcKeymapText.Unbind(lines, "MovementForward", 0, "DIK_UP", 0), "by an alias");
|
||||
Eq(Of(lines, "MovementForward").Count, 1, "W stays");
|
||||
}
|
||||
|
||||
private static void RoundTrip()
|
||||
{
|
||||
List<string> lines = AcKeymapText.Split(Sample, out string nl);
|
||||
Eq(nl, "\r\n", "CRLF kept");
|
||||
Eq(AcKeymapText.Join(lines, nl), Sample, "split and join give the same text");
|
||||
List<string> lf = AcKeymapText.Split(Sample.Replace("\r\n", "\n"), out string nl2);
|
||||
Eq(nl2, "\n", "LF kept");
|
||||
Eq(lf.Count, lines.Count, "same lines either way");
|
||||
Eq(AcKeymapText.Format("UseQuickSlot_1", 0, "DIK_1", 2), "UseQuickSlot_1 [ \"\" [ 0 DIK_1 ] 0x00000002 ]", "a line with a mask");
|
||||
Eq(AcKeymapText.Format("UseQuickSlot_1", 0, "DIK_1", 0), "UseQuickSlot_1 [ \"\" [ 0 DIK_1 ] ]", "a line without");
|
||||
}
|
||||
|
||||
private static void Describe()
|
||||
{
|
||||
Eq(AcKeymapText.Describe("UseQuickSlot_5"), "shortcut slot 5", "a slot");
|
||||
Eq(AcKeymapText.Describe("ToggleSpellbookPanel"), "Toggle Spellbook Panel", "camel case");
|
||||
Eq(AcKeymapText.Describe("AltF4"), "Alt F4", "a key name");
|
||||
Eq(AcKeymapText.Describe("LOGOUT"), "LOGOUT", "all capitals");
|
||||
}
|
||||
|
||||
private static void RealFile()
|
||||
{
|
||||
string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Asheron's Call", "Normal.keymap");
|
||||
if (!File.Exists(path)) { Console.WriteLine("(no Normal.keymap here: the real-file case is skipped)"); return; }
|
||||
string text = File.ReadAllText(path);
|
||||
List<string> lines = AcKeymapText.Split(text, out string nl);
|
||||
Eq(AcKeymapText.Join(lines, nl), text, "the real file round trips");
|
||||
int count = AcKeymapText.Bindings(lines).Count;
|
||||
Check(count > 50, $"the real file's bindings read ({count})");
|
||||
Check(Of(lines, "UseQuickSlot_1").Count >= 1, "the real file has slot 1");
|
||||
Check(AcKeymapText.TryMeta(lines, HotkeyMods.Ctrl, out uint ctrl, out _) && ctrl != 0, "the real file has Ctrl");
|
||||
// In memory only: slot 10 to F11 takes it from whatever has it, and every other line is still read.
|
||||
int had = AcKeymapText.Uses(lines, 0, "DIK_F11", 0).Count;
|
||||
Check(AcKeymapText.Bind(lines, "UseQuickSlot_10", 0, "DIK_F11", 0, out var taken, out _), "real file: bind slot 10 to F11");
|
||||
Eq(taken.Count, had, "real file: F11 taken from all its game uses");
|
||||
Eq(AcKeymapText.Bindings(lines).Count, count - had + 1, "real file: one line in, the taken ones out");
|
||||
Eq(AcKeymapText.Uses(lines, 0, "DIK_F11", 0).Count, 1, "real file: F11 does one thing now");
|
||||
}
|
||||
}
|
||||
|
|
@ -601,11 +601,12 @@ internal static class Program
|
|||
Eq((int)Marshal.OffsetOf<RynthCore.PluginSdk.TrainingEntryNative>(f.Name), (int)Marshal.OffsetOf<RynthCore.Engine.Plugins.TrainingEntryNative>(f.Name), "TrainingEntryNative." + f.Name + " offset");
|
||||
Eq(RynthCore.PluginSdk.TrainingInfoFlags.Busy, RynthCore.Engine.Plugins.TrainingInfoFlags.Busy, "info flag bits");
|
||||
Eq(RynthCore.PluginSdk.TrainingEntryFlags.Trainable, RynthCore.Engine.Plugins.TrainingEntryFlags.Trainable, "entry flag bits");
|
||||
// The three v79 slots follow v78's, then v80's two and v81's GetMergeStackResultFn (v82-v89 follow).
|
||||
var names = typeof(RynthCore.Engine.Plugins.RynthCoreAPI).GetFields().Select(f => f.Name).SkipLast(11).TakeLast(6).ToArray();
|
||||
// The three v79 slots follow v78's, then v80's two and v81's GetMergeStackResultFn (v82-v90 follow:
|
||||
// eleven slots to v89, then v90's thirteen).
|
||||
var names = typeof(RynthCore.Engine.Plugins.RynthCoreAPI).GetFields().Select(f => f.Name).SkipLast(24).TakeLast(6).ToArray();
|
||||
Check(names.SequenceEqual(new[] { "GetTrainingInfoFn", "RaiseFn", "TrainSkillFn", "GetContainerOrderFn", "PutItemInContainerFn", "GetMergeStackResultFn" }),
|
||||
"v79, v80 then v81 slots last: " + string.Join(",", names));
|
||||
var sdkNames = typeof(RynthCore.PluginSdk.RynthCoreApiNative).GetFields().Select(f => f.Name).SkipLast(11).TakeLast(6).ToArray();
|
||||
var sdkNames = typeof(RynthCore.PluginSdk.RynthCoreApiNative).GetFields().Select(f => f.Name).SkipLast(24).TakeLast(6).ToArray();
|
||||
Check(sdkNames.SequenceEqual(names), "SDK v79, v80 and v81 slots in the same order");
|
||||
}
|
||||
|
||||
|
|
@ -614,8 +615,21 @@ internal static class Program
|
|||
// order on both sides, and the same size.
|
||||
private static void ContainerOrderSlots()
|
||||
{
|
||||
var names = typeof(RynthCore.Engine.Plugins.RynthCoreAPI).GetFields().Select(f => f.Name).ToArray();
|
||||
var sdkNames = typeof(RynthCore.PluginSdk.RynthCoreApiNative).GetFields().Select(f => f.Name).ToArray();
|
||||
var all = typeof(RynthCore.Engine.Plugins.RynthCoreAPI).GetFields().Select(f => f.Name).ToArray();
|
||||
var sdkAll = typeof(RynthCore.PluginSdk.RynthCoreApiNative).GetFields().Select(f => f.Name).ToArray();
|
||||
// v90: the frameless-window slots and the settings drawers end the table; the checks after these
|
||||
// are on the table before them.
|
||||
string[] v90 = { "PanelDragWithLastItemFn", "SetPanelPopOutFn", "PanelTextSizeFn", "RenderSettingsDrawerFn",
|
||||
"GetShortcutsFn", "ShortcutActionFn", "GetActionKeysFn", "GetIconTextureFn", "KeyCaptureFn", "SetActionKeyFn", "AcPanelFn", "PanelScaleFn", "DropTargetFn" };
|
||||
Check(all.TakeLast(v90.Length).SequenceEqual(v90), "v90 slots last: " + string.Join(",", all.TakeLast(v90.Length)));
|
||||
Check(sdkAll.TakeLast(v90.Length).SequenceEqual(v90), "SDK v90 slots last: " + string.Join(",", sdkAll.TakeLast(v90.Length)));
|
||||
foreach (string slot in v90)
|
||||
Eq((int)Marshal.OffsetOf<RynthCore.PluginSdk.RynthCoreApiNative>(slot),
|
||||
(int)Marshal.OffsetOf<RynthCore.Engine.Plugins.RynthCoreAPI>(slot), slot + " offset");
|
||||
Eq((int)Marshal.OffsetOf<RynthCore.Engine.Plugins.RynthCoreAPI>("PanelDragWithLastItemFn"),
|
||||
(int)Marshal.OffsetOf<RynthCore.Engine.Plugins.RynthCoreAPI>("SetPanelOpenFn") + IntPtr.Size, "PanelDragWithLastItemFn right after SetPanelOpenFn");
|
||||
var names = all.SkipLast(v90.Length).ToArray();
|
||||
var sdkNames = sdkAll.SkipLast(v90.Length).ToArray();
|
||||
// v81's GetMergeStackResultFn follows v80's two slots.
|
||||
Check(names.SkipLast(12).TakeLast(2).SequenceEqual(new[] { "GetContainerOrderFn", "PutItemInContainerFn" }), "v80 slots before v81's to v85's: " + string.Join(",", names.SkipLast(12).TakeLast(2)));
|
||||
Check(sdkNames.SkipLast(12).TakeLast(2).SequenceEqual(names.SkipLast(12).TakeLast(2)), "SDK v80 slots in the same order");
|
||||
|
|
@ -630,8 +644,8 @@ internal static class Program
|
|||
Check(names.SkipLast(4).Last() == "GetServerStateJsonFn", "v86 slot before v87's: " + names.SkipLast(4).Last());
|
||||
// v87: GetWieldedItems (what the player wields, from the server's messages), then v89's three.
|
||||
Check(names.SkipLast(3).Last() == "GetWieldedItemsFn", "v87 slot before v89's: " + names.SkipLast(3).Last());
|
||||
// v89: plugin windows (the engine's look, panels by key) end the table.
|
||||
Check(names.TakeLast(3).SequenceEqual(new[] { "GetUiColorFn", "GetUiFontFn", "SetPanelOpenFn" }), "v89 slots last: " + string.Join(",", names.TakeLast(3)));
|
||||
// v89: plugin windows (the engine's look, panels by key) end the table before v90's.
|
||||
Check(names.TakeLast(3).SequenceEqual(new[] { "GetUiColorFn", "GetUiFontFn", "SetPanelOpenFn" }), "v89 slots before v90's: " + string.Join(",", names.TakeLast(3)));
|
||||
Check(typeof(RynthCore.PluginSdk.RynthCoreApiNative).GetFields().Select(f => f.Name).SequenceEqual(typeof(RynthCore.Engine.Plugins.RynthCoreAPI).GetFields().Select(f => f.Name)), "SDK table has the engine's slots in the same order");
|
||||
Eq(Marshal.SizeOf<RynthCore.PluginSdk.RynthCoreApiNative>(), Marshal.SizeOf<RynthCore.Engine.Plugins.RynthCoreAPI>(), "SDK table size = engine table size");
|
||||
Eq((int)Marshal.OffsetOf<RynthCore.PluginSdk.RynthCoreApiNative>("PutItemInContainerFn"),
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ internal static class Program
|
|||
ManifestWindows();
|
||||
WindowPlanChoices();
|
||||
WindowTakeOver();
|
||||
WindowFrameless();
|
||||
StackCheckAfterPluginDraw();
|
||||
|
||||
Console.WriteLine();
|
||||
|
|
@ -559,6 +560,31 @@ internal static class Program
|
|||
Check(after.Count == 0 && taken2.Count == 0, "no manifest: nothing hosted, nothing taken over");
|
||||
}
|
||||
|
||||
// v90: a window that draws its own frame ("chrome": "none") and fits its height to its content.
|
||||
private const string FramelessManifest = """
|
||||
{ "version": 1, "windows": [
|
||||
{ "id": "dashboard", "title": "RynthAi", "surface": "window:dashboard", "takeOver": true,
|
||||
"chrome": "none", "fitHeight": true, "width": 296, "height": 240, "minWidth": 280, "minHeight": 54 },
|
||||
{ "id": "plain", "title": "Notes", "surface": "window:notes" },
|
||||
{ "id": "odd", "title": "Odd", "surface": "window:odd", "chrome": " NONE ", "fitHeight": "yes" },
|
||||
{ "id": "framed", "title": "Framed", "surface": "window:framed", "chrome": "standard" } ] }
|
||||
""";
|
||||
|
||||
private static void WindowFrameless()
|
||||
{
|
||||
Case("plugin windows: frameless and fitted (v90)");
|
||||
SectionManifest m = SectionManifestParser.Parse("RynthAi", FramelessManifest, out string err);
|
||||
Check(err.Length == 0 && m.Windows.Length == 4, "parses: " + err);
|
||||
Check(m.Windows[0].Frameless && m.Windows[0].FitHeight && m.Windows[0].TakeOver, "\"chrome\": \"none\" and \"fitHeight\": true read");
|
||||
Check(!m.Windows[1].Frameless && !m.Windows[1].FitHeight, "absent: framed and sized by the player (as before)");
|
||||
Check(m.Windows[2].Frameless && !m.Windows[2].FitHeight, "\"none\" in any case, padded; fitHeight not a boolean: off");
|
||||
Check(!m.Windows[3].Frameless, "any other chrome: the engine's frame");
|
||||
Check(m.Windows[0].Width == 296 && m.Windows[0].MinWidth == 280, "sizes kept (the minimum height has the parser's floor)");
|
||||
Check(WindowPlan.Signature(m.Windows[0]) != WindowPlan.Signature(m.Windows[0] with { Frameless = false })
|
||||
&& WindowPlan.Signature(m.Windows[0]) != WindowPlan.Signature(m.Windows[0] with { FitHeight = false }),
|
||||
"chrome and fitHeight are in the signature (a change re-registers)");
|
||||
}
|
||||
|
||||
// ImGui 1.91.6's ImGuiErrorRecoveryState, in field order: windows, IDs, tree nodes, colours,
|
||||
// style vars, fonts, focus scopes, groups, item flags, popups, disabled. The base values are
|
||||
// the ones a 32-bit probe of our cimgui.dll read inside a panel's body child (2026-10-21).
|
||||
|
|
|
|||
188
tools/ThemeTests/Program.cs
Normal file
188
tools/ThemeTests/Program.cs
Normal file
|
|
@ -0,0 +1,188 @@
|
|||
// tools/ThemeTests: the colour theme's presets, the player's own colours and saved schemes
|
||||
// (RynthTheme.cs, ThemeSchemes.cs). Each case runs in its own process with RYNTHCORE_THEME_DIR
|
||||
// pointing at a fresh temp folder (the theme reads its files once per process).
|
||||
using System.Diagnostics;
|
||||
using RynthCore.Engine.ImGuiBackend;
|
||||
|
||||
namespace RynthCore.Engine.UI
|
||||
{
|
||||
/// <summary>Stub: the engine saves in the background; here at once, so a case can read the file back.</summary>
|
||||
internal static class UiBackgroundWriter
|
||||
{
|
||||
public static void Enqueue(string label, Action work) => work();
|
||||
}
|
||||
}
|
||||
|
||||
namespace RynthCore.Engine
|
||||
{
|
||||
internal static class RynthLog
|
||||
{
|
||||
public static void UI(string message) { }
|
||||
}
|
||||
}
|
||||
|
||||
namespace ThemeTests
|
||||
{
|
||||
internal static class Program
|
||||
{
|
||||
private const string Mine = "accent=112233\nhighlight=445566\nbackground=010203\ntitlebar=0A0B0C\nbutton=202122\nborder=303132\ntext=F0F1F2\nmuted=A0A1A2\n";
|
||||
private static readonly uint[] MineColours = { 0x112233, 0x445566, 0x010203, 0x0A0B0C, 0x202122, 0x303132, 0xF0F1F2, 0xA0A1A2 };
|
||||
|
||||
private static int _failures;
|
||||
|
||||
private static void Check(bool ok, string what)
|
||||
{
|
||||
Console.WriteLine((ok ? " ok " : " FAIL ") + what);
|
||||
if (!ok) _failures++;
|
||||
}
|
||||
|
||||
private static string Dir => Environment.GetEnvironmentVariable("RYNTHCORE_THEME_DIR")!;
|
||||
private static string ThemeFile => File.ReadAllText(Path.Combine(Dir, "theme.txt")).Replace("\r", "");
|
||||
private static string[] SchemeFiles => Directory.Exists(Path.Combine(Dir, "themes"))
|
||||
? Directory.GetFiles(Path.Combine(Dir, "themes"), "*.theme") : Array.Empty<string>();
|
||||
|
||||
private static bool IsMine()
|
||||
{
|
||||
for (int i = 0; i < 8; i++)
|
||||
if ((RynthTheme.GetPrimary(i) & 0xFFFFFF) != MineColours[i]) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private static int Brass => Array.IndexOf(ThemePalette.PresetNames, "Brass");
|
||||
|
||||
private static readonly (string Name, string? ThemeTxt, Action Run)[] Cases =
|
||||
{
|
||||
("an older Custom file loads as Custom with its colours", "preset=Custom\n" + Mine, () =>
|
||||
{
|
||||
Check(RynthTheme.Preset == RynthTheme.Custom, "Custom in use");
|
||||
Check(IsMine(), "the eight colours as saved");
|
||||
}),
|
||||
("picking a preset keeps the player's own colours, and Custom brings them back", "preset=Custom\n" + Mine, () =>
|
||||
{
|
||||
RynthTheme.SetPreset(Brass);
|
||||
Check(RynthTheme.Preset == Brass, "Brass in use");
|
||||
Check(!IsMine(), "Brass's colours on screen");
|
||||
string file = ThemeFile;
|
||||
Check(file.StartsWith("preset=Brass\n"), "theme.txt says Brass");
|
||||
Check(file.Contains("accent=112233") && file.Contains("muted=A0A1A2"), "theme.txt still has the player's eight");
|
||||
RynthTheme.SetPicker(RynthTheme.PickerNames().Length - 1); // Custom
|
||||
Check(RynthTheme.Preset == RynthTheme.Custom && IsMine(), "Custom: the player's colours again");
|
||||
}),
|
||||
("a preset file with the player's colours (written by this engine) restarts on the preset, Custom intact", "preset=Brass\n" + Mine, () =>
|
||||
{
|
||||
Check(RynthTheme.Preset == Brass, "Brass in use after a restart");
|
||||
RynthTheme.UseCustom();
|
||||
Check(IsMine(), "Custom: the player's colours");
|
||||
}),
|
||||
("Reset Colours (RynthCore's) keeps the player's colours too", "preset=Custom\n" + Mine, () =>
|
||||
{
|
||||
RynthTheme.SetPreset(0);
|
||||
Check(RynthTheme.Preset == 0, "RynthCore in use");
|
||||
Check(ThemeFile.Contains("accent=112233"), "the player's colours still in theme.txt");
|
||||
}),
|
||||
("no theme.txt: RynthCore's colours, nothing new written until a change", null, () =>
|
||||
{
|
||||
Check(RynthTheme.Preset == 0, "RynthCore (the default) in use");
|
||||
Check(!File.Exists(Path.Combine(Dir, "theme.txt")), "no theme.txt written");
|
||||
}),
|
||||
("a preset-only file (an older engine's) writes no colours of its own", "preset=Ember\n", () =>
|
||||
{
|
||||
RynthTheme.SetPreset(Brass);
|
||||
Check(ThemeFile == "preset=Brass\n", "only the preset line: " + ThemeFile.Replace("\n", " | "));
|
||||
}),
|
||||
("Save colours as: a scheme file, in the picker, in use, and back after a restart (part 1)", "preset=Custom\n" + Mine, () =>
|
||||
{
|
||||
Check(RynthTheme.SaveScheme(" Night watch ") == "Night watch", "saved as \"Night watch\" (trimmed)");
|
||||
Check(SchemeFiles.Length == 1, "one scheme file");
|
||||
Check(RynthTheme.PickerNames().Contains("Night watch"), "listed in the Theme picker");
|
||||
Check(RynthTheme.SchemeInUse && RynthTheme.SchemeName == "Night watch", "the scheme is in use");
|
||||
Check(ThemeFile.StartsWith("preset=scheme:Night watch\n"), "theme.txt names the scheme");
|
||||
int idx = RynthTheme.PickerIndex;
|
||||
Check(RynthTheme.PickerNames()[idx] == "Night watch", "the picker shows it selected");
|
||||
}),
|
||||
("a scheme picked from the picker shows its colours; a scheme that is gone falls back to Custom", "preset=Custom\n" + Mine, () =>
|
||||
{
|
||||
RynthTheme.SaveScheme("Copy");
|
||||
RynthTheme.SetPreset(Brass);
|
||||
int i = Array.IndexOf(RynthTheme.PickerNames(), "Copy");
|
||||
RynthTheme.SetPicker(i);
|
||||
Check(RynthTheme.SchemeInUse && IsMine(), "\"Copy\" in use with its colours");
|
||||
Check(!RynthTheme.UseScheme("No such scheme"), "an unknown name is refused");
|
||||
}),
|
||||
("names: a preset's or Custom get My in front; empty is refused; 40 characters at most", null, () =>
|
||||
{
|
||||
Check(ThemeSchemes.CleanName("Brass") == "My Brass", "Brass -> My Brass");
|
||||
Check(ThemeSchemes.CleanName("custom") == "My custom", "custom -> My custom");
|
||||
Check(ThemeSchemes.CleanName(" ") == "", "blank refused");
|
||||
Check(ThemeSchemes.CleanName(new string('x', 60)).Length == 40, "60 characters cut to 40");
|
||||
Check(RynthTheme.SaveScheme("") == "", "Save with no name does nothing");
|
||||
}),
|
||||
("the same name replaces the scheme; Delete removes the one in use and keeps its colours as Custom", "preset=Custom\n" + Mine, () =>
|
||||
{
|
||||
RynthTheme.SaveScheme("Mine");
|
||||
RynthTheme.SaveScheme("mine");
|
||||
Check(SchemeFiles.Length == 1, "still one file after saving the same name again");
|
||||
Check(RynthTheme.DeleteCurrentScheme(), "deleted");
|
||||
Check(SchemeFiles.Length == 0, "the file is gone");
|
||||
Check(RynthTheme.Preset == RynthTheme.Custom && IsMine(), "Custom with the same colours");
|
||||
Check(!RynthTheme.PickerNames().Contains("Mine"), "not in the picker any more");
|
||||
}),
|
||||
("changing a colour on a preset first keeps the player's own colours as \"My colours\"", "preset=Brass\n" + Mine, () =>
|
||||
{
|
||||
RynthTheme.SetPrimary(0, 0xFF00FF00);
|
||||
Check(RynthTheme.Preset == RynthTheme.Custom, "Custom after the change");
|
||||
Check(RynthTheme.PickerNames().Contains("My colours"), "\"My colours\" saved");
|
||||
int i = Array.IndexOf(RynthTheme.PickerNames(), "My colours");
|
||||
RynthTheme.SetPicker(i);
|
||||
Check(IsMine(), "\"My colours\" holds the colours from before");
|
||||
RynthTheme.UseCustom();
|
||||
Check((RynthTheme.GetPrimary(0) & 0xFFFFFF) == 0x00FF00, "Custom holds the change (Brass + green accent)");
|
||||
}),
|
||||
("no second \"My colours\" when they are already kept", "preset=Brass\n" + Mine, () =>
|
||||
{
|
||||
RynthTheme.UseCustom();
|
||||
RynthTheme.SaveScheme("Already"); // the player's own colours, kept by name
|
||||
RynthTheme.SetPreset(Brass);
|
||||
RynthTheme.SetPrimary(0, 0xFF00FF00);
|
||||
Check(!RynthTheme.PickerNames().Contains("My colours"), "nothing new: \"Already\" has them");
|
||||
}),
|
||||
("changing a colour while on Custom saves nothing extra", "preset=Custom\n" + Mine, () =>
|
||||
{
|
||||
RynthTheme.SetPrimary(1, 0xFFFF0000);
|
||||
Check(SchemeFiles.Length == 0, "no scheme files");
|
||||
Check(ThemeFile.Contains("highlight=FF0000"), "theme.txt has the change");
|
||||
}),
|
||||
};
|
||||
|
||||
private static int Main(string[] args)
|
||||
{
|
||||
if (args.Length == 2 && args[0] == "--case")
|
||||
{
|
||||
Cases[int.Parse(args[1])].Run();
|
||||
return _failures == 0 ? 0 : 1;
|
||||
}
|
||||
|
||||
string exe = Environment.ProcessPath!;
|
||||
string root = Path.Combine(Path.GetTempPath(), "rynth-themetests-" + Environment.ProcessId);
|
||||
int failed = 0;
|
||||
for (int i = 0; i < Cases.Length; i++)
|
||||
{
|
||||
string dir = Path.Combine(root, i.ToString());
|
||||
Directory.CreateDirectory(dir);
|
||||
if (Cases[i].ThemeTxt != null) File.WriteAllText(Path.Combine(dir, "theme.txt"), Cases[i].ThemeTxt);
|
||||
var psi = new ProcessStartInfo(exe, $"--case {i}") { RedirectStandardOutput = true, UseShellExecute = false };
|
||||
psi.Environment["RYNTHCORE_THEME_DIR"] = dir;
|
||||
using var p = Process.Start(psi)!;
|
||||
string output = p.StandardOutput.ReadToEnd();
|
||||
p.WaitForExit();
|
||||
Console.WriteLine($"-- {Cases[i].Name}");
|
||||
Console.Write(output);
|
||||
if (p.ExitCode != 0) failed++;
|
||||
}
|
||||
try { Directory.Delete(root, true); } catch { }
|
||||
Console.WriteLine();
|
||||
Console.WriteLine(failed == 0 ? $"PASS ({Cases.Length} cases)" : $"FAIL ({failed} of {Cases.Length} cases)");
|
||||
return failed == 0 ? 0 : 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
32
tools/ThemeTests/ThemeTests.csproj
Normal file
32
tools/ThemeTests/ThemeTests.csproj
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<!--
|
||||
Offline checks for the colour theme (Tom 2026-10-22: a new preset must never override the
|
||||
colours a player made, and players can save their own schemes).
|
||||
src\RynthCore.Engine\ImGui\RynthTheme.cs and ThemeSchemes.cs, compiled in, with stub
|
||||
UiBackgroundWriter (runs the save at once) and RynthLog. The theme reads its files once per
|
||||
process, so each case runs in a child process pointed at its own temp folder with
|
||||
RYNTHCORE_THEME_DIR. Never touches %AppData%\RynthCore.
|
||||
Run: dotnet run -c Release (exit 0 = pass, 1 = fail)
|
||||
-->
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<InvariantGlobalization>true</InvariantGlobalization>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<RootNamespace>ThemeTests</RootNamespace>
|
||||
<NoWarn>$(NoWarn);CS0162;CS0414</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="ImGui.NET" Version="1.91.6.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="..\..\src\RynthCore.Engine\ImGui\RynthTheme.cs" Link="Engine\RynthTheme.cs" />
|
||||
<Compile Include="..\..\src\RynthCore.Engine\ImGui\ThemeSchemes.cs" Link="Engine\ThemeSchemes.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Loading…
Reference in a new issue