Add safer chunk usage
This commit is contained in:
		
							parent
							
								
									736ced24e4
								
							
						
					
					
						commit
						622192a489
					
				| 
						 | 
					@ -92,19 +92,28 @@ public partial class Mission : Node3D
 | 
				
			||||||
		ClearMap();
 | 
							ClearMap();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		_textureLoader = new TextureLoader(_installPaths.famPath, FileName.GetBaseDir());
 | 
							_textureLoader = new TextureLoader(_installPaths.famPath, FileName.GetBaseDir());
 | 
				
			||||||
 | 
					 | 
				
			||||||
		_file = new(FileName);
 | 
							_file = new(FileName);
 | 
				
			||||||
		var textureList = (TxList)_file.Chunks["TXLIST"];
 | 
							UseChunk<TxList>("TXLIST", LoadTextures);
 | 
				
			||||||
		LoadTextures(textureList);
 | 
							UseChunk<WorldRep>("WREXT", BuildWrMeshes);
 | 
				
			||||||
		if (Dump) DumpTextureList(textureList);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		var wr = (WorldRep)_file.Chunks["WREXT"];
 | 
					 | 
				
			||||||
		BuildMeshes(wr.Cells, wr.DataHeader.LightmapFormat == 2);
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	private void BuildMeshes(WorldRep.Cell[] cells, bool lmHdr)
 | 
						private void UseChunk<T>(string name, Action<T> action)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		GD.Print($"HDR: {lmHdr}");
 | 
							if (_file.Chunks.TryGetValue(name, out var value))
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								action((T)value);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							else
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								GD.Print($"No chunk found/loaded: {name}");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						private void BuildWrMeshes(WorldRep worldRep)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							var cells = worldRep.Cells;
 | 
				
			||||||
 | 
							var lmHdr = worldRep.DataHeader.LightmapFormat == 2;
 | 
				
			||||||
 | 
							GD.Print($"HDR Lightmap: {lmHdr}");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		var packingRects = new List<PackingRectangle>();
 | 
							var packingRects = new List<PackingRectangle>();
 | 
				
			||||||
		var surfaceDataMap = new Dictionary<int, MeshSurfaceData>();
 | 
							var surfaceDataMap = new Dictionary<int, MeshSurfaceData>();
 | 
				
			||||||
| 
						 | 
					@ -345,6 +354,8 @@ public partial class Mission : Node3D
 | 
				
			||||||
				GD.Print($"Failed to load texture: {path}");
 | 
									GD.Print($"Failed to load texture: {path}");
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (Dump) DumpTextureList(textureList);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	private static void DumpTextureList(TxList textureList)
 | 
						private static void DumpTextureList(TxList textureList)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue