Browse Source

Expose DetourCrowdManager::GetActiveAgents() to Lua. Closes #728.

Lasse Öörni 10 years ago
parent
commit
082cd11edc

+ 14 - 0
Source/Urho3D/LuaScript/ToluaUtils.cpp

@@ -314,6 +314,20 @@ template<> int ToluaPushPODVector<UIElement*>(lua_State* L, void* data, const ch
     return 1;
     return 1;
 }
 }
 
 
+#ifdef URHO3D_NAVIGATION
+template<> int ToluaPushPODVector<CrowdAgent*>(lua_State* L, void* data, const char*)
+{
+    const PODVector<CrowdAgent*>& vector = *((const PODVector<CrowdAgent*>*)data);
+    lua_newtable(L);
+    for (unsigned i = 0; i < vector.Size(); ++i)
+    {
+        tolua_pushusertype(L, vector[i], "CrowdAgent");
+        lua_rawseti(L, -2, i + 1);
+    }
+    return 1;
+}
+#endif
+
 #ifdef URHO3D_PHYSICS
 #ifdef URHO3D_PHYSICS
 template<> int ToluaPushPODVector<RigidBody*>(lua_State* L, void* data, const char*)
 template<> int ToluaPushPODVector<RigidBody*>(lua_State* L, void* data, const char*)
 {
 {

+ 7 - 0
Source/Urho3D/LuaScript/ToluaUtils.h

@@ -24,6 +24,9 @@
 
 
 #include "../Core/Context.h"
 #include "../Core/Context.h"
 #include "../Graphics/OctreeQuery.h"
 #include "../Graphics/OctreeQuery.h"
+#ifdef URHO3D_NAVIGATION
+#include "../Navigation/CrowdAgent.h"
+#endif
 #ifdef URHO3D_PHYSICS
 #ifdef URHO3D_PHYSICS
 #include "../Physics/PhysicsWorld.h"
 #include "../Physics/PhysicsWorld.h"
 #endif
 #endif
@@ -138,6 +141,10 @@ template<> int ToluaPushPODVector<Vector3>(lua_State* L, void* data, const char*
 template<> int ToluaPushPODVector<IntVector2>(lua_State* L, void* data, const char* type);
 template<> int ToluaPushPODVector<IntVector2>(lua_State* L, void* data, const char* type);
 /// Push PODVector<OctreeQueryResult> to Lua as a table.
 /// Push PODVector<OctreeQueryResult> to Lua as a table.
 template<> int ToluaPushPODVector<OctreeQueryResult>(lua_State* L, void* data, const char* type);
 template<> int ToluaPushPODVector<OctreeQueryResult>(lua_State* L, void* data, const char* type);
+#ifdef URHO3D_NAVIGATION
+/// Push PODVector<CrowdAgent*> to Lua as a table.
+template<> int ToluaPushPODVector<CrowdAgent*>(lua_State* L, void* data, const char* type);
+#endif
 #ifdef URHO3D_PHYSICS
 #ifdef URHO3D_PHYSICS
 /// Push PODVector<PhysicsRaycastResult> to Lua as a table.
 /// Push PODVector<PhysicsRaycastResult> to Lua as a table.
 template<> int ToluaPushPODVector<PhysicsRaycastResult>(lua_State* L, void* data, const char* type);
 template<> int ToluaPushPODVector<PhysicsRaycastResult>(lua_State* L, void* data, const char* type);

+ 12 - 0
Source/Urho3D/LuaScript/pkgs/Navigation/DetourCrowdManager.pkg

@@ -26,7 +26,19 @@ class DetourCrowdManager : public Component
     unsigned GetMaxAgents() const;
     unsigned GetMaxAgents() const;
     float GetAreaCost(unsigned filterID, unsigned areaID) const;
     float GetAreaCost(unsigned filterID, unsigned areaID) const;
     unsigned GetAgentCount() const;
     unsigned GetAgentCount() const;
+    tolua_outside const PODVector<CrowdAgent*>& DetourCrowdManagerGetActiveAgents @ GetActiveAgents();
 
 
     tolua_property__get_set NavigationMesh* navigationMesh;
     tolua_property__get_set NavigationMesh* navigationMesh;
     tolua_property__get_set int maxAgents;
     tolua_property__get_set int maxAgents;
 };
 };
+
+${
+
+static const PODVector<CrowdAgent*>& DetourCrowdManagerGetActiveAgents(DetourCrowdManager* crowdManager)
+{
+    static PODVector<CrowdAgent*> result;
+    result = crowdManager->GetActiveAgents();
+    return result;
+}
+
+$}