Re: [vassalengine-devel] making map painting more efficient
Brought to you by:
rodneykinney,
uckelman
From: Joel U. <uck...@no...> - 2006-11-29 15:59:51
|
Thus spake "Rodney Kinney": > > Whenever we paint a map, we're repainting everything which is visible, > > so far as can see. > > There are already some optimizations along these lines. Notice that the > Map, Board, and Stack draw() methods are overridden, and some of the > signatures take a visibleRect parameter. When drawing the map on the > screen, Map.draw() computes the visible rectangle and passes it through to > the other classes. This gives a speed-up most of the time, but it depends > on how expensive it is to call boundingBox() instead of draw(). For games > with lots of pieces on the map, it's a big payoff. To get further speedup, > we'd have to do something to cache the bounding boxes of the stacks, but > knowing when to update them is tricky. > > rk What you're talking about is avoiding painting objects outside of the visible rectangle, right? What I'm talking about is avoiding *re*painting things inside the visible rectangle. More specifically: We divide the Map into an array of Chunks. Each Chunk should have height and width roughly equal to the average height and width of objects on the Map, which ensures that most objects will intersect a small number of chunks. Each Chunk keeps a list of what objects fall into it, and whether it is "dirty", i.e., has changed since the last time it was painted. Whenever an object moves, we remove it from the Chunks its leaving, add it to the Chunks its entering, and mark all of those Chunks as dirty. On any given call to paint, we repaint just those dirty Chunks and set them to clean again. So, rather than repainting the whole visible area when I move one token, VASSAL could repaint just the few Chunks which it vacated and the few chunks into which it was dropped. -- J. |