Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10048


Ignore:
Timestamp:
May 8, 2014, 3:59:26 PM (10 years ago)
Author:
samuezu
Message:

created struct event, an eventlist and the functions eventscheduler and execute, modified tick function

Location:
code/branches/ScriptableController
Files:
3 edited

Legend:

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

    r10047 r10048  
    1515-- If it worked, call its "movetoposition" function
    1616if ctrl ~= nil then
    17   ctrl:moveToPosition_beta(x, y, z)
     17  ctrl:eventScheduler("moveToPosition_beta", x, y, z, 5)
    1818end
    1919
  • code/branches/ScriptableController/src/orxonox/controllers/ScriptController.cc

    r10047 r10048  
    3636namespace orxonox
    3737{
     38    float scTime=0;  /*initialise time, to coordinate eventTime*/
     39
     40
     41
     42    std::vector<event> eventList;
     43
     44   
     45
     46
     47
    3848    RegisterClass(ScriptController);
    3949
     
    103113    }
    104114
     115    void ScriptController::execute(event ev)
     116    {
     117        if(ev.fctName=="moveToPosition_beta")
     118        {
     119            moveToPosition_beta(ev.xCoord,ev.yCoord,ev.zCoord);
     120        }
     121    }
     122
     123
    105124    void ScriptController::tick(float dt)
    106125    {
     
    114133        //this->entity_->rotatePitch(0.8f * 100.0f);
    115134
     135        if(eventList[0].eventTime<=scTime)
     136        {
     137            /*TO DO: execute the function: eventList[0].fctName*/
     138
     139
     140            eventList.erase(eventList.begin());
     141        }
     142
    116143        SUPER(ScriptController, tick, dt);
    117     }
     144
     145        scTime=scTime+dt;
     146    }
     147
     148
    118149
    119150
     
    134165    }
    135166
    136 
    137     /* TODO:    hilfs(zwischen)funktionen um lua eingabe zu ermoeglichen: zb moveToPosition(float...) weil in LUA wohl
    138                 kein vektor3 definierbar ist
    139 
    140                 NB: viele noetige funktionen sind schon in artificial- bzw formationcontroller vorhanden
    141 
    142                 tick funktion?*/       
     167    void ScriptController::eventScheduler(std::string instruction, float x, float y, float z, float executionTime)
     168    {
     169        /*put data (from LUA) into time-sorted eventList*/
     170        /*nimmt den befehl und die argumente aus luascript und ertellt einen struct pro event, diese structs werden sortiert nach eventTime*/
     171        struct event tmp;
     172        tmp.fctName=instruction;
     173        tmp.xCoord=x;
     174        tmp.yCoord=y;
     175        tmp.zCoord=z;
     176        tmp.eventTime=executionTime;
     177
     178        for(unsigned int i=0;i<eventList.size();i++)
     179        {
     180            if(tmp.eventTime<eventList[i].eventTime)
     181            {
     182                std::vector<event>::iterator it = eventList.begin();
     183
     184                eventList.insert(it+(i+1),tmp);
     185                break;
     186            }
     187            if(i==eventList.size()-1)
     188            {
     189                std::vector<event>::iterator it = eventList.end();
     190
     191                eventList.insert(it,tmp);
     192
     193            }
     194
     195        }
     196       
     197    }
     198
     199
     200
     201    /* TODO:    struct event erweitern um mehr funktionen benutzen zu koennen
     202
     203                mehr funktionen definieren (und dann in  execute if(...))
     204                NB: viele noetige funktionen sind schon in artificial- bzw formationcontroller vorhanden */       
    143205
    144206
  • code/branches/ScriptableController/src/orxonox/controllers/ScriptController.h

    r10047 r10048  
    3535
    3636
     37
    3738namespace orxonox  // tolua_export
    3839{  // tolua_export
     40
     41    struct event
     42    {   
     43        std::string fctName;
     44        float xCoord;
     45        float yCoord;
     46        float zCoord;
     47
     48        float eventTime;
     49
     50    };
     51
    3952    class _OrxonoxExport ScriptController // tolua_export
    4053       : public ArtificialController, public Tickable
     
    6073            void moveToPosition_beta(float x, float y, float z);
    6174
    62            
     75            void eventScheduler(std::string instruction, float x, float y, float z, float time);
     76
    6377            static ScriptController* getScriptController();
    6478
     
    6882            // tolua_end
    6983            const Vector3& getPosition();
     84
     85            void execute(event ev);
    7086
    7187        private:
Note: See TracChangeset for help on using the changeset viewer.