IBrushInstance IBrush.MakeInstance( Player player, CommandReader cmd, DrawOperation op ) { if( ReadParams( cmd ) ) { return this; } else { return null; } }
public override Block NextBlock(DrawOperation op) { if (op == null) throw new ArgumentNullException("op"); Block block = op.Map.GetBlock(op.Coords); for (int i = 0; i < Blocks.Length; i++) { if (block == Blocks[i]) { return Block.None; } } return Replacement; }
public bool Begin(Player player, DrawOperation state) { if (player == null) throw new ArgumentNullException("player"); if (state == null) throw new ArgumentNullException("state"); if (Blocks == null || Blocks.Length == 0) { if (player.LastUsedBlockType == Block.None) { player.Message("Cannot deduce desired block. Click a block or type out the block name."); return false; } else { Blocks = new[] { player.GetBind(player.LastUsedBlockType) }; } } return true; }
public IBrushInstance MakeInstance( Player player, CommandReader cmd, DrawOperation state ) { if( player == null ) throw new ArgumentNullException( "player" ); if( cmd == null ) throw new ArgumentNullException( "cmd" ); if( state == null ) throw new ArgumentNullException( "state" ); List<Block> blocks = new List<Block>(); while( cmd.HasNext ) { Block block; if( !cmd.NextBlock( player, true, out block ) ) { return null; } blocks.Add( block ); } return new NormalBrush( blocks.ToArray() ); }
public virtual bool Begin( Player player, DrawOperation op ) { if( player == null ) throw new ArgumentNullException( "player" ); if( op == null ) throw new ArgumentNullException( "op" ); if( op.Bounds.Volume > 32 * 32 * 32 ) { player.Message( "{0} brush: Preparing, please wait...", Brush.Factory.Name ); } noise3D = new PerlinNoise3D( new Random( Seed ) ) { Amplitude = 1, Frequency = Frequency, Octaves = Octaves, Persistence = Persistence }; // generate and normalize the raw (float) data float[, ,] rawData = new float[op.Bounds.Width, op.Bounds.Length, op.Bounds.Height]; for( int x = 0; x < op.Bounds.Width; x++ ) { for( int y = 0; y < op.Bounds.Length; y++ ) { for( int z = 0; z < op.Bounds.Height; z++ ) { rawData[x, y, z] = noise3D.Compute( x, y, z ); } } } Noise.Normalize( rawData, out normMultiplier, out normConstant ); if( MapAllValues( rawData ) ) { Noise.Normalize( rawData, out normMultiplier, out normConstant ); } // create a mapping of raw data to blocks int totalBlocks = BlockRatios.Sum(); int blocksSoFar = BlockRatios[0]; computedThresholds = new float[Blocks.Length]; computedThresholds[0] = 0; for( int i = 1; i < Blocks.Length; i++ ) { float desiredCoverage = blocksSoFar / (float)totalBlocks; computedThresholds[i] = Noise.FindThreshold( rawData, desiredCoverage ); blocksSoFar += BlockRatios[i]; } return true; }
public IBrushInstance MakeInstance( Player player, CommandReader cmd, DrawOperation op ) { if( player == null ) throw new ArgumentNullException( "player" ); if( cmd == null ) throw new ArgumentNullException( "cmd" ); if( op == null ) throw new ArgumentNullException( "op" ); if( cmd.HasNext ) { Block block, altBlock; if( !cmd.NextBlock( player, true, out block ) ) return null; if( cmd.HasNext ) { if( !cmd.NextBlock( player, true, out altBlock ) ) return null; } else { altBlock = Block.None; } Block1 = block; Block2 = altBlock; } else if( Block1 == Block.None ) { player.Message( "{0}: Please specify one or two blocks.", Factory.Name ); return null; } return new CheckeredBrush( this ); }
public bool Begin([NotNull] Player player, [NotNull] DrawOperation state) { if (player == null) { throw new ArgumentNullException("player"); } if (state == null) { throw new ArgumentNullException("state"); } if (Block == Block.Undefined) { if (player.LastUsedBlockType == Block.Undefined) { player.Message("Cannot deduce desired block. Click a block or type out the block name."); return(false); } else { Block = player.GetBind(player.LastUsedBlockType); } } return(true); }
/// <summary> Called after the DrawOperation has been prepared. /// Should be used to verify that the brush is ready for use. /// Resources used by the brush should be obtained here. </summary> /// <param name="player"> Player who started the DrawOperation. </param> /// <param name="op"> DrawOperation that will be using this brush. </param> /// <returns> Whether this brush instance has successfully began or not. </returns> public bool Begin(Player player, DrawOperation op) { if (player == null) { throw new ArgumentNullException("player"); } if (op == null) { throw new ArgumentNullException("op"); } if (Block == Block.None) { if (player.LastUsedBlockType == Block.None) { player.Message("Cannot deduce desired block. Click a block or type out the block name."); return(false); } else { Block = player.GetBind(player.LastUsedBlockType); } } return(true); }
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 ); // normalize value value = value * normMultiplier + normConstant; // find the right block type for given value for( int i = 1; i < Blocks.Length; i++ ) { if( computedThresholds[i] > value ) { return Blocks[i - 1]; } } return Blocks[Blocks.Length - 1]; }
// Returns false if cancelled protected static bool RaiseBeginningEvent( DrawOperation op ) { var h = Beginning; if( h == null ) return true; var e = new DrawOperationBeginningEventArgs( op ); h( null, e ); return !e.Cancel; }
public IBrushInstance MakeInstance( Player player, CommandReader cmd, DrawOperation op ) { if( player == null ) throw new ArgumentNullException( "player" ); if( cmd == null ) throw new ArgumentNullException( "cmd" ); if( op == null ) throw new ArgumentNullException( "op" ); Stack<Block> blocks = new Stack<Block>(); while( cmd.HasNext ) { Block block; if( !cmd.NextBlock( player, false, out block ) ) return null; blocks.Push( block ); } if( blocks.Count == 0 && Blocks == null ) { player.Message( "ReplaceNot brush requires at least 1 block." ); return null; } if( blocks.Count > 0 ) { if( blocks.Count > 1 ) Replacement = blocks.Pop(); Blocks = blocks.ToArray(); } return new ReplaceNotBrush( this ); }
Block IBrush.NextBlock(DrawOperation op) { return(NextBlock()); }
public IBrushInstance MakeInstance([NotNull] Player player, [NotNull] Command cmd, [NotNull] DrawOperation state) { if (player == null) { throw new ArgumentNullException("player"); } if (cmd == null) { throw new ArgumentNullException("cmd"); } if (state == null) { throw new ArgumentNullException("state"); } List <Block> blocks = new List <Block>(); List <int> blockRatios = new List <int>(); while (cmd.HasNext) { int ratio = 1; Block block = cmd.NextBlockWithParam(player, ref ratio); if (ratio < 0 || ratio > MaxRatio) { player.Message("Invalid block ratio ({0}). Must be between 1 and {1}.", ratio, MaxRatio); return(null); } if (block == Block.Undefined) { return(null); } blocks.Add(block); blockRatios.Add(ratio); } if (blocks.Count == 0) { if (Blocks.Length == 0) { player.Message("{0} brush: Please specify at least one block.", Factory.Name); return(null); } else { return(new CloudyBrush(this)); } } else if (blocks.Count == 1) { return(new CloudyBrush(blocks[0], blockRatios[0])); } else { return(new CloudyBrush(blocks.ToArray(), blockRatios.ToArray())); } }
public bool Begin(Player player, DrawOperation state) { return(true); }
public IBrushInstance MakeInstance([NotNull] Player player, [NotNull] Command cmd, [NotNull] DrawOperation state) { if (player == null) { throw new ArgumentNullException("player"); } if (cmd == null) { throw new ArgumentNullException("cmd"); } if (state == null) { throw new ArgumentNullException("state"); } Block block = Block.Undefined, altBlock = Block.Undefined; if (cmd.HasNext) { block = cmd.NextBlock(player); if (block == Block.Undefined) { return(null); } if (cmd.HasNext) { altBlock = cmd.NextBlock(player); if (altBlock == Block.Undefined) { return(null); } } } return(new NormalBrush(block, altBlock)); }
bool IBrushInstance.Begin( Player player, DrawOperation op ) { return true; }
protected static void RaiseEndedEvent(DrawOperation op) { EndedEvent.Raise(new DrawOperationEventArgs(op)); }
public IBrushInstance MakeInstance([NotNull] Player player, [NotNull] Command cmd, [NotNull] DrawOperation op) { if (player == null) { throw new ArgumentNullException("player"); } if (cmd == null) { throw new ArgumentNullException("cmd"); } if (op == null) { throw new ArgumentNullException("op"); } Stack <Block> temp = new Stack <Block>(); Block[] b; while (cmd.HasNext) { Block block = cmd.NextBlock(player); if (block == Block.Undefined) { return(null); } temp.Push(block); } if (temp.Count > 0) { b = temp.ToArray(); } else if (player.LastUsedBlockType != Block.Undefined) { b = new[] { player.LastUsedBlockType, Block.Air }; } else { b = new[] { Block.Stone, Block.Air }; } return(new DiagonalBrush(b)); }
protected static void RaiseBeganEvent(DrawOperation op) { BeganEvent.Raise(new DrawOperationEventArgs(op)); }
public IBrushInstance MakeInstance([NotNull] Player player, [NotNull] Command cmd, [NotNull] DrawOperation op) { if (player == null) { throw new ArgumentNullException("player"); } if (cmd == null) { throw new ArgumentNullException("cmd"); } if (op == null) { throw new ArgumentNullException("op"); } if (cmd.HasNext) { Block block = cmd.NextBlock(player); if (block == Block.Undefined) { return(null); } Block altBlock = cmd.NextBlock(player); Block1 = block; Block2 = altBlock; } else if (Block1 == Block.Undefined) { player.Message("{0}: Please specify at least one block.", Factory.Name); return(null); } return(new CheckeredBrush(this)); }
public Block NextBlock(DrawOperation state) { return(BWRainbow[(state.Coords.X + state.Coords.Y + state.Coords.Z) % 8]); }
protected static void RaiseEndedEvent( DrawOperation op ) { var h = Ended; if( h != null ) h( null, new DrawOperationEventArgs( op ) ); }
protected static void RaiseBeganEvent(DrawOperation op) { var h = Began; if (h != null) h(null, new DrawOperationEventArgs(op)); }
public DrawOperationBeginningEventArgs( DrawOperation drawOp ) { DrawOp = drawOp; }
protected static void RaiseEndedEvent(DrawOperation op) { var h = Ended; if (h != null) h(null, new DrawOperationEventArgs(op)); }
public bool Begin(Player player, DrawOperation op) { if (player == null) throw new ArgumentNullException("player"); if (op == null) throw new ArgumentNullException("op"); if (Blocks == null || Blocks.Length == 0) { throw new InvalidOperationException("No blocks given."); } if (Replacement == Block.None) { if (player.LastUsedBlockType == Block.None) { player.Message("Cannot deduce desired replacement block. Click a block or type out the block name."); return false; } else { Replacement = player.GetBind(player.LastUsedBlockType); } } op.Context |= BlockChangeContext.Replaced; return true; }
public IBrushInstance MakeInstance([NotNull] Player player, [NotNull] Command cmd, [NotNull] DrawOperation op) { if (player == null) { throw new ArgumentNullException("player"); } if (cmd == null) { throw new ArgumentNullException("cmd"); } if (op == null) { throw new ArgumentNullException("op"); } if (cmd.HasNext) { Block block = cmd.NextBlock(player); if (block == Block.Undefined) { return(null); } string brushName = cmd.Next(); if (brushName == null || !CommandManager.IsValidCommandName(brushName)) { player.Message("ReplaceBrush usage: &H/Brush rb <Block> <BrushName>"); return(null); } IBrushFactory brushFactory = BrushManager.GetBrushFactory(brushName); if (brushFactory == null) { player.Message("Unrecognized brush \"{0}\"", brushName); return(null); } IBrush replacement = brushFactory.MakeBrush(player, cmd); if (replacement == null) { return(null); } Block = block; Replacement = replacement; } ReplacementInstance = Replacement.MakeInstance(player, cmd, op); if (ReplacementInstance == null) { return(null); } return(new ReplaceBrushBrush(this)); }
public bool Begin( Player player, DrawOperation state ) { if( player == null ) throw new ArgumentNullException( "player" ); if( state == null ) throw new ArgumentNullException( "state" ); return true; }
public bool Begin( Player player, DrawOperation op ) { if( player == null ) throw new ArgumentNullException( "player" ); if( op == null ) throw new ArgumentNullException( "op" ); if( Blocks == null || Blocks.Length == 0 ) { throw new InvalidOperationException( "No blocks given." ); } return true; }
public UndoState( DrawOperation op ) { Op = op; Buffer = new List<UndoBlock>(); }
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; double derp = (n / (double)0x7FFFFFFF) * actualBlocks.Length; return actualBlocks[(int)Math.Floor( derp )]; }
bool IBrush.Begin(Player player, DrawOperation op) { return(true); }
public bool Begin( Player player, DrawOperation op ) { if( player == null ) throw new ArgumentNullException( "player" ); if( op == null ) throw new ArgumentNullException( "op" ); op.Context |= BlockChangeContext.Replaced; return ReplacementInstance.Begin( player, op ); }
public bool Begin( Player player, DrawOperation op ) { if( player == null ) throw new ArgumentNullException( "player" ); if( op == null ) throw new ArgumentNullException( "op" ); bool extraLarge = ( op.Bounds.Volume > ExtraLargeThreshold ); if( extraLarge ) { player.MessageNow( "{0} brush: Preparing, please wait...", Brush.Factory.Name ); } noise3D = new PerlinNoise3D( new Random( Seed ) ) { Amplitude = 1, Frequency = Frequency, Octaves = Octaves, Persistence = Persistence }; BoundingBox samplerBox = op.Bounds; int sampleScale = 1; if( extraLarge ) { samplerBox = new BoundingBox( op.Bounds.MinVertex, op.Bounds.Width / 2, op.Bounds.Length / 2, op.Bounds.Height / 2 ); sampleScale = 2; } // generate and normalize the raw (float) data float[,,] rawData = new float[samplerBox.Width,samplerBox.Length,samplerBox.Height]; for( int x = 0; x < samplerBox.Width; x++ ) { for( int y = 0; y < samplerBox.Length; y++ ) { for( int z = 0; z < samplerBox.Height; z++ ) { rawData[x, y, z] = noise3D.Compute( x * sampleScale, y * sampleScale, z * sampleScale ); } } } Noise.Normalize( rawData, out normMultiplier, out normConstant ); // create a mapping of raw data to blocks int totalBlocks = BlockRatios.Sum(); int blocksSoFar = BlockRatios[0]; computedThresholds = new float[Blocks.Length]; computedThresholds[0] = 0; for( int i = 1; i < Blocks.Length; i++ ) { float desiredCoverage = blocksSoFar / (float)totalBlocks; computedThresholds[i] = Noise.FindThreshold( rawData, desiredCoverage ); blocksSoFar += BlockRatios[i]; } return true; }
public Block NextBlock( DrawOperation op ) { if( op == null ) throw new ArgumentNullException( "op" ); Block block = op.Map.GetBlock( op.Coords ); if( block == Block ) { return ReplacementInstance.NextBlock( op ); } return Block.None; }
public IBrushInstance MakeInstance( Player player, CommandReader cmd, DrawOperation state ) { if( player == null ) throw new ArgumentNullException( "player" ); if( cmd == null ) throw new ArgumentNullException( "cmd" ); if( state == null ) throw new ArgumentNullException( "state" ); List<Block> blocks = new List<Block>(); List<int> blockRatios = new List<int>(); while( cmd.HasNext ) { int ratio; Block block; if( !cmd.NextBlockWithParam( player, true, out block, out ratio ) ) return null; if( ratio < 1 || ratio > MaxRatio ) { player.Message( "Cloudy brush: Invalid block ratio ({0}). Must be between 1 and {1}.", ratio, MaxRatio ); return null; } blocks.Add( block ); blockRatios.Add( ratio ); } if( blocks.Count == 0 ) { if( Blocks.Length == 0 ) { player.Message( "{0} brush: Please specify at least one block.", Factory.Name ); return null; } else { return new CloudyBrush( this ); } } else if( blocks.Count == 1 ) { return new CloudyBrush( blocks[0], blockRatios[0] ); } else { return new CloudyBrush( blocks.ToArray(), blockRatios.ToArray() ); } }
public IBrushInstance MakeInstance( Player player, CommandReader cmd, DrawOperation op ) { if( player == null ) throw new ArgumentNullException( "player" ); if( cmd == null ) throw new ArgumentNullException( "cmd" ); if( op == null ) throw new ArgumentNullException( "op" ); if( cmd.HasNext ) { Block block; if( !cmd.NextBlock( player, false, out block ) ) return null; string brushName = cmd.Next(); if( brushName == null || !CommandManager.IsValidCommandName( brushName ) ) { player.Message( "ReplaceBrush usage: &H/Brush rb <Block> <BrushName>" ); return null; } IBrushFactory brushFactory = BrushManager.GetBrushFactory( brushName ); if( brushFactory == null ) { player.Message( "Unrecognized brush \"{0}\"", brushName ); return null; } IBrush replacement = brushFactory.MakeBrush( player, cmd ); if( replacement == null ) { return null; } Block = block; Replacement = replacement; } ReplacementInstance = Replacement.MakeInstance( player, cmd, op ); if( ReplacementInstance == null ) return null; return new ReplaceBrushBrush( this ); }
protected static void RaiseBeganEvent( DrawOperation op ) { var h = Began; if( h != null ) h( null, new DrawOperationEventArgs( op ) ); }
//copy-paste from BuildingCommands private static void DrawOperationBegin(Player player, Command cmd, DrawOperation op) { IBrushInstance instance = player.Brush.MakeInstance(player, cmd, op); if (instance != null) { op.Brush = instance; player.SelectionStart(op.ExpectedMarks, new SelectionCallback(DrawOperationCallback), op, new Permission[] { Permission.DrawAdvanced }); player.Message("{0}: Click {1} blocks or use &H/Mark&S to make a selection.", new object[] { op.Description, op.ExpectedMarks }); } }
public DrawOperationEventArgs( DrawOperation drawOp ) { DrawOp = drawOp; }
public bool Begin(Player player, DrawOperation op) { if (player == null) { throw new ArgumentNullException("player"); } if (op == null) { throw new ArgumentNullException("op"); } bool extraLarge = (op.Bounds.Volume > ExtraLargeThreshold); if (extraLarge) { player.MessageNow("{0} brush: Preparing, please wait...", Brush.Factory.Name); } noise3D = new PerlinNoise3D(new Random(Seed)) { Amplitude = 1, Frequency = Frequency, Octaves = Octaves, Persistence = Persistence }; BoundingBox samplerBox = op.Bounds; int sampleScale = 1; if (extraLarge) { samplerBox = new BoundingBox(op.Bounds.MinVertex, op.Bounds.Width / 2, op.Bounds.Length / 2, op.Bounds.Height / 2); sampleScale = 2; } // generate and normalize the raw (float) data float[,,] rawData = new float[samplerBox.Width, samplerBox.Length, samplerBox.Height]; for (int x = 0; x < samplerBox.Width; x++) { for (int y = 0; y < samplerBox.Length; y++) { for (int z = 0; z < samplerBox.Height; z++) { rawData[x, y, z] = noise3D.Compute(x * sampleScale, y * sampleScale, z * sampleScale); } } } Noise.Normalize(rawData, out normMultiplier, out normConstant); // create a mapping of raw data to blocks int totalBlocks = BlockRatios.Sum(); int blocksSoFar = BlockRatios[0]; computedThresholds = new float[Blocks.Length]; computedThresholds[0] = 0; for (int i = 1; i < Blocks.Length; i++) { float desiredCoverage = blocksSoFar / (float)totalBlocks; computedThresholds[i] = Noise.FindThreshold(rawData, desiredCoverage); blocksSoFar += BlockRatios[i]; } return(true); }
public IBrushInstance MakeInstance([NotNull] Player player, [NotNull] Command cmd, [NotNull] DrawOperation op) { if (player == null) { throw new ArgumentNullException("player"); } if (cmd == null) { throw new ArgumentNullException("cmd"); } if (op == null) { throw new ArgumentNullException("op"); } Stack <Block> blocks = new Stack <Block>(); while (cmd.HasNext) { Block block = cmd.NextBlock(player); if (block == Block.Undefined) { return(null); } blocks.Push(block); } if (blocks.Count == 0 && Blocks == null) { player.Message("Replace brush requires at least 1 block."); return(null); } if (blocks.Count > 0) { if (blocks.Count > 1) { Replacement = blocks.Pop(); } Blocks = blocks.ToArray(); } return(new ReplaceBrush(this)); }
public IBrushInstance MakeInstance(Player player, CommandReader cmd, DrawOperation op) { return(this); }
Block IBrushInstance.NextBlock( DrawOperation op ) { return NextBlock(); }
public Block NextBlock(DrawOperation state) { if (state == null) throw new ArgumentNullException("state"); if (state.AlternateBlockIndex < Blocks.Length) { return Blocks[state.AlternateBlockIndex]; } else { return Block.None; } }
public IBrushInstance MakeInstance( Player player, Command cmd, DrawOperation state ) { return this; }
internal UndoState([CanBeNull] DrawOperation op) { Op = op; Buffer = new List <UndoBlock>(); }
public IBrushInstance MakeInstance(Player player, Command cmd, DrawOperation state) { return(this); }
Block IBrushInstance.NextBlock(DrawOperation op) { return(NextBlock()); }
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 { return Block2; } }
/// <summary> Creates a new UndoState for the given DrawOperation. <param name="op"/> can be null. </summary> public UndoState([CanBeNull] DrawOperation op) { Op = op; }
static void DrawOperationBegin( Player player, CommandReader cmd, DrawOperation op ) { // try to create instance of player's currently selected brush // all command parameters are passed to the brush IBrushInstance brush = player.Brush.MakeInstance( player, cmd, op ); // MakeInstance returns null if there were problems with syntax, abort if( brush == null ) return; op.Brush = brush; player.SelectionStart( op.ExpectedMarks, DrawOperationCallback, op, Permission.Draw ); player.Message( "{0}: Click or &H/Mark&S {1} blocks.", op.Description, op.ExpectedMarks ); }
public UndoState(DrawOperation op) { Op = op; Buffer = new List <UndoBlock>(); }