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