Archived

This topic is now archived and is closed to further replies.

Laroche

Console Clear Screen

Recommended Posts

Fruny    1658
MSDN Q99261 - HOWTO: Performing Clear Screen (CLS) in a Console Application.

Heh, look at the publication date

Anyway, I wouldn''t recommend system() for such a trivial task. It''s horribly inefficient.

Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]

Share this post


Link to post
Share on other sites
ElCrazon    308

  void clrscr()
{
COORD coordScreen = { 0, 0 };
DWORD cCharsWritten;
CONSOLE_SCREEN_BUFFER_INFO csbi;
DWORD dwConSize;
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);

GetConsoleScreenBufferInfo(hConsole, &csbi);
dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
FillConsoleOutputCharacter(hConsole, TEXT('' ''),
dwConSize,
coordScreen,
&cCharsWritten);
GetConsoleScreenBufferInfo(hConsole, &csbi);
FillConsoleOutputAttribute(hConsole,
csbi.wAttributes,
dwConSize,
coordScreen,
&cCharsWritten);
SetConsoleCursorPosition(hConsole, coordScreen);
}

should work, might be slow though...

Share this post


Link to post
Share on other sites
Laroche    140
hmm im asking because im fooling around at school making a sort of roguelike game, and I want it NOT to flicker as it redraws the characters. I had something like what elcrazon showed me, but it was too slow. Is system("cls") fast enough?

Share this post


Link to post
Share on other sites
Fruny    1658
quote:
Original post by Laroche
hmm im asking because im fooling around at school making a sort of roguelike game, and I want it NOT to flicker as it redraws the characters. I had something like what elcrazon showed me, but it was too slow. Is system("cls") fast enough?


Redraw only what needs to be redrawn, and write spaces to erase what needs to be erased. No cls.

Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]

Share this post


Link to post
Share on other sites
Laroche    140
Im not quite sure how I could only redraw parts of the map? Its stored in a multi-dimensional array of CTiles, which basically just have a char representing the onscreen "sprite" and an int for the effect it has. Its all been wrapped into a CMap class with a function called "render", which basically looks like this:

  
for (int y = 0; y < Height; ++y)
{
for (int x = 0; x < Width; ++x)
{
cout << pMap[x + y * Width].Sprite;
}
}


How would I write a function like render which would only update changes or something? Im a little lost, since im used to using graphics and not chars (im doing it for fun to fool around a bit)

Share this post


Link to post
Share on other sites
Fruny    1658
Look at the console functions (starting with those referenced in the MSDN article/code snippet), there are functions that let you change the position of the console cursor (i.e. choose where to write). It also has functions that will actually do the output.

At that level, I''m not sure how will streams interact with them.

you might also search for "ANSI control sequences", though it will not work on Win2k & later consoles (works fine in terminals like telnet, if you''re doing a networked version of nethack (finally ))

Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]

Share this post


Link to post
Share on other sites
You should look up the function
WriteConsoleOutput
It is pretty fast, as it does a ton of things in a single call. Its good for writting stuff to specific areas of the screen, i suggest you wrap it up in a small gameconsole engine.

Share this post


Link to post
Share on other sites
_Stinger    122
I beleive there is a function in conio.h (C runtime) called clrscr() but I haven''t used that for ages, and I havent tried it in a console window.

Share this post


Link to post
Share on other sites