Browse Source

Fixed love.keyboard.setKeyRepeat, fixed issues with Body:getWhatever, and made the save directory settable.

rude 16 years ago
parent
commit
435fc43f68

+ 0 - 4
src/modules/filesystem/physfs/Filesystem.cpp

@@ -60,10 +60,6 @@ namespace physfs
 		if(!isInited)
 			return false;
 
-		// Check whether save directory is already set.
-		if(!save_identity.empty() || PHYSFS_getWriteDir() != 0)
-			return false;
-
 		// Store the save directory.
 		save_identity = std::string(ident);
 

+ 3 - 0
src/modules/image/devil/ImageData.cpp

@@ -89,6 +89,9 @@ namespace devil
 		ilBindImage(image);	
 
 		ilTexImage(width, height, 1, bpp, IL_RGBA, IL_UNSIGNED_BYTE, 0);
+
+		// Set to black.
+		memset((void*)ilGetData(), 0, width*height*4);
 	}
 	
 	ImageData::ImageData(int width, int height, void *data)

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

@@ -180,7 +180,7 @@ namespace keyboard
 			KEY_MAX_ENUM = 512
 		};
 
-		static const int DEFAULT = 0;
+		static const int DEFAULT = -1;
 
 		virtual ~Keyboard(){}
 

+ 3 - 4
src/modules/keyboard/sdl/Keyboard.cpp

@@ -46,11 +46,10 @@ namespace sdl
 
 	void Keyboard::setKeyRepeat(int delay, int interval) const
 	{
-		if(delay == DEFAULT)
-			delay = SDL_DEFAULT_REPEAT_DELAY;
+		delay = (delay == DEFAULT) ? SDL_DEFAULT_REPEAT_DELAY : delay;
+		interval = (interval == DEFAULT) ? SDL_DEFAULT_REPEAT_INTERVAL : interval;
 
-		if(interval == DEFAULT)
-			interval = SDL_DEFAULT_REPEAT_INTERVAL;
+		SDL_EnableKeyRepeat(delay, interval);
 	}
 
 	int Keyboard::getKeyRepeatDelay() const

+ 6 - 5
src/modules/keyboard/sdl/wrap_Keyboard.cpp

@@ -46,13 +46,14 @@ namespace sdl
 
 	int w_setKeyRepeat(lua_State * L)
 	{
-		if(lua_gettop(L) == 0)
-		{
-			instance->setKeyRepeat(0, 0);
-			return 0;
+		if(lua_gettop(L) == 0)
+		{
+			// Disables key repeat.
+			instance->setKeyRepeat(0, 0);
+			return 0;
 		}
 
-		instance->setKeyRepeat(luaL_checkint(L, 1), luaL_checkint(L, 2));
+		instance->setKeyRepeat(luaL_optint(L, 1, Keyboard::DEFAULT), luaL_optint(L, 2, Keyboard::DEFAULT));
 		return 0;
 	}
 

+ 40 - 26
src/modules/physics/box2d/Body.cpp

@@ -58,14 +58,18 @@ namespace box2d
 		return world->scaleUp(body->GetPosition().y);
 	}
 
-	int Body::getPosition(lua_State * L)
+	void Body::getPosition(float & x_o, float & y_o)
 	{
-		return pushVector(L, world->scaleUp(body->GetPosition()));
+		b2Vec2 v = world->scaleUp(body->GetPosition());
+		x_o = v.x;
+		y_o = v.y;
 	}
 
-	int Body::getLinearVelocity(lua_State * L)
+	void Body::getLinearVelocity(float & x_o, float & y_o)
 	{
-		return pushVector(L, world->scaleUp(body->GetLinearVelocity()));
+		b2Vec2 v = world->scaleUp(body->GetLinearVelocity());
+		x_o = v.x;
+		y_o = v.y;
 	}
 
 	float Body::getAngle()
@@ -73,14 +77,18 @@ namespace box2d
 		return body->GetAngle();
 	}
 
-	int Body::getWorldCenter(lua_State * L)
+	void Body::getWorldCenter(float & x_o, float & y_o)
 	{
-		return pushVector(L, world->scaleUp(body->GetWorldCenter()));
+		b2Vec2 v = world->scaleUp(body->GetWorldCenter());
+		x_o = v.x;
+		y_o = v.y;
 	}
 
