moai/moai-dev — pull request #773 by seebs (2013-09-07 22:39:42+00:00)
Title: Overhaul of Grid/GridDeck2D/Prop interactions

It would be neat if grids had the ability to set color and scale
for each object. But it would also be neat if this weren't really
expensive. So! We create a new DrawRegion function for the grid,
which just calls another function through a function pointer. The
existing implementations of this logic in GridDeck2D and Prop are
combined into a function, with a little generalization. Then four
copies are made, one for each combination of color being present
(yes/no) and scale being present (yes/no), so if you don't add
colors and scales, you don't get a ton of extra processing. ZLColorVec
has an operator* now.

The actual implementation of the color is a bit ugly; we find the
current "ambient" color of the GfxDevice once at the start of the
loop, then for each grid element set the ambient color to the
starting color times that grid element's color, then restore the
original value after the loop. The reason for this is that the
alternative is to introduce another overload of Draw() which accepts
a color argument, and use that for *everything*, which is much
more intrusive. (On the other hand, it might be more efficient.
On the other, other, hand the way that polygons are getting rendered
right now is already running through multiple layers of indirection,
so I'm not sure it matters.)

Signed-off-by: Seebs