Closed Ape closed 4 years ago
The tileset is always rendered pixel perfect without scaling. Small letterboxes are used when needed and window resizing affects the console size (in characters).
This can now be done with tcod.console.recommended_size and tcod.console_flush. recommended_size
uses the window size and active tileset size to determine the size of the console. This replaces most of your resize
method. console_flush
should be given integer_scaling=True
and a console with the size from recommended_size
to achieve the fixed scaling and letterbox. The new console_flush
replaces your flush
method.
I implemented zooming by changing to different tileset character sizes.
This will work as normal, just be sure to change the tileset before calling recommended_size
.
This would also mean switching back to tcod.console_init_root
. The only things not implemented right now would be starting as a maximized window, but you can still get the window pointer with tcod.lib.TCOD_sys_get_sdl_window
, and then use tcod.lib.SDL_SetWindowFullscreen
I can give code examples if I didn't explain this well enough.
Thanks, always nice to have my code simplified.
Am I doing this right? Should I call tcod.console_init_root
and then create separate console instances on resize? Like this:
import numpy as np
import tcod
import tcod.console
class Display:
def __init__(self, game, title, console_size, fullscreen, vsync,
bg=(0, 0, 0)):
self.game = game
self.bg = bg
tcod.console_init_root(*console_size, title=title,
fullscreen=fullscreen, order="F", vsync=vsync)
tcod.mouse_show_cursor(False)
self.resize()
def resize(self):
max_size = np.array(tcod.console.recommended_size())
console_size = np.minimum(self.game.map.shape, max_size)
self.console = tcod.console.Console(*console_size, order="F")
def flush(self):
tcod.console_flush(self.console, integer_scaling=True)
This seems to at least have the effect that if I change the font with tcod.console_set_custom_font
and call my resize method, the font isn't actually changed, but tcod.console.recommended_size()
is still calculated using the new font.
You're doing it right. The font changes not being reflected in the rendering is a regression in libtcod, which I'll be fixing right now.
Version 11.11.0
has been released. It should show the correct tileset as you change it.
One last thing is that tcod.console_init_root
does return the important "root console" object and you should at least call that objects close
method when you're done with the libtcod window. Not doing so will give a warning as your program exits.
Thanks.
I now found an issue that the screen isn't redrawn properly after font change (+ my resize method). The screen sometimes just goes black after changing fonts and tiles are redrawn only when I change them (individually). It might be just an issue in my code, but it didn't happen before.
I figured I was going to forget something. Sounds like the "console cache" thinking that it doesn't need to redraw the tiles because the console size hasn't changed. I'll get that fixed too.
The blank screen was slightly confusing but I figured out how that happened. This should be the last fix.
Version 11.11.1
is deploying, it will be about 2 hours after this post for it to be available. Unless you install from the master branch or something.
Is this current solution good enough to close this issue?
Or are you still having trouble with something?
Sorry, I didn't test the latest version yet. Seems like 11.11.1 is missing some files: https://pypi.org/project/tcod/11.11.1/#files
I didn't notice that the Windows wheels failed to upload. I've redeployed it now.
I think resizing and redrawing are now working perfectly.
I still have one issue with the updated version. I used to be able to use color codes like this with console.print:
"123%c%c%c%c456%c789" % (tcod.COLCTRL_FORE_RGB, 255, 0, 0, tcod.COLCTRL_STOP)
It would print 123456789, where bold characters are correctly red. In the current version it prints this instead: 1235689.
I still have one issue with the updated version. I used to be able to use color codes like this with console.print: ...
Should be fixed in the latest release: 11.11.3
.
That previous example with color codes works now, but there seems to be still an issue with this:
"%c%c%c%c123%c\n456" % (tcod.COLCTRL_FORE_RGB, 255, 0, 0, tcod.COLCTRL_STOP)
If the new line character comes directly after the color code, it won't have an effect. If there is text between the color code and the new line character then it works.
Sorry for that. I've been having a hard time with the C string parser. At this point I'm just adding your examples to unit tests as you report them.
Released more fixes with 11.11.4
, if you find another problem then I might ask you to build from the sources later.
I think everything works again!
I noticed that the experimental
custrender.py
feature has been removed. I had implemented a custom window resize functionality using it, but it doesn't work anymore starting with python-tcod 11.7.0. Instead, it fails with this:Here's a demo about the functionality:
The tileset is always rendered pixel perfect without scaling. Small letterboxes are used when needed and window resizing affects the console size (in characters). I implemented zooming by changing to different tileset character sizes.
Is there a way to implement this functionality with the current python-tcod version?
Here's my code in case looking at it helps understanding the situation: