Răsfoiți Sursa

Add a very ugly hack to support another very ugly thing in World.

Daniele Bartolini 12 ani în urmă
părinte
comite
2dd5853c6a
2 a modificat fișierele cu 28 adăugiri și 0 ștergeri
  1. 19 0
      engine/lua/LuaEnvironment.cpp
  2. 9 0
      engine/lua/LuaEnvironment.h

+ 19 - 0
engine/lua/LuaEnvironment.cpp

@@ -165,4 +165,23 @@ void LuaEnvironment::call_global(const char* func, uint8_t argc, ...)
 	lua_pcall(m_L, argc, 0, -argc - 2);
 }
 
+void LuaEnvironment::call_physics_callback(Actor* actor_0, Actor* actor_1, Unit* unit_0, Unit* unit_1, const Vector3& where, const Vector3& normal, const char* type)
+{
+	LuaStack stack(m_L);
+
+	lua_pushcfunction(m_L, lua_system::error_handler);
+	lua_getglobal(m_L, "physics_callback");
+
+	stack.push_table();
+	stack.push_key_begin("actor_0"); stack.push_actor(actor_0); stack.push_key_end();
+	stack.push_key_begin("actor_1"); stack.push_actor(actor_1); stack.push_key_end();
+	stack.push_key_begin("unit_0"); stack.push_unit(unit_0); stack.push_key_end();
+	stack.push_key_begin("unit_1"); stack.push_unit(unit_1); stack.push_key_end();
+	stack.push_key_begin("where"); stack.push_vector3(where); stack.push_key_end();
+	stack.push_key_begin("normal"); stack.push_vector3(normal); stack.push_key_end();
+	stack.push_key_begin("type"); stack.push_string(type); stack.push_key_end();
+
+	lua_pcall(m_L, 1, 0, -3);
+}
+
 } // namespace crown

+ 9 - 0
engine/lua/LuaEnvironment.h

@@ -31,6 +31,9 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "Types.h"
 #include "Macros.h"
 
+// HACK
+#include "MathTypes.h"
+
 namespace crown
 {
 
@@ -40,6 +43,9 @@ enum LuaArgumentType
 };
 
 struct LuaResource;
+// HACK
+struct Actor;
+struct Unit;
 
 /// LuaEnvironment is a wrapper of a subset of Lua functions and 
 /// provides utilities for extending Lua
@@ -70,6 +76,9 @@ public:
 	/// Returns true if success, false otherwise
 	void call_global(const char* func, uint8_t argc, ...);
 
+	// HACK
+	void call_physics_callback(Actor* actor_0, Actor* actor_1, Unit* unit_0, Unit* unit_1, const Vector3& where, const Vector3& normal, const char* type);
+
 private:
 
 	// Disable copying