If your application requires continuous updates of data elements and there are dependencies between them, try breaking the computations into discrete units and perform one iteration per image frame displayed.
For example, the following figure shows an application that
runs a continuous physics simulation of a flag.
Figure 6-1 Flag simulation
The flag is made up of a grid of nodes that are connected
to the neighboring nodes. These nodes are shown in the following
Figure 6-2 Flag simulation grid
The simulation runs as a series of iterations. In one iteration,
all the nodes are updated and the image is redrawn.
The following operations are performed in each iteration:
- The node values
are read from a buffer A.
- A physics simulation computes the forces between
- The position and forces on the nodes are updated
and stored into buffer B.
- The flag image is drawn.
- Buffer A and buffer B are switched.
In this case, splitting the computations into iterations also
splits the dependencies. The data required for one frame is computed
in the previous frame.
Some types of simulation require many iterations for relatively
small movements. If this is the case, try computing multiple iterations
before drawing frames.