I'm making a multiplayer game which involves drawing lines. It's based this game: http://curvefever.com/sites/default/files/resize/remote/ef86488088c618df13b34f8b87aafd4e-1107x808.jpg. The game is setup so each "worm" has an own bitmap. All these bitmaps then get drawn in another single bitmap for best performance. Now i'm trying to implement online multiplayer into the game. However I've had some doing struggle implementing online multiplayer. The thing is that I will need to reverse the state of the draw lines in case a packet from the server comes late to the client. The biggest problem is that the drawing needs to be done very fast since the game updates every 20th millisecond. However I figured out and tried some different approaches to this:
-Save the state of the whole context and then redraw it. This is probably the slowest method.
-Only save a part of the context (100x100) in a another bitmap hidden by looping through each pixel, then looping through each pixel from that bitmap to the main bitmap that is shown on the screen.
-Save each point of the drawn path in a some kind of path reference, then when reverting the context, draw this path with the background color (0,0,0,1).
-Saving the position in the bitmap of each pixel that gets drawn in a separate array and then setting that pixel alpha to 0 (in the drawn bitmap) when I need to undo.
The last approach or 2nd one should be the fastest of them all. Are my approaches that I've listed above correct or is there some method that I'm missing that I should use? I've been prototyping my approaches in code above but they have been rendered to slow or they haven't worked.