浏览代码

Cleaned up some code, the 'ry' parameter of love.graphics.rectangle now defaults to the value of 'rx' rather than defaulting to 0.

Alex Szpakowski 10 年之前
父节点
当前提交
0f986b10aa

+ 1 - 1
src/common/Object.h

@@ -132,7 +132,7 @@ public:
 private:
 
 	T *object;
-	
+
 }; // StrongRef
 
 } // love

+ 3 - 5
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 <typename T, typename F>
@@ -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

+ 1 - 1
src/modules/filesystem/File.cpp

@@ -71,7 +71,7 @@ FileData *File::read(int64 size)
 
 	if (!isopen)
 		close();
-	
+
 	return fileData;
 }
 

+ 1 - 1
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;
 }
 

+ 1 - 1
src/modules/filesystem/wrap_Filesystem.cpp

@@ -38,7 +38,7 @@ namespace love
 {
 namespace filesystem
 {
-	
+
 #define instance() (Module::getInstance<Filesystem>(Module::M_FILESYSTEM))
 
 bool hack_setupWriteDirectory()

+ 1 - 1
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);

+ 1 - 1
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);

+ 56 - 74
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<float>(LOVE_M_PI * 2);
-	if (points <= 0) points = 1;
-	float angle_shift = (two_pi / points);
+	if (rx == 0 || ry == 0)
+	{
+		rectangle(mode, x, y, w, h);
+		return;
+	}
+
+	points = std::max(points, 1);
+
+	const float half_pi = static_cast<float>(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;
 
-	float *coords = new float[2 * (points + 1)];
-	for (int i = 0; i < points; ++i, phi += angle_shift)
+	for (int i = 0; i <= points + 2; ++i, phi += angle_shift)
 	{
-		coords[2*i]   = x + radius * cosf(phi);
-		coords[2*i+1] = y + radius * sinf(phi);
+		coords[2 * i + 0] = x + rx * (1 - cosf(phi));
+		coords[2 * i + 1] = y + ry * (1 - sinf(phi));
 	}
 
-	coords[2*points]   = coords[0];
-	coords[2*points+1] = coords[1];
+	phi = half_pi;
 
-	polygon(mode, coords, (points + 1) * 2);
+	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<float>(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<float>(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

+ 14 - 14
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).

+ 2 - 2
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;
 }
 

+ 11 - 11
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;

+ 1 - 1
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;
 }
 

+ 1 - 1
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;
 }
 

+ 1 - 1
src/modules/joystick/sdl/Joystick.h

@@ -129,7 +129,7 @@ private:
 
 	static EnumMap<GamepadButton, SDL_GameControllerButton, GAMEPAD_BUTTON_MAX_ENUM>::Entry gpButtonEntries[];
 	static EnumMap<GamepadButton, SDL_GameControllerButton, GAMEPAD_BUTTON_MAX_ENUM> gpButtons;
-	
+
 };
 
 } // sdl

+ 1 - 1
src/modules/keyboard/Keyboard.cpp

@@ -514,7 +514,7 @@ StringMap<Keyboard::Scancode, Keyboard::SCANCODE_MAX_ENUM>::Entry Keyboard::scan
 	{"kbdillumup", SCANCODE_KBDILLUMUP},
 	{"eject", SCANCODE_EJECT},
 	{"sleep", SCANCODE_SLEEP},
-	
+
 	{"app1", SCANCODE_APP1},
 	{"app2", SCANCODE_APP2},
 };

+ 2 - 2
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,
 

+ 1 - 1
src/modules/keyboard/sdl/Keyboard.cpp

@@ -627,7 +627,7 @@ EnumMap<Keyboard::Scancode, SDL_Scancode, SDL_NUM_SCANCODES>::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},
 };

+ 7 - 7
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<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},

+ 1 - 1
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;
 }
 

+ 1 - 1
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);

+ 1 - 1
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;
 }
 

+ 1 - 1
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.

+ 4 - 4
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;
 }
 

+ 1 - 1
src/modules/timer/sdl/Timer.h

@@ -41,7 +41,7 @@ public:
 	const char *getName() const override;
 
 	void sleep(double seconds) const override;
-	
+
 }; // Timer
 
 } // sdl

+ 2 - 2
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;
 }