Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 11207


Ignore:
Timestamp:
May 26, 2016, 4:38:51 PM (8 years ago)
Author:
fvultier
Message:

merged scriptable controller

Location:
code/branches/presentationFS16
Files:
10 edited
3 copied

Legend:

Unmodified
Added
Removed
  • code/branches/presentationFS16

  • code/branches/presentationFS16/data/gui/scripts/testscript.lua

    r10622 r11207  
    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, 2)
    26   ctrl:eventScheduler("idle", 1)
    27   ctrl:eventScheduler("ral", xl, yl, zl, 3, 3000, 0, math.pi)
    28   ctrl:eventScheduler("idle", 1)
    29   ctrl:eventScheduler("mal", 0,0,1000, xl,yl,zl, 3)
    30   ctrl:eventScheduler("idle", 1)
    31   ctrl:eventScheduler("chl", xl, yl, zl, xr, yr, zr, 2)
    32   ctrl:eventScheduler("idle", 1)
    33   ctrl:eventScheduler("mal", xr + 600,yr,zr, xr,yr,zr, 4)
    34   ctrl:eventScheduler("idle", 1)
    35   ctrl:eventScheduler("chl", xr, yr, zr, xl, yl, zl, 3)
    36   ctrl:eventScheduler("idle", 1)
    37   ctrl:eventScheduler("spi", xm,ym,zm, 0,0,0, 4)
    38   ctrl:eventScheduler("idle", 1)
     25  ctrl:moveTo(1, 0, 0, 100, 200)
     26  ctrl:moveTo(20, 0, 0, 100, 200)
     27  ctrl:moveTo(40, 0, 100, 0, 200)
     28  --ctrl:eventScheduler("mal", xl,yl,zl, xl,yl,zl, 10)
     29  -- ctrl:eventScheduler("ral", xl, yl, zl, 3, 3000, 0, math.pi)
     30  -- ctrl:eventScheduler("idle", 1)
     31  -- ctrl:eventScheduler("mal", 0,0,1000, xl,yl,zl, 3)
     32  -- ctrl:eventScheduler("idle", 1)
     33  -- ctrl:eventScheduler("chl", xl, yl, zl, xr, yr, zr, 2)
     34  -- ctrl:eventScheduler("idle", 1)
     35  -- ctrl:eventScheduler("mal", xr + 600,yr,zr, xr,yr,zr, 4)
     36  -- ctrl:eventScheduler("idle", 1)
     37  -- ctrl:eventScheduler("chl", xr, yr, zr, xl, yl, zl, 3)
     38  -- ctrl:eventScheduler("idle", 1)
     39  -- ctrl:eventScheduler("spi", xm,ym,zm, 0,0,0, 4)
     40  -- ctrl:eventScheduler("idle", 1)
    3941
    4042end
  • code/branches/presentationFS16/data/levels/scriptController.oxw

    r10622 r11207  
    3939    <Billboard position="2500,0,0" material="Flares/ringflare2" colour="0.2,0.4,0.8" scale=10 />
    4040    <DistanceTrigger position="2500,0,0" distance="200" target="Pawn"
    41       beaconMode="exclude" targetname="bcnDestroyer" name="takeControl"
     41      beaconMode="exclude" targetname="bcnDestroyer" name="takeControl" stayActive="true"
    4242    />
    4343
     
    5454    </StaticEntity>
    5555
     56
     57    <StaticEntity position  = "3000,0,0" mass=10000 collisionType=static >
     58      <attached>
     59        <Model mesh="cube_green.mesh" mass=10 position="0,0,0" scale=10 />
     60      </attached>
     61    </StaticEntity>
     62
     63    <StaticEntity position  = "2000,0,0" mass=10000 collisionType=static >
     64      <attached>
     65        <Model mesh="cube_green.mesh" mass=10 position="0,0,0" scale=10 />
     66      </attached>
     67    </StaticEntity>
     68
     69    <StaticEntity position  = "2500,500,0" mass=10000 collisionType=static >
     70      <attached>
     71        <Model mesh="cube_green.mesh" mass=10 position="0,0,0" scale=10 />
     72      </attached>
     73    </StaticEntity>
     74
    5675<!-- ControllerDirector waits for the event takeControl to attach a new Controller -->
    57     <ControllerDirector position="0,0,0" scriptname="presentation">
     76    <ControllerDirector position="0,0,0" scriptname="testscript">
    5877        <events>
    5978            <takeControl>
  • code/branches/presentationFS16/src/orxonox/CMakeLists.txt

    r11206 r11207  
    6666    infos/PlayerInfo.h
    6767    sound/SoundManager.h
    68     controllers/ScriptController.h
     68    controllers/NewScriptController.h
    6969    overlays/CampaignMenu.h
    7070  PCH_FILE
  • code/branches/presentationFS16/src/orxonox/OrxonoxPrereqs.h

    r11080 r11207  
    9898    class HumanController;
    9999    class ScriptController;
     100    class NewScriptController;
    100101    class WaypointController;
    101102    class WaypointPatrolController;
  • code/branches/presentationFS16/src/orxonox/controllers/CMakeLists.txt

    r11052 r11207  
    55  ArtificialController.cc
    66  AIController.cc
    7   ScriptController.cc
    87  WaypointController.cc
    98  WaypointPatrolController.cc
     
    1918  FightingController.cc
    2019  MasterController.cc
     20  NewScriptController.cc
    2121)
     22ADD_SUBDIRECTORY(scriptTasks)
  • code/branches/presentationFS16/src/orxonox/controllers/ControllerDirector.cc

    r11071 r11207  
    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 */
     
    105105        * the next time it is triggered */
    106106       ctrlid += 1;
     107
     108        orxout()<<"swag"<< endl;
    107109    }
    108110
     
    112114        this->player_ = nullptr;
    113115
    114         orxout(verbose) << "Preparation to take Control!" << endl;
     116        orxout() << "Preparation to take Control!" << endl;
    115117
    116118        // Check whether it is a player trigger and extract pawn from it
     
    121123
    122124            // Check if there actually was a player returned.
    123             if( this->player_ == nullptr) return false;
     125            if( this->player_ == nullptr) {
     126            orxout()<<"swag control"<< endl;
     127
     128              return false;
     129            }
    124130        }
    125131        else
    126132        {
    127             orxout(verbose) << "ControllerDirector::preparationToTakeControl "
     133            orxout() << "ControllerDirector::preparationToTakeControl "
    128134              << "Not a player trigger, can't extract pawn from it.." << endl;
    129135            return false;
  • code/branches/presentationFS16/src/orxonox/controllers/ControllerDirector.h

    r11071 r11207  
    2727 */
    2828
     29/*
     30@todo:
     31
     32in the take control or preparationToTakeControl functions remove the former controller and store it somewhere so it can be put back later.
     33
     34*/
    2935#ifndef _ControllerDirector_H__
    3036#define _ControllerDirector_H__
  • code/branches/presentationFS16/src/orxonox/controllers/ScriptController.cc

    r11083 r11207  
    3434  * Command             | Abbreviation | Parameter 1          | '' 2     | '' 3    | '' 4                 | '' 5     | '' 6     | '' 7
    3535  *
    36   * "Move And Look"     | mal          | GoTo X Coordinate    | '' Y ''  | '' Z '' | LookAt X Coordinate  |  '' Y '' |  '' Y '' | Duration
    37   * "Rotate And Look"   | ral          | GoTo X Coordinate    | '' Y ''  | '' Z '' | Axis (1=x, 2=z, 3=z) |     -    |     -    | Duration
    38   * "Spiral"            | spi          | GoTo X Coordinate    | '' Y ''  | '' Z '' |          -           |     -    |     -    | Duration
    39   * "Transition Look"   | chl          | From X Coordinate    | '' Y ''  | '' Z '' | To X Coordinate      |  '' Y '' |  '' Y '' | Duration
     36  * "Move And Look"     | mal          | GoTo X Coordinate    |  '' Y ''  | '' Z '' | LookAt X Coordinate  |  '' Y '' |  '' Y '' | Duration
     37  * "Rotate And Look"   | ral          | GoTo X Coordinate    |  '' Y ''  | '' Z '' | Axis (1=x, 2=y, 3=z) |     -    |     -    | Duration
     38  * "Spiral"            | spi          | GoTo X Coordinate    |  '' Y ''  | '' Z '' |          -           |     -    |     -    | Duration
     39  * "Transition Look"   | chl          | From X Coordinate    |  '' Y ''  | '' Z '' | To X Coordinate      |  '' Y '' |  '' Y '' | Duration
     40  * "rotate round X crd"| rotX         | anchor coordinate    | angle(rad)|    -    |                      |          |          | Duration
    4041  * "Idle (Do nothing)" | idle         | Duration
    4142  */
     
    4647#include "worldentities/ControllableEntity.h"
    4748#include "core/LuaState.h"
    48 #include "core/LuaState.h"
    4949#include "util/Math.h"
    5050
     
    9090        /* Output some debugging information */
    9191        orxout(verbose) << "ScriptController: Taking control" << endl;
    92         orxout(verbose) << "This-pointer: " << this << endl;
     92        orxout(verbose) << "This-pointer: " << this << endl; 
    9393
    9494        /* Set the controller ID (the argument here should be nonzero) */
     
    103103         */
    104104        this->entity_->setDestroyWhenPlayerLeft(false);
    105         this->player_->pauseControl();
     105        this->player_->stopTemporaryControl();
    106106        this->entity_->setController(this);
    107107        this->setControllableEntity(this->entity_);
    108         this->entity_->mouseLook();
    109         this->entity_->setVisible(false);
     108        //this->entity_->mouseLook();
     109        //this->entity_->setVisible(false);
     110       
     111        // TODO take the human Controllers control  dont forget to give it back in the destructor
    110112    }
    111113
     
    201203        {
    202204          // Abbreviation for "spiral" (rotation + translation)
    203           if (this->currentEvent.fctName == "spi") {
    204 
    205             // Need to know a perpendicular basis to the translation vector:
     205          if (this->currentEvent.fctName == "spi")
     206          {
     207              spi(dl); // call the external function
     208          }
     209
     210          // Abbreviation for "rotate and look"
     211          else if (this->currentEvent.fctName == "ral")
     212          {
     213              ral(dl); 
     214          }
     215          else if( this->currentEvent.fctName == "mal" )
     216          {
     217              mal(dl);
     218          }
     219          else if( this->currentEvent.fctName == "chl" )
     220          {
     221              chl(dl);
     222          }
     223
     224
     225          /* Force mouse look */
     226          if( this->entity_->isInMouseLook() == false )
     227            this->entity_->mouseLook();
     228        }
     229    }
     230
     231    void ScriptController::eventScheduler(std::string instruction,
     232      float x1, float y1, float z1,
     233      float x2, float y2, float z2,
     234      float duration, float executionTime)
     235    {
     236      /* put data (from LUA) into time-sorted eventList*/
     237      /* Nimmt den befehl und die argumente aus luascript und ertellt einen
     238       * struct pro event, diese structs werden sortiert nach eventTime
     239       */
     240      struct event tmp;
     241
     242      /* Fill the structure with all the provided information */
     243      tmp.fctName = instruction;
     244
     245      //tmp.x1 = x1; tmp.y1 = y1; tmp.z1 = z1;
     246      //tmp.x2 = x2; tmp.y2 = y2; tmp.z2 = z2;
     247      tmp.v1 = Vector3(x1,y1,z1);
     248      tmp.v2 = Vector3(x2,y2,z2);
     249
     250      // the parameters are not required to be vector coordinates!
     251      // for convenience they are however stored twice if they have some kind of different meaning
     252      tmp.a = x1;
     253      tmp.b = y1;
     254      tmp.c = z1;
     255      tmp.d = x2;
     256      tmp.e = y2;
     257      tmp.f = z2;
     258
     259      tmp.duration = duration;
     260
     261      /* This is kind of a hack. If we hit the function idle all we want to do is
     262         advance event execution time, not schedule anything */
     263      if (instruction == "idle") {
     264        tmp.eventTime = this->prevEventTime;
     265        this->prevEventTime += x1;
     266        return;
     267      } else {
     268        tmp.eventTime = this->prevEventTime;
     269        this->prevEventTime += duration;
     270      }
     271
     272      /* Add the created event to the event list */
     273      if(eventList.size()==0)
     274      { /* The list is still empty, just add it */
     275        orxout(verbose) << "eventList empty (01)" << endl;
     276        eventList.insert(eventList.begin(), tmp);
     277        this->eventno += 1;
     278        return; /* Nothing more to do, the event was added */
     279      }
     280
     281      /* Event was not added yet since the list was not empty. Walk through
     282       * the list of events and add it so that the events are correctly in
     283       * order.
     284       */
     285      for (std::vector<event>::iterator it=eventList.begin(); it<eventList.end(); it++)
     286      { if(tmp.eventTime < it->eventTime)
     287        { eventList.insert(it,tmp);
     288          this->eventno += 1;
     289          //orxout()<<"new event added"<<endl;
     290          return;
     291        }
     292      }
     293
     294      /* If the event was still not added here, it belongs in the end of the list */
     295      eventList.insert(eventList.end(), tmp);
     296      this->eventno += 1;
     297
     298    }
     299
     300    // Event Functions
     301
     302    void ScriptController::spi(float dl)
     303    {
     304   
     305                // Need to know a perpendicular basis to the translation vector:
    206306            // Given (a, b, c) we chose (b, -a, 0)norm and (0, c, -b)norm
    207307            // Currently we set a fix rotational radius of 400
     
    221321            delete ortho1;
    222322            delete ortho2;
    223           }
    224 
    225           // Abbreviation for "rotate and look"
    226           if (this->currentEvent.fctName == "ral")
    227           {
     323
     324    }
     325
     326    void ScriptController::ral(float dl)
     327    {
    228328            // Specify the axis
    229329            Vector3 a;
     
    250350            /* Look at the specified position */
    251351            this->entity_->lookAt(this->currentEvent.v1);
    252           }
    253           else if( this->currentEvent.fctName == "mal" )
    254           {
     352     
     353    }
     354
     355    void ScriptController::mal(float dl)
     356    {
    255357            /* Set the position to the correct place in the trajectory */
    256358            this->entity_->setPosition( (1-dl)*startpos + dl * this->currentEvent.v1);
     
    258360            /* Look at the specified position */
    259361            this->entity_->lookAt(this->currentEvent.v2);
    260           }
    261           else if( this->currentEvent.fctName == "chl" )
    262           {
     362
     363    }
     364
     365    void ScriptController::chl(float dl)
     366    {
    263367            /* Sweep the look from v1 to v2 */
    264368            this->entity_->lookAt( (1-dl)*this->currentEvent.v1 +
    265369              dl * this->currentEvent.v2 );
    266           }
    267 
    268 
    269           /* Force mouse look */
    270           if( this->entity_->isInMouseLook() == false )
    271             this->entity_->mouseLook();
    272         }
    273     }
    274 
    275     void ScriptController::eventScheduler(std::string instruction,
    276       float x1, float y1, float z1,
    277       float x2, float y2, float z2,
    278       float duration, float executionTime)
    279     {
    280       /* put data (from LUA) into time-sorted eventList*/
    281       /* Nimmt den befehl und die argumente aus luascript und ertellt einen
    282        * struct pro event, diese structs werden sortiert nach eventTime
    283        */
    284       struct event tmp;
    285 
    286       /* Fill the structure with all the provided information */
    287       tmp.fctName = instruction;
    288 
    289       //tmp.x1 = x1; tmp.y1 = y1; tmp.z1 = z1;
    290       //tmp.x2 = x2; tmp.y2 = y2; tmp.z2 = z2;
    291       tmp.v1 = Vector3(x1,y1,z1);
    292       tmp.v2 = Vector3(x2,y2,z2);
    293 
    294       // the parameters are not required to be vector coordinates!
    295       // for convenience they are however stored twice if they have some kind of different meaning
    296       tmp.a = x1;
    297       tmp.b = y1;
    298       tmp.c = z1;
    299       tmp.d = x2;
    300       tmp.e = y2;
    301       tmp.f = z2;
    302 
    303       tmp.duration = duration;
    304 
    305       /* This is kind of a hack. If we hit the function idle all we want to do is
    306          advance event execution time, not schedule anything */
    307       if (instruction == "idle") {
    308         tmp.eventTime = this->prevEventTime;
    309         this->prevEventTime += x1;
    310         return;
    311       } else {
    312         tmp.eventTime = this->prevEventTime;
    313         this->prevEventTime += duration;
    314       }
    315 
    316       /* Add the created event to the event list */
    317       if(eventList.size()==0)
    318       { /* The list is still empty, just add it */
    319         orxout(verbose) << "eventList empty (01)" << endl;
    320         eventList.insert(eventList.begin(), tmp);
    321         this->eventno += 1;
    322         return; /* Nothing more to do, the event was added */
    323       }
    324 
    325       /* Event was not added yet since the list was not empty. Walk through
    326        * the list of events and add it so that the events are correctly in
    327        * order.
    328        */
    329       for (std::vector<event>::iterator it=eventList.begin(); it<eventList.end(); it++)
    330       { if(tmp.eventTime < it->eventTime)
    331         { eventList.insert(it,tmp);
    332           this->eventno += 1;
    333           //orxout()<<"new event added"<<endl;
    334           return;
    335         }
    336       }
    337 
    338       /* If the event was still not added here, it belongs in the end of the list */
    339       eventList.insert(eventList.end(), tmp);
    340       this->eventno += 1;
     370
     371    }
     372
     373    void ScriptController::rotX(float dl)
     374    {
     375
    341376
    342377    }
  • code/branches/presentationFS16/src/orxonox/controllers/ScriptController.h

    r11071 r11207  
    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
     
    128127            //Vector3 lookAtPosition;
    129128
    130     };// tolua_export
    131 } // tolua_export
     129
     130            /* private member functions */
     131
     132            /*spiral event*/
     133            void spi(float dl);
     134
     135            /* rotate and look event */
     136            void ral(float dl);
     137
     138            /* move and look event */
     139            void mal(float dl);
     140
     141            /* transition look event */
     142            void chl(float dl);
     143
     144            /* rotate around x-coordinate event */
     145            void rotX(float dl);
     146
     147    };
     148}
    132149
    133150#endif /* _ScriptController_H__ */
Note: See TracChangeset for help on using the changeset viewer.