-	int Body::getLocalCenter(lua_State * L)
+	void Body::getLocalCenter(float & x_o, float & y_o)
 	{
-		return pushVector(L, world->scaleUp(body->GetLocalCenter()));
+		b2Vec2 v = world->scaleUp(body->GetLocalCenter());
+		x_o = v.x;
+		y_o = v.y;
 	}
 
 	float Body::getAngularVelocity() const
@@ -187,40 +195,46 @@ namespace box2d
 		body->SetMass(&massData);
 	}
 
-	int Body::getWorldPoint(lua_State * L)
+	void Body::getWorldPoint(float x, float y, float & x_o, float & y_o)
 	{
-		b2Vec2 v = world->scaleDown(getVector(L));
-		return pushVector(L, world->scaleUp(body->GetWorldPoint(v)));
+		b2Vec2 v = world->scaleUp(body->GetWorldPoint(world->scaleDown(b2Vec2(x, y))));
+		x_o = v.x;
+		y_o = v.y;
 	}
 
-	int Body::getWorldVector(lua_State * L)
+	void Body::getWorldVector(float x, float y, float & x_o, float & y_o)
 	{
-		b2Vec2 v = world->scaleDown(getVector(L));
-		return pushVector(L, world->scaleUp(body->GetWorldVector(v)));
+		b2Vec2 v = world->scaleUp(body->GetWorldVector(world->scaleDown(b2Vec2(x, y))));
+		x_o = v.x;
+		y_o = v.y;
 	}
 
-	int Body::getLocalPoint(lua_State * L)
+	void Body::getLocalPoint(float x, float y, float & x_o, float & y_o)
 	{
-		b2Vec2 v = world->scaleDown(getVector(L));
-		return pushVector(L, world->scaleUp(body->GetLocalPoint(v)));
+		b2Vec2 v = world->scaleUp(body->GetLocalPoint(world->scaleDown(b2Vec2(x, y))));
+		x_o = v.x;
+		y_o = v.y;
 	}
 
-	int Body::getLocalVector(lua_State * L)
+	void Body::getLocalVector(float x, float y, float & x_o, float & y_o)
 	{
-		b2Vec2 v = world->scaleDown(getVector(L));
-		return pushVector(L, world->scaleUp(body->GetLocalVector(v)));
+		b2Vec2 v = world->scaleUp(body->GetLocalVector(world->scaleDown(b2Vec2(x, y))));
+		x_o = v.x;
+		y_o = v.y;
 	}
 
-	int Body::getLinearVelocityFromWorldPoint(lua_State * L)
+	void Body::getLinearVelocityFromWorldPoint(float x, float y, float & x_o, float & y_o)
 	{
-		b2Vec2 v = world->scaleDown(getVector(L));
-		return pushVector(L, world->scaleUp(body->GetLinearVelocityFromWorldPoint(v)));
+		b2Vec2 v = world->scaleUp(body->GetLinearVelocityFromWorldPoint(world->scaleDown(b2Vec2(x, y))));
+		x_o = v.x;
+		y_o = v.y;
 	}
 
-	int Body::getLinearVelocityFromLocalPoint(lua_State * L)
+	void Body::getLinearVelocityFromLocalPoint(float x, float y, float & x_o, float & y_o)
 	{
-		b2Vec2 v = world->scaleDown(getVector(L));
-		return pushVector(L, world->scaleUp(body->GetLinearVelocityFromLocalPoint(v)));
+		b2Vec2 v = world->scaleUp(body->GetLinearVelocityFromLocalPoint(world->scaleDown(b2Vec2(x, y))));
+		x_o = v.x;
+		y_o = v.y;
 	}
 
 	bool Body::isBullet() const

+ 13 - 14
src/modules/physics/box2d/Body.h

@@ -22,6 +22,7 @@
 #define LOVE_PHYSICS_BOX2D_BODY_H
 
 // LOVE
+#include <common/math.h>
 #include <common/runtime.h>
 #include <common/Object.h>
 
@@ -93,17 +94,15 @@ namespace box2d
 
 		/**
 		* Gets the current position of the Body.
-		* @returns The current x-position.
-		* @returns The current y-position.
+		* @returns The current position.
 		**/
-		int getPosition(lua_State * L);
+		void getPosition(float & x_o, float & y_o);
 
 		/**
 		* Gets the velocity in the current center of mass.
-		* @returns The x-component of the velocity.
-		* @returns The y-component of the velocity.
+		* @returns The velocity in the current center of mass.
 		**/
-		int getLinearVelocity(lua_State * L);
+		void getLinearVelocity(float & x_o, float & y_o);
 
 		/**
 		* The current center of mass for the Body in world
@@ -111,7 +110,7 @@ namespace box2d
 		* @returns The x-component of the point.
 		* @returns The y-component of the point.
 		**/
