Skip to content

Commit 03af28e

Browse files
Optimise replace brush to be around 15% faster (when run under profiler)
1 parent 72fecbe commit 03af28e

File tree

11 files changed

+3
-25
lines changed

11 files changed

+3
-25
lines changed

fCraft/Drawing/Brushes/BWRainbowBrush.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ public bool Begin(Player player, DrawOperation state) {
5656

5757

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

fCraft/Drawing/Brushes/CheckeredBrush.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,6 @@ public bool Begin(Player player, DrawOperation state) {
105105

106106

107107
public Block NextBlock(DrawOperation state) {
108-
if (state == null)
109-
throw new ArgumentNullException("state");
110108
if (((state.Coords.X + state.Coords.Y + state.Coords.Z) & 1) == 1) {
111109
return Block1;
112110
} else {

fCraft/Drawing/Brushes/CloudyBrush.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,6 @@ public bool Begin(Player player, DrawOperation op) {
334334

335335

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

fCraft/Drawing/Brushes/NormalBrush.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,6 @@ public bool Begin(Player player, DrawOperation state) {
103103

104104

105105
public Block NextBlock(DrawOperation state) {
106-
if (state == null)
107-
throw new ArgumentNullException("state");
108106
if (state.AlternateBlockIndex < Blocks.Length) {
109107
return Blocks[state.AlternateBlockIndex];
110108
} else {

fCraft/Drawing/Brushes/PasteBrush.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,6 @@ public bool Begin(Player player, DrawOperation op) {
138138

139139

140140
public Block NextBlock(DrawOperation op) {
141-
if (op == null) throw new ArgumentNullException("op");
142-
143141
// TODO: offset op.Coords
144142
Vector3I pasteCoords = new Vector3I {
145143
X = Mod(op.Coords.X - op.Marks[0].X, CopyInfo.Bounds.Width),

fCraft/Drawing/Brushes/RainbowBrush.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@ public bool Begin(Player player, DrawOperation state) {
6767

6868

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

fCraft/Drawing/Brushes/RandomBrush.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,6 @@ public bool Begin(Player player, DrawOperation op) {
154154

155155

156156
public Block NextBlock(DrawOperation op) {
157-
if (op == null)
158-
throw new ArgumentNullException("op");
159157
int n = seed ^ (op.Coords.X + 1290 * op.Coords.Y + 1664510 * op.Coords.Z);
160158
n = (n << 13) ^ n;
161159
n = (n * (n * n * 15731 + 789221) + 1376312589) & 0x7FFFFFFF;

fCraft/Drawing/Brushes/ReplaceBrush.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,7 @@ public bool Begin(Player player, DrawOperation op) {
122122

123123

124124
public virtual Block NextBlock(DrawOperation op) {
125-
if (op == null)
126-
throw new ArgumentNullException("op");
127-
Block block = op.Map.GetBlock(op.Coords);
125+
Block block = (Block)op.Map.Blocks[op.Map.Index(op.Coords)];
128126
for (int i = 0; i < Blocks.Length; i++) {
129127
if (block == Blocks[i]) {
130128
return Replacement;

fCraft/Drawing/Brushes/ReplaceBrushBrush.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,7 @@ public bool Begin(Player player, DrawOperation op) {
112112

113113

114114
public Block NextBlock(DrawOperation op) {
115-
if (op == null)
116-
throw new ArgumentNullException("op");
117-
Block block = op.Map.GetBlock(op.Coords);
115+
Block block = (Block)op.Map.Blocks[op.Map.Index(op.Coords)];
118116
if (block == Block) {
119117
return Replacement.NextBlock(op);
120118
}

fCraft/Drawing/Brushes/ReplaceNotBrush.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,7 @@ public override IBrushFactory Factory {
7474

7575

7676
public override Block NextBlock(DrawOperation op) {
77-
if (op == null)
78-
throw new ArgumentNullException("op");
79-
Block block = op.Map.GetBlock(op.Coords);
77+
Block block = (Block)op.Map.Blocks[op.Map.Index(op.Coords)];
8078
for (int i = 0; i < Blocks.Length; i++) {
8179
if (block == Blocks[i]) {
8280
return Block.None;

0 commit comments

Comments
 (0)