Changeset 10047 for code/branches/ScriptableController
- Timestamp:
- May 8, 2014, 10:16:23 AM (11 years ago)
- Location:
- code/branches/ScriptableController
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/ScriptableController/data/gui/scripts/testscript.lua
r10046 r10047 3 3 --orxonox.execute("orxout message test " .. k) 4 4 5 -- Set some test variables 5 6 x = 1.1 6 7 y = 2.2 7 8 z = 3.3 8 9 10 --os.execute("sleep " .. 2) 9 11 12 -- Get a local pointer to a scriptcontroller 10 13 local ctrl = orxonox.ScriptController:getScriptController() 14 15 -- If it worked, call its "movetoposition" function 11 16 if ctrl ~= nil then 12 17 ctrl:moveToPosition_beta(x, y, z) 13 18 end 14 19 15 --ctrl.moveToPosition(x,y,z) 16 -- 20 -- Output the newctrlid variable we set from the C++ code 17 21 if newctrlid ~= nil then 18 22 orxonox.execute("orxout message test " .. newctrlid) 19 end20 21 local docks = orxonox.Dock:getNumberOfActiveDocks()22 local docklist = {}23 for i = 0, docks-1 do24 table.insert(docklist, orxonox.Dock:getActiveDockAtIndex(i))25 end26 local dock = docklist[1]27 if dock ~= nil then28 dock:dock()29 23 end 30 24 -
code/branches/ScriptableController/src/orxonox/controllers/ControllerDirector.cc
r10046 r10047 6 6 7 7 #include "ControllerDirector.h" 8 #include "ScriptController.h" 8 9 #include "core/CoreIncludes.h" 9 10 … … 32 33 this->entity_ = NULL; 33 34 this->pTrigger_ = NULL; 35 this->context_ = context; 34 36 } 35 37 … … 64 66 * triggered our event. 65 67 */ 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; 69 83 70 84 /* Set up a luastate to use for running the scripts */ … … 90 104 91 105 92 /*bool ControllerDirector::preparationToTakeControl(BaseObject * trigger) {93 94 106 bool ControllerDirector::preparationToTakeControl(BaseObject * trigger) 107 { 108 this->pTrigger_ = orxonox_cast<PlayerTrigger*>(trigger); 95 109 this->player_ = NULL; 96 110 97 111 orxout() << "Preparation to take Control!" << endl; 112 98 113 // Check whether it is a player trigger and extract pawn from it 99 114 if(this->pTrigger_ != NULL) 100 115 { 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; 103 121 } 104 122 else 105 123 { 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; 107 126 return false; 108 127 } 109 128 110 111 129 this->entity_ = this->player_->getControllableEntity(); 112 130 assert(this->entity_); 113 131 114 return true; 115 132 return true; 116 133 } 117 134 135 /* // Currently unused 118 136 void ControllerDirector::setNewController(Controller * controller) { 119 137 … … 124 142 this->player_->pauseControl(); 125 143 this->entity_->setController(controller); 126 this->setControllableEntity(this->entity_); 127 128 129 144 this->player_->startControl(this->entity_); 145 //this->setControllableEntity(this->entity_); 130 146 } 131 */147 */ 132 148 133 149 -
code/branches/ScriptableController/src/orxonox/controllers/ControllerDirector.h
r10027 r10047 48 48 49 49 50 50 /* Take over control of a given object */ 51 51 void takeControl(Controller * controller, BaseObject * trigger); 52 52 bool preparationToTakeControl(BaseObject * trigger); 53 void setNewController(Controller * controller); 53 54 // currently unused 55 //void setNewController(Controller * controller); 54 56 55 57 … … 57 59 private: 58 60 59 PlayerInfo* player_; 60 61 ControllableEntity* entity_; 62 63 PlayerTrigger * pTrigger_; 61 PlayerInfo* player_; 62 ControllableEntity* entity_; 63 PlayerTrigger * pTrigger_; 64 Context* context_; 64 65 65 66 -
code/branches/ScriptableController/src/orxonox/controllers/ScriptController.cc
r10046 r10047 28 28 29 29 #include "ScriptController.h" 30 #include "infos/PlayerInfo.h" 30 31 #include "core/CoreIncludes.h" 31 32 #include "worldentities/ControllableEntity.h" … … 42 43 RegisterObject(ScriptController); 43 44 //set_controlled(CE); 45 this->ctrlid_ = 0; 44 46 } 45 47 46 void ScriptController:: set_luasrc(std::string lsrc)48 void ScriptController::takeControl(int ctrlid) 47 49 { 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_); 49 60 } 50 61 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 56 70 void ScriptController::XMLPort(Element& xmlelement, XMLPort::Mode mode) 57 71 { … … 62 76 const Vector3& ScriptController::getPosition() 63 77 { 64 return this-> controlled->getPosition();78 return this->entity_->getPosition(); 65 79 } 66 80 … … 70 84 orxout() << "Great success!" << std::endl; 71 85 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 */ 73 93 for(ObjectList<ScriptController>::iterator it = 74 94 ObjectList<ScriptController>::begin(); … … 76 96 { 77 97 // TODO: do some selection here. Currently just returns the first one 78 return *it; 98 if( (*it)->getID() > 0 ) 99 return *it; 79 100 80 101 } … … 82 103 } 83 104 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 } 84 118 85 119 86 120 void ScriptController::moveToPosition_beta(float x, float y, float z ) 87 121 { 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; 92 126 93 127 94 //this->controlled->lookAt(target);95 //this->controlled->moveFrontBack(way.length());128 this->entity_->lookAt(target); 129 this->entity_->moveFrontBack(-1000*target.length()); 96 130 97 131 … … 99 133 orxout()<<x<<" "<<y<<" "<<z<<endl; 100 134 } 135 101 136 102 137 /* TODO: hilfs(zwischen)funktionen um lua eingabe zu ermoeglichen: zb moveToPosition(float...) weil in LUA wohl -
code/branches/ScriptableController/src/orxonox/controllers/ScriptController.h
r10046 r10047 38 38 { // tolua_export 39 39 class _OrxonoxExport ScriptController // tolua_export 40 : public ArtificialController 40 : public ArtificialController, public Tickable 41 41 { // tolua_export 42 42 public: … … 48 48 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 49 49 50 void takeControl(int ctrlid); 51 void setPlayer(PlayerInfo* player) { this->player_ = player; } 50 52 51 void set_luasrc(std::string);52 void set_controlled(ControllableEntity*);53 //void set_luasrc(std::string); 54 //void set_controlled(ControllableEntity*); 53 55 56 virtual void tick(float dt); 54 57 55 58 // LUA interface … … 59 62 60 63 static ScriptController* getScriptController(); 64 65 int getID() { return ctrlid_; } 61 66 62 /* virtual void tick(float dt);*/63 67 64 68 // tolua_end … … 66 70 67 71 private: 68 std::string luasrc; // name of the LUA-sourcefile that shall be executed->see XMLPort-function 69 70 ControllableEntity* controlled; //entity controlled by this SC 72 // name of the LUA-sourcefile that shall be executed->see XMLPort-function 73 std::string luasrc; 74 PlayerInfo* player_; 75 ControllableEntity* entity_; 76 int ctrlid_; 71 77 72 78
Note: See TracChangeset
for help on using the changeset viewer.