/// <summary> /// Reloads a map that was unloaded for memory conservation. /// </summary> public void LoadMap() { Map = new ClassicWorld(Path); HCSettings = new HypercubeMetadata(); // -- Create our HC Specific settings Map.MetadataParsers.Add("Hypercube", HCSettings); // -- Register it with the map loader Map.Load(); // -- Load the map if (HCSettings.History == null) { HCSettings.History = new int[Map.BlockData.Length]; } Path = Path.Replace(".cwu", ".cw"); Loaded = true; System.IO.File.Move(Path + "u", Path); }
/// <summary> /// Loads a pre-existing map /// </summary> /// <param name="Filename">The path to the map.</param> public HypercubeMap(Hypercube Core, string Filename) { ServerCore = Core; Path = Filename; Map = new ClassicWorld(Filename); HCSettings = new HypercubeMetadata(); // -- Create our HC Specific settings Map.MetadataParsers.Add("Hypercube", HCSettings); // -- Register it with the map loader Map.Load(); // -- Load the map // -- Creates HC Metadata if it does not exist. if (HCSettings.BuildRanks == null) { foreach (Rank r in Core.Rankholder.Ranks) // -- Allow all ranks to access this map by default. { BuildRanks.Add(r); } } if (HCSettings.ShowRanks == null) { foreach (Rank r in Core.Rankholder.Ranks) // -- Allow all ranks to access this map by default. { ShowRanks.Add(r); } } if (HCSettings.JoinRanks == null) { foreach (Rank r in Core.Rankholder.Ranks) // -- Allow all ranks to access this map by default. { JoinRanks.Add(r); } HCSettings.Building = true; HCSettings.Physics = true; } HCSettings.Building = true; HCSettings.Physics = true; if (HCSettings.History == null) { HCSettings.History = new int[Map.BlockData.Length]; } LastClient = DateTime.UtcNow; Clients = new List <NetworkClient>(); Entities = new List <Entity>(); // -- Set CPE Information... var myRef = (CPEMetadata)Map.MetadataParsers["CPE"]; if (myRef.CustomBlocksFallback == null) { myRef.CustomBlocksLevel = 1; myRef.CustomBlocksVersion = 1; myRef.CustomBlocksFallback = new byte[256]; for (int i = 50; i < 66; i++) { myRef.CustomBlocksFallback[i] = (byte)Core.Blockholder.GetBlock(i).CPEReplace; } Map.MetadataParsers["CPE"] = myRef; } // -- Memory Conservation: if (Path.Substring(Path.Length - 1, 1) == "u") // -- Unloads anything with a ".cwu" file extension. (ClassicWorld unloaded) { Map.BlockData = null; HCSettings.History = null; GC.Collect(); Loaded = false; var testing = (HypercubeMetadata)Map.MetadataParsers["Hypercube"]; testing.History = null; } }