Re: Render a View to a Bitmap - Some questions
Posted: Tue Feb 02, 2016 10:30 pm
Spogg wrote:Many thanks for doing that tulamide.
I actually think we are in agreement![]()
A "single" trigger source, like the stock trigger button, does not generate a single trigger but one in turn for all the items connected to it, depending on the connection order (as in Trog's tutorial). Plus we know that the Windows timer system is not accurate but Ruby runs at a steady 100Hz (as I understand it).
What is not complete in my understanding is that you suggest it might be possible to do this sync'ed thing in Green, if you had the time to demo it. Please don't spend any more of your valuable time on this, but I am intrigued by the idea that we could make lots of stuff happen simultaneously and in sync from just one trigger source and in green.
Cheers
Spogg
I've thought about your comparison with a real world circuit. There is a difference, but you probably already know about it, thanks to trog: A trigger can cause back-triggers. For example, if your LED would rely on another input, then the incoming trigger would activate the LEDs programming, which would ask the other input for data by sending a back-trigger.
That's certainly a huge difference to the real world circuits.
Regarding your second paragraph: The secret to synchronizing is buffering. I give you an example of how DirectSound starts several audio tracks in sync. Each track is given an id, starting from 0. Then, starting from the highest ID, each track fills a buffer with its data and sets a variable to its ID. When the last track, the one with ID 0, has filled the buffer, the variable is set to 0. The next component, say an algorithm that sends the buffer to the audiocard, waits until this variable is 0, only then it sends the buffer to the audio card.
That is also the reason for audible crackles. It means that it took too long for all tracks to fill the buffer, since the audio card uses the next buffer, as soon as the previous one is played. If there is no next buffer, it plays silence. That's when you should either reduce the number of audiotracks or increase the size of the buffer.
I've done the same with the Ruby module: A draw call waits for all code executed in the draw method. All the things are drawn into a bitmap (that you are never aware of and have no access to) with the size of the associated view. Only when the draw method is finished, the now completed bitmap is drawn on the screen. So, the individual LEDs are still drawn one after the other, but because the draw call waits for a bitmap, we don't see the individual drawings of the LEDs, but the finished bitmap with all LEDs in it.
Example (0 = LED off, X = LED on)
View's current bitmap (this is displayed): [00000000]
draw method is invoked, builds a new bitmap:
[X]
[XX]
[XXX]
[XXXX]
[XXXXX]
[XXXXXX]
[XXXXXXX]
[XXXXXXXX]
this whole process above is hidden, the user still sees [00000000]
now that the drawing is done, the new bitmap is displayed: [XXXXXXXX]
the user thinks that all of the LEDs have switched in sync.
And this can be done in green as well