mirror of
https://github.com/love2d/love.git
synced 2026-08-20 04:30:09 +02:00
More internal code cleanup
This commit is contained in:
@@ -28,7 +28,7 @@ namespace love
|
|||||||
namespace event
|
namespace event
|
||||||
{
|
{
|
||||||
|
|
||||||
Message::Message(std::string name, Variant *a, Variant *b, Variant *c, Variant *d)
|
Message::Message(const std::string &name, Variant *a, Variant *b, Variant *c, Variant *d)
|
||||||
: name(name)
|
: name(name)
|
||||||
, nargs(0)
|
, nargs(0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ private:
|
|||||||
int nargs;
|
int nargs;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Message(std::string name, Variant *a = NULL, Variant *b = NULL, Variant *c = NULL, Variant *d = NULL);
|
Message(const std::string &name, Variant *a = NULL, Variant *b = NULL, Variant *c = NULL, Variant *d = NULL);
|
||||||
~Message();
|
~Message();
|
||||||
|
|
||||||
int toLua(lua_State *L);
|
int toLua(lua_State *L);
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ namespace physfs
|
|||||||
|
|
||||||
extern bool hack_setupWriteDirectory();
|
extern bool hack_setupWriteDirectory();
|
||||||
|
|
||||||
File::File(std::string filename)
|
File::File(const std::string &filename)
|
||||||
: filename(filename)
|
: filename(filename)
|
||||||
, file(0)
|
, file(0)
|
||||||
, mode(filesystem::File::CLOSED)
|
, mode(filesystem::File::CLOSED)
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ public:
|
|||||||
* @param source The source from which to load the file. (Archive or directory)
|
* @param source The source from which to load the file. (Archive or directory)
|
||||||
* @param filename The relative filepath of the file to load from the source.
|
* @param filename The relative filepath of the file to load from the source.
|
||||||
**/
|
**/
|
||||||
File(std::string filename);
|
File(const std::string &filename);
|
||||||
|
|
||||||
virtual ~File();
|
virtual ~File();
|
||||||
|
|
||||||
|
|||||||
@@ -343,28 +343,17 @@ void Filesystem::append(const char *filename, const void *data, int64 size) cons
|
|||||||
|
|
||||||
int Filesystem::enumerate(lua_State *L)
|
int Filesystem::enumerate(lua_State *L)
|
||||||
{
|
{
|
||||||
int n = lua_gettop(L);
|
const char *dir = luaL_checkstring(L, 1);
|
||||||
|
|
||||||
if (n != 1)
|
|
||||||
return luaL_error(L, "Function requires a single parameter.");
|
|
||||||
|
|
||||||
int type = lua_type(L, 1);
|
|
||||||
|
|
||||||
if (type != LUA_TSTRING)
|
|
||||||
return luaL_error(L, "Function requires parameter of type string.");
|
|
||||||
|
|
||||||
const char *dir = lua_tostring(L, 1);
|
|
||||||
char **rc = PHYSFS_enumerateFiles(dir);
|
char **rc = PHYSFS_enumerateFiles(dir);
|
||||||
char **i;
|
|
||||||
int index = 1;
|
int index = 1;
|
||||||
|
|
||||||
lua_newtable(L);
|
lua_newtable(L);
|
||||||
|
|
||||||
for (i = rc; *i != 0; i++)
|
for (char **i = rc; *i != 0; i++)
|
||||||
{
|
{
|
||||||
lua_pushinteger(L, index);
|
|
||||||
lua_pushstring(L, *i);
|
lua_pushstring(L, *i);
|
||||||
lua_settable(L, -3);
|
lua_rawseti(L, -2, index);
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -507,7 +507,7 @@ void Canvas::startGrab(const std::vector<Canvas *> &canvases)
|
|||||||
for (size_t i = 0; i < canvases.size(); i++)
|
for (size_t i = 0; i < canvases.size(); i++)
|
||||||
canvases[i]->retain();
|
canvases[i]->retain();
|
||||||
|
|
||||||
// release previously attached canvases
|
// release any old canvases
|
||||||
for (size_t i = 0; i < attachedCanvases.size(); i++)
|
for (size_t i = 0; i < attachedCanvases.size(); i++)
|
||||||
attachedCanvases[i]->release();
|
attachedCanvases[i]->release();
|
||||||
|
|
||||||
@@ -687,7 +687,6 @@ void Canvas::unloadVolatile()
|
|||||||
settings.wrap = getWrap();
|
settings.wrap = getWrap();
|
||||||
strategy->deleteFBO(fbo, depth_stencil, img);
|
strategy->deleteFBO(fbo, depth_stencil, img);
|
||||||
|
|
||||||
// release attached canvases
|
|
||||||
for (size_t i = 0; i < attachedCanvases.size(); i++)
|
for (size_t i = 0; i < attachedCanvases.size(); i++)
|
||||||
attachedCanvases[i]->release();
|
attachedCanvases[i]->release();
|
||||||
|
|
||||||
|
|||||||
@@ -51,20 +51,20 @@ Font::Font(love::font::Rasterizer *r, const Image::Filter &filter)
|
|||||||
{
|
{
|
||||||
// try to find the best texture size match for the font size
|
// try to find the best texture size match for the font size
|
||||||
// default to the largest texture size if no rough match is found
|
// default to the largest texture size if no rough match is found
|
||||||
texture_size_index = NUM_TEXTURE_SIZES - 1;
|
textureSizeIndex = NUM_TEXTURE_SIZES - 1;
|
||||||
for (int i = 0; i < NUM_TEXTURE_SIZES; i++)
|
for (int i = 0; i < NUM_TEXTURE_SIZES; i++)
|
||||||
{
|
{
|
||||||
// base our chosen texture width/height on a very rough guess of the total size taken up by the font's used glyphs
|
// base our chosen texture width/height on a very rough guess of the total size taken up by the font's used glyphs
|
||||||
// the estimate is likely larger than the actual total size taken up, which is good since texture changes are expensive
|
// the estimate is likely larger than the actual total size taken up, which is good since texture changes are expensive
|
||||||
if ((height * 0.8) * height * 95 <= TEXTURE_WIDTHS[i] * TEXTURE_HEIGHTS[i])
|
if ((height * 0.8) * height * 95 <= TEXTURE_WIDTHS[i] * TEXTURE_HEIGHTS[i])
|
||||||
{
|
{
|
||||||
texture_size_index = i;
|
textureSizeIndex = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
texture_width = TEXTURE_WIDTHS[texture_size_index];
|
textureWidth = TEXTURE_WIDTHS[textureSizeIndex];
|
||||||
texture_height = TEXTURE_HEIGHTS[texture_size_index];
|
textureHeight = TEXTURE_HEIGHTS[textureSizeIndex];
|
||||||
|
|
||||||
love::font::GlyphData *gd = 0;
|
love::font::GlyphData *gd = 0;
|
||||||
|
|
||||||
@@ -102,8 +102,8 @@ bool Font::initializeTexture(GLint format)
|
|||||||
glTexImage2D(GL_TEXTURE_2D,
|
glTexImage2D(GL_TEXTURE_2D,
|
||||||
0,
|
0,
|
||||||
internalformat,
|
internalformat,
|
||||||
(GLsizei)texture_width,
|
(GLsizei)textureWidth,
|
||||||
(GLsizei)texture_height,
|
(GLsizei)textureHeight,
|
||||||
0,
|
0,
|
||||||
format,
|
format,
|
||||||
GL_UNSIGNED_BYTE,
|
GL_UNSIGNED_BYTE,
|
||||||
@@ -114,7 +114,7 @@ bool Font::initializeTexture(GLint format)
|
|||||||
|
|
||||||
void Font::createTexture()
|
void Font::createTexture()
|
||||||
{
|
{
|
||||||
texture_x = texture_y = rowHeight = TEXTURE_PADDING;
|
textureX = textureY = rowHeight = TEXTURE_PADDING;
|
||||||
|
|
||||||
GLuint t;
|
GLuint t;
|
||||||
glGenTextures(1, &t);
|
glGenTextures(1, &t);
|
||||||
@@ -132,17 +132,17 @@ void Font::createTexture()
|
|||||||
|
|
||||||
// try to initialize the texture, attempting smaller sizes if initialization fails
|
// try to initialize the texture, attempting smaller sizes if initialization fails
|
||||||
bool initialized = false;
|
bool initialized = false;
|
||||||
while (texture_size_index >= 0)
|
while (textureSizeIndex >= 0)
|
||||||
{
|
{
|
||||||
texture_width = TEXTURE_WIDTHS[texture_size_index];
|
textureWidth = TEXTURE_WIDTHS[textureSizeIndex];
|
||||||
texture_height = TEXTURE_HEIGHTS[texture_size_index];
|
textureHeight = TEXTURE_HEIGHTS[textureSizeIndex];
|
||||||
|
|
||||||
initialized = initializeTexture(format);
|
initialized = initializeTexture(format);
|
||||||
|
|
||||||
if (initialized || texture_size_index <= 0)
|
if (initialized || textureSizeIndex <= 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
--texture_size_index;
|
--textureSizeIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!initialized)
|
if (!initialized)
|
||||||
@@ -156,12 +156,12 @@ void Font::createTexture()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Fill the texture with transparent black
|
// Fill the texture with transparent black
|
||||||
std::vector<GLubyte> emptyData(texture_width * texture_height * (type == FONT_TRUETYPE ? 2 : 4), 0);
|
std::vector<GLubyte> emptyData(textureWidth * textureHeight * (type == FONT_TRUETYPE ? 2 : 4), 0);
|
||||||
glTexSubImage2D(GL_TEXTURE_2D,
|
glTexSubImage2D(GL_TEXTURE_2D,
|
||||||
0,
|
0,
|
||||||
0, 0,
|
0, 0,
|
||||||
(GLsizei)texture_width,
|
(GLsizei)textureWidth,
|
||||||
(GLsizei)texture_height,
|
(GLsizei)textureHeight,
|
||||||
format,
|
format,
|
||||||
GL_UNSIGNED_BYTE,
|
GL_UNSIGNED_BYTE,
|
||||||
&emptyData[0]);
|
&emptyData[0]);
|
||||||
@@ -175,14 +175,14 @@ Font::Glyph *Font::addGlyph(unsigned int glyph)
|
|||||||
int w = gd->getWidth();
|
int w = gd->getWidth();
|
||||||
int h = gd->getHeight();
|
int h = gd->getHeight();
|
||||||
|
|
||||||
if (texture_x + w + TEXTURE_PADDING > texture_width)
|
if (textureX + w + TEXTURE_PADDING > textureWidth)
|
||||||
{
|
{
|
||||||
// out of space - new row!
|
// out of space - new row!
|
||||||
texture_x = TEXTURE_PADDING;
|
textureX = TEXTURE_PADDING;
|
||||||
texture_y += rowHeight;
|
textureY += rowHeight;
|
||||||
rowHeight = TEXTURE_PADDING;
|
rowHeight = TEXTURE_PADDING;
|
||||||
}
|
}
|
||||||
if (texture_y + h + TEXTURE_PADDING > texture_height)
|
if (textureY + h + TEXTURE_PADDING > textureHeight)
|
||||||
{
|
{
|
||||||
// totally out of space - new texture!
|
// totally out of space - new texture!
|
||||||
createTexture();
|
createTexture();
|
||||||
@@ -203,8 +203,8 @@ Font::Glyph *Font::addGlyph(unsigned int glyph)
|
|||||||
bindTexture(t);
|
bindTexture(t);
|
||||||
glTexSubImage2D(GL_TEXTURE_2D,
|
glTexSubImage2D(GL_TEXTURE_2D,
|
||||||
0,
|
0,
|
||||||
texture_x,
|
textureX,
|
||||||
texture_y,
|
textureY,
|
||||||
w, h,
|
w, h,
|
||||||
(type == FONT_TRUETYPE ? GL_LUMINANCE_ALPHA : GL_RGBA),
|
(type == FONT_TRUETYPE ? GL_LUMINANCE_ALPHA : GL_RGBA),
|
||||||
GL_UNSIGNED_BYTE,
|
GL_UNSIGNED_BYTE,
|
||||||
@@ -213,12 +213,12 @@ Font::Glyph *Font::addGlyph(unsigned int glyph)
|
|||||||
g->texture = t;
|
g->texture = t;
|
||||||
|
|
||||||
Quad::Viewport v;
|
Quad::Viewport v;
|
||||||
v.x = (float) texture_x;
|
v.x = (float) textureX;
|
||||||
v.y = (float) texture_y;
|
v.y = (float) textureY;
|
||||||
v.w = (float) w;
|
v.w = (float) w;
|
||||||
v.h = (float) h;
|
v.h = (float) h;
|
||||||
|
|
||||||
Quad q = Quad(v, (const float) texture_width, (const float) texture_height);
|
Quad q = Quad(v, (const float) textureWidth, (const float) textureHeight);
|
||||||
const vertex *verts = q.getVertices();
|
const vertex *verts = q.getVertices();
|
||||||
|
|
||||||
// copy vertex data to the glyph and set proper bearing
|
// copy vertex data to the glyph and set proper bearing
|
||||||
@@ -231,7 +231,7 @@ Font::Glyph *Font::addGlyph(unsigned int glyph)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (w > 0)
|
if (w > 0)
|
||||||
texture_x += (w + TEXTURE_PADDING);
|
textureX += (w + TEXTURE_PADDING);
|
||||||
if (h > 0)
|
if (h > 0)
|
||||||
rowHeight = std::max(rowHeight, h + TEXTURE_PADDING);
|
rowHeight = std::max(rowHeight, h + TEXTURE_PADDING);
|
||||||
|
|
||||||
|
|||||||
@@ -183,12 +183,16 @@ private:
|
|||||||
float lineHeight;
|
float lineHeight;
|
||||||
float mSpacing; // modifies the spacing by multiplying it with this value
|
float mSpacing; // modifies the spacing by multiplying it with this value
|
||||||
|
|
||||||
int texture_size_index;
|
int textureSizeIndex;
|
||||||
int texture_width;
|
int textureWidth;
|
||||||
int texture_height;
|
int textureHeight;
|
||||||
|
|
||||||
|
// vector of packed textures
|
||||||
|
std::vector<GLuint> textures;
|
||||||
|
|
||||||
|
// maps glyphs to glyph texture information
|
||||||
|
std::map<unsigned int, Glyph *> glyphs;
|
||||||
|
|
||||||
std::vector<GLuint> textures; // vector of packed textures
|
|
||||||
std::map<unsigned int, Glyph *> glyphs; // maps glyphs to quad information
|
|
||||||
FontType type;
|
FontType type;
|
||||||
Image::Filter filter;
|
Image::Filter filter;
|
||||||
|
|
||||||
@@ -198,7 +202,7 @@ private:
|
|||||||
|
|
||||||
static const int TEXTURE_PADDING = 1;
|
static const int TEXTURE_PADDING = 1;
|
||||||
|
|
||||||
int texture_x, texture_y;
|
int textureX, textureY;
|
||||||
int rowHeight;
|
int rowHeight;
|
||||||
|
|
||||||
bool initializeTexture(GLint format);
|
bool initializeTexture(GLint format);
|
||||||
|
|||||||
@@ -272,33 +272,29 @@ bool Graphics::isCreated() const
|
|||||||
int Graphics::getModes(lua_State *L) const
|
int Graphics::getModes(lua_State *L) const
|
||||||
{
|
{
|
||||||
int n;
|
int n;
|
||||||
love::window::Window::WindowSize **modes = currentWindow->getFullscreenSizes(n);
|
love::window::Window::WindowSize *modes = currentWindow->getFullscreenSizes(n);
|
||||||
|
|
||||||
if (modes == 0)
|
if (modes == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
lua_newtable(L);
|
lua_createtable(L, n, 0);
|
||||||
|
|
||||||
for (int i = 0; i < n ; i++)
|
for (int i = 0; i < n ; i++)
|
||||||
{
|
{
|
||||||
lua_pushinteger(L, i+1);
|
lua_pushinteger(L, i+1);
|
||||||
lua_newtable(L);
|
lua_createtable(L, 0, 2);
|
||||||
|
|
||||||
// Inner table attribs.
|
// Inner table attribs.
|
||||||
|
|
||||||
lua_pushstring(L, "width");
|
lua_pushinteger(L, modes[i].width);
|
||||||
lua_pushinteger(L, modes[i]->width);
|
lua_setfield(L, -2, "width");
|
||||||
lua_settable(L, -3);
|
|
||||||
|
|
||||||
lua_pushstring(L, "height");
|
lua_pushinteger(L, modes[i].height);
|
||||||
lua_pushinteger(L, modes[i]->height);
|
lua_setfield(L, -2, "height");
|
||||||
lua_settable(L, -3);
|
|
||||||
|
|
||||||
// Inner table attribs end.
|
// Inner table attribs end.
|
||||||
|
|
||||||
lua_settable(L, -3);
|
lua_settable(L, -3);
|
||||||
|
|
||||||
delete modes[i];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
delete[] modes;
|
delete[] modes;
|
||||||
|
|||||||
@@ -71,9 +71,12 @@ Shader::Shader(const ShaderSources &sources)
|
|||||||
if (shaderSources.empty())
|
if (shaderSources.empty())
|
||||||
throw love::Exception("Cannot create shader: no source code!");
|
throw love::Exception("Cannot create shader: no source code!");
|
||||||
|
|
||||||
GLint maxtexunits;
|
if (maxTextureUnits <= 0)
|
||||||
glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxtexunits);
|
{
|
||||||
maxTextureUnits = std::max(maxtexunits - 1, 0);
|
GLint maxtexunits;
|
||||||
|
glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxtexunits);
|
||||||
|
maxTextureUnits = std::max(maxtexunits - 1, 0);
|
||||||
|
}
|
||||||
|
|
||||||
// initialize global texture id counters if needed
|
// initialize global texture id counters if needed
|
||||||
if (textureCounters.size() < (size_t) maxTextureUnits)
|
if (textureCounters.size() < (size_t) maxTextureUnits)
|
||||||
@@ -174,7 +177,7 @@ void Shader::createProgram(const std::vector<GLuint> &shaderids)
|
|||||||
|
|
||||||
if (status == GL_FALSE)
|
if (status == GL_FALSE)
|
||||||
{
|
{
|
||||||
const std::string warnings = getWarnings();
|
std::string warnings = getWarnings();
|
||||||
glDeleteProgram(program);
|
glDeleteProgram(program);
|
||||||
|
|
||||||
throw love::Exception("Cannot link shader program object:\n%s", warnings.c_str());
|
throw love::Exception("Cannot link shader program object:\n%s", warnings.c_str());
|
||||||
|
|||||||
@@ -179,14 +179,14 @@ int w_Canvas_clear(lua_State *L)
|
|||||||
}
|
}
|
||||||
else if (lua_istable(L, 2))
|
else if (lua_istable(L, 2))
|
||||||
{
|
{
|
||||||
lua_rawgeti(L, 2, 1);
|
for (int i = 1; i <= 4; i++)
|
||||||
c.r = (unsigned char)luaL_checkint(L, -1);
|
lua_rawgeti(L, 2, i);
|
||||||
lua_rawgeti(L, 2, 2);
|
|
||||||
c.g = (unsigned char)luaL_checkint(L, -1);
|
c.r = (unsigned char)luaL_checkint(L, -4);
|
||||||
lua_rawgeti(L, 2, 3);
|
c.g = (unsigned char)luaL_checkint(L, -3);
|
||||||
c.b = (unsigned char)luaL_checkint(L, -1);
|
c.b = (unsigned char)luaL_checkint(L, -2);
|
||||||
lua_rawgeti(L, 2, 4);
|
|
||||||
c.g = (unsigned char)luaL_optint(L, -1, 255);
|
c.g = (unsigned char)luaL_optint(L, -1, 255);
|
||||||
|
|
||||||
lua_pop(L, 4);
|
lua_pop(L, 4);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -601,14 +601,14 @@ int w_setColor(lua_State *L)
|
|||||||
Color c;
|
Color c;
|
||||||
if (lua_istable(L, 1))
|
if (lua_istable(L, 1))
|
||||||
{
|
{
|
||||||
lua_rawgeti(L, 1, 1);
|
for (int i = 1; i <= 4; i++)
|
||||||
c.r = (unsigned char)luaL_checkint(L, -1);
|
lua_rawgeti(L, 1, i);
|
||||||
lua_rawgeti(L, 1, 2);
|
|
||||||
c.g = (unsigned char)luaL_checkint(L, -1);
|
c.r = (unsigned char)luaL_checkint(L, -4);
|
||||||
lua_rawgeti(L, 1, 3);
|
c.g = (unsigned char)luaL_checkint(L, -3);
|
||||||
c.b = (unsigned char)luaL_checkint(L, -1);
|
c.b = (unsigned char)luaL_checkint(L, -2);
|
||||||
lua_rawgeti(L, 1, 4);
|
|
||||||
c.a = (unsigned char)luaL_optint(L, -1, 255);
|
c.a = (unsigned char)luaL_optint(L, -1, 255);
|
||||||
|
|
||||||
lua_pop(L, 4);
|
lua_pop(L, 4);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -637,14 +637,14 @@ int w_setBackgroundColor(lua_State *L)
|
|||||||
Color c;
|
Color c;
|
||||||
if (lua_istable(L, 1))
|
if (lua_istable(L, 1))
|
||||||
{
|
{
|
||||||
lua_rawgeti(L, 1, 1);
|
for (int i = 1; i <= 4; i++)
|
||||||
c.r = (unsigned char)luaL_checkint(L, -1);
|
lua_rawgeti(L, 1, i);
|
||||||
lua_rawgeti(L, 1, 2);
|
|
||||||
c.g = (unsigned char)luaL_checkint(L, -1);
|
c.r = (unsigned char)luaL_checkint(L, -4);
|
||||||
lua_rawgeti(L, 1, 3);
|
c.g = (unsigned char)luaL_checkint(L, -3);
|
||||||
c.b = (unsigned char)luaL_checkint(L, -1);
|
c.b = (unsigned char)luaL_checkint(L, -2);
|
||||||
lua_rawgeti(L, 1, 4);
|
|
||||||
c.a = (unsigned char)luaL_optint(L, -1, 255);
|
c.a = (unsigned char)luaL_optint(L, -1, 255);
|
||||||
|
|
||||||
lua_pop(L, 4);
|
lua_pop(L, 4);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -985,6 +985,7 @@ int w_setCanvases(lua_State *L)
|
|||||||
|
|
||||||
if (is_table)
|
if (is_table)
|
||||||
{
|
{
|
||||||
|
// grab the first canvas in the array and attach the rest
|
||||||
lua_rawgeti(L, 1, 1);
|
lua_rawgeti(L, 1, 1);
|
||||||
canvas = luax_checkcanvas(L, -1);
|
canvas = luax_checkcanvas(L, -1);
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
|
|||||||
@@ -158,18 +158,15 @@ int w_SpriteBatch_setColor(lua_State *L)
|
|||||||
}
|
}
|
||||||
else if (lua_istable(L, 2))
|
else if (lua_istable(L, 2))
|
||||||
{
|
{
|
||||||
lua_rawgeti(L, 2, 1);
|
for (int i = 1; i <= 4; i++)
|
||||||
c.r = (unsigned char) luaL_checkint(L, -1);
|
lua_rawgeti(L, 2, i);
|
||||||
lua_pop(L, 1);
|
|
||||||
lua_rawgeti(L, 2, 2);
|
c.r = (unsigned char) luaL_checkint(L, -4);
|
||||||
c.g = (unsigned char) luaL_checkint(L, -1);
|
c.g = (unsigned char) luaL_checkint(L, -3);
|
||||||
lua_pop(L, 1);
|
c.b = (unsigned char) luaL_checkint(L, -2);
|
||||||
lua_rawgeti(L, 2, 3);
|
|
||||||
c.b = (unsigned char) luaL_checkint(L, -1);
|
|
||||||
lua_pop(L, 1);
|
|
||||||
lua_rawgeti(L, 2, 4);
|
|
||||||
c.a = (unsigned char) luaL_optint(L, -1, 255);
|
c.a = (unsigned char) luaL_optint(L, -1, 255);
|
||||||
lua_pop(L, 1);
|
|
||||||
|
lua_pop(L, 4);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -131,13 +131,9 @@ void ImageData::load(Data *data)
|
|||||||
|
|
||||||
create(width, height, ilGetData());
|
create(width, height, ilGetData());
|
||||||
}
|
}
|
||||||
catch (love::Exception &)
|
|
||||||
{
|
|
||||||
ilDeleteImage(image);
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
catch (std::exception &e)
|
catch (std::exception &e)
|
||||||
{
|
{
|
||||||
|
// catches love and std exceptions
|
||||||
ilDeleteImage(image);
|
ilDeleteImage(image);
|
||||||
throw love::Exception("%s", e.what());
|
throw love::Exception("%s", e.what());
|
||||||
}
|
}
|
||||||
@@ -225,14 +221,9 @@ void ImageData::encode(love::filesystem::File *f, ImageData::Format format)
|
|||||||
f->write(encoded_data, size);
|
f->write(encoded_data, size);
|
||||||
f->close();
|
f->close();
|
||||||
}
|
}
|
||||||
catch (love::Exception &)
|
|
||||||
{
|
|
||||||
ilDeleteImage(tempimage);
|
|
||||||
delete[] encoded_data;
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
catch (std::exception &e)
|
catch (std::exception &e)
|
||||||
{
|
{
|
||||||
|
// catches love and std exceptions
|
||||||
ilDeleteImage(tempimage);
|
ilDeleteImage(tempimage);
|
||||||
delete[] encoded_data;
|
delete[] encoded_data;
|
||||||
throw love::Exception("%s", e.what());
|
throw love::Exception("%s", e.what());
|
||||||
|
|||||||
@@ -167,13 +167,14 @@ int w_ImageData_encode(lua_State *L)
|
|||||||
{
|
{
|
||||||
ext = file->getExtension();
|
ext = file->getExtension();
|
||||||
fmt = ext.c_str();
|
fmt = ext.c_str();
|
||||||
ImageData::getConstant(fmt, format);
|
if (!ImageData::getConstant(fmt, format))
|
||||||
|
return luaL_error(L, "Invalid image format '%s'.", fmt);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fmt = luaL_checkstring(L, 3);
|
fmt = luaL_checkstring(L, 3);
|
||||||
if (!ImageData::getConstant(fmt, format))
|
if (!ImageData::getConstant(fmt, format))
|
||||||
luaL_error(L, "Invalid image format.");
|
return luaL_error(L, "Invalid image format '%s'.", fmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
@@ -189,7 +190,6 @@ int w_ImageData_encode(lua_State *L)
|
|||||||
|
|
||||||
static const luaL_Reg functions[] =
|
static const luaL_Reg functions[] =
|
||||||
{
|
{
|
||||||
|
|
||||||
// Data
|
// Data
|
||||||
{ "getPointer", w_Data_getPointer },
|
{ "getPointer", w_Data_getPointer },
|
||||||
{ "getSize", w_Data_getSize },
|
{ "getSize", w_Data_getSize },
|
||||||
|
|||||||
@@ -38,8 +38,8 @@ namespace sdl
|
|||||||
{
|
{
|
||||||
|
|
||||||
Timer::Timer()
|
Timer::Timer()
|
||||||
: currTime(getMicroTime())
|
: currTime(0)
|
||||||
, prevFpsUpdate(currTime)
|
, prevFpsUpdate(0)
|
||||||
, fps(0)
|
, fps(0)
|
||||||
, averageDelta(0)
|
, averageDelta(0)
|
||||||
, fpsUpdateFrequency(1)
|
, fpsUpdateFrequency(1)
|
||||||
@@ -49,6 +49,8 @@ Timer::Timer()
|
|||||||
// Init the SDL timer system.
|
// Init the SDL timer system.
|
||||||
if (SDL_InitSubSystem(SDL_INIT_TIMER) < 0)
|
if (SDL_InitSubSystem(SDL_INIT_TIMER) < 0)
|
||||||
throw Exception(SDL_GetError());
|
throw Exception(SDL_GetError());
|
||||||
|
|
||||||
|
prevFpsUpdate = currTime = getMicroTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
Timer::~Timer()
|
Timer::~Timer()
|
||||||
|
|||||||
@@ -59,14 +59,14 @@ public:
|
|||||||
virtual void getWindow(int &width, int &height, WindowFlags &flags) const = 0;
|
virtual void getWindow(int &width, int &height, WindowFlags &flags) const = 0;
|
||||||
|
|
||||||
virtual bool checkWindowSize(int width, int height, bool fullscreen) const = 0;
|
virtual bool checkWindowSize(int width, int height, bool fullscreen) const = 0;
|
||||||
virtual WindowSize **getFullscreenSizes(int &n) const = 0;
|
virtual WindowSize *getFullscreenSizes(int &n) const = 0;
|
||||||
|
|
||||||
virtual int getWidth() const = 0;
|
virtual int getWidth() const = 0;
|
||||||
virtual int getHeight() const = 0;
|
virtual int getHeight() const = 0;
|
||||||
|
|
||||||
virtual bool isCreated() const = 0;
|
virtual bool isCreated() const = 0;
|
||||||
|
|
||||||
virtual void setWindowTitle(std::string &title) = 0;
|
virtual void setWindowTitle(const std::string &title) = 0;
|
||||||
virtual std::string getWindowTitle() const = 0;
|
virtual std::string getWindowTitle() const = 0;
|
||||||
|
|
||||||
virtual bool setIcon(love::image::ImageData *imgd) = 0;
|
virtual bool setIcon(love::image::ImageData *imgd) = 0;
|
||||||
|
|||||||
@@ -211,7 +211,7 @@ bool Window::checkWindowSize(int width, int height, bool fullscreen) const
|
|||||||
|
|
||||||
typedef Window::WindowSize WindowSize;
|
typedef Window::WindowSize WindowSize;
|
||||||
|
|
||||||
WindowSize **Window::getFullscreenSizes(int &n) const
|
WindowSize *Window::getFullscreenSizes(int &n) const
|
||||||
{
|
{
|
||||||
SDL_Rect **modes = SDL_ListModes(0, SDL_OPENGL | SDL_FULLSCREEN);
|
SDL_Rect **modes = SDL_ListModes(0, SDL_OPENGL | SDL_FULLSCREEN);
|
||||||
|
|
||||||
@@ -225,13 +225,12 @@ WindowSize **Window::getFullscreenSizes(int &n) const
|
|||||||
for (int i = 0; modes[i]; i++)
|
for (int i = 0; modes[i]; i++)
|
||||||
n++;
|
n++;
|
||||||
|
|
||||||
WindowSize **sizes = new WindowSize*[n];
|
WindowSize *sizes = new WindowSize[n];
|
||||||
|
|
||||||
for (int i = 0; i < n; i++)
|
for (int i = 0; i < n; i++)
|
||||||
{
|
{
|
||||||
sizes[i] = new WindowSize;
|
WindowSize w = {modes[i]->w, modes[i]->h};
|
||||||
sizes[i]->width = modes[i]->w;
|
sizes[i] = w;
|
||||||
sizes[i]->height = modes[i]->h;
|
|
||||||
}
|
}
|
||||||
return sizes;
|
return sizes;
|
||||||
}
|
}
|
||||||
@@ -251,7 +250,7 @@ bool Window::isCreated() const
|
|||||||
return created;
|
return created;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::setWindowTitle(std::string &title)
|
void Window::setWindowTitle(const std::string &title)
|
||||||
{
|
{
|
||||||
windowTitle = title;
|
windowTitle = title;
|
||||||
SDL_WM_SetCaption(windowTitle.c_str(), 0);
|
SDL_WM_SetCaption(windowTitle.c_str(), 0);
|
||||||
|
|||||||
@@ -41,14 +41,14 @@ public:
|
|||||||
void getWindow(int &width, int &height, WindowFlags &flags) const;
|
void getWindow(int &width, int &height, WindowFlags &flags) const;
|
||||||
|
|
||||||
bool checkWindowSize(int width, int height, bool fullscreen) const;
|
bool checkWindowSize(int width, int height, bool fullscreen) const;
|
||||||
WindowSize **getFullscreenSizes(int &n) const;
|
WindowSize *getFullscreenSizes(int &n) const;
|
||||||
|
|
||||||
int getWidth() const;
|
int getWidth() const;
|
||||||
int getHeight() const;
|
int getHeight() const;
|
||||||
|
|
||||||
bool isCreated() const;
|
bool isCreated() const;
|
||||||
|
|
||||||
void setWindowTitle(std::string &title);
|
void setWindowTitle(const std::string &title);
|
||||||
std::string getWindowTitle() const;
|
std::string getWindowTitle() const;
|
||||||
|
|
||||||
bool setIcon(love::image::ImageData *imgd);
|
bool setIcon(love::image::ImageData *imgd);
|
||||||
|
|||||||
Reference in New Issue
Block a user