diff --git a/changes.txt b/changes.txt index 8c79dab51..7288795f5 100644 --- a/changes.txt +++ b/changes.txt @@ -1,3 +1,34 @@ +LOVE 0.9.2 [Baby Inspector] +--------------------------- + + Released: N/A + + * Added Shader:getExternVariable. + * Added several new canvas texture formats. + * Added love.graphics.hasCanvasFormat. + * Added an optional duration argument to Joystick:setVibration. + * Added love.joystick.loadGamepadMappings and love.joystick.saveGamepadMappings. + * Added Joint:setUserData and Joint:getUserData. + * Added Body:getWorld. + * Added love.window.getDisplayName. + + * Fixed shader:getWarnings returning unnecessary information. + * Fixed love.filesystem.setIdentity breaking in some situations when called multiple times. + * Fixed a potential crash when Shader objects are garbage collected. + * Fixed love.graphics.newMesh(vertexcount, ...) causing the Mesh to do instanced rendering. + * Fixed Mesh:getVertexMap. + * Fixed Image:refresh generating mipmaps multiple times if mipmap filtering is enabled. + * Fixed Mesh:setDrawRange when the Mesh has a vertex map set. + * Fixed internal detection of the 'position' and 'effect' shader functions. + + * Renamed all cases of FSAA to MSAA. The FSAA names still exist for backward-compatibility. + + * Updated error message when love.math.setRandomseed(0) is attempted. + * Updated love.physics.newChainShape to error if the number of arguments is invalid. + * Updated love-created threads to use names visible in external debuggers. + * Updated SpriteBatch:unbind to use less VRAM if the SpriteBatch has the static usage hint. + * Updated love.graphics.newImage, love.image.newImageData, etc. to leave less Lua-owned memory around. + LOVE 0.9.1 [Baby Inspector] --------------------------- diff --git a/src/modules/graphics/Graphics.cpp b/src/modules/graphics/Graphics.cpp index 15bc9242b..b95786d81 100644 --- a/src/modules/graphics/Graphics.cpp +++ b/src/modules/graphics/Graphics.cpp @@ -184,7 +184,7 @@ StringMap::Entry Graphics::syst {"pointsize", Graphics::LIMIT_POINT_SIZE}, {"texturesize", Graphics::LIMIT_TEXTURE_SIZE}, {"multicanvas", Graphics::LIMIT_MULTI_CANVAS}, - {"canvasfsaa", Graphics::LIMIT_CANVAS_FSAA}, + {"canvasmsaa", Graphics::LIMIT_CANVAS_MSAA}, }; StringMap Graphics::systemLimits(Graphics::systemLimitEntries, sizeof(Graphics::systemLimitEntries)); diff --git a/src/modules/graphics/Graphics.h b/src/modules/graphics/Graphics.h index 1887de759..766d7e23d 100644 --- a/src/modules/graphics/Graphics.h +++ b/src/modules/graphics/Graphics.h @@ -102,7 +102,7 @@ public: LIMIT_POINT_SIZE, LIMIT_TEXTURE_SIZE, LIMIT_MULTI_CANVAS, - LIMIT_CANVAS_FSAA, + LIMIT_CANVAS_MSAA, LIMIT_MAX_ENUM }; diff --git a/src/modules/graphics/opengl/Canvas.cpp b/src/modules/graphics/opengl/Canvas.cpp index 955696ed6..818652487 100644 --- a/src/modules/graphics/opengl/Canvas.cpp +++ b/src/modules/graphics/opengl/Canvas.cpp @@ -417,15 +417,15 @@ static void getStrategy() } } -Canvas::Canvas(int width, int height, Format format, int fsaa) +Canvas::Canvas(int width, int height, Format format, int msaa) : fbo(0) , resolve_fbo(0) , texture(0) - , fsaa_buffer(0) + , msaa_buffer(0) , depth_stencil(0) , format(format) - , fsaa_samples(fsaa) - , fsaa_dirty(false) + , msaa_samples(msaa) + , msaa_dirty(false) { this->width = width; this->height = height; @@ -467,7 +467,7 @@ Canvas::~Canvas() unloadVolatile(); } -bool Canvas::createFSAAFBO(GLenum internalformat) +bool Canvas::createMSAAFBO(GLenum internalformat) { // Create our FBO without a texture. status = strategy->createFBO(fbo, 0); @@ -482,7 +482,7 @@ bool Canvas::createFSAAFBO(GLenum internalformat) } // Create and attach the MSAA buffer for our FBO. - if (strategy->createMSAABuffer(width, height, fsaa_samples, internalformat, fsaa_buffer)) + if (strategy->createMSAABuffer(width, height, msaa_samples, internalformat, msaa_buffer)) status = GL_FRAMEBUFFER_COMPLETE; else status = GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; @@ -494,10 +494,10 @@ bool Canvas::createFSAAFBO(GLenum internalformat) if (status != GL_FRAMEBUFFER_COMPLETE) { // Clean up. - strategy->deleteFBO(fbo, 0, fsaa_buffer); + strategy->deleteFBO(fbo, 0, msaa_buffer); strategy->deleteFBO(resolve_fbo, 0, 0); - fbo = fsaa_buffer = resolve_fbo = 0; - fsaa_samples = 0; + fbo = msaa_buffer = resolve_fbo = 0; + msaa_samples = 0; } if (current != this) @@ -509,7 +509,7 @@ bool Canvas::createFSAAFBO(GLenum internalformat) bool Canvas::loadVolatile() { fbo = depth_stencil = texture = 0; - resolve_fbo = fsaa_buffer = 0; + resolve_fbo = msaa_buffer = 0; status = GL_FRAMEBUFFER_COMPLETE; // glTexImage2D is guaranteed to error in this case. @@ -556,16 +556,16 @@ bool Canvas::loadVolatile() glGetIntegerv(GL_MAX_SAMPLES, &max_samples); } - if (fsaa_samples > max_samples) - fsaa_samples = max_samples; + if (msaa_samples > max_samples) + msaa_samples = max_samples; - // Try to create a FSAA FBO if requested. - bool fsaasuccess = false; - if (fsaa_samples > 1) - fsaasuccess = createFSAAFBO(internalformat); + // Try to create a MSAA FBO if requested. + bool msaasuccess = false; + if (msaa_samples > 1) + msaasuccess = createMSAAFBO(internalformat); - // On failure (or no requested FSAA), fall back to a regular FBO. - if (!fsaasuccess) + // On failure (or no requested MSAA), fall back to a regular FBO. + if (!msaasuccess) status = strategy->createFBO(fbo, texture); if (status != GL_FRAMEBUFFER_COMPLETE) @@ -573,20 +573,20 @@ bool Canvas::loadVolatile() clear(Color(0, 0, 0, 0)); - fsaa_dirty = (fsaa_buffer != 0); + msaa_dirty = (msaa_buffer != 0); return true; } void Canvas::unloadVolatile() { - strategy->deleteFBO(fbo, depth_stencil, fsaa_buffer); + strategy->deleteFBO(fbo, depth_stencil, msaa_buffer); strategy->deleteFBO(resolve_fbo, 0, 0); gl.deleteTexture(texture); fbo = depth_stencil = texture = 0; - resolve_fbo = fsaa_buffer = 0; + resolve_fbo = msaa_buffer = 0; for (size_t i = 0; i < attachedCanvases.size(); i++) attachedCanvases[i]->release(); @@ -705,8 +705,8 @@ void Canvas::setupGrab() else if (screenHasSRGB) glDisable(GL_FRAMEBUFFER_SRGB); - if (fsaa_buffer != 0) - fsaa_dirty = true; + if (msaa_buffer != 0) + msaa_dirty = true; } void Canvas::startGrab(const std::vector &canvases) @@ -723,8 +723,8 @@ void Canvas::startGrab(const std::vector &canvases) if ((int) canvases.size() + 1 > gl.getMaxRenderTargets()) throw love::Exception("This system can't simultaniously render to %d canvases.", canvases.size()+1); - if (fsaa_samples != 0) - throw love::Exception("Multi-canvas rendering is not supported with FSAA."); + if (msaa_samples != 0) + throw love::Exception("Multi-canvas rendering is not supported with MSAA."); } for (size_t i = 0; i < canvases.size(); i++) @@ -735,8 +735,8 @@ void Canvas::startGrab(const std::vector &canvases) if (canvases[i]->getTextureFormat() != format) throw love::Exception("All canvas arguments must have the same texture format."); - if (canvases[i]->getFSAA() != 0) - throw love::Exception("Multi-canvas rendering is not supported with FSAA."); + if (canvases[i]->getMSAA() != 0) + throw love::Exception("Multi-canvas rendering is not supported with MSAA."); if (!canvaseschanged && canvases[i] != attachedCanvases[i]) canvaseschanged = true; @@ -857,8 +857,8 @@ void Canvas::clear(Color c) if (current != this) strategy->bindFBO(previous); - if (fsaa_buffer != 0) - fsaa_dirty = true; + if (msaa_buffer != 0) + msaa_dirty = true; } bool Canvas::checkCreateStencil() @@ -870,7 +870,7 @@ bool Canvas::checkCreateStencil() if (current != this) strategy->bindFBO(fbo); - bool success = strategy->createStencil(width, height, fsaa_samples, depth_stencil); + bool success = strategy->createStencil(width, height, msaa_samples, depth_stencil); if (current && current != this) strategy->bindFBO(current->fbo); @@ -889,9 +889,9 @@ love::image::ImageData *Canvas::getImageData(love::image::Image *image) GLubyte *pixels = new GLubyte[size]; // Our texture is attached to 'resolve_fbo' when we use MSAA. - if (fsaa_samples > 1 && (GLEE_VERSION_3_0 || GLEE_ARB_framebuffer_object)) + if (msaa_samples > 1 && (GLEE_VERSION_3_0 || GLEE_ARB_framebuffer_object)) glBindFramebuffer(GL_READ_FRAMEBUFFER, resolve_fbo); - else if (fsaa_samples > 1 && GLEE_EXT_framebuffer_multisample) + else if (msaa_samples > 1 && GLEE_EXT_framebuffer_multisample) glBindFramebufferEXT(GL_READ_FRAMEBUFFER, resolve_fbo); else strategy->bindFBO(fbo); @@ -913,9 +913,9 @@ void Canvas::getPixel(unsigned char* pixel_rgba, int x, int y) resolveMSAA(); // Our texture is attached to 'resolve_fbo' when we use MSAA. - if (fsaa_samples > 1 && (GLEE_VERSION_3_0 || GLEE_ARB_framebuffer_object)) + if (msaa_samples > 1 && (GLEE_VERSION_3_0 || GLEE_ARB_framebuffer_object)) glBindFramebuffer(GL_READ_FRAMEBUFFER, resolve_fbo); - else if (fsaa_samples > 1 && GLEE_EXT_framebuffer_multisample) + else if (msaa_samples > 1 && GLEE_EXT_framebuffer_multisample) glBindFramebufferEXT(GL_READ_FRAMEBUFFER, resolve_fbo); else if (current != this) strategy->bindFBO(fbo); @@ -930,10 +930,10 @@ void Canvas::getPixel(unsigned char* pixel_rgba, int x, int y) bool Canvas::resolveMSAA() { - if (resolve_fbo == 0 || fsaa_buffer == 0) + if (resolve_fbo == 0 || msaa_buffer == 0) return false; - if (!fsaa_dirty) + if (!msaa_dirty) return true; GLuint previous = 0; @@ -961,7 +961,7 @@ bool Canvas::resolveMSAA() strategy->bindFBO(previous); if (current != this) - fsaa_dirty = false; + msaa_dirty = false; return true; } diff --git a/src/modules/graphics/opengl/Canvas.h b/src/modules/graphics/opengl/Canvas.h index 3e2a623d2..d12d5ed42 100644 --- a/src/modules/graphics/opengl/Canvas.h +++ b/src/modules/graphics/opengl/Canvas.h @@ -57,7 +57,7 @@ public: FORMAT_MAX_ENUM }; - Canvas(int width, int height, Format format = FORMAT_NORMAL, int fsaa = 0); + Canvas(int width, int height, Format format = FORMAT_NORMAL, int msaa = 0); virtual ~Canvas(); // Implements Volatile. @@ -108,9 +108,9 @@ public: return format; } - inline int getFSAA() const + inline int getMSAA() const { - return fsaa_samples; + return msaa_samples; } bool resolveMSAA(); @@ -133,7 +133,7 @@ public: private: - bool createFSAAFBO(GLenum internalformat); + bool createMSAAFBO(GLenum internalformat); static Format getSizedFormat(Format format); static void convertFormat(Format format, GLenum &internalformat, GLenum &externalformat, GLenum &type); @@ -142,7 +142,7 @@ private: GLuint resolve_fbo; GLuint texture; - GLuint fsaa_buffer; + GLuint msaa_buffer; GLuint depth_stencil; Format format; @@ -151,8 +151,8 @@ private: std::vector attachedCanvases; - int fsaa_samples; - bool fsaa_dirty; + int msaa_samples; + bool msaa_dirty; void setupGrab(); void drawv(const Matrix &t, const Vertex *v); diff --git a/src/modules/graphics/opengl/Graphics.cpp b/src/modules/graphics/opengl/Graphics.cpp index d36cae05b..b9af5723f 100644 --- a/src/modules/graphics/opengl/Graphics.cpp +++ b/src/modules/graphics/opengl/Graphics.cpp @@ -497,7 +497,7 @@ ParticleSystem *Graphics::newParticleSystem(Texture *texture, int size) return new ParticleSystem(texture, size); } -Canvas *Graphics::newCanvas(int width, int height, Canvas::Format format, int fsaa) +Canvas *Graphics::newCanvas(int width, int height, Canvas::Format format, int msaa) { if (!Canvas::isFormatSupported(format)) { @@ -514,7 +514,7 @@ Canvas *Graphics::newCanvas(int width, int height, Canvas::Format format, int fs while (GL_NO_ERROR != glGetError()) /* clear opengl error flag */; - Canvas *canvas = new Canvas(width, height, format, fsaa); + Canvas *canvas = new Canvas(width, height, format, msaa); GLenum err = canvas->getStatus(); // everything ok, return canvas (early out) @@ -1097,7 +1097,7 @@ double Graphics::getSystemLimit(SystemLimit limittype) const case Graphics::LIMIT_MULTI_CANVAS: limit = (double) gl.getMaxRenderTargets(); break; - case Graphics::LIMIT_CANVAS_FSAA: + case Graphics::LIMIT_CANVAS_MSAA: if (GLEE_VERSION_3_0 || GLEE_ARB_framebuffer_object || GLEE_EXT_framebuffer_multisample) { diff --git a/src/modules/graphics/opengl/Graphics.h b/src/modules/graphics/opengl/Graphics.h index 52fc6e3bd..316ad292b 100644 --- a/src/modules/graphics/opengl/Graphics.h +++ b/src/modules/graphics/opengl/Graphics.h @@ -206,7 +206,7 @@ public: ParticleSystem *newParticleSystem(Texture *texture, int size); - Canvas *newCanvas(int width, int height, Canvas::Format format = Canvas::FORMAT_NORMAL, int fsaa = 0); + Canvas *newCanvas(int width, int height, Canvas::Format format = Canvas::FORMAT_NORMAL, int msaa = 0); Shader *newShader(const Shader::ShaderSources &sources); diff --git a/src/modules/graphics/opengl/ParticleSystem.cpp b/src/modules/graphics/opengl/ParticleSystem.cpp index 49f4cf087..8c1dd3484 100644 --- a/src/modules/graphics/opengl/ParticleSystem.cpp +++ b/src/modules/graphics/opengl/ParticleSystem.cpp @@ -146,12 +146,16 @@ ParticleSystem::ParticleSystem(const ParticleSystem &p) , offsetX(p.offsetX) , offsetY(p.offsetY) , colors(p.colors) + , quads(p.quads) , relativeRotation(p.relativeRotation) { setBufferSize(maxParticles); if (texture != nullptr) texture->retain(); + + for (Quad *quad : quads) + quad->retain(); } ParticleSystem::~ParticleSystem() @@ -159,6 +163,9 @@ ParticleSystem::~ParticleSystem() if (texture != nullptr) texture->release(); + for (Quad *quad : quads) + quad->release(); + deleteBuffers(); } @@ -305,6 +312,8 @@ void ParticleSystem::initParticle(Particle *p, float t) p->angle += atan2f(p->velocity.y, p->velocity.x); p->color = colors[0]; + + p->quadIndex = 0; } void ParticleSystem::insertTop(Particle *p) @@ -721,6 +730,30 @@ std::vector ParticleSystem::getColor() const return ncolors; } +void ParticleSystem::setQuads(const std::vector &newQuads) +{ + for (Quad *quad : newQuads) + quad->retain(); + + for (Quad *quad : quads) + quad->release(); + + quads = newQuads; +} + +void ParticleSystem::setQuads() +{ + for (Quad *quad : quads) + quad->release(); + + quads.clear(); +} + +const std::vector &ParticleSystem::getQuads() const +{ + return quads; +} + void ParticleSystem::setRelativeRotation(bool enable) { relativeRotation = enable; @@ -820,9 +853,14 @@ void ParticleSystem::draw(float x, float y, float angle, float sx, float sy, flo Vertex *pVerts = particleVerts; Particle *p = pHead; + bool useQuads = !quads.empty(); + // set the vertex data for each particle (transformation, texcoords, color) while (p) { + if (useQuads) + textureVerts = quads[p->quadIndex]->getVertices(); + // particle vertices are image vertices transformed by particle information t.setTransformation(p->position[0], p->position[1], p->angle, p->size, p->size, offsetX, offsetY, 0.0f, 0.0f); t.transform(pVerts, textureVerts, 4); @@ -948,6 +986,15 @@ void ParticleSystem::update(float dt) s -= (float)i; // 0 <= s <= 1 p->color = colors[i] * (1.0f - s) + colors[k] * s; + // Update the quad index. + k = quads.size(); + if (k > 0) + { + s = t * (float) k; // [0:numquads-1] (clamped below) + i = (s > 0.0f) ? (size_t) s : 0; + p->quadIndex = (i < k) ? i : k - 1; + } + // Next particle. p = p->next; } diff --git a/src/modules/graphics/opengl/ParticleSystem.h b/src/modules/graphics/opengl/ParticleSystem.h index 96e6f8d5a..6f9e8750f 100644 --- a/src/modules/graphics/opengl/ParticleSystem.h +++ b/src/modules/graphics/opengl/ParticleSystem.h @@ -27,6 +27,7 @@ #include "common/Vector.h" #include "graphics/Drawable.h" #include "graphics/Color.h" +#include "graphics/Quad.h" #include "Texture.h" // STL @@ -421,6 +422,17 @@ public: **/ std::vector getColor() const; + /** + * Sets a list of Quads to use for particles over their lifetime. + **/ + void setQuads(const std::vector &newQuads); + void setQuads(); + + /** + * Gets the Quads used when drawing the particles. + **/ + const std::vector &getQuads() const; + /** * sets whether particle angles & rotations are relative to their velocities. **/ @@ -531,6 +543,8 @@ protected: float spinEnd; Colorf color; + + int quadIndex; }; // Pointer to the beginning of the allocated memory. @@ -625,6 +639,9 @@ protected: // Color. std::vector colors; + // Quads. + std::vector quads; + bool relativeRotation; void createBuffers(size_t size); diff --git a/src/modules/graphics/opengl/wrap_Canvas.cpp b/src/modules/graphics/opengl/wrap_Canvas.cpp index 885374202..91fba30b4 100644 --- a/src/modules/graphics/opengl/wrap_Canvas.cpp +++ b/src/modules/graphics/opengl/wrap_Canvas.cpp @@ -122,10 +122,10 @@ int w_Canvas_getFormat(lua_State *L) return 1; } -int w_Canvas_getFSAA(lua_State *L) +int w_Canvas_getMSAA(lua_State *L) { Canvas *canvas = luax_checkcanvas(L, 1); - lua_pushinteger(L, canvas->getFSAA()); + lua_pushinteger(L, canvas->getMSAA()); return 1; } @@ -145,7 +145,7 @@ static const luaL_Reg functions[] = { "getPixel", w_Canvas_getPixel }, { "clear", w_Canvas_clear }, { "getFormat", w_Canvas_getFormat }, - { "getFSAA", w_Canvas_getFSAA }, + { "getMSAA", w_Canvas_getMSAA }, { 0, 0 } }; diff --git a/src/modules/graphics/opengl/wrap_Canvas.h b/src/modules/graphics/opengl/wrap_Canvas.h index 4e48ffe03..2b775f93b 100644 --- a/src/modules/graphics/opengl/wrap_Canvas.h +++ b/src/modules/graphics/opengl/wrap_Canvas.h @@ -40,7 +40,7 @@ int w_Canvas_getImageData(lua_State *L); int w_Canvas_getPixel(lua_State * L); int w_Canvas_clear(lua_State *L); int w_Canvas_getFormat(lua_State *L); -int w_Canvas_getFSAA(lua_State *L); +int w_Canvas_getMSAA(lua_State *L); extern "C" int luaopen_canvas(lua_State *L); } // opengl diff --git a/src/modules/graphics/opengl/wrap_Graphics.cpp b/src/modules/graphics/opengl/wrap_Graphics.cpp index 6a04042d0..0f668bf4d 100644 --- a/src/modules/graphics/opengl/wrap_Graphics.cpp +++ b/src/modules/graphics/opengl/wrap_Graphics.cpp @@ -351,7 +351,7 @@ int w_newCanvas(lua_State *L) int width = luaL_optint(L, 1, instance->getWidth()); int height = luaL_optint(L, 2, instance->getHeight()); const char *str = luaL_optstring(L, 3, "normal"); - int fsaa = luaL_optint(L, 4, 0); + int msaa = luaL_optint(L, 4, 0); Canvas::Format format; if (!Canvas::getConstant(str, format)) @@ -359,7 +359,7 @@ int w_newCanvas(lua_State *L) Canvas *canvas = nullptr; luax_catchexcept(L, - [&](){ canvas = instance->newCanvas(width, height, format, fsaa); } + [&](){ canvas = instance->newCanvas(width, height, format, msaa); } ); if (canvas == nullptr) diff --git a/src/modules/graphics/opengl/wrap_ParticleSystem.cpp b/src/modules/graphics/opengl/wrap_ParticleSystem.cpp index 5f196d475..45bcaff04 100644 --- a/src/modules/graphics/opengl/wrap_ParticleSystem.cpp +++ b/src/modules/graphics/opengl/wrap_ParticleSystem.cpp @@ -569,6 +569,53 @@ int w_ParticleSystem_getColors(lua_State *L) return colors.size(); } +int w_ParticleSystem_setQuads(lua_State *L) +{ + ParticleSystem *t = luax_checkparticlesystem(L, 1); + std::vector quads; + + if (lua_istable(L, 2)) + { + for (size_t i = 1; i <= lua_objlen(L, 2); i++) + { + lua_rawgeti(L, 2, i); + + Quad *q = luax_checktype(L, -1, "Quad", GRAPHICS_QUAD_T); + quads.push_back(q); + + lua_pop(L, 1); + } + } + else + { + for (int i = 2; i <= lua_gettop(L); i++) + { + Quad *q = luax_checktype(L, i, "Quad", GRAPHICS_QUAD_T); + quads.push_back(q); + } + } + + t->setQuads(quads); + return 0; +} + +int w_ParticleSystem_getQuads(lua_State *L) +{ + ParticleSystem *t = luax_checkparticlesystem(L, 1); + const std::vector quads = t->getQuads(); + + lua_createtable(L, (int) quads.size(), 0); + + for (size_t i = 0; i < quads.size(); i++) + { + quads[i]->retain(); + luax_pushtype(L, "Quad", GRAPHICS_QUAD_T, quads[i]); + lua_rawseti(L, -2, i + 1); + } + + return 1; +} + int w_ParticleSystem_setRelativeRotation(lua_State *L) { ParticleSystem *t = luax_checkparticlesystem(L, 1); @@ -699,6 +746,8 @@ static const luaL_Reg functions[] = { "getSpinVariation", w_ParticleSystem_getSpinVariation }, { "setColors", w_ParticleSystem_setColors }, { "getColors", w_ParticleSystem_getColors }, + { "setQuads", w_ParticleSystem_setQuads }, + { "getQuads", w_ParticleSystem_getQuads }, { "setOffset", w_ParticleSystem_setOffset }, { "getOffset", w_ParticleSystem_getOffset }, { "setRelativeRotation", w_ParticleSystem_setRelativeRotation }, diff --git a/src/modules/graphics/opengl/wrap_ParticleSystem.h b/src/modules/graphics/opengl/wrap_ParticleSystem.h index b3c96a54f..f1f788388 100644 --- a/src/modules/graphics/opengl/wrap_ParticleSystem.h +++ b/src/modules/graphics/opengl/wrap_ParticleSystem.h @@ -75,6 +75,8 @@ int w_ParticleSystem_setSpinVariation(lua_State *L); int w_ParticleSystem_getSpinVariation(lua_State *L); int w_ParticleSystem_setColors(lua_State *L); int w_ParticleSystem_getColors(lua_State *L); +int w_ParticleSystem_setQuads(lua_State *L); +int w_ParticleSystem_getQuads(lua_State *L); int w_ParticleSystem_setOffset(lua_State *L); int w_ParticleSystem_getOffset(lua_State *L); int w_ParticleSystem_setRelativeRotation(lua_State *L); diff --git a/src/modules/keyboard/wrap_Keyboard.cpp b/src/modules/keyboard/wrap_Keyboard.cpp index de48c52bd..a06a899d4 100644 --- a/src/modules/keyboard/wrap_Keyboard.cpp +++ b/src/modules/keyboard/wrap_Keyboard.cpp @@ -68,34 +68,8 @@ int w_setTextInput(lua_State *L) return 0; } -template -static int throwExcept(lua_State *L, const T& func) -{ - bool should_error = false; - - try - { - func(); - } - catch (love::Exception &e) - { - should_error = true; - lua_pushstring(L, e.what()); - } - - if (should_error) - return luaL_error(L, lua_tostring(L, -1)); - - return 0; -} - int w_hasTextInput(lua_State *L) { - bool asdf = true; - throwExcept(L, [&](){ instance->setTextInput(asdf); }); - -// throwExcept(L, L); - luax_pushboolean(L, instance->hasTextInput()); return 1; } diff --git a/src/modules/physics/box2d/Joint.cpp b/src/modules/physics/box2d/Joint.cpp index 5e3ec277f..8ca574530 100644 --- a/src/modules/physics/box2d/Joint.cpp +++ b/src/modules/physics/box2d/Joint.cpp @@ -41,20 +41,29 @@ namespace box2d Joint::Joint(Body *body1) : world(body1->world) + , udata(nullptr) , body1(body1) - , body2(0) + , body2(nullptr) { + udata = new jointudata(); + udata->ref = nullptr; } Joint::Joint(Body *body1, Body *body2) : world(body1->world) + , udata(nullptr) , body1(body1) , body2(body2) { + udata = new jointudata(); + udata->ref = nullptr; } Joint::~Joint() { + if (udata != nullptr) + delete udata->ref; + delete udata; } Joint::Type Joint::getType() const @@ -116,6 +125,7 @@ float Joint::getReactionTorque(float dt) b2Joint *Joint::createJoint(b2JointDef *def) { + def->userData = udata; joint = world->world->CreateJoint(def); Memoizer::add(joint, this); // Box2D joint has a reference to this love Joint. @@ -151,6 +161,34 @@ bool Joint::getCollideConnected() const return joint->GetCollideConnected(); } +int Joint::setUserData(lua_State *L) +{ + love::luax_assert_argc(L, 1, 1); + + if (udata->ref != nullptr) + { + // We set the Reference's lua_State to this one before deleting it, so + // it unrefs using the current lua_State's stack. This is necessary + // if setUserData is called in a coroutine. + udata->ref->setL(L); + delete udata->ref; + } + + udata->ref = new Reference(L); + + return 0; +} + +int Joint::getUserData(lua_State *L) +{ + if (udata != nullptr && udata->ref != nullptr) + udata->ref->push(L); + else + lua_pushnil(L); + + return 1; +} + } // box2d } // physics } // love diff --git a/src/modules/physics/box2d/Joint.h b/src/modules/physics/box2d/Joint.h index 22622df1d..ba266808b 100644 --- a/src/modules/physics/box2d/Joint.h +++ b/src/modules/physics/box2d/Joint.h @@ -39,6 +39,16 @@ namespace box2d class Body; class World; +/** + * This struct is stored in a void pointer in the Box2D Joint class. For now, all + * we need is a Lua reference to arbitrary data, but we might need more later. + **/ +struct jointudata +{ + // Reference to arbitrary data. + Reference *ref; +}; + /** * A Joint acts as positioning constraints on Bodies. * A Joint can be used to prevent Bodies from going to @@ -95,6 +105,17 @@ public: bool getCollideConnected() const; + /** + * This function stores an in-C reference to arbitrary Lua data in the Box2D + * Joint object. + **/ + int setUserData(lua_State *L); + + /** + * Gets the data set with setUserData. If no data is set, nil is returned. + **/ + int getUserData(lua_State *L); + /** * Joints require pointers to a Box2D joint objects at * different polymorphic levels, which is why these function @@ -117,6 +138,8 @@ protected: World *world; + jointudata *udata; + private: // A Joint must be destroyed *before* the bodies it acts upon, diff --git a/src/modules/physics/box2d/wrap_Body.cpp b/src/modules/physics/box2d/wrap_Body.cpp index f3551030c..040438dc7 100644 --- a/src/modules/physics/box2d/wrap_Body.cpp +++ b/src/modules/physics/box2d/wrap_Body.cpp @@ -522,6 +522,15 @@ int w_Body_isFixedRotation(lua_State *L) return 1; } +int w_Body_getWorld(lua_State *L) +{ + Body *t = luax_checkbody(L, 1); + World *world = t->getWorld(); + world->retain(); + luax_pushtype(L, "World", PHYSICS_WORLD_T, world); + return 1; +} + int w_Body_getFixtureList(lua_State *L) { Body *t = luax_checkbody(L, 1); @@ -604,6 +613,7 @@ static const luaL_Reg functions[] = { "setAwake", w_Body_setAwake }, { "setFixedRotation", w_Body_setFixedRotation }, { "isFixedRotation", w_Body_isFixedRotation }, + { "getWorld", w_Body_getWorld }, { "getFixtureList", w_Body_getFixtureList }, { "destroy", w_Body_destroy }, { "setUserData", w_Body_setUserData }, diff --git a/src/modules/physics/box2d/wrap_Body.h b/src/modules/physics/box2d/wrap_Body.h index 2a41556f0..c702b5f56 100644 --- a/src/modules/physics/box2d/wrap_Body.h +++ b/src/modules/physics/box2d/wrap_Body.h @@ -83,6 +83,7 @@ int w_Body_setActive(lua_State *L); int w_Body_setAwake(lua_State *L); int w_Body_setFixedRotation(lua_State *L); int w_Body_isFixedRotation(lua_State *L); +int w_Body_getWorld(lua_State *L); int w_Body_getFixtureList(lua_State *L); int w_Body_destroy(lua_State *L); int w_Body_setUserData(lua_State *L); diff --git a/src/modules/physics/box2d/wrap_DistanceJoint.cpp b/src/modules/physics/box2d/wrap_DistanceJoint.cpp index 0824e3566..219196b03 100644 --- a/src/modules/physics/box2d/wrap_DistanceJoint.cpp +++ b/src/modules/physics/box2d/wrap_DistanceJoint.cpp @@ -94,6 +94,8 @@ static const luaL_Reg functions[] = { "getReactionForce", w_Joint_getReactionForce }, { "getReactionTorque", w_Joint_getReactionTorque }, { "getCollideConnected", w_Joint_getCollideConnected }, + { "setUserData", w_Joint_setUserData }, + { "getUserData", w_Joint_getUserData }, { "destroy", w_Joint_destroy }, { 0, 0 } }; diff --git a/src/modules/physics/box2d/wrap_FrictionJoint.cpp b/src/modules/physics/box2d/wrap_FrictionJoint.cpp index 7124a8530..cc202e3b8 100644 --- a/src/modules/physics/box2d/wrap_FrictionJoint.cpp +++ b/src/modules/physics/box2d/wrap_FrictionJoint.cpp @@ -78,6 +78,8 @@ static const luaL_Reg functions[] = { "getReactionForce", w_Joint_getReactionForce }, { "getReactionTorque", w_Joint_getReactionTorque }, { "getCollideConnected", w_Joint_getCollideConnected }, + { "setUserData", w_Joint_setUserData }, + { "getUserData", w_Joint_getUserData }, { "destroy", w_Joint_destroy }, { 0, 0 } }; diff --git a/src/modules/physics/box2d/wrap_GearJoint.cpp b/src/modules/physics/box2d/wrap_GearJoint.cpp index c6f84114f..114045e13 100644 --- a/src/modules/physics/box2d/wrap_GearJoint.cpp +++ b/src/modules/physics/box2d/wrap_GearJoint.cpp @@ -61,6 +61,8 @@ static const luaL_Reg functions[] = { "getReactionForce", w_Joint_getReactionForce }, { "getReactionTorque", w_Joint_getReactionTorque }, { "getCollideConnected", w_Joint_getCollideConnected }, + { "setUserData", w_Joint_setUserData }, + { "getUserData", w_Joint_getUserData }, { "destroy", w_Joint_destroy }, { 0, 0 } }; diff --git a/src/modules/physics/box2d/wrap_Joint.cpp b/src/modules/physics/box2d/wrap_Joint.cpp index 053f8b45d..4e2727e7c 100644 --- a/src/modules/physics/box2d/wrap_Joint.cpp +++ b/src/modules/physics/box2d/wrap_Joint.cpp @@ -75,6 +75,20 @@ int w_Joint_getCollideConnected(lua_State *L) return 1; } +int w_Joint_setUserData(lua_State *L) +{ + Joint *t = luax_checkjoint(L, 1); + lua_remove(L, 1); + return t->setUserData(L); +} + +int w_Joint_getUserData(lua_State *L) +{ + Joint *t = luax_checkjoint(L, 1); + lua_remove(L, 1); + return t->getUserData(L); +} + int w_Joint_destroy(lua_State *L) { Joint *t = luax_checkjoint(L, 1); @@ -89,6 +103,8 @@ static const luaL_Reg functions[] = { "getReactionForce", w_Joint_getReactionForce }, { "getReactionTorque", w_Joint_getReactionTorque }, { "getCollideConnected", w_Joint_getCollideConnected }, + { "setUserData", w_Joint_setUserData }, + { "getUserData", w_Joint_getUserData }, { "destroy", w_Joint_destroy }, { 0, 0 } }; diff --git a/src/modules/physics/box2d/wrap_Joint.h b/src/modules/physics/box2d/wrap_Joint.h index 3a2495d83..63d4537ec 100644 --- a/src/modules/physics/box2d/wrap_Joint.h +++ b/src/modules/physics/box2d/wrap_Joint.h @@ -38,6 +38,8 @@ int w_Joint_getAnchors(lua_State *L); int w_Joint_getReactionForce(lua_State *L); int w_Joint_getReactionTorque(lua_State *L); int w_Joint_getCollideConnected(lua_State *L); +int w_Joint_setUserData(lua_State *L); +int w_Joint_getUserData(lua_State *L); int w_Joint_destroy(lua_State *L); extern "C" int luaopen_joint(lua_State *L); diff --git a/src/modules/physics/box2d/wrap_MotorJoint.cpp b/src/modules/physics/box2d/wrap_MotorJoint.cpp index 4403ddc88..17d1501a0 100644 --- a/src/modules/physics/box2d/wrap_MotorJoint.cpp +++ b/src/modules/physics/box2d/wrap_MotorJoint.cpp @@ -128,6 +128,8 @@ static const luaL_Reg functions[] = { "getReactionForce", w_Joint_getReactionForce }, { "getReactionTorque", w_Joint_getReactionTorque }, { "getCollideConnected", w_Joint_getCollideConnected }, + { "setUserData", w_Joint_setUserData }, + { "getUserData", w_Joint_getUserData }, { "destroy", w_Joint_destroy }, { 0, 0 } }; diff --git a/src/modules/physics/box2d/wrap_MouseJoint.cpp b/src/modules/physics/box2d/wrap_MouseJoint.cpp index 8e02addf7..38cf46b26 100644 --- a/src/modules/physics/box2d/wrap_MouseJoint.cpp +++ b/src/modules/physics/box2d/wrap_MouseJoint.cpp @@ -112,6 +112,8 @@ static const luaL_Reg functions[] = { "getReactionForce", w_Joint_getReactionForce }, { "getReactionTorque", w_Joint_getReactionTorque }, { "getCollideConnected", w_Joint_getCollideConnected }, + { "setUserData", w_Joint_setUserData }, + { "getUserData", w_Joint_getUserData }, { "destroy", w_Joint_destroy }, { 0, 0 } }; diff --git a/src/modules/physics/box2d/wrap_PrismaticJoint.cpp b/src/modules/physics/box2d/wrap_PrismaticJoint.cpp index ed3b6838f..e820d38d8 100644 --- a/src/modules/physics/box2d/wrap_PrismaticJoint.cpp +++ b/src/modules/physics/box2d/wrap_PrismaticJoint.cpp @@ -189,6 +189,8 @@ static const luaL_Reg functions[] = { "getReactionForce", w_Joint_getReactionForce }, { "getReactionTorque", w_Joint_getReactionTorque }, { "getCollideConnected", w_Joint_getCollideConnected }, + { "setUserData", w_Joint_setUserData }, + { "getUserData", w_Joint_getUserData }, { "destroy", w_Joint_destroy }, { 0, 0 } }; diff --git a/src/modules/physics/box2d/wrap_PulleyJoint.cpp b/src/modules/physics/box2d/wrap_PulleyJoint.cpp index 1e9e01aa2..25c41758c 100644 --- a/src/modules/physics/box2d/wrap_PulleyJoint.cpp +++ b/src/modules/physics/box2d/wrap_PulleyJoint.cpp @@ -75,6 +75,8 @@ static const luaL_Reg functions[] = { "getReactionForce", w_Joint_getReactionForce }, { "getReactionTorque", w_Joint_getReactionTorque }, { "getCollideConnected", w_Joint_getCollideConnected }, + { "setUserData", w_Joint_setUserData }, + { "getUserData", w_Joint_getUserData }, { "destroy", w_Joint_destroy }, { 0, 0 } }; diff --git a/src/modules/physics/box2d/wrap_RevoluteJoint.cpp b/src/modules/physics/box2d/wrap_RevoluteJoint.cpp index 82203f0ad..13d3468f9 100644 --- a/src/modules/physics/box2d/wrap_RevoluteJoint.cpp +++ b/src/modules/physics/box2d/wrap_RevoluteJoint.cpp @@ -189,6 +189,8 @@ static const luaL_Reg functions[] = { "getReactionForce", w_Joint_getReactionForce }, { "getReactionTorque", w_Joint_getReactionTorque }, { "getCollideConnected", w_Joint_getCollideConnected }, + { "setUserData", w_Joint_setUserData }, + { "getUserData", w_Joint_getUserData }, { "destroy", w_Joint_destroy }, { 0, 0 } }; diff --git a/src/modules/physics/box2d/wrap_RopeJoint.cpp b/src/modules/physics/box2d/wrap_RopeJoint.cpp index 907b519c5..45fecce2b 100644 --- a/src/modules/physics/box2d/wrap_RopeJoint.cpp +++ b/src/modules/physics/box2d/wrap_RopeJoint.cpp @@ -51,6 +51,8 @@ static const luaL_Reg functions[] = { "getReactionForce", w_Joint_getReactionForce }, { "getReactionTorque", w_Joint_getReactionTorque }, { "getCollideConnected", w_Joint_getCollideConnected }, + { "setUserData", w_Joint_setUserData }, + { "getUserData", w_Joint_getUserData }, { "destroy", w_Joint_destroy }, { 0, 0 } }; diff --git a/src/modules/physics/box2d/wrap_WeldJoint.cpp b/src/modules/physics/box2d/wrap_WeldJoint.cpp index 84476ee05..0937c044b 100644 --- a/src/modules/physics/box2d/wrap_WeldJoint.cpp +++ b/src/modules/physics/box2d/wrap_WeldJoint.cpp @@ -77,6 +77,8 @@ static const luaL_Reg functions[] = { "getReactionForce", w_Joint_getReactionForce }, { "getReactionTorque", w_Joint_getReactionTorque }, { "getCollideConnected", w_Joint_getCollideConnected }, + { "setUserData", w_Joint_setUserData }, + { "getUserData", w_Joint_getUserData }, { "destroy", w_Joint_destroy }, { 0, 0 } }; diff --git a/src/modules/physics/box2d/wrap_WheelJoint.cpp b/src/modules/physics/box2d/wrap_WheelJoint.cpp index 861b61904..31b1c5b84 100644 --- a/src/modules/physics/box2d/wrap_WheelJoint.cpp +++ b/src/modules/physics/box2d/wrap_WheelJoint.cpp @@ -153,6 +153,8 @@ static const luaL_Reg functions[] = { "getReactionForce", w_Joint_getReactionForce }, { "getReactionTorque", w_Joint_getReactionTorque }, { "getCollideConnected", w_Joint_getCollideConnected }, + { "setUserData", w_Joint_setUserData }, + { "getUserData", w_Joint_getUserData }, { "destroy", w_Joint_destroy }, { 0, 0 } }; diff --git a/src/modules/window/Window.cpp b/src/modules/window/Window.cpp index ecd0fb73b..84fce5b22 100644 --- a/src/modules/window/Window.cpp +++ b/src/modules/window/Window.cpp @@ -42,7 +42,7 @@ WindowSettings::WindowSettings() : fullscreen(false) , fstype(Window::FULLSCREEN_TYPE_NORMAL) , vsync(true) - , fsaa(0) + , msaa(0) , resizable(false) , minwidth(1) , minheight(1) @@ -89,7 +89,7 @@ StringMap::Entry Window::settingEntri {"fullscreen", SETTING_FULLSCREEN}, {"fullscreentype", SETTING_FULLSCREEN_TYPE}, {"vsync", SETTING_VSYNC}, - {"fsaa", SETTING_FSAA}, + {"msaa", SETTING_MSAA}, {"resizable", SETTING_RESIZABLE}, {"minwidth", SETTING_MIN_WIDTH}, {"minheight", SETTING_MIN_HEIGHT}, diff --git a/src/modules/window/Window.h b/src/modules/window/Window.h index afe8bd4e5..d9795ae04 100644 --- a/src/modules/window/Window.h +++ b/src/modules/window/Window.h @@ -57,7 +57,7 @@ public: SETTING_FULLSCREEN, SETTING_FULLSCREEN_TYPE, SETTING_VSYNC, - SETTING_FSAA, + SETTING_MSAA, SETTING_RESIZABLE, SETTING_MIN_WIDTH, SETTING_MIN_HEIGHT, @@ -94,6 +94,8 @@ public: virtual int getDisplayCount() const = 0; + virtual const char *getDisplayName(int displayindex) const = 0; + virtual std::vector getFullscreenSizes(int displayindex) const = 0; virtual void getDesktopDimensions(int displayindex, int &width, int &height) const = 0; @@ -163,7 +165,7 @@ struct WindowSettings bool fullscreen; // = false Window::FullscreenType fstype; // = FULLSCREEN_TYPE_NORMAL bool vsync; // = true - int fsaa; // = 0 + int msaa; // = 0 bool resizable; // = false int minwidth; // = 1 int minheight; // = 1 diff --git a/src/modules/window/sdl/Window.cpp b/src/modules/window/sdl/Window.cpp index cd44b54ec..ea005665b 100644 --- a/src/modules/window/sdl/Window.cpp +++ b/src/modules/window/sdl/Window.cpp @@ -139,7 +139,7 @@ bool Window::setWindow(int width, int height, WindowSettings *settings) wflags &= testflags; if (sdlflags != wflags || width != curMode.width || height != curMode.height - || f.display != curdisplay || f.fsaa != curMode.settings.fsaa) + || f.display != curdisplay || f.msaa != curMode.settings.msaa) { SDL_DestroyWindow(window); window = 0; @@ -158,21 +158,21 @@ bool Window::setWindow(int width, int height, WindowSettings *settings) created = false; // In Windows and Linux, some GL attributes are set on window creation. - setWindowGLAttributes(f.fsaa, f.sRGB); + setWindowGLAttributes(f.msaa, f.sRGB); const char *title = windowTitle.c_str(); int pos = f.centered ? centeredpos : uncenteredpos; window = SDL_CreateWindow(title, pos, pos, width, height, sdlflags); - if (!window && f.fsaa > 0) + if (!window && f.msaa > 0) { - // FSAA might have caused the failure, disable it and try again. + // MSAA might have caused the failure, disable it and try again. SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0); window = SDL_CreateWindow(title, pos, pos, width, height, sdlflags); - f.fsaa = 0; + f.msaa = 0; } // Make sure the window keeps any previously set icon. @@ -194,7 +194,7 @@ bool Window::setWindow(int width, int height, WindowSettings *settings) SDL_RaiseWindow(window); - if (!setContext(f.fsaa, f.vsync, f.sRGB)) + if (!setContext(f.msaa, f.vsync, f.sRGB)) return false; created = true; @@ -231,9 +231,9 @@ bool Window::onWindowResize(int width, int height) return true; } -bool Window::setContext(int fsaa, bool vsync, bool sRGB) +bool Window::setContext(int msaa, bool vsync, bool sRGB) { - // We would normally only need to recreate the context if FSAA changes or + // We would normally only need to recreate the context if MSAA changes or // SDL_GL_MakeCurrent is unsuccessful, but in Windows MakeCurrent can // sometimes claim success but the context will actually be trashed. if (context) @@ -243,13 +243,13 @@ bool Window::setContext(int fsaa, bool vsync, bool sRGB) } // Make sure the proper attributes are set. - setWindowGLAttributes(fsaa, sRGB); + setWindowGLAttributes(msaa, sRGB); context = SDL_GL_CreateContext(window); - if (!context && fsaa > 0) + if (!context && msaa > 0) { - // FSAA might have caused the failure, disable it and try again. + // MSAA might have caused the failure, disable it and try again. SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0); context = SDL_GL_CreateContext(window); @@ -276,26 +276,26 @@ bool Window::setContext(int fsaa, bool vsync, bool sRGB) // Set vertical synchronization. SDL_GL_SetSwapInterval(vsync ? 1 : 0); - // Verify FSAA setting. + // Verify MSAA setting. int buffers; int samples; SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &buffers); SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &samples); // Don't fail because of this, but issue a warning. - if ((!buffers && fsaa) || (samples != fsaa)) + if ((!buffers && msaa) || (samples != msaa)) { - std::cerr << "Warning, FSAA setting failed! (Result: buffers: " << buffers << ", samples: " << samples << ")" << std::endl; - fsaa = (buffers > 0) ? samples : 0; + std::cerr << "Warning, MSAA setting failed! (Result: buffers: " << buffers << ", samples: " << samples << ")" << std::endl; + msaa = (buffers > 0) ? samples : 0; } - curMode.settings.fsaa = fsaa; + curMode.settings.msaa = msaa; curMode.settings.vsync = SDL_GL_GetSwapInterval() != 0; return true; } -void Window::setWindowGLAttributes(int fsaa, bool /* sRGB */) const +void Window::setWindowGLAttributes(int msaa, bool /* sRGB */) const { // Set GL window attributes. SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); @@ -306,9 +306,9 @@ void Window::setWindowGLAttributes(int fsaa, bool /* sRGB */) const SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 1); SDL_GL_SetAttribute(SDL_GL_RETAINED_BACKING, 0); - // FSAA. - SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, (fsaa > 0) ? 1 : 0); - SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, (fsaa > 0) ? fsaa : 0); + // MSAA. + SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, (msaa > 0) ? 1 : 0); + SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, (msaa > 0) ? msaa : 0); /* FIXME: Enable this code but make sure to try to re-create the window and * context with this disabled, if creation fails with it enabled. @@ -461,6 +461,16 @@ int Window::getDisplayCount() const return SDL_GetNumVideoDisplays(); } +const char *Window::getDisplayName(int displayindex) const +{ + const char *name = SDL_GetDisplayName(displayindex); + + if (name == nullptr) + throw love::Exception("Invalid display index: %d", displayindex + 1); + + return name; +} + typedef Window::WindowSize WindowSize; std::vector Window::getFullscreenSizes(int displayindex) const diff --git a/src/modules/window/sdl/Window.h b/src/modules/window/sdl/Window.h index 74ce36551..a5c23ee99 100644 --- a/src/modules/window/sdl/Window.h +++ b/src/modules/window/sdl/Window.h @@ -51,6 +51,8 @@ public: int getDisplayCount() const; + const char *getDisplayName(int displayindex) const; + std::vector getFullscreenSizes(int displayindex) const; void getDesktopDimensions(int displayindex, int &width, int &height) const; @@ -89,8 +91,8 @@ public: private: - bool setContext(int fsaa, bool vsync, bool sRGB); - void setWindowGLAttributes(int fsaa, bool sRGB) const; + bool setContext(int msaa, bool vsync, bool sRGB); + void setWindowGLAttributes(int msaa, bool sRGB) const; // Update the saved window settings based on the window's actual state. void updateSettings(const WindowSettings &newsettings); diff --git a/src/modules/window/wrap_Window.cpp b/src/modules/window/wrap_Window.cpp index f7c72d68f..48cec8b75 100644 --- a/src/modules/window/wrap_Window.cpp +++ b/src/modules/window/wrap_Window.cpp @@ -34,6 +34,17 @@ int w_getDisplayCount(lua_State *L) return 1; } +int w_getDisplayName(lua_State *L) +{ + int index = luaL_checkint(L, 1) - 1; + + const char *name = nullptr; + luax_catchexcept(L, [&](){ name = instance->getDisplayName(index); }); + + lua_pushstring(L, name); + return 1; +} + static const char *settingName(Window::Setting setting) { const char *name = nullptr; @@ -88,7 +99,7 @@ int w_setMode(lua_State *L) settings.fullscreen = luax_boolflag(L, 3, settingName(Window::SETTING_FULLSCREEN), false); settings.vsync = luax_boolflag(L, 3, settingName(Window::SETTING_VSYNC), true); - settings.fsaa = luax_intflag(L, 3, settingName(Window::SETTING_FSAA), 0); + settings.msaa = luax_intflag(L, 3, settingName(Window::SETTING_MSAA), 0); settings.resizable = luax_boolflag(L, 3, settingName(Window::SETTING_RESIZABLE), false); settings.minwidth = luax_intflag(L, 3, settingName(Window::SETTING_MIN_WIDTH), 1); settings.minheight = luax_intflag(L, 3, settingName(Window::SETTING_MIN_HEIGHT), 1); @@ -130,8 +141,8 @@ int w_getMode(lua_State *L) luax_pushboolean(L, settings.vsync); lua_setfield(L, -2, settingName(Window::SETTING_VSYNC)); - lua_pushinteger(L, settings.fsaa); - lua_setfield(L, -2, settingName(Window::SETTING_FSAA)); + lua_pushinteger(L, settings.msaa); + lua_setfield(L, -2, settingName(Window::SETTING_MSAA)); luax_pushboolean(L, settings.resizable); lua_setfield(L, -2, settingName(Window::SETTING_RESIZABLE)); @@ -300,6 +311,7 @@ int w_getPixelScale(lua_State *L) static const luaL_Reg functions[] = { { "getDisplayCount", w_getDisplayCount }, + { "getDisplayName", w_getDisplayName }, { "setMode", w_setMode }, { "getMode", w_getMode }, { "getFullscreenModes", w_getFullscreenModes }, diff --git a/src/modules/window/wrap_Window.h b/src/modules/window/wrap_Window.h index f096a3789..b7fd92a04 100644 --- a/src/modules/window/wrap_Window.h +++ b/src/modules/window/wrap_Window.h @@ -30,6 +30,7 @@ namespace window { int w_getDisplayCount(lua_State *L); +int w_getDisplayName(lua_State *L); int w_setMode(lua_State *L); int w_getMode(lua_State *L); int w_getFullscreenModes(lua_State *L); diff --git a/src/scripts/boot.lua b/src/scripts/boot.lua index aa39f9607..ae02575d2 100644 --- a/src/scripts/boot.lua +++ b/src/scripts/boot.lua @@ -307,7 +307,7 @@ function love.init() fullscreentype = "normal", display = 1, vsync = true, - fsaa = 0, + msaa = 0, borderless = false, resizable = false, centered = true, @@ -394,7 +394,7 @@ function love.init() fullscreen = c.window.fullscreen, fullscreentype = c.window.fullscreentype, vsync = c.window.vsync, - fsaa = c.window.fsaa, + msaa = c.window.msaa, resizable = c.window.resizable, minwidth = c.window.minwidth, minheight = c.window.minheight, diff --git a/src/scripts/boot.lua.h b/src/scripts/boot.lua.h index 350114830..4596ab5c1 100644 --- a/src/scripts/boot.lua.h +++ b/src/scripts/boot.lua.h @@ -559,7 +559,7 @@ const unsigned char boot_lua[] = 0x3d, 0x20, 0x22, 0x6e, 0x6f, 0x72, 0x6d, 0x61, 0x6c, 0x22, 0x2c, 0x0a, 0x09, 0x09, 0x09, 0x64, 0x69, 0x73, 0x70, 0x6c, 0x61, 0x79, 0x20, 0x3d, 0x20, 0x31, 0x2c, 0x0a, 0x09, 0x09, 0x09, 0x76, 0x73, 0x79, 0x6e, 0x63, 0x20, 0x3d, 0x20, 0x74, 0x72, 0x75, 0x65, 0x2c, 0x0a, - 0x09, 0x09, 0x09, 0x66, 0x73, 0x61, 0x61, 0x20, 0x3d, 0x20, 0x30, 0x2c, 0x0a, + 0x09, 0x09, 0x09, 0x6d, 0x73, 0x61, 0x61, 0x20, 0x3d, 0x20, 0x30, 0x2c, 0x0a, 0x09, 0x09, 0x09, 0x62, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x6c, 0x65, 0x73, 0x73, 0x20, 0x3d, 0x20, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x2c, 0x0a, 0x09, 0x09, 0x09, 0x72, 0x65, 0x73, 0x69, 0x7a, 0x61, 0x62, 0x6c, 0x65, 0x20, 0x3d, 0x20, 0x66, 0x61, 0x6c, @@ -686,8 +686,8 @@ const unsigned char boot_lua[] = 0x65, 0x65, 0x6e, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x0a, 0x09, 0x09, 0x09, 0x76, 0x73, 0x79, 0x6e, 0x63, 0x20, 0x3d, 0x20, 0x63, 0x2e, 0x77, 0x69, 0x6e, 0x64, 0x6f, 0x77, 0x2e, 0x76, 0x73, 0x79, 0x6e, 0x63, 0x2c, 0x0a, - 0x09, 0x09, 0x09, 0x66, 0x73, 0x61, 0x61, 0x20, 0x3d, 0x20, 0x63, 0x2e, 0x77, 0x69, 0x6e, 0x64, 0x6f, 0x77, - 0x2e, 0x66, 0x73, 0x61, 0x61, 0x2c, 0x0a, + 0x09, 0x09, 0x09, 0x6d, 0x73, 0x61, 0x61, 0x20, 0x3d, 0x20, 0x63, 0x2e, 0x77, 0x69, 0x6e, 0x64, 0x6f, 0x77, + 0x2e, 0x6d, 0x73, 0x61, 0x61, 0x2c, 0x0a, 0x09, 0x09, 0x09, 0x72, 0x65, 0x73, 0x69, 0x7a, 0x61, 0x62, 0x6c, 0x65, 0x20, 0x3d, 0x20, 0x63, 0x2e, 0x77, 0x69, 0x6e, 0x64, 0x6f, 0x77, 0x2e, 0x72, 0x65, 0x73, 0x69, 0x7a, 0x61, 0x62, 0x6c, 0x65, 0x2c, 0x0a, 0x09, 0x09, 0x09, 0x6d, 0x69, 0x6e, 0x77, 0x69, 0x64, 0x74, 0x68, 0x20, 0x3d, 0x20, 0x63, 0x2e, 0x77, 0x69,