[Orxonox-commit 6252] r10909 - in code/branches/campaignHS15: data/levels src/orxonox/controllers

gania at orxonox.net gania at orxonox.net
Tue Dec 1 10:03:10 CET 2015


Author: gania
Date: 2015-12-01 10:03:10 +0100 (Tue, 01 Dec 2015)
New Revision: 10909

Modified:
   code/branches/campaignHS15/data/levels/AITest.oxw
   code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc
   code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.h
   code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc
   code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc
   code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc
   code/branches/campaignHS15/src/orxonox/controllers/WingmanController.h
Log:
decided to get rid of action timer and call action in tick instead: action is being called once in 2 sec in a tick, 2 sec were split in 4 * 0.25 sec, with 0.25 sec gap for each member of division to call its action, resulted in significant speed up.

Modified: code/branches/campaignHS15/data/levels/AITest.oxw
===================================================================
--- code/branches/campaignHS15/data/levels/AITest.oxw	2015-11-30 21:55:38 UTC (rev 10908)
+++ code/branches/campaignHS15/data/levels/AITest.oxw	2015-12-01 09:03:10 UTC (rev 10909)
@@ -156,7 +156,7 @@
 <!-- HERE ENDS DEMO FOR THE ACTIONPOINTS -->
 <!-- HERE STARTS DEMO FOR FIGHTING -->
     
-<!-- 
+
     <SpaceShip position="-4000, 1500, -1000" lookat="0,0,0" team=0 name="d1sd1">
       <templates>
         <Template link=spaceshipassff />
@@ -296,7 +296,7 @@
         <WingmanController team=1>
         </WingmanController>
       </controller>
-    </SpaceShip> -->
+    </SpaceShip>
     <SpaceShip position="1000, -2400, 1000" lookat="0,0,0" team=1 name="d2s1w2">
       <templates>
         <Template link=spaceshipassff />

Modified: code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc	2015-11-30 21:55:38 UTC (rev 10908)
+++ code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc	2015-12-01 09:03:10 UTC (rev 10909)
@@ -90,6 +90,9 @@
         maneuverCounter_ += dt;
         if (maneuverCounter_ > 6.0f)
             maneuverCounter_ = 0;
+        this->timeOffset_ += dt;
+        if (this->timeOffset_ >= 2.0f)
+            this->timeOffset_ = 0.0f;
         if (timeout_ <= 0)
             this->bFiredRocket_ = false;
 
@@ -101,6 +104,8 @@
         {
             this->lookAtTarget(dt);
         }
+
+
         if (this->bShooting_)
         {
             this->doFire();
@@ -116,18 +121,25 @@
         }
         if (this->bFirstTick_)
         {    
+            this->timeOffset_ = 0.0f;
+            this->bActionCalled_ = false;
             setSpawners();
             // orxout(internal_error) << "health spawners size = " << this->healthSpawners_.size() <<
             // ", damage spawners size = " << this->damageSpawners_.size() <<
             // ", speed spawners size = " << this->speedSpawners_.size() << endl;        
             this->bFirstTick_ = false;
         }
-        if (this->hasTarget())
+
+        //maneuver every 0.25 sec -> 
+        float currentPeriodTime = this->timeOffset_ - static_cast<int>(this->timeOffset_);
+        if (this->hasTarget() && ((currentPeriodTime >= 0.25f && currentPeriodTime <= 0.5f) || (currentPeriodTime >= 0.75 && currentPeriodTime <= 0.999f)) && !this->bManeuverCalled_)
         {
+            this->bManeuverCalled_ = true;
             this->maneuver();
-            if (static_cast<int>(this->maneuverCounter_*100) % 3 == 0)
-                this->bShooting_ = this->canFire();
+            this->bShooting_ = this->canFire();
         }
+        if ((currentPeriodTime >= 0.0f && currentPeriodTime <= 0.25f) || (currentPeriodTime >= 0.5f && currentPeriodTime <= 0.75f))
+            this->bManeuverCalled_ = false;
         SUPER(ActionpointController, tick, dt);
     }
     void ActionpointController::action()
@@ -136,7 +148,7 @@
             return;
         if (!this->getControllableEntity() || !orxonox_cast<Pawn*> (this->getControllableEntity()))
             return;
-            this->startAttackingEnemiesThatAreClose();
+        this->startAttackingEnemiesThatAreClose();
 
         this->deltaHp = orxonox_cast<Pawn*> (this->getControllableEntity())->getHealth() - this->previousHp;
         this->previousHp = orxonox_cast<Pawn*> (this->getControllableEntity())->getHealth();
@@ -545,8 +557,7 @@
             this->nextActionpoint();
             return;
         }  
