Support map sizes from 1-15 blocks too.

This commit is contained in:
UnknownShadow200 2018-01-26 18:56:36 +11:00
parent 8adae20194
commit cf8c251d43
4 changed files with 26 additions and 31 deletions

View File

@ -27,8 +27,12 @@ namespace MCGalaxy {
public ConfigAttribute Attrib; public ConfigAttribute Attrib;
public FieldInfo Field; public FieldInfo Field;
const BindingFlags flags = BindingFlags.Instance | BindingFlags.Static | public string Format(object instance) {
BindingFlags.Public | BindingFlags.NonPublic; object value = Field.GetValue(instance);
return Attrib.Name + " = " + Attrib.Serialise(value);
}
const BindingFlags flags = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;
public static ConfigElement[] GetAll(Type type) { public static ConfigElement[] GetAll(Type type) {
List<ConfigElement> elems = new List<ConfigElement>(); List<ConfigElement> elems = new List<ConfigElement>();
@ -59,10 +63,8 @@ namespace MCGalaxy {
} }
/// <summary> Writes all config elements to the given stream, grouped by named sections. </summary> /// <summary> Writes all config elements to the given stream, grouped by named sections. </summary>
public static void Serialise(ConfigElement[] elements, string suffix, public static void Serialise(ConfigElement[] elements, string suffix, StreamWriter dst, object instance) {
StreamWriter dst, object instance) { Dictionary<string, List<ConfigElement>> sections = new Dictionary<string, List<ConfigElement>>();
Dictionary<string, List<ConfigElement>> sections
= new Dictionary<string, List<ConfigElement>>();
foreach (ConfigElement elem in elements) { foreach (ConfigElement elem in elements) {
List<ConfigElement> members; List<ConfigElement> members;
@ -76,19 +78,10 @@ namespace MCGalaxy {
foreach (var kvp in sections) { foreach (var kvp in sections) {
dst.WriteLine("# " + kvp.Key + suffix); dst.WriteLine("# " + kvp.Key + suffix);
foreach (ConfigElement elem in kvp.Value) { foreach (ConfigElement elem in kvp.Value) {
object value = elem.Field.GetValue(instance); dst.WriteLine(elem.Format(instance));
dst.WriteLine(elem.Attrib.Name + " = " + elem.Attrib.Serialise(value));
} }
dst.WriteLine(); dst.WriteLine();
} }
} }
/// <summary> Writes all config elements to the given stream. </summary>
public static void SerialisePlain(ConfigElement[] elements, StreamWriter dst, object instance) {
foreach (ConfigElement elem in elements) {
object value = elem.Field.GetValue(instance);
dst.WriteLine(elem.Attrib.Name + " = " + elem.Attrib.Serialise(value));
}
}
} }
} }

View File

@ -101,8 +101,11 @@ namespace MCGalaxy.Games {
} }
public void Save(string mapName) { public void Save(string mapName) {
ConfigElement[] elements = elems;
using (StreamWriter w = new StreamWriter("CTF/" + mapName + ".config")) { using (StreamWriter w = new StreamWriter("CTF/" + mapName + ".config")) {
ConfigElement.SerialisePlain(elems, w, this); for (int i = 0; i < elements.Length; i++) {
w.WriteLine(elements[i].Format(this));
}
} }
} }

View File

@ -40,14 +40,15 @@ namespace MCGalaxy {
public sealed partial class Level : IDisposable { public sealed partial class Level : IDisposable {
public Level(string n, ushort x, ushort y, ushort z) { public Level(string name, ushort width, ushort height, ushort length) {
Width = x; Height = y; Length = z; if (width < 1) width = 1;
if (Width < 16) Width = 16; if (height < 1) height = 1;
if (Height < 16) Height = 16; if (length < 1) length = 1;
if (Length < 16) Length = 16;
Width = width; Height = height; Length = length;
for (int i = 0; i < CustomBlockDefs.Length; i++) for (int i = 0; i < CustomBlockDefs.Length; i++) {
CustomBlockDefs[i] = BlockDefinition.GlobalDefs[i]; CustomBlockDefs[i] = BlockDefinition.GlobalDefs[i];
}
LoadCoreProps(); LoadCoreProps();
for (int i = 0; i < blockAABBs.Length; i++) { for (int i = 0; i < blockAABBs.Length; i++) {
@ -56,10 +57,10 @@ namespace MCGalaxy {
} }
UpdateBlockHandlers(); UpdateBlockHandlers();
name = n; MapName = n.ToLower(); this.name = name; MapName = name.ToLower();
BlockDB = new BlockDB(this); BlockDB = new BlockDB(this);
Config.EdgeLevel = (short)(y / 2); Config.EdgeLevel = (short)(height / 2);
Config.CloudsHeight = (short)(y + 2); Config.CloudsHeight = (short)(height + 2);
blocks = new byte[Width * Height * Length]; blocks = new byte[Width * Height * Length];
ChunksX = Utils.CeilDiv16(Width); ChunksX = Utils.CeilDiv16(Width);

View File

@ -31,8 +31,7 @@ namespace MCGalaxy.Util {
} }
public bool Get(int x, int y, int z) { public bool Get(int x, int y, int z) {
int index = (x >> 4) + chunksX * int index = (x >> 4) + chunksX * ((z >> 4) + (y >> 4) * chunksZ);
((z >> 4) + (y >> 4) * chunksZ);
byte[] chunk = bits[index]; byte[] chunk = bits[index];
if (chunk == null) return false; if (chunk == null) return false;
@ -41,8 +40,7 @@ namespace MCGalaxy.Util {
} }
public void Set(int x, int y, int z, bool bit) { public void Set(int x, int y, int z, bool bit) {
int index = (x >> 4) + chunksX * int index = (x >> 4) + chunksX * ((z >> 4) + (y >> 4) * chunksZ);
((z >> 4) + (y >> 4) * chunksZ);
byte[] chunk = bits[index]; byte[] chunk = bits[index];
if (chunk == null) { if (chunk == null) {
chunk = new byte[(16 * 16 * 16) / 8]; chunk = new byte[(16 * 16 * 16) / 8];