7

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?

eflles
  • 6,606
  • 11
  • 41
  • 55

5 Answers5

8

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
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • 1
    I think the fact you are guessing makes your answer basically useless. – Dave Hillier Feb 05 '09 at 12:28
  • @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 Feb 05 '09 at 13:08
  • 1
    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 Feb 05 '09 at 16:06
  • 1
    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 Feb 05 '09 at 16:18
  • Get over it. It's my opinion that your answer wasn't very good. It's only one down vote. – Dave Hillier Feb 05 '09 at 20:42
  • 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 Feb 05 '09 at 21:20
  • +1 for write it to a log file. Then you have it forever - even when you crash your system. – Steven Evers Feb 05 '09 at 22:37
4

"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
  • 61,751
  • 23
  • 87
  • 115
  • What is to say you can implement a console faster than the XNA team? – Dave Hillier Feb 05 '09 at 12:28
  • 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 Feb 05 '09 at 13:23
  • @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 Feb 06 '09 at 09:36
3

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
  • 18,105
  • 9
  • 43
  • 87
2

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.

0

Simply,you can do the following:

Create a class called e.g. Trace, and in the draw method you draw the information you need on the screen using SpriteBatch.DrawString(...) this is better than Console I guess ..

I hope this helps,

Peace.

Stecya
  • 22,896
  • 10
  • 72
  • 102
Zero
  • 118
  • 3
  • 14