From 531338a955b71f04dcbef8b4cfa61791e27aab7b Mon Sep 17 00:00:00 2001 From: Pavlos Touboulidis Date: Wed, 21 May 2014 22:56:59 +0300 Subject: [PATCH] Preload sequences and fix #5382 --- OpenRA.Game/FileSystem/GlobalFileSystem.cs | 23 +++++++++++++++++----- OpenRA.Game/Graphics/SequenceProvider.cs | 22 +++++++++++++++++++-- OpenRA.Game/ModData.cs | 4 +++- 3 files changed, 41 insertions(+), 8 deletions(-) diff --git a/OpenRA.Game/FileSystem/GlobalFileSystem.cs b/OpenRA.Game/FileSystem/GlobalFileSystem.cs index f7eeb62db9..45ca6af2bf 100644 --- a/OpenRA.Game/FileSystem/GlobalFileSystem.cs +++ b/OpenRA.Game/FileSystem/GlobalFileSystem.cs @@ -168,18 +168,27 @@ namespace OpenRA.FileSystem public static Stream Open(string filename) { return OpenWithExts(filename, ""); } public static Stream OpenWithExts(string filename, params string[] exts) + { + Stream s; + if (!TryOpenWithExts(filename, exts, out s)) + throw new FileNotFoundException("File not found: {0}".F(filename), filename); + + return s; + } + + public static bool TryOpenWithExts(string filename, string[] exts, out Stream s) { if (filename.IndexOfAny(new char[] { '/', '\\' }) == -1) { foreach (var ext in exts) { - var s = GetFromCache(PackageHashType.Classic, filename + ext); + s = GetFromCache(PackageHashType.Classic, filename + ext); if (s != null) - return s; + return true; s = GetFromCache(PackageHashType.CRC32, filename + ext); if (s != null) - return s; + return true; } } @@ -191,10 +200,14 @@ namespace OpenRA.FileSystem .FirstOrDefault(); if (folder != null) - return folder.GetContent(filename + ext); + { + s = folder.GetContent(filename + ext); + return true; + } } - throw new FileNotFoundException("File not found: {0}".F(filename), filename); + s = null; + return false; } public static bool Exists(string filename) { return MountedFolders.Any(f => f.Exists(filename)); } diff --git a/OpenRA.Game/Graphics/SequenceProvider.cs b/OpenRA.Game/Graphics/SequenceProvider.cs index 1adfa14d19..5ce8d618f4 100644 --- a/OpenRA.Game/Graphics/SequenceProvider.cs +++ b/OpenRA.Game/Graphics/SequenceProvider.cs @@ -58,6 +58,21 @@ namespace OpenRA.Graphics return unitSeq.Value.Keys; } + + public void Preload() + { + foreach (var unitSeq in sequences.Value.Values) + { + try + { + foreach (var seq in unitSeq.Value.Values); + } + catch (FileNotFoundException ex) + { + Log.Write("debug", ex.Message); + } + } + } } public class SequenceCache @@ -100,8 +115,11 @@ namespace OpenRA.Graphics else { t = Exts.Lazy(() => (IReadOnlyDictionary)new ReadOnlyDictionary( - node.Value.NodesDict.ToDictionary(x => x.Key, x => - new Sequence(spriteLoader.Value, node.Key, x.Key, x.Value)))); + node.Value.NodesDict.ToDictionary(x => x.Key, x => + { + using (new Support.PerfTimer("new Sequence(\"{0}\")".F(node.Key), 20)) + return new Sequence(spriteLoader.Value, node.Key, x.Key, x.Value); + }))); sequenceCache.Add(key, t); items.Add(node.Key, t); } diff --git a/OpenRA.Game/ModData.cs b/OpenRA.Game/ModData.cs index 4ad17eaaf7..1716bcd1e5 100644 --- a/OpenRA.Game/ModData.cs +++ b/OpenRA.Game/ModData.cs @@ -134,8 +134,10 @@ namespace OpenRA // Mount map package so custom assets can be used. TODO: check priority. GlobalFileSystem.Mount(GlobalFileSystem.OpenPackage(map.Path, null, int.MaxValue)); - using (new Support.PerfTimer("Map.LoadRules")) + using (new Support.PerfTimer("Map.PreloadRules")) map.PreloadRules(); + using (new Support.PerfTimer("Map.SequenceProvider.Preload")) + map.SequenceProvider.Preload(); VoxelProvider.Initialize(Manifest.VoxelSequences, map.VoxelSequenceDefinitions);