internal RsiLoadedEventArgs(ResourcePath path, RSIResource resource, Image atlas, Dictionary <RSI.StateId, Vector2i[][]> atlasOffsets) { Path = path; Resource = resource; Atlas = atlas; AtlasOffsets = atlasOffsets; }
private void PreloadRsis(ISawmill sawmill) { var sw = Stopwatch.StartNew(); var resList = GetTypeDict <RSIResource>(); var rsiList = ContentFindFiles("/Textures/") .Where(p => p.ToString().EndsWith(".rsi/meta.json")) .Select(c => c.Directory) .Where(p => !resList.ContainsKey(p)) .Select(p => new RSIResource.LoadStepData { Path = p }) .ToArray(); Parallel.ForEach(rsiList, data => { try { RSIResource.LoadPreTexture(this, data); } catch (Exception e) { // Mark failed loads as bad and skip them in the next few stages. // Avoids any silly array resizing or similar. sawmill.Error($"Exception while loading RSI {data.Path}:\n{e}"); data.Bad = true; } }); foreach (var data in rsiList) { if (data.Bad) { continue; } try { RSIResource.LoadTexture(_clyde, data); } catch (Exception e) { sawmill.Error($"Exception while loading RSI {data.Path}:\n{e}"); data.Bad = true; } } Parallel.ForEach(rsiList, data => { if (data.Bad) { return; } try { RSIResource.LoadPostTexture(data); } catch (Exception e) { data.Bad = true; sawmill.Error($"Exception while loading RSI {data.Path}:\n{e}"); } }); var errors = 0; foreach (var data in rsiList) { if (data.Bad) { errors += 1; continue; } try { var rsiRes = new RSIResource(); rsiRes.LoadFinish(this, data); resList[data.Path] = rsiRes; } catch (Exception e) { sawmill.Error($"Exception while loading RSI {data.Path}:\n{e}"); data.Bad = true; errors += 1; } } sawmill.Debug( "Preloaded {CountLoaded} RSIs ({CountErrored} errored) in {LoadTime}", rsiList.Length, errors, sw.Elapsed); }