[Orxonox-commit 3860] r8534 - in code/branches/pickup: data/levels src/modules/pickup/items

ssgier at orxonox.net ssgier at orxonox.net
Mon May 23 14:37:09 CEST 2011


Author: ssgier
Date: 2011-05-23 14:37:08 +0200 (Mon, 23 May 2011)
New Revision: 8534

Modified:
   code/branches/pickup/data/levels/pickups.oxw
   code/branches/pickup/src/modules/pickup/items/ShrinkPickup.cc
   code/branches/pickup/src/modules/pickup/items/ShrinkPickup.h
Log:
finished code for ShrinkPickup, adapted XML file\

Modified: code/branches/pickup/data/levels/pickups.oxw
===================================================================
--- code/branches/pickup/data/levels/pickups.oxw	2011-05-23 12:26:25 UTC (rev 8533)
+++ code/branches/pickup/data/levels/pickups.oxw	2011-05-23 12:37:08 UTC (rev 8534)
@@ -191,7 +191,7 @@
 
     <PickupSpawner position="-30,-30,-30" respawnTime="60" triggerDistance="20" maxSpawnedItems="5">
       <pickup>
-        <ShrinkPickup />
+        <ShrinkPickup shrinkFactor = "5.0" duration = "5.0" shrinkSpeed = "5.0"/>
       </pickup>
     </PickupSpawner>
 

Modified: code/branches/pickup/src/modules/pickup/items/ShrinkPickup.cc
===================================================================
--- code/branches/pickup/src/modules/pickup/items/ShrinkPickup.cc	2011-05-23 12:26:25 UTC (rev 8533)
+++ code/branches/pickup/src/modules/pickup/items/ShrinkPickup.cc	2011-05-23 12:37:08 UTC (rev 8534)
@@ -50,14 +50,15 @@
 {
     CreateFactory(ShrinkPickup);
 
+		/**
+    @brief
+        Constructor: Initializes the Pickup.
+    */
     ShrinkPickup::ShrinkPickup(BaseObject* creator) : Pickup(creator)
     {
         RegisterObject(ShrinkPickup);
 
         this->initialize();
-        shrinkFactor_ = 5.0;
-        duration_ = 5.0;
-        shrinkSpeed_ = 5.0;
         isActive_ = false;
         isTerminating_ = false;
     }
@@ -67,11 +68,84 @@
 
     }
 
+    void ShrinkPickup::initializeIdentifier(void)
+    {
+        std::stringstream stream;
+        stream << this->getShrinkFactor();
+        std::string type1 = "shrinkFactor";
+        std::string val1 = stream.str();
+        this->pickupIdentifier_->addParameter(type1, val1);
+
+        stream.clear();
+        stream << this->getDuration();
+        std::string val2 = stream.str();
+        std::string type2 = "duration";
+        this->pickupIdentifier_->addParameter(type2, val2);
+
+        stream.clear();
+        stream << this->getShrinkSpeed();
+        std::string val3 = stream.str();
+        std::string type3 = "shrinkSpeed";
+        this->pickupIdentifier_->addParameter(type3, val3);
+    }
+
+   /**
+    @brief
+        Method for creating a HealthPickup object through XML.
+    */
+    void ShrinkPickup::XMLPort(Element& xmlelement, orxonox::XMLPort::Mode mode)
+    {
+        SUPER(ShrinkPickup, XMLPort, xmlelement, mode);
+
+        XMLPortParam(ShrinkPickup, "shrinkFactor", setShrinkFactor, getShrinkFactor, xmlelement, mode);
+        XMLPortParam(ShrinkPickup, "duration", setDuration, getDuration, xmlelement, mode);
+        XMLPortParam(ShrinkPickup, "shrinkSpeed", setShrinkSpeed, getShrinkSpeed, xmlelement, mode);
+
+        this->initializeIdentifier();
+    }
+
+    /**
+    @brief
+        Sets the shrinking factor.
+    @param factor
+        The factor.
+    */
+    void ShrinkPickup::setShrinkFactor(float factor)
+    {
+        this->shrinkFactor_ = factor;
+    }
+
+    /**
+    @brief
+        Sets the duration.
+    @param duration
+        The duration.
+    */
+    void ShrinkPickup::setDuration(float duration)
+    {
+        this->duration_ = duration;
+    }
+
+    /**
+    @brief
+        Sets the shrinking speed.
+    @param speed
+        The speed.
+    */
+    void ShrinkPickup::setShrinkSpeed(float speed)
+    {
+        this->shrinkSpeed_ = speed;
+    }
+
     void ShrinkPickup::initialize(void)
     {
         this->addTarget(ClassIdentifier<Pawn>::getIdentifier());
     }
 
