Added an opportunity to disable caching for sprites #297
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.
Recently I attempted to create a video player in Go. I decoded video playback with Reisen and tried to play each frame using
sprite.Set()
and thensprite.Draw()
but I encountered an issue with RAM consumption. Pixel saves each picture the sprite receives throughsprite.Set()
. When we play a video, there gonna be a lot of different pictures going to the sprite. But there's no need for them after they were played on the screen.That's why I think there's no need to make all the sprites able to cache incoming pictures. I implemented
Cached
parameter forDrawer
andSetCached()
method forSprite
so the user can disable picture caching for the sprite for a period of time or forever.Here's a snippet of code that produces random images and passes them through a channel to the renderer for them to be displayed on the screen. Launch the terminal, execute
top
command, then run the code and see how the application process depletes your RAM.Source code
But if you add a
videoSprite.SetCached(false)
line right after the sprite creation fragment, the RAM consumption disappears and the amount of memory taken by the application stay approximately the same. This addition is really useful.