Changeset 6709 for code/trunk/src
- Timestamp:
- Apr 13, 2010, 9:32:08 AM (15 years ago)
- Location:
- code/trunk
- Files:
-
- 15 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
/code/branches/ppspickups1 (added) merged: 6552,6574-6575,6579,6607,6643,6645-6648,6681,6694,6703,6705-6706
- Property svn:mergeinfo changed
-
code/trunk/src/modules/pickup/Pickup.cc
r6540 r6709 39 39 #include "DroppedPickup.h" 40 40 41 #include "tools/Timer.h" 42 41 43 namespace orxonox 42 44 { 43 45 44 46 /*static*/ const std::string Pickup::activationTypeImmediate_s = "immediate"; 45 47 /*static*/ const std::string Pickup::activationTypeOnUse_s = "onUse"; 46 48 /*static*/ const std::string Pickup::durationTypeOnce_s = "once"; 47 49 /*static*/ const std::string Pickup::durationTypeContinuous_s = "continuous"; 48 50 49 51 Pickup::Pickup(BaseObject* creator) : BaseObject(creator) 50 52 { 51 53 RegisterObject(Pickup); 52 54 53 55 this->initialize(); 54 56 } 55 57 56 58 Pickup::~Pickup() 57 59 { 58 59 } 60 60 61 } 62 61 63 /** 62 64 @brief … … 68 70 this->durationType_ = pickupDurationType::once; 69 71 } 70 72 71 73 /** 72 74 @brief … … 74 76 */ 75 77 void Pickup::initializeIdentifier(void) 76 { 78 { 77 79 std::string val1 = this->getActivationType(); 78 80 std::string type1 = "activationType"; 79 81 this->pickupIdentifier_->addParameter(type1, val1); 80 82 81 83 std::string val2 = this->getDurationType(); 82 84 std::string type2 = "durationType"; 83 85 this->pickupIdentifier_->addParameter(type2, val2); 84 86 } 85 87 86 88 /** 87 89 @brief … … 94 96 XMLPortParam(Pickup, "activationType", setActivationType, getActivationType, xmlelement, mode); 95 97 XMLPortParam(Pickup, "durationType", setDurationType, getDurationType, xmlelement, mode); 96 98 97 99 this->initializeIdentifier(); 98 100 } 99 101 100 102 /** 101 103 @brief … … 116 118 } 117 119 } 118 120 119 121 /** 120 122 @brief … … 135 137 } 136 138 } 137 139 138 140 /** 139 141 @brief … … 157 159 } 158 160 } 159 161 160 162 /** 161 163 @brief … … 179 181 } 180 182 } 181 183 182 184 /** 183 185 @brief … … 188 190 { 189 191 SUPER(Pickup, changedPickedUp); 190 192 191 193 //! Sets the Pickup to used if the Pickup has activation type 'immediate' and gets picked up. 192 194 if(this->getCarrier() != NULL && this->isPickedUp() && this->isImmediate()) … … 195 197 } 196 198 } 197 199 198 200 /** 199 201 @brief … … 206 208 if(item == NULL) 207 209 item = new Pickup(this); 208 210 209 211 SUPER(Pickup, clone, item); 210 212 211 213 Pickup* pickup = dynamic_cast<Pickup*>(item); 212 214 pickup->setActivationTypeDirect(this->getActivationTypeDirect()); 213 215 pickup->setDurationTypeDirect(this->getDurationTypeDirect()); 214 216 215 217 pickup->initializeIdentifier(); 216 218 } 217 219 218 220 /** 219 221 @brief … … 231 233 return true; 232 234 } 233 235 236 /** 237 @brief 238 Starts the pickup duration timer. 239 After the specified durationTime has expired the function pickupTimerCallback is called. 240 pickupTimerCallback can be overloaded and thus the desired functionality can be implemented. 241 @param durationTime 242 The duration after which the expires and the callback function is called. 243 @return 244 Returns true if the pickup duration timer was started successfully, false if not. 245 */ 246 bool Pickup::startPickupTimer(float durationTime) 247 { 248 if (durationTime<=0) 249 { 250 COUT(1) << "Invalid durationTime in pickup." << std::endl; 251 return false; 252 } 253 if (this->durationTimer_.isActive()) //!< Check if Timer is already running 254 { 255 COUT(1) << "Pickup durationTimer already in use." << std::endl; 256 return false; 257 } 258 this->durationTimer_.setTimer(durationTime, false, createExecutor(createFunctor(&Pickup::pickupTimerCallback, this))); 259 return true; 260 } 234 261 } -
code/trunk/src/modules/pickup/Pickup.h
r6540 r6709 42 42 #include "interfaces/Pickupable.h" 43 43 44 #include "tools/Timer.h" 45 44 46 namespace orxonox 45 47 { … … 54 56 }; 55 57 } 56 58 57 59 //! Enum for the duration tyoe. 58 60 namespace pickupDurationType … … 64 66 }; 65 67 } 66 68 67 69 /** 68 70 @brief … … 74 76 class _PickupExport Pickup : public Pickupable, public BaseObject 75 77 { 76 78 77 79 protected: 78 80 Pickup(BaseObject* creator); //!< Constructor. 79 81 80 82 public: 81 83 virtual ~Pickup(); //!< Destructor. 82 84 83 85 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 84 86 85 87 /** 86 88 @brief Get the activation type of the pickup. … … 95 97 inline pickupDurationType::Value getDurationTypeDirect(void) 96 98 { return this->durationType_; } 97 99 98 100 const std::string& getActivationType(void); //!< Get the activation type of the pickup. 99 101 const std::string& getDurationType(void); //!< Get the duration type of the pickup. 100 102 101 103 /** 102 104 @brief Get whether the activation type is 'immediate'. … … 123 125 inline bool isContinuous(void) 124 126 { return this->getDurationTypeDirect() == pickupDurationType::continuous; } 125 127 126 128 virtual void changedPickedUp(void); //!< Should be called when the pickup has transited from picked up to dropped or the other way around. 127 129 128 130 virtual void clone(OrxonoxClass*& item); //!< Creates a duplicate of the Pickup. 129 131 130 132 protected: 131 133 void initializeIdentifier(void); 132 134 133 135 virtual bool createSpawner(void); //!< Facilitates the creation of a PickupSpawner upon dropping of the Pickupable. 134 136 137 bool startPickupTimer(float durationTime); 138 139 virtual void pickupTimerCallback(void) {} 140 135 141 /** 136 142 @brief Set the activation type of the pickup. … … 145 151 inline void setDurationTypeDirect(pickupDurationType::Value type) 146 152 { this->durationType_ = type; } 147 153 148 154 void setActivationType(const std::string& type); //!< Set the activation type of the pickup. 149 155 void setDurationType(const std::string& type); //!< Set the duration type of the pickup 150 156 151 157 private: 152 158 void initialize(void); //!< Initializes the member variables. 153 159 160 //TODO: Problems, when there are more Timers needed? Solutions? 161 Timer durationTimer_; //!< Timer at the disposal of each Class implementing Pickup. 162 154 163 pickupActivationType::Value activationType_; //!< The activation type of the Pickup. 155 164 pickupDurationType::Value durationType_; //!< The duration type of the pickup. 156 165 157 166 static const std::string activationTypeImmediate_s; 158 167 static const std::string activationTypeOnUse_s; 159 168 static const std::string durationTypeOnce_s; 160 169 static const std::string durationTypeContinuous_s; 161 162 170 }; 163 171 164 172 } 165 173 #endif // _Pickup_H__ -
code/trunk/src/modules/pickup/PickupPrereqs.h
r6524 r6709 73 73 class PickupRepresentation; 74 74 class PickupSpawner; 75 75 76 76 //items 77 77 class HealthPickup; 78 78 class MetaPickup; 79 79 class SpeedPickup; 80 80 81 } 81 82 -
code/trunk/src/modules/pickup/items/CMakeLists.txt
r6524 r6709 1 1 ADD_SOURCE_FILES(PICKUP_SRC_FILES 2 2 3 HealthPickup.cc 4 5 SpeedPickup.cc 3 6 MetaPickup.cc 7 4 8 ) -
code/trunk/src/modules/pickup/items/HealthPickup.cc
- Property svn:eol-style set to native
-
code/trunk/src/modules/pickup/items/HealthPickup.h
- Property svn:eol-style set to native
-
code/trunk/src/modules/pickup/items/MetaPickup.cc
- Property svn:eol-style set to native
-
code/trunk/src/modules/pickup/items/MetaPickup.h
- Property svn:eol-style set to native
-
code/trunk/src/orxonox/interfaces/PickupCarrier.h
r6563 r6709 47 47 namespace orxonox 48 48 { 49 50 //! Pre-declarations. 49 class Pickupable; 51 50 class Pickup; 52 51 class HealthPickup; 53 52 class MetaPickup; 53 class SpeedPickup; 54 54 55 55 /** … … 67 67 friend class HealthPickup; 68 68 friend class MetaPickup; 69 69 friend class SpeedPickup; 70 70 71 public: 71 72 PickupCarrier(); //!< Constructor. 72 73 virtual ~PickupCarrier(); //!< Destructor. 73 74 74 75 /** 75 76 @brief Can be called to pick up a Pickupable. … … 87 88 return pickedUp; 88 89 } 89 90 90 91 /** 91 92 @brief Can be called to drop a Pickupable. … … 95 96 */ 96 97 bool drop(Pickupable* pickup, bool drop = true) 97 { 98 { 98 99 bool dropped = this->pickups_.erase(pickup) == 1; 99 100 if(dropped && drop) … … 104 105 return dropped; 105 106 } 106 107 107 108 /** 108 109 @brief Can be used to check whether the PickupCarrier or a child of his is a target ot the input Pickupable. … … 114 115 if(pickup->isTarget(this)) //!< If the PickupCarrier itself is a target. 115 116 return true; 116 117 117 118 //! Go recursively through all children to check whether they are a target. 118 119 std::list<PickupCarrier*>* children = this->getCarrierChildren(); … … 122 123 return true; 123 124 } 124 125 125 126 children->clear(); 126 127 delete children; 127 128 128 129 return false; 129 130 } 130 131 131 132 /** 132 133 @brief Get the carrier that is both a child of the PickupCarrier (or the PickupCarrier itself) and a target of the input Pickupable. … … 138 139 if(!this->isTarget(pickup)) 139 140 return NULL; 140 141 141 142 if(pickup->isTarget(this)) //!< If the PickupCarrier itself is a target. 142 143 return this; 143 144 144 145 //! Go recursively through all children to check whether they are the target. 145 146 std::list<PickupCarrier*>* children = this->getCarrierChildren(); … … 149 150 return *it; 150 151 } 151 152 152 153 children->clear(); 153 154 delete children; 154 155 155 156 return NULL; 156 157 } 157 158 158 159 /** 159 160 @brief Get the (absolute) position of the PickupCarrier. … … 162 163 */ 163 164 virtual const Vector3& getCarrierPosition(void) = 0; 164 165 protected: 165 166 protected: 166 167 /** 167 168 @brief Get all direct children of this PickupSpawner. 168 169 This method needs to be implemented by any direct derivative class of PickupCarrier. 169 170 The returned list will be deleted by the methods calling this function. 170 @return Returns a pointer to a list of all direct children. 171 @return Returns a pointer to a list of all direct children. 171 172 */ 172 173 virtual std::list<PickupCarrier*>* getCarrierChildren(void) = 0; … … 177 178 */ 178 179 virtual PickupCarrier* getCarrierParent(void) = 0; 179 180 180 181 /** 181 182 @brief Get all Pickupables this PickupCarrier has. … … 184 185 std::set<Pickupable*>& getPickups(void) 185 186 { return this->pickups_; } 186 187 187 188 private: 188 189 std::set<Pickupable*> pickups_; //!< The list of Pickupables carried by this PickupCarrier. 189 190 190 191 }; 191 192 } -
code/trunk/src/orxonox/items/Engine.cc
r6540 r6709 64 64 this->boostBlur_ = 0; 65 65 66 this->speedAdd_ = 0.0; 67 this->speedMultiply_ = 1.0; 68 66 69 this->setConfigValues(); 67 70 this->registerVariables(); … … 119 122 registerVariable(this->accelerationLeftRight_, VariableDirection::ToClient); 120 123 registerVariable(this->accelerationUpDown_, VariableDirection::ToClient); 124 125 registerVariable(this->speedAdd_, VariableDirection::ToClient); 126 registerVariable(this->speedMultiply_, VariableDirection::ToClient); 121 127 } 122 128 … … 192 198 } 193 199 194 this->ship_->setAcceleration(this->ship_->getOrientation() * acceleration);200 this->ship_->setAcceleration(this->ship_->getOrientation() * (acceleration*this->getSpeedMultiply()+Vector3(0,0,-this->getSpeedAdd()))); 195 201 196 202 if (!this->ship_->getPermanentBoost()) … … 241 247 return Vector3::ZERO; 242 248 } 249 250 PickupCarrier* Engine::getCarrierParent(void) 251 { 252 return this->ship_; 253 } 254 255 const Vector3& Engine::getCarrierPosition(void) 256 { 257 return this->ship_->getWorldPosition(); 258 } 243 259 } -
code/trunk/src/orxonox/items/Engine.h
r6417 r6709 35 35 #include "Item.h" 36 36 37 #include "interfaces/PickupCarrier.h" 38 37 39 namespace orxonox 38 40 { 39 class _OrxonoxExport Engine : public Item, public Tickable 41 class _OrxonoxExport Engine : public Item, public Tickable, public PickupCarrier 40 42 { 41 43 public: … … 104 106 { return this->accelerationUpDown_; } 105 107 108 inline float getSpeedAdd(void) 109 { return this->speedAdd_; } 110 inline float getSpeedMultiply(void) 111 { return this->speedMultiply_; } 112 106 113 virtual const Vector3& getDirection() const; 114 115 virtual const Vector3& getCarrierPosition(void); 116 117 //TODO: Move to protected or private. How? 118 inline void setSpeedAdd(float speedAdd) 119 { this->speedAdd_=speedAdd; } 120 inline void setSpeedMultiply(float speedMultiply) 121 { this->speedMultiply_=speedMultiply; } 122 123 protected: 124 virtual std::list<PickupCarrier*>* getCarrierChildren(void) 125 { return new std::list<PickupCarrier*>(); } 126 virtual PickupCarrier* getCarrierParent(void); 107 127 108 128 private: … … 114 134 float boostFactor_; 115 135 float speedFactor_; 136 137 float speedAdd_; 138 float speedMultiply_; 116 139 117 140 float maxSpeedFront_; -
code/trunk/src/orxonox/items/MultiStateEngine.cc
r6417 r6709 129 129 else 130 130 this->state_ = Idle; 131 132 if (this->state_ == Idle && this->getSpeedAdd() > 0) 133 this->state_ = Normal; 131 134 } 132 135 -
code/trunk/src/orxonox/worldentities/pawns/SpaceShip.cc
r6417 r6709 220 220 engine->addToSpaceShip(this); 221 221 } 222 223 std::list<PickupCarrier*>* SpaceShip::getCarrierChildren(void) 224 { 225 std::list<PickupCarrier*>* list = new std::list<PickupCarrier*>(); 226 list->push_front(this->engine_); 227 return list; 228 } 222 229 } -
code/trunk/src/orxonox/worldentities/pawns/SpaceShip.h
r5781 r6709 86 86 87 87 protected: 88 virtual std::list<PickupCarrier*>* getCarrierChildren(void); 88 89 bool bInvertYAxis_; 89 90
Note: See TracChangeset
for help on using the changeset viewer.