Speeding up terminal output?
[removed]
Posted Jan 25, 2019, 2:34 PM UTC
[removed]
Posted Jan 25, 2019, 2:34 PM UTC
https://docs.python.org/3/howto/curses.html
Or libraries that improve on curses:
I looked into those early on and of those, only asthmatics is cross-platform. curses and blessing are Linux only I believe..
Part of this for me is learning lower-level operations and not just feeding parameters into a library of screen/widget makers. (I do that all day long with PyQt)
Sure, it's re-inventing the wheel, but that's part of the fun for me.
I may have found a solution:
Instead of clearing the screen and drawing it again (which is what's causing the visible flickering, I can use escape characters to position the cursor at the top-left of the window and then draw over the existing screen.
Implemented in python 3.7, it looks like this:
def draw(self, clear_first=False):
""" Prints current screen to the output window """
if clear_first:
self.clear()
stdout.write(f"\x1b7\x1b[0;0f{self.array_to_string(self.screen)}\x1b8")
stdout.flush()
It's already quite a bit better, and could probably be improved even more by only drawing over the elements that need to be updated,
Wow - this what happens ehen you ask an applications programmer instead of a game developer. This type of question works better on the gamedev stack exchange.
Use libtcod.
http://roguecentral.org/doryen/data/libtcod/doc/1.5.1/index2.html
You could use a faster terminal.
alacritty is a GPU accelerated terminal, https://github.com/jwilm/alacritty
Thanks. I'll look into this in the future.
Don't redraw the whole screen every time, figure out what parts changed and then redraw those.