[Orxonox-commit 6524] r11167 - in code/branches/plehmannFS16: data/gui/scripts src/orxonox/controllers

plehmann at orxonox.net plehmann at orxonox.net
Thu Apr 14 16:03:16 CEST 2016


Author: plehmann
Date: 2016-04-14 16:03:16 +0200 (Thu, 14 Apr 2016)
New Revision: 11167

Modified:
   code/branches/plehmannFS16/data/gui/scripts/testscript.lua
   code/branches/plehmannFS16/src/orxonox/controllers/CMakeLists.txt
   code/branches/plehmannFS16/src/orxonox/controllers/ControllerDirector.cc
   code/branches/plehmannFS16/src/orxonox/controllers/DebugTask.cc
   code/branches/plehmannFS16/src/orxonox/controllers/DebugTask.h
   code/branches/plehmannFS16/src/orxonox/controllers/NewScriptController.cc
   code/branches/plehmannFS16/src/orxonox/controllers/NewScriptController.h
   code/branches/plehmannFS16/src/orxonox/controllers/ScriptController.h
   code/branches/plehmannFS16/src/orxonox/controllers/Task.cc
   code/branches/plehmannFS16/src/orxonox/controllers/Task.h
Log:
changed the NewScriptController and Task classes

Modified: code/branches/plehmannFS16/data/gui/scripts/testscript.lua
===================================================================
--- code/branches/plehmannFS16/data/gui/scripts/testscript.lua	2016-04-14 14:02:00 UTC (rev 11166)
+++ code/branches/plehmannFS16/data/gui/scripts/testscript.lua	2016-04-14 14:03:16 UTC (rev 11167)
@@ -17,12 +17,14 @@
 pi = 3.1415
 
 -- Get a local pointer to a scriptcontroller
-local ctrl = orxonox.ScriptController:getScriptController()
+local ctrl = orxonox.NewScriptController:getNewScriptController()
 
 -- If it worked, call its "movetoposition" function
 if ctrl ~= nil then
 
-  ctrl:eventScheduler("mal", xl,yl,zl, xl,yl,zl, 10)
+
+    ctrl:debugOut()
+  --ctrl:eventScheduler("mal", xl,yl,zl, xl,yl,zl, 10)
   -- ctrl:eventScheduler("ral", xl, yl, zl, 3, 3000, 0, math.pi)
   -- ctrl:eventScheduler("idle", 1)
   -- ctrl:eventScheduler("mal", 0,0,1000, xl,yl,zl, 3)

Modified: code/branches/plehmannFS16/src/orxonox/controllers/CMakeLists.txt
===================================================================
--- code/branches/plehmannFS16/src/orxonox/controllers/CMakeLists.txt	2016-04-14 14:02:00 UTC (rev 11166)
+++ code/branches/plehmannFS16/src/orxonox/controllers/CMakeLists.txt	2016-04-14 14:03:16 UTC (rev 11167)
@@ -4,7 +4,7 @@
   NewHumanController.cc
   ArtificialController.cc
   AIController.cc
-  ScriptController.cc
+  
   WaypointController.cc
   WaypointPatrolController.cc
   DroneController.cc

Modified: code/branches/plehmannFS16/src/orxonox/controllers/ControllerDirector.cc
===================================================================
--- code/branches/plehmannFS16/src/orxonox/controllers/ControllerDirector.cc	2016-04-14 14:02:00 UTC (rev 11166)
+++ code/branches/plehmannFS16/src/orxonox/controllers/ControllerDirector.cc	2016-04-14 14:03:16 UTC (rev 11167)
@@ -5,7 +5,7 @@
  */
 
 #include "ControllerDirector.h"
-#include "ScriptController.h"
+#include "NewScriptController.h"
 #include "core/CoreIncludes.h"
 
 //#include "network/NetworkFunction.h"
