[Orxonox-commit 2011] r6728 - in code/trunk: data/levels src/modules/pickup src/modules/pickup/items

dafrick at orxonox.net dafrick at orxonox.net
Thu Apr 15 13:15:12 CEST 2010


Author: dafrick
Date: 2010-04-15 13:15:11 +0200 (Thu, 15 Apr 2010)
New Revision: 6728

Modified:
   code/trunk/data/levels/pickup.oxw
   code/trunk/src/modules/pickup/Pickup.h
   code/trunk/src/modules/pickup/PickupManager.cc
   code/trunk/src/modules/pickup/items/SpeedPickup.cc
Log:
No more seg faults with pickups (at least that's what I hope. ;))


Modified: code/trunk/data/levels/pickup.oxw
===================================================================
--- code/trunk/data/levels/pickup.oxw	2010-04-14 17:54:41 UTC (rev 6727)
+++ code/trunk/data/levels/pickup.oxw	2010-04-15 11:15:11 UTC (rev 6728)
@@ -119,5 +119,11 @@
         </pickup>
     </PickupSpawner>
     
+    <PickupSpawner position="0,-50,-100" triggerDistance="10" respawnTime="30" maxSpawnedItems="10">
+        <pickup>
+            <HealthPickup activationType=immediate durationType=continuous healthRate=10 health=100 />
+        </pickup>
+    </PickupSpawner>
+    
   </Scene>
 </Level>

Modified: code/trunk/src/modules/pickup/Pickup.h
===================================================================
--- code/trunk/src/modules/pickup/Pickup.h	2010-04-14 17:54:41 UTC (rev 6727)
+++ code/trunk/src/modules/pickup/Pickup.h	2010-04-15 11:15:11 UTC (rev 6728)
@@ -134,8 +134,18 @@
 
             virtual bool createSpawner(void); //!< Facilitates the creation of a PickupSpawner upon dropping of the Pickupable.
 
-            bool startPickupTimer(float durationTime);
+            bool startPickupTimer(float durationTime); //!< Starts the pickup duration timer.
+            /**
+            @brief Get your Timer.
+            @return Returns a pointer to the Timer.
+            */
+            inline Timer* getTimer(void)
+                { return &this->durationTimer_; }
 
+            /**
+            @brief The callback method for the Timer.
+                   Can be overloaded to implement desired functionality.
+            */
             virtual void pickupTimerCallback(void) {}
 
             /**
@@ -163,6 +173,7 @@
             pickupActivationType::Value activationType_; //!< The activation type of the Pickup.
             pickupDurationType::Value durationType_; //!< The duration type of the pickup.
 
+            //! Strings for the activation and duration types.
             static const std::string activationTypeImmediate_s;
             static const std::string activationTypeOnUse_s;
             static const std::string durationTypeOnce_s;

Modified: code/trunk/src/modules/pickup/PickupManager.cc
===================================================================
--- code/trunk/src/modules/pickup/PickupManager.cc	2010-04-14 17:54:41 UTC (rev 6727)
+++ code/trunk/src/modules/pickup/PickupManager.cc	2010-04-15 11:15:11 UTC (rev 6728)
@@ -197,13 +197,15 @@
     void PickupManager::dropPickup(int index, PickupCarrier* carrier)
     {
         Pickupable* pickup = carrier->getPickup(index);
-        carrier->drop(pickup);
+        if(pickup != NULL)
+            carrier->drop(pickup);
     }
     
     void PickupManager::usePickup(int index, PickupCarrier* carrier, bool use)
     {
         Pickupable* pickup = carrier->getPickup(index);
-        pickup->setUsed(use);
+        if(pickup != NULL)
+            pickup->setUsed(use);
     }
     
 }

Modified: code/trunk/src/modules/pickup/items/SpeedPickup.cc
===================================================================
--- code/trunk/src/modules/pickup/items/SpeedPickup.cc	2010-04-14 17:54:41 UTC (rev 6727)
+++ code/trunk/src/modules/pickup/items/SpeedPickup.cc	2010-04-15 11:15:11 UTC (rev 6728)
@@ -140,7 +140,14 @@
         //! If the pickup has transited to used.
         if(this->isUsed())
         {
-            this->startPickupTimer(this->getDuration());
+            if(!this->getTimer()->isActive() && this->getTimer()->getRemainingTime() > 0.0f)
+            {
+                this->getTimer()->unpauseTimer();
+            }
+            else
+            {
+                this->startPickupTimer(this->getDuration());
+            }
             engine->setSpeedAdd(this->getSpeedAdd());
             engine->setSpeedMultiply(this->getSpeedMultiply());
         }
@@ -151,7 +158,15 @@
             
             if(this->isOnce())
             {
-                this->destroy();
+                if(!this->getTimer()->isActive() && this->getTimer()->getRemainingTime() == this->getDuration())
+                {
+                    //TODO: Potentially dangerous, not only for this pickup. Think long and hard about this!!!
+                    this->destroy();
+                }
+                else
+                {
+                    this->getTimer()->pauseTimer();
+                }
             }
         }
     }




More information about the Orxonox-commit mailing list