Flickering still present in console double buffer
-
lunes, 16 de julio de 2012 23:16
Update:
This question is now answered, but for all those wanting an easy to use buffer class for the console, I have decided to upload it. Please give credit where credit is due, thanks!
The object, along with an example can be found here:
http://code.msdn.microsoft.com/C-Console-Double-Buffer-adc31032
- Editado JeffrBaker lunes, 16 de julio de 2012 23:17
- Editado JeffrBaker lunes, 16 de julio de 2012 23:18
- Editado JeffrBaker martes, 17 de julio de 2012 2:34
- Editado JeffrBaker martes, 17 de julio de 2012 3:02 Updating code
- Editado JeffrBaker martes, 17 de julio de 2012 3:44
- Editado JeffrBaker martes, 17 de julio de 2012 3:44
- Editado JeffrBaker martes, 17 de julio de 2012 12:53
- Editado JeffrBaker martes, 17 de julio de 2012 13:07
- Editado JeffrBaker miércoles, 18 de julio de 2012 13:42
- Editado JeffrBaker miércoles, 18 de julio de 2012 13:43
- Editado JeffrBaker miércoles, 18 de julio de 2012 13:45
- Editado JeffrBaker miércoles, 18 de julio de 2012 14:19
- Editado JeffrBaker miércoles, 18 de julio de 2012 21:34
- Editado JeffrBaker sábado, 17 de noviembre de 2012 16:14
Todas las respuestas
-
martes, 17 de julio de 2012 3:25You could try keeping a copy of the buffer that was just written. Then when writing a new buffer to the screen, compare it to the old one cell by cell, and only redraw the cells that have changed.
-
martes, 17 de julio de 2012 3:37I can switch the code around easy enough and do that without any if statements. There is still an error in the print method that I can't seem to weed out. It prints gibberish.
-
martes, 17 de julio de 2012 4:43
This line...
temp = temp + graphic[i][j];
...appears to fill temp with a vertical column of characters, which then gets drawn as if it's a horizontal row. You probably need to swap the loops for i and j around.
-
martes, 17 de julio de 2012 12:52
Odd. That fixed the printing order, but there is still some flickering. If I continousy refresh the screen, it looks as if the image is getting drawn in the middle, then jumps up to the top. I think it may be my line placement. I will check that.
Thanks for your help!
I have updated the code.- Editado JeffrBaker martes, 17 de julio de 2012 12:53
-
martes, 17 de julio de 2012 13:50
Maybe you should write directly to output buffer using WriteConsoleOutput. With this function you can update the console is one action. Which is probably faster than writing to stdout.
See for a example: (first answer)
http://stackoverflow.com/questions/2754518/how-can-i-write-fast-colored-output-to-console
- Marcado como respuesta JeffrBaker miércoles, 18 de julio de 2012 3:05
-
martes, 17 de julio de 2012 18:27
You should also be using the StringBuilder class instead of a string
String temp = ""; //Console.Clear(); for(int i = 0; i < height;i++) { for(int j = 0; j<width;j++) { temp = temp + graphic[j][i]; } }
is very inefficient
Thanks, Paul
- Marcado como respuesta JeffrBaker miércoles, 18 de julio de 2012 3:05
- Desmarcado como respuesta JeffrBaker miércoles, 18 de julio de 2012 3:06
-
miércoles, 18 de julio de 2012 2:18Thanks! Was not aware of this functionality.
-
miércoles, 18 de julio de 2012 2:52
@Boothwine
I took a look, very intersting. I am a little confused on how I use the CharInfo. The example shows how to fill a page with a single character, but does not really explain how I would add many characters of different types to it. Do I just do buf[i].Char.AsciiChar = character; where character is the unique character over and over again?
Never mind, I tinkered and figured it out.
- Editado JeffrBaker miércoles, 18 de julio de 2012 2:59
- Editado JeffrBaker miércoles, 18 de julio de 2012 3:05
- Editado JeffrBaker miércoles, 18 de julio de 2012 3:05
- Editado JeffrBaker miércoles, 18 de julio de 2012 15:27

