Skip to content

Commit

Permalink
Checkered brush: Also support providing frequencies/weights for blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownShadow200 committed Nov 8, 2022
1 parent 6b76086 commit 2e51fdb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 22 deletions.
8 changes: 4 additions & 4 deletions MCGalaxy/Drawing/BrushFactories/FrequencyBrushes.cs
Expand Up @@ -107,9 +107,9 @@ public sealed class RandomBrushFactory : BrushFactory

public override Brush Construct(BrushArgs args) {
int[] count;
BlockID[] toAffect = FrequencyBrush.GetBlocks(args, out count, P => false, null);

BlockID[] toAffect = FrequencyBrush.GetBlocks(args, out count, P => false, null);
if (toAffect == null) return null;

BlockID[] blocks = FrequencyBrush.Combine(toAffect, count);
return new RandomBrush(blocks);
}
Expand All @@ -130,9 +130,9 @@ public sealed class GradientBrushFactory : BrushFactory
public override Brush Construct(BrushArgs args) {
CustomModelAnimAxis axis = GetAxis(ref args);
int[] count;
BlockID[] toAffect = FrequencyBrush.GetBlocks(args, out count, P => false, null);

BlockID[] toAffect = FrequencyBrush.GetBlocks(args, out count, P => false, null);
if (toAffect == null) return null;

BlockID[] blocks = FrequencyBrush.Combine(toAffect, count);
return new GradientBrush(blocks, axis);
}
Expand Down
26 changes: 9 additions & 17 deletions MCGalaxy/Drawing/BrushFactories/SimpleBrushes.cs
Expand Up @@ -65,27 +65,19 @@ public sealed class CheckeredBrushFactory : BrushFactory

public override Brush Construct(BrushArgs args) {
Player p = args.Player;
// avoid allocating the arrays for the most common case
if (args.Message.Length == 0) {
if (!CommandParser.IsBlockAllowed(p, "draw with", args.Block)) return null;
return new CheckeredBrush(args.Block, Block.Invalid);
}
string[] parts = args.Message.SplitSpaces();

BlockID block1;
if (!CommandParser.GetBlockIfAllowed(p, parts[0], "draw with", out block1, true)) return null;
if (parts.Length == 1)
return new CheckeredBrush(block1, Block.Invalid);

if (parts.Length == 2) {
BlockID block2;
if (!CommandParser.GetBlockIfAllowed(p, parts[1], "draw with", out block2, true)) return null;
return new CheckeredBrush(block1, block2);
}

BlockID[] blocks = new BlockID[parts.Length];
for (int i = 0; i < blocks.Length; i++) {
if (!CommandParser.GetBlockIfAllowed(p, parts[i], "draw with", out blocks[i], true)) return null;
}

int[] count;
BlockID[] toAffect = FrequencyBrush.GetBlocks(args, out count, P => false, null);
if (toAffect == null) return null;

BlockID[] blocks = FrequencyBrush.Combine(toAffect, count);
if (blocks.Length == 2)
return new CheckeredBrush(blocks[0], blocks[1]);
return new CheckeredPaletteBrush(blocks);
}
}
Expand Down
3 changes: 2 additions & 1 deletion MCGalaxy/Drawing/Brushes/CloudyBrush.cs
Expand Up @@ -90,10 +90,11 @@ public sealed class CloudyBrush : Brush
// then the threshold for all blocks is set to this.
// If sum was say 0.8 instead, then only the threshold for the
// very last block would be increased.
// TODO rewrite to be single pass (only need to update current instead of all counts)
for (int j = 0; j < counts.Length; j++) {
if (sum <= coverage[j])
thresholds[j] = i / (float)accuracy;
}
}
sum += values[i] / (float)volume;
}
thresholds[blocks.Length - 1] = 1;
Expand Down

0 comments on commit 2e51fdb

Please sign in to comment.