mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-24 05:03:34 -04:00
Prefer strongly typed delegates
This commit is contained in:
parent
67667486c2
commit
597fe6c727
@ -28,11 +28,8 @@ namespace MCGalaxy {
|
|||||||
|
|
||||||
static void SetCoreProperties() {
|
static void SetCoreProperties() {
|
||||||
for (int i = 0; i < Block.Count; i++)
|
for (int i = 0; i < Block.Count; i++)
|
||||||
Props[i] = new BlockProps((byte)i);
|
Props[i] = BlockProps.MakeDefault();
|
||||||
for (int i = 0; i < Block.Count; i++) {
|
for (int i = 0; i < Block.Count; i++) {
|
||||||
// Fallback for unrecognised physics blocks
|
|
||||||
if (i >= CpeCount) Props[i].ConvertId = Block.orange;
|
|
||||||
|
|
||||||
if ((i >= op_glass && i <= op_lava) || i == Invalid || i == rocketstart || i == blackrock)
|
if ((i >= op_glass && i <= op_lava) || i == Invalid || i == rocketstart || i == blackrock)
|
||||||
Props[i].OPBlock = true;
|
Props[i].OPBlock = true;
|
||||||
|
|
||||||
|
@ -182,7 +182,7 @@ namespace MCGalaxy {
|
|||||||
|
|
||||||
Level[] loaded = LevelInfo.Loaded.Items;
|
Level[] loaded = LevelInfo.Loaded.Items;
|
||||||
foreach (Level lvl in loaded) {
|
foreach (Level lvl in loaded) {
|
||||||
lvl.SetBlockHandlers();
|
lvl.UpdateBlockHandlers();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@ namespace MCGalaxy {
|
|||||||
GlobalProps = new BlockProps[Block.Count * 2];
|
GlobalProps = new BlockProps[Block.Count * 2];
|
||||||
for (int i = 0; i < Block.Count; i++) {
|
for (int i = 0; i < Block.Count; i++) {
|
||||||
GlobalProps[i] = Block.Props[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);
|
BlockProps.Load("global", GlobalProps, true);
|
||||||
}
|
}
|
||||||
@ -163,7 +163,7 @@ namespace MCGalaxy {
|
|||||||
|
|
||||||
defs[raw] = def;
|
defs[raw] = def;
|
||||||
if (global) Block.SetDefaultNames();
|
if (global) Block.SetDefaultNames();
|
||||||
if (!global) level.SetBlockHandler(ExtBlock.FromRaw(raw));
|
if (!global) level.UpdateBlockHandler(ExtBlock.FromRaw(raw));
|
||||||
|
|
||||||
Player[] players = PlayerInfo.Online.Items;
|
Player[] players = PlayerInfo.Online.Items;
|
||||||
foreach (Player pl in players) {
|
foreach (Player pl in players) {
|
||||||
@ -192,7 +192,7 @@ namespace MCGalaxy {
|
|||||||
|
|
||||||
defs[raw] = null;
|
defs[raw] = null;
|
||||||
if (global) Block.SetDefaultNames();
|
if (global) Block.SetDefaultNames();
|
||||||
if (!global) level.SetBlockHandler(ExtBlock.FromRaw(raw));
|
if (!global) level.UpdateBlockHandler(ExtBlock.FromRaw(raw));
|
||||||
|
|
||||||
Player[] players = PlayerInfo.Online.Items;
|
Player[] players = PlayerInfo.Online.Items;
|
||||||
foreach (Player pl in players) {
|
foreach (Player pl in players) {
|
||||||
|
@ -29,9 +29,6 @@ namespace MCGalaxy.Blocks {
|
|||||||
/// <summary> Extended and physics properties of a block. </summary>
|
/// <summary> Extended and physics properties of a block. </summary>
|
||||||
public struct BlockProps {
|
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>
|
/// <summary> Block name used for in commands. </summary>
|
||||||
public string Name;
|
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>
|
/// <summary> Whether the properties for this block have been modified and hence require saving. </summary>
|
||||||
public bool Changed;
|
public bool Changed;
|
||||||
|
|
||||||
public BlockProps(byte block) {
|
public static BlockProps MakeDefault() {
|
||||||
this = default(BlockProps);
|
BlockProps props = default(BlockProps);
|
||||||
ConvertId = block;
|
props.Name = "unknown";
|
||||||
Name = "unknown";
|
props.ODoorId = Block.Invalid;
|
||||||
ODoorId = Block.Invalid;
|
return props;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -570,7 +570,7 @@ namespace MCGalaxy.Commands.CPE {
|
|||||||
Level[] loaded = LevelInfo.Loaded.Items;
|
Level[] loaded = LevelInfo.Loaded.Items;
|
||||||
byte raw = block.BlockID;
|
byte raw = block.BlockID;
|
||||||
foreach (Level lvl in loaded) {
|
foreach (Level lvl in loaded) {
|
||||||
if (lvl.CustomBlockDefs[raw] != null) continue;
|
if (lvl.CustomBlockDefs[raw] != BlockDefinition.GlobalDefs[raw]) continue;
|
||||||
lvl.BlockProps[block.Index] = props;
|
lvl.BlockProps[block.Index] = props;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -585,7 +585,7 @@ namespace MCGalaxy.Commands.CPE {
|
|||||||
if (block.BlockID < Block.CpeCount) {
|
if (block.BlockID < Block.CpeCount) {
|
||||||
BlockDefinition.GlobalProps[block.Index] = Block.Props[block.Index];
|
BlockDefinition.GlobalProps[block.Index] = Block.Props[block.Index];
|
||||||
} else {
|
} else {
|
||||||
BlockDefinition.GlobalProps[block.Index] = new BlockProps(block.RawID);
|
BlockDefinition.GlobalProps[block.Index] = BlockProps.MakeDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
Level[] loaded = LevelInfo.Loaded.Items;
|
Level[] loaded = LevelInfo.Loaded.Items;
|
||||||
|
@ -180,7 +180,7 @@ namespace MCGalaxy.Commands.World {
|
|||||||
Level[] loaded = LevelInfo.Loaded.Items;
|
Level[] loaded = LevelInfo.Loaded.Items;
|
||||||
|
|
||||||
foreach (Level lvl in loaded) {
|
foreach (Level lvl in loaded) {
|
||||||
lvl.SetBlockHandler(block);
|
lvl.UpdateBlockHandler(block);
|
||||||
lvl.BlockProps[block.Index] = BlockDefinition.GlobalProps[block.Index];
|
lvl.BlockProps[block.Index] = BlockDefinition.GlobalProps[block.Index];
|
||||||
}
|
}
|
||||||
} else if (scope == BlockDefinition.GlobalProps) {
|
} else if (scope == BlockDefinition.GlobalProps) {
|
||||||
@ -191,11 +191,11 @@ namespace MCGalaxy.Commands.World {
|
|||||||
foreach (Level lvl in loaded) {
|
foreach (Level lvl in loaded) {
|
||||||
if (lvl.CustomBlockDefs[raw] != BlockDefinition.GlobalDefs[raw]) continue;
|
if (lvl.CustomBlockDefs[raw] != BlockDefinition.GlobalDefs[raw]) continue;
|
||||||
lvl.BlockProps[block.Index] = BlockDefinition.GlobalProps[block.Index];
|
lvl.BlockProps[block.Index] = BlockDefinition.GlobalProps[block.Index];
|
||||||
lvl.SetBlockHandler(block);
|
lvl.UpdateBlockHandler(block);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
BlockProps.Save("lvl_" + level.name, scope, i => SelectLevel(level, i));
|
BlockProps.Save("lvl_" + level.name, scope, i => SelectLevel(level, i));
|
||||||
level.SetBlockHandler(block);
|
level.UpdateBlockHandler(block);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ namespace MCGalaxy.Drawing.Ops {
|
|||||||
return (long)(Math.PI / 3 * (R * R * H));
|
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);
|
Vec3U16 p1 = Clamp(Min), p2 = Clamp(Max);
|
||||||
Vec3S32 C = (Min + Max) / 2;
|
Vec3S32 C = (Min + Max) / 2;
|
||||||
int height = Max.Y - Min.Y;
|
int height = Max.Y - Min.Y;
|
||||||
@ -67,7 +67,7 @@ namespace MCGalaxy.Drawing.Ops {
|
|||||||
return (long)(outer - inner);
|
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);
|
Vec3U16 p1 = Clamp(Min), p2 = Clamp(Max);
|
||||||
Vec3S32 C = (Min + Max) / 2;
|
Vec3S32 C = (Min + Max) / 2;
|
||||||
int height = Max.Y - Min.Y;
|
int height = Max.Y - Min.Y;
|
||||||
@ -98,7 +98,7 @@ namespace MCGalaxy.Drawing.Ops {
|
|||||||
return (long)(Math.PI / 3 * (R * R * H));
|
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);
|
Vec3U16 p1 = Clamp(Min), p2 = Clamp(Max);
|
||||||
Vec3S32 C = (Min + Max) / 2;
|
Vec3S32 C = (Min + Max) / 2;
|
||||||
int height = Max.Y - Min.Y;
|
int height = Max.Y - Min.Y;
|
||||||
|
@ -42,7 +42,7 @@ namespace MCGalaxy.Drawing.Ops {
|
|||||||
return (long)(Math.PI * 4.0 / 3.0 * (R * R * R));
|
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);
|
int upper = (Radius + 1) * (Radius + 1);
|
||||||
Vec3U16 p1 = Clamp(Min), p2 = Clamp(Max);
|
Vec3U16 p1 = Clamp(Min), p2 = Clamp(Max);
|
||||||
Vec3S32 C = (Min + Max) / 2;
|
Vec3S32 C = (Min + Max) / 2;
|
||||||
@ -69,7 +69,7 @@ namespace MCGalaxy.Drawing.Ops {
|
|||||||
return (long)(outer - inner);
|
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);
|
int upper = (Radius + 1) * (Radius + 1), inner = (Radius - 1) * (Radius - 1);
|
||||||
Vec3U16 p1 = Clamp(Min), p2 = Clamp(Max);
|
Vec3U16 p1 = Clamp(Min), p2 = Clamp(Max);
|
||||||
Vec3S32 C = (Min + Max) / 2;
|
Vec3S32 C = (Min + Max) / 2;
|
||||||
|
@ -34,7 +34,7 @@ namespace MCGalaxy.Drawing.Ops {
|
|||||||
return (R * R * H) / 3;
|
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);
|
Vec3U16 p1 = Clamp(Min), p2 = Clamp(Max);
|
||||||
Vec3S32 C = (Min + Max) / 2;
|
Vec3S32 C = (Min + Max) / 2;
|
||||||
|
|
||||||
@ -66,7 +66,7 @@ namespace MCGalaxy.Drawing.Ops {
|
|||||||
return outer - inner;
|
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);
|
Vec3U16 p1 = Clamp(Min), p2 = Clamp(Max);
|
||||||
Vec3S32 C = (Min + Max) / 2;
|
Vec3S32 C = (Min + Max) / 2;
|
||||||
int height = Max.Y - Min.Y;
|
int height = Max.Y - Min.Y;
|
||||||
|
@ -29,7 +29,7 @@ namespace MCGalaxy.Drawing.Ops {
|
|||||||
return (Max.X - Min.X + 1) * (Max.Y - Min.Y + 1) * (Max.Z - Min.Z + 1);
|
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);
|
Vec3U16 p1 = Clamp(Min), p2 = Clamp(Max);
|
||||||
for (ushort y = p1.Y; y <= p2.Y; y++)
|
for (ushort y = p1.Y; y <= p2.Y; y++)
|
||||||
for (ushort z = p1.Z; z <= p2.Z; z++)
|
for (ushort z = p1.Z; z <= p2.Z; z++)
|
||||||
@ -51,7 +51,7 @@ namespace MCGalaxy.Drawing.Ops {
|
|||||||
return xQuadsVol + yQuadsVol + zQuadzVol;
|
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);
|
Vec3U16 p1 = Clamp(Min), p2 = Clamp(Max);
|
||||||
int lenX = (p2.X - p1.X + 1), lenY = (p2.Y - p1.Y + 1);
|
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);
|
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,
|
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 y = y1; y <= y2; y++)
|
||||||
for (ushort z = z1; z <= z2; z++)
|
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,
|
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 z = z1; z <= z2; z++)
|
||||||
for (ushort x = x1; x <= x2; x++)
|
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,
|
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 y = y1; y <= y2; y++)
|
||||||
for (ushort x = x1; x <= x2; x++)
|
for (ushort x = x1; x <= x2; x++)
|
||||||
{
|
{
|
||||||
@ -107,7 +107,7 @@ namespace MCGalaxy.Drawing.Ops {
|
|||||||
return xQuadsVol + zQuadsVol;
|
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);
|
Vec3U16 p1 = Clamp(Min), p2 = Clamp(Max);
|
||||||
int lenX = (p2.X - p1.X + 1);
|
int lenX = (p2.X - p1.X + 1);
|
||||||
QuadX(p1.X, p1.Y, p1.Z, p2.Y, p2.Z, brush, output);
|
QuadX(p1.X, p1.Y, p1.Z, p2.Y, p2.Z, brush, output);
|
||||||
@ -129,7 +129,7 @@ namespace MCGalaxy.Drawing.Ops {
|
|||||||
return horSidesvol + verSidesVol;
|
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);
|
Vec3U16 p1 = Clamp(Min), p2 = Clamp(Max);
|
||||||
for (ushort y = p1.Y; y <= p2.Y; y++ ) {
|
for (ushort y = p1.Y; y <= p2.Y; y++ ) {
|
||||||
output(Place(p1.X, y, p1.Z, brush));
|
output(Place(p1.X, y, p1.Z, brush));
|
||||||
|
@ -26,7 +26,7 @@ namespace MCGalaxy.Drawing.Ops {
|
|||||||
public override string Name { get { return "Hollow"; } }
|
public override string Name { get { return "Hollow"; } }
|
||||||
public byte Skip;
|
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);
|
Vec3U16 p1 = Clamp(Min), p2 = Clamp(Max);
|
||||||
ExtBlock air = ExtBlock.Air;
|
ExtBlock air = ExtBlock.Air;
|
||||||
|
|
||||||
@ -62,7 +62,7 @@ namespace MCGalaxy.Drawing.Ops {
|
|||||||
public override string Name { get { return "Outline"; } }
|
public override string Name { get { return "Outline"; } }
|
||||||
public ExtBlock Target;
|
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);
|
Vec3U16 p1 = Clamp(Min), p2 = Clamp(Max);
|
||||||
for (ushort y = p1.Y; y <= p2.Y; y++)
|
for (ushort y = p1.Y; y <= p2.Y; y++)
|
||||||
for (ushort z = p1.Z; z <= p2.Z; z++)
|
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 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);
|
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);
|
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;
|
byte stepX = 0, stepY = 0, stepZ = 0;
|
||||||
|
@ -30,6 +30,9 @@ namespace MCGalaxy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
namespace MCGalaxy.Drawing.Ops {
|
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 {
|
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>
|
/// 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 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) {
|
public virtual bool CanDraw(Vec3S32[] marks, Player p, long affected) {
|
||||||
if (p != null && affected > p.group.maxBlocks) {
|
if (p != null && affected > p.group.maxBlocks) {
|
||||||
|
@ -49,7 +49,7 @@ namespace MCGalaxy.Drawing.Ops {
|
|||||||
return true;
|
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;
|
ushort x, y, z;
|
||||||
for (int i = 0; i < Positions.Count; i++) {
|
for (int i = 0; i < Positions.Count; i++) {
|
||||||
int pos = Positions[i];
|
int pos = Positions[i];
|
||||||
|
@ -50,7 +50,7 @@ namespace MCGalaxy.Drawing.Ops {
|
|||||||
|
|
||||||
public override long BlocksAffected(Level lvl, Vec3S32[] marks) { return -1; }
|
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;
|
this.output = output;
|
||||||
PerformHighlight();
|
PerformHighlight();
|
||||||
this.output = null;
|
this.output = null;
|
||||||
@ -71,7 +71,7 @@ namespace MCGalaxy.Drawing.Ops {
|
|||||||
PerformOldHighlight(args);
|
PerformOldHighlight(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
Action<DrawOpBlock> output;
|
DrawOpOutput output;
|
||||||
Vec3U16 dims;
|
Vec3U16 dims;
|
||||||
|
|
||||||
void HighlightBlock(BlockDBEntry e) {
|
void HighlightBlock(BlockDBEntry e) {
|
||||||
|
@ -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]);
|
Vec3U16 p1 = Clamp(marks[0]), p2 = Clamp(marks[1]);
|
||||||
List<Vec3S32> buffer = new List<Vec3S32>();
|
List<Vec3S32> buffer = new List<Vec3S32>();
|
||||||
DrawLine(p1.X, p1.Y, p1.Z, MaxLength, p2.X, p2.Y, p2.Z, buffer);
|
DrawLine(p1.X, p1.Y, p1.Z, MaxLength, p2.X, p2.Y, p2.Z, buffer);
|
||||||
|
@ -38,7 +38,7 @@ namespace MCGalaxy.Drawing.Ops {
|
|||||||
return lenX * lenZ * 3;
|
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;
|
width = Max.X - Min.X;
|
||||||
if (width % 2 != 0) { width++; Min.X--; }
|
if (width % 2 != 0) { width++; Min.X--; }
|
||||||
width -= 2;
|
width -= 2;
|
||||||
|
@ -44,7 +44,7 @@ namespace MCGalaxy.Drawing.Ops {
|
|||||||
Max.X += cState.Width - 1; Max.Y += cState.Height - 1; Max.Z += cState.Length - 1;
|
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;
|
CopyState state = CopyState;
|
||||||
bool pasteAir = state.PasteAir;
|
bool pasteAir = state.PasteAir;
|
||||||
Vec3U16 p1 = Clamp(Min), p2 = Clamp(Max);
|
Vec3U16 p1 = Clamp(Min), p2 = Clamp(Max);
|
||||||
|
@ -50,7 +50,7 @@ namespace MCGalaxy.Drawing.Ops {
|
|||||||
return total;
|
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;
|
Vec3S32 p1 = Min, p2 = Max;
|
||||||
baseOp.SetLevel(Level);
|
baseOp.SetLevel(Level);
|
||||||
baseOp.Player = Player;
|
baseOp.Player = Player;
|
||||||
@ -93,7 +93,7 @@ namespace MCGalaxy.Drawing.Ops {
|
|||||||
|
|
||||||
public override string Name { get { return "Pyramid reverse"; } }
|
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);
|
Vec3U16 p1 = Clamp(Min), p2 = Clamp(Max);
|
||||||
wallOp.Min = Min; wallOp.Max = Max;
|
wallOp.Min = Min; wallOp.Max = Max;
|
||||||
baseOp.Min = Min; baseOp.Max = Max;
|
baseOp.Min = Min; baseOp.Max = Max;
|
||||||
|
@ -39,7 +39,7 @@ namespace MCGalaxy.Drawing.Ops {
|
|||||||
|
|
||||||
public override long BlocksAffected(Level lvl, Vec3S32[] marks) { return -1; }
|
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);
|
int[] ids = NameConverter.FindIds(Player.name);
|
||||||
if (ids.Length == 0) return;
|
if (ids.Length == 0) return;
|
||||||
|
|
||||||
@ -54,7 +54,7 @@ namespace MCGalaxy.Drawing.Ops {
|
|||||||
this.output = null;
|
this.output = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Action<DrawOpBlock> output;
|
DrawOpOutput output;
|
||||||
Vec3U16 dims;
|
Vec3U16 dims;
|
||||||
|
|
||||||
void RedoBlock(BlockDBEntry e) {
|
void RedoBlock(BlockDBEntry e) {
|
||||||
|
@ -39,7 +39,7 @@ namespace MCGalaxy.Drawing.Ops {
|
|||||||
return (Max.X - Min.X + 1) * (Max.Y - Min.Y + 1) * (Max.Z - Min.Z + 1);
|
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);
|
Vec3U16 p1 = Clamp(Min), p2 = Clamp(Max);
|
||||||
for (ushort y = p1.Y; y <= p2.Y; y++)
|
for (ushort y = p1.Y; y <= p2.Y; y++)
|
||||||
for (ushort z = p1.Z; z <= p2.Z; z++)
|
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);
|
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);
|
Vec3U16 p1 = Clamp(Min), p2 = Clamp(Max);
|
||||||
for (ushort y = p1.Y; y <= p2.Y; y++)
|
for (ushort y = p1.Y; y <= p2.Y; y++)
|
||||||
for (ushort z = p1.Z; z <= p2.Z; z++)
|
for (ushort z = p1.Z; z <= p2.Z; z++)
|
||||||
|
@ -36,7 +36,7 @@ namespace MCGalaxy.Drawing.Ops {
|
|||||||
|
|
||||||
public Level Source;
|
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.X = Math.Min(Max.X, Source.Width - 1);
|
||||||
Max.Y = Math.Min(Max.Y, Source.Height - 1);
|
Max.Y = Math.Min(Max.Y, Source.Height - 1);
|
||||||
Max.Z = Math.Min(Max.Z, Source.Length - 1);
|
Max.Z = Math.Min(Max.Z, Source.Length - 1);
|
||||||
|
@ -29,7 +29,7 @@ namespace MCGalaxy.Drawing.Ops {
|
|||||||
return (int)(Math.PI * 4.0/3.0 * rx * ry * rz);
|
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 */
|
/* 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 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 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);
|
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 */
|
/* 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 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 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);
|
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 */
|
/* 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 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;
|
double rx = (Max.X - Min.X) / 2.0 + 0.25, rz = (Max.Z - Min.Z) / 2.0 + 0.25;
|
||||||
|
@ -30,7 +30,7 @@ namespace MCGalaxy.Drawing.Ops {
|
|||||||
return (int)(2 * Math.PI * Math.PI * rTube * rTube * Math.Abs(rCentre));
|
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 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 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;
|
double rTube = ry, rCentre = Math.Min(rx, rz) - rTube;
|
||||||
|
@ -42,7 +42,7 @@ namespace MCGalaxy.Drawing.Ops {
|
|||||||
|
|
||||||
public override long BlocksAffected(Level lvl, Vec3S32[] marks) { return Tree.EstimateBlocksAffected(); }
|
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;
|
if (brush == null) brush = defBrush;
|
||||||
Vec3U16 P = Clamp(marks[0]);
|
Vec3U16 P = Clamp(marks[0]);
|
||||||
Level lvl = Level;
|
Level lvl = Level;
|
||||||
|
@ -33,7 +33,7 @@ namespace MCGalaxy.Drawing.Ops {
|
|||||||
return (int)Math.Sqrt(s * (s - a) * (s - b) * (s - c));
|
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 V1 = marks[0], V2 = marks[1], V3 = marks[2];
|
||||||
Vec3F32 N = Vec3F32.Cross(V2 - V1, V3 - V1);
|
Vec3F32 N = Vec3F32.Cross(V2 - V1, V3 - V1);
|
||||||
N = Vec3F32.Normalise(N);
|
N = Vec3F32.Normalise(N);
|
||||||
|
@ -54,7 +54,7 @@ namespace MCGalaxy.Drawing.Ops {
|
|||||||
|
|
||||||
public override long BlocksAffected(Level lvl, Vec3S32[] marks) { return -1; }
|
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;
|
this.output = output;
|
||||||
PerformUndo();
|
PerformUndo();
|
||||||
this.output = null;
|
this.output = null;
|
||||||
@ -75,7 +75,7 @@ namespace MCGalaxy.Drawing.Ops {
|
|||||||
PerformOldUndo(args);
|
PerformOldUndo(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
Action<DrawOpBlock> output;
|
DrawOpOutput output;
|
||||||
Vec3U16 dims;
|
Vec3U16 dims;
|
||||||
|
|
||||||
void UndoBlock(BlockDBEntry e) {
|
void UndoBlock(BlockDBEntry e) {
|
||||||
|
@ -30,7 +30,7 @@ namespace MCGalaxy.Drawing.Ops {
|
|||||||
|
|
||||||
public override long BlocksAffected(Level lvl, Vec3S32[] marks) { return -1; }
|
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) {
|
if (Level.UndoBuffer.Count != Server.physUndo) {
|
||||||
int count = Level.currentUndo;
|
int count = Level.currentUndo;
|
||||||
for (int i = count; i >= 0; i--) {
|
for (int i = count; i >= 0; i--) {
|
||||||
|
@ -42,7 +42,7 @@ namespace MCGalaxy.Drawing.Ops {
|
|||||||
|
|
||||||
int dirX, dirZ;
|
int dirX, dirZ;
|
||||||
Vec3U16 pos;
|
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]);
|
Vec3U16 p1 = Clamp(marks[0]), p2 = Clamp(marks[1]);
|
||||||
if (Math.Abs(p2.X - p1.X) > Math.Abs(p2.Z - p1.Z))
|
if (Math.Abs(p2.X - p1.X) > Math.Abs(p2.Z - p1.Z))
|
||||||
dirX = p2.X > p1.X? 1 : -1;
|
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) {
|
if ((int)c >= 256 || letters[(int)c] == null) {
|
||||||
Player.Message(p, "\"" + c + "\" is not currently supported, replacing with space.");
|
Player.Message(p, "\"" + c + "\" is not currently supported, replacing with space.");
|
||||||
pos.X = (ushort)(pos.X + dirX * 4 * Scale);
|
pos.X = (ushort)(pos.X + dirX * 4 * Scale);
|
||||||
|
@ -40,7 +40,7 @@ namespace MCGalaxy.Drawing.Ops {
|
|||||||
Vec3S32 dx, dy, adj;
|
Vec3S32 dx, dy, adj;
|
||||||
IPaletteMatcher selector;
|
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);
|
CalcState(Direction);
|
||||||
selector = new RgbPaletteMatcher();
|
selector = new RgbPaletteMatcher();
|
||||||
CalcLayerColors();
|
CalcLayerColors();
|
||||||
@ -108,7 +108,7 @@ namespace MCGalaxy.Drawing.Ops {
|
|||||||
return entry;
|
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 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 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);
|
ushort z = (ushort)(Origin.Z + dx.Z * P.X + dy.Z * P.Y);
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Drawing.Imaging;
|
using System.Drawing.Imaging;
|
||||||
|
using MCGalaxy.Drawing.Ops;
|
||||||
|
|
||||||
namespace MCGalaxy.Drawing {
|
namespace MCGalaxy.Drawing {
|
||||||
|
|
||||||
@ -40,14 +41,14 @@ namespace MCGalaxy.Drawing {
|
|||||||
data = bmp.LockBits(r, ImageLockMode.ReadOnly, bmp.PixelFormat);
|
data = bmp.LockBits(r, ImageLockMode.ReadOnly, bmp.PixelFormat);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Iterate(Action<DrawOpBlock> output,
|
public void Iterate(DrawOpOutput output,
|
||||||
Action<Pixel, Action<DrawOpBlock>> callback) {
|
Action<Pixel, DrawOpOutput> callback) {
|
||||||
if (data == null) IterateSlow(output, callback);
|
if (data == null) IterateSlow(output, callback);
|
||||||
else IterateFast(output, callback);
|
else IterateFast(output, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe void IterateFast(Action<DrawOpBlock> output,
|
unsafe void IterateFast(DrawOpOutput output,
|
||||||
Action<Pixel, Action<DrawOpBlock>> callback) {
|
Action<Pixel, DrawOpOutput> callback) {
|
||||||
Pixel pixel;
|
Pixel pixel;
|
||||||
int width = bmp.Width, height = bmp.Height;
|
int width = bmp.Width, height = bmp.Height;
|
||||||
byte* scan0 = (byte*)data.Scan0;
|
byte* scan0 = (byte*)data.Scan0;
|
||||||
@ -68,8 +69,8 @@ namespace MCGalaxy.Drawing {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void IterateSlow(Action<DrawOpBlock> output,
|
void IterateSlow(DrawOpOutput output,
|
||||||
Action<Pixel, Action<DrawOpBlock>> callback) {
|
Action<Pixel, DrawOpOutput> callback) {
|
||||||
Pixel pixel;
|
Pixel pixel;
|
||||||
int width = bmp.Width, height = bmp.Height;
|
int width = bmp.Width, height = bmp.Height;
|
||||||
for (int y = 0; y < height; y++)
|
for (int y = 0; y < height; y++)
|
||||||
|
@ -40,13 +40,13 @@ namespace MCGalaxy.Drawing.Transforms {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override void Perform(Vec3S32[] marks, Player p, Level lvl,
|
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;
|
P = (op.Min + op.Max) / 2;
|
||||||
if (!CentreOrigin) P = op.Origin;
|
if (!CentreOrigin) P = op.Origin;
|
||||||
op.Perform(marks, brush, b => OutputBlock(b, output));
|
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 dx = b.X - P.X, dy = b.Y - P.Y, dz = b.Z - P.Z;
|
||||||
double rotX = 0, rotY = 0, rotZ = 0;
|
double rotX = 0, rotY = 0, rotZ = 0;
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ namespace MCGalaxy.Drawing.Transforms {
|
|||||||
public static NoTransform Instance = new NoTransform();
|
public static NoTransform Instance = new NoTransform();
|
||||||
|
|
||||||
public override void Perform(Vec3S32[] marks, Player p, Level lvl,
|
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);
|
op.Perform(marks, brush, output);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -50,7 +50,7 @@ namespace MCGalaxy.Drawing.Transforms {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override void Perform(Vec3S32[] marks, Player p, Level lvl,
|
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;
|
P = (op.Min + op.Max) / 2;
|
||||||
dirX = 1; dirY = 1; dirZ = 1;
|
dirX = 1; dirY = 1; dirZ = 1;
|
||||||
width = lvl.Width; height = lvl.Height; length = lvl.Length;
|
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));
|
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;
|
int dx = b.X - P.X, dy = b.Y - P.Y, dz = b.Z - P.Z;
|
||||||
|
|
||||||
// Scale out until we hit the next block
|
// Scale out until we hit the next block
|
||||||
|
@ -35,6 +35,6 @@ namespace MCGalaxy.Drawing.Transforms {
|
|||||||
public virtual void Configure(DrawOp op, Player p) { }
|
public virtual void Configure(DrawOp op, Player p) { }
|
||||||
|
|
||||||
public abstract void Perform(Vec3S32[] marks, Player p, Level lvl,
|
public abstract void Perform(Vec3S32[] marks, Player p, Level lvl,
|
||||||
DrawOp op, Brush brush, Action<DrawOpBlock> output);
|
DrawOp op, Brush brush, DrawOpOutput output);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@ using System.Collections.Generic;
|
|||||||
|
|
||||||
namespace MCGalaxy.Generator {
|
namespace MCGalaxy.Generator {
|
||||||
|
|
||||||
|
/// <summary> Holds arguments for a map generator. </summary>
|
||||||
public struct MapGenArgs {
|
public struct MapGenArgs {
|
||||||
public Player Player;
|
public Player Player;
|
||||||
public Level Level;
|
public Level Level;
|
||||||
@ -27,6 +28,9 @@ namespace MCGalaxy.Generator {
|
|||||||
public bool UseSeed;
|
public bool UseSeed;
|
||||||
public int Seed;
|
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>
|
/// <summary> Maintains a list of map generator instances. </summary>
|
||||||
public static class MapGen {
|
public static class MapGen {
|
||||||
@ -67,7 +71,7 @@ namespace MCGalaxy.Generator {
|
|||||||
genArgs.UseSeed = args != "";
|
genArgs.UseSeed = args != "";
|
||||||
if (genArgs.UseSeed && !int.TryParse(args, out genArgs.Seed))
|
if (genArgs.UseSeed && !int.TryParse(args, out genArgs.Seed))
|
||||||
genArgs.Seed = args.GetHashCode();
|
genArgs.Seed = args.GetHashCode();
|
||||||
Func<MapGenArgs, bool> generator = null;
|
MapGenerator generator = null;
|
||||||
|
|
||||||
simpleGens.TryGetValue(theme, out generator);
|
simpleGens.TryGetValue(theme, out generator);
|
||||||
if (generator != null) return generator(genArgs);
|
if (generator != null) return generator(genArgs);
|
||||||
@ -77,18 +81,18 @@ namespace MCGalaxy.Generator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static Dictionary<string, Func<MapGenArgs, bool>> simpleGens, advGens;
|
static Dictionary<string, MapGenerator> simpleGens, advGens;
|
||||||
public static void RegisterSimpleGen(string theme, Func<MapGenArgs, bool> gen) {
|
public static void RegisterSimpleGen(string theme, MapGenerator gen) {
|
||||||
simpleGens[theme.ToLower()] = 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;
|
advGens[theme.ToLower()] = gen;
|
||||||
}
|
}
|
||||||
|
|
||||||
static MapGen() {
|
static MapGen() {
|
||||||
simpleGens = new Dictionary<string, Func<MapGenArgs, bool>>();
|
simpleGens = new Dictionary<string, MapGenerator>();
|
||||||
advGens = new Dictionary<string, Func<MapGenArgs, bool>>();
|
advGens = new Dictionary<string, MapGenerator>();
|
||||||
SimpleGen.RegisterGenerators();
|
SimpleGen.RegisterGenerators();
|
||||||
fCraftMapGenerator.RegisterGenerators();
|
fCraftMapGenerator.RegisterGenerators();
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ namespace MCGalaxy {
|
|||||||
ExtBlock block = ExtBlock.FromIndex(i);
|
ExtBlock block = ExtBlock.FromIndex(i);
|
||||||
blockAABBs[i] = Block.BlockAABB(block, this);
|
blockAABBs[i] = Block.BlockAABB(block, this);
|
||||||
}
|
}
|
||||||
SetBlockHandlers();
|
UpdateBlockHandlers();
|
||||||
|
|
||||||
name = n; MapName = n.ToLower();
|
name = n; MapName = n.ToLower();
|
||||||
BlockDB = new BlockDB(this);
|
BlockDB = new BlockDB(this);
|
||||||
@ -390,7 +390,7 @@ namespace MCGalaxy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
MCGalaxy.Blocks.BlockProps.Load("lvl_" + lvl.MapName, lvl.BlockProps, true);
|
MCGalaxy.Blocks.BlockProps.Load("lvl_" + lvl.MapName, lvl.BlockProps, true);
|
||||||
lvl.SetBlockHandlers();
|
lvl.UpdateBlockHandlers();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool CheckLoadOnGoto(string givenName) {
|
public static bool CheckLoadOnGoto(string givenName) {
|
||||||
@ -487,13 +487,13 @@ namespace MCGalaxy {
|
|||||||
public ushort smallX, smallY, smallZ;
|
public ushort smallX, smallY, smallZ;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetBlockHandlers() {
|
public void UpdateBlockHandlers() {
|
||||||
for (int i = 0; i < BlockProps.Length; i++) {
|
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;
|
bool nonSolid;
|
||||||
if (GetBlockDef(block) == null) {
|
if (GetBlockDef(block) == null) {
|
||||||
nonSolid = Block.Walkthrough(Block.Convert(block.BlockID));
|
nonSolid = Block.Walkthrough(Block.Convert(block.BlockID));
|
||||||
@ -512,7 +512,7 @@ namespace MCGalaxy {
|
|||||||
public void UpdateCustomBlock(byte raw, BlockDefinition def) {
|
public void UpdateCustomBlock(byte raw, BlockDefinition def) {
|
||||||
CustomBlockDefs[raw] = def;
|
CustomBlockDefs[raw] = def;
|
||||||
ExtBlock block = ExtBlock.FromRaw(raw);
|
ExtBlock block = ExtBlock.FromRaw(raw);
|
||||||
SetBlockHandler(block);
|
UpdateBlockHandler(block);
|
||||||
blockAABBs[block.Index] = Block.BlockAABB(block, this);
|
blockAABBs[block.Index] = Block.BlockAABB(block, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user