Help with an algorithm for dynamically updating text display

First, some background:

I do what can be a " roguelike ", so I can learn some interesting ideas that I have floating around in my head. The gameplay will not bypass the dungeon, but in any case, the display will be made in a similar fasion with simple ascii characters.

Being the fact that this is an independent exercise, I try to code it myself.

In the end, I would like the game to run on arbitrarily large game worlds. (to such an extent that I assume that the game is networked and distributed to many monitors in a computer lab).

Right now I have code that can read and write to arbitrary sections of the text console and create a simple partitioning system so that I can find the paths efficiently.


And now the question is:

I did some tests, and the biggest bottleneck is redrawing text consoles.

The presence of the game world, which will require intelligent display updates. I donโ€™t want to repeat the entire game buffer every frame ... I need the pointers on how to configure it so that it only draws sections of the game, to be updated. (and not just the individual characters that I have)

I manipulated the Windows console through windows.h, but I would also be interested in running it on Linux devices through the puTTY client connected to the server.

I tried to adapt some video processing procedures, since the ratio between the pixel and the symbol is almost 1: 1, but I was not lucky.

In fact, I just want to explain some of the principles underlying it. But some example (psudo) code will be nice too.

+4
source share
3 answers

I am not going to demand that this be understood, but I believe that this is close to the problem behind the legendary legendary Gosling Emacs . See his article entitled "The Redraw Algorithm", as well as the general problem of line-to-line correction .

+4
source

Use Curses, or if you need to do it yourself, read about VTnnn control codes. Both should work with windows and terms and consoles (and Windows). You can also read the hack source code for tips. This will allow you to change the characters on the screen wherever changes have occurred.

+6
source

Having a game world that will require intelligent display updates. I donโ€™t want to drag my entire game buffer every frame ... I need pointers on how to configure it so that it only draws sections of the game that have been updated. (and not just the individual characters that I have)

The size of the game world does not really matter, because all you have to do is work out a visible area for each client and send this data. If you have a typical 80x25 console display, you send only 2 or 3 kilobytes of data each time, even if you add color codes and the like. This is typical of most online games of this kind: update what a person can see, not everything in the world.

If you want to experiment with trying to find a way to reduce what you send, then feel free to do it for training purposes, but we are about 10 years ago when itโ€™s inefficient to update the console display in something close to real time, and it would be a shame to spend time to fix a problem that does not need to be fixed. Note that the linked PDF file gives an O (ND) solution, while just sending the entire console is half O (N), where N is defined as the sum of the lengths of A and B and D.

+1
source

All Articles