Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
mjuchno opened this issue Jul 29, 2019 · 16 comments
Closed

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

mjuchno opened this issue Jul 29, 2019 · 16 comments
Assignees
Labels

Comments

@mjuchno
Copy link

mjuchno commented Jul 29, 2019

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 HexDecimal self-assigned this Jul 29, 2019
@HexDecimal
Copy link
Collaborator

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 added a commit that referenced this issue Jul 29, 2019
@HexDecimal
Copy link
Collaborator

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
Copy link
Author

mjuchno commented Jul 30, 2019

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
Copy link
Collaborator

HexDecimal commented Jul 30, 2019

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
Copy link
Author

mjuchno commented Jul 31, 2019

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
Copy link
Collaborator

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 HexDecimal reopened this Jul 31, 2019
@HexDecimal HexDecimal changed the title "module 'tcod' has no attribute 'tileset'" when using tileset.get_default() tcod.tileset won't update already set tiles. Jul 31, 2019
@HexDecimal HexDecimal added bug and removed invalid labels Jul 31, 2019
@HexDecimal
Copy link
Collaborator

Tilesets should be fixed in python-tcod 11.1.1.

@mjuchno
Copy link
Author

mjuchno commented Aug 1, 2019

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

@HexDecimal
Copy link
Collaborator

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

@mjuchno
Copy link
Author

mjuchno commented Aug 1, 2019

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
Copy link
Collaborator

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
Copy link
Author

mjuchno commented Aug 2, 2019

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
Copy link
Collaborator

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
Copy link
Author

mjuchno commented Aug 3, 2019

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
Copy link
Collaborator

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

@mjuchno
Copy link
Author

mjuchno commented Aug 4, 2019

Great! I'm glad I could help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants