/// <summary> /// Loads a new file into this map object. /// </summary> /// <param name="filename">The file to load into this map.</param> public void Load(string filename) { if (!File.Exists(filename)) { if (File.Exists(filename + "u")) File.Move(filename + "u", filename); else return; } Path = filename; CWMap = new Classicworld(filename); HCSettings = new HypercubeMetadata(); CWMap.MetadataParsers.Add("Hypercube", HCSettings); CWMap.Load(); _physicsBitmask = new byte[(CWMap.BlockData.Length / 8) + 1]; HCSettings = (HypercubeMetadata)CWMap.MetadataParsers["Hypercube"]; if (HCSettings.BuildPerms == null) { Buildperms.Add("player.build", ServerCore.Permholder.GetPermission("player.build")); } else Buildperms = PermissionContainer.SplitPermissions(HCSettings.BuildPerms); if (HCSettings.ShowPerms == null) { Showperms.Add("map.joinmap", ServerCore.Permholder.GetPermission("map.joinmap")); } else Showperms = PermissionContainer.SplitPermissions(HCSettings.ShowPerms); if (HCSettings.JoinPerms == null) { Joinperms.Add("map.joinmap", ServerCore.Permholder.GetPermission("map.joinmap")); HCSettings.Building = true; HCSettings.Physics = true; HCSettings.History = true; } else Joinperms = PermissionContainer.SplitPermissions(HCSettings.JoinPerms); if (HCSettings.SaveInterval == 0) HCSettings.SaveInterval = 10; CPESettings = (CPEMetadata)CWMap.MetadataParsers["CPE"]; if (CPESettings.CustomBlocksFallback == null) { CPESettings.CustomBlocksLevel = CPE.CustomBlocksSupportLevel; CPESettings.CustomBlocksVersion = CPE.CustomBlocksVersion; CPESettings.CustomBlocksFallback = new byte[256]; for (var i = 50; i < 66; i++) CPESettings.CustomBlocksFallback[i] = (byte)ServerCore.Blockholder.GetBlock(i).CPEReplace; CWMap.MetadataParsers["CPE"] = CPESettings; } if (CPESettings.EnvMapAppearanceVersion != CPE.EnvMapAppearanceVersion) { CPESettings.TextureUrl = ""; CPESettings.EdgeBlock = 8; CPESettings.SideBlock = 7; CPESettings.SideLevel = (short)(CWMap.SizeY / 2); CPESettings.EnvMapAppearanceVersion = CPE.EnvMapAppearanceVersion; } if (HCSettings.History) History = new MapHistory(this); }
/// <summary> /// Loads a pre-existing map. /// </summary> /// <param name="filename">File to load.</param> public HypercubeMap(string filename) { Load(filename); Lastclient = DateTime.UtcNow; Clients = new Dictionary<short, NetworkClient>(); Entities = new Dictionary<int, Entity>(); CreateClientList(); // -- Memory Conservation if (Path.Substring(Path.Length - 1, 1) == "u") { CWMap.BlockData = null; CWMap.MetadataParsers.Clear(); GC.Collect(); Loaded = false; } if (HCSettings.History) History = new MapHistory(this); for (sbyte i = 0; i < 127; i++) FreeIds.Push(i); }
/// <summary> /// Reloads the map after being unloaded to conserve memory. /// </summary> public void Load() { if (Loaded) return; CWMap = new Classicworld(Path); HCSettings = new HypercubeMetadata(); CWMap.MetadataParsers.Add("Hypercube", HCSettings); CWMap.Load(); _physicsBitmask = new byte[(CWMap.BlockData.Length / 8) + 1]; HCSettings = (HypercubeMetadata)CWMap.MetadataParsers["Hypercube"]; Path = Path.Replace(".cwu", ".cw"); if (File.Exists(Path)) File.Delete(Path); File.Move(Path + "u", Path); if (HCSettings.History && History != null) History.ReloadHistory(); else if (HCSettings.History) History = new MapHistory(this); Loaded = true; ServerCore.Logger.Log("Map", CWMap.MapName + " reloaded.", LogType.Info); ServerCore.Luahandler.RunFunction("E_MapReloaded", this); }
private byte[] _physicsBitmask; // -- A simple bitmask for determineing what blocks are in the physics queue. #endregion Fields #region Constructors /// <summary> /// Creates a new map. /// </summary> /// <param name="filename">Where to save the file</param> /// <param name="mapName">What to name the map</param> /// <param name="sizeX">Map's X size</param> /// <param name="sizeY">Map's Y size</param> /// <param name="sizeZ">Map's Z size</param> public HypercubeMap(string filename, string mapName, short sizeX, short sizeY, short sizeZ) { CWMap = new Classicworld(sizeX, sizeZ, sizeY); HCSettings = new HypercubeMetadata {Building = true, Physics = true, History = true, SaveInterval = 10}; // -- Hypercube specific settings, woo. var joinPerm = ServerCore.Permholder.GetPermission("map.joinmap"); Joinperms.Add("map.joinmap", joinPerm); Showperms.Add("map.joinmap", joinPerm); Buildperms.Add("player.build", ServerCore.Permholder.GetPermission("player.build")); CWMap.MetadataParsers.Add("Hypercube", HCSettings); CWMap.MapName = mapName; CWMap.GeneratingSoftware = "Hypercube"; CWMap.GeneratorName = "Blank"; CWMap.CreatingService = "Classicube"; CWMap.CreatingUsername = "******"; CPESettings = (CPEMetadata) CWMap.MetadataParsers["CPE"]; if (CPESettings.CustomBlocksFallback == null) { CPESettings.CustomBlocksLevel = CPE.CustomBlocksSupportLevel; CPESettings.CustomBlocksVersion = CPE.CustomBlocksVersion; CPESettings.CustomBlocksFallback = new byte[256]; for (var i = 50; i < 66; i++) CPESettings.CustomBlocksFallback[i] = (byte)ServerCore.Blockholder.GetBlock(i).CPEReplace; CWMap.MetadataParsers["CPE"] = CPESettings; } CPESettings.TextureUrl = ""; CPESettings.EdgeBlock = 8; CPESettings.SideBlock = 7; CPESettings.SideLevel = (short)(CWMap.SizeY / 2); CPESettings.EnvMapAppearanceVersion = CPE.EnvMapAppearanceVersion; Lastclient = DateTime.UtcNow; Clients = new Dictionary<short, NetworkClient>(); Entities = new Dictionary<int, Entity>(); CreateClientList(); Path = filename; Save(Path); History = new MapHistory(this); for (sbyte i = 0; i < 127; i++) FreeIds.Push(i); _physicsBitmask = new byte[(CWMap.BlockData.Length / 8) + 1]; }