diff --git a/src/common/Object.h b/src/common/Object.h index 418d70253..624957a9d 100644 --- a/src/common/Object.h +++ b/src/common/Object.h @@ -132,7 +132,7 @@ public: private: T *object; - + }; // StrongRef } // love diff --git a/src/common/runtime.h b/src/common/runtime.h index af13de335..a4fb68586 100644 --- a/src/common/runtime.h +++ b/src/common/runtime.h @@ -463,9 +463,9 @@ T *luax_optmodule(lua_State *L, love::Type type) if (!typeFlags[u->type][type]) luaL_error(L, "Incorrect module %s", name); - + lua_pop(L, 2); - + return (T *) u->object; } @@ -510,7 +510,6 @@ int luax_catchexcept(lua_State *L, const T& func) return luaL_error(L, "%s", lua_tostring(L, -1)); return 0; - } template @@ -532,9 +531,8 @@ int luax_catchexcept(lua_State *L, const T& func, const F& finallyfunc) if (should_error) return luaL_error(L, "%s", lua_tostring(L, -1)); - + return 0; - } } // love diff --git a/src/modules/filesystem/File.cpp b/src/modules/filesystem/File.cpp index 578bacf33..6f4f44991 100644 --- a/src/modules/filesystem/File.cpp +++ b/src/modules/filesystem/File.cpp @@ -71,7 +71,7 @@ FileData *File::read(int64 size) if (!isopen) close(); - + return fileData; } diff --git a/src/modules/filesystem/wrap_File.cpp b/src/modules/filesystem/wrap_File.cpp index 857648da6..f8b0fe0fc 100644 --- a/src/modules/filesystem/wrap_File.cpp +++ b/src/modules/filesystem/wrap_File.cpp @@ -319,7 +319,7 @@ int w_File_lines_i(lua_State *L) file->seek(userpos); else file->close(); - + return 0; } diff --git a/src/modules/filesystem/wrap_Filesystem.cpp b/src/modules/filesystem/wrap_Filesystem.cpp index cceb6ce89..8e8941d54 100644 --- a/src/modules/filesystem/wrap_Filesystem.cpp +++ b/src/modules/filesystem/wrap_Filesystem.cpp @@ -38,7 +38,7 @@ namespace love { namespace filesystem { - + #define instance() (Module::getInstance(Module::M_FILESYSTEM)) bool hack_setupWriteDirectory() diff --git a/src/modules/font/wrap_GlyphData.cpp b/src/modules/font/wrap_GlyphData.cpp index a1a48d603..494d9e5e0 100644 --- a/src/modules/font/wrap_GlyphData.cpp +++ b/src/modules/font/wrap_GlyphData.cpp @@ -59,7 +59,7 @@ int w_GlyphData_getGlyph(lua_State *L) lua_pushnumber(L, (lua_Number) glyph); return 1; } - + int w_GlyphData_getGlyphString(lua_State *L) { GlyphData *t = luax_checkglyphdata(L, 1); diff --git a/src/modules/graphics/opengl/GLBuffer.cpp b/src/modules/graphics/opengl/GLBuffer.cpp index 587e32e05..86fcca92d 100644 --- a/src/modules/graphics/opengl/GLBuffer.cpp +++ b/src/modules/graphics/opengl/GLBuffer.cpp @@ -315,7 +315,7 @@ void VertexIndex::resize(size_t size) } GLBuffer *new_element_array; - + // Depending on the size, a switch to int and more memory is needed. GLenum target_type = getType(size); size_t elem_size = (target_type == GL_UNSIGNED_SHORT) ? sizeof(GLushort) : sizeof(GLuint); diff --git a/src/modules/graphics/opengl/Graphics.cpp b/src/modules/graphics/opengl/Graphics.cpp index 4a1cdc84c..c7e59facb 100644 --- a/src/modules/graphics/opengl/Graphics.cpp +++ b/src/modules/graphics/opengl/Graphics.cpp @@ -1112,50 +1112,88 @@ void Graphics::rectangle(DrawMode mode, float x, float y, float w, float h) polygon(mode, coords, 5 * 2); } -void Graphics::circle(DrawMode mode, float x, float y, float radius, int points) +void Graphics::rectangle(DrawMode mode, float x, float y, float w, float h, float rx, float ry, int points) { - float two_pi = static_cast(LOVE_M_PI * 2); - if (points <= 0) points = 1; - float angle_shift = (two_pi / points); - float phi = .0f; - - float *coords = new float[2 * (points + 1)]; - for (int i = 0; i < points; ++i, phi += angle_shift) + if (rx == 0 || ry == 0) { - coords[2*i] = x + radius * cosf(phi); - coords[2*i+1] = y + radius * sinf(phi); + rectangle(mode, x, y, w, h); + return; } - coords[2*points] = coords[0]; - coords[2*points+1] = coords[1]; + points = std::max(points, 1); - polygon(mode, coords, (points + 1) * 2); + const float half_pi = static_cast(LOVE_M_PI / 2); + float angle_shift = half_pi / ((float) points + 1.0f); + + int num_coords = (points + 2) * 8; + float *coords = new float[num_coords + 2]; + float phi = .0f; + + for (int i = 0; i <= points + 2; ++i, phi += angle_shift) + { + coords[2 * i + 0] = x + rx * (1 - cosf(phi)); + coords[2 * i + 1] = y + ry * (1 - sinf(phi)); + } + + phi = half_pi; + + for (int i = points + 2; i <= 2 * (points + 2); ++i, phi += angle_shift) + { + coords[2 * i + 0] = x + w - rx * (1 + cosf(phi)); + coords[2 * i + 1] = y + ry * (1 - sinf(phi)); + } + + phi = 2 * half_pi; + + for (int i = 2 * (points + 2); i <= 3 * (points + 2); ++i, phi += angle_shift) + { + coords[2 * i + 0] = x + w - rx * (1 + cosf(phi)); + coords[2 * i + 1] = y + h - ry * (1 + sinf(phi)); + } + + phi = 3 * half_pi; + + for (int i = 3 * (points + 2); i <= 4 * (points + 2); ++i, phi += angle_shift) + { + coords[2 * i + 0] = x + rx * (1 - cosf(phi)); + coords[2 * i + 1] = y + h - ry * (1 + sinf(phi)); + } + + coords[num_coords + 0] = coords[0]; + coords[num_coords + 1] = coords[1]; + + polygon(mode, coords, num_coords + 2); delete[] coords; } +void Graphics::circle(DrawMode mode, float x, float y, float radius, int points) +{ + ellipse(mode, x, y, radius, radius, points); +} + void Graphics::ellipse(DrawMode mode, float x, float y, float a, float b, int points) { float two_pi = static_cast(LOVE_M_PI * 2); if (points <= 0) points = 1; float angle_shift = (two_pi / points); float phi = .0f; - + float *coords = new float[2 * (points + 1)]; for (int i = 0; i < points; ++i, phi += angle_shift) { - coords[2*i] = x + a * cosf(phi); + coords[2*i+0] = x + a * cosf(phi); coords[2*i+1] = y + b * sinf(phi); } - - coords[2*points] = coords[0]; + + coords[2*points+0] = coords[0]; coords[2*points+1] = coords[1]; - + polygon(mode, coords, (points + 1) * 2); - + delete[] coords; } - + void Graphics::arc(DrawMode mode, float x, float y, float radius, float angle1, float angle2, int points) { // Nothing to display with no points or equal angles. (Or is there with line mode?) @@ -1206,62 +1244,6 @@ void Graphics::arc(DrawMode mode, float x, float y, float radius, float angle1, delete[] coords; } -void Graphics::rectangle(DrawMode mode, float x, float y, float w, float h, float rx, float ry, float points) -{ - if (points < 1) - points = 1; - - if (rx == 0 || ry == 0) - { - rectangle(mode, x, y, w, h); - return; - } - - const float half_pi = static_cast(LOVE_M_PI / 2); - float angle_shift = half_pi / (points + 1); - - int num_coords = (points + 2) * 8; - float *coords = new float[num_coords + 2]; - float phi = .0f; - - for (int i = 0; i <= points + 2; ++i, phi += angle_shift) - { - coords[2 * i] = x + rx * (1 - cosf(phi)); - coords[2 * i + 1] = y + ry * (1 - sinf(phi)); - } - - phi = half_pi; - - for (int i = points + 2; i <= 2 * (points + 2); ++i, phi += angle_shift) - { - coords[2 * i] = x + w - rx * (1 + cosf(phi)); - coords[2 * i + 1] = y + ry * (1 - sinf(phi)); - } - - phi = 2 * half_pi; - - for (int i = 2 * (points + 2); i <= 3 * (points + 2); ++i, phi += angle_shift) - { - coords[2 * i] = x + w - rx * (1 + cosf(phi)); - coords[2 * i + 1] = y + h - ry * (1 + sinf(phi)); - } - - phi = 3 * half_pi; - - for (int i = 3 * (points + 2); i <= 4 * (points + 2); ++i, phi += angle_shift) - { - coords[2 * i] = x + rx * (1 - cosf(phi)); - coords[2 * i + 1] = y + h - ry * (1 + sinf(phi)); - } - - coords[num_coords] = coords[0]; - coords[num_coords + 1] = coords[1]; - - polygon(mode, coords, num_coords + 2); - - delete[] coords; -} - /// @param mode the draw mode /// @param coords the coordinate array /// @param count the number of coordinates/size of the array diff --git a/src/modules/graphics/opengl/Graphics.h b/src/modules/graphics/opengl/Graphics.h index aacc887b0..5279e7f26 100644 --- a/src/modules/graphics/opengl/Graphics.h +++ b/src/modules/graphics/opengl/Graphics.h @@ -367,6 +367,19 @@ public: **/ void rectangle(DrawMode mode, float x, float y, float w, float h); + /** + * Variant of rectangle that draws a rounded rectangle. + * @param mode The mode of drawing (line/filled). + * @param x X-coordinate of top-left corner + * @param y Y-coordinate of top-left corner + * @param w The width of the rectangle. + * @param h The height of the rectangle. + * @param rx The radius of the corners on the x axis + * @param ry The radius of the corners on the y axis + * @param points The number of points to use per corner + **/ + void rectangle(DrawMode mode, float x, float y, float w, float h, float rx, float ry, int points = 10); + /** * Draws a circle using the specified arguments. * @param mode The mode of drawing (line/filled). @@ -387,7 +400,7 @@ public: * @param points Number of points to use to draw the circle. **/ void ellipse(DrawMode mode, float x, float y, float a, float b, int points = 10); - + /** * Draws an arc using the specified arguments. * @param mode The mode of drawing (line/filled). @@ -400,19 +413,6 @@ public: **/ void arc(DrawMode mode, float x, float y, float radius, float angle1, float angle2, int points = 10); - /** - * Variant of rectanglge that draws a rounded rectangle. - * @param mode The mode of drawing (line/filled). - * @param x X-coordinate of top-left corner - * @param y Y-coordinate of top-left corner - * @param w The width of the rectangle. - * @param h The height of the rectangle. - * @param rx The radius of the corners on the x axis - * @param ry The radius of the corners on the y axis - * @param points The number of points to use per corner - **/ - void rectangle(DrawMode mode, float x, float y, float w, float h, float rx, float ry, float points = 10); - /** * Draws a polygon with an arbitrary number of vertices. * @param mode The type of drawing (line/filled). diff --git a/src/modules/graphics/opengl/Image.cpp b/src/modules/graphics/opengl/Image.cpp index ad06591fc..fb104b466 100644 --- a/src/modules/graphics/opengl/Image.cpp +++ b/src/modules/graphics/opengl/Image.cpp @@ -306,7 +306,7 @@ void Image::unloadVolatile() gl.deleteTexture(texture); texture = 0; - + gl.updateTextureMemorySize(textureMemorySize, 0); textureMemorySize = 0; } @@ -347,7 +347,7 @@ bool Image::refresh(int xoffset, int yoffset, int w, int h) generateMipmaps(); } - + return true; } diff --git a/src/modules/graphics/opengl/wrap_Graphics.cpp b/src/modules/graphics/opengl/wrap_Graphics.cpp index f534b04d9..c1c9358e7 100644 --- a/src/modules/graphics/opengl/wrap_Graphics.cpp +++ b/src/modules/graphics/opengl/wrap_Graphics.cpp @@ -417,7 +417,7 @@ int w_newParticleSystem(lua_State *L) lua_Number size = luaL_optnumber(L, 2, 1000); ParticleSystem *t = 0; if (size < 1.0 || size > ParticleSystem::MAX_PARTICLES) - return luaL_error(L, "Invalid ParticleSystem size"); + return luaL_error(L, "Invalid ParticleSystem size"); luax_catchexcept(L, [&](){ t = instance()->newParticleSystem(texture, int(size)); } @@ -1037,7 +1037,7 @@ int w_getDefaultMipmapFilter(lua_State *L) lua_pushstring(L, str); else lua_pushnil(L); - + lua_pushnumber(L, sharpness); return 2; @@ -1372,7 +1372,7 @@ int w_getStats(lua_State *L) Graphics::getConstant(Graphics::STAT_TEXTURE_MEMORY, sname); lua_pushnumber(L, (lua_Number) stats.textureMemory); lua_setfield(L, -2, sname); - + return 1; } @@ -1533,14 +1533,14 @@ int w_rectangle(lua_State *L) float w = (float)luaL_checknumber(L, 4); float h = (float)luaL_checknumber(L, 5); float rx = (float)luaL_optnumber(L, 6, 0.0); - float ry = (float)luaL_optnumber(L, 7, 0.0); - + float ry = (float)luaL_optnumber(L, 7, rx); + int points; if (lua_isnoneornil(L, 8)) - points = rx + ry > 20 ? (int)((rx + ry) / 2) : 10; + points = rx + ry > 20 ? (int)((rx + ry) / 4) : 10; else points = luaL_checkint(L, 8); - + instance()->rectangle(mode, x, y, w, h, rx, ry, points); return 0; } @@ -1571,12 +1571,12 @@ int w_ellipse(lua_State *L) const char *str = luaL_checkstring(L, 1); if (!Graphics::getConstant(str, mode)) return luaL_error(L, "Incorrect draw mode %s", str); - + float x = (float)luaL_checknumber(L, 2); float y = (float)luaL_checknumber(L, 3); float a = (float)luaL_checknumber(L, 4); float b = (float)luaL_optnumber(L, 5, a); - + int points; if (lua_isnoneornil(L, 6)) points = a + b > 30 ? (int)((a + b) / 2) : 15; @@ -1586,7 +1586,7 @@ int w_ellipse(lua_State *L) instance()->ellipse(mode, x, y, a, b, points); return 0; } - + int w_arc(lua_State *L) { Graphics::DrawMode mode; @@ -1608,7 +1608,7 @@ int w_arc(lua_State *L) instance()->arc(mode, x, y, radius, angle1, angle2, points); return 0; } - + int w_polygon(lua_State *L) { int args = lua_gettop(L) - 1; diff --git a/src/modules/graphics/opengl/wrap_Mesh.cpp b/src/modules/graphics/opengl/wrap_Mesh.cpp index 67dc6e35d..1d737fca2 100644 --- a/src/modules/graphics/opengl/wrap_Mesh.cpp +++ b/src/modules/graphics/opengl/wrap_Mesh.cpp @@ -268,7 +268,7 @@ int w_Mesh_getVertexFormat(lua_State *L) // format[i] = {name, type, components} lua_rawseti(L, -2, (int) i + 1); } - + return 1; } diff --git a/src/modules/joystick/sdl/Joystick.cpp b/src/modules/joystick/sdl/Joystick.cpp index bc2be0eab..f9fe3db13 100644 --- a/src/modules/joystick/sdl/Joystick.cpp +++ b/src/modules/joystick/sdl/Joystick.cpp @@ -332,7 +332,7 @@ bool Joystick::runVibrationEffect() if (vibration.id != -1 && SDL_HapticRunEffect(haptic, vibration.id, 1) == 0) return true; - + return false; } diff --git a/src/modules/joystick/sdl/Joystick.h b/src/modules/joystick/sdl/Joystick.h index e4521a8fd..c4b2084ff 100644 --- a/src/modules/joystick/sdl/Joystick.h +++ b/src/modules/joystick/sdl/Joystick.h @@ -129,7 +129,7 @@ private: static EnumMap::Entry gpButtonEntries[]; static EnumMap gpButtons; - + }; } // sdl diff --git a/src/modules/keyboard/Keyboard.cpp b/src/modules/keyboard/Keyboard.cpp index c9770147c..969e27f28 100644 --- a/src/modules/keyboard/Keyboard.cpp +++ b/src/modules/keyboard/Keyboard.cpp @@ -514,7 +514,7 @@ StringMap::Entry Keyboard::scan {"kbdillumup", SCANCODE_KBDILLUMUP}, {"eject", SCANCODE_EJECT}, {"sleep", SCANCODE_SLEEP}, - + {"app1", SCANCODE_APP1}, {"app2", SCANCODE_APP2}, }; diff --git a/src/modules/keyboard/Keyboard.h b/src/modules/keyboard/Keyboard.h index 1eb3de35d..3ac7cb434 100644 --- a/src/modules/keyboard/Keyboard.h +++ b/src/modules/keyboard/Keyboard.h @@ -503,7 +503,7 @@ public: SCANCODE_AC_STOP, SCANCODE_AC_REFRESH, SCANCODE_AC_BOOKMARKS, - + SCANCODE_BRIGHTNESSDOWN, SCANCODE_BRIGHTNESSUP, SCANCODE_DISPLAYSWITCH, @@ -512,7 +512,7 @@ public: SCANCODE_KBDILLUMUP, SCANCODE_EJECT, SCANCODE_SLEEP, - + SCANCODE_APP1, SCANCODE_APP2, diff --git a/src/modules/keyboard/sdl/Keyboard.cpp b/src/modules/keyboard/sdl/Keyboard.cpp index 1960a8d7b..829dcead9 100644 --- a/src/modules/keyboard/sdl/Keyboard.cpp +++ b/src/modules/keyboard/sdl/Keyboard.cpp @@ -627,7 +627,7 @@ EnumMap::Entry Keyboard::sc {SCANCODE_KBDILLUMUP, SDL_SCANCODE_KBDILLUMUP}, {SCANCODE_EJECT, SDL_SCANCODE_EJECT}, {SCANCODE_SLEEP, SDL_SCANCODE_SLEEP}, - + {SCANCODE_APP1, SDL_SCANCODE_APP1}, {SCANCODE_APP2, SDL_SCANCODE_APP2}, }; diff --git a/src/modules/math/wrap_BezierCurve.cpp b/src/modules/math/wrap_BezierCurve.cpp index 620d5b281..30c85104b 100644 --- a/src/modules/math/wrap_BezierCurve.cpp +++ b/src/modules/math/wrap_BezierCurve.cpp @@ -98,14 +98,14 @@ int w_BezierCurve_removeControlPoint(lua_State *L) { BezierCurve *curve = luax_checkbeziercurve(L, 1); int idx = luaL_checkint(L, 2); - + if (idx > 0) // 1-indexing idx--; - + luax_catchexcept(L, [&](){ curve->removeControlPoint(idx); }); return 0; } - + int w_BezierCurve_getControlPointCount(lua_State *L) { BezierCurve *curve = luax_checkbeziercurve(L, 1); @@ -197,10 +197,10 @@ int w_BezierCurve_renderSegment(lua_State *L) double start = luaL_checknumber(L, 2); double end = luaL_checknumber(L, 3); int accuracy = luaL_optinteger(L, 4, 5); - + std::vector points; luax_catchexcept(L, [&](){ points = curve->renderSegment(start, end, accuracy); }); - + lua_createtable(L, points.size()*2, 0); for (size_t i = 0; i < points.size(); ++i) { @@ -209,10 +209,10 @@ int w_BezierCurve_renderSegment(lua_State *L) lua_pushnumber(L, points[i].y); lua_rawseti(L, -2, 2*i+2); } - + return 1; } - + static const luaL_Reg functions[] = { {"getDegree", w_BezierCurve_getDegree}, diff --git a/src/modules/math/wrap_Math.cpp b/src/modules/math/wrap_Math.cpp index 2af22ae60..e1d58a863 100644 --- a/src/modules/math/wrap_Math.cpp +++ b/src/modules/math/wrap_Math.cpp @@ -280,7 +280,7 @@ static int getGammaArgs(lua_State *L, float color[4]) if (numcomponents == 0) luaL_checknumber(L, 1); - + return numcomponents; } diff --git a/src/modules/physics/box2d/Body.cpp b/src/modules/physics/box2d/Body.cpp index 886bbcca2..998685d49 100644 --- a/src/modules/physics/box2d/Body.cpp +++ b/src/modules/physics/box2d/Body.cpp @@ -482,7 +482,7 @@ int Body::getContactList(lua_State *L) const contact = new Contact(ce->contact); else contact->retain(); - + luax_pushtype(L, PHYSICS_CONTACT_ID, contact); contact->release(); lua_rawseti(L, -2, i); diff --git a/src/modules/physics/box2d/Joint.cpp b/src/modules/physics/box2d/Joint.cpp index 61aca42c8..acc76d544 100644 --- a/src/modules/physics/box2d/Joint.cpp +++ b/src/modules/physics/box2d/Joint.cpp @@ -213,7 +213,7 @@ int Joint::getUserData(lua_State *L) udata->ref->push(L); else lua_pushnil(L); - + return 1; } diff --git a/src/modules/physics/box2d/MotorJoint.h b/src/modules/physics/box2d/MotorJoint.h index e677ca64c..530ed50d3 100644 --- a/src/modules/physics/box2d/MotorJoint.h +++ b/src/modules/physics/box2d/MotorJoint.h @@ -69,7 +69,7 @@ public: /// Get the position correction factor in the range [0,1]. float getCorrectionFactor() const; - + private: // The Box2D MotorJoint object. diff --git a/src/modules/sound/lullaby/CoreAudioDecoder.cpp b/src/modules/sound/lullaby/CoreAudioDecoder.cpp index b17c201e0..a32847457 100644 --- a/src/modules/sound/lullaby/CoreAudioDecoder.cpp +++ b/src/modules/sound/lullaby/CoreAudioDecoder.cpp @@ -229,26 +229,26 @@ int CoreAudioDecoder::decode() bool CoreAudioDecoder::seek(float s) { OSStatus err = ExtAudioFileSeek(extAudioFile, (SInt64) (s * inputInfo.mSampleRate)); - + if (err == noErr) { eof = false; return true; } - + return false; } bool CoreAudioDecoder::rewind() { OSStatus err = ExtAudioFileSeek(extAudioFile, 0); - + if (err == noErr) { eof = false; return true; } - + return false; } diff --git a/src/modules/timer/sdl/Timer.h b/src/modules/timer/sdl/Timer.h index d11d9e06f..3f2da641a 100644 --- a/src/modules/timer/sdl/Timer.h +++ b/src/modules/timer/sdl/Timer.h @@ -41,7 +41,7 @@ public: const char *getName() const override; void sleep(double seconds) const override; - + }; // Timer } // sdl diff --git a/src/modules/window/sdl/Window.cpp b/src/modules/window/sdl/Window.cpp index 24493543b..15812ad47 100644 --- a/src/modules/window/sdl/Window.cpp +++ b/src/modules/window/sdl/Window.cpp @@ -148,7 +148,7 @@ bool Window::checkGLVersion(const ContextAttribs &attribs) if (glmajor < attribs.versionMajor || (glmajor == attribs.versionMajor && glminor < attribs.versionMinor)) return false; - + return true; } @@ -355,7 +355,7 @@ bool Window::createWindowAndContext(int x, int y, int w, int h, Uint32 windowfla return false; } - + return true; }