From 480d8f65aeb13d0d96ba110a3de551e0d279f130 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Fri, 22 Jul 2016 23:49:25 +1000 Subject: [PATCH] Organise Level.Fields.cs --- Levels/Level.Fields.cs | 324 +++++++++++++++++++--------------------- Levels/Level.Physics.cs | 10 +- Levels/Level.cs | 4 - 3 files changed, 158 insertions(+), 180 deletions(-) diff --git a/Levels/Level.Fields.cs b/Levels/Level.Fields.cs index 6cb86524d..be77b37f1 100644 --- a/Levels/Level.Fields.cs +++ b/Levels/Level.Fields.cs @@ -17,72 +17,24 @@ */ using System; using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Runtime.InteropServices; using System.Threading; using MCGalaxy.BlockPhysics; using MCGalaxy.Config; using MCGalaxy.Games; -using MCGalaxy.Generator; -using MCGalaxy.Levels.IO; using Timer = System.Timers.Timer; - namespace MCGalaxy { public sealed partial class Level : IDisposable { - - public static bool cancelload; - public static bool cancelsave; - public static bool cancelphysics; - internal FastList ListCheck = new FastList(); //A list of blocks that need to be updated - internal FastList ListUpdate = new FastList(); //A list of block to change after calculation - internal SparseBitSet listCheckExists, listUpdateExists; - - internal readonly Dictionary leaves = new Dictionary(); - // Holds block state for leaf decay - - internal readonly Dictionary liquids = new Dictionary(); - // Holds random flow data for liqiud physics - bool physicssate = false; - [ConfigBool("Survival death", "General", null, false)] - public bool Death; + + public string name; + [ConfigString("MOTD", "General", null, "ignore", true)] + public string motd = "ignore"; + + public byte rotx, roty; + public ushort spawnx, spawny, spawnz; + public BlockDefinition[] CustomBlockDefs; public ExtrasCollection Extras = new ExtrasCollection(); - public bool GrassDestroy = true; - public bool GrassGrow = true; - [ConfigBool("Killer blocks", "General", null, true)] - public bool Killer = true; - public List UndoBuffer = new List(); - public List ZoneList; - [ConfigBool("Animal AI", "General", null, true)] - public bool ai = true; - public bool backedup; - public List blockCache = new List(); - [ConfigBool("Buildable", "Permissions", null, true)] - public bool Buildable = true; - [ConfigBool("Deletable", "Permissions", null, true)] - public bool Deletable = true; - [ConfigBool("UseBlockDB", "Other", null, true)] - public bool UseBlockDB = true; - [ConfigString("RealmOwner", "Other", null, "", true)] - public string RealmOwner = ""; - - [ConfigInt("Weather", "Env", null, 0, 0, 2)] - public int Weather; - [ConfigString("Texture", "Env", null, "", true)] - public string terrainUrl = ""; - [ConfigString("TexturePack", "Env", null, "", true)] - public string texturePackUrl = ""; - - public bool cancelsave1; - public bool cancelunload; - public bool changed; - public bool physicschanged { get { return ListCheck.Count > 0; } } - internal bool saveLevel = true; - - public bool ctfmode; - public int currentUndo; public ushort Width, Height, Length; // NOTE: These are for legacy code only, you should use upper case Width/Height/Length // as these correctly map Y to being Height @@ -91,80 +43,40 @@ namespace MCGalaxy { [Obsolete] public ushort depth; [Obsolete] public ushort length; - public bool IsMuseum { - get { return name.StartsWith("&cMuseum " + Server.DefaultColor, StringComparison.Ordinal); } - } + public bool IsMuseum { + get { return name.StartsWith("&cMuseum " + Server.DefaultColor, StringComparison.Ordinal); } + } + + public static bool cancelload; + public static bool cancelsave; + public static bool cancelphysics; + public bool cancelsave1; + public bool cancelunload; + public bool changed; + internal bool saveLevel = true; + + [ConfigBool("LoadOnGoto", "General", null, true)] + public bool loadOnGoto = true; + [ConfigString("Theme", "General", null, "Normal", true)] + public string theme = "Normal"; + [ConfigBool("Unload", "General", null, true)] + public bool unload = true; + [ConfigBool("WorldChat", "General", null, true)] + public bool worldChat = true; + + public bool bufferblocks = Server.bufferblocks; + internal readonly object queueLock = new object(), saveLock = new object(), savePropsLock = new object(); + public List blockqueue = new List(); + BufferedBlockSender bulkSender; + + public List UndoBuffer = new List(); + public List ZoneList; + public bool backedup; + public List blockCache = new List(); + [ConfigBool("UseBlockDB", "Other", null, true)] + public bool UseBlockDB = true; - [ConfigInt("Drown", "General", null, 70)] - public int drown = 70; - [ConfigBool("Edge water", "General", null, true)] - public bool edgeWater; - [ConfigInt("Fall", "General", null, 9)] - public int fall = 9; - [ConfigBool("Finite mode", "General", null, false)] - public bool finite; - [ConfigBool("GrowTrees", "General", null, false)] - public bool growTrees; - [ConfigBool("Guns", "General", null, false)] - public bool guns = false; public byte jailrotx, jailroty; - - /// Color of the clouds (RGB packed into an int). Set to -1 to use client defaults. - [ConfigString("CloudColor", "Env", null, "", true)] - public string CloudColor = ""; - - /// Color of the fog (RGB packed into an int). Set to -1 to use client defaults. - [ConfigString("FogColor", "Env", null, "", true)] - public string FogColor = ""; - - /// Color of the sky (RGB packed into an int). Set to -1 to use client defaults. - [ConfigString("SkyColor", "Env", null, "", true)] - public string SkyColor = ""; - - /// Color of the blocks in shadows (RGB packed into an int). Set to -1 to use client defaults. - [ConfigString("ShadowColor", "Env", null, "", true)] - public string ShadowColor = ""; - - /// Color of the blocks in the light (RGB packed into an int). Set to -1 to use client defaults. - [ConfigString("LightColor", "Env", null, "", true)] - public string LightColor = ""; - - /// Elevation of the "ocean" that surrounds maps. Default is map height / 2. - [ConfigInt("EdgeLevel", "Env", null, -1, short.MinValue, short.MaxValue)] - public int EdgeLevel; - - /// Elevation of the clouds. Default is map height + 2. - [ConfigInt("CloudsHeight", "Env", null, -1, short.MinValue, short.MaxValue)] - public int CloudsHeight; - - /// Max fog distance the client can see. - /// Default is 0, meaning use the client-side defined maximum fog distance. - [ConfigInt("MaxFog", "Env", null, 0, short.MinValue, short.MaxValue)] - public int MaxFogDistance; - - /// Clouds speed, in units of 256ths. Default is 256 (1 speed). - [ConfigInt("clouds-speed", "Env", null, 256, short.MinValue, short.MaxValue)] - public int CloudsSpeed = 256; - - /// Weather speed, in units of 256ths. Default is 256 (1 speed). - [ConfigInt("weather-speed", "Env", null, 256, short.MinValue, short.MaxValue)] - public int WeatherSpeed = 256; - - /// Weather fade, in units of 256ths. Default is 256 (1 speed). - [ConfigInt("weather-fade", "Env", null, 128, short.MinValue, short.MaxValue)] - public int WeatherFade = 128; - - /// The block which will be displayed on the horizon. - [ConfigInt("HorizonBlock", "Env", null, Block.water, 0, 255)] - public int HorizonBlock = Block.water; - - /// The block which will be displayed on the edge of the map. - [ConfigInt("EdgeBlock", "Env", null, Block.blackrock, 0, 255)] - public int EdgeBlock = Block.blackrock; - - public BlockDefinition[] CustomBlockDefs; - - [ConfigInt("JailX", "Jail", null, 0, 0, 65535)] public int jailx; [ConfigInt("JailY", "Jail", null, 0, 0, 65535)] @@ -172,18 +84,62 @@ namespace MCGalaxy { [ConfigInt("JailZ", "Jail", null, 0, 0, 65535)] public int jailz; - public int lastCheck; - public int lastUpdate; - [ConfigBool("LeafDecay", "General", null, false)] - public bool leafDecay; - [ConfigBool("LoadOnGoto", "General", null, true)] - public bool loadOnGoto = true; - [ConfigString("MOTD", "General", null, "ignore", true)] - public string motd = "ignore"; - public string name; - [ConfigInt("Physics overload", "General", null, 250)] - public int overload = 1500; + + // Environment settings + [ConfigInt("Weather", "Env", null, 0, 0, 2)] + public int Weather; + [ConfigString("Texture", "Env", null, "", true)] + public string terrainUrl = ""; + [ConfigString("TexturePack", "Env", null, "", true)] + public string texturePackUrl = ""; + /// Color of the clouds (RGB packed into an int). Set to -1 to use client defaults. + [ConfigString("CloudColor", "Env", null, "", true)] + public string CloudColor = ""; + /// Color of the fog (RGB packed into an int). Set to -1 to use client defaults. + [ConfigString("FogColor", "Env", null, "", true)] + public string FogColor = ""; + /// Color of the sky (RGB packed into an int). Set to -1 to use client defaults. + [ConfigString("SkyColor", "Env", null, "", true)] + public string SkyColor = ""; + /// Color of the blocks in shadows (RGB packed into an int). Set to -1 to use client defaults. + [ConfigString("ShadowColor", "Env", null, "", true)] + public string ShadowColor = ""; + /// Color of the blocks in the light (RGB packed into an int). Set to -1 to use client defaults. + [ConfigString("LightColor", "Env", null, "", true)] + public string LightColor = ""; + /// Elevation of the "ocean" that surrounds maps. Default is map height / 2. + [ConfigInt("EdgeLevel", "Env", null, -1, short.MinValue, short.MaxValue)] + public int EdgeLevel; + /// Elevation of the clouds. Default is map height + 2. + [ConfigInt("CloudsHeight", "Env", null, -1, short.MinValue, short.MaxValue)] + public int CloudsHeight; + /// Max fog distance the client can see. Default is 0, means use client-side defined max fog distance. + [ConfigInt("MaxFog", "Env", null, 0, short.MinValue, short.MaxValue)] + public int MaxFogDistance; + /// Clouds speed, in units of 256ths. Default is 256 (1 speed). + [ConfigInt("clouds-speed", "Env", null, 256, short.MinValue, short.MaxValue)] + public int CloudsSpeed = 256; + /// Weather speed, in units of 256ths. Default is 256 (1 speed). + [ConfigInt("weather-speed", "Env", null, 256, short.MinValue, short.MaxValue)] + public int WeatherSpeed = 256; + /// Weather fade, in units of 256ths. Default is 256 (1 speed). + [ConfigInt("weather-fade", "Env", null, 128, short.MinValue, short.MaxValue)] + public int WeatherFade = 128; + /// The block which will be displayed on the horizon. + [ConfigInt("HorizonBlock", "Env", null, Block.water, 0, 255)] + public int HorizonBlock = Block.water; + /// The block which will be displayed on the edge of the map. + [ConfigInt("EdgeBlock", "Env", null, Block.blackrock, 0, 255)] + public int EdgeBlock = Block.blackrock; + + // Permission settings + [ConfigString("RealmOwner", "Permissions", null, "", true)] + public string RealmOwner = ""; + [ConfigBool("Buildable", "Permissions", null, true)] + public bool Buildable = true; + [ConfigBool("Deletable", "Permissions", null, true)] + public bool Deletable = true; [ConfigPerm("PerBuildMax", "Permissions", null, LevelPermission.Nobody, true)] public LevelPermission perbuildmax = LevelPermission.Nobody; [ConfigPerm("PerBuild", "Permissions", null, LevelPermission.Guest, true)] @@ -198,46 +154,72 @@ namespace MCGalaxy { public List VisitWhitelist = new List(); [ConfigStringList("VisitBlacklist", "Permissions", null)] public List VisitBlacklist = new List(); + + + // Physics fields and settings + public int physics { + get { return Physicsint; } + set { + if (value > 0 && Physicsint == 0) StartPhysics(); + Physicsint = value; + } + } + int Physicsint; + public bool GrassDestroy = true; + public bool GrassGrow = true; + public bool physicschanged { get { return ListCheck.Count > 0; } } + public int currentUndo; + + [ConfigInt("Physics overload", "Physics", null, 250)] + public int overload = 1500; + [ConfigBool("RandomFlow", "Physics", null, true)] + public bool randomFlow = true; + [ConfigInt("Physics speed", "Physics", null, 250)] + public int speedPhysics = 250; + [ConfigBool("LeafDecay", "Physics", null, false)] + public bool leafDecay; + [ConfigBool("Finite mode", "Physics", null, false)] + public bool finite; + [ConfigBool("GrowTrees", "Physics", null, false)] + public bool growTrees; + [ConfigBool("Animal AI", "Physics", null, true)] + public bool ai = true; + + public int lastCheck, lastUpdate; + internal FastList ListCheck = new FastList(); //A list of blocks that need to be updated + internal FastList ListUpdate = new FastList(); //A list of block to change after calculation + internal SparseBitSet listCheckExists, listUpdateExists; public Random physRandom = new Random(); public bool physPause; public DateTime physResume; public Thread physThread; public Timer physTimer = new Timer(1000); - - public int physics { - get { return Physicsint; } - set { - if (value > 0 && Physicsint == 0) - StartPhysics(); - Physicsint = value; - } - } - int Physicsint; - - [ConfigBool("RandomFlow", "General", null, true)] - public bool randomFlow = true; - public byte rotx, roty; - public ushort spawnx, spawny, spawnz; - - [ConfigInt("Physics speed", "General", null, 250)] - public int speedPhysics = 250; - - [ConfigString("Theme", "General", null, "Normal", true)] - public string theme = "Normal"; - [ConfigBool("Unload", "General", null, true)] - public bool unload = true; - [ConfigBool("WorldChat", "General", null, true)] - public bool worldChat = true; - - public bool bufferblocks = Server.bufferblocks; - internal readonly object queueLock = new object(), saveLock = new object(), savePropsLock = new object(); - public List blockqueue = new List(); readonly object physThreadLock = new object(); - BufferedBlockSender bulkSender; - + bool physThreadStarted = false; + public List C4list = new List(); - // Games fields + internal readonly Dictionary leaves = new Dictionary(); // Block state for leaf decay + internal readonly Dictionary liquids = new Dictionary(); // Random flow data for liquid physics + + + // Survival settings + [ConfigInt("Drown", "Survival", null, 70)] + public int drown = 70; + [ConfigBool("Edge water", "Survival", null, true)] + public bool edgeWater; + [ConfigInt("Fall", "Survival", null, 9)] + public int fall = 9; + [ConfigBool("Guns", "Survival", null, false)] + public bool guns = false; + [ConfigBool("Survival death", "Survival", null, false)] + public bool Death; + [ConfigBool("Killer blocks", "Survival", null, true)] + public bool Killer = true; + + + // Games settings + public bool ctfmode; [ConfigInt("Likes", "Game", null, 0)] public int Likes; [ConfigInt("Dislikes", "Game", null, 0)] diff --git a/Levels/Level.Physics.cs b/Levels/Level.Physics.cs index 3c2b624ec..36b55ab8a 100644 --- a/Levels/Level.Physics.cs +++ b/Levels/Level.Physics.cs @@ -40,13 +40,13 @@ namespace MCGalaxy { public void StartPhysics() { lock (physThreadLock) { if (physThread != null && physThread.ThreadState == ThreadState.Running) return; - if (ListCheck.Count == 0 || physicssate) return; + if (ListCheck.Count == 0 || physThreadStarted) return; physThread = new Thread(PhysicsLoop); physThread.Name = "MCG_Physics"; PhysicsEnabled = true; physThread.Start(); - physicssate = true; + physThreadStarted = true; } } @@ -104,7 +104,7 @@ namespace MCGalaxy { wait = speedPhysics; } } - physicssate = false; + physThreadStarted = false; physThread.Abort(); } @@ -220,7 +220,7 @@ namespace MCGalaxy { } //Dont need to check physics here because if the list is active, then physics is active :) } - if (!physicssate && physics > 0) + if (!physThreadStarted && physics > 0) StartPhysics(); } catch { //s.Log("Warning-PhysicsCheck"); @@ -254,7 +254,7 @@ namespace MCGalaxy { } ListUpdate.Add(new Update(b, (byte)type, data)); - if (!physicssate && physics > 0) + if (!physThreadStarted && physics > 0) StartPhysics(); return true; } catch { diff --git a/Levels/Level.cs b/Levels/Level.cs index 687c613dc..d8d47816d 100644 --- a/Levels/Level.cs +++ b/Levels/Level.cs @@ -92,8 +92,6 @@ namespace MCGalaxy { public List players { get { return getPlayers(); } } - #region IDisposable Members - public void Dispose() { Extras.Clear(); liquids.Clear(); @@ -112,8 +110,6 @@ namespace MCGalaxy { } } - #endregion - /// Whether block changes made on this level should be /// saved to the BlockDB and .lvl files. public bool ShouldSaveChanges() {