Preload sequences and fix #5382
This commit is contained in:
@@ -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)); }
|
||||
|
||||
@@ -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
|
||||
@@ -101,7 +116,10 @@ namespace OpenRA.Graphics
|
||||
{
|
||||
t = Exts.Lazy(() => (IReadOnlyDictionary<string, Sequence>)new ReadOnlyDictionary<string, Sequence>(
|
||||
node.Value.NodesDict.ToDictionary(x => x.Key, x =>
|
||||
new Sequence(spriteLoader.Value, node.Key, x.Key, x.Value))));
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user