@@ -63,7 +63,7 @@
     void ControllerDirector::takeControl(Controller * controller, BaseObject * trigger) 
     {
        /* Output a message confirming that the function was called */
-       orxout(verbose)<<"test takecontrol."<< endl;
+       orxout()<<"test takecontrol."<< endl;
 
        /* First, we set up a new controller to attach to the unit that
         * triggered our event. 
@@ -73,7 +73,7 @@
        if( prepok == true) 
        {
          /* Create a scriptcontroller object */
-         ScriptController *newctrl = new ScriptController(this->context_);
+         NewScriptController *newctrl = new NewScriptController(this->context_);
 
          /* Make the player we were given its slave */
          newctrl->setPlayer(this->player_);
@@ -111,7 +111,7 @@
         this->pTrigger_ = orxonox_cast<PlayerTrigger*>(trigger);
         this->player_ = nullptr;
 
-        orxout(verbose) << "Preparation to take Control!" << endl; 
+        orxout() << "Preparation to take Control!" << endl; 
 
         // Check whether it is a player trigger and extract pawn from it
         if(this->pTrigger_ != nullptr)
@@ -124,7 +124,7 @@
         }
         else
         {
-            orxout(verbose) << "ControllerDirector::preparationToTakeControl " 
+            orxout() << "ControllerDirector::preparationToTakeControl " 
               << "Not a player trigger, can't extract pawn from it.." << endl;
             return false;
         }

Modified: code/branches/plehmannFS16/src/orxonox/controllers/DebugTask.cc
===================================================================
--- code/branches/plehmannFS16/src/orxonox/controllers/DebugTask.cc	2016-04-14 14:02:00 UTC (rev 11166)
+++ code/branches/plehmannFS16/src/orxonox/controllers/DebugTask.cc	2016-04-14 14:03:16 UTC (rev 11167)
@@ -38,17 +38,15 @@
    
     RegisterClass(DebugTask);
 
-    DebugTask::DebugTask() : isRunning_(false)
+    DebugTask::DebugTask(Context* context) : isRunning_(false)
     {
         RegisterObject(DebugTask);
     }
-    DebugTask::DebugTask(float startTime) : isRunning_(false)
+
+    DebugTask::Tick(float dt)
     {
-        RegisterObject(DebugTask);
-        startTime_ = startTime;
+
+    	orxout() << "*" << endl;
     }
 
-
-    
-
 }
\ No newline at end of file

Modified: code/branches/plehmannFS16/src/orxonox/controllers/DebugTask.h
===================================================================
--- code/branches/plehmannFS16/src/orxonox/controllers/DebugTask.h	2016-04-14 14:02:00 UTC (rev 11166)
+++ code/branches/plehmannFS16/src/orxonox/controllers/DebugTask.h	2016-04-14 14:03:16 UTC (rev 11167)
@@ -38,10 +38,12 @@
     class _OrxonoxExport Task : public Task
     {
         public:
-            DebugTask();
-            DebugTask(float startTime)
+            DebugTask(Context* context);
             virtual ~Task();
 
+            //this function needs to be called otherwise the task is never carriedout
+            initialize()
+
             virtual void tick(float dt) override;
 
         private:

Modified: code/branches/plehmannFS16/src/orxonox/controllers/NewScriptController.cc
===================================================================
--- code/branches/plehmannFS16/src/orxonox/controllers/NewScriptController.cc	2016-04-14 14:02:00 UTC (rev 11166)
+++ code/branches/plehmannFS16/src/orxonox/controllers/NewScriptController.cc	2016-04-14 14:03:16 UTC (rev 11167)
@@ -60,30 +60,40 @@
         RegisterObject(NewScriptController);
 
 
-        /* Set default values for all variables */
-        /* - pointers to zero */
+        // Set default values for all variables 
+        // - pointers to zero 
         this->player_ = nullptr;
         this->entity_ = nullptr;
 
-        /* - times */
+        // - times
         this->scTime_ = 0.0f;
 
+        //taskList_->push(new DebugTask);
+
     }
 
