Build type information on first use (load-time), instead of using a hardcoded list

--HG--
branch : dynamiccore2
This commit is contained in:
Bart van Strien
2016-11-13 16:38:57 +01:00
parent 452a8a877e
commit c761202486
192 changed files with 734 additions and 614 deletions
+2
View File
@@ -38,6 +38,8 @@ class Drawable : public Object
{
public:
static love::Type type;
/**
* Destructor.
**/
+2
View File
@@ -58,6 +58,8 @@ void unGammaCorrectColor(Colorf &c)
}
}
love::Type Graphics::type(&Module::type);
Graphics::~Graphics()
{
}
+2
View File
@@ -63,6 +63,8 @@ class Graphics : public Module
{
public:
static love::Type type;
enum DrawMode
{
DRAW_LINE,
+2
View File
@@ -50,6 +50,8 @@ float calculate_variation(float inner, float outer, float var)
} // anonymous namespace
love::Type ParticleSystem::type(&Drawable::type);
ParticleSystem::ParticleSystem(Texture *texture, uint32 size)
: pMem(nullptr)
, pFree(nullptr)
+3
View File
@@ -45,6 +45,9 @@ namespace graphics
class ParticleSystem : public Drawable
{
public:
static love::Type type;
/**
* Type of distribution new particles are drawn from: None, uniform, normal, ellipse.
*/
+2
View File
@@ -29,6 +29,8 @@ namespace love
namespace graphics
{
love::Type Quad::type(&Object::type);
Quad::Quad(const Quad::Viewport &v, double sw, double sh)
: sw(sw)
, sh(sh)
+2
View File
@@ -34,6 +34,8 @@ class Quad : public Object
{
public:
static love::Type type;
struct Viewport
{
double x, y;
+2
View File
@@ -25,6 +25,8 @@ namespace love
namespace graphics
{
love::Type Texture::type(&Drawable::type);
Texture::Filter Texture::defaultFilter;
Texture::Texture()
+2
View File
@@ -40,6 +40,8 @@ class Texture : public Drawable
{
public:
static love::Type type;
enum WrapMode
{
WRAP_CLAMP,
+1
View File
@@ -88,6 +88,7 @@ static GLenum createMSAABuffer(int width, int height, int &samples, GLenum iform
return status;
}
love::Type Canvas::type(&Texture::type);
Canvas *Canvas::current = nullptr;
OpenGL::Viewport Canvas::systemViewport = OpenGL::Viewport();
bool Canvas::screenHasSRGB = false;
+2
View File
@@ -43,6 +43,8 @@ class Canvas : public Texture, public Volatile
{
public:
static love::Type type;
// Different Canvas render target formats.
enum Format
{
+8 -6
View File
@@ -39,6 +39,8 @@ namespace graphics
namespace opengl
{
love::Type Font::type(&Object::type);
static inline uint16 normToUint16(double n)
{
return (uint16) (n * LOVE_UINT16_MAX);
@@ -77,7 +79,7 @@ Font::Font(love::font::Rasterizer *r, const Texture::Filter &filter)
}
love::font::GlyphData *gd = r->getGlyphData(32); // Space character.
type = (gd->getFormat() == font::GlyphData::FORMAT_LUMINANCE_ALPHA) ? FONT_TRUETYPE : FONT_IMAGE;
fontType = (gd->getFormat() == font::GlyphData::FORMAT_LUMINANCE_ALPHA) ? FONT_TRUETYPE : FONT_IMAGE;
gd->release();
if (!r->hasGlyph(9)) // No tab character in the Rasterizer.
@@ -142,7 +144,7 @@ void Font::createTexture()
{
OpenGL::TempDebugGroup debuggroup("Font create texture");
size_t bpp = type == FONT_TRUETYPE ? 2 : 4;
size_t bpp = fontType == FONT_TRUETYPE ? 2 : 4;
size_t prevmemsize = textureMemorySize;
if (prevmemsize > 0)
@@ -177,7 +179,7 @@ void Font::createTexture()
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
GLenum internalformat = GL_RGBA;
GLenum format = getTextureFormat(type, &internalformat);
GLenum format = getTextureFormat(fontType, &internalformat);
// Initialize the texture with transparent black.
std::vector<GLubyte> emptydata(size.width * size.height * bpp, 0);
@@ -285,7 +287,7 @@ const Font::Glyph &Font::addGlyph(uint32 glyph)
// don't waste space for empty glyphs. also fixes a divide by zero bug with ATI drivers
if (w > 0 && h > 0)
{
GLenum format = getTextureFormat(type);
GLenum format = getTextureFormat(fontType);
g.texture = textures.back();
gl.bindTextureToUnit(g.texture, 0, false);
@@ -1021,7 +1023,7 @@ int Font::getDescent() const
float Font::getBaseline() const
{
// 1.25 is magic line height for true type fonts
return (type == FONT_TRUETYPE) ? floorf(getHeight() / 1.25f + 0.5f) : 0.0f;
return (fontType == FONT_TRUETYPE) ? floorf(getHeight() / 1.25f + 0.5f) : 0.0f;
}
bool Font::hasGlyph(uint32 glyph) const
@@ -1065,7 +1067,7 @@ void Font::setFallbacks(const std::vector<Font *> &fallbacks)
{
for (const Font *f : fallbacks)
{
if (f->type != this->type)
if (f->fontType != this->fontType)
throw love::Exception("Font fallbacks must be of the same font type.");
}
+3 -1
View File
@@ -50,6 +50,8 @@ class Font : public Object, public Volatile
{
public:
static love::Type type;
typedef std::vector<uint32> Codepoints;
enum AlignMode
@@ -235,7 +237,7 @@ private:
// map of left/right glyph pairs to horizontal kerning.
std::unordered_map<uint64, float> kerning;
FontType type;
FontType fontType;
Texture::Filter filter;
int textureX, textureY;
+2
View File
@@ -43,6 +43,8 @@ namespace graphics
namespace opengl
{
love::Type Image::type(&Texture::type);
int Image::imageCount = 0;
float Image::maxMipmapSharpness = 0.0f;
+2
View File
@@ -52,6 +52,8 @@ class Image : public Texture, public Volatile
{
public:
static love::Type type;
enum FlagType
{
FLAG_TYPE_MIPMAPS,
+2
View File
@@ -58,6 +58,8 @@ static std::vector<Mesh::AttribFormat> getDefaultVertexFormat()
return vertexformat;
}
love::Type Mesh::type(&Drawable::type);
Mesh::Mesh(const std::vector<AttribFormat> &vertexformat, const void *data, size_t datasize, DrawMode drawmode, Usage usage)
: vertexFormat(vertexformat)
, vbo(nullptr)
+2
View File
@@ -50,6 +50,8 @@ class Mesh : public Drawable
{
public:
static love::Type type;
// The expected usage pattern of the Mesh's vertex data.
enum Usage
{
+1
View File
@@ -62,6 +62,7 @@ namespace
} // anonymous namespace
love::Type Shader::type(&Object::type);
Shader *Shader::current = nullptr;
Shader *Shader::defaultShader = nullptr;
Shader *Shader::defaultVideoShader = nullptr;
+2
View File
@@ -48,6 +48,8 @@ class Shader : public Object, public Volatile
{
public:
static love::Type type;
enum ShaderStage
{
STAGE_VERTEX,
@@ -41,6 +41,8 @@ namespace graphics
namespace opengl
{
love::Type SpriteBatch::type(&Drawable::type);
SpriteBatch::SpriteBatch(Texture *texture, int size, Mesh::Usage usage)
: texture(texture)
, size(size)
@@ -52,6 +52,8 @@ class SpriteBatch : public Drawable
{
public:
static love::Type type;
SpriteBatch(Texture *texture, int size, Mesh::Usage usage);
virtual ~SpriteBatch();
+2
View File
@@ -30,6 +30,8 @@ namespace graphics
namespace opengl
{
love::Type Text::type(&Drawable::type);
Text::Text(Font *font, const std::vector<Font::ColoredString> &text)
: font(font)
, vbo(nullptr)
+2
View File
@@ -38,6 +38,8 @@ class Text : public Drawable
{
public:
static love::Type type;
Text(Font *font, const std::vector<Font::ColoredString> &text = {});
virtual ~Text();
+2
View File
@@ -30,6 +30,8 @@ namespace graphics
namespace opengl
{
love::Type Video::type(&Drawable::type);
Video::Video(love::video::VideoStream *stream)
: stream(stream)
, filter(Texture::getDefaultFilter())
+2
View File
@@ -40,6 +40,8 @@ class Video : public Drawable, public Volatile
{
public:
static love::Type type;
Video(love::video::VideoStream *stream);
~Video();
+4 -4
View File
@@ -30,7 +30,7 @@ namespace opengl
Canvas *luax_checkcanvas(lua_State *L, int idx)
{
return luax_checktype<Canvas>(L, idx, GRAPHICS_CANVAS_ID);
return luax_checktype<Canvas>(L, idx, Canvas::type);
}
int w_Canvas_renderTo(lua_State *L)
@@ -68,7 +68,7 @@ int w_Canvas_renderTo(lua_State *L)
int w_Canvas_newImageData(lua_State *L)
{
Canvas *canvas = luax_checkcanvas(L, 1);
love::image::Image *image = luax_getmodule<love::image::Image>(L, MODULE_IMAGE_ID);
love::image::Image *image = luax_getmodule<love::image::Image>(L, love::image::Image::type);
int x = (int) luaL_optnumber(L, 2, 0);
int y = (int) luaL_optnumber(L, 3, 0);
int w = (int) luaL_optnumber(L, 4, canvas->getWidth());
@@ -77,7 +77,7 @@ int w_Canvas_newImageData(lua_State *L)
love::image::ImageData *img = nullptr;
luax_catchexcept(L, [&](){ img = canvas->newImageData(image, x, y, w, h); });
luax_pushtype(L, IMAGE_IMAGE_DATA_ID, img);
luax_pushtype(L, love::image::ImageData::type, img);
img->release();
return 1;
}
@@ -112,7 +112,7 @@ static const luaL_Reg w_Canvas_functions[] =
extern "C" int luaopen_canvas(lua_State *L)
{
return luax_register_type(L, GRAPHICS_CANVAS_ID, "Canvas", w_Texture_functions, w_Canvas_functions, nullptr);
return luax_register_type(L, Canvas::type, "Canvas", w_Texture_functions, w_Canvas_functions, nullptr);
}
} // opengl
+2 -2
View File
@@ -35,7 +35,7 @@ namespace opengl
Font *luax_checkfont(lua_State *L, int idx)
{
return luax_checktype<Font>(L, idx, GRAPHICS_FONT_ID);
return luax_checktype<Font>(L, idx, Font::type);
}
int w_Font_getHeight(lua_State *L)
@@ -207,7 +207,7 @@ static const luaL_Reg w_Font_functions[] =
extern "C" int luaopen_font(lua_State *L)
{
return luax_register_type(L, GRAPHICS_FONT_ID, "Font", w_Font_functions, nullptr);
return luax_register_type(L, Font::type, "Font", w_Font_functions, nullptr);
}
} // opengl
+38 -38
View File
@@ -313,7 +313,7 @@ int w_newImage(lua_State *L)
bool releasedata = false;
// Convert to ImageData / CompressedImageData, if necessary.
if (lua_isstring(L, 1) || luax_istype(L, 1, FILESYSTEM_FILE_ID) || luax_istype(L, 1, FILESYSTEM_FILE_DATA_ID))
if (lua_isstring(L, 1) || luax_istype(L, 1, love::filesystem::File::type) || luax_istype(L, 1, love::filesystem::FileData::type))
{
auto imagemodule = Module::getInstance<love::image::Image>(Module::M_IMAGE);
if (imagemodule == nullptr)
@@ -339,7 +339,7 @@ int w_newImage(lua_State *L)
// Lua's GC won't release the image data, so we should do it ourselves.
releasedata = true;
}
else if (luax_istype(L, 1, IMAGE_COMPRESSED_IMAGE_DATA_ID))
else if (luax_istype(L, 1, love::image::CompressedImageData::type))
cdata.push_back(love::image::luax_checkcompressedimagedata(L, 1));
else
data.push_back(love::image::luax_checkimagedata(L, 1));
@@ -358,14 +358,14 @@ int w_newImage(lua_State *L)
if (!data.empty())
{
if (!luax_istype(L, -1, IMAGE_IMAGE_DATA_ID))
if (!luax_istype(L, -1, love::image::ImageData::type))
luax_convobj(L, -1, "image", "newImageData");
data.push_back(love::image::luax_checkimagedata(L, -1));
}
else if (!cdata.empty())
{
if (!luax_istype(L, -1, IMAGE_COMPRESSED_IMAGE_DATA_ID))
if (!luax_istype(L, -1, love::image::CompressedImageData::type))
luax_convobj(L, -1, "image", "newCompressedData");
cdata.push_back(love::image::luax_checkcompressedimagedata(L, -1));
@@ -402,7 +402,7 @@ int w_newImage(lua_State *L)
return luaL_error(L, "Could not load image.");
// Push the type.
luax_pushtype(L, GRAPHICS_IMAGE_ID, image);
luax_pushtype(L, Image::type, image);
image->release();
return 1;
}
@@ -421,7 +421,7 @@ int w_newQuad(lua_State *L)
double sh = luaL_checknumber(L, 6);
Quad *quad = instance()->newQuad(v, sw, sh);
luax_pushtype(L, GRAPHICS_QUAD_ID, quad);
luax_pushtype(L, Quad::type, quad);
quad->release();
return 1;
}
@@ -433,7 +433,7 @@ int w_newFont(lua_State *L)
Font *font = nullptr;
// Convert to Rasterizer, if necessary.
if (!luax_istype(L, 1, FONT_RASTERIZER_ID))
if (!luax_istype(L, 1, love::font::Rasterizer::type))
{
std::vector<int> idxs;
for (int i = 0; i < lua_gettop(L); i++)
@@ -442,14 +442,14 @@ int w_newFont(lua_State *L)
luax_convobj(L, &idxs[0], (int) idxs.size(), "font", "newRasterizer");
}
love::font::Rasterizer *rasterizer = luax_checktype<love::font::Rasterizer>(L, 1, FONT_RASTERIZER_ID);
love::font::Rasterizer *rasterizer = luax_checktype<love::font::Rasterizer>(L, 1, love::font::Rasterizer::type);
luax_catchexcept(L, [&]() {
font = instance()->newFont(rasterizer, instance()->getDefaultFilter()); }
);
// Push the type.
luax_pushtype(L, GRAPHICS_FONT_ID, font);
luax_pushtype(L, Font::type, font);
font->release();
return 1;
}
@@ -462,19 +462,19 @@ int w_newImageFont(lua_State *L)
Texture::Filter filter = instance()->getDefaultFilter();
// Convert to ImageData if necessary.
if (luax_istype(L, 1, GRAPHICS_IMAGE_ID))
if (luax_istype(L, 1, Image::type))
{
Image *i = luax_checktype<Image>(L, 1, GRAPHICS_IMAGE_ID);
Image *i = luax_checktype<Image>(L, 1, Image::type);
filter = i->getFilter();
const auto &idlevels = i->getImageData();
if (idlevels.empty())
return luaL_argerror(L, 1, "Image must not be compressed.");
luax_pushtype(L, IMAGE_IMAGE_DATA_ID, idlevels[0].get());
luax_pushtype(L, love::image::ImageData::type, idlevels[0].get());
lua_replace(L, 1);
}
// Convert to Rasterizer if necessary.
if (!luax_istype(L, 1, FONT_RASTERIZER_ID))
if (!luax_istype(L, 1, love::font::Rasterizer::type))
{
luaL_checktype(L, 2, LUA_TSTRING);
@@ -485,13 +485,13 @@ int w_newImageFont(lua_State *L)
luax_convobj(L, &idxs[0], (int) idxs.size(), "font", "newImageRasterizer");
}
love::font::Rasterizer *rasterizer = luax_checktype<love::font::Rasterizer>(L, 1, FONT_RASTERIZER_ID);
love::font::Rasterizer *rasterizer = luax_checktype<love::font::Rasterizer>(L, 1, love::font::Rasterizer::type);
// Create the font.
Font *font = instance()->newFont(rasterizer, filter);
// Push the type.
luax_pushtype(L, GRAPHICS_FONT_ID, font);
luax_pushtype(L, Font::type, font);
font->release();
return 1;
}
@@ -515,7 +515,7 @@ int w_newSpriteBatch(lua_State *L)
[&](){ t = instance()->newSpriteBatch(texture, size, usage); }
);
luax_pushtype(L, GRAPHICS_SPRITE_BATCH_ID, t);
luax_pushtype(L, SpriteBatch::type, t);
t->release();
return 1;
}
@@ -534,7 +534,7 @@ int w_newParticleSystem(lua_State *L)
[&](){ t = instance()->newParticleSystem(texture, int(size)); }
);
luax_pushtype(L, GRAPHICS_PARTICLE_SYSTEM_ID, t);
luax_pushtype(L, ParticleSystem::type, t);
t->release();
return 1;
}
@@ -561,7 +561,7 @@ int w_newCanvas(lua_State *L)
if (canvas == nullptr)
return luaL_error(L, "Canvas not created, but no error thrown. I don't even...");
luax_pushtype(L, GRAPHICS_CANVAS_ID, canvas);
luax_pushtype(L, Canvas::type, canvas);
canvas->release();
return 1;
}
@@ -654,7 +654,7 @@ int w_newShader(lua_State *L)
try
{
Shader *shader = instance()->newShader(source);
luax_pushtype(L, GRAPHICS_SHADER_ID, shader);
luax_pushtype(L, Shader::type, shader);
shader->release();
}
catch (love::Exception &e)
@@ -803,10 +803,10 @@ static Mesh *newCustomMesh(lua_State *L)
int vertexcount = (int) luaL_checknumber(L, 2);
luax_catchexcept(L, [&](){ t = instance()->newMesh(vertexformat, vertexcount, drawmode, usage); });
}
else if (luax_istype(L, 2, DATA_ID))
else if (luax_istype(L, 2, Data::type))
{
// Vertex data comes directly from a Data object.
Data *data = luax_checktype<Data>(L, 2, DATA_ID);
Data *data = luax_checktype<Data>(L, 2, Data::type);
luax_catchexcept(L, [&](){ t = instance()->newMesh(vertexformat, data->getData(), data->getSize(), drawmode, usage); });
}
else
@@ -886,7 +886,7 @@ int w_newMesh(lua_State *L)
else
t = newStandardMesh(L);
luax_pushtype(L, GRAPHICS_MESH_ID, t);
luax_pushtype(L, Mesh::type, t);
t->release();
return 1;
}
@@ -908,7 +908,7 @@ int w_newText(lua_State *L)
luax_catchexcept(L, [&](){ t = instance()->newText(font, text); });
}
luax_pushtype(L, GRAPHICS_TEXT_ID, t);
luax_pushtype(L, Text::type, t);
t->release();
return 1;
}
@@ -917,14 +917,14 @@ int w_newVideo(lua_State *L)
{
luax_checkgraphicscreated(L);
if (!luax_istype(L, 1, VIDEO_VIDEO_STREAM_ID))
if (!luax_istype(L, 1, love::video::VideoStream::type))
luax_convobj(L, 1, "video", "newVideoStream");
auto stream = luax_checktype<love::video::VideoStream>(L, 1, VIDEO_VIDEO_STREAM_ID);
auto stream = luax_checktype<love::video::VideoStream>(L, 1, love::video::VideoStream::type);
Video *video = nullptr;
luax_catchexcept(L, [&]() { video = instance()->newVideo(stream); });
luax_pushtype(L, GRAPHICS_VIDEO_ID, video);
luax_pushtype(L, Video::type, video);
video->release();
return 1;
}
@@ -1004,14 +1004,14 @@ int w_getBackgroundColor(lua_State *L)
int w_setNewFont(lua_State *L)
{
int ret = w_newFont(L);
Font *font = luax_checktype<Font>(L, -1, GRAPHICS_FONT_ID);
Font *font = luax_checktype<Font>(L, -1, Font::type);
instance()->setFont(font);
return ret;
}
int w_setFont(lua_State *L)
{
Font *font = luax_checktype<Font>(L, 1, GRAPHICS_FONT_ID);
Font *font = luax_checktype<Font>(L, 1, Font::type);
instance()->setFont(font);
return 0;
}
@@ -1021,7 +1021,7 @@ int w_getFont(lua_State *L)
Font *f = nullptr;
luax_catchexcept(L, [&](){ f = instance()->getFont(); });
luax_pushtype(L, GRAPHICS_FONT_ID, f);
luax_pushtype(L, Font::type, f);
return 1;
}
@@ -1248,13 +1248,13 @@ int w_isWireframe(lua_State *L)
int w_newScreenshot(lua_State *L)
{
love::image::Image *image = luax_getmodule<love::image::Image>(L, MODULE_IMAGE_ID);
love::image::Image *image = luax_getmodule<love::image::Image>(L, love::image::Image::type);
bool copyAlpha = luax_optboolean(L, 1, false);
love::image::ImageData *i = 0;
luax_catchexcept(L, [&](){ i = instance()->newScreenshot(image, copyAlpha); });
luax_pushtype(L, IMAGE_IMAGE_DATA_ID, i);
luax_pushtype(L, love::image::ImageData::type, i);
i->release();
return 1;
}
@@ -1306,7 +1306,7 @@ int w_getCanvas(lua_State *L)
for (Canvas *c : canvases)
{
luax_pushtype(L, GRAPHICS_CANVAS_ID, c);
luax_pushtype(L, Canvas::type, c);
n++;
}
@@ -1336,7 +1336,7 @@ int w_getShader(lua_State *L)
{
Shader *shader = instance()->getShader();
if (shader)
luax_pushtype(L, GRAPHICS_SHADER_ID, shader);
luax_pushtype(L, Shader::type, shader);
else
lua_pushnil(L);
@@ -1525,10 +1525,10 @@ int w_draw(lua_State *L)
Quad *quad = nullptr;
int startidx = 2;
if (luax_istype(L, 2, GRAPHICS_QUAD_ID))
if (luax_istype(L, 2, Quad::type))
{
texture = luax_checktexture(L, 1);
quad = luax_totype<Quad>(L, 2, GRAPHICS_QUAD_ID);
quad = luax_totype<Quad>(L, 2, Quad::type);
startidx = 3;
}
else if (lua_isnil(L, 2) && !lua_isnoneornil(L, 3))
@@ -1537,7 +1537,7 @@ int w_draw(lua_State *L)
}
else
{
drawable = luax_checktype<Drawable>(L, 1, GRAPHICS_DRAWABLE_ID);
drawable = luax_checktype<Drawable>(L, 1, Drawable::type);
startidx = 2;
}
@@ -2090,7 +2090,7 @@ static const luaL_Reg functions[] =
static int luaopen_drawable(lua_State *L)
{
return luax_register_type(L, GRAPHICS_DRAWABLE_ID, "Drawable", nullptr);
return luax_register_type(L, Drawable::type, "Drawable", nullptr);
}
// Types for this module.
@@ -2124,7 +2124,7 @@ extern "C" int luaopen_love_graphics(lua_State *L)
WrappedModule w;
w.module = instance;
w.name = "graphics";
w.type = MODULE_GRAPHICS_ID;
w.type = &Graphics::type;
w.functions = functions;
w.types = types;
+4 -4
View File
@@ -30,7 +30,7 @@ namespace opengl
Image *luax_checkimage(lua_State *L, int idx)
{
return luax_checktype<Image>(L, idx, GRAPHICS_IMAGE_ID);
return luax_checktype<Image>(L, idx, Image::type);
}
int w_Image_setMipmapFilter(lua_State *L)
@@ -98,7 +98,7 @@ int w_Image_getData(lua_State *L)
{
for (const auto &cdata : i->getCompressedData())
{
luax_pushtype(L, IMAGE_COMPRESSED_IMAGE_DATA_ID, cdata.get());
luax_pushtype(L, love::image::CompressedImageData::type, cdata.get());
n++;
}
}
@@ -106,7 +106,7 @@ int w_Image_getData(lua_State *L)
{
for (const auto &data : i->getImageData())
{
luax_pushtype(L, IMAGE_IMAGE_DATA_ID, data.get());
luax_pushtype(L, love::image::ImageData::type, data.get());
n++;
}
}
@@ -150,7 +150,7 @@ static const luaL_Reg w_Image_functions[] =
extern "C" int luaopen_image(lua_State *L)
{
return luax_register_type(L, GRAPHICS_IMAGE_ID, "Image", w_Texture_functions, w_Image_functions, nullptr);
return luax_register_type(L, Image::type, "Image", w_Texture_functions, w_Image_functions, nullptr);
}
} // opengl
+6 -6
View File
@@ -37,7 +37,7 @@ namespace opengl
Mesh *luax_checkmesh(lua_State *L, int idx)
{
return luax_checktype<Mesh>(L, idx, GRAPHICS_MESH_ID);
return luax_checktype<Mesh>(L, idx, Mesh::type);
}
static inline size_t writeByteData(lua_State *L, int startidx, int components, char *data)
@@ -117,9 +117,9 @@ int w_Mesh_setVertices(lua_State *L)
size_t stride = t->getVertexStride();
size_t byteoffset = vertoffset * stride;
if (luax_istype(L, 2, DATA_ID))
if (luax_istype(L, 2, Data::type))
{
Data *d = luax_checktype<Data>(L, 2, DATA_ID);
Data *d = luax_checktype<Data>(L, 2, Data::type);
size_t datasize = std::min(d->getSize(), (t->getVertexCount() - vertoffset) * stride);
char *bytedata = (char *) t->mapVertexData() + byteoffset;
@@ -437,9 +437,9 @@ int w_Mesh_getTexture(lua_State *L)
// FIXME: big hack right here.
if (typeid(*tex) == typeid(Image))
luax_pushtype(L, GRAPHICS_IMAGE_ID, tex);
luax_pushtype(L, Image::type, tex);
else if (typeid(*tex) == typeid(Canvas))
luax_pushtype(L, GRAPHICS_CANVAS_ID, tex);
luax_pushtype(L, Canvas::type, tex);
else
return luaL_error(L, "Unable to determine texture type.");
@@ -528,7 +528,7 @@ static const luaL_Reg w_Mesh_functions[] =
extern "C" int luaopen_mesh(lua_State *L)
{
return luax_register_type(L, GRAPHICS_MESH_ID, "Mesh", w_Mesh_functions, nullptr);
return luax_register_type(L, Mesh::type, "Mesh", w_Mesh_functions, nullptr);
}
} // opengl
@@ -41,7 +41,7 @@ namespace opengl
ParticleSystem *luax_checkparticlesystem(lua_State *L, int idx)
{
return luax_checktype<ParticleSystem>(L, idx, GRAPHICS_PARTICLE_SYSTEM_ID);
return luax_checktype<ParticleSystem>(L, idx, ParticleSystem::type);
}
int w_ParticleSystem_clone(lua_State *L)
@@ -51,7 +51,7 @@ int w_ParticleSystem_clone(lua_State *L)
ParticleSystem *clone = nullptr;
luax_catchexcept(L, [&](){ clone = t->clone(); });
luax_pushtype(L, GRAPHICS_PARTICLE_SYSTEM_ID, clone);
luax_pushtype(L, ParticleSystem::type, clone);
clone->release();
return 1;
}
@@ -71,9 +71,9 @@ int w_ParticleSystem_getTexture(lua_State *L)
// FIXME: big hack right here.
if (typeid(*tex) == typeid(Image))
luax_pushtype(L, GRAPHICS_IMAGE_ID, tex);
luax_pushtype(L, Image::type, tex);
else if (typeid(*tex) == typeid(Canvas))
luax_pushtype(L, GRAPHICS_CANVAS_ID, tex);
luax_pushtype(L, Canvas::type, tex);
else
return luaL_error(L, "Unable to determine texture type.");
@@ -584,7 +584,7 @@ int w_ParticleSystem_setQuads(lua_State *L)
{
lua_rawgeti(L, 2, i);
Quad *q = luax_checktype<Quad>(L, -1, GRAPHICS_QUAD_ID);
Quad *q = luax_checktype<Quad>(L, -1, Quad::type);
quads.push_back(q);
lua_pop(L, 1);
@@ -594,7 +594,7 @@ int w_ParticleSystem_setQuads(lua_State *L)
{
for (int i = 2; i <= lua_gettop(L); i++)
{
Quad *q = luax_checktype<Quad>(L, i, GRAPHICS_QUAD_ID);
Quad *q = luax_checktype<Quad>(L, i, Quad::type);
quads.push_back(q);
}
}
@@ -612,7 +612,7 @@ int w_ParticleSystem_getQuads(lua_State *L)
for (int i = 0; i < (int) quads.size(); i++)
{
luax_pushtype(L, GRAPHICS_QUAD_ID, quads[i]);
luax_pushtype(L, Quad::type, quads[i]);
lua_rawseti(L, -2, i + 1);
}
@@ -772,7 +772,7 @@ static const luaL_Reg w_ParticleSystem_functions[] =
extern "C" int luaopen_particlesystem(lua_State *L)
{
return luax_register_type(L, GRAPHICS_PARTICLE_SYSTEM_ID, "ParticleSystem", w_ParticleSystem_functions, nullptr);
return luax_register_type(L, ParticleSystem::type, "ParticleSystem", w_ParticleSystem_functions, nullptr);
}
} // opengl
+2 -2
View File
@@ -35,7 +35,7 @@ namespace opengl
Shader *luax_checkshader(lua_State *L, int idx)
{
return luax_checktype<Shader>(L, idx, GRAPHICS_SHADER_ID);
return luax_checktype<Shader>(L, idx, Shader::type);
}
int w_Shader_getWarnings(lua_State *L)
@@ -317,7 +317,7 @@ static const luaL_Reg w_Shader_functions[] =
extern "C" int luaopen_shader(lua_State *L)
{
return luax_register_type(L, GRAPHICS_SHADER_ID, "Shader", w_Shader_functions, nullptr);
return luax_register_type(L, Shader::type, "Shader", w_Shader_functions, nullptr);
}
} // opengl
@@ -36,16 +36,16 @@ namespace opengl
SpriteBatch *luax_checkspritebatch(lua_State *L, int idx)
{
return luax_checktype<SpriteBatch>(L, idx, GRAPHICS_SPRITE_BATCH_ID);
return luax_checktype<SpriteBatch>(L, idx, SpriteBatch::type);
}
static inline int w_SpriteBatch_add_or_set(lua_State *L, SpriteBatch *t, int startidx, int index)
{
Quad *quad = nullptr;
if (luax_istype(L, startidx, GRAPHICS_QUAD_ID))
if (luax_istype(L, startidx, Quad::type))
{
quad = luax_totype<Quad>(L, startidx, GRAPHICS_QUAD_ID);
quad = luax_totype<Quad>(L, startidx, Quad::type);
startidx++;
}
else if (lua_isnil(L, startidx) && !lua_isnoneornil(L, startidx + 1))
@@ -122,9 +122,9 @@ int w_SpriteBatch_getTexture(lua_State *L)
// FIXME: big hack right here.
if (typeid(*tex) == typeid(Image))
luax_pushtype(L, GRAPHICS_IMAGE_ID, tex);
luax_pushtype(L, Image::type, tex);
else if (typeid(*tex) == typeid(Canvas))
luax_pushtype(L, GRAPHICS_CANVAS_ID, tex);
luax_pushtype(L, Canvas::type, tex);
else
return luaL_error(L, "Unable to determine texture type.");
@@ -201,7 +201,7 @@ int w_SpriteBatch_attachAttribute(lua_State *L)
{
SpriteBatch *t = luax_checkspritebatch(L, 1);
const char *name = luaL_checkstring(L, 2);
Mesh *m = luax_checktype<Mesh>(L, 3, GRAPHICS_MESH_ID);
Mesh *m = luax_checktype<Mesh>(L, 3, Mesh::type);
luax_catchexcept(L, [&](){ t->attachAttribute(name, m); });
return 0;
@@ -257,7 +257,7 @@ static const luaL_Reg w_SpriteBatch_functions[] =
extern "C" int luaopen_spritebatch(lua_State *L)
{
return luax_register_type(L, GRAPHICS_SPRITE_BATCH_ID, "SpriteBatch", w_SpriteBatch_functions, nullptr);
return luax_register_type(L, SpriteBatch::type, "SpriteBatch", w_SpriteBatch_functions, nullptr);
}
} // opengl
+4 -4
View File
@@ -29,7 +29,7 @@ namespace opengl
Text *luax_checktext(lua_State *L, int idx)
{
return luax_checktype<Text>(L, idx, GRAPHICS_TEXT_ID);
return luax_checktype<Text>(L, idx, Text::type);
}
void luax_checkcoloredstring(lua_State *L, int idx, std::vector<Font::ColoredString> &strings)
@@ -190,7 +190,7 @@ int w_Text_clear(lua_State *L)
int w_Text_setFont(lua_State *L)
{
Text *t = luax_checktext(L, 1);
Font *f = luax_checktype<Font>(L, 2, GRAPHICS_FONT_ID);
Font *f = luax_checktype<Font>(L, 2, Font::type);
luax_catchexcept(L, [&](){ t->setFont(f); });
return 0;
}
@@ -199,7 +199,7 @@ int w_Text_getFont(lua_State *L)
{
Text *t = luax_checktext(L, 1);
Font *f = t->getFont();
luax_pushtype(L, GRAPHICS_FONT_ID, f);
luax_pushtype(L, Font::type, f);
return 1;
}
@@ -245,7 +245,7 @@ static const luaL_Reg w_Text_functions[] =
extern "C" int luaopen_text(lua_State *L)
{
return luax_register_type(L, GRAPHICS_TEXT_ID, "Text", w_Text_functions, nullptr);
return luax_register_type(L, Text::type, "Text", w_Text_functions, nullptr);
}
} // opengl
+6 -6
View File
@@ -34,13 +34,13 @@ namespace opengl
Video *luax_checkvideo(lua_State *L, int idx)
{
return luax_checktype<Video>(L, idx, GRAPHICS_VIDEO_ID);
return luax_checktype<Video>(L, idx, Video::type);
}
int w_Video_getStream(lua_State *L)
{
Video *video = luax_checkvideo(L, 1);
luax_pushtype(L, VIDEO_VIDEO_STREAM_ID, video->getStream());
luax_pushtype(L, love::video::VideoStream::type, video->getStream());
return 1;
}
@@ -49,7 +49,7 @@ int w_Video_getSource(lua_State *L)
Video *video = luax_checkvideo(L, 1);
auto source = video->getSource();
if (source)
luax_pushtype(L, AUDIO_SOURCE_ID, video->getSource());
luax_pushtype(L, love::audio::Source::type, video->getSource());
else
lua_pushnil(L);
return 1;
@@ -62,7 +62,7 @@ int w_Video_setSource(lua_State *L)
video->setSource(nullptr);
else
{
auto source = luax_checktype<love::audio::Source>(L, 2, AUDIO_SOURCE_ID);
auto source = luax_checktype<love::audio::Source>(L, 2, love::audio::Source::type);
video->setSource(source);
}
return 0;
@@ -143,10 +143,10 @@ static const luaL_Reg functions[] =
int luaopen_video(lua_State *L)
{
int ret = luax_register_type(L, GRAPHICS_VIDEO_ID, "Video", functions, nullptr);
int ret = luax_register_type(L, Video::type, "Video", functions, nullptr);
luaL_loadbuffer(L, video_lua, sizeof(video_lua), "Video.lua");
luax_gettypemetatable(L, GRAPHICS_VIDEO_ID);
luax_gettypemetatable(L, Video::type);
lua_call(L, 1, 0);
return ret;
+2 -2
View File
@@ -28,7 +28,7 @@ namespace graphics
Quad *luax_checkquad(lua_State *L, int idx)
{
return luax_checktype<Quad>(L, idx, GRAPHICS_QUAD_ID);
return luax_checktype<Quad>(L, idx, Quad::type);
}
int w_Quad_setViewport(lua_State *L)
@@ -84,7 +84,7 @@ static const luaL_Reg w_Quad_functions[] =
extern "C" int luaopen_quad(lua_State *L)
{
return luax_register_type(L, GRAPHICS_QUAD_ID, "Quad", w_Quad_functions, nullptr);
return luax_register_type(L, Quad::type, "Quad", w_Quad_functions, nullptr);
}
} // graphics
+2 -2
View File
@@ -27,7 +27,7 @@ namespace graphics
Texture *luax_checktexture(lua_State *L, int idx)
{
return luax_checktype<Texture>(L, idx, GRAPHICS_TEXTURE_ID);
return luax_checktype<Texture>(L, idx, Texture::type);
}
int w_Texture_getWidth(lua_State *L)
@@ -139,7 +139,7 @@ const luaL_Reg w_Texture_functions[] =
extern "C" int luaopen_texture(lua_State *L)
{
return luax_register_type(L, GRAPHICS_TEXTURE_ID, "Texture", w_Texture_functions, nullptr);
return luax_register_type(L, Texture::type, "Texture", w_Texture_functions, nullptr);
}
} // graphics