Use TryGetChunk everywhere
This commit is contained in:
parent
ab738203d6
commit
3fa86a233f
|
@ -38,21 +38,19 @@ public class ObjectHierarchy
|
|||
|
||||
T GetMergedChunk<T>(string name) where T : IMergable
|
||||
{
|
||||
if (db.Chunks.TryGetValue(name, out var rawChunk))
|
||||
if (!db.TryGetChunk<T>(name, out var chunk))
|
||||
{
|
||||
var chunk = (T)rawChunk;
|
||||
if (gam != null && gam.Chunks.TryGetValue(name, out var rawGamChunk))
|
||||
throw new ArgumentException($"No chunk with name ({name}) found", nameof(name));
|
||||
}
|
||||
|
||||
if (gam != null && gam.TryGetChunk<T>(name, out var gamChunk))
|
||||
{
|
||||
var gamChunk = (T)rawGamChunk;
|
||||
gamChunk.Merge(chunk);
|
||||
return gamChunk;
|
||||
}
|
||||
return chunk;
|
||||
}
|
||||
|
||||
throw new ArgumentException($"No chunk with name ({name}) found", nameof(name));
|
||||
}
|
||||
|
||||
// Add parentages
|
||||
var metaPropLinks = GetMergedChunk<LinkChunk>("L$MetaProp");
|
||||
var metaPropLinkData = GetMergedChunk<LinkDataMetaProp>("LD$MetaProp");
|
||||
|
|
|
@ -58,9 +58,8 @@ class Program
|
|||
var hierarchy = Timing.TimeStage("Build Hierarchy", () => BuildHierarchy(misPath, mis));
|
||||
|
||||
// Build embree mesh
|
||||
if (!mis.Chunks.TryGetValue("WREXT", out var wrRaw))
|
||||
if (!mis.TryGetChunk<WorldRep>("WREXT", out var worldRep))
|
||||
return;
|
||||
var worldRep = (WorldRep)wrRaw;
|
||||
var scene = Timing.TimeStage("Build Scene", () =>
|
||||
{
|
||||
var rt = new Raytracer();
|
||||
|
@ -70,9 +69,9 @@ class Program
|
|||
});
|
||||
|
||||
// For each lightmap pixel cast against all the brush and object lights
|
||||
if (!mis.Chunks.TryGetValue("RENDPARAMS", out var rendParamsRaw))
|
||||
if (!mis.TryGetChunk<RendParams>("RENDPARAMS", out var rendParams))
|
||||
return;
|
||||
var ambient = ((RendParams)rendParamsRaw).ambientLight * 255;
|
||||
var ambient = rendParams.ambientLight * 255;
|
||||
var lights = Timing.TimeStage("Gather Lights", () => BuildLightList(mis, hierarchy, campaign));
|
||||
Timing.TimeStage("Light", () => CastSceneParallel(scene, worldRep, [.. lights], ambient));
|
||||
|
||||
|
@ -279,11 +278,11 @@ class Program
|
|||
private static ObjectHierarchy BuildHierarchy(string misPath, DbFile misFile)
|
||||
{
|
||||
ObjectHierarchy objHierarchy;
|
||||
if (misFile.Chunks.TryGetValue("GAM_FILE", out var gamFileChunk))
|
||||
if (misFile.TryGetChunk<GamFile>("GAM_FILE", out var gamFile))
|
||||
{
|
||||
var dir = Path.GetDirectoryName(misPath);
|
||||
var options = new EnumerationOptions { MatchCasing = MatchCasing.CaseInsensitive };
|
||||
var name = ((GamFile)gamFileChunk).fileName;
|
||||
var name = gamFile.fileName;
|
||||
var paths = Directory.GetFiles(dir!, name, options);
|
||||
if (paths.Length > 0)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue