Browse Source

Added script targets to AIAgent and AIState to support Lua script callback functions for the listener interfaces.

Chris Culy 13 years ago
parent
commit
2a0e8784fc
4 changed files with 14 additions and 6 deletions
  1. 4 1
      gameplay/src/AIAgent.cpp
  2. 2 1
      gameplay/src/AIAgent.h
  3. 6 3
      gameplay/src/AIState.cpp
  4. 2 1
      gameplay/src/AIState.h

+ 4 - 1
gameplay/src/AIAgent.cpp

@@ -9,6 +9,8 @@ AIAgent::AIAgent()
     : _stateMachine(NULL), _node(NULL), _enabled(true), _next(NULL)
 {
     _stateMachine = new AIStateMachine(this);
+
+    addEvent("message", "<AIMessage>");
 }
 
 AIAgent::~AIAgent()
@@ -82,7 +84,8 @@ bool AIAgent::processMessage(AIMessage* message)
     if (_listener && _listener->messageReceived(message))
         return true;
     
-    // TODO: Fire script listener
+    if (fireEvent<bool>("message", message))
+        return true;
     
     return false;
 }

+ 2 - 1
gameplay/src/AIAgent.h

@@ -4,6 +4,7 @@
 #include "Ref.h"
 #include "AIStateMachine.h"
 #include "AIMessage.h"
+#include "ScriptTarget.h"
 
 namespace gameplay
 {
@@ -18,7 +19,7 @@ class Node;
  * such as state machines. By default, an AIAgent has an empty state 
  * machine.
  */
-class AIAgent : public Ref
+class AIAgent : public Ref, public ScriptTarget
 {
     friend class Node;
     friend class AIController;

+ 6 - 3
gameplay/src/AIState.cpp

@@ -10,6 +10,9 @@ AIState* AIState::_empty = NULL;
 AIState::AIState(const char* id)
     : _id(id), _listener(NULL)
 {
+    addEvent("enter", "<AIAgent><AIState>");
+    addEvent("exit", "<AIAgent><AIState>");
+    addEvent("update", "<AIAgent><AIState>f");
 }
 
 AIState::~AIState()
@@ -36,7 +39,7 @@ void AIState::enter(AIStateMachine* stateMachine)
     if (_listener)
         _listener->stateEnter(stateMachine->getAgent(), this);
 
-    // TODO: Fire script event
+    fireEvent<void>("enter", stateMachine->getAgent(), this);
 }
 
 void AIState::exit(AIStateMachine* stateMachine)
@@ -44,7 +47,7 @@ void AIState::exit(AIStateMachine* stateMachine)
     if (_listener)
         _listener->stateExit(stateMachine->getAgent(), this);
 
-    // TODO: Fire script event
+    fireEvent<void>("exit", stateMachine->getAgent(), this);
 }
 
 void AIState::update(AIStateMachine* stateMachine, float elapsedTime)
@@ -52,7 +55,7 @@ void AIState::update(AIStateMachine* stateMachine, float elapsedTime)
     if (_listener)
         _listener->stateUpdate(stateMachine->getAgent(), this, elapsedTime);
 
-    // TODO: Fire script event
+    fireEvent<void>("update", stateMachine->getAgent(), this);
 }
 
 AIState::Listener::~Listener()

+ 2 - 1
gameplay/src/AIState.h

@@ -2,6 +2,7 @@
 #define AISTATE_H_
 
 #include "Ref.h"
+#include "ScriptTarget.h"
 
 namespace gameplay
 {
@@ -18,7 +19,7 @@ class AIStateMachine;
  *
  * 
  */
-class AIState : public Ref
+class AIState : public Ref, public ScriptTarget
 {
     friend class AIStateMachine;