Patch:
Show
Code: Select all
Index: fCraft/Commands/BuildingCommands.cs
===================================================================
--- fCraft/Commands/BuildingCommands.cs (revision 1634)
+++ fCraft/Commands/BuildingCommands.cs (working copy)
@@ -66,9 +66,11 @@
CdEllipsoidHollow.Help += GeneralDrawingHelp;
CommandManager.RegisterCommand( CdLine );
+ CommandManager.RegisterCommand( CdSnap );
CommandManager.RegisterCommand( CdTriangle );
CommandManager.RegisterCommand( CdTriangleWireframe );
CdLine.Help += GeneralDrawingHelp;
+ CdSnap.Help += GeneralDrawingHelp;
CdTriangle.Help += GeneralDrawingHelp;
CdTriangleWireframe.Help += GeneralDrawingHelp;
@@ -225,9 +227,26 @@
static void LineHandler( Player player, CommandReader cmd ) {
DrawOperationBegin( player, cmd, new LineDrawOperation( player ) );
}
+
+
+
+ static readonly CommandDescriptor CdSnap = new CommandDescriptor {
+ Name = "Snap",
+ Aliases = new[] { "SnapLine", "sn", "sl" },
+ Category = CommandCategory.Building,
+ Permissions = new[] { Permission.Draw },
+ RepeatableSelection = true,
+ Help = "Draws a line along the axis or at 45degrees thereof." +
+ "Second mark automatically snaps into position.",
+ Handler = SnapHandler
+ };
+
+ static void SnapHandler( Player player, CommandReader cmd ) {
+ DrawOperationBegin( player, cmd, new SnapDrawOperation( player ) );
+ }
+
-
static readonly CommandDescriptor CdTriangleWireframe = new CommandDescriptor {
Name = "TriangleW",
Aliases = new[] { "tw" },
Index: fCraft/Drawing/DrawOps/SnapDrawOperation.cs
===================================================================
--- fCraft/Drawing/DrawOps/SnapDrawOperation.cs (revision 0)
+++ fCraft/Drawing/DrawOps/SnapDrawOperation.cs (revision 0)
@@ -0,0 +1,49 @@
+using System;
+using System.Collections.Generic;
+
+namespace fCraft.Drawing
+{
+ public sealed class SnapDrawOperation : DrawOperation
+ {
+ public override string Name {
+ get { return "Snap"; }
+ }
+
+ public override int ExpectedMarks {
+ get { return 2; }
+ }
+
+ public SnapDrawOperation( Player player )
+ : base( player ) {
+ }
+
+
+ public override bool Prepare( Vector3I[] marks ) {
+ if( !base.Prepare( marks ) ) return false;
+
+ Vector3I diff = new Vector3I(marks[1]-marks[0]);
+ foreach(Axis a in Enum.GetValues(typeof(Axis)))
+ marks[1][a]=(Math.Abs(diff[a])>Math.Abs(diff[diff.LongestAxis])>>1)?
+ marks[0][a]+Math.Abs(diff[diff.LongestAxis])*Math.Sign(diff[a]):
+ marks[0][a];
+
+ BlocksTotalEstimate = Math.Max( Bounds.Width, Math.Max( Bounds.Height, Bounds.Length ) );
+
+ coordEnumerator = LineEnumerator( marks[0], marks[1] ).GetEnumerator();
+ return true;
+ }
+
+
+ IEnumerator<Vector3I> coordEnumerator;
+ public override int DrawBatch( int maxBlocksToDraw ) {
+ int blocksDone = 0;
+ while( coordEnumerator.MoveNext() ) {
+ Coords = coordEnumerator.Current;
+ if( DrawOneBlock() ) {
+ blocksDone++;
+ if( blocksDone >= maxBlocksToDraw ) return blocksDone;
+ }
+ if( TimeToEndBatch ) return blocksDone;
+ }
+ IsDone = true;
+ return blocksDone;
+ }
+ }
+}
+
Show
fCraft/Commands/BuildingCommands.cs: line 67
Add:
fCraft/Commands/BuildingCommands.cs: line 230
Add:
Add a new file:
fCraft/Drawing/DrawOps/SnapDrawOperation.cs
Add:
Code: Select all
CommandManager.RegisterCommand( CdSnap );
CdSnap.Help += GeneralDrawingHelp;
Add:
Code: Select all
static readonly CommandDescriptor CdSnap = new CommandDescriptor {
Name = "Snap",
Aliases = new[] { "SnapLine", "sn", "sl" },
Category = CommandCategory.Building,
Permissions = new[] { Permission.Draw },
RepeatableSelection = true,
Help = "Draws a line along the axis or at 45degrees thereof." +
"Second mark automatically snaps into position.",
Handler = SnapHandler
};
static void SnapHandler( Player player, CommandReader cmd ) {
DrawOperationBegin( player, cmd, new SnapDrawOperation( player ) );
}
fCraft/Drawing/DrawOps/SnapDrawOperation.cs
Code: Select all
using System;
using System.Collections.Generic;
namespace fCraft.Drawing
{
public sealed class SnapDrawOperation : DrawOperation
{
public override string Name {
get { return "Snap"; }
}
public override int ExpectedMarks {
get { return 2; }
}
public SnapDrawOperation( Player player )
: base( player ) {
}
public override bool Prepare( Vector3I[] marks ) {
if( !base.Prepare( marks ) ) return false;
Vector3I diff = new Vector3I(marks[1]-marks[0]);
foreach(Axis a in Enum.GetValues(typeof(Axis)))
marks[1][a]=(Math.Abs(diff[a])>Math.Abs(diff[diff.LongestAxis])>>1)?
marks[0][a]+Math.Abs(diff[diff.LongestAxis])*Math.Sign(diff[a]):
marks[0][a];
BlocksTotalEstimate = Math.Max( Bounds.Width, Math.Max( Bounds.Height, Bounds.Length ) );
coordEnumerator = LineEnumerator( marks[0], marks[1] ).GetEnumerator();
return true;
}
IEnumerator<Vector3I> coordEnumerator;
public override int DrawBatch( int maxBlocksToDraw ) {
int blocksDone = 0;
while( coordEnumerator.MoveNext() ) {
Coords = coordEnumerator.Current;
if( DrawOneBlock() ) {
blocksDone++;
if( blocksDone >= maxBlocksToDraw ) return blocksDone;
}
if( TimeToEndBatch ) return blocksDone;
}
IsDone = true;
return blocksDone;
}
}
}