Merged love.graphics.drawg into love.graphics.draw, and SpriteBatch:addg/setg into SpriteBatch:add/set (resolves issue #639)

This commit is contained in:
Alex Szpakowski
2013-07-17 18:34:57 -03:00
parent f9ce521794
commit 7cf7f3a25f
2 changed files with 79 additions and 113 deletions
+31 -57
View File
@@ -1168,64 +1168,40 @@ int w_getRendererInfo(lua_State *L)
return 1; return 1;
} }
/**
* Draws an Image at the specified coordinates, with rotation and
* scaling along both axes.
* @param x The x-coordinate.
* @param y The y-coordinate.
* @param angle The amount of rotation.
* @param sx The scale factor along the x-axis. (1 = normal).
* @param sy The scale factor along the y-axis. (1 = normal).
* @param ox The offset along the x-axis.
* @param oy The offset along the y-axis.
* @param kx Shear along the x-axis.
* @param ky Shear along the y-axis.
**/
int w_draw(lua_State *L) int w_draw(lua_State *L)
{ {
Drawable *drawable = luax_checktype<Drawable>(L, 1, "Drawable", GRAPHICS_DRAWABLE_T); Drawable *drawable = 0;
float x = (float)luaL_optnumber(L, 2, 0.0f); DrawGable *drawgable = 0;
float y = (float)luaL_optnumber(L, 3, 0.0f); Geometry *geom = 0;
float angle = (float)luaL_optnumber(L, 4, 0.0f); int startidx = 2;
float sx = (float)luaL_optnumber(L, 5, 1.0f);
float sy = (float)luaL_optnumber(L, 6, sx); if (luax_istype(L, 2, GRAPHICS_GEOMETRY_T))
float ox = (float)luaL_optnumber(L, 7, 0); {
float oy = (float)luaL_optnumber(L, 8, 0); drawgable = luax_checktype<DrawGable>(L, 1, "DrawGable", GRAPHICS_DRAWGABLE_T);
float kx = (float)luaL_optnumber(L, 9, 0); geom = luax_totype<Geometry>(L, 2, "Geometry", GRAPHICS_GEOMETRY_T);
float ky = (float)luaL_optnumber(L, 10, 0); startidx = 3;
drawable->draw(x, y, angle, sx, sy, ox, oy, kx, ky); }
return 0; else
} {
drawable = luax_checktype<Drawable>(L, 1, "Drawable", GRAPHICS_DRAWABLE_T);
startidx = 2;
}
float x = (float) luaL_optnumber(L, startidx + 0, 0.0);
float y = (float) luaL_optnumber(L, startidx + 1, 0.0);
float a = (float) luaL_optnumber(L, startidx + 2, 0.0);
float sx = (float) luaL_optnumber(L, startidx + 3, 1.0);
float sy = (float) luaL_optnumber(L, startidx + 4, sx);
float ox = (float) luaL_optnumber(L, startidx + 5, 0.0);
float oy = (float) luaL_optnumber(L, startidx + 6, 0.0);
float kx = (float) luaL_optnumber(L, startidx + 7, 0.0);
float ky = (float) luaL_optnumber(L, startidx + 8, 0.0);
if (drawgable && geom)
drawgable->drawg(geom, x, y, a, sx, sy, ox, oy, kx, ky);
else if (drawable)
drawable->draw(x, y, a, sx, sy, ox, oy, kx, ky);
/**
* Draws a portion of a DrawGable at the specified coordinates,
* with rotation and scaling along both axes.
*
* @param q The Quad to draw.
* @param x The x-coordinate.
* @param y The y-coordinate.
* @param angle The amount of rotation.
* @param sx The scale factor along the x-axis. (1 = normal).
* @param sy The scale factor along the y-axis. (1 = normal).
* @param ox The offset along the x-axis.
* @param oy The offset along the y-axis.
* @param kx Shear along the x-axis.
* @param ky Shear along the y-axis.
**/
int w_drawg(lua_State *L)
{
DrawGable *dq = luax_checktype<DrawGable>(L, 1, "DrawGable", GRAPHICS_DRAWGABLE_T);
Geometry *geom = luax_checkgeometry(L, 2);
float x = (float)luaL_optnumber(L, 3, 0.0f);
float y = (float)luaL_optnumber(L, 4, 0.0f);
float angle = (float)luaL_optnumber(L, 5, 0);
float sx = (float)luaL_optnumber(L, 6, 1);
float sy = (float)luaL_optnumber(L, 7, sx);
float ox = (float)luaL_optnumber(L, 8, 0);
float oy = (float)luaL_optnumber(L, 9, 0);
float kx = (float)luaL_optnumber(L, 10, 0);
float ky = (float)luaL_optnumber(L, 11, 0);
dq->drawg(geom, x, y, angle, sx, sy, ox, oy, kx, ky);
return 0; return 0;
} }
@@ -1564,8 +1540,6 @@ static const luaL_Reg functions[] =
{ "getRendererInfo", w_getRendererInfo }, { "getRendererInfo", w_getRendererInfo },
{ "draw", w_draw }, { "draw", w_draw },
{ "drawq", w_drawg }, // legacy
{ "drawg", w_drawg },
{ "print", w_print }, { "print", w_print },
{ "printf", w_printf }, { "printf", w_printf },
@@ -36,84 +36,78 @@ SpriteBatch *luax_checkspritebatch(lua_State *L, int idx)
int w_SpriteBatch_add(lua_State *L) int w_SpriteBatch_add(lua_State *L)
{ {
SpriteBatch *t = luax_checkspritebatch(L, 1); SpriteBatch *t = luax_checkspritebatch(L, 1);
float x = (float)luaL_optnumber(L, 2, 0.0f); Geometry *geom = 0;
float y = (float)luaL_optnumber(L, 3, 0.0f); int startidx = 2;
float angle = (float)luaL_optnumber(L, 4, 0.0f);
float sx = (float)luaL_optnumber(L, 5, 1.0f);
float sy = (float)luaL_optnumber(L, 6, sx);
float ox = (float)luaL_optnumber(L, 7, 0);
float oy = (float)luaL_optnumber(L, 8, 0);
float kx = (float)luaL_optnumber(L, 9, 0);
float ky = (float)luaL_optnumber(L, 10, 0);
lua_pushnumber(L, t->add(x, y, angle, sx, sy, ox, oy, kx, ky));
return 1;
}
int w_SpriteBatch_addg(lua_State *L) if (luax_istype(L, 2, GRAPHICS_GEOMETRY_T))
{ {
SpriteBatch *t = luax_checkspritebatch(L, 1); geom = luax_totype<Geometry>(L, 2, "Geometry", GRAPHICS_GEOMETRY_T);
Geometry *g = luax_checktype<Geometry>(L, 2, "Geometry", GRAPHICS_GEOMETRY_T); startidx = 3;
}
float x = (float)luaL_optnumber(L, 3, 0.0f); float x = (float) luaL_optnumber(L, startidx + 0, 0.0);
float y = (float)luaL_optnumber(L, 4, 0.0f); float y = (float) luaL_optnumber(L, startidx + 1, 0.0);
float angle = (float)luaL_optnumber(L, 5, 0.0f); float a = (float) luaL_optnumber(L, startidx + 2, 0.0);
float sx = (float)luaL_optnumber(L, 6, 1.0f); float sx = (float) luaL_optnumber(L, startidx + 3, 1.0);
float sy = (float)luaL_optnumber(L, 7, sx); float sy = (float) luaL_optnumber(L, startidx + 4, sx);
float ox = (float)luaL_optnumber(L, 8, 0); float ox = (float) luaL_optnumber(L, startidx + 5, 0.0);
float oy = (float)luaL_optnumber(L, 9, 0); float oy = (float) luaL_optnumber(L, startidx + 6, 0.0);
float kx = (float)luaL_optnumber(L, 10, 0); float kx = (float) luaL_optnumber(L, startidx + 7, 0.0);
float ky = (float)luaL_optnumber(L, 11, 0); float ky = (float) luaL_optnumber(L, startidx + 8, 0.0);
int id = 0;
try try
{ {
lua_pushnumber(L, t->addg(g, x, y, angle, sx, sy, ox, oy, kx, ky)); if (geom)
id = t->addg(geom, x, y, a, sx, sy, ox, oy, kx, ky);
else
id = t->add(x, y, a, sx, sy, ox, oy, kx, ky);
} }
catch (love::Exception &e) catch (love::Exception &e)
{ {
return luaL_error(L, "%s", e.what()); return luaL_error(L, "%s", e.what());
} }
lua_pushinteger(L, id);
return 1; return 1;
} }
int w_SpriteBatch_set(lua_State *L) int w_SpriteBatch_set(lua_State *L)
{ {
SpriteBatch *t = luax_checkspritebatch(L, 1); SpriteBatch *t = luax_checkspritebatch(L, 1);
int index = luaL_checkinteger(L, 2); int id = luaL_checkinteger(L, 2);
float x = (float)luaL_optnumber(L, 3, 0.0f);
float y = (float)luaL_optnumber(L, 4, 0.0f);
float angle = (float)luaL_optnumber(L, 5, 0.0f);
float sx = (float)luaL_optnumber(L, 6, 1.0f);
float sy = (float)luaL_optnumber(L, 7, sx);
float ox = (float)luaL_optnumber(L, 8, 0);
float oy = (float)luaL_optnumber(L, 9, 0);
float kx = (float)luaL_optnumber(L, 10, 0);
float ky = (float)luaL_optnumber(L, 11, 0);
t->add(x, y, angle, sx, sy, ox, oy, kx, ky, index);
return 0;
}
int w_SpriteBatch_setg(lua_State *L) Geometry *geom = 0;
{ int startidx = 3;
SpriteBatch *t = luax_checkspritebatch(L, 1);
int index = luaL_checkinteger(L, 2); if (luax_istype(L, 2, GRAPHICS_GEOMETRY_T))
Geometry *g = luax_checktype<Geometry>(L, 3, "Geometry", GRAPHICS_GEOMETRY_T); {
geom = luax_totype<Geometry>(L, 2, "Geometry", GRAPHICS_GEOMETRY_T);
startidx = 4;
}
float x = (float) luaL_optnumber(L, startidx + 0, 0.0);
float y = (float) luaL_optnumber(L, startidx + 1, 0.0);
float a = (float) luaL_optnumber(L, startidx + 2, 0.0);
float sx = (float) luaL_optnumber(L, startidx + 3, 1.0);
float sy = (float) luaL_optnumber(L, startidx + 4, sx);
float ox = (float) luaL_optnumber(L, startidx + 5, 0.0);
float oy = (float) luaL_optnumber(L, startidx + 6, 0.0);
float kx = (float) luaL_optnumber(L, startidx + 7, 0.0);
float ky = (float) luaL_optnumber(L, startidx + 8, 0.0);
float x = (float)luaL_optnumber(L, 4, 0.0f);
float y = (float)luaL_optnumber(L, 5, 0.0f);
float angle = (float)luaL_optnumber(L, 6, 0.0f);
float sx = (float)luaL_optnumber(L, 7, 1.0f);
float sy = (float)luaL_optnumber(L, 8, sx);
float ox = (float)luaL_optnumber(L, 9, 0);
float oy = (float)luaL_optnumber(L, 10, 0);
float kx = (float)luaL_optnumber(L, 11, 0);
float ky = (float)luaL_optnumber(L, 12, 0);
try try
{ {
t->addg(g, x, y, angle, sx, sy, ox, oy, kx, ky, index); if (geom)
t->addg(geom, x, y, a, sx, sy, ox, oy, kx, ky, id);
else
t->add(x, y, a, sx, sy, ox, oy, kx, ky, id);
} }
catch (love::Exception &e) catch (love::Exception &e)
{ {
return luaL_error(L, "%s", e.what()); return luaL_error(L, "%s", e.what());
} }
return 0; return 0;
} }
@@ -246,9 +240,7 @@ int w_SpriteBatch_getBufferSize(lua_State *L)
static const luaL_Reg functions[] = static const luaL_Reg functions[] =
{ {
{ "add", w_SpriteBatch_add }, { "add", w_SpriteBatch_add },
{ "addg", w_SpriteBatch_addg },
{ "set", w_SpriteBatch_set }, { "set", w_SpriteBatch_set },
{ "setg", w_SpriteBatch_setg },
{ "clear", w_SpriteBatch_clear }, { "clear", w_SpriteBatch_clear },
{ "bind", w_SpriteBatch_bind }, { "bind", w_SpriteBatch_bind },
{ "unbind", w_SpriteBatch_unbind }, { "unbind", w_SpriteBatch_unbind },