Dwarrowdelf.Server.Fortress.FortressWorldCreator.CreateOrLoadTerrain C# (CSharp) Method

CreateOrLoadTerrain() static private method

static private CreateOrLoadTerrain ( IntSize3 size ) : TerrainData
size IntSize3
return Dwarrowdelf.TerrainGen.TerrainData
		static TerrainData CreateOrLoadTerrain(IntSize3 size)
		{
			var path = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location), "save");
			string file = Path.Combine(path, "terrain-cache-hack.dat");

			TerrainData terrain = null;

			try
			{
				var sw = Stopwatch.StartNew();
				terrain = TerrainData.LoadTerrain(file, "fortress", size);
				sw.Stop();
				Trace.TraceInformation("Load cached terrain {0} ms", sw.ElapsedMilliseconds);
			}
			catch (Exception e)
			{
				Trace.TraceError("Failed to load cached terrain: {0}", e.Message);
			}

			if (terrain == null)
			{
				terrain = CreateTerrain(size);
				var sw = Stopwatch.StartNew();
				terrain.SaveTerrain(file, "fortress");
				sw.Stop();
				Trace.TraceInformation("Save cached terrain {0} ms", sw.ElapsedMilliseconds);
			}
			return terrain;
		}