소스 검색

Add Lua bindings for Actor and PhysicsWorld

Daniele Bartolini 12 년 전
부모
커밋
d16074cfc6
9개의 변경된 파일335개의 추가작업 그리고 0개의 파일을 삭제
  1. 2 0
      engine/Android.mk
  2. 2 0
      engine/CMakeLists.txt
  3. 210 0
      engine/lua/LuaActor.cpp
  4. 2 0
      engine/lua/LuaEnvironment.cpp
  5. 2 0
      engine/lua/LuaEnvironment.h
  6. 65 0
      engine/lua/LuaPhysicsWorld.cpp
  7. 26 0
      engine/lua/LuaStack.h
  8. 13 0
      engine/lua/LuaUnit.cpp
  9. 13 0
      engine/lua/LuaWorld.cpp

+ 2 - 0
engine/Android.mk

@@ -105,6 +105,8 @@ LOCAL_SRC_FILES :=\
 	lua/LuaWorld.cpp\
 	lua/LuaMesh.cpp\
 	lua/LuaSprite.cpp\
+	lua/LuaActor.cpp\
+	lua/LuaPhysicsWorld.cpp\
 \
 	audio/sles/SLESRenderer.cpp\
 \

+ 2 - 0
engine/CMakeLists.txt

@@ -362,6 +362,8 @@ set (LUA_SRC
 	lua/LuaCamera.cpp
 	lua/LuaMesh.cpp
 	lua/LuaSprite.cpp
+	lua/LuaActor.cpp
+	lua/LuaPhysicsWorld.cpp
 )
 
 set (LUA_HEADERS

+ 210 - 0
engine/lua/LuaActor.cpp

@@ -0,0 +1,210 @@
+/*
+Copyright (c) 2013 Daniele Bartolini, Michele Rossi
+Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+*/
+
+#include "LuaStack.h"
+#include "LuaEnvironment.h"
+#include "Actor.h"
+
+namespace crown
+{
+
+//-----------------------------------------------------------------------------
+CE_EXPORT int actor_enable_gravity(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Actor* actor = stack.get_actor(1);
+
+	actor->enable_gravity();
+	return 0;
+}
+
+//-----------------------------------------------------------------------------
+CE_EXPORT int actor_disable_gravity(lua_State* L)
+{
+	LuaStack stack(L);
+	Actor* actor = stack.get_actor(1);
+
+	actor->disable_gravity();
+	return 0;
+}
+
+//-----------------------------------------------------------------------------
+CE_EXPORT int actor_is_static(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Actor* actor = stack.get_actor(1);
+
+	stack.push_bool(actor->is_static());
+	return 1;
+}
+
+//-----------------------------------------------------------------------------
+CE_EXPORT int actor_is_dynamic(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Actor* actor = stack.get_actor(1);
+
+	stack.push_bool(actor->is_dynamic());
+	return 1;
+}
+
+//-----------------------------------------------------------------------------
+CE_EXPORT int actor_linear_damping(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Actor* actor = stack.get_actor(1);
+
+	stack.push_float(actor->linear_damping());
+	return 1;
+}
+
+//-----------------------------------------------------------------------------
+CE_EXPORT int actor_set_linear_damping(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Actor* actor = stack.get_actor(1);
+	const float rate = stack.get_float(2);
+
+	actor->set_linear_damping(rate);
+	return 0;
+}
+
+//-----------------------------------------------------------------------------
+CE_EXPORT int actor_angular_damping(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Actor* actor = stack.get_actor(1);
+
+	stack.push_float(actor->angular_damping());
+	return 1;
+}
+
+//-----------------------------------------------------------------------------
+CE_EXPORT int actor_set_angular_damping(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Actor* actor = stack.get_actor(1);
+	const float rate = stack.get_float(2);
+
+	actor->set_angular_damping(rate);
+	return 0;
+}
+
+//-----------------------------------------------------------------------------
+CE_EXPORT int actor_linear_velocity(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Actor* actor = stack.get_actor(1);
+
+	stack.push_vector3(actor->linear_velocity());
+	return 1;
+}
+
+//-----------------------------------------------------------------------------
+CE_EXPORT int actor_set_linear_velocity(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Actor* actor = stack.get_actor(1);
+	const Vector3& vel = stack.get_vector3(2);
+
+	actor->set_linear_velocity(vel);
+	return 0;
+}
+
+//-----------------------------------------------------------------------------
+CE_EXPORT int actor_angular_velocity(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Actor* actor = stack.get_actor(1);
+
+	stack.push_vector3(actor->angular_velocity());
+	return 1;
+}
+
+//-----------------------------------------------------------------------------
+CE_EXPORT int actor_set_angular_velocity(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Actor* actor = stack.get_actor(1);
+	const Vector3& vel = stack.get_vector3(2);
+
+	actor->set_angular_velocity(vel);
+	return 0;
+}
+
+//-----------------------------------------------------------------------------
+CE_EXPORT int actor_is_sleeping(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Actor* actor = stack.get_actor(1);
+
+	stack.push_bool(actor->is_sleeping());
+	return 1;
+}
+
+//-----------------------------------------------------------------------------
+CE_EXPORT int actor_wake_up(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Actor* actor = stack.get_actor(1);
+
+	actor->wake_up();
+	return 0;
+}
+
+//-----------------------------------------------------------------------------
+void load_actor(LuaEnvironment& env)
+{
+	env.load_module_function("Actor", "enable_gravity",			actor_enable_gravity);
+	env.load_module_function("Actor", "disable_gravity",		actor_disable_gravity);
+	env.load_module_function("Actor", "is_static",				actor_is_static);
+	env.load_module_function("Actor", "is_dynamic",				actor_is_dynamic);
+	env.load_module_function("Actor", "linear_damping",			actor_linear_damping);
+	env.load_module_function("Actor", "set_linear_damping",		actor_set_linear_damping);
+	env.load_module_function("Actor", "angular_damping",		actor_angular_damping);
+	env.load_module_function("Actor", "set_angular_damping",	actor_set_angular_damping);
+	env.load_module_function("Actor", "linear_velocity",		actor_linear_velocity);
+	env.load_module_function("Actor", "set_linear_velocity",	actor_set_linear_velocity);
+	env.load_module_function("Actor", "angular_velocity",		actor_angular_velocity);
+	env.load_module_function("Actor", "set_angular_velocity",	actor_set_angular_velocity);
+	env.load_module_function("Actor", "is_sleeping",			actor_is_sleeping);
+	env.load_module_function("Actor", "wake_up",				actor_wake_up);
+}
+
+} // namespace crown

+ 2 - 0
engine/lua/LuaEnvironment.cpp

@@ -78,6 +78,8 @@ CE_EXPORT int luaopen_libcrown(lua_State* /*L*/)
 	load_world(*env);
 	load_mesh(*env);
 	load_sprite(*env);
+	load_actor(*env);
+	load_physics_world(*env);
 
 	return 1;
 }

+ 2 - 0
engine/lua/LuaEnvironment.h

@@ -111,6 +111,8 @@ void load_camera(LuaEnvironment& env);
 void load_world(LuaEnvironment& env);
 void load_mesh(LuaEnvironment& env);
 void load_sprite(LuaEnvironment& env);
+void load_actor(LuaEnvironment& env);
+void load_physics_world(LuaEnvironment& env);
 
 CE_EXPORT int32_t luaopen_libcrown(lua_State* L);
 

+ 65 - 0
engine/lua/LuaPhysicsWorld.cpp

@@ -0,0 +1,65 @@
+/*
+Copyright (c) 2013 Daniele Bartolini, Michele Rossi
+Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+*/
+
+#include "PhysicsWorld.h"
+#include "Vector3.h"
+#include "LuaStack.h"
+#include "LuaEnvironment.h"
+
+namespace crown
+{
+
+//-----------------------------------------------------------------------------
+CE_EXPORT int physics_world_gravity(lua_State* L)
+{
+	LuaStack stack(L);
+
+	PhysicsWorld* world = stack.get_physics_world(1);
+
+	stack.push_vector3(world->gravity());
+	return 1;
+}
+
+//-----------------------------------------------------------------------------
+CE_EXPORT int physics_world_set_gravity(lua_State* L)
+{
+	LuaStack stack(L);
+
+	PhysicsWorld* world = stack.get_physics_world(1);
+	const Vector3& gravity = stack.get_vector3(2);
+
+	world->set_gravity(gravity);
+	return 0;
+}
+
+//-----------------------------------------------------------------------------
+void load_physics_world(LuaEnvironment& env)
+{
+	env.load_module_function("PhysicsWorld", "gravity",			physics_world_gravity);
+	env.load_module_function("PhysicsWorld", "set_gravity",		physics_world_set_gravity);
+}
+
+} // namespace crown

+ 26 - 0
engine/lua/LuaStack.h

@@ -42,6 +42,8 @@ class Camera;
 class World;
 class Mesh;
 class Sprite;
+class PhysicsWorld;
+class Actor;
 class ResourcePackage;
 typedef Id SoundInstanceId;
 
@@ -247,6 +249,30 @@ public:
 		return (Sprite*) lua_touserdata(m_state, index);
 	}
 
+	//-----------------------------------------------------------------------------
+	PhysicsWorld* get_physics_world(int32_t index)
+	{
+		return (PhysicsWorld*) lua_touserdata(m_state, index);
+	}
+
+	//-----------------------------------------------------------------------------
+	void push_physics_world(PhysicsWorld* world)
+	{
+		lua_pushlightuserdata(m_state, world);
+	}
+
+	//-----------------------------------------------------------------------------
+	void push_actor(Actor* actor)
+	{
+		lua_pushlightuserdata(m_state, actor);
+	}
+
+	//-----------------------------------------------------------------------------
+	Actor* get_actor(int32_t index)
+	{
+		return (Actor*) lua_touserdata(m_state, index);
+	}	
+
 	//-------------------------------------------------------------------------
 	void push_sound_instance_id(const SoundInstanceId id)
 	{

+ 13 - 0
engine/lua/LuaUnit.cpp

@@ -238,6 +238,18 @@ CE_EXPORT int unit_sprite(lua_State* L)
 	return 1;
 }
 
+//-----------------------------------------------------------------------------
+CE_EXPORT int unit_actor(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Unit* unit = stack.get_unit(1);
+	const char* actor_name = stack.get_string(2);
+
+	stack.push_actor(unit->actor(actor_name));
+	return 1;
+}
+
 //-----------------------------------------------------------------------------
 void load_unit(LuaEnvironment& env)
 {
@@ -260,6 +272,7 @@ void load_unit(LuaEnvironment& env)
 	env.load_module_function("Unit", "camera",					unit_camera);
 	env.load_module_function("Unit", "mesh",					unit_mesh);	
 	env.load_module_function("Unit", "sprite",					unit_sprite);
+	env.load_module_function("Unit", "actor",					unit_actor);
 }
 
 } // namespace crown

+ 13 - 0
engine/lua/LuaWorld.cpp

@@ -172,6 +172,17 @@ CE_EXPORT int world_set_sound_volume(lua_State* L)
 	return 0;
 }
 
+//-----------------------------------------------------------------------------
+CE_EXPORT int world_physics_world(lua_State* L)
+{
+	LuaStack stack(L);
+
+	World* world = stack.get_world(1);
+
+	stack.push_physics_world(world->physics_world());
+	return 1;
+}
+
 //-----------------------------------------------------------------------------
 void load_world(LuaEnvironment& env)
 {
@@ -186,6 +197,8 @@ void load_world(LuaEnvironment& env)
 	env.load_module_function("World", "set_sound_position", world_set_sound_position);
 	env.load_module_function("World", "set_sound_range", 	world_set_sound_range);
 	env.load_module_function("World", "set_sound_volume", 	world_set_sound_volume);
+
+	env.load_module_function("World", "physics_world",		world_physics_world);
 }
 
 } // namespace crown