[Home]Ugluk/Graphical Debugger

Robo Home | Ugluk | Changes | Preferences | AllPages

Showing revision 1
The following class is what I presently (9/12/2007) use to manage my drawing routines. During the normal run of my code, any class can add a line, square, or circle to the "to-do" list, specifying how long the graphics should last. Turn scope is for anything constantly updated (e.g. waves, wall intercept position). Round scope records events that last longer (e.g. where bullets have hit, tank travel paths). Battle scope is also available for the long haul.

Enjoy. -- Martin

public class GraphicalDebugger
{

	//:://////////////////////////////////////
	//::  Static Methods
	//:://////////////////////////////////////

	public static void drawVehicleHitBox( StaticPosition center, Color color )
	{
		GraphicalDebugger.addRenderableSquareTurnScope( center, 18.0, color );
	}

	public static void drawMarker( StaticPosition center, Color color )
	{
		GraphicalDebugger.addRenderableSquareTurnScope( center, 2.0, color );
	}

	public static void drawRenderableLineSegment( Graphics2D console, RenderableLineSegment o )
	{
		console.setColor( o.color );
		console.draw( new Line2D.Double( o.x1, o.y1, o.x2, o.y2 ) );
	}
	
	public static void drawRenderableRing( Graphics2D console, RenderableRing o )
	{
		console.setColor( o.color );
		console.draw( new Ellipse2D.Double( o.x - o.radius, o.y - o.radius, o.radius + o.radius, o.radius + o.radius ) );
	}
	
	public static void drawRenderableSquare( Graphics2D console, RenderableSquare o )
	{
		console.setColor( o.color );
		console.draw( new Rectangle2D.Double( o.x1, o.y1, o.x2 - o.x1, o.y2 - o.y1 ) );
		new Rectangle2D.Double(o.x1, o.y1, o.x2, o.y2 );
	}

	public static void drawRenderableLineSegments( Graphics2D console, Queue<RenderableLineSegment> queue )
	{
		Iterator iterator = queue.iterator();
		while( iterator.hasNext() )
		{
			GraphicalDebugger.drawRenderableLineSegment( console, (RenderableLineSegment)iterator.next() );
		}
	}
	
	public static void drawRenderableRings( Graphics2D console, Queue<RenderableRing> queue )
	{
		Iterator iterator = queue.iterator();
		while( iterator.hasNext() )
		{
			GraphicalDebugger.drawRenderableRing( console, (RenderableRing)iterator.next() );
		}
	}
	
	public static void drawRenderableSquares( Graphics2D console, Queue<RenderableSquare> queue )
	{
		Iterator iterator = queue.iterator();
		while( iterator.hasNext() )
		{
			GraphicalDebugger.drawRenderableSquare( console, (RenderableSquare)iterator.next() );
		}
	}
	
	public static void traceVehicleMovement( SnapshotHistory history )
	{
		Snapshot previousSnapshot = history.getHistoricalSnapshot( 1 );
		if( previousSnapshot != null )
		{
			if( history.getTime() - 1 == previousSnapshot.getTime() )
			{
				double distance = previousSnapshot.getDistance( history );
				float heat = (float)(distance / Constraints.maxAbsVehicleVelocity);
				GraphicalDebugger.addRenderableLineSegmentRoundScope( history, previousSnapshot, new Color( heat, heat, heat ) );
			}
		}
	}
	
	public static void traceBulletMovement( SnapshotHistory history )
	{
		Snapshot previousSnapshot = history.getHistoricalSnapshot( 1 );
		if( previousSnapshot != null )
		{
			if( history.getTime() - 1 == previousSnapshot.getTime() )
			{
				double distance = previousSnapshot.getDistance( history );
				float heat = (float)(distance / Constraints.maxBulletVelocity);
				GraphicalDebugger.addRenderableLineSegmentRoundScope( history, previousSnapshot, new Color( (float)1.0, (float)0.0, heat ) );
			}
		}
	}
	