-		int getWorldCenter(lua_State * L);
+		void getWorldCenter(float & x_o, float & y_o);
 
 		/**
 		* The current center of mass for the Body in local
@@ -119,7 +118,7 @@ namespace box2d
 		* @returns The x-component of the point.
 		* @returns The y-component of the point.
 		**/
-		int getLocalCenter(lua_State * L);
+		void getLocalCenter(float & x_o, float & y_o);
 
 		/**
 		* Get the current Body spin. (Angular velocity).
@@ -233,7 +232,7 @@ namespace box2d
 		* @returns The x-coordinate of the point in world coordinates.
 		* @returns The y-coordinate of the point in world coordinates.
 		**/
-		int getWorldPoint(lua_State * L);
+		void getWorldPoint(float x, float y, float & x_o, float & y_o);
 
 		/**
 		* Transforms a vector (x, y) from local coordinates
@@ -243,7 +242,7 @@ namespace box2d
 		* @returns The x-coordinate of the vector in world coordinates.
 		* @returns The y-coordinate of the vector in world coordinates.
 		**/
-		int getWorldVector(lua_State * L);
+		void getWorldVector(float x, float y, float & x_o, float & y_o);
 
 		/**
 		* Transforms a point (x, y) from world coordinates
@@ -253,7 +252,7 @@ namespace box2d
 		* @returns The x-coordinate of the point in local coordinates.
 		* @returns The y-coordinate of the point in local coordinates.
 		**/
-		int getLocalPoint(lua_State * L);
+		void getLocalPoint(float x, float y, float & x_o, float & y_o);
 
 		/**
 		* Transforms a vector (x, y) from world coordinates
@@ -263,7 +262,7 @@ namespace box2d
 		* @returns The x-coordinate of the vector in local coordinates.
 		* @returns The y-coordinate of the vector in local coordinates.
 		**/
-		int getLocalVector(lua_State * L);
+		void getLocalVector(float x, float y, float & x_o, float & y_o);
 
 		/**
 		* Gets the velocity on the Body for the given world point.
@@ -272,7 +271,7 @@ namespace box2d
 		* @returns The x-component of the velocity vector.
 		* @returns The y-component of the velocity vector.
 		**/
-		int getLinearVelocityFromWorldPoint(lua_State * L);
+		void getLinearVelocityFromWorldPoint(float x, float y, float & x_o, float & y_o);
 
 		/**
 		* Gets the velocity on the Body for the given local point.
@@ -281,7 +280,7 @@ namespace box2d
 		* @returns The x-component of the velocity vector.
 		* @returns The y-component of the velocity vector.
 		**/
-		int getLinearVelocityFromLocalPoint(lua_State * L);
+		void getLinearVelocityFromLocalPoint(float x, float y, float & x_o, float & y_o);
 
 		/**
 		* Returns true if the Body is a bullet, false otherwise.

+ 82 - 10
src/modules/physics/box2d/wrap_Body.cpp

@@ -55,25 +55,49 @@ namespace box2d
 	int w_Body_getPosition(lua_State * L)
 	{
 		Body * t = luax_checkbody(L, 1);
-		return t->getPosition(L);
+
+		float x_o, y_o;
+		t->getPosition(x_o, y_o);
+		lua_pushnumber(L, x_o);
+		lua_pushnumber(L, y_o);
+
+		return 2;
 	}
 
 	int w_Body_getLinearVelocity(lua_State * L)
 	{
 		Body * t = luax_checkbody(L, 1);
-		return t->getLinearVelocity(L);
+
+		float x_o, y_o;
+		t->getLinearVelocity(x_o, y_o);
+		lua_pushnumber(L, x_o);
+		lua_pushnumber(L, y_o);
+
+		return 2;
 	}
 
 	int w_Body_getWorldCenter(lua_State * L)
 	{
 		Body * t = luax_checkbody(L, 1);
-		return t->getWorldCenter(L);
+
+		float x_o, y_o;
+		t->getWorldCenter(x_o, y_o);
+		lua_pushnumber(L, x_o);
+		lua_pushnumber(L, y_o);
+
+		return 2;
 	}
 
 	int w_Body_getLocalCenter(lua_State * L)
 	{
 		Body * t = luax_checkbody(L, 1);
-		return t->getLocalCenter(L);
+
+		float x_o, y_o;
+		t->getLocalCenter(x_o, y_o);
+		lua_pushnumber(L, x_o);
+		lua_pushnumber(L, y_o);
+
+		return 2;
 	}
 
 	int w_Body_getAngularVelocity(lua_State * L)
@@ -228,37 +252,85 @@ namespace box2d
 	int w_Body_getWorldPoint(lua_State * L)
 	{
 		Body * t = luax_checkbody(L, 1);
-		return t->getWorldPoint(L);
+
+		float x = (float)luaL_checknumber(L, 2);
+		float y = (float)luaL_checknumber(L, 3);
+		float x_o, y_o;
+		t->getWorldPoint(x, y, x_o, y_o);
+		lua_pushnumber(L, x_o);
+		lua_pushnumber(L, y_o);
+
+		return 2;
 	}
 
 	int w_Body_getWorldVector(lua_State * L)
 	{
 		Body * t = luax_checkbody(L, 1);
-		return t->getWorldVector(L);
+
+		float x = (float)luaL_checknumber(L, 2);
+		float y = (float)luaL_checknumber(L, 3);
+		float x_o, y_o;
+		t->getWorldVector(x, y, x_o, y_o);
+		lua_pushnumber(L, x_o);
+		lua_pushnumber(L, y_o);
+
+		return 2;
 	}
 
 	int w_Body_getLocalPoint(lua_State * L)
 	{
 		Body * t = luax_checkbody(L, 1);
-		return t->getLocalPoint(L);
+
+		float x = (float)luaL_checknumber(L, 2);
+		float y = (float)luaL_checknumber(L, 3);
+		float x_o, y_o;
+		t->getLocalPoint(x, y, x_o, y_o);
+		lua_pushnumber(L, x_o);
+		lua_pushnumber(L, y_o);
+
+		return 2;
 	}
 
 	int w_Body_getLocalVector(lua_State * L)
 	{
 		Body * t = luax_checkbody(L, 1);
-		return t->getLocalVector(L);
+
+		float x = (float)luaL_checknumber(L, 2);
+		float y = (float)luaL_checknumber(L, 3);
+		float x_o, y_o;
+		t->getLocalVector(x, y, x_o, y_o);
+		lua_pushnumber(L, x_o);
+		lua_pushnumber(L, y_o);
+
+		return 2;
 	}
 
 	int w_Body_getLinearVelocityFromWorldPoint(lua_State * L)
 	{
 		Body * t = luax_checkbody(L, 1);
-		return t->getLinearVelocityFromWorldPoint(L);
+
+		float x = (float)luaL_checknumber(L, 2);
+		float y = (float)luaL_checknumber(L, 3);
+		float x_o, y_o;
+		t->getLinearVelocityFromWorldPoint(x, y, x_o, y_o);
+		lua_pushnumber(L, x_o);
+		lua_pushnumber(L, y_o);
+
+		return 2;
 	}
 
 	int w_Body_getLinearVelocityFromLocalPoint(lua_State * L)
 	{
 		Body * t = luax_checkbody(L, 1);
-		return t->getLinearVelocityFromLocalPoint(L);
+
+		float x = (float)luaL_checknumber(L, 2);
+		float y = (float)luaL_checknumber(L, 3);
+		float x_o, y_o;
+		t->getLinearVelocityFromLocalPoint(x, y, x_o, y_o);
+		lua_pushnumber(L, x_o);
+		lua_pushnumber(L, y_o);
+
+		return 2;
 	}
 
 	int w_Body_isBullet(lua_State * L)

+ 16 - 2
src/scripts/boot.lua

@@ -60,7 +60,18 @@ end
 
 -- Returns the leaf of a full path.
 function love.path.leaf(p)
-
+	local a = 1
+	local last = p
+	
+	while a do
+		a = string.find(p, "/", a+1)
+		
+		if a then
+			last = string.sub(p, a+1)
+		end
+	end
+	
+	return last
 end
 
 -- Finds the key in the table with the lowest integral index. The lowest 
@@ -113,7 +124,10 @@ function love.boot()
 
 	if arg and arg[1] then
 		love.filesystem.init(love.path.getfull(love.arg.getLow(arg)))
-		if not pcall(love.filesystem.setSource, love.path.getfull(arg[1])) then
+		local full_source =  love.path.getfull(arg[1])
+		local leaf = love.path.leaf(full_source)
+		love.filesystem.setIdentity(leaf)
+		if not pcall(love.filesystem.setSource, full_source) then
 			love.nogame()
 		end
 	else