mirror of
https://git.triforceproject.com/triforce/source
synced 2026-11-21 09:09:58 -04:00
Triforce v0.6.0 "Sage Of Power"
Faster frames (the replay's memory work, held submits, helper threads, collection and capture cuts), the game letting old areas go (QueryMemoryInfo), the 0.5.2 stutter fixed, AMD RX 5000/6000 and integrated-GPU fixes, the GPU device chosen by name, the in-game menus and launcher reworked, controller, Linux and benchmark fixes.
This commit is contained in:
@@ -11,6 +11,12 @@ static partial class Tests
|
||||
(string, Func<Task>) Sync(string n, Action a) => (n, () => { a(); return Task.CompletedTask; });
|
||||
yield return Sync("settings: registry.txt round trip", SettingsTestRoot);
|
||||
yield return Sync("settings: builder.ini round trip (Linux store)", SettingsIni);
|
||||
yield return Sync("linux: the user folder follows the saves (triforce/user, then hookshot, then the game's)", LinuxUserFolder);
|
||||
yield return Sync("benchmark: an uneven run gets Steady frame rate Refresh steps, an even one keeps the player's", BenchSteady);
|
||||
yield return Sync("benchmark: a place left out is read and said", BenchSkipped);
|
||||
yield return Sync("settings: color scheme, the page's 'color' read", ColorParse);
|
||||
yield return Sync("settings: color scheme kept and read back (registry.txt, builder.ini, old files)", ColorKept);
|
||||
yield return Sync("settings: color scheme, the launcher's color (--snapshot, commands out of order)", ColorChoice);
|
||||
yield return Sync("startup: argument parsing", StartArgsParsing);
|
||||
yield return Sync("startup: lock name algorithm", LockName);
|
||||
yield return Sync("startup: installed run, old exe removed, second start defers", StartupInstalled);
|
||||
@@ -43,6 +49,8 @@ static partial class Tests
|
||||
yield return Sync("steam: add, set, remove in a fake Steam folder", SteamShortcut);
|
||||
yield return Sync("report: names out", ReportNames);
|
||||
yield return Sync("languages", LanguagesTest);
|
||||
yield return Sync("media: the game's music loop through decode, mix and WAV (smpl)", MusicLoop);
|
||||
yield return Sync("media: the WAV cache made again with the loop, an older file replaced", MusicCache);
|
||||
}
|
||||
|
||||
// ---- settings ----
|
||||
@@ -77,6 +85,48 @@ static partial class Tests
|
||||
Equal(null, Ctx(root).Settings.Language, "NoWrites writes nothing");
|
||||
}
|
||||
|
||||
static void BenchSkipped()
|
||||
{
|
||||
var root = NewRoot("benchskip");
|
||||
var f = Path.Combine(root, "results.json");
|
||||
File.WriteAllText(f, "{\"version\":1,\"stopped\":false,\"scenes\":[{\"name\":\"Hyrule Field\",\"avg\":60,\"low1\":50,\"frametimes_ms\":[16.6]}],\"skipped\":[\"Lake Hylia\"],\"settings\":{}}");
|
||||
var run = Benchmark.ReadResults(f, TimeSpan.FromSeconds(1));
|
||||
Equal(1, run.Scenes.Count, "the measured place");
|
||||
Equal("Lake Hylia", run.Skipped.Single(), "the place left out");
|
||||
Check(Benchmark.SkippedNote(run.Skipped).Contains("Lake Hylia was left out"), "the verdict's note");
|
||||
Equal("", Benchmark.SkippedNote(Array.Empty<string>()), "no note without one");
|
||||
File.WriteAllText(f, "{\"version\":1,\"stopped\":false,\"scenes\":[]}");
|
||||
Equal(0, Benchmark.ReadResults(f, TimeSpan.Zero).Skipped.Count, "an older game's results: none");
|
||||
}
|
||||
|
||||
static void BenchSteady()
|
||||
{
|
||||
var now = new Dictionary<string, int> { [Benchmark.KSteady] = 0 };
|
||||
var uneven = new[] { new PlaceResult("Hyrule Field", 45, 28), new PlaceResult("Kokiri Forest", 58, 55) };
|
||||
var r = Benchmark.Recommend(now, uneven, null, null, 60).Single(c => c.Key == Benchmark.KSteady);
|
||||
Equal(Benchmark.SteadyRefreshSteps, r.To, "lows under 80 % of the average: Refresh steps (36 fps on 60 Hz was uneven)");
|
||||
var even = new[] { new PlaceResult("Hyrule Field", 60, 58) };
|
||||
Equal(0, Benchmark.Recommend(now, even, null, null, 60).Single(c => c.Key == Benchmark.KSteady).To, "even: the player's own");
|
||||
}
|
||||
|
||||
static void LinuxUserFolder()
|
||||
{
|
||||
var root = NewRoot("linuxuser");
|
||||
var p = new LinuxPlatform(new Dictionary<string, string?> { ["TRIFORCE_TEST_ROOT"] = root });
|
||||
var game = Path.Combine(root, "game");
|
||||
var now = Path.Combine(p.DataHome, "triforce", "user");
|
||||
var old = Path.Combine(p.DataHome, "hookshot");
|
||||
Equal(now, p.UserFolder(game), "no saves anywhere: the new folder");
|
||||
Directory.CreateDirectory(Path.Combine(game, "user", "save", "1"));
|
||||
Equal(Path.Combine(game, "user"), p.UserFolder(game), "saves the game could not move out of its folder: there");
|
||||
Directory.CreateDirectory(Path.Combine(old, "save", "1"));
|
||||
Equal(old, p.UserFolder(game), "an older build's ~/.local/share/hookshot, not renamed yet: there");
|
||||
Equal(Path.Combine(old, "save", "abc"), p.SaveFolder(game, "abc"), "SaveFolder under it");
|
||||
Directory.CreateDirectory(Path.Combine(now, "save", "1"));
|
||||
Equal(now, p.UserFolder(game), "triforce/user once it has saves: first");
|
||||
Equal(Path.Combine(now, "save", "abc"), p.SaveFolder(game, "abc"), "SaveFolder under the new one");
|
||||
}
|
||||
|
||||
static void SettingsIni()
|
||||
{
|
||||
var root = NewRoot("ini");
|
||||
@@ -95,6 +145,119 @@ static partial class Tests
|
||||
Throws<ArgumentException>(() => s.Set("x", "a\nb"), "a line break is refused");
|
||||
}
|
||||
|
||||
static void ColorParse()
|
||||
{
|
||||
Equal("#e0b23e", LauncherColor.Default, "the default is Triforce gold, the page's GOLD");
|
||||
Equal("#5e9cf0", LauncherColor.Parse("#5E9CF0"), "upper case kept as lower case");
|
||||
Equal("#0a0908", LauncherColor.Parse("#0a0908"), "lower case as it is");
|
||||
foreach (var bad in new[] { null, "", "#", "#fff", "e0b23e", "#e0b23", "#e0b23e0", "#e0b23eff", "#gggggg", " #e0b23e", "#e0b23e ",
|
||||
"#e0b23e\n", "##e0b23", "rgb(224,178,62)", "gold", "#e0 23e", "#" + (char)0xFF45 + "0b23e" })
|
||||
Equal(null, LauncherColor.Parse(bad), "not a #rrggbb: [" + bad + "]");
|
||||
|
||||
string? Cmd(string json) => LauncherColor.FromCommand(System.Text.Json.Nodes.JsonNode.Parse(json));
|
||||
Equal("#5e9cf0", Cmd("""{"t":"cmd","c":"color","hex":"#5E9CF0"}"""), "the page's message");
|
||||
Equal("#e0b23e", Cmd("""{"t":"cmd","c":"color","hex":"#e0b23e"}"""), "Reset to gold");
|
||||
Equal(null, Cmd("""{"t":"cmd","c":"color"}"""), "no hex");
|
||||
Equal(null, Cmd("""{"t":"cmd","c":"color","hex":null}"""), "hex null");
|
||||
Equal(null, Cmd("""{"t":"cmd","c":"color","hex":14725694}"""), "hex a number");
|
||||
Equal(null, Cmd("""{"t":"cmd","c":"color","hex":true}"""), "hex a bool");
|
||||
Equal(null, Cmd("""{"t":"cmd","c":"color","hex":["#e0b23e"]}"""), "hex an array");
|
||||
Equal(null, Cmd("""{"t":"cmd","c":"color","hex":{"v":"#e0b23e"}}"""), "hex an object");
|
||||
Equal(null, Cmd("""{"t":"cmd","c":"color","hex":"#e0b23e; background:url(x)"}"""), "hex with more after it");
|
||||
Equal(null, Cmd("""{"t":"cmd","c":"color","hex":"blue"}"""), "a name");
|
||||
Equal(null, Cmd("""["#e0b23e"]"""), "a message that is not an object");
|
||||
Equal(null, LauncherColor.FromCommand(null), "no message");
|
||||
}
|
||||
|
||||
static void ColorKept()
|
||||
{
|
||||
// registry.txt (Windows' values in a test run): a file from before the color has no Color line and reads as gold
|
||||
var root = NewRoot("color");
|
||||
File.WriteAllLines(Path.Combine(root, "registry.txt"), new[] { @"Software\Triforce\Language=de", @"Software\Triforce\MusicVolume=55", @"Software\Triforce\Muted=1" });
|
||||
var old = Ctx(root);
|
||||
Equal(LauncherColor.Default, old.Settings.Color, "an old settings file: the default");
|
||||
Equal("de", old.Settings.Language, "and its other values as before");
|
||||
Equal(55, old.Settings.MusicVolume, "music volume as before");
|
||||
Check(old.Settings.Muted, "muted as before");
|
||||
Check(!File.ReadAllText(Path.Combine(root, "registry.txt")).Contains("Color"), "reading writes nothing");
|
||||
|
||||
old.Settings.Color = "#5E9CF0";
|
||||
Equal("#5e9cf0", Ctx(root).Settings.Color, "kept, lower case, read back by a new start");
|
||||
var lines = File.ReadAllLines(Path.Combine(root, "registry.txt"));
|
||||
Check(lines.Contains(@"Software\Triforce\Color=#5e9cf0"), "one line beside the others: " + string.Join(" / ", lines));
|
||||
Check(lines.Contains(@"Software\Triforce\Language=de") && lines.Contains(@"Software\Triforce\MusicVolume=55"), "the other values kept");
|
||||
|
||||
Throws<ArgumentException>(() => old.Settings.Color = "blue", "a bad color is refused");
|
||||
Throws<ArgumentException>(() => old.Settings.Color = "#fff", "three digits are refused");
|
||||
Equal("#5e9cf0", Ctx(root).Settings.Color, "and the kept one stays");
|
||||
|
||||
Ctx(root).Settings.Color = LauncherColor.Default;
|
||||
Equal(LauncherColor.Default, Ctx(root).Settings.Color, "Reset to gold kept");
|
||||
Equal(1, File.ReadAllLines(Path.Combine(root, "registry.txt")).Count(l => l.StartsWith(@"Software\Triforce\Color=")), "one line per name after a write");
|
||||
|
||||
// a kept value that does not read (changed by hand) is the default, not an error
|
||||
Ctx(root).Settings.Set(SettingNames.Color, "#12345");
|
||||
Equal(LauncherColor.Default, Ctx(root).Settings.Color, "an unreadable kept value: the default");
|
||||
Ctx(root).Settings.Set(SettingNames.Color, "#ABCDEF");
|
||||
Equal("#abcdef", Ctx(root).Settings.Color, "a kept upper-case value reads as lower case");
|
||||
|
||||
var snap = Ctx(root);
|
||||
snap.NoWrites = true;
|
||||
snap.Settings.Color = "#4fc3b4";
|
||||
Equal("#abcdef", Ctx(root).Settings.Color, "NoWrites writes no color");
|
||||
|
||||
Ctx(root).Platform.Settings.RemoveAll();
|
||||
Equal(LauncherColor.Default, Ctx(root).Settings.Color, "settings removed (uninstall): the default");
|
||||
|
||||
// builder.ini (Linux): its own key, the Tk builder's keys kept
|
||||
var iroot = NewRoot("color-ini");
|
||||
var file = Path.Combine(iroot, "triforce", "builder.ini");
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(file)!);
|
||||
File.WriteAllText(file, "kind=nup\nout=/home/a/Games/Triforce\nlanguage=en-US\nMusicVolume=30\n");
|
||||
var ini = new Settings(new IniSettingsStore(file), () => false);
|
||||
Equal(LauncherColor.Default, ini.Color, "an old builder.ini: the default");
|
||||
Equal(30, ini.MusicVolume, "and its volume as before");
|
||||
ini.Color = "#C77DDA";
|
||||
Equal("#c77dda", new Settings(new IniSettingsStore(file), () => false).Color, "kept in builder.ini");
|
||||
var text = File.ReadAllText(file);
|
||||
Check(text.Contains("Color=#c77dda\n") && text.Contains("kind=nup\n") && text.Contains("out=/home/a/Games/Triforce\n") && text.Contains("MusicVolume=30\n"),
|
||||
"Color= beside the Tk builder's keys: " + text);
|
||||
}
|
||||
|
||||
static void ColorChoice()
|
||||
{
|
||||
static System.Text.Json.Nodes.JsonNode Msg(string hex) => System.Text.Json.Nodes.JsonNode.Parse("{\"t\":\"cmd\",\"c\":\"color\",\"hex\":\"" + hex + "\"}")!;
|
||||
var root = NewRoot("color-choice");
|
||||
Ctx(root).Settings.Color = "#5e9cf0";
|
||||
|
||||
// --snapshot (NoWrites): the choice is not kept, but state.color (Current) is the player's, not the kept one
|
||||
var snap = Ctx(root);
|
||||
snap.NoWrites = true;
|
||||
var c = new LauncherColorChoice(snap.Settings);
|
||||
Equal("#5e9cf0", c.Current, "before the page sends one: the kept color");
|
||||
Equal("#c77dda", c.Take(Msg("#C77DDA")), "the page's color taken, lower case");
|
||||
c.Keep();
|
||||
Equal("#c77dda", c.Current, "NoWrites: the chosen color, so the Settings list does not set the page back");
|
||||
Equal("#5e9cf0", Ctx(root).Settings.Color, "and nothing written");
|
||||
Equal(null, c.Take(Msg("blue")), "a bad color is not taken");
|
||||
Equal("#c77dda", c.Current, "and the choice stays");
|
||||
|
||||
// a 'settings.list' handled before the 'color' just ahead of it has been kept: Current is already the new color
|
||||
var ctx = Ctx(root);
|
||||
c = new LauncherColorChoice(ctx.Settings);
|
||||
c.Take(Msg("#4fc3b4"));
|
||||
Equal("#4fc3b4", c.Current, "taken as it arrives, before its worker runs");
|
||||
Equal("#5e9cf0", ctx.Settings.Color, "not kept yet");
|
||||
// two colors whose workers run the wrong way round: the newest is kept
|
||||
c.Take(Msg("#e05a5a"));
|
||||
c.Keep(); c.Keep();
|
||||
Equal("#e05a5a", Ctx(root).Settings.Color, "the newest kept");
|
||||
Equal("#e05a5a", c.Current, "and sent");
|
||||
c.Take(Msg(LauncherColor.Default));
|
||||
c.Keep();
|
||||
Equal(LauncherColor.Default, Ctx(root).Settings.Color, "Reset to gold kept");
|
||||
}
|
||||
|
||||
// ---- startup ----
|
||||
|
||||
static void StartArgsParsing()
|
||||
|
||||
@@ -232,6 +232,33 @@ static partial class Tests
|
||||
Equal("0: NVIDIA GeForce RTX 4070", L("gpu_device", 1), "gpu 1");
|
||||
GameOptionsSchema.UseSystemGpus(); // (not asked here: the tests do not read this PC's registry)
|
||||
Check(GameOptionsSchema.GpuNames != null, "the hook is set");
|
||||
// ((Triforce) 11-19) the game's own order, from its triforce_gpus.txt: Windows lists the Intel first on that laptop,
|
||||
// Vulkan the NVIDIA, and the row's values are Vulkan's
|
||||
var g = NewRoot("gpulist");
|
||||
File.WriteAllText(Path.Combine(g, GameOptionsSchema.GpuListFile), "1\tNVIDIA GeForce RTX 3050 6GB Laptop GPU\n2\tIntel(R) UHD Graphics 770\n");
|
||||
GameOptionsSchema.UseGameGpus(() => g);
|
||||
Equal("0: NVIDIA GeForce RTX 3050 6GB Laptop GPU", L("gpu_device", 1), "the game's first card is the row's 1");
|
||||
Equal("1: Intel(R) UHD Graphics 770", L("gpu_device", 2), "and its second the row's 2");
|
||||
File.WriteAllText(Path.Combine(g, GameOptionsSchema.GpuListFile), "garbage\n3\tout of order\n");
|
||||
GameOptionsSchema.UseGameGpus(() => g);
|
||||
Check(GameOptionsSchema.GpuNames!() != null, "a file with nothing usable: Windows' list (no throw)");
|
||||
// ((Triforce) 11-20) Save writes the card's name with its number (gpu_device_name: the game finds it by the name
|
||||
// first), and an empty one for Auto
|
||||
GameOptionsSchema.GpuNames = () => new[] { "AMD Radeon(TM) 860M Graphics", "NVIDIA GeForce RTX 5060 Laptop GPU" };
|
||||
Equal("NVIDIA GeForce RTX 5060 Laptop GPU", GameOptionsSchema.GpuNameOf(2), "the name of the row's 2");
|
||||
Equal(null, GameOptionsSchema.GpuNameOf(0), "Auto has no name");
|
||||
var nf = NewRoot("gpuname");
|
||||
var opt = GameOptionsFile.Load(nf);
|
||||
opt.Set(GameOptionsSchema.GpuKey, 2);
|
||||
opt.Save();
|
||||
var text = File.ReadAllText(Path.Combine(nf, GameOptionsSchema.FileName));
|
||||
Check(text.Contains("gpu_device=2") && text.Contains("gpu_device_name=NVIDIA GeForce RTX 5060 Laptop GPU"),
|
||||
"the number and the name saved: " + text.Replace("\n", " | "));
|
||||
opt.Set(GameOptionsSchema.GpuKey, 0);
|
||||
opt.Save();
|
||||
text = File.ReadAllText(Path.Combine(nf, GameOptionsSchema.FileName));
|
||||
Check(text.Contains("gpu_device=0") && text.Contains("gpu_device_name=\r\n") || text.Contains("gpu_device_name=\n"),
|
||||
"Auto: the name emptied: " + text.Replace("\n", " | "));
|
||||
}
|
||||
finally { GameOptionsSchema.GpuNames = before; }
|
||||
|
||||
|
||||
122
launcher/LogicTests/Tests.Media.cs
Normal file
122
launcher/LogicTests/Tests.Media.cs
Normal file
@@ -0,0 +1,122 @@
|
||||
using System.Text;
|
||||
using Triforce.Core.GameFiles;
|
||||
using static Triforce.LogicTests.T;
|
||||
|
||||
namespace Triforce.LogicTests;
|
||||
|
||||
static partial class Tests
|
||||
{
|
||||
// ---- the launcher's music: the game's loop from the BWAV through the mix into the WAV the page plays ----
|
||||
// (every sound here is made by the test: no game file is read)
|
||||
|
||||
/// <summary>A BWAV file laid out as the game's are, with PCM16 channels (one in the middle, or two: left and right) and
|
||||
/// a loop from loopStart to just before loopEnd (0xFFFFFFFF: none, as the item fanfare and the interface sounds).</summary>
|
||||
static byte[] TestBwav(short[][] channels, uint loopStart, uint loopEnd, int rate = 48000)
|
||||
{
|
||||
var frames = channels[0].Length;
|
||||
var at = (0x10 + channels.Length * 0x4C + 0x3F) & ~0x3F; // (the samples start at 0xC0 in the game's two-channel files)
|
||||
var b = new byte[at + channels.Length * frames * 2];
|
||||
void Put(int o, long v, int n) { for (var i = 0; i < n; i++) b[o + i] = (byte)(v >> 8 * i); }
|
||||
Encoding.ASCII.GetBytes("BWAV").CopyTo(b, 0);
|
||||
Put(4, 0xFEFF, 2); Put(6, 1, 2); Put(0x0E, channels.Length, 2);
|
||||
for (var c = 0; c < channels.Length; c++)
|
||||
{
|
||||
int info = 0x10 + c * 0x4C, data = at + c * frames * 2;
|
||||
Put(info, 0, 2); Put(info + 2, channels.Length == 1 ? 2 : c, 2); Put(info + 4, rate, 4); Put(info + 8, frames, 4); Put(info + 0xC, frames, 4);
|
||||
Put(info + 0x30, data, 4); Put(info + 0x34, data, 4); Put(info + 0x38, 1, 4); Put(info + 0x3C, loopEnd, 4); Put(info + 0x40, loopStart, 4);
|
||||
for (var i = 0; i < frames; i++)
|
||||
Put(data + 2 * i, channels[c][i], 2);
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
static short[] TestTone(int frames, int step) => Enumerable.Range(0, frames).Select(i => (short)(i * step % 2000 - 1000)).ToArray();
|
||||
|
||||
static void MusicLoop()
|
||||
{
|
||||
// (1000 frames: an intro of 300, then the loop to the end, as the game's songs are laid out)
|
||||
short[] left = TestTone(1000, 7), right = TestTone(1000, 11);
|
||||
(int Start, int End)? want = (300, 1000);
|
||||
var pcm = Bwav.Decode(TestBwav(new[] { left, right }, 300, 1000));
|
||||
Equal(1000, pcm.Frames, "frames");
|
||||
Equal(want, pcm.Loop, "the header's loop: its start, and its end the sample after its last");
|
||||
Check(Bwav.Decode(TestBwav(new[] { left, right }, 0, 0xFFFFFFFF)).Loop == null, "end 0xFFFFFFFF: no loop");
|
||||
Check(Bwav.Decode(TestBwav(new[] { left, right }, 1000, 1000)).Loop == null, "a loop that starts at its end is none");
|
||||
Equal(want, Bwav.Decode(TestBwav(new[] { left, right }, 300, 5000)).Loop, "an end past the sound is cut to it");
|
||||
Equal(want, Bwav.Decode(TestBwav(new[] { left }, 300, 1000)).Loop, "one channel");
|
||||
|
||||
// the mix (the eight layers of Saria's Song share one loop) keeps it; layers with other loops have none
|
||||
var layer = Bwav.Decode(TestBwav(new[] { right, left }, 300, 1000));
|
||||
var mixed = Bwav.Mix(pcm, layer);
|
||||
Equal(want, mixed.Loop, "a mix of layers with the same loop");
|
||||
Check(Bwav.Mix(pcm, Bwav.Decode(TestBwav(new[] { right, left }, 200, 1000))).Loop == null, "a mix of layers with other loops: none");
|
||||
Check(Bwav.Mix(pcm, Bwav.Decode(TestBwav(new[] { right, left }, 0, 0xFFFFFFFF))).Loop == null, "a mix with a layer that does not loop: none");
|
||||
Equal(want, Bwav.Normalize(pcm).Loop, "normalized");
|
||||
Equal(want, Bwav.Gain(pcm, .5).Loop, "made quieter");
|
||||
|
||||
// the WAV: the 44-byte header and the samples at 44 as before, then a smpl chunk with the loop, its last sample in
|
||||
var wav = Bwav.ToWav(mixed);
|
||||
var data = mixed.Samples.Length * 2;
|
||||
Equal(44 + data + Bwav.SmplChunkSize, wav.Length, "length with the smpl chunk");
|
||||
Equal("RIFF", Encoding.ASCII.GetString(wav, 0, 4), "RIFF");
|
||||
Equal(wav.Length - 8, BitConverter.ToInt32(wav, 4), "the RIFF size takes the smpl chunk in");
|
||||
Equal("data", Encoding.ASCII.GetString(wav, 36, 4), "the data chunk where it was");
|
||||
Equal(data, BitConverter.ToInt32(wav, 40), "data size");
|
||||
Check(Bwav.FromWav(wav).Samples.SequenceEqual(mixed.Samples), "the samples read back");
|
||||
var smpl = 44 + data;
|
||||
Equal("smpl", Encoding.ASCII.GetString(wav, smpl, 4), "smpl after the data");
|
||||
Equal(60, BitConverter.ToInt32(wav, smpl + 4), "smpl size: 36 and one loop");
|
||||
Equal(1_000_000_000 / 48000, BitConverter.ToInt32(wav, smpl + 8 + 8), "the sample period in ns");
|
||||
Equal(60, BitConverter.ToInt32(wav, smpl + 8 + 12), "MIDI unity note");
|
||||
Equal(1, BitConverter.ToInt32(wav, smpl + 8 + 28), "one loop");
|
||||
Equal(0, BitConverter.ToInt32(wav, smpl + 8 + 40), "forward");
|
||||
Equal(300, BitConverter.ToInt32(wav, smpl + 8 + 44), "loop start");
|
||||
Equal(999, BitConverter.ToInt32(wav, smpl + 8 + 48), "the loop's last sample");
|
||||
Equal(0, BitConverter.ToInt32(wav, smpl + 8 + 56), "play count 0: for ever");
|
||||
Equal(want, Bwav.FromWav(wav).Loop, "the loop read back");
|
||||
|
||||
// a sound that plays once: the WAV as before (44 bytes and the samples), no smpl
|
||||
var once = Bwav.Decode(TestBwav(new[] { left, right }, 0, 0xFFFFFFFF));
|
||||
var plain = Bwav.ToWav(once);
|
||||
Equal(44 + once.Samples.Length * 2, plain.Length, "no loop, no smpl chunk");
|
||||
Equal(36 + once.Samples.Length * 2, BitConverter.ToInt32(plain, 4), "its RIFF size as before");
|
||||
Check(Bwav.FromWav(plain).Loop == null, "read back without a loop");
|
||||
|
||||
// a smpl loop that is not inside the sound, or a smpl without loops, reads as no loop
|
||||
var past = (byte[])wav.Clone();
|
||||
BitConverter.TryWriteBytes(past.AsSpan(smpl + 8 + 48), 1000);
|
||||
Check(Bwav.FromWav(past).Loop == null, "a loop whose last sample is past the sound");
|
||||
var backwards = (byte[])wav.Clone();
|
||||
BitConverter.TryWriteBytes(backwards.AsSpan(smpl + 8 + 44), 1000);
|
||||
Check(Bwav.FromWav(backwards).Loop == null, "a loop that ends before it starts");
|
||||
var none = (byte[])wav.Clone();
|
||||
BitConverter.TryWriteBytes(none.AsSpan(smpl + 8 + 28), 0);
|
||||
Check(Bwav.FromWav(none).Loop == null, "a smpl chunk with no loop");
|
||||
Check(Bwav.FromWav(wav.AsSpan(0, smpl + 8 + 40).ToArray()).Loop == null, "a smpl chunk cut off");
|
||||
}
|
||||
|
||||
static void MusicCache()
|
||||
{
|
||||
var root = NewRoot("media-loop");
|
||||
var stream = Path.Combine(root, "romfs", "Sound", "Resource", "Stream");
|
||||
Directory.CreateDirectory(stream);
|
||||
short[] tone = TestTone(1000, 7);
|
||||
File.WriteAllBytes(Path.Combine(stream, "BGM_GreatFairyFountain.bwav"), TestBwav(new[] { tone, tone }, 300, 1000));
|
||||
File.WriteAllBytes(Path.Combine(stream, "BGM_ItemGet_Large.bwav"), TestBwav(new[] { tone, tone }, 0, 0xFFFFFFFF));
|
||||
var cache = Path.Combine(root, "media");
|
||||
Directory.CreateDirectory(cache);
|
||||
// (what an older launcher left: the same name with another key, and no loop in it)
|
||||
var old = Path.Combine(cache, "fairy-0123456789abcdef.wav");
|
||||
File.WriteAllBytes(old, Bwav.ToWav(new Pcm { Rate = 48000, Samples = new short[20] }));
|
||||
|
||||
using var source = new FolderSource(root);
|
||||
var media = new GameMedia(source, cache);
|
||||
var file = media.WavFile("fairy");
|
||||
Check(!File.Exists(old), "the older launcher's WAV is replaced");
|
||||
Check(Path.GetFileName(file).StartsWith("fairy-", StringComparison.Ordinal) && Path.GetFileName(file).Length == Path.GetFileName(old).Length, "named as before: " + file);
|
||||
(int Start, int End)? want = (300, 1000);
|
||||
Equal(want, Bwav.FromWav(File.ReadAllBytes(file)).Loop, "the cached WAV has the game's loop");
|
||||
Equal(file, new GameMedia(source, cache).WavFile("fairy"), "read back from the cache the next time");
|
||||
Check(Bwav.FromWav(media.Wav("itemget")).Loop == null, "the fanfare plays once");
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,8 @@
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Logic\Triforce.Logic.csproj" />
|
||||
<!-- (the game's media decoders, for the music loop's tests: on sounds the tests make, never a game's) -->
|
||||
<ProjectReference Include="..\Core\Triforce.Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user