Prefer strongly typed delegates

This commit is contained in:
UnknownShadow200 2017-06-15 18:34:45 +10:00
parent 67667486c2
commit 597fe6c727
35 changed files with 92 additions and 90 deletions

View File

@ -28,11 +28,8 @@ namespace MCGalaxy {
static void SetCoreProperties() {
for (int i = 0; i < Block.Count; i++)
Props[i] = new BlockProps((byte)i);
for (int i = 0; i < Block.Count; i++) {
// Fallback for unrecognised physics blocks
if (i >= CpeCount) Props[i].ConvertId = Block.orange;
Props[i] = BlockProps.MakeDefault();
for (int i = 0; i < Block.Count; i++) {
if ((i >= op_glass && i <= op_lava) || i == Invalid || i == rocketstart || i == blackrock)
Props[i].OPBlock = true;

View File

@ -182,7 +182,7 @@ namespace MCGalaxy {
Level[] loaded = LevelInfo.Loaded.Items;
foreach (Level lvl in loaded) {
lvl.SetBlockHandlers();
lvl.UpdateBlockHandlers();
}
}

View File

@ -138,7 +138,7 @@ namespace MCGalaxy {
GlobalProps = new BlockProps[Block.Count * 2];
for (int i = 0; i < Block.Count; i++) {
GlobalProps[i] = Block.Props[i];
GlobalProps[i + Block.Count] = new BlockProps((byte)i);
GlobalProps[i + Block.Count] = BlockProps.MakeDefault();
}
BlockProps.Load("global", GlobalProps, true);
}
@ -163,7 +163,7 @@ namespace MCGalaxy {
defs[raw] = def;
if (global) Block.SetDefaultNames();
if (!global) level.SetBlockHandler(ExtBlock.FromRaw(raw));
if (!global) level.UpdateBlockHandler(ExtBlock.FromRaw(raw));
Player[] players = PlayerInfo.Online.Items;
foreach (Player pl in players) {
@ -192,7 +192,7 @@ namespace MCGalaxy {
defs[raw] = null;
if (global) Block.SetDefaultNames();
if (!global) level.SetBlockHandler(ExtBlock.FromRaw(raw));
if (!global) level.UpdateBlockHandler(ExtBlock.FromRaw(raw));
Player[] players = PlayerInfo.Online.Items;
foreach (Player pl in players) {

View File

@ -29,9 +29,6 @@ namespace MCGalaxy.Blocks {
/// <summary> Extended and physics properties of a block. </summary>
public struct BlockProps {
/// <summary> Standard block id sent to clients in map and block update packets. </summary>
public byte ConvertId;
/// <summary> Block name used for in commands. </summary>
public string Name;
@ -69,11 +66,11 @@ namespace MCGalaxy.Blocks {
/// <summary> Whether the properties for this block have been modified and hence require saving. </summary>
public bool Changed;
public BlockProps(byte block) {
this = default(BlockProps);
ConvertId = block;
Name = "unknown";
ODoorId = Block.Invalid;
public static BlockProps MakeDefault() {
BlockProps props = default(BlockProps);
props.Name = "unknown";
props.ODoorId = Block.Invalid;
return props;
}

View File

@ -570,7 +570,7 @@ namespace MCGalaxy.Commands.CPE {
Level[] loaded = LevelInfo.Loaded.Items;
byte raw = block.BlockID;
foreach (Level lvl in loaded) {
if (lvl.CustomBlockDefs[raw] != null) continue;
if (lvl.CustomBlockDefs[raw] != BlockDefinition.GlobalDefs[raw]) continue;
lvl.BlockProps[block.Index] = props;
}
}
@ -585,7 +585,7 @@ namespace MCGalaxy.Commands.CPE {
if (block.BlockID < Block.CpeCount) {
BlockDefinition.GlobalProps[block.Index] = Block.Props[block.Index];
} else {
BlockDefinition.GlobalProps[block.Index] = new BlockProps(block.RawID);
BlockDefinition.GlobalProps[block.Index] = BlockProps.MakeDefault();
}
Level[] loaded = LevelInfo.Loaded.Items;

View File

@ -180,7 +180,7 @@ namespace MCGalaxy.Commands.World {
Level[] loaded = LevelInfo.Loaded.Items;
foreach (Level lvl in loaded) {
lvl.SetBlockHandler(block);
lvl.UpdateBlockHandler(block);
lvl.BlockProps[block.Index] = BlockDefinition.GlobalProps[block.Index];
}
} else if (scope == BlockDefinition.GlobalProps) {
@ -191,11 +191,11 @@ namespace MCGalaxy.Commands.World {
foreach (Level lvl in loaded) {
if (lvl.CustomBlockDefs[raw] != BlockDefinition.GlobalDefs[raw]) continue;
lvl.BlockProps[block.Index] = BlockDefinition.GlobalProps[block.Index];
lvl.SetBlockHandler(block);
lvl.UpdateBlockHandler(block);
}
} else {
BlockProps.Save("lvl_" + level.name, scope, i => SelectLevel(level, i));
level.SetBlockHandler(block);
level.UpdateBlockHandler(block);
}
}

View File

@ -34,7 +34,7 @@ namespace MCGalaxy.Drawing.Ops {
return (long)(Math.PI / 3 * (R * R * H));
}
public override void Perform(Vec3S32[] marks, Brush brush, Action<DrawOpBlock> output) {
public override void Perform(Vec3S32[] marks, Brush brush, DrawOpOutput output) {
Vec3U16 p1 = Clamp(Min), p2 = Clamp(Max);
Vec3S32 C = (Min + Max) / 2;
int height = Max.Y - Min.Y;
@ -67,7 +67,7 @@ namespace MCGalaxy.Drawing.Ops {
return (long)(outer - inner);
}
public override void Perform(Vec3S32[] marks, Brush brush, Action<DrawOpBlock> output) {
public override void Perform(Vec3S32[] marks, Brush brush, DrawOpOutput output) {
Vec3U16 p1 = Clamp(Min), p2 = Clamp(Max);
Vec3S32 C = (Min + Max) / 2;
int height = Max.Y - Min.Y;
@ -98,7 +98,7 @@ namespace MCGalaxy.Drawing.Ops {
return (long)(Math.PI / 3 * (R * R * H));
}
public override void Perform(Vec3S32[] marks, Brush brush, Action<DrawOpBlock> output) {
public override void Perform(Vec3S32[] marks, Brush brush, DrawOpOutput output) {
Vec3U16 p1 = Clamp(Min), p2 = Clamp(Max);
Vec3S32 C = (Min + Max) / 2;
int height = Max.Y - Min.Y;

View File

@ -42,7 +42,7 @@ namespace MCGalaxy.Drawing.Ops {
return (long)(Math.PI * 4.0 / 3.0 * (R * R * R));
}
public override void Perform(Vec3S32[] marks, Brush brush, Action<DrawOpBlock> output) {
public override void Perform(Vec3S32[] marks, Brush brush, DrawOpOutput output) {
int upper = (Radius + 1) * (Radius + 1);
Vec3U16 p1 = Clamp(Min), p2 = Clamp(Max);
Vec3S32 C = (Min + Max) / 2;
@ -69,7 +69,7 @@ namespace MCGalaxy.Drawing.Ops {
return (long)(outer - inner);
}
public override void Perform(Vec3S32[] marks, Brush brush, Action<DrawOpBlock> output) {
public override void Perform(Vec3S32[] marks, Brush brush, DrawOpOutput output) {
int upper = (Radius + 1) * (Radius + 1), inner = (Radius - 1) * (Radius - 1);
Vec3U16 p1 = Clamp(Min), p2 = Clamp(Max);
Vec3S32 C = (Min + Max) / 2;

View File

@ -34,7 +34,7 @@ namespace MCGalaxy.Drawing.Ops {
return (R * R * H) / 3;
}
public override void Perform(Vec3S32[] marks, Brush brush, Action<DrawOpBlock> output) {
public override void Perform(Vec3S32[] marks, Brush brush, DrawOpOutput output) {
Vec3U16 p1 = Clamp(Min), p2 = Clamp(Max);
Vec3S32 C = (Min + Max) / 2;
@ -66,7 +66,7 @@ namespace MCGalaxy.Drawing.Ops {
return outer - inner;
}
public override void Perform(Vec3S32[] marks, Brush brush, Action<DrawOpBlock> output) {
public override void Perform(Vec3S32[] marks, Brush brush, DrawOpOutput output) {
Vec3U16 p1 = Clamp(Min), p2 = Clamp(Max);
Vec3S32 C = (Min + Max) / 2;
int height = Max.Y - Min.Y;

View File

@ -29,7 +29,7 @@ namespace MCGalaxy.Drawing.Ops {
return (Max.X - Min.X + 1) * (Max.Y - Min.Y + 1) * (Max.Z - Min.Z + 1);
}
public override void Perform(Vec3S32[] marks, Brush brush, Action<DrawOpBlock> output) {
public override void Perform(Vec3S32[] marks, Brush brush, DrawOpOutput output) {
Vec3U16 p1 = Clamp(Min), p2 = Clamp(Max);
for (ushort y = p1.Y; y <= p2.Y; y++)
for (ushort z = p1.Z; z <= p2.Z; z++)
@ -51,7 +51,7 @@ namespace MCGalaxy.Drawing.Ops {
return xQuadsVol + yQuadsVol + zQuadzVol;
}
public override void Perform(Vec3S32[] marks, Brush brush, Action<DrawOpBlock> output) {
public override void Perform(Vec3S32[] marks, Brush brush, DrawOpOutput output) {
Vec3U16 p1 = Clamp(Min), p2 = Clamp(Max);
int lenX = (p2.X - p1.X + 1), lenY = (p2.Y - p1.Y + 1);
QuadY(p1.Y, p1.X, p1.Z, p2.X, p2.Z, brush, output);
@ -70,7 +70,7 @@ namespace MCGalaxy.Drawing.Ops {
}
protected void QuadX(ushort x, ushort y1, ushort z1, ushort y2, ushort z2,
Brush brush, Action<DrawOpBlock> output) {
Brush brush, DrawOpOutput output) {
for (ushort y = y1; y <= y2; y++)
for (ushort z = z1; z <= z2; z++)
{
@ -79,7 +79,7 @@ namespace MCGalaxy.Drawing.Ops {
}
protected void QuadY(ushort y, ushort x1, ushort z1, ushort x2, ushort z2,
Brush brush, Action<DrawOpBlock> output) {
Brush brush, DrawOpOutput output) {
for (ushort z = z1; z <= z2; z++)
for (ushort x = x1; x <= x2; x++)
{
@ -88,7 +88,7 @@ namespace MCGalaxy.Drawing.Ops {
}
protected void QuadZ(ushort z, ushort y1, ushort x1, ushort y2, ushort x2,
Brush brush, Action<DrawOpBlock> output) {
Brush brush, DrawOpOutput output) {
for (ushort y = y1; y <= y2; y++)
for (ushort x = x1; x <= x2; x++)
{
@ -107,7 +107,7 @@ namespace MCGalaxy.Drawing.Ops {
return xQuadsVol + zQuadsVol;
}
public override void Perform(Vec3S32[] marks, Brush brush, Action<DrawOpBlock> output) {
public override void Perform(Vec3S32[] marks, Brush brush, DrawOpOutput output) {
Vec3U16 p1 = Clamp(Min), p2 = Clamp(Max);
int lenX = (p2.X - p1.X + 1);
QuadX(p1.X, p1.Y, p1.Z, p2.Y, p2.Z, brush, output);
@ -129,7 +129,7 @@ namespace MCGalaxy.Drawing.Ops {
return horSidesvol + verSidesVol;
}
public override void Perform(Vec3S32[] marks, Brush brush, Action<DrawOpBlock> output) {
public override void Perform(Vec3S32[] marks, Brush brush, DrawOpOutput output) {
Vec3U16 p1 = Clamp(Min), p2 = Clamp(Max);
for (ushort y = p1.Y; y <= p2.Y; y++ ) {
output(Place(p1.X, y, p1.Z, brush));

View File

@ -26,7 +26,7 @@ namespace MCGalaxy.Drawing.Ops {
public override string Name { get { return "Hollow"; } }
public byte Skip;
public override void Perform(Vec3S32[] marks, Brush brush, Action<DrawOpBlock> output) {
public override void Perform(Vec3S32[] marks, Brush brush, DrawOpOutput output) {
Vec3U16 p1 = Clamp(Min), p2 = Clamp(Max);
ExtBlock air = ExtBlock.Air;
@ -62,7 +62,7 @@ namespace MCGalaxy.Drawing.Ops {
public override string Name { get { return "Outline"; } }
public ExtBlock Target;
public override void Perform(Vec3S32[] marks, Brush brush, Action<DrawOpBlock> output) {
public override void Perform(Vec3S32[] marks, Brush brush, DrawOpOutput output) {
Vec3U16 p1 = Clamp(Min), p2 = Clamp(Max);
for (ushort y = p1.Y; y <= p2.Y; y++)
for (ushort z = p1.Z; z <= p2.Z; z++)
@ -90,7 +90,7 @@ namespace MCGalaxy.Drawing.Ops {
public override string Name { get { return "Rainbow"; } }
public override void Perform(Vec3S32[] marks, Brush brush, Action<DrawOpBlock> output) {
public override void Perform(Vec3S32[] marks, Brush brush, DrawOpOutput output) {
Vec3U16 p1 = Clamp(Min), p2 = Clamp(Max);
int dx = Math.Abs(p1.X - p2.X), dy = Math.Abs(p1.Y - p2.Y), dz = Math.Abs(p1.Z - p2.Z);
byte stepX = 0, stepY = 0, stepZ = 0;

View File

@ -30,6 +30,9 @@ namespace MCGalaxy {
}
namespace MCGalaxy.Drawing.Ops {
/// <summary> Performs on action on a block output from a draw operation. </summary>
public delegate void DrawOpOutput(DrawOpBlock block);
public abstract partial class DrawOp {
@ -77,7 +80,7 @@ namespace MCGalaxy.Drawing.Ops {
/// Note that this estimate assumes that all possibly affected blocks will be changed by the drawing command. </summary>
public abstract long BlocksAffected(Level lvl, Vec3S32[] marks);
public abstract void Perform(Vec3S32[] marks, Brush brush, Action<DrawOpBlock> output);
public abstract void Perform(Vec3S32[] marks, Brush brush, DrawOpOutput output);
public virtual bool CanDraw(Vec3S32[] marks, Player p, long affected) {
if (p != null && affected > p.group.maxBlocks) {

View File

@ -49,7 +49,7 @@ namespace MCGalaxy.Drawing.Ops {
return true;
}
public override void Perform(Vec3S32[] marks, Brush brush, Action<DrawOpBlock> output) {
public override void Perform(Vec3S32[] marks, Brush brush, DrawOpOutput output) {
ushort x, y, z;
for (int i = 0; i < Positions.Count; i++) {
int pos = Positions[i];

View File

@ -50,7 +50,7 @@ namespace MCGalaxy.Drawing.Ops {
public override long BlocksAffected(Level lvl, Vec3S32[] marks) { return -1; }
public override void Perform(Vec3S32[] marks, Brush brush, Action<DrawOpBlock> output) {
public override void Perform(Vec3S32[] marks, Brush brush, DrawOpOutput output) {
this.output = output;
PerformHighlight();
this.output = null;
@ -71,7 +71,7 @@ namespace MCGalaxy.Drawing.Ops {
PerformOldHighlight(args);
}
Action<DrawOpBlock> output;
DrawOpOutput output;
Vec3U16 dims;
void HighlightBlock(BlockDBEntry e) {

View File

@ -38,7 +38,7 @@ namespace MCGalaxy.Drawing.Ops {
}
}
public override void Perform(Vec3S32[] marks, Brush brush, Action<DrawOpBlock> output) {
public override void Perform(Vec3S32[] marks, Brush brush, DrawOpOutput output) {
Vec3U16 p1 = Clamp(marks[0]), p2 = Clamp(marks[1]);
List<Vec3S32> buffer = new List<Vec3S32>();
DrawLine(p1.X, p1.Y, p1.Z, MaxLength, p2.X, p2.Y, p2.Z, buffer);

View File

@ -38,7 +38,7 @@ namespace MCGalaxy.Drawing.Ops {
return lenX * lenZ * 3;
}
public override void Perform(Vec3S32[] marks, Brush brush, Action<DrawOpBlock> output) {
public override void Perform(Vec3S32[] marks, Brush brush, DrawOpOutput output) {
width = Max.X - Min.X;
if (width % 2 != 0) { width++; Min.X--; }
width -= 2;

View File

@ -44,7 +44,7 @@ namespace MCGalaxy.Drawing.Ops {
Max.X += cState.Width - 1; Max.Y += cState.Height - 1; Max.Z += cState.Length - 1;
}
public override void Perform(Vec3S32[] marks, Brush brush, Action<DrawOpBlock> output) {
public override void Perform(Vec3S32[] marks, Brush brush, DrawOpOutput output) {
CopyState state = CopyState;
bool pasteAir = state.PasteAir;
Vec3U16 p1 = Clamp(Min), p2 = Clamp(Max);

View File

@ -50,7 +50,7 @@ namespace MCGalaxy.Drawing.Ops {
return total;
}
public override void Perform(Vec3S32[] marks, Brush brush, Action<DrawOpBlock> output) {
public override void Perform(Vec3S32[] marks, Brush brush, DrawOpOutput output) {
Vec3S32 p1 = Min, p2 = Max;
baseOp.SetLevel(Level);
baseOp.Player = Player;
@ -93,7 +93,7 @@ namespace MCGalaxy.Drawing.Ops {
public override string Name { get { return "Pyramid reverse"; } }
public override void Perform(Vec3S32[] marks, Brush brush, Action<DrawOpBlock> output) {
public override void Perform(Vec3S32[] marks, Brush brush, DrawOpOutput output) {
Vec3U16 p1 = Clamp(Min), p2 = Clamp(Max);
wallOp.Min = Min; wallOp.Max = Max;
baseOp.Min = Min; baseOp.Max = Max;

View File

@ -39,7 +39,7 @@ namespace MCGalaxy.Drawing.Ops {
public override long BlocksAffected(Level lvl, Vec3S32[] marks) { return -1; }
public override void Perform(Vec3S32[] marks, Brush brush, Action<DrawOpBlock> output) {
public override void Perform(Vec3S32[] marks, Brush brush, DrawOpOutput output) {
int[] ids = NameConverter.FindIds(Player.name);
if (ids.Length == 0) return;
@ -54,7 +54,7 @@ namespace MCGalaxy.Drawing.Ops {
this.output = null;
}
Action<DrawOpBlock> output;
DrawOpOutput output;
Vec3U16 dims;
void RedoBlock(BlockDBEntry e) {

View File

@ -39,7 +39,7 @@ namespace MCGalaxy.Drawing.Ops {
return (Max.X - Min.X + 1) * (Max.Y - Min.Y + 1) * (Max.Z - Min.Z + 1);
}
public override void Perform(Vec3S32[] marks, Brush brush, Action<DrawOpBlock> output) {
public override void Perform(Vec3S32[] marks, Brush brush, DrawOpOutput output) {
Vec3U16 p1 = Clamp(Min), p2 = Clamp(Max);
for (ushort y = p1.Y; y <= p2.Y; y++)
for (ushort z = p1.Z; z <= p2.Z; z++)
@ -67,7 +67,7 @@ namespace MCGalaxy.Drawing.Ops {
return (Max.X - Min.X + 1) * (Max.Y - Min.Y + 1) * (Max.Z - Min.Z + 1);
}
public override void Perform(Vec3S32[] marks, Brush brush, Action<DrawOpBlock> output) {
public override void Perform(Vec3S32[] marks, Brush brush, DrawOpOutput output) {
Vec3U16 p1 = Clamp(Min), p2 = Clamp(Max);
for (ushort y = p1.Y; y <= p2.Y; y++)
for (ushort z = p1.Z; z <= p2.Z; z++)

View File

@ -36,7 +36,7 @@ namespace MCGalaxy.Drawing.Ops {
public Level Source;
public override void Perform(Vec3S32[] marks, Brush brush, Action<DrawOpBlock> output) {
public override void Perform(Vec3S32[] marks, Brush brush, DrawOpOutput output) {
Max.X = Math.Min(Max.X, Source.Width - 1);
Max.Y = Math.Min(Max.Y, Source.Height - 1);
Max.Z = Math.Min(Max.Z, Source.Length - 1);

View File

@ -29,7 +29,7 @@ namespace MCGalaxy.Drawing.Ops {
return (int)(Math.PI * 4.0/3.0 * rx * ry * rz);
}
public override void Perform(Vec3S32[] marks, Brush brush, Action<DrawOpBlock> output) {
public override void Perform(Vec3S32[] marks, Brush brush, DrawOpOutput output) {
/* Courtesy of fCraft's awesome Open-Source'ness :D */
double cx = (Min.X + Max.X) / 2.0, cy = (Min.Y + Max.Y) / 2.0, cz = (Min.Z + Max.Z) / 2.0;
double rx = (Max.X - Min.X) / 2.0 + 0.25, ry = (Max.Y - Min.Y) / 2.0 + 0.25, rz = (Max.Z - Min.Z) / 2.0 + 0.25;
@ -56,7 +56,7 @@ namespace MCGalaxy.Drawing.Ops {
return (int)(Math.PI * 4.0/3.0 * rx * ry * rz);
}
public override void Perform(Vec3S32[] marks, Brush brush, Action<DrawOpBlock> output) {
public override void Perform(Vec3S32[] marks, Brush brush, DrawOpOutput output) {
/* Courtesy of fCraft's awesome Open-Source'ness :D */
double cx = (Min.X + Max.X) / 2.0, cy = (Min.Y + Max.Y) / 2.0, cz = (Min.Z + Max.Z) / 2.0;
double rx = (Max.X - Min.X) / 2.0 + 0.25, ry = (Max.Y - Min.Y) / 2.0 + 0.25, rz = (Max.Z - Min.Z) / 2.0 + 0.25;
@ -89,7 +89,7 @@ namespace MCGalaxy.Drawing.Ops {
return (int)(Math.PI * rx * rz * height);
}
public override void Perform(Vec3S32[] marks, Brush brush, Action<DrawOpBlock> output) {
public override void Perform(Vec3S32[] marks, Brush brush, DrawOpOutput output) {
/* Courtesy of fCraft's awesome Open-Source'ness :D */
double cx = (Min.X + Max.X) / 2.0, cz = (Min.Z + Max.Z) / 2.0;
double rx = (Max.X - Min.X) / 2.0 + 0.25, rz = (Max.Z - Min.Z) / 2.0 + 0.25;

View File

@ -30,7 +30,7 @@ namespace MCGalaxy.Drawing.Ops {
return (int)(2 * Math.PI * Math.PI * rTube * rTube * Math.Abs(rCentre));
}
public override void Perform(Vec3S32[] marks, Brush brush, Action<DrawOpBlock> output) {
public override void Perform(Vec3S32[] marks, Brush brush, DrawOpOutput output) {
double cx = (Min.X + Max.X) / 2.0, cy = (Min.Y + Max.Y) / 2.0, cz = (Min.Z + Max.Z) / 2.0;
double rx = (Max.X - Min.X) / 2.0 + 0.25, ry = (Max.Y - Min.Y) / 2.0 + 0.25, rz = (Max.Z - Min.Z) / 2.0 + 0.25;
double rTube = ry, rCentre = Math.Min(rx, rz) - rTube;

View File

@ -42,7 +42,7 @@ namespace MCGalaxy.Drawing.Ops {
public override long BlocksAffected(Level lvl, Vec3S32[] marks) { return Tree.EstimateBlocksAffected(); }
public override void Perform(Vec3S32[] marks, Brush brush, Action<DrawOpBlock> output) {
public override void Perform(Vec3S32[] marks, Brush brush, DrawOpOutput output) {
if (brush == null) brush = defBrush;
Vec3U16 P = Clamp(marks[0]);
Level lvl = Level;

View File

@ -33,7 +33,7 @@ namespace MCGalaxy.Drawing.Ops {
return (int)Math.Sqrt(s * (s - a) * (s - b) * (s - c));
}
public override void Perform(Vec3S32[] marks, Brush brush, Action<DrawOpBlock> output) {
public override void Perform(Vec3S32[] marks, Brush brush, DrawOpOutput output) {
Vec3F32 V1 = marks[0], V2 = marks[1], V3 = marks[2];
Vec3F32 N = Vec3F32.Cross(V2 - V1, V3 - V1);
N = Vec3F32.Normalise(N);

View File

@ -54,7 +54,7 @@ namespace MCGalaxy.Drawing.Ops {
public override long BlocksAffected(Level lvl, Vec3S32[] marks) { return -1; }
public override void Perform(Vec3S32[] marks, Brush brush, Action<DrawOpBlock> output) {
public override void Perform(Vec3S32[] marks, Brush brush, DrawOpOutput output) {
this.output = output;
PerformUndo();
this.output = null;
@ -75,7 +75,7 @@ namespace MCGalaxy.Drawing.Ops {
PerformOldUndo(args);
}
Action<DrawOpBlock> output;
DrawOpOutput output;
Vec3U16 dims;
void UndoBlock(BlockDBEntry e) {

View File

@ -30,7 +30,7 @@ namespace MCGalaxy.Drawing.Ops {
public override long BlocksAffected(Level lvl, Vec3S32[] marks) { return -1; }
public override void Perform(Vec3S32[] marks, Brush brush, Action<DrawOpBlock> output) {
public override void Perform(Vec3S32[] marks, Brush brush, DrawOpOutput output) {
if (Level.UndoBuffer.Count != Server.physUndo) {
int count = Level.currentUndo;
for (int i = count; i >= 0; i--) {

View File

@ -42,7 +42,7 @@ namespace MCGalaxy.Drawing.Ops {
int dirX, dirZ;
Vec3U16 pos;
public override void Perform(Vec3S32[] marks, Brush brush, Action<DrawOpBlock> output) {
public override void Perform(Vec3S32[] marks, Brush brush, DrawOpOutput output) {
Vec3U16 p1 = Clamp(marks[0]), p2 = Clamp(marks[1]);
if (Math.Abs(p2.X - p1.X) > Math.Abs(p2.Z - p1.Z))
dirX = p2.X > p1.X? 1 : -1;
@ -55,7 +55,7 @@ namespace MCGalaxy.Drawing.Ops {
}
}
void DrawLetter(Player p, Level lvl, char c, Brush brush, Action<DrawOpBlock> output) {
void DrawLetter(Player p, Level lvl, char c, Brush brush, DrawOpOutput output) {
if ((int)c >= 256 || letters[(int)c] == null) {
Player.Message(p, "\"" + c + "\" is not currently supported, replacing with space.");
pos.X = (ushort)(pos.X + dirX * 4 * Scale);

View File

@ -40,7 +40,7 @@ namespace MCGalaxy.Drawing.Ops {
Vec3S32 dx, dy, adj;
IPaletteMatcher selector;
public override void Perform(Vec3S32[] marks, Brush brush, Action<DrawOpBlock> output) {
public override void Perform(Vec3S32[] marks, Brush brush, DrawOpOutput output) {
CalcState(Direction);
selector = new RgbPaletteMatcher();
CalcLayerColors();
@ -108,7 +108,7 @@ namespace MCGalaxy.Drawing.Ops {
return entry;
}
void OutputPixel(Pixel P, Action<DrawOpBlock> output) {
void OutputPixel(Pixel P, DrawOpOutput output) {
ushort x = (ushort)(Origin.X + dx.X * P.X + dy.X * P.Y);
ushort y = (ushort)(Origin.Y + dx.Y * P.X + dy.Y * P.Y);
ushort z = (ushort)(Origin.Z + dx.Z * P.X + dy.Z * P.Y);

View File

@ -18,6 +18,7 @@
using System;
using System.Drawing;
using System.Drawing.Imaging;
using MCGalaxy.Drawing.Ops;
namespace MCGalaxy.Drawing {
@ -40,14 +41,14 @@ namespace MCGalaxy.Drawing {
data = bmp.LockBits(r, ImageLockMode.ReadOnly, bmp.PixelFormat);
}
public void Iterate(Action<DrawOpBlock> output,
Action<Pixel, Action<DrawOpBlock>> callback) {
public void Iterate(DrawOpOutput output,
Action<Pixel, DrawOpOutput> callback) {
if (data == null) IterateSlow(output, callback);
else IterateFast(output, callback);
}
unsafe void IterateFast(Action<DrawOpBlock> output,
Action<Pixel, Action<DrawOpBlock>> callback) {
unsafe void IterateFast(DrawOpOutput output,
Action<Pixel, DrawOpOutput> callback) {
Pixel pixel;
int width = bmp.Width, height = bmp.Height;
byte* scan0 = (byte*)data.Scan0;
@ -68,8 +69,8 @@ namespace MCGalaxy.Drawing {
}
}
void IterateSlow(Action<DrawOpBlock> output,
Action<Pixel, Action<DrawOpBlock>> callback) {
void IterateSlow(DrawOpOutput output,
Action<Pixel, DrawOpOutput> callback) {
Pixel pixel;
int width = bmp.Width, height = bmp.Height;
for (int y = 0; y < height; y++)

View File

@ -40,13 +40,13 @@ namespace MCGalaxy.Drawing.Transforms {
}
public override void Perform(Vec3S32[] marks, Player p, Level lvl,
DrawOp op, Brush brush, Action<DrawOpBlock> output) {
DrawOp op, Brush brush, DrawOpOutput output) {
P = (op.Min + op.Max) / 2;
if (!CentreOrigin) P = op.Origin;
op.Perform(marks, brush, b => OutputBlock(b, output));
}
void OutputBlock(DrawOpBlock b, Action<DrawOpBlock> output) {
void OutputBlock(DrawOpBlock b, DrawOpOutput output) {
double dx = b.X - P.X, dy = b.Y - P.Y, dz = b.Z - P.Z;
double rotX = 0, rotY = 0, rotZ = 0;

View File

@ -28,7 +28,7 @@ namespace MCGalaxy.Drawing.Transforms {
public static NoTransform Instance = new NoTransform();
public override void Perform(Vec3S32[] marks, Player p, Level lvl,
DrawOp op, Brush brush, Action<DrawOpBlock> output) {
DrawOp op, Brush brush, DrawOpOutput output) {
op.Perform(marks, brush, output);
}
}
@ -50,7 +50,7 @@ namespace MCGalaxy.Drawing.Transforms {
}
public override void Perform(Vec3S32[] marks, Player p, Level lvl,
DrawOp op, Brush brush, Action<DrawOpBlock> output) {
DrawOp op, Brush brush, DrawOpOutput output) {
P = (op.Min + op.Max) / 2;
dirX = 1; dirY = 1; dirZ = 1;
width = lvl.Width; height = lvl.Height; length = lvl.Length;
@ -66,7 +66,7 @@ namespace MCGalaxy.Drawing.Transforms {
op.Perform(marks, brush, b => OutputBlock(b, output));
}
void OutputBlock(DrawOpBlock b, Action<DrawOpBlock> output) {
void OutputBlock(DrawOpBlock b, DrawOpOutput output) {
int dx = b.X - P.X, dy = b.Y - P.Y, dz = b.Z - P.Z;
// Scale out until we hit the next block

View File

@ -35,6 +35,6 @@ namespace MCGalaxy.Drawing.Transforms {
public virtual void Configure(DrawOp op, Player p) { }
public abstract void Perform(Vec3S32[] marks, Player p, Level lvl,
DrawOp op, Brush brush, Action<DrawOpBlock> output);
DrawOp op, Brush brush, DrawOpOutput output);
}
}

View File

@ -20,6 +20,7 @@ using System.Collections.Generic;
namespace MCGalaxy.Generator {
/// <summary> Holds arguments for a map generator. </summary>
public struct MapGenArgs {
public Player Player;
public Level Level;
@ -27,6 +28,9 @@ namespace MCGalaxy.Generator {
public bool UseSeed;
public int Seed;
}
/// <summary> Represents a map generator, returning whether map generation succeeded or not. </summary>
public delegate bool MapGenerator(MapGenArgs args);
/// <summary> Maintains a list of map generator instances. </summary>
public static class MapGen {
@ -67,7 +71,7 @@ namespace MCGalaxy.Generator {
genArgs.UseSeed = args != "";
if (genArgs.UseSeed && !int.TryParse(args, out genArgs.Seed))
genArgs.Seed = args.GetHashCode();
Func<MapGenArgs, bool> generator = null;
MapGenerator generator = null;
simpleGens.TryGetValue(theme, out generator);
if (generator != null) return generator(genArgs);
@ -77,18 +81,18 @@ namespace MCGalaxy.Generator {
}
static Dictionary<string, Func<MapGenArgs, bool>> simpleGens, advGens;
public static void RegisterSimpleGen(string theme, Func<MapGenArgs, bool> gen) {
static Dictionary<string, MapGenerator> simpleGens, advGens;
public static void RegisterSimpleGen(string theme, MapGenerator gen) {
simpleGens[theme.ToLower()] = gen;
}
public static void RegisterAdvancedGen(string theme, Func<MapGenArgs, bool> gen) {
public static void RegisterAdvancedGen(string theme, MapGenerator gen) {
advGens[theme.ToLower()] = gen;
}
static MapGen() {
simpleGens = new Dictionary<string, Func<MapGenArgs, bool>>();
advGens = new Dictionary<string, Func<MapGenArgs, bool>>();
simpleGens = new Dictionary<string, MapGenerator>();
advGens = new Dictionary<string, MapGenerator>();
SimpleGen.RegisterGenerators();
fCraftMapGenerator.RegisterGenerators();

View File

@ -60,7 +60,7 @@ namespace MCGalaxy {
ExtBlock block = ExtBlock.FromIndex(i);
blockAABBs[i] = Block.BlockAABB(block, this);
}
SetBlockHandlers();
UpdateBlockHandlers();
name = n; MapName = n.ToLower();
BlockDB = new BlockDB(this);
@ -390,7 +390,7 @@ namespace MCGalaxy {
}
MCGalaxy.Blocks.BlockProps.Load("lvl_" + lvl.MapName, lvl.BlockProps, true);
lvl.SetBlockHandlers();
lvl.UpdateBlockHandlers();
}
public static bool CheckLoadOnGoto(string givenName) {
@ -487,13 +487,13 @@ namespace MCGalaxy {
public ushort smallX, smallY, smallZ;
}
public void SetBlockHandlers() {
public void UpdateBlockHandlers() {
for (int i = 0; i < BlockProps.Length; i++) {
SetBlockHandler(ExtBlock.FromIndex(i));
UpdateBlockHandler(ExtBlock.FromIndex(i));
}
}
public void SetBlockHandler(ExtBlock block) {
public void UpdateBlockHandler(ExtBlock block) {
bool nonSolid;
if (GetBlockDef(block) == null) {
nonSolid = Block.Walkthrough(Block.Convert(block.BlockID));
@ -512,7 +512,7 @@ namespace MCGalaxy {
public void UpdateCustomBlock(byte raw, BlockDefinition def) {
CustomBlockDefs[raw] = def;
ExtBlock block = ExtBlock.FromRaw(raw);
SetBlockHandler(block);
UpdateBlockHandler(block);
blockAABBs[block.Index] = Block.BlockAABB(block, this);
}
}