Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xna debugging

I use the console.out.writeline() to print the coordinates belonging to the different sprites in a XNA game. But after a few seconds, the game starts to go really slow, and almost stop.
(When not writing to the console, there are no problems with performance). (The sprite's positions are written in every update method)

Is there a way to write to the console without destroying the performance to the game?

like image 362
eflles Avatar asked Feb 04 '09 17:02

eflles


4 Answers

Are you able to write to a log file instead of the console? That may well be faster due to buffering and the lack of scrolling, displaying etc.

Do you actually have a console up while this is running? If so, try minimising it when you're not interested. My guess is it's the scrolling which is causing the problem.

EDIT: Okay, it seems some evidence is in order.

A few tests... I don't have XNA installed, but different ways of writing to consoles are still interesting. I wrote the numbers 0-99999 to various consoles:

  • As a WinForms app, under the debugger, to the Visual Studio console: 135000ms, whether the console was visible or covered up.
  • As a WinForms app, under the debugger, writing to a file: 160ms
  • As a console app, not under the debugger, console minimised: 4149ms
  • As a console app, not under the debugger, console not minimised: 14514ms

So as you can see, the Visual Studio console is painfully slow, a non-minimised "normal" console is next slowest, a minimised console is reasonably nippy, and writing to a file is very quick.

I stand by my advice to try writing to a file instead of the console, and otherwise if it's a standalone console, try to minimise it for most of the time.

like image 152
Jon Skeet Avatar answered Oct 21 '22 05:10

Jon Skeet


"Is there a way to write to the console without destroying the performance to the game?"

Well, you could create your own ingame console like most game engines do (most notably Quake), and display the console when a key is pressed.

Edit:

if you don't want to implement your own console, there is a project doing this:

http://www.codeplex.com/XnaConsole

which has advantages over the Win32 console, because it runs in game, at game framerate, and won't make you loose your device when switching between the console and your xna app. (Although device recovery is automatic in XNA, loosing the device still happens under the covers)

like image 35
Pop Catalin Avatar answered Oct 21 '22 06:10

Pop Catalin


It is likely that you are writing too much data to the console. Reduce the frequency of console writes by using a counter or a timer. One update per second is usually enough to see what you need.

like image 3
Dave Hillier Avatar answered Oct 21 '22 06:10

Dave Hillier


I know this is an old post, but for those with similar questions there is a better way. There is another console-type library you can include that is really easy to use (a lot easier than the xna console project). It is called XNA Debug Terminal and it can be found at http://www.protohacks.net/xna_debug_terminal
This puts a terminal like command window on top of your game and allows you to view/set the value of any variable, invoke any method, or even watch values change in real time. It is completely open source and works with XNA 3.0 and XNA 3.1. This can easily allow you to see your sprite coordinates (or anything else) at any time during your game execution.

like image 2
BluePlateSpecial Avatar answered Oct 21 '22 05:10

BluePlateSpecial