libtcod / python-tcod

A high-performance Python port of libtcod. Includes the libtcodpy module for backwards compatibility with older projects.
BSD 2-Clause "Simplified" License
410 stars 36 forks source link

tcod.tileset won't update already set tiles. #81

Closed mjuchno closed 5 years ago

mjuchno commented 5 years ago

Hello, I wanted to experiment with tcod.tileset even though its API is provisional.

I am getting "module 'tcod' has no attribute 'tileset'" error when trying to use tcod.tileset.get_default(). Neither my IDE nor dir(tcod) show tileset attribute.

Am I using it the wrong way (with a bitmap font) or is it no longer available in version 11.1.0 ?

HexDecimal commented 5 years ago

The tcod.tileset module isn't implicitly imported by the libtcodpy API which is part of tcod, so you'll need to import it manually with import tcod.tileset. It's the same thing with tcod.event.

Once you add import tcod.tileset your IDE will know it exists.

HexDecimal commented 5 years ago

This was explained better for the tcod.event module. I've added more documentation to make it clear the need to import the tcod.tileset module.

mjuchno commented 5 years ago

Thanks! After I found tileset.py in the tcod folder I suspected that this might be the case.

What is the best place to ask question about the library (without opening issues)?

My experiment with tileset allowed me to change a tile (by altering a color table) after the console was initiated (using SDL2 renderer) but only before the tile was first used. After it was used any further modification with the same method did not do anything.

I'am aware that this functionality is not meant for animations or layer stacking but I was wondering if it could be. Here is how I tried doing it:

tile_set = libtcod.tileset.get_default() player_tile = tile_set.get_tile(glyph_number)

then altering a player_tile and after that:

tile_set.set_tile(glyph_number, player_tile)

the following I tried as a last resort, but it didn't help:

libtcod.tileset.set_default(tile_set)

HexDecimal commented 5 years ago

What is the best place to ask question about the library (without opening issues)?

You could continue talking on this issue, contact me directly, or discuss on the roguelikedev Discord or IRC channel. Sometimes people ask questions on Reddit.

https://discord.gg/jEgZtqB http://webchat.quakenet.org/?channels=rgrd https://www.reddit.com/r/roguelikedev/

I don't mind trivial issues being opened here, so that isn't a problem.

My experiment with tileset allowed me to change a tile (by altering a color table) after the console was initiated (using SDL2 renderer) but only before the tile was first used. After it was used any further modification with the same method did not do anything.

This could be an actual issue. There's an optimization in the SDL2 renderer that skips redrawing characters. It's supposed to be aware that tiles could be altered in a tileset but that might not be triggering.

mjuchno commented 5 years ago

Thanks! That could explain it. Unfortunately OPENGL2 gives exactly the same result and all other renders give me all sorts of other problems that testing this particular thing does not make sense.

I that something that can be fixed on the python-tcod side or rather on the SDL2 side?

Well anyway, I only finished the tutorial so far so I shouldn't be thinking about adding animation of layer stacking to a "skeleton" that has only a tutorial style core implemented.

HexDecimal commented 5 years ago

I assumed that OPENGL2 would fix it. If it didn't then this issue is narrowed down to the tileset implementation rather than any of libtcod's renderers. Renderers outside of SDL2/OPENGL2 don't support these tilesets.

HexDecimal commented 5 years ago

Tilesets should be fixed in python-tcod 11.1.1.

mjuchno commented 5 years ago

That's great! Thank you! I will definitely take it for a spin again when the new version shows up!

HexDecimal commented 5 years ago

I've already released that version. It should be finished deploying around now.

mjuchno commented 5 years ago

A very quick test during a coffee break shows that it works! Thank you!

I will have to test it more in my usual environment at home to verify few things from a quick test: -game window opening significantly slower (like 4sec, but it might be something wrong with the python setup on this particular machine) -first frame with an updated tile shows a blank tile (or with an artifact white pixels on the left border) but when the screen is refreshed the tile is showed correctly. Maybe it is due the time needed for set_tile() to be update (documentation warns about it being slow).

I will test it more at home.

HexDecimal commented 5 years ago

set_tile() is slow since it usually needs to upload to the GPU. I expect it to be synchronous with other calls so there shouldn't be artifact frames. I didn't see that kind of issue in my own tests.

mjuchno commented 5 years ago

I've tested it a bit more on my home computer

The slow opening window was clearly a problem with that other environment. I don't have such behavior on this one.

As for the "artifact" it only appears in OPENGL2 renderer and SDL2 works fine, here is an example of how it looks like. (Of course changing a color is not the point here, but but being able to modify tiles pixels is)

HexDecimal commented 5 years ago

I've been unable to reproduce any artifacts. It could be graphics card specific or something else. Is it possible for me to see your repository?

mjuchno commented 5 years ago

My repo should be public now. engine_set_tile_test.py has renderer fixed to OPENGL2 in the main() and the part modifying the tile with set_tile() around the begging of play_game(). After starting the game, the tile color is changed every ~10 frames/events.

I have a bit non-standard graphics card setup so I wouldn't be surprised if that would be the reason, although it rarely gives me any problems like that. As for me, I'm already happy that SDL2 works fine and grateful that managed to fix it that quick! Thanks!

HexDecimal commented 5 years ago

Thanks for uploading that. With it I was able to reproduce and fix the issue.

mjuchno commented 5 years ago

Great! I'm glad I could help