This program is intended to speed up the load times of some animations I am currently rendering on a mobile device. Currently I am creating animations frame-by-frame and adding them to an AnimationDrawable or some other animation object (I am using Xamarin). Once this is finished rendering, (if it did not crash from running out of memory), the animation is displayed.This current method has the following issues:slow loading times on some animations, animations happen sequentially and can not stack, and the phone running out of memory before the full animation can be rendered. I am not trying to lower the resolution of the images being rendered.My goal is to fix all three problems at once by shifting to a more parallel approach. By shifting to parallel the animations could render more quickly, avoid running out of memory, and the animations could be added dynamically (stacking them).I have begun research into the C# TPL Dataflow library and it looks very promising. I believe it will help me achieve exactly what I want by doing much of the heavy work in parallel and will let me organize the information into individual flowing blocks that have the ability to wait for information. I have begun to design what I believe to be the best approach in the flow diagram I have included.A brief explanation of the diagrams operation:At start an image is generated and stored as the current image. Then the initial image is set as the displayed image. Then the add random animation sleep is started, this is explained later. This is the end of normal execution.The rest of the blocks are actions that happen in parallel to the main thread except in the end where the main thread has to be accessed to set the displayed image.If the add random animation sleep period finishes, add a random animation to be performed, then sleep again. If the block does not finish, it was killed, that means that an animation was added to the current animations. This block will be started again after the current animation block completes (there are currently no more animations). The point of the add random animation is to add an animation if some animation has not been displayed in a while.If at any time a touch is made on the displayed image, its corresponding animation is added to be performed.When an animation is added, the random animation sleep is killed. Animations are added to the a current animations list. When this list empties (completes) the random animation sleep is started.The render frame block waits for there to be a current animation. When there is, renders the current frame, and adds it to the frame queue. This will run in parallel so that each frame can be rendered more quickly. Even though the frames are rendered in parallel, the dataflow blocks ensure information is passed along in the order it was recieved, in a FIFO manner.The sleep before grab frame is used to cause a delay between frames being displayed. This delay would be set to the length a frame should be displayed. ex: 1/24s for 24 frames per second. After the delay the frame is taken from the frame queue and over the main thread sets the displayed image. The only problem I see with this is a long frame render time could cause a visual delay.Is this the correct approach to solve my goals? Will this cause any potential issues? Any additional feedback is greatly appreciated!
Dynamic Animation Renderer
c#;animation;dataflow