+
+
     void NewScriptController::takeControl(int ctrlid)
     {
-        /* Output some debugging information */
+        // Output some debugging information 
         orxout(verbose) << "NewScriptController: Taking control" << endl;
         orxout(verbose) << "This-pointer: " << this << endl; 
 
 
-        /* Store the entity pointer in a private variable */
+        // Store the entity pointer in a private variable
         this->entity_ = this->player_->getControllableEntity();
         assert(this->entity_);
+
+        this->ctrlid_ = ctrlid;
+        if (ctrlid_ == 0)
+        {
+          ctrlid_ = 1;
+        }
          
-        /* Add the controller here to this entity. Apparently this still leaves
-         * any preexisting human controllers in place. 
-         */
+        // Add the controller here to this entity. Apparently this still leaves
+        // any preexisting human controllers in place. 
+         
         this->entity_->setDestroyWhenPlayerLeft(false);
         this->player_->stopTemporaryControl();
         this->entity_->setController(this);
@@ -97,23 +107,24 @@
 
     void NewScriptController::tick(float dt)
     {
-        /* Call the tick function of the classes we derive from */
-        SUPER(ScriptController, tick, dt);
+        // Call the tick function of the classes we derive from 
+        SUPER(NewScriptController, tick, dt);
 
-        /* If this controller has no entity entry, do nothing */
+/*
+        // If this controller has no entity entry, do nothing 
         if( !(this->entity_) ) return;
 
-        /* See if time has come for the next event to be run */
+        // See if time has come for the next event to be run 
         if(this->taskList_->size() > 0 && this->taskList_->front().getStartTime() <= scTime_)
-        { /* Execute the next event on the list */
+        { // Execute the next event on the list 
           activeTasks_->push_back(taskList_->front());
           taskList_->pop();
         }
 
-        /* Update the local timers in this object */
+        // Update the local timers in this object 
         scTime_ += dt;
 
-        /* tick active tasks and delete completed tasks */
+        // tick active tasks and delete completed tasks 
         for(std::vector<Task>::iterator it = activeTasks_->begin(); it != activeTasks_->end(); it++)
         {
           it->tick(dt);
@@ -124,7 +135,7 @@
           }
 
         }
-
+*/
     }
 
 
@@ -133,5 +144,31 @@
       taskList_->push(newTask);
     }
 
+    void NewScriptController::debugOut()
+    {
+      orxout() << "NewScriptController: Taking control" << endl;
+    }
 
+    NewScriptController* NewScriptController::getNewScriptController()
+    {
+      /* Output a message that confirms this function was called */
+      orxout() << "Great success!" << std::endl;
+
+      /* Debugging: print all the scriptcontroller object pointers */
+      for(NewScriptController* controller : ObjectList<NewScriptController>())
+      { orxout() << "Have object in list: " << controller << endl; }
+
+      /* Find the first one with a nonzero ID */
+      for(NewScriptController* controller : ObjectList<NewScriptController>())
+      { 
+        // TODO: do some selection here. Currently just returns the first one
+        if( controller->getID() > 0 )
+        { orxout() << "Controller to return: " << controller << endl;
+          return controller;
+        }
+      
+      }
+      return nullptr;
+    }
+
 }

Modified: code/branches/plehmannFS16/src/orxonox/controllers/NewScriptController.h
===================================================================
--- code/branches/plehmannFS16/src/orxonox/controllers/NewScriptController.h	2016-04-14 14:02:00 UTC (rev 11166)
+++ code/branches/plehmannFS16/src/orxonox/controllers/NewScriptController.h	2016-04-14 14:03:16 UTC (rev 11167)
@@ -56,27 +56,37 @@
             // LUA interface
             // tolua_begin 
 
+            void debugOut();
+
+            static NewScriptController* getNewScriptController();
+
+            int getID() { return ctrlid_; }
+
+            //tolua_end
+
             void createAndAddTask(Task newTask);
 
         private:
-            /* Information about the player that this ScriptController will
-             * control */
-            /* - Player pointer */
+            // Information about the player that this ScriptController will
+            // control 
+            // - Player pointer 
             PlayerInfo* player_;
 
-            /* - Entity pointer, this is for convenience and will be the same as 
-             *   player_->getControllableEntity() 
-             */
+            // - Entity pointer, this is for convenience and will be the same as 
+            //   player_->getControllableEntity() 
             ControllableEntity* entity_;
 
-            /* List of events to walk through */
+            // Controller ID, defaults to 0 and is set using takeControl() 
+            int ctrlid_;
+
+            // List of events to walk through 
             std::queue<Task>* taskList_;
 
 
-            /*List of Tasks currently active */
+            //List of Tasks currently active 
             std::vector<Task>* activeTasks_;
 
-            /* Time since the creation of this ScriptController object */
+            // Time since the creation of this ScriptController object
             float scTime_;  
 
 

Modified: code/branches/plehmannFS16/src/orxonox/controllers/ScriptController.h
===================================================================
--- code/branches/plehmannFS16/src/orxonox/controllers/ScriptController.h	2016-04-14 14:02:00 UTC (rev 11166)
+++ code/branches/plehmannFS16/src/orxonox/controllers/ScriptController.h	2016-04-14 14:03:16 UTC (rev 11167)
@@ -35,8 +35,8 @@
 
 
 
-namespace orxonox  // tolua_export
-{  // tolua_export
+namespace orxonox  
+{  
 
     /** Structure to describe a single event */
     struct event 
@@ -60,9 +60,9 @@
         float eventTime;
     }; 
 
-    class _OrxonoxExport ScriptController // tolua_export 
+    class _OrxonoxExport ScriptController  
        : public ArtificialController, public Tickable
-    {  // tolua_export
+    {  
         public:
             ScriptController(Context* context);
             virtual ~ScriptController() { }
@@ -72,8 +72,7 @@
            
             virtual void tick(float dt) override;
 
-            // LUA interface
-            // tolua_begin 
+           
             void eventScheduler(std::string instruction = "", 
               float x1 = 0, float y1 = 0, float z1 = 0, 
               float x2 = 0, float y2 = 0, float z2 = 0, 
@@ -83,7 +82,7 @@
 
             int getID() { return ctrlid_; }
 
-            // tolua_end
+           
             const Vector3& getPosition();
 
             void execute(event ev);
@@ -145,7 +144,7 @@
             /* rotate around x-coordinate event */
             void rotX(float dl);
 
-    };// tolua_export
-} // tolua_export
+    };
+} 
 
 #endif /* _ScriptController_H__ */

Modified: code/branches/plehmannFS16/src/orxonox/controllers/Task.cc
===================================================================
--- code/branches/plehmannFS16/src/orxonox/controllers/Task.cc	2016-04-14 14:02:00 UTC (rev 11166)
+++ code/branches/plehmannFS16/src/orxonox/controllers/Task.cc	2016-04-14 14:03:16 UTC (rev 11167)
@@ -30,7 +30,7 @@
 #include "Task.h"
 
 #include "infos/PlayerInfo.h"
-#include "controllers/ArtificialController.h"
+//#include "controllers/ArtificialController.h"
 #include "tools/interfaces/Tickable.h"
 
 namespace orxonox
@@ -38,11 +38,24 @@
    
     RegisterClass(Task);
 
-    Task::Task() : isRunning_(false)
+    Task::Task(Context* context) : isRunning_(false)
     {
         RegisterObject(Task);
+        startTime_ = -1;
     }
+    Task::~Task()
+    {
 
-    
+    }
+/*
+    Task::initialize(float startTime)
+    {
+    	startTime_ = startTime;
+    }
+*/
+    void Task::tick(float dt)
+    {
 
+    }
+
 }
\ No newline at end of file

Modified: code/branches/plehmannFS16/src/orxonox/controllers/Task.h
===================================================================
--- code/branches/plehmannFS16/src/orxonox/controllers/Task.h	2016-04-14 14:02:00 UTC (rev 11166)
+++ code/branches/plehmannFS16/src/orxonox/controllers/Task.h	2016-04-14 14:03:16 UTC (rev 11167)
@@ -30,7 +30,7 @@
 #define _Task_H__
 
 #include "infos/PlayerInfo.h"
-#include "controllers/ArtificialController.h"
+//#include "controllers/ArtificialController.h"
 #include "tools/interfaces/Tickable.h"
 
 namespace orxonox
@@ -38,9 +38,12 @@
     class _OrxonoxExport Task : public Tickable
     {
         public:
-            Task();
+            Task(Context* context);
             virtual ~Task();
 
+            //this function needs to be called otherwise the task is never carriedout
+            //initialize();
+
             virtual void tick(float dt) override;
 
             void setIsRunning(bool shouldBeRunning)




More information about the Orxonox-commit mailing list