A few years ago we ended up getting a Roku for our cable cutting needs. It supports Netflix, Hulu, and Amazon Prime as well as a slew of other Streaming services that I hadn’t heard of before. It’s also simple to use (unlike the HTPC I built), which helps ensure that it gets used by the rest of the household. As an added bonus you can search a title, and it’ll return every service that has that title as well as the cost to buy/rent if available. It is well priced, and frankly I’m surprised more people haven’t gotten one.
It is also fairly accessible to program. The language is called BrightScript, and it sits in a comfortable place between easy to implement and flexible. BrightScript focuses on streaming audio and video from another source and not doing much (if any) local graphics processing. But the Roku 3 could handle simple games and it is perfect for displaying information, especially if the heavy lifting for that information is done elsewhere.
I have a screen saver that I put together for the Roku that displays dragons from the online game Flight Rising. It pulls them off the website, so as your dragons grow and change you’ll be able to see their latest incarnation pop up on the TV screen saver. It wasn’t very solid; it was a quick weekend project to help me learn BrightScript. I recently got a few kid free hours, and sat down to improve the screen saver. Specifically, addressing that the dragons have an odd white border surrounding them.
A quick inspection of the files showed that the dragon images didn’t contain a white border, and a test confirmed that the issue wasn’t in the image, but with how it was I was rendering it with the Roku. As I started to dig through the code, I ended up refactoring it and fixing a bunch of problems. By the time I was done, the following things had been done:
- Fixed several graphical artifacts that only occasionally manifested (clipped sprites, abandoned sprites, dragons that failed to display)
According to the documentation, roCompositor.Draw() and roCompositor.DrawAll() differ only in that Draw() draws recently updated sprites, while DrawAll() redraws everything. However, in practice, Draw() seems to have issues tracking what sprites have been updated recently. Unless you are doing something with a fairly complex scene, DrawAll() seems like a better approach. - Improved the timing mechanism to make it more robust, flexible, and expandable.
- Improved the error handling on the process that grabs the images from the website
- Made the file retrieval more responsive
- Improved the local file storage
- Cleaned up the code to make it more readable and easier to manage
And, of course, I eventually figured out the problem with the white border. If the display object (roScreen in my case) does not have Alpha Blending enabled, then no objects drawn on it will have their alpha values evaluated, regardless of how they are configured. I believe this is due to the computational cost of calculating alpha values, and that a more complex application would toggle Alpha Blending strategically in order to streamline processing.
Once that was addressed the screen saver looks pretty solid. Next we’ll talk about how I got around a particularity in BrightScript’s Regex handling and it’s inability to tell how much storage space is available.
Post a Comment