Organise Level.Fields.cs

This commit is contained in:
UnknownShadow200 2016-07-22 23:49:25 +10:00
parent c580484c4c
commit 480d8f65ae
3 changed files with 158 additions and 180 deletions

View File

@ -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<Check> ListCheck = new FastList<Check>(); //A list of blocks that need to be updated
internal FastList<Update> ListUpdate = new FastList<Update>(); //A list of block to change after calculation
internal SparseBitSet listCheckExists, listUpdateExists;
public string name;
[ConfigString("MOTD", "General", null, "ignore", true)]
public string motd = "ignore";
internal readonly Dictionary<int, sbyte> leaves = new Dictionary<int, sbyte>();
// Holds block state for leaf decay
internal readonly Dictionary<int, bool[]> liquids = new Dictionary<int, bool[]>();
// Holds random flow data for liqiud physics
bool physicssate = false;
[ConfigBool("Survival death", "General", null, false)]
public bool Death;
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<UndoPos> UndoBuffer = new List<UndoPos>();
public List<Zone> ZoneList;
[ConfigBool("Animal AI", "General", null, true)]
public bool ai = true;
public bool backedup;
public List<BlockPos> blockCache = new List<BlockPos>();
[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
@ -95,76 +47,36 @@ namespace MCGalaxy {
get { return name.StartsWith("&cMuseum " + Server.DefaultColor, StringComparison.Ordinal); }
}
[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 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<ulong> blockqueue = new List<ulong>();
BufferedBlockSender bulkSender;
public List<UndoPos> UndoBuffer = new List<UndoPos>();
public List<Zone> ZoneList;
public bool backedup;
public List<BlockPos> blockCache = new List<BlockPos>();
[ConfigBool("UseBlockDB", "Other", null, true)]
public bool UseBlockDB = true;
public byte jailrotx, jailroty;
/// <summary> Color of the clouds (RGB packed into an int). Set to -1 to use client defaults. </summary>
[ConfigString("CloudColor", "Env", null, "", true)]
public string CloudColor = "";
/// <summary> Color of the fog (RGB packed into an int). Set to -1 to use client defaults. </summary>
[ConfigString("FogColor", "Env", null, "", true)]
public string FogColor = "";
/// <summary> Color of the sky (RGB packed into an int). Set to -1 to use client defaults. </summary>
[ConfigString("SkyColor", "Env", null, "", true)]
public string SkyColor = "";
/// <summary> Color of the blocks in shadows (RGB packed into an int). Set to -1 to use client defaults. </summary>
[ConfigString("ShadowColor", "Env", null, "", true)]
public string ShadowColor = "";
/// <summary> Color of the blocks in the light (RGB packed into an int). Set to -1 to use client defaults. </summary>
[ConfigString("LightColor", "Env", null, "", true)]
public string LightColor = "";
/// <summary> Elevation of the "ocean" that surrounds maps. Default is map height / 2. </summary>
[ConfigInt("EdgeLevel", "Env", null, -1, short.MinValue, short.MaxValue)]
public int EdgeLevel;
/// <summary> Elevation of the clouds. Default is map height + 2. </summary>
[ConfigInt("CloudsHeight", "Env", null, -1, short.MinValue, short.MaxValue)]
public int CloudsHeight;
/// <summary> Max fog distance the client can see.
/// Default is 0, meaning use the client-side defined maximum fog distance. </summary>
[ConfigInt("MaxFog", "Env", null, 0, short.MinValue, short.MaxValue)]
public int MaxFogDistance;
/// <summary> Clouds speed, in units of 256ths. Default is 256 (1 speed). </summary>
[ConfigInt("clouds-speed", "Env", null, 256, short.MinValue, short.MaxValue)]
public int CloudsSpeed = 256;
/// <summary> Weather speed, in units of 256ths. Default is 256 (1 speed). </summary>
[ConfigInt("weather-speed", "Env", null, 256, short.MinValue, short.MaxValue)]
public int WeatherSpeed = 256;
/// <summary> Weather fade, in units of 256ths. Default is 256 (1 speed). </summary>
[ConfigInt("weather-fade", "Env", null, 128, short.MinValue, short.MaxValue)]
public int WeatherFade = 128;
/// <summary> The block which will be displayed on the horizon. </summary>
[ConfigInt("HorizonBlock", "Env", null, Block.water, 0, 255)]
public int HorizonBlock = Block.water;
/// <summary> The block which will be displayed on the edge of the map. </summary>
[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 = "";
/// <summary> Color of the clouds (RGB packed into an int). Set to -1 to use client defaults. </summary>
[ConfigString("CloudColor", "Env", null, "", true)]
public string CloudColor = "";
/// <summary> Color of the fog (RGB packed into an int). Set to -1 to use client defaults. </summary>
[ConfigString("FogColor", "Env", null, "", true)]
public string FogColor = "";
/// <summary> Color of the sky (RGB packed into an int). Set to -1 to use client defaults. </summary>
[ConfigString("SkyColor", "Env", null, "", true)]
public string SkyColor = "";
/// <summary> Color of the blocks in shadows (RGB packed into an int). Set to -1 to use client defaults. </summary>
[ConfigString("ShadowColor", "Env", null, "", true)]
public string ShadowColor = "";
/// <summary> Color of the blocks in the light (RGB packed into an int). Set to -1 to use client defaults. </summary>
[ConfigString("LightColor", "Env", null, "", true)]
public string LightColor = "";
/// <summary> Elevation of the "ocean" that surrounds maps. Default is map height / 2. </summary>
[ConfigInt("EdgeLevel", "Env", null, -1, short.MinValue, short.MaxValue)]
public int EdgeLevel;
/// <summary> Elevation of the clouds. Default is map height + 2. </summary>
[ConfigInt("CloudsHeight", "Env", null, -1, short.MinValue, short.MaxValue)]
public int CloudsHeight;
/// <summary> Max fog distance the client can see. Default is 0, means use client-side defined max fog distance. </summary>
[ConfigInt("MaxFog", "Env", null, 0, short.MinValue, short.MaxValue)]
public int MaxFogDistance;
/// <summary> Clouds speed, in units of 256ths. Default is 256 (1 speed). </summary>
[ConfigInt("clouds-speed", "Env", null, 256, short.MinValue, short.MaxValue)]
public int CloudsSpeed = 256;
/// <summary> Weather speed, in units of 256ths. Default is 256 (1 speed). </summary>
[ConfigInt("weather-speed", "Env", null, 256, short.MinValue, short.MaxValue)]
public int WeatherSpeed = 256;
/// <summary> Weather fade, in units of 256ths. Default is 256 (1 speed). </summary>
[ConfigInt("weather-fade", "Env", null, 128, short.MinValue, short.MaxValue)]
public int WeatherFade = 128;
/// <summary> The block which will be displayed on the horizon. </summary>
[ConfigInt("HorizonBlock", "Env", null, Block.water, 0, 255)]
public int HorizonBlock = Block.water;
/// <summary> The block which will be displayed on the edge of the map. </summary>
[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)]
@ -199,45 +155,71 @@ namespace MCGalaxy {
[ConfigStringList("VisitBlacklist", "Permissions", null)]
public List<string> VisitBlacklist = new List<string>();
// 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<Check> ListCheck = new FastList<Check>(); //A list of blocks that need to be updated
internal FastList<Update> ListUpdate = new FastList<Update>(); //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<ulong> blockqueue = new List<ulong>();
readonly object physThreadLock = new object();
BufferedBlockSender bulkSender;
bool physThreadStarted = false;
public List<C4Data> C4list = new List<C4Data>();
// Games fields
internal readonly Dictionary<int, sbyte> leaves = new Dictionary<int, sbyte>(); // Block state for leaf decay
internal readonly Dictionary<int, bool[]> liquids = new Dictionary<int, bool[]>(); // 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)]

View File

@ -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 {

View File

@ -92,8 +92,6 @@ namespace MCGalaxy {
public List<Player> players { get { return getPlayers(); } }
#region IDisposable Members
public void Dispose() {
Extras.Clear();
liquids.Clear();
@ -112,8 +110,6 @@ namespace MCGalaxy {
}
}
#endregion
/// <summary> Whether block changes made on this level should be
/// saved to the BlockDB and .lvl files. </summary>
public bool ShouldSaveChanges() {