	public static void addRenderableLineSegmentBattleScope( StaticPosition a, StaticPosition b, Color c ) { renderableLineSegmentsBattle.add( new RenderableLineSegment( a, b, c ) ); }
	public static void addRenderableLineSegmentRoundScope( StaticPosition a, StaticPosition b, Color c ) { renderableLineSegmentsRound.add( new RenderableLineSegment( a, b, c ) ); }
	public static void addRenderableLineSegmentTurnScope( StaticPosition a, StaticPosition b, Color c ) { renderableLineSegmentsTurn.add( new RenderableLineSegment( a, b, c ) ); }
	public static void addRenderableLineSegmentBattleScope( Line2D.Double line, Color c ) { renderableLineSegmentsBattle.add( new RenderableLineSegment( line, c ) ); }
	public static void addRenderableLineSegmentRoundScope( Line2D.Double line, Color c ) { renderableLineSegmentsRound.add( new RenderableLineSegment( line, c ) ); }
	public static void addRenderableLineSegmentTurnScope( Line2D.Double line, Color c ) { renderableLineSegmentsTurn.add( new RenderableLineSegment( line, c ) ); }
	public static void addRenderableRingBattleScope( StaticPosition a, double b, Color c ) { renderableRingsBattle.add( new RenderableRing( a, b, c ) ); }
	public static void addRenderableRingRoundScope( StaticPosition a, double b, Color c ) { renderableRingsRound.add( new RenderableRing( a, b, c ) ); }
	public static void addRenderableRingTurnScope( StaticPosition a, double b, Color c ) { renderableRingsTurn.add( new RenderableRing( a, b, c ) ); }
	public static void addRenderableSquareBattleScope( StaticPosition a, double b, Color c ) { renderableSquaresBattle.add( new RenderableSquare( a, b, c ) ); }
	public static void addRenderableSquareRoundScope( StaticPosition a, double b, Color c ) { renderableSquaresRound.add( new RenderableSquare( a, b, c ) ); }
	public static void addRenderableSquareTurnScope( StaticPosition a, double b, Color c ) { renderableSquaresTurn.add( new RenderableSquare( a, b, c ) ); }
	
	public static void onRoundSetup()
	{ 
		renderableLineSegmentsRound.clear();
		renderableRingsRound.clear();
		renderableSquaresRound.clear();
	}

	public static void onTurnSetup()
	{
		renderableLineSegmentsTurn.clear();
		renderableRingsTurn.clear();
		renderableSquaresTurn.clear();
	}
	
	public static void onPaint( Graphics2D console )
	{
		GraphicalDebugger.drawRenderableLineSegments( console, renderableLineSegmentsBattle );
		GraphicalDebugger.drawRenderableLineSegments( console, renderableLineSegmentsRound );
		GraphicalDebugger.drawRenderableLineSegments( console, renderableLineSegmentsTurn );
		GraphicalDebugger.drawRenderableRings( console, renderableRingsBattle );
		GraphicalDebugger.drawRenderableRings( console, renderableRingsRound );
		GraphicalDebugger.drawRenderableRings( console, renderableRingsTurn );
		GraphicalDebugger.drawRenderableSquares( console, renderableSquaresBattle );
		GraphicalDebugger.drawRenderableSquares( console, renderableSquaresRound );
		GraphicalDebugger.drawRenderableSquares( console, renderableSquaresTurn );
	}
	
	//:://////////////////////////////////////
	//::  Static Constants
	//:://////////////////////////////////////

	private static final Queue<RenderableLineSegment> renderableLineSegmentsBattle = new LinkedList<RenderableLineSegment>();
	private static final Queue<RenderableLineSegment> renderableLineSegmentsRound = new LinkedList<RenderableLineSegment>();
	private static final Queue<RenderableLineSegment> renderableLineSegmentsTurn = new LinkedList<RenderableLineSegment>();
	private static final Queue<RenderableRing> renderableRingsBattle = new LinkedList<RenderableRing>();
	private static final Queue<RenderableRing> renderableRingsRound = new LinkedList<RenderableRing>();
	private static final Queue<RenderableRing> renderableRingsTurn = new LinkedList<RenderableRing>();
	private static final Queue<RenderableSquare> renderableSquaresBattle = new LinkedList<RenderableSquare>();
	private static final Queue<RenderableSquare> renderableSquaresRound = new LinkedList<RenderableSquare>();
	private static final Queue<RenderableSquare> renderableSquaresTurn = new LinkedList<RenderableSquare>();

}

Robo Home | Ugluk | Changes | Preferences | AllPages
Edit revision 1 of this page | View other revisions | View current revision
Edited September 12, 2007 22:38 EST by Martin Alan Pedersen (diff)
Search: