Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 8, 2014, 10:16:23 AM (11 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/ControllerDirector.cc

    r10046 r10047  
    66
    77#include "ControllerDirector.h"
     8#include "ScriptController.h"
    89#include "core/CoreIncludes.h"
    910
     
    3233        this->entity_ = NULL;
    3334        this->pTrigger_ = NULL;
     35        this->context_ = context;
    3436    }
    3537
     
    6466        * triggered our event.
    6567        */
    66        static int ctrlid = 0;
    67        // preparationTo(trigger);
    68        // setNewController(controller);
     68       static int ctrlid = 1;
     69       bool prepok = preparationToTakeControl(trigger);
     70       if( prepok == true)
     71       {
     72         /* Create a scriptcontroller object */
     73         ScriptController *newctrl = new ScriptController(this->context_);
     74
     75         /* Make the player we were given its slave */
     76         newctrl->setPlayer(this->player_);
     77
     78         /* Start controlling that object */
     79         newctrl->takeControl(ctrlid);
     80       }
     81       else
     82         return;
    6983       
    7084       /* Set up a luastate to use for running the scripts */
     
    90104
    91105       
    92     /*bool ControllerDirector::preparationToTakeControl(BaseObject * trigger) {
    93 
    94             this->pTrigger_ = orxonox_cast<PlayerTrigger*>(trigger);
     106    bool ControllerDirector::preparationToTakeControl(BaseObject * trigger)
     107    {
     108        this->pTrigger_ = orxonox_cast<PlayerTrigger*>(trigger);
    95109        this->player_ = NULL;
    96110
    97111        orxout() << "Preparation to take Control!" << endl;
     112
    98113        // Check whether it is a player trigger and extract pawn from it
    99114        if(this->pTrigger_ != NULL)
    100115        {
    101            
    102             player_ = this->pTrigger_->getTriggeringPlayer();  //Get the object which triggered the event.
     116            // Get the object which triggered the event.
     117            this->player_ = this->pTrigger_->getTriggeringPlayer(); 
     118
     119            // Check if there actually was a player returned.
     120            if( this->player_ == NULL) return false;
    103121        }
    104122        else
    105123        {
    106             orxout() << "ControllerDirector::preparationToTakeControl Not a player trigger, can't extract pawn from it.." << endl;
     124            orxout() << "ControllerDirector::preparationToTakeControl "
     125              << "Not a player trigger, can't extract pawn from it.." << endl;
    107126            return false;
    108127        }
    109128
    110        
    111129        this->entity_ = this->player_->getControllableEntity();
    112130        assert(this->entity_);
    113131
    114     return true;
    115 
     132        return true;
    116133    }
    117134
     135    /* // Currently unused
    118136    void ControllerDirector::setNewController(Controller * controller) {
    119137
     
    124142        this->player_->pauseControl();
    125143        this->entity_->setController(controller);
    126         this->setControllableEntity(this->entity_);
    127 
    128 
    129 
     144        this->player_->startControl(this->entity_);
     145        //this->setControllableEntity(this->entity_);
    130146    }
    131 */
     147    */
    132148       
    133149   
Note: See TracChangeset for help on using the changeset viewer.