Debugging waves with onPaint()

Jump to navigation Jump to search

Two important things here:

  • The bullet's fire time is the tick you call fire/setFire/setFireBullet. The following tick the bullet appears and has traveled forward by its speed once from the location you were when you fired it. The tick after you call fire is the first tick the enemy can see that you've fired a bullet. And the tick before you called fire is the last info you could use to aim, since on the firing tick, the bullet is fired before the gun is turned.
  • The order of operations is: (all other events), onScannedRobot, onPaint, run(), time increments. So if you fire from onScannedRobot, your graphics will line up. But if you fire from run(), things might look a tick behind, because they won't be painted until next tick's onPaint.
Voidious16:29, 17 May 2012

Re: "But if you fire from run(), things might look a tick behind"

Unless of course your bot is using a trick like making your "run()" code happen at the start of onPaint when onPaint is called, effectively re-ordering the "run()" code to be before "onPaint()" :-)

Rednaxela17:12, 17 May 2012
 

If you fire from run(), graphics can still line up if you also paint from that same run().

The way I do:

(all events), put all event data in a custom queue, execute() returns, cache battle state to avoid 1000 calls, process event queue and everything else in the order I want: radar, retrieve data from teammates, movement, fire gun, energy management, turn gun, send data to teammates, graphical debugging.

MN17:14, 17 May 2012

I assume you're referring to if you use the "getGraphics()" call instead of implementing "onPaint()" right?

At least personally I don't care for that approach because then either your bot will spend CPU time on the painting when painting is disabled, or you have to check if onPaint is called anyway.

Rednaxela17:34, 17 May 2012

Using getGraphics() also works. But I am implementing onPaint and storing an object in a member variable (that object contains the Graphics object), which is then consumed in the run() method. That variable is cleared before calling execute() (in case debug is disabled in the middle of a battle). It is bulky, but it is fast.

If painting is disabled, onPaint is not called and nothing is setted in that variable. Yep, there is one check to see if the variable was set. The onPaint event is treated a bit differently (separated queue) from other events to make it easier to process it at the end.

MN19:03, 17 May 2012
 

Well keep in mind that the difference between onPaint and getGraphics are twofold.

First if I recall, the painting done by getGraphics is synced better with your current activity. Also you don't have to store any of your painting data for later to paint (which if I recall is part of the sync issue).

Which makes getGraphics much more useful for debugging then onPaint in my humble opinion. Where as onPaint is better for fancy graphics for everyone else after it is released.

Chase-san23:55, 17 May 2012

The approach I told above is based in gathering all event data first, then process everything, only then do some output. Shift from an event driven architecture to a simpler request driven (input/process/output) architecture.

The main advantage is not being constrained with event ordering. Event ordering in Robocode doesn´t give any extra information. The main drawbacks are increased codesize (not an option for nanobots), and necessity of member variables (not an option for perceptual bots).

MN14:29, 18 May 2012

Of course, for private/temporary debugging, entangling draws and sysouts in the middle of other events is fine.

MN14:35, 18 May 2012
 

This is what I kind of what I figured the painting was for in the first place. :)

Chase-san03:23, 19 May 2012