+		/**
+    @brief
+        Prepares for shrinking (collecting several informations).
+    */
     void ShrinkPickup::changedUsed(void)
     {
         SUPER(ShrinkPickup, changedUsed);
@@ -82,6 +156,7 @@
             if(pawn == NULL) // If the PickupCarrier is no Pawn, then this pickup is useless and therefore is destroyed.
                 this->Pickupable::destroy();
 
+            //Collect scaling information.
             defaultScale_ = this->pawn->getScale3D();
             defaultMass_ = this->pawn->getMass();
 
@@ -93,14 +168,20 @@
 
             cameraPositions_ = this->pawn->getCameraPositions();
             size_ = cameraPositions_.size();
-            isActive_ = true;
-            durationTimer.setTimer(duration_, false, createExecutor(createFunctor(&ShrinkPickup::terminate, this)));
+            isActive_ = true;    //start shrinking now.
+            durationTimer.setTimer(duration_, false, createExecutor(createFunctor(&ShrinkPickup::terminate, this)));    //Set timer for termination.
         }
     }
 
+	/**
+    @brief
+        Updates the scales of the ship.
+    @param dt
+        Time since last call.
+    */
     void ShrinkPickup::tick(float dt)
     {
-        if(isActive_ == true && actualScale_ > smallScale_)
+        if(isActive_ == true && actualScale_ > smallScale_)    //if the ship has not reached the target scale, continue shrinking
         {
             float factor_ = 1 + dt*shrinkSpeed_;
 
@@ -120,7 +201,7 @@
         }
         else isActive_ = false;
 
-        if(isTerminating_ == true && actualScale_ < defaultScale_)
+        if(isTerminating_ == true && actualScale_ < defaultScale_)    //grow until the ship reaches its default scale.
         {
             float factor_ = 1 + dt*shrinkSpeed_;
 
@@ -143,6 +224,10 @@
 
     }
 
+	/**
+    @brief
+        Initializes the termination.
+    */
     void ShrinkPickup::terminate(void)
     {
         isActive_ = false;
@@ -170,5 +255,11 @@
             item = new ShrinkPickup(this);
 
         SUPER(ShrinkPickup, clone, item);
+        ShrinkPickup* pickup = dynamic_cast<ShrinkPickup*>(item);
+        pickup->setShrinkFactor(this->getShrinkFactor());
+        pickup->setDuration(this->getDuration());
+        pickup->setShrinkSpeed(this->getShrinkSpeed());
+
+        pickup->initializeIdentifier();
     }
 }

Modified: code/branches/pickup/src/modules/pickup/items/ShrinkPickup.h
===================================================================
--- code/branches/pickup/src/modules/pickup/items/ShrinkPickup.h	2011-05-23 12:26:25 UTC (rev 8533)
+++ code/branches/pickup/src/modules/pickup/items/ShrinkPickup.h	2011-05-23 12:37:08 UTC (rev 8534)
@@ -58,31 +58,42 @@
             ShrinkPickup(BaseObject* creator); //!< Constructor.
             virtual ~ShrinkPickup(); //!< Destructor.
             virtual void changedUsed(void); //!< Is called when the pickup has transited from used to unused or the other way around.
-			virtual void clone(OrxonoxClass*& item); //!< Creates a duplicate of the input OrxonoxClass.
-			void tick(float dt);
+            virtual void clone(OrxonoxClass*& item); //!< Creates a duplicate of the input OrxonoxClass.
+            virtual void XMLPort(Element& xmlelement, orxonox::XMLPort::Mode mode);
+            inline float getShrinkFactor(void) const
+                { return this->shrinkFactor_; }
+            inline float getDuration(void) const
+                { return this->duration_; }
+            inline float getShrinkSpeed(void) const
+                { return this->shrinkSpeed_; }
+            void setShrinkFactor(float factor);
+            void setDuration(float duration);
+            void setShrinkSpeed(float speed);
+            void tick(float dt);
 
+        protected:
+            void initializeIdentifier(void);
+
         private:
             void initialize(void);
-			
-			float duration_;			//!< determines how long the pickup will be active
-    		float shrinkFactor_;		//shrink factor of the space ship
-			float shrinkSpeed_;
-			bool isActive_;
-			bool isTerminating_;
-			int size_;
-			std::list<SmartPtr<CameraPosition> > cameraPositions_;
-			float defaultCameraPos_;
-			Ogre::Vector3 defaultScale_;
-			Ogre::Vector3 actualScale_;
-			Ogre::Vector3 smallScale_;
-			float defaultMass_;
-			float actualMass_;
-			float smallMass_;			
-			Pawn* carrierToPawnHelper(void);
-			Pawn* pawn;
-			Timer durationTimer;
-			void terminate(void);
-
+            float duration_;			//!< determines how long the pickup will be active
+            float shrinkFactor_;        //shrink factor of the space ship
+            float shrinkSpeed_;         //speed of shrinking
+            bool isActive_;             //true if ship is shrinking or small
+            bool isTerminating_;        //true if ship is growing
+            int size_;                  //number of camera positions
+            std::list<SmartPtr<CameraPosition> > cameraPositions_;
+            float defaultCameraPos_;    //all default, actual and small values...
+            Ogre::Vector3 defaultScale_;
+            Ogre::Vector3 actualScale_;
+            Ogre::Vector3 smallScale_;
+            float defaultMass_;
+            float actualMass_;
+            float smallMass_;			
+            Pawn* carrierToPawnHelper(void);
+            Pawn* pawn;
+            Timer durationTimer;
+            void terminate(void);
     };
 }
 




More information about the Orxonox-commit mailing list