-        if (this->actionCounter_ % 3 == 0)
-            this->setTargetOrientation(this->getProtect()->getWorldOrientation());
+        this->setTargetOrientation(this->getProtect()->getWorldOrientation());
     }
     void ActionpointController::nextActionpoint()
     {

Modified: code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.h	2015-11-30 21:55:38 UTC (rev 10908)
+++ code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.h	2015-12-01 09:03:10 UTC (rev 10909)
@@ -235,6 +235,10 @@
                 std::multimap <int, std::pair<PickupSpawner*, bool> > damageSpawners_; 
                 std::multimap <int, std::pair<PickupSpawner*, bool> > speedSpawners_; 
 
+                float timeOffset_;
+                bool bActionCalled_;
+                bool bManeuverCalled_;
+
         private:
             
     };

Modified: code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc	2015-11-30 21:55:38 UTC (rev 10908)
+++ code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc	2015-12-01 09:03:10 UTC (rev 10909)
@@ -42,7 +42,7 @@
         this->target_ = 0;
         this->myFollower_ = 0;
         this->myWingman_ = 0;
-        this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&DivisionController::action, this)));
+        //this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&DivisionController::action, this)));
     }
 
     DivisionController::~DivisionController()
@@ -67,6 +67,17 @@
         if (!this->isActive())
             return;   
         SUPER(DivisionController, tick, dt);
+        if (this->timeOffset_ >= 0.0f && this->timeOffset_ <= 0.5f && !this->bActionCalled_)
+        {
+            this->action();
+            this->bActionCalled_ = true;
+        }
+        if (this->timeOffset_ > 1.0f)
+        {
+            this->bActionCalled_ = false;
+        }
+
+        
     }
     void DivisionController::action()
     {   

Modified: code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc	2015-11-30 21:55:38 UTC (rev 10908)
+++ code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc	2015-12-01 09:03:10 UTC (rev 10909)
@@ -43,7 +43,7 @@
         RegisterObject(SectionController);
         this->setFormationMode(FormationMode::FINGER4);
 
-        this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&SectionController::action, this)));
+        //this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&SectionController::action, this)));
         this->myWingman_ = 0;
         this->myDivisionLeader_ = 0;
         this->bFirstAction_ = true;
@@ -73,6 +73,15 @@
             return;
    
         SUPER(SectionController, tick, dt);
+        if (this->timeOffset_ >= 0.5f && this->timeOffset_ <= 1.0f && !this->bActionCalled_)
+        {
+            this->action();
+            this->bActionCalled_ = true;
+        }
+        if (this->timeOffset_ > 1.5f)
+        {
+            this->bActionCalled_ = false;
+        }
     }
 
     void SectionController::action()

Modified: code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc	2015-11-30 21:55:38 UTC (rev 10908)
+++ code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc	2015-12-01 09:03:10 UTC (rev 10909)
@@ -38,7 +38,7 @@
     WingmanController::WingmanController(Context* context) : ActionpointController(context)
     {
         RegisterObject(WingmanController);
-        this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&WingmanController::action, this)));
+        //this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&WingmanController::action, this)));
         this->myLeader_ = 0;
         this->bFirstAction_ = true;
 
@@ -67,6 +67,15 @@
             return; 
         
         SUPER(WingmanController, tick, dt);
+        if (this->timeOffset_ >= this->actionTime_ && this->timeOffset_ <= this->actionTime_ + 0.5f && !this->bActionCalled_)
+        {
+            this->action();
+            this->bActionCalled_ = true;
+        }
+        if (this->timeOffset_ <= 0.5f)
+        {
+            this->bActionCalled_ = false;
+        }
     }
     
     //----action for hard calculations----
@@ -228,6 +237,14 @@
             //----Racing conditions----
             if (closestLeader->setWingman(orxonox_cast<ActionpointController*>(this)))
             {
+                if (closestLeader->getIdentifier()->getName() == "SectionController")
+                {
+                    this->actionTime_ = 1.0f;
+                }
+                else
+                {
+                    this->actionTime_ = 1.5f;
+                }
                 return closestLeader;
             }
         }

Modified: code/branches/campaignHS15/src/orxonox/controllers/WingmanController.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/WingmanController.h	2015-11-30 21:55:38 UTC (rev 10908)
+++ code/branches/campaignHS15/src/orxonox/controllers/WingmanController.h	2015-12-01 09:03:10 UTC (rev 10909)
@@ -69,7 +69,7 @@
                 WeakPtr<ActionpointController> myLeader_;
                 Timer actionTimer_; //<! Regularly calls action().
                 bool bFirstAction_;
-
+                float actionTime_;
     };
 }
 




More information about the Orxonox-commit mailing list