static void SaveTileTypes(BinBuffer bb) { // don't write anything for now, custom tiles aren't implemented return; #pragma warning disable 162 var map = new ModIdMap(TileID.Count, or => new TileRef(or).Resolve().Type, id => new TileRef(id)); #pragma warning restore 162 int ot = 0; int amt = 0; bool once = true; int op = bb.Position; bb.Write(0); for (int y = 0; y < Main.maxTilesY; y++) { for (int x = 0; x < Main.maxTilesX; x++) { int t = Main.tile[x, y] == null || !Main.tile[x, y].active() ? 0 : Main.tile[x, y].type; if (once) { ot = t; bb.Write(map.Register(new TileRef(t))); once = false; continue; } if (t == ot && amt < UInt16.MaxValue) { amt++; } else { bb.Write((ushort)amt); // write the amount of successing tiles of the same type, // instead of the type over and over again, to save some space amt = 0; ot = t; bb.Write(map.Register(new TileRef(t))); } } } bb.Write((ushort)amt); var p = bb.Position; bb.Position = op; bb.Write(p - op); // dictionary offset bb.Position = p; map.WriteDictionary(bb); }
//TODO: make these faster (especially write) static void Write2DArray(BinBuffer bb, ModIdMap map, int xLen, int yLen, Func <int, int, bool> isEmpty, Func <int, int, int> getElemV, Func <int, int, ObjectRef> getElemM) { var ov = 0; var ot = ObjectRef.Null; bool isOV = true; int amt = 0; bool once = true; int dictOffsetPosition = bb.Position; bb.Write(0); // dictionary position for (int y = 0; y < yLen; y++) { for (int x = 0; x < xLen; x++) { var e = isEmpty(x, y); var v = e ? 0 : getElemV(x, y); var t = ObjectRef.Null; var isV = e || v > 0; if (!e && v == 0) { t = getElemM(x, y); isV = false; } if (once) { if (isV) { ov = v; } else { ot = t; } isOV = isV; bb.Write((uint)(isV ? map.Register(v) : map.Register(t))); once = false; } else if (isV == isOV && (isV ? v == ov : t == ot) && amt < UInt16.MaxValue) { amt++; } else { bb.Write((ushort)amt); // write the amount of successing elements of the same type, // instead of the type over and over again, to save some space amt = 0; // amt == 0 -> one element if (isV) { ov = v; } else { ot = t; } isOV = isV; bb.Write((uint)(isV ? map.Register(v) : map.Register(t))); } } } bb.Write((ushort)amt); // write final amt var afterData = bb.Position; bb.Position = dictOffsetPosition; bb.Write(afterData); // dictionary position bb.Position = afterData; map.WriteDictionary(bb); }
//TODO: make these faster (especially write) static void Write2DArray(BinBuffer bb, ModIdMap map, int xLen, int yLen, Func <int, int, bool> isEmpty , Func <int, int, int > getElemV, Func<int, int, ObjectRef> getElemM) { var ov = 0; var ot = ObjectRef.Null; bool isOV = true; int amt = 0; bool once = true; int dictOffsetPosition = bb.Position; bb.Write(0); // dictionary position for (int y = 0; y < yLen; y++) for (int x = 0; x < xLen; x++) { var e = isEmpty(x, y); var v = e ? 0 : getElemV(x, y); var t = ObjectRef.Null; var isV = e || v > 0; if (!e && v == 0) { t = getElemM(x, y); isV = false; } if (once) { if (isV) ov = v; else ot = t; isOV = isV; bb.Write((uint)(isV ? map.Register(v) : map.Register(t))); once = false; } else if (isV == isOV && (isV ? v == ov : t == ot) && amt < UInt16.MaxValue) amt++; else { bb.Write((ushort)amt); // write the amount of successing elements of the same type, // instead of the type over and over again, to save some space amt = 0; // amt == 0 -> one element if (isV) ov = v; else ot = t; isOV = isV; bb.Write((uint)(isV ? map.Register(v) : map.Register(t))); } } bb.Write((ushort)amt); // write final amt var afterData = bb.Position; bb.Position = dictOffsetPosition; bb.Write(afterData); // dictionary position bb.Position = afterData; map.WriteDictionary(bb); }
static void SaveTileTypes(BinBuffer bb) { // don't write anything for now, custom tiles aren't implemented return; #pragma warning disable 162 var map = new ModIdMap(TileID.Count, or => new TileRef(or).Resolve().Type, id => new TileRef(id)); #pragma warning restore 162 int ot = 0; int amt = 0; bool once = true; int op = bb.Position; bb.Write(0); for (int y = 0; y < Main.maxTilesY; y++) for (int x = 0; x < Main.maxTilesX; x++) { int t = Main.tile[x, y] == null || !Main.tile[x, y].active() ? 0 : Main.tile[x, y].type; if (once) { ot = t; bb.Write(map.Register(new TileRef(t))); once = false; continue; } if (t == ot && amt < UInt16.MaxValue) amt++; else { bb.Write((ushort)amt); // write the amount of successing tiles of the same type, // instead of the type over and over again, to save some space amt = 0; ot = t; bb.Write(map.Register(new TileRef(t))); } } bb.Write((ushort)amt); var p = bb.Position; bb.Position = op; bb.Write(p - op); // dictionary offset bb.Position = p; map.WriteDictionary(bb); }