Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.