Skip to content
Permalink
Browse files

Optimise replace brush to be around 15% faster (when run under profiler)

  • Loading branch information...
UnknownShadow200 committed Feb 19, 2018
1 parent 72fecbe commit 03af28e636dac866445b990470ff42b913588b9c
@@ -56,8 +56,6 @@ public sealed class BWRainbowBrush : IBrushFactory, IBrush {


public Block NextBlock(DrawOperation state) {
if (state == null)
throw new ArgumentNullException("state");
return BWRainbow[(state.Coords.X + state.Coords.Y + state.Coords.Z) % 8];
}

@@ -105,8 +105,6 @@ public sealed class CheckeredBrush : IBrush {


public Block NextBlock(DrawOperation state) {
if (state == null)
throw new ArgumentNullException("state");
if (((state.Coords.X + state.Coords.Y + state.Coords.Z) & 1) == 1) {
return Block1;
} else {
@@ -334,8 +334,6 @@ public CloudyBrush([NotNull] Block[] blocks, [NotNull] int[] ratios)


public Block NextBlock(DrawOperation op) {
if (op == null)
throw new ArgumentNullException("op");
Vector3I relativeCoords = op.Coords - op.Bounds.MinVertex;
float value = noise3D.Compute(relativeCoords.X, relativeCoords.Y, relativeCoords.Z);

@@ -103,8 +103,6 @@ public sealed class NormalBrush : IBrush {


public Block NextBlock(DrawOperation state) {
if (state == null)
throw new ArgumentNullException("state");
if (state.AlternateBlockIndex < Blocks.Length) {
return Blocks[state.AlternateBlockIndex];
} else {
@@ -138,8 +138,6 @@ public sealed class PasteBrush : IBrush {


public Block NextBlock(DrawOperation op) {
if (op == null) throw new ArgumentNullException("op");

// TODO: offset op.Coords
Vector3I pasteCoords = new Vector3I {
X = Mod(op.Coords.X - op.Marks[0].X, CopyInfo.Bounds.Width),
@@ -67,8 +67,6 @@ public sealed class RainbowBrush : IBrushFactory, IBrush {


public Block NextBlock(DrawOperation state) {
if (state == null)
throw new ArgumentNullException("state");
return Rainbow[(state.Coords.X + state.Coords.Y + state.Coords.Z) % 13];
}

@@ -154,8 +154,6 @@ public sealed class RandomBrush : IBrush {


public Block NextBlock(DrawOperation op) {
if (op == null)
throw new ArgumentNullException("op");
int n = seed ^ (op.Coords.X + 1290 * op.Coords.Y + 1664510 * op.Coords.Z);
n = (n << 13) ^ n;
n = (n * (n * n * 15731 + 789221) + 1376312589) & 0x7FFFFFFF;
@@ -122,9 +122,7 @@ public class ReplaceBrush : IBrush {


public virtual Block NextBlock(DrawOperation op) {
if (op == null)
throw new ArgumentNullException("op");
Block block = op.Map.GetBlock(op.Coords);
Block block = (Block)op.Map.Blocks[op.Map.Index(op.Coords)];
for (int i = 0; i < Blocks.Length; i++) {
if (block == Blocks[i]) {
return Replacement;
@@ -112,9 +112,7 @@ public sealed class ReplaceBrushBrush : IBrush {


public Block NextBlock(DrawOperation op) {
if (op == null)
throw new ArgumentNullException("op");
Block block = op.Map.GetBlock(op.Coords);
Block block = (Block)op.Map.Blocks[op.Map.Index(op.Coords)];
if (block == Block) {
return Replacement.NextBlock(op);
}
@@ -74,9 +74,7 @@ public ReplaceNotBrush(Block[] blocks, Block replacement)


public override Block NextBlock(DrawOperation op) {
if (op == null)
throw new ArgumentNullException("op");
Block block = op.Map.GetBlock(op.Coords);
Block block = (Block)op.Map.Blocks[op.Map.Index(op.Coords)];
for (int i = 0; i < Blocks.Length; i++) {
if (block == Blocks[i]) {
return Block.None;
@@ -105,8 +105,6 @@ public sealed class StripedBrush : IBrush {


public Block NextBlock(DrawOperation state) {
if (state == null)
throw new ArgumentNullException("state");
if (((state.Coords.X + state.Coords.Y + state.Coords.Z) & 2) == 2) {
return Block1;
} else {

0 comments on commit 03af28e

Please sign in to comment.
You can’t perform that action at this time.