Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 8, 2014, 10:16:23 AM (10 years ago)
Author:
smerkli
Message:

Controller switching works now, however lua script
execution is blocking, which means we can only schedule
stuff in them, not leave them running in realtime

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/ScriptableController/src/orxonox/controllers/ScriptController.cc

    r10046 r10047  
    2828
    2929#include "ScriptController.h"
     30#include "infos/PlayerInfo.h"
    3031#include "core/CoreIncludes.h"
    3132#include "worldentities/ControllableEntity.h"
     
    4243        RegisterObject(ScriptController);
    4344        //set_controlled(CE);
     45        this->ctrlid_ = 0;
    4446    }
    4547
    46     void ScriptController::set_luasrc(std::string lsrc)
     48    void ScriptController::takeControl(int ctrlid)
    4749    {
    48         this->luasrc=lsrc;
     50        orxout() << "ScriptController: Taking control" << endl;
     51        orxout() << "This-pointer: " << this << endl;
     52        this->ctrlid_ = ctrlid;
     53        this->entity_ = this->player_->getControllableEntity();
     54        assert(this->entity_);
     55
     56        this->entity_->setDestroyWhenPlayerLeft(false);
     57        this->player_->pauseControl();
     58        this->entity_->setController(this);
     59        this->setControllableEntity(this->entity_);
    4960    }
    5061
    51     void ScriptController::set_controlled(ControllableEntity* toControl)
    52     {
    53         this->controlled=toControl;
    54     }
    55    
     62    /* Yet to be implemented and tested */
     63    //void ScriptController::yieldControl()
     64    //{
     65        //this->player_->startControl(this->entity_);
     66        //this->setActive(false);
     67        //this->controllableEntity_ = NULL;
     68    //}
     69
    5670    void ScriptController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    5771    {
     
    6276    const Vector3& ScriptController::getPosition()
    6377    {
    64         return this->controlled->getPosition();
     78        return this->entity_->getPosition();
    6579    }
    6680
     
    7084      orxout() << "Great success!" << std::endl;
    7185
    72       /* Loop over all the scriptcontrollers currently present in the game */
     86      /* Debugging: print all the scriptcontroller object pointers */
     87      for(ObjectList<ScriptController>::iterator it =
     88        ObjectList<ScriptController>::begin();
     89        it != ObjectList<ScriptController>::end(); ++it)
     90      { orxout() << "Have object in list: " << *it << endl; }
     91
     92      /* Find the first one with a nonzero ID */
    7393      for(ObjectList<ScriptController>::iterator it =
    7494        ObjectList<ScriptController>::begin();
     
    7696      {
    7797        // TODO: do some selection here. Currently just returns the first one
    78         return *it;
     98        if( (*it)->getID() > 0 )
     99          return *it;
    79100     
    80101      }
     
    82103    }
    83104
     105    void ScriptController::tick(float dt)
     106    {
     107        /* If this controller has no entity entry, do nothing */
     108        if( !(this->entity_) )
     109          return;
     110
     111        //orxout() << "Rotating!" << endl;
     112
     113        //this->entity_->rotateYaw(-1.0f * 100.0f * dt);
     114        //this->entity_->rotatePitch(0.8f * 100.0f);
     115
     116        SUPER(ScriptController, tick, dt);
     117    }
    84118
    85119
    86120    void ScriptController::moveToPosition_beta(float x, float y, float z )
    87121    {
    88         /* The section commented out here below throws segfaults */
    89         //const Vector3 local=getPosition();
    90         //const Vector3 target=Vector3(x,y,z);
    91         //Vector3 way=target-local;
     122        //const Vector3 local = this->getPosition();
     123        const Vector3 target = Vector3(100*x,100*y,100*z);
     124        //Vector3 way = target-local;
     125        orxout() << "Moving This-pointer: " << this << endl;
    92126       
    93127       
    94         //this->controlled->lookAt(target);
    95         //this->controlled->moveFrontBack(way.length());     
     128        this->entity_->lookAt(target);
     129        this->entity_->moveFrontBack(-1000*target.length());     
    96130
    97131 
     
    99133        orxout()<<x<<"  "<<y<<"  "<<z<<endl;
    100134    }
     135
    101136
    102137    /* TODO:    hilfs(zwischen)funktionen um lua eingabe zu ermoeglichen: zb moveToPosition(float...) weil in LUA wohl
Note: See TracChangeset for help on using the changeset viewer.