Get SpriteConsole's sprite sheet when rendering sprite #287
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Related to #152 and also got me very very close to the fix included in this PR, so credits to aknautiyal.
I think the expected behavior is that a
SpriteConsole
has a sprite_sheet idx and uses this to render from the correctSpriteSheet
fromBTermInternal.sprite_sheets
. Currently though the code inbracket-terminal/src/hal/gl_common/shared_main_loop.rs
will only ever pull from the first sprite sheet. The change I provide here gets the correct sprite sheet idx from theSpriteConsole
so that it will render the correct sprite.Minimal case for reproduction:
The above code produces this output on current master, it is pulling from the first spritesheet for both
![image](https://user-images.githubusercontent.com/43679332/183944006-fe3e1e29-6b59-4ad7-9a0b-3536afe402d1.png)
SpriteConsoles
This PR produces this output, which has them each pulling their respective sprite sheets:
![image](https://user-images.githubusercontent.com/43679332/183944336-59b73eb7-ca54-4052-a473-d5d5e40fb9af.png)
I don't have a super deep understanding of this project's code yet so apologies if there's some glaring and obvious reason why this code is the way it is. This could also be a breaking change if some projects relied on it always pulling from the first spritesheet even when specifying others.
I assumed that it is pretty guaranteed that the
ConsoleBacking
will never mismatch and that the console will always be a SpriteConsole in that branch of the match statement so that the downcast should never panic. If there were a mismatch for some reason and the underlying Console isn't a SpriteConsole, I would assume there'd be a panic or some undefined behavior from trying to draw a sprite to it anyway.