views:

542

answers:

4
+3  Q: 

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?

+3  A: 

"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)

Pop Catalin
What is to say you can implement a console faster than the XNA team?
Dave Hillier
The console is not implemented by the XNA team, the console he is using (If I'm not mistaken) is the Win32 Console.
Pop Catalin
Changed my vote since you've changed your answer!
Dave Hillier
@Dave Hillie, I appreciate negative votes equally, they mean, I wasn't clear or I've missed something or that I said something which is not correct, in which case I need to go back and review my answer, possibly correcting it or seeking more information about it. Thanks.
Pop Catalin
+3  A: 

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.

Jon Skeet
Downvoters: comments make the downvotes actually *helpful*.
Jon Skeet
I think the fact you are guessing makes your answer basically useless.
Dave Hillier
@Dave: On the contrary, I've given suggestions for areas of exploration and options which may well hope. You wrote "It is likely" which indicates uncertainty too. Does that make your answer useless?
Jon Skeet
Yes, it is useless, if it turns out that the assertion I make is false. I've used consoles to debug games previously. I have never experienced 'scrolling' as the cause of any slow downs.
Dave Hillier
So you're *assuming* that my guess is wrong and thus my answer is useless? Despite the fact that I've provided two alternatives that eflles can try, to see if they help? We clearly have a different idea of "useless".
Jon Skeet
Get over it. It's my opinion that your answer wasn't very good. It's only one down vote.
Dave Hillier
And it's my opinion that my answer is a perfectly reasonably starting point, rather than "basically useless". Why should I defend my point of view?
Jon Skeet
+1 for write it to a log file. Then you have it forever - even when you crash your system.
SnOrfus
+3  A: 

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.

Dave Hillier
+1  A: 

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.

BluePlateSpecial