VB.Net and Slow Console

A

Amzin

Hello. I'm writing roguelike using VB.NET. It has very slow
console output. Is there any methods to make it work faster?

For example,

Sub PlaceAt(ByVal s As String, ByVal x As Integer, ByVal y As
Integer)
Console.SetCursorPosition(x, y)
Console.Write(s)
End Sub

Sub Setcolor(ByVal fg, ByVal bg)
Console.ForegroundColor = fg
Console.BackgroundColor = bg
End Sub

For I = 0 To mapwidth
For J = 0 To mapheight
Setcolor(ConsoleColor.DarkBlue, ConsoleColor.Blue)
PlaceAt(things(map(I, J)).image, I, J)
Next
Next

When mapwidth=80 and mapheight=25 (standard console) screen fills with
coloured symbols in 2 seconds or more (Vista/XP). Is there workaround?
 
G

Göran Andersson

Amzin said:
Hello. I'm writing roguelike using VB.NET. It has very slow
console output. Is there any methods to make it work faster?

For example,

Sub PlaceAt(ByVal s As String, ByVal x As Integer, ByVal y As
Integer)
Console.SetCursorPosition(x, y)
Console.Write(s)
End Sub

Sub Setcolor(ByVal fg, ByVal bg)
Console.ForegroundColor = fg
Console.BackgroundColor = bg
End Sub

For I = 0 To mapwidth
For J = 0 To mapheight
Setcolor(ConsoleColor.DarkBlue, ConsoleColor.Blue)
PlaceAt(things(map(I, J)).image, I, J)
Next
Next

When mapwidth=80 and mapheight=25 (standard console) screen fills with
coloured symbols in 2 seconds or more (Vista/XP). Is there workaround?

Doesn't the console remember the color for more than one write? Move the
setting of the color outside the loop:

Setcolor(ConsoleColor.DarkBlue, ConsoleColor.Blue)
For I = 0 To mapwidth
For J = 0 To mapheight
PlaceAt(things(map(I, J)).image, I, J)
Next
Next

Then perhaps putting together a string for a complete line instead of
writing each character by themselves:

Setcolor(ConsoleColor.DarkBlue, ConsoleColor.Blue)
For J = 0 To mapheight
Dim line As New Char(mapwidth - 1)
For I = 0 To mapwidth
line(I) = things(map(I, J)).image.Chars(0)
Next
PlaceAt(New String(line), 0, J)
Next
 
A

Amzin

Doesn't the console remember the color for more than one write? Move the
setting of the color outside the loop:

Hello, Goran!
It not the case, unfortunately. My real application needs different
colors in each cell or like that - thats why I did insert colouring
into the inner cycle.
 
C

Cor Ligthert[MVP]

Amzin,

As the solution from Goran or things like that are not possible, then I
assume that you have to accept that you are doing something that needs an
extreme fast (expensive) video board to get a little bit more speed.

You ask for a solution for the speed and then you start to give all kind of
other obstructions which have nothing to do with your first question.

-Cor

"Amzin" <[email protected]> schreef in bericht
Doesn't the console remember the color for more than one write? Move the
setting of the color outside the loop:

Hello, Goran!
It not the case, unfortunately. My real application needs different
colors in each cell or like that - thats why I did insert colouring
into the inner cycle.
 
A

Amzin

Amzin,

As the solution from Goran or things like that are not possible, then I
assume that you have to accept that you are doing something that needs an
extreme fast (expensive) video board to get a little bit more speed.

Nevermind and thank you for your post. When I was using Qbasic any
text output was smooth and fast. My video card was very slow in those
times. As I can see Console class itself IS extremely slow. I'm trying
to use WinApi now instead.

Thank you.
 
G

Goran Andersson

Amzin said:
When I was using Qbasic any
text output was smooth and fast. My video card was very slow in those
times. As I can see Console class itself IS extremely slow. I'm trying
to use WinApi now instead.

Console output is always slow, and has always been. I am pretty sure
that what QBasic did to get fast output was to circumvent the console
(the standard output stream), and write directly to video memory. I know
that Turbo Pascal used that method.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top