Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 11167


Ignore:
Timestamp:
Apr 14, 2016, 4:03:16 PM (9 years ago)
Author:
plehmann
Message:

changed the NewScriptController and Task classes

Location:
code/branches/plehmannFS16
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • code/branches/plehmannFS16/data/gui/scripts/testscript.lua

    r11152 r11167  
    1818
    1919-- Get a local pointer to a scriptcontroller
    20 local ctrl = orxonox.ScriptController:getScriptController()
     20local ctrl = orxonox.NewScriptController:getNewScriptController()
    2121
    2222-- If it worked, call its "movetoposition" function
    2323if ctrl ~= nil then
    2424
    25   ctrl:eventScheduler("mal", xl,yl,zl, xl,yl,zl, 10)
     25
     26    ctrl:debugOut()
     27  --ctrl:eventScheduler("mal", xl,yl,zl, xl,yl,zl, 10)
    2628  -- ctrl:eventScheduler("ral", xl, yl, zl, 3, 3000, 0, math.pi)
    2729  -- ctrl:eventScheduler("idle", 1)
  • code/branches/plehmannFS16/src/orxonox/controllers/CMakeLists.txt

    r11165 r11167  
    55  ArtificialController.cc
    66  AIController.cc
    7   ScriptController.cc
     7 
    88  WaypointController.cc
    99  WaypointPatrolController.cc
  • code/branches/plehmannFS16/src/orxonox/controllers/ControllerDirector.cc

    r11071 r11167  
    66
    77#include "ControllerDirector.h"
    8 #include "ScriptController.h"
     8#include "NewScriptController.h"
    99#include "core/CoreIncludes.h"
    1010
     
    6464    {
    6565       /* Output a message confirming that the function was called */
    66        orxout(verbose)<<"test takecontrol."<< endl;
     66       orxout()<<"test takecontrol."<< endl;
    6767
    6868       /* First, we set up a new controller to attach to the unit that
     
    7474       {
    7575         /* Create a scriptcontroller object */
    76          ScriptController *newctrl = new ScriptController(this->context_);
     76         NewScriptController *newctrl = new NewScriptController(this->context_);
    7777
    7878         /* Make the player we were given its slave */
     
    112112        this->player_ = nullptr;
    113113
    114         orxout(verbose) << "Preparation to take Control!" << endl;
     114        orxout() << "Preparation to take Control!" << endl;
    115115
    116116        // Check whether it is a player trigger and extract pawn from it
     
    125125        else
    126126        {
    127             orxout(verbose) << "ControllerDirector::preparationToTakeControl "
     127            orxout() << "ControllerDirector::preparationToTakeControl "
    128128              << "Not a player trigger, can't extract pawn from it.." << endl;
    129129            return false;
  • code/branches/plehmannFS16/src/orxonox/controllers/DebugTask.cc

    r11165 r11167  
    3939    RegisterClass(DebugTask);
    4040
    41     DebugTask::DebugTask() : isRunning_(false)
     41    DebugTask::DebugTask(Context* context) : isRunning_(false)
    4242    {
    4343        RegisterObject(DebugTask);
    4444    }
    45     DebugTask::DebugTask(float startTime) : isRunning_(false)
     45
     46    DebugTask::Tick(float dt)
    4647    {
    47         RegisterObject(DebugTask);
    48         startTime_ = startTime;
     48
     49        orxout() << "*" << endl;
    4950    }
    5051
    51 
    52    
    53 
    5452}
  • code/branches/plehmannFS16/src/orxonox/controllers/DebugTask.h

    r11165 r11167  
    3939    {
    4040        public:
    41             DebugTask();
    42             DebugTask(float startTime)
     41            DebugTask(Context* context);
    4342            virtual ~Task();
     43
     44            //this function needs to be called otherwise the task is never carriedout
     45            initialize()
    4446
    4547            virtual void tick(float dt) override;
  • code/branches/plehmannFS16/src/orxonox/controllers/NewScriptController.cc

    r11165 r11167  
    6161
    6262
    63         /* Set default values for all variables */
    64         /* - pointers to zero */
     63        // Set default values for all variables
     64        // - pointers to zero
    6565        this->player_ = nullptr;
    6666        this->entity_ = nullptr;
    6767
    68         /* - times */
     68        // - times
    6969        this->scTime_ = 0.0f;
     70
     71        //taskList_->push(new DebugTask);
    7072
    7173    }
    7274
     75
     76
    7377    void NewScriptController::takeControl(int ctrlid)
    7478    {
    75         /* Output some debugging information */
     79        // Output some debugging information
    7680        orxout(verbose) << "NewScriptController: Taking control" << endl;
    7781        orxout(verbose) << "This-pointer: " << this << endl;
    7882
    7983
    80         /* Store the entity pointer in a private variable */
     84        // Store the entity pointer in a private variable
    8185        this->entity_ = this->player_->getControllableEntity();
    8286        assert(this->entity_);
     87
     88        this->ctrlid_ = ctrlid;
     89        if (ctrlid_ == 0)
     90        {
     91          ctrlid_ = 1;
     92        }
    8393         
    84         /* Add the controller here to this entity. Apparently this still leaves
    85          * any preexisting human controllers in place.
    86          */
     94        // Add the controller here to this entity. Apparently this still leaves
     95        // any preexisting human controllers in place.
     96         
    8797        this->entity_->setDestroyWhenPlayerLeft(false);
    8898        this->player_->stopTemporaryControl();
     
    98108    void NewScriptController::tick(float dt)
    99109    {
    100         /* Call the tick function of the classes we derive from */
    101         SUPER(ScriptController, tick, dt);
     110        // Call the tick function of the classes we derive from
     111        SUPER(NewScriptController, tick, dt);
    102112
    103         /* If this controller has no entity entry, do nothing */
     113/*
     114        // If this controller has no entity entry, do nothing
    104115        if( !(this->entity_) ) return;
    105116
    106         /* See if time has come for the next event to be run */
     117        // See if time has come for the next event to be run
    107118        if(this->taskList_->size() > 0 && this->taskList_->front().getStartTime() <= scTime_)
    108         { /* Execute the next event on the list */
     119        { // Execute the next event on the list
    109120          activeTasks_->push_back(taskList_->front());
    110121          taskList_->pop();
    111122        }
    112123
    113         /* Update the local timers in this object */
     124        // Update the local timers in this object
    114125        scTime_ += dt;
    115126
    116         /* tick active tasks and delete completed tasks */
     127        // tick active tasks and delete completed tasks
    117128        for(std::vector<Task>::iterator it = activeTasks_->begin(); it != activeTasks_->end(); it++)
    118129        {
     
    125136
    126137        }
    127 
     138*/
    128139    }
    129140
     
    134145    }
    135146
     147    void NewScriptController::debugOut()
     148    {
     149      orxout() << "NewScriptController: Taking control" << endl;
     150    }
     151
     152    NewScriptController* NewScriptController::getNewScriptController()
     153    {
     154      /* Output a message that confirms this function was called */
     155      orxout() << "Great success!" << std::endl;
     156
     157      /* Debugging: print all the scriptcontroller object pointers */
     158      for(NewScriptController* controller : ObjectList<NewScriptController>())
     159      { orxout() << "Have object in list: " << controller << endl; }
     160
     161      /* Find the first one with a nonzero ID */
     162      for(NewScriptController* controller : ObjectList<NewScriptController>())
     163      {
     164        // TODO: do some selection here. Currently just returns the first one
     165        if( controller->getID() > 0 )
     166        { orxout() << "Controller to return: " << controller << endl;
     167          return controller;
     168        }
     169     
     170      }
     171      return nullptr;
     172    }
    136173
    137174}
  • code/branches/plehmannFS16/src/orxonox/controllers/NewScriptController.h

    r11165 r11167  
    5757            // tolua_begin
    5858
     59            void debugOut();
     60
     61            static NewScriptController* getNewScriptController();
     62
     63            int getID() { return ctrlid_; }
     64
     65            //tolua_end
     66
    5967            void createAndAddTask(Task newTask);
    6068
    6169        private:
    62             /* Information about the player that this ScriptController will
    63              * control */
    64             /* - Player pointer */
     70            // Information about the player that this ScriptController will
     71            // control
     72            // - Player pointer
    6573            PlayerInfo* player_;
    6674
    67             /* - Entity pointer, this is for convenience and will be the same as
    68              *   player_->getControllableEntity()
    69              */
     75            // - Entity pointer, this is for convenience and will be the same as
     76            //   player_->getControllableEntity()
    7077            ControllableEntity* entity_;
    7178
    72             /* List of events to walk through */
     79            // Controller ID, defaults to 0 and is set using takeControl()
     80            int ctrlid_;
     81
     82            // List of events to walk through
    7383            std::queue<Task>* taskList_;
    7484
    7585
    76             /*List of Tasks currently active */
     86            //List of Tasks currently active
    7787            std::vector<Task>* activeTasks_;
    7888
    79             /* Time since the creation of this ScriptController object */
     89            // Time since the creation of this ScriptController object
    8090            float scTime_; 
    8191
  • code/branches/plehmannFS16/src/orxonox/controllers/ScriptController.h

    r11152 r11167  
    3636
    3737
    38 namespace orxonox  // tolua_export
    39 // tolua_export
     38namespace orxonox 
     39
    4040
    4141    /** Structure to describe a single event */
     
    6161    };
    6262
    63     class _OrxonoxExport ScriptController // tolua_export
     63    class _OrxonoxExport ScriptController
    6464       : public ArtificialController, public Tickable
    65     {  // tolua_export
     65    { 
    6666        public:
    6767            ScriptController(Context* context);
     
    7373            virtual void tick(float dt) override;
    7474
    75             // LUA interface
    76             // tolua_begin
     75           
    7776            void eventScheduler(std::string instruction = "",
    7877              float x1 = 0, float y1 = 0, float z1 = 0,
     
    8483            int getID() { return ctrlid_; }
    8584
    86             // tolua_end
     85           
    8786            const Vector3& getPosition();
    8887
     
    146145            void rotX(float dl);
    147146
    148     };// tolua_export
    149 } // tolua_export
     147    };
     148}
    150149
    151150#endif /* _ScriptController_H__ */
  • code/branches/plehmannFS16/src/orxonox/controllers/Task.cc

    r11165 r11167  
    3131
    3232#include "infos/PlayerInfo.h"
    33 #include "controllers/ArtificialController.h"
     33//#include "controllers/ArtificialController.h"
    3434#include "tools/interfaces/Tickable.h"
    3535
     
    3939    RegisterClass(Task);
    4040
    41     Task::Task() : isRunning_(false)
     41    Task::Task(Context* context) : isRunning_(false)
    4242    {
    4343        RegisterObject(Task);
     44        startTime_ = -1;
     45    }
     46    Task::~Task()
     47    {
     48
     49    }
     50/*
     51    Task::initialize(float startTime)
     52    {
     53        startTime_ = startTime;
     54    }
     55*/
     56    void Task::tick(float dt)
     57    {
     58
    4459    }
    4560
    46    
    47 
    4861}
  • code/branches/plehmannFS16/src/orxonox/controllers/Task.h

    r11165 r11167  
    3131
    3232#include "infos/PlayerInfo.h"
    33 #include "controllers/ArtificialController.h"
     33//#include "controllers/ArtificialController.h"
    3434#include "tools/interfaces/Tickable.h"
    3535
     
    3939    {
    4040        public:
    41             Task();
     41            Task(Context* context);
    4242            virtual ~Task();
     43
     44            //this function needs to be called otherwise the task is never carriedout
     45            //initialize();
    4346
    4447            virtual void tick(float dt) override;
Note: See TracChangeset for help on using the changeset viewer.