private static void CollectTileTerrtex(string[] args) { List <TileTerrtexDirectory> summary = new List <TileTerrtexDirectory>(); foreach (string arg in args) { if (Directory.Exists(arg)) { Trace.WriteLine($"Scanning {args}..."); foreach (string path in Directory.GetDirectories(arg, "Tiles", SearchOption.AllDirectories)) { Trace.WriteLine($"Scanning {path}..."); TileTerrtexDirectory data = new TileTerrtexDirectory(path); foreach (string file in Directory.GetFiles(path, "*.t")) { try { TerrainFile t = new TerrainFile(file); if (t.Terrain.Patchsets.Length != 1) { throw new InvalidDataException($"Tile has {t.Terrain.Patchsets.Length} patch sets; expected 1."); } if (t.Terrain.Patchsets[0].PatchSize != 16) { throw new InvalidDataException($"Tile has {t.Terrain.Patchsets[0].PatchSize} patches; expected 16."); } if (t.Terrain.Patchsets[0].Patches.Length != 256) { throw new InvalidDataException($"Tile has {t.Terrain.Patchsets[0].Patches.Length} patches; expected 256."); } data.TileCount++; Formats.Msts.Models.PatchSet patchset = t.Terrain.Patchsets[0]; List <string> textures = new List <string>(patchset.PatchSize * patchset.PatchSize); foreach (Formats.Msts.Models.Patch patch in patchset.Patches) { textures.Add(string.Join("|", (from ts in t.Terrain.Shaders[patch.ShaderIndex].Textureslots select ts.FileName).ToArray())); } // 1th if (textures.Distinct().Count() == 1) { data.Tile1Count++; } // 4th List <string>[] textures4 = new List <string> [4]; for (int i = 0; i < textures4.Length; i++) { textures4[i] = new List <string>(); } for (int x = 0; x < 16; x++) { for (int y = 0; y < 16; y++) { int tx = x / 8; int ty = y / 8; textures4[tx + ty * 2].Add(textures[x + y * 16]); } } for (int i = 0; i < textures4.Length; i++) { if (textures4[i].Distinct().Count() == 1) { data.Tile4Count++; } } // 16th List <string>[] textures16 = new List <string> [16]; for (int i = 0; i < textures16.Length; i++) { textures16[i] = new List <string>(); } for (int x = 0; x < 16; x++) { for (int y = 0; y < 16; y++) { int tx = x / 4; int ty = y / 4; textures16[tx + ty * 4].Add(textures[x + y * 16]); } } for (int i = 0; i < textures16.Length; i++) { if (textures16[i].Distinct().Count() == 1) { data.Tile16Count++; } } // 64th List <string>[] textures64 = new List <string> [64]; for (int i = 0; i < textures64.Length; i++) { textures64[i] = new List <string>(); } for (int x = 0; x < 16; x++) { for (int y = 0; y < 16; y++) { int tx = x / 2; int ty = y / 2; textures64[tx + ty * 8].Add(textures[x + y * 16]); } } for (int i = 0; i < textures64.Length; i++) { if (textures64[i].Distinct().Count() == 1) { data.Tile64Count++; } } } #pragma warning disable CA1031 // Do not catch general exception types catch (Exception error) #pragma warning restore CA1031 // Do not catch general exception types { Trace.WriteLine($"Error reading tile {file}: {error}"); } } if (data.TileCount > 0) { summary.Add(data); } } } } Trace.WriteLine(string.Empty); foreach (TileTerrtexDirectory data in from data in summary orderby data.Path select data) { Trace.WriteLine($"{data.Path,30} / {data.TileCount,-4} / 1th {data.Tile1Count / data.TileCount,5:P0} / 4th {data.Tile4Count / 4 / data.TileCount,5:P0} / 16th {data.Tile16Count / 16 / data.TileCount,5:P0} / 64th {data.Tile64Count / 64 / data.TileCount,5:P0}"); } }
static void CollectTileTerrtex(string[] args) { var summary = new List <TileTerrtexDirectory>(); foreach (var arg in args) { if (Directory.Exists(arg)) { Console.WriteLine("Scanning {0}...", arg); foreach (var path in Directory.GetDirectories(arg, "Tiles", SearchOption.AllDirectories)) { Console.WriteLine("Scanning {0}...", path); var data = new TileTerrtexDirectory(path); foreach (var file in Directory.GetFiles(path, "*.t")) { try { var t = new TerrainFile(file); if (t.terrain.terrain_patchsets.Length != 1) { throw new InvalidDataException(String.Format("Tile has {0} patch sets; expected 1.", t.terrain.terrain_patchsets.Length)); } if (t.terrain.terrain_patchsets[0].terrain_patchset_npatches != 16) { throw new InvalidDataException(String.Format("Tile has {0} patches; expected 16.", t.terrain.terrain_patchsets[0].terrain_patchset_npatches)); } if (t.terrain.terrain_patchsets[0].terrain_patchset_patches.Length != 256) { throw new InvalidDataException(String.Format("Tile has {0} patches; expected 256.", t.terrain.terrain_patchsets[0].terrain_patchset_patches.Length)); } data.TileCount++; var patchset = t.terrain.terrain_patchsets[0]; var textures = new List <string>(patchset.terrain_patchset_npatches * patchset.terrain_patchset_npatches); foreach (var patch in patchset.terrain_patchset_patches) { textures.Add(String.Join("|", (from ts in t.terrain.terrain_shaders[patch.ShaderIndex].terrain_texslots select ts.Filename).ToArray())); } // 1th if (textures.Distinct().Count() == 1) { data.Tile1Count++; } // 4th var textures4 = new List <string> [4]; for (var i = 0; i < textures4.Length; i++) { textures4[i] = new List <string>(); } for (var x = 0; x < 16; x++) { for (var y = 0; y < 16; y++) { var tx = (int)(x / 8); var ty = (int)(y / 8); textures4[tx + ty * 2].Add(textures[x + y * 16]); } } for (var i = 0; i < textures4.Length; i++) { if (textures4[i].Distinct().Count() == 1) { data.Tile4Count++; } } // 16th var textures16 = new List <string> [16]; for (var i = 0; i < textures16.Length; i++) { textures16[i] = new List <string>(); } for (var x = 0; x < 16; x++) { for (var y = 0; y < 16; y++) { var tx = (int)(x / 4); var ty = (int)(y / 4); textures16[tx + ty * 4].Add(textures[x + y * 16]); } } for (var i = 0; i < textures16.Length; i++) { if (textures16[i].Distinct().Count() == 1) { data.Tile16Count++; } } // 64th var textures64 = new List <string> [64]; for (var i = 0; i < textures64.Length; i++) { textures64[i] = new List <string>(); } for (var x = 0; x < 16; x++) { for (var y = 0; y < 16; y++) { var tx = (int)(x / 2); var ty = (int)(y / 2); textures64[tx + ty * 8].Add(textures[x + y * 16]); } } for (var i = 0; i < textures64.Length; i++) { if (textures64[i].Distinct().Count() == 1) { data.Tile64Count++; } } } catch (Exception error) { Console.WriteLine("Error reading tile {0}: {1}", file, error); } } if (data.TileCount > 0) { summary.Add(data); } } } } Console.WriteLine(); foreach (var data in from data in summary orderby data.Path select data) { Console.WriteLine("{0,30} / {1,-4} / 1th {2,5:P0} / 4th {3,5:P0} / 16th {4,5:P0} / 64th {5,5:P0}", data.Path, data.TileCount, data.Tile1Count / data.TileCount, data.Tile4Count / 4 / data.TileCount, data.Tile16Count / 16 / data.TileCount, data.Tile64Count / 64 / data.TileCount); } }