开发者

Running text graphics over telnet efficiently

I have a simple game which you can play over telnet, but it refreshes the screen by printing a few line breaks and then sending the entire screen again. Sometimes this can cause flicker, and if the user scrolls up their terminal they see all the old frames.

What 开发者_StackOverflowimprovements could I make?

Is there a way to just modify certain characters rather than re-sending everything? This would probably prevent the flicker, and stop the users terminal from filling up with loads of old frames.

I tried sending the backspace character (8), but this doesn't go any further than the start of the current line. Something like this which goes to other lines would be perfect!

Also, I noticed that telnet towel.blinkenlights.nl doesn't use my horrible frame-sending method.. so I know there is a better solution.


Curses will do that. If you want to write it yourself, the algorithm is pretty simple. It remembers the state of the screen in one buffer, the program draws the new screen to another buffer, it calls a refresh, and the library compares the two buffers and only sends the required changes. It then copies the new buffer to the current buffer and then goes to the next frame. The tricky part is dealing with all the different terminal types and their control sequences to move the cursor around. The Curses stuff has a terminal library included.


Apparently I can use ANSI escape sequences.. seems to work okay on my terminal.

It's probably a horrible unsupported thing to do, but it answers the question so I'll leave the link here for anyone who may need it in the future.

http://www.termsys.demon.co.uk/vtansi.htm

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