[Orxonox-commit 5385] r10048 - in code/branches/ScriptableController: data/gui/scripts src/orxonox/controllers

samuezu at orxonox.net samuezu at orxonox.net
Thu May 8 15:59:26 CEST 2014


Author: samuezu
Date: 2014-05-08 15:59:26 +0200 (Thu, 08 May 2014)
New Revision: 10048

Modified:
   code/branches/ScriptableController/data/gui/scripts/testscript.lua
   code/branches/ScriptableController/src/orxonox/controllers/ScriptController.cc
   code/branches/ScriptableController/src/orxonox/controllers/ScriptController.h
Log:
created struct event, an eventlist and the functions eventscheduler and execute, modified tick function

Modified: code/branches/ScriptableController/data/gui/scripts/testscript.lua
===================================================================
--- code/branches/ScriptableController/data/gui/scripts/testscript.lua	2014-05-08 08:16:23 UTC (rev 10047)
+++ code/branches/ScriptableController/data/gui/scripts/testscript.lua	2014-05-08 13:59:26 UTC (rev 10048)
@@ -14,7 +14,7 @@
 
 -- If it worked, call its "movetoposition" function
 if ctrl ~= nil then
-  ctrl:moveToPosition_beta(x, y, z)
+  ctrl:eventScheduler("moveToPosition_beta", x, y, z, 5)
 end
 
 -- Output the newctrlid variable we set from the C++ code

Modified: code/branches/ScriptableController/src/orxonox/controllers/ScriptController.cc
===================================================================
--- code/branches/ScriptableController/src/orxonox/controllers/ScriptController.cc	2014-05-08 08:16:23 UTC (rev 10047)
+++ code/branches/ScriptableController/src/orxonox/controllers/ScriptController.cc	2014-05-08 13:59:26 UTC (rev 10048)
@@ -35,6 +35,16 @@
 
 namespace orxonox
 {
+    float scTime=0;  /*initialise time, to coordinate eventTime*/
+
+
+
+    std::vector<event> eventList;
+
+    
+
+
+
     RegisterClass(ScriptController);
 
     //ScriptController::ScriptController(Context* context, ControllableEntity* CE) : ArtificialController(context)
@@ -102,6 +112,15 @@
       return NULL;
     }
 
+    void ScriptController::execute(event ev)
+    {
+        if(ev.fctName=="moveToPosition_beta")
+        {
+            moveToPosition_beta(ev.xCoord,ev.yCoord,ev.zCoord);
+        }
+    }
+
+
     void ScriptController::tick(float dt)
     {
         /* If this controller has no entity entry, do nothing */
@@ -113,10 +132,22 @@
         //this->entity_->rotateYaw(-1.0f * 100.0f * dt);
         //this->entity_->rotatePitch(0.8f * 100.0f);
 
+        if(eventList[0].eventTime<=scTime)
+        {
+            /*TO DO: execute the function: eventList[0].fctName*/
+
+
+            eventList.erase(eventList.begin());
+        }
+
         SUPER(ScriptController, tick, dt);
+
+        scTime=scTime+dt;
     }
 
 
+
+
     void ScriptController::moveToPosition_beta(float x, float y, float z )
     {
         //const Vector3 local = this->getPosition();
@@ -133,14 +164,45 @@
         orxout()<<x<<"  "<<y<<"  "<<z<<endl;
     }
 
+    void ScriptController::eventScheduler(std::string instruction, float x, float y, float z, float executionTime)
+    {
+        /*put data (from LUA) into time-sorted eventList*/ 
+        /*nimmt den befehl und die argumente aus luascript und ertellt einen struct pro event, diese structs werden sortiert nach eventTime*/
+        struct event tmp;
+        tmp.fctName=instruction;
+        tmp.xCoord=x;
+        tmp.yCoord=y;
+        tmp.zCoord=z;
+        tmp.eventTime=executionTime;
 
-    /* TODO:    hilfs(zwischen)funktionen um lua eingabe zu ermoeglichen: zb moveToPosition(float...) weil in LUA wohl 
-                kein vektor3 definierbar ist
+        for(unsigned int i=0;i<eventList.size();i++)
+        {
+            if(tmp.eventTime<eventList[i].eventTime)
+            {
+                std::vector<event>::iterator it = eventList.begin();
 
-                NB: viele noetige funktionen sind schon in artificial- bzw formationcontroller vorhanden 
+                eventList.insert(it+(i+1),tmp);
+                break;
+            }
+            if(i==eventList.size()-1)
+            {
+                std::vector<event>::iterator it = eventList.end();
 
-                tick funktion?*/        
+                eventList.insert(it,tmp);
 
+            }
 
+        }
+        
+    }
 
+
+
+    /* TODO:    struct event erweitern um mehr funktionen benutzen zu koennen
+
+                mehr funktionen definieren (und dann in  execute if(...))
+                NB: viele noetige funktionen sind schon in artificial- bzw formationcontroller vorhanden */        
+
+
+
 }

Modified: code/branches/ScriptableController/src/orxonox/controllers/ScriptController.h
===================================================================
--- code/branches/ScriptableController/src/orxonox/controllers/ScriptController.h	2014-05-08 08:16:23 UTC (rev 10047)
+++ code/branches/ScriptableController/src/orxonox/controllers/ScriptController.h	2014-05-08 13:59:26 UTC (rev 10048)
@@ -34,8 +34,21 @@
 #include "core/EventIncludes.h"
 
 
+
 namespace orxonox  // tolua_export
 {  // tolua_export
+
+    struct event 
+    {   
+        std::string fctName;
+        float xCoord;
+        float yCoord;
+        float zCoord;
+
+        float eventTime;
+
+    }; 
+
     class _OrxonoxExport ScriptController // tolua_export 
        : public ArtificialController, public Tickable
     {  // tolua_export
@@ -59,7 +72,8 @@
             // tolua_begin 
             void moveToPosition_beta(float x, float y, float z);
 
-           
+            void eventScheduler(std::string instruction, float x, float y, float z, float time);
+
             static ScriptController* getScriptController();
 
             int getID() { return ctrlid_; }
@@ -68,6 +82,8 @@
             // tolua_end
             const Vector3& getPosition();
 
+            void execute(event ev);
+
         private:
             // name of the LUA-sourcefile that shall be executed->see XMLPort-function
             std::string luasrc;		




More information about the Orxonox-commit mailing list