diff options
| author | Mattia <mattia2700franzin+dev@gmail.com> | 2026-11-23 16:32:22 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-11-23 09:32:22 -0600 |
| commit | c646bf836777ef63587ecdbea44bd62df827c433 (patch) | |
| tree | 918b4f77f789cb15d526062e6b9230a9fe3a2fe0 /tools/rpf9dump/Program.cs | |
| parent | 1cc6e3c121969761d9dad8fdec99f19928213973 (diff) | |
Speed up make_game by overlapping stages and showing progress. (#1797)
Squash-merged after diff review of PR #1797
Diffstat (limited to 'tools/rpf9dump/Program.cs')
| -rw-r--r-- | tools/rpf9dump/Program.cs | 46 |
1 files changed, 32 insertions, 14 deletions
diff --git a/tools/rpf9dump/Program.cs b/tools/rpf9dump/Program.cs index 6c7263851..b04d49c01 100644 --- a/tools/rpf9dump/Program.cs +++ b/tools/rpf9dump/Program.cs | |||
| @@ -5,27 +5,45 @@ using System.Globalization; | |||
| 5 | using System.Text.Json; | 5 | using System.Text.Json; |
| 6 | using RpfPreview.Core; | 6 | using RpfPreview.Core; |
| 7 | 7 | ||
| 8 | // Optional --jobs N anywhere among the args (default: every core). Stripped before mode/src/outdir. | ||
| 9 | var argv = args.ToList(); | ||
| 10 | int jobs = Environment.ProcessorCount; | ||
| 11 | for (int i = 0; i < argv.Count; ) | ||
| 12 | { | ||
| 13 | if (argv[i] == "--jobs") | ||
| 14 | { | ||
| 15 | if (i + 1 >= argv.Count || !int.TryParse(argv[i + 1], out jobs) || jobs < 1) | ||
| 16 | { | ||
| 17 | Console.Error.WriteLine("--jobs must be at least 1"); | ||
| 18 | return 2; | ||
| 19 | } | ||
| 20 | argv.RemoveAt(i); | ||
| 21 | argv.RemoveAt(i); | ||
| 22 | continue; | ||
| 23 | } | ||
| 24 | i++; | ||
| 25 | } | ||
| 8 | // The mode is checked before the source or the output folder is touched. A typo used to fall through every branch: | 26 | // The mode is checked before the source or the output folder is touched. A typo used to fall through every branch: |
| 9 | // it created the output folder, printed ok=0 fail=0 skip=0 and exited 0, which make_game reads as a finished stage. | 27 | // it created the output folder, printed ok=0 fail=0 skip=0 and exited 0, which make_game reads as a finished stage. |
| 10 | string[] modes = ["ttpf", "audio", "xma", "models", "textures"]; | 28 | string[] modes = ["ttpf", "audio", "xma", "models", "textures"]; |
| 11 | if (args.Length < 3) { Usage(); return 2; } | 29 | if (argv.Count < 3) { Usage(); return 2; } |
| 12 | if (!modes.Contains(args[0])) { Console.Error.WriteLine($"unknown mode '{args[0]}'"); Usage(); return 2; } | 30 | if (!modes.Contains(argv[0])) { Console.Error.WriteLine($"unknown mode '{argv[0]}'"); Usage(); return 2; } |
| 13 | string mode = args[0], src = Path.GetFullPath(args[1]), outRoot = Path.GetFullPath(args[2]); | 31 | string mode = argv[0], src = Path.GetFullPath(argv[1]), outRoot = Path.GetFullPath(argv[2]); |
| 14 | // --start/--length scan one window of the file instead of the whole archive. A window is a raw slice of an | 32 | // --start/--length scan one window of the file instead of the whole archive. A window is a raw slice of an |
| 15 | // archive (`levels.rpf` cut at an offset), so it need not carry the file's header and it is not an | 33 | // archive (`levels.rpf` cut at an offset), so it need not carry the file's header and it is not an |
| 16 | // ArchiveDocument: models and textures then read every resource from its own compression blocks | 34 | // ArchiveDocument: models and textures then read every resource from its own compression blocks |
| 17 | // (tools/rpf9dump/Segments.cs). A window is how a multi-GiB archive is exported a piece at a time. | 35 | // (tools/rpf9dump/Segments.cs). A window is how a multi-GiB archive is exported a piece at a time. |
| 18 | long scanStart = 0; long? scanLength = null; | 36 | long scanStart = 0; long? scanLength = null; |
| 19 | for (int i = 3; i < args.Length; i += 2) | 37 | for (int i = 3; i < argv.Count; i += 2) |
| 20 | { | 38 | { |
| 21 | if (i + 1 >= args.Length || !long.TryParse(args[i + 1], NumberStyles.None, CultureInfo.InvariantCulture, out long bytes) || bytes < 0) | 39 | if (i + 1 >= argv.Count || !long.TryParse(argv[i + 1], NumberStyles.None, CultureInfo.InvariantCulture, out long bytes) || bytes < 0) |
| 22 | { | 40 | { |
| 23 | Console.WriteLine($"{args[i]} needs a non-negative byte count."); | 41 | Console.WriteLine($"{argv[i]} needs a non-negative byte count."); |
| 24 | return 2; | 42 | return 2; |
| 25 | } | 43 | } |
| 26 | if (args[i] == "--start") scanStart = bytes; | 44 | if (argv[i] == "--start") scanStart = bytes; |
| 27 | else if (args[i] == "--length") scanLength = bytes; | 45 | else if (argv[i] == "--length") scanLength = bytes; |
| 28 | else { Console.WriteLine($"Unknown option {args[i]}."); return 2; } | 46 | else { Console.WriteLine($"Unknown option {argv[i]}."); return 2; } |
| 29 | } | 47 | } |
| 30 | bool window = scanStart != 0 || scanLength is not null; | 48 | bool window = scanStart != 0 || scanLength is not null; |
| 31 | if (window && mode is not ("models" or "textures")) | 49 | if (window && mode is not ("models" or "textures")) |
| @@ -48,10 +66,10 @@ var sw = Stopwatch.StartNew(); | |||
| 48 | string baseName = Path.GetFileNameWithoutExtension(src); | 66 | string baseName = Path.GetFileNameWithoutExtension(src); |
| 49 | string outDir = Path.Combine(outRoot, baseName); Directory.CreateDirectory(outDir); | 67 | string outDir = Path.Combine(outRoot, baseName); Directory.CreateDirectory(outDir); |
| 50 | int ok = 0, fail = 0, skip = 0, writeFail = 0; | 68 | int ok = 0, fail = 0, skip = 0, writeFail = 0; |
| 51 | // Every mode below works on all cores. Core's readers open their own read handle per call, entry and file names | 69 | // Every mode below works on all cores by default. Core's readers open their own read handle per call, entry and |
| 52 | // come from offsets and indexes, and results are put back in source order, so outputs match a one-thread run. | 70 | // file names come from offsets and indexes, and results are put back in source order, so outputs match a |
| 53 | // ponytail: every core, no flag; add --jobs if someone needs the machine during a build. | 71 | // one-thread run. --jobs caps that when make_game.py overlaps this with another CPU-heavy stage. |
| 54 | var par = new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount }; | 72 | var par = new ParallelOptions { MaxDegreeOfParallelism = jobs }; |
| 55 | 73 | ||
| 56 | if (mode == "ttpf") | 74 | if (mode == "ttpf") |
| 57 | { | 75 | { |
| @@ -390,7 +408,7 @@ static void WithdrawMarker(string path) | |||
| 390 | 408 | ||
| 391 | static void Usage() | 409 | static void Usage() |
| 392 | { | 410 | { |
| 393 | Console.WriteLine("usage: rpf9dump <mode> <source> <outdir> [--start BYTES] [--length BYTES]"); | 411 | Console.WriteLine("usage: rpf9dump <mode> <source> <outdir> [--jobs N] [--start BYTES] [--length BYTES]"); |
| 394 | Console.WriteLine(" ttpf texture dictionaries and world texture pools as DDS"); | 412 | Console.WriteLine(" ttpf texture dictionaries and world texture pools as DDS"); |
| 395 | Console.WriteLine(" models drawable models as OBJ, with their embedded textures"); | 413 | Console.WriteLine(" models drawable models as OBJ, with their embedded textures"); |
| 396 | Console.WriteLine(" textures texture dictionaries as DDS"); | 414 | Console.WriteLine(" textures texture dictionaries as DDS"); |