Browse Source

Added node-specific CrowdAgent events

Nick Royer 10 years ago
parent
commit
318e0f6552

+ 4 - 4
Source/Urho3D/Navigation/CrowdAgent.cpp

@@ -292,7 +292,7 @@ int CrowdAgent::AddAgentToCrowd(bool force)
             crowdManager_->SendEvent(E_CROWD_AGENT_FAILURE, map);
             crowdManager_->SendEvent(E_CROWD_AGENT_FAILURE, map);
             Node* node = GetNode();
             Node* node = GetNode();
             if (node)
             if (node)
-                node->SendEvent(E_CROWD_AGENT_FAILURE, map);
+                node->SendEvent(E_CROWD_AGENT_NODE_FAILURE, map);
 
 
             // Reevaluate states as handling of event may have resulted in changes
             // Reevaluate states as handling of event may have resulted in changes
             previousAgentState_ = GetAgentState();
             previousAgentState_ = GetAgentState();
@@ -529,7 +529,7 @@ void CrowdAgent::OnCrowdUpdate(dtCrowdAgent* ag, float dt)
             map[P_ARRIVED] = HasArrived();
             map[P_ARRIVED] = HasArrived();
             map[P_TIMESTEP] = dt;
             map[P_TIMESTEP] = dt;
             crowdManager_->SendEvent(E_CROWD_AGENT_REPOSITION, map);
             crowdManager_->SendEvent(E_CROWD_AGENT_REPOSITION, map);
-            node_->SendEvent(E_CROWD_AGENT_REPOSITION, map);
+            node_->SendEvent(E_CROWD_AGENT_NODE_REPOSITION, map);
 
 
             if (updateNodePosition_)
             if (updateNodePosition_)
             {
             {
@@ -554,7 +554,7 @@ void CrowdAgent::OnCrowdUpdate(dtCrowdAgent* ag, float dt)
             map[P_POSITION] = newPos;
             map[P_POSITION] = newPos;
             map[P_VELOCITY] = newVel;
             map[P_VELOCITY] = newVel;
             crowdManager_->SendEvent(E_CROWD_AGENT_STATE_CHANGED, map);
             crowdManager_->SendEvent(E_CROWD_AGENT_STATE_CHANGED, map);
-            node_->SendEvent(E_CROWD_AGENT_STATE_CHANGED, map);
+            node_->SendEvent(E_CROWD_AGENT_NODE_STATE_CHANGED, map);
 
 
             // Send a failure event if either state is a failed status
             // Send a failure event if either state is a failed status
             if (newAgentState == CA_STATE_INVALID || newTargetState == CA_TARGET_FAILED)
             if (newAgentState == CA_STATE_INVALID || newTargetState == CA_TARGET_FAILED)
@@ -567,7 +567,7 @@ void CrowdAgent::OnCrowdUpdate(dtCrowdAgent* ag, float dt)
                 map[P_POSITION] = newPos;
                 map[P_POSITION] = newPos;
                 map[P_VELOCITY] = newVel;
                 map[P_VELOCITY] = newVel;
                 crowdManager_->SendEvent(E_CROWD_AGENT_FAILURE, map);
                 crowdManager_->SendEvent(E_CROWD_AGENT_FAILURE, map);
-                node_->SendEvent(E_CROWD_AGENT_FAILURE, map);
+                node_->SendEvent(E_CROWD_AGENT_NODE_FAILURE, map);
             }
             }
 
 
             // State may have been altered during the handling of the event
             // State may have been altered during the handling of the event

+ 43 - 0
Source/Urho3D/Navigation/NavigationEvents.h

@@ -53,6 +53,16 @@ URHO3D_EVENT(E_CROWD_AGENT_FORMATION, CrowdAgentFormation)
     URHO3D_PARAM(P_POSITION, Position); // Vector3 [in/out]
     URHO3D_PARAM(P_POSITION, Position); // Vector3 [in/out]
 }
 }
 
 
+/// Crowd agent formation specific to a node.
+URHO3D_EVENT(E_CROWD_AGENT_NODE_FORMATION, CrowdAgentNodeFormation)
+{
+    URHO3D_PARAM(P_NODE, Node); // Node pointer
+    URHO3D_PARAM(P_CROWD_AGENT, CrowdAgent); // CrowdAgent pointer
+    URHO3D_PARAM(P_INDEX, Index); // unsigned
+    URHO3D_PARAM(P_SIZE, Size); // unsigned
+    URHO3D_PARAM(P_POSITION, Position); // Vector3 [in/out]
+}
+
 /// Crowd agent has been repositioned.
 /// Crowd agent has been repositioned.
 URHO3D_EVENT(E_CROWD_AGENT_REPOSITION, CrowdAgentReposition)
 URHO3D_EVENT(E_CROWD_AGENT_REPOSITION, CrowdAgentReposition)
 {
 {
@@ -64,6 +74,17 @@ URHO3D_EVENT(E_CROWD_AGENT_REPOSITION, CrowdAgentReposition)
     URHO3D_PARAM(P_TIMESTEP, TimeStep); // float
     URHO3D_PARAM(P_TIMESTEP, TimeStep); // float
 }
 }
 
 
+/// Crowd agent has been repositioned, specific to a node
+URHO3D_EVENT(E_CROWD_AGENT_NODE_REPOSITION, CrowdAgentNodeReposition)
+{
+    URHO3D_PARAM(P_NODE, Node); // Node pointer
+    URHO3D_PARAM(P_CROWD_AGENT, CrowdAgent); // CrowdAgent pointer
+    URHO3D_PARAM(P_POSITION, Position); // Vector3
+    URHO3D_PARAM(P_VELOCITY, Velocity); // Vector3
+    URHO3D_PARAM(P_ARRIVED, Arrived); // bool
+    URHO3D_PARAM(P_TIMESTEP, TimeStep); // float
+}
+
 /// Crowd agent's internal state has become invalidated. This is a special case of CrowdAgentStateChanged event.
 /// Crowd agent's internal state has become invalidated. This is a special case of CrowdAgentStateChanged event.
 URHO3D_EVENT(E_CROWD_AGENT_FAILURE, CrowdAgentFailure)
 URHO3D_EVENT(E_CROWD_AGENT_FAILURE, CrowdAgentFailure)
 {
 {
@@ -75,6 +96,17 @@ URHO3D_EVENT(E_CROWD_AGENT_FAILURE, CrowdAgentFailure)
     URHO3D_PARAM(P_CROWD_TARGET_STATE, CrowdTargetState); // int
     URHO3D_PARAM(P_CROWD_TARGET_STATE, CrowdTargetState); // int
 }
 }
 
 
+/// Crowd agent's internal state has become invalidated. This is a special case of CrowdAgentStateChanged event.
+URHO3D_EVENT(E_CROWD_AGENT_NODE_FAILURE, CrowdAgentNodeFailure)
+{
+    URHO3D_PARAM(P_NODE, Node); // Node pointer
+    URHO3D_PARAM(P_CROWD_AGENT, CrowdAgent); // CrowdAgent pointer
+    URHO3D_PARAM(P_POSITION, Position); // Vector3
+    URHO3D_PARAM(P_VELOCITY, Velocity); // Vector3
+    URHO3D_PARAM(P_CROWD_AGENT_STATE, CrowdAgentState); // int
+    URHO3D_PARAM(P_CROWD_TARGET_STATE, CrowdTargetState); // int
+}
+
 /// Crowd agent's state has been changed.
 /// Crowd agent's state has been changed.
 URHO3D_EVENT(E_CROWD_AGENT_STATE_CHANGED, CrowdAgentStateChanged)
 URHO3D_EVENT(E_CROWD_AGENT_STATE_CHANGED, CrowdAgentStateChanged)
 {
 {
@@ -86,6 +118,17 @@ URHO3D_EVENT(E_CROWD_AGENT_STATE_CHANGED, CrowdAgentStateChanged)
     URHO3D_PARAM(P_CROWD_TARGET_STATE, CrowdTargetState); // int
     URHO3D_PARAM(P_CROWD_TARGET_STATE, CrowdTargetState); // int
 }
 }
 
 
+/// Crowd agent's state has been changed.
+URHO3D_EVENT(E_CROWD_AGENT_NODE_STATE_CHANGED, CrowdAgentNodeStateChanged)
+{
+    URHO3D_PARAM(P_NODE, Node); // Node pointer
+    URHO3D_PARAM(P_CROWD_AGENT, CrowdAgent); // CrowdAgent pointer
+    URHO3D_PARAM(P_POSITION, Position); // Vector3
+    URHO3D_PARAM(P_VELOCITY, Velocity); // Vector3
+    URHO3D_PARAM(P_CROWD_AGENT_STATE, CrowdAgentState); // int
+    URHO3D_PARAM(P_CROWD_TARGET_STATE, CrowdTargetState); // int
+}
+
 /// Addition of obstacle to dynamic navigation mesh.
 /// Addition of obstacle to dynamic navigation mesh.
 URHO3D_EVENT(E_NAVIGATION_OBSTACLE_ADDED, NavigationObstacleAdded)
 URHO3D_EVENT(E_NAVIGATION_OBSTACLE_ADDED, NavigationObstacleAdded)
 {
 {