Changeset 8706 for code/trunk/src/orxonox
- Timestamp:
- Jun 14, 2011, 8:53:28 PM (14 years ago)
- Location:
- code/trunk
- Files:
-
- 2 deleted
- 54 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/LevelManager.cc
r8079 r8706 222 222 this->nextLevel_ = this->availableLevels_.begin(); 223 223 } 224 224 225 while(this->nextIndex_ != index) 225 226 { -
code/trunk/src/orxonox/MoodManager.cc
r8351 r8706 93 93 94 94 95 std::string MoodListener::mood_s;96 97 95 MoodListener::MoodListener() 98 96 { … … 102 100 /*static*/ void MoodListener::changedMood(const std::string& mood) 103 101 { 104 mood_s = mood;105 102 for (ObjectList<MoodListener>::iterator it = ObjectList<MoodListener>::begin(); it; ++it) 106 it->moodChanged(mood _s);103 it->moodChanged(mood); 107 104 } 108 105 } -
code/trunk/src/orxonox/MoodManager.h
r7163 r8706 50 50 virtual ~MoodListener() {} 51 51 52 const std::string& getMood() const { return mood_s; }53 54 52 private: 55 53 virtual void moodChanged(const std::string& mood) = 0; 56 54 57 55 static void changedMood(const std::string& mood); 58 static std::string mood_s;59 56 }; 60 57 -
code/trunk/src/orxonox/collisionshapes/CollisionShape.cc
r7401 r8706 26 26 * 27 27 */ 28 29 /** 30 @file CollisionShape.cc 31 @brief Implementation of the CollisionShape class. 32 */ 28 33 29 34 #include "CollisionShape.h" … … 39 44 namespace orxonox 40 45 { 46 47 /** 48 @brief 49 Constructor. Registers and initializes the object. 50 */ 41 51 CollisionShape::CollisionShape(BaseObject* creator) 42 52 : BaseObject(creator) … … 51 61 this->orientation_ = Quaternion::IDENTITY; 52 62 this->scale_ = Vector3::UNIT_SCALE; 63 this->uniformScale_ = true; 53 64 54 65 this->registerVariables(); 55 66 } 56 67 68 /** 69 @brief 70 Destructor. Detaches the CollisionShape from its parent. 71 */ 57 72 CollisionShape::~CollisionShape() 58 73 { 59 // Detach from parent 74 // Detach from parent CompoundCollisionShape. 60 75 if (this->isInitialized() && this->parent_) 61 76 this->parent_->detach(this); … … 75 90 } 76 91 92 /** 93 @brief 94 Register variables that need synchronizing over the network. 95 */ 77 96 void CollisionShape::registerVariables() 78 97 { 98 // Keep the shape's parent (can be either a CompoundCollisionShape or a WorldEntity) consistent over the network. 79 99 registerVariable(this->parentID_, VariableDirection::ToClient, new NetworkCallback<CollisionShape>(this, &CollisionShape::parentChanged)); 80 100 } 81 101 102 /** 103 @brief 104 Notifies the CollisionShape of being attached to a CompoundCollisionShape. 105 @param newParent 106 A pointer to the CompoundCollisionShape the CollisionShape was attached to. 107 @return 108 Returns 109 */ 110 bool CollisionShape::notifyBeingAttached(CompoundCollisionShape* newParent) 111 { 112 // If the CollisionShape is attached to a CompoundCollisionShapes, detach it. 113 if (this->parent_) 114 this->parent_->detach(this); 115 116 this->parent_ = newParent; 117 118 // If the new parent is a WorldEntityCollisionShape, the parentID is set to the objectID of the WorldEntity that is its owner. 119 // TODO: Why? 120 WorldEntityCollisionShape* parentWECCS = orxonox_cast<WorldEntityCollisionShape*>(newParent); 121 if (parentWECCS) 122 this->parentID_ = parentWECCS->getWorldEntityOwner()->getObjectID(); 123 // Else it is set to the objectID of the CompoundCollisionShape. 124 else 125 this->parentID_ = newParent->getObjectID(); 126 127 return true; 128 } 129 130 /** 131 @brief 132 Notifies the CollisionShape of being detached from a CompoundCollisionShape. 133 */ 134 void CollisionShape::notifyDetached() 135 { 136 this->parent_ = 0; 137 this->parentID_ = OBJECTID_UNKNOWN; 138 } 139 140 /** 141 @brief 142 Updates the CompoundCollisionShape the CollisionShape belongs to (if it belongs to one), after the CollisionShape has changed. 143 */ 144 void CollisionShape::updateParent() 145 { 146 if (this->parent_) 147 this->parent_->updateAttachedShape(this); 148 } 149 150 /** 151 @brief 152 Is called when the parentID of the CollisionShape has changed. 153 Attaches it to the object with the changed parentID, which can either be a CompoundCollisionShape or a WorldEntity. 154 */ 82 155 void CollisionShape::parentChanged() 83 156 { 157 // Get the parent object from the network. 84 158 Synchronisable* parent = Synchronisable::getSynchronisable(this->parentID_); 159 85 160 // Parent can either be a WorldEntity or a CompoundCollisionShape. The reason is that the 86 161 // internal collision shape (which is compound) of a WE doesn't get synchronised. 87 162 CompoundCollisionShape* parentCCS = orxonox_cast<CompoundCollisionShape*>(parent); 163 164 // If the parent is a CompoundCollisionShape, attach the CollisionShape to it. 88 165 if (parentCCS) 89 166 parentCCS->attach(this); 90 167 else 91 168 { 169 // If the parent is a WorldEntity, attach the CollisionShape to its collision shapes. 92 170 WorldEntity* parentWE = orxonox_cast<WorldEntity*>(parent); 93 171 if (parentWE) … … 96 174 } 97 175 98 bool CollisionShape::notifyBeingAttached(CompoundCollisionShape* newParent) 99 { 100 if (this->parent_) 101 this->parent_->detach(this); 102 103 this->parent_ = newParent; 104 105 WorldEntityCollisionShape* parentWECCS = orxonox_cast<WorldEntityCollisionShape*>(newParent); 106 if (parentWECCS) 107 this->parentID_ = parentWECCS->getWorldEntityOwner()->getObjectID(); 108 else 109 this->parentID_ = newParent->getObjectID(); 110 111 return true; 112 } 113 114 void CollisionShape::notifyDetached() 115 { 116 this->parent_ = 0; 117 this->parentID_ = OBJECTID_UNKNOWN; 118 } 119 120 void CollisionShape::updateParent() 121 { 122 if (this->parent_) 123 this->parent_->updateAttachedShape(this); 124 } 125 176 /** 177 @brief 178 Check whether the CollisionShape has been either moved or rotated or both. (i.e. it doesn't have position zero and identity orientation any more) 179 @return 180 Returns true if it has been moved. 181 */ 126 182 bool CollisionShape::hasTransform() const 127 183 { … … 130 186 } 131 187 188 /** 189 @brief 190 Set the scale of the CollisionShape. 191 Since the scale is a vector the CollisionShape can be scaled independently in each direction, allowing for linear distortions. 192 If the scale changes, this causes the parent CompoundCollisionShape (if there is one) to be updated. 193 Beware, non-uniform scaling (i.e. distortions) might not be supported by all CollisionShapes. 194 @param scale 195 The new scale to be set. Vector3::UNIT_SCALE is the initial scale. 196 */ 132 197 void CollisionShape::setScale3D(const Vector3& scale) 133 198 { 134 CCOUT(2) << "Warning: Cannot set the scale of a collision shape: Not yet implemented." << std::endl; 135 } 136 199 if(this->scale_ == scale) 200 return; 201 202 // If the vectors are not in the same direction, then this is no longer a uniform scaling. 203 if(scale_.crossProduct(scale).squaredLength() != 0.0f) 204 { 205 CCOUT(2) << "Warning: Non-uniform scaling is not yet supported." << endl; 206 return; 207 } 208 209 this->scale_ = scale; 210 211 this->changedScale(); 212 this->updateParent(); 213 } 214 215 /** 216 @brief 217 Set the (uniform) scale of the CollisionShape. 218 If the scale changes, this causes the parent CompoundCollisionShape (if there is one) to be updated. 219 @param scale 220 The scale to scale the CollisionShape with. 1.0f is the initial scale. 221 */ 137 222 void CollisionShape::setScale(float scale) 138 223 { 139 CCOUT(2) << "Warning: Cannot set the scale of a collision shape: Not yet implemented." << std::endl; 140 } 141 224 if(this->scale_.length() == scale) 225 return; 226 227 this->scale_ = Vector3::UNIT_SCALE*scale; 228 229 this->changedScale(); 230 this->updateParent(); 231 } 232 233 /** 234 @brief 235 Is called when the scale of the CollisionShape has changed. 236 */ 237 void CollisionShape::changedScale() 238 { 239 // Adjust the position of the CollisionShape. 240 this->position_ *= this->getScale3D(); 241 } 242 243 /** 244 @brief 245 Updates the shape. 246 Is called when the internal parameters of the shape have changed such that a new shape needs to be created. 247 */ 142 248 void CollisionShape::updateShape() 143 249 { 144 250 btCollisionShape* oldShape = this->collisionShape_; 145 251 this->collisionShape_ = this->createNewShape(); 252 // If the CollisionShape has been rescaled, scale the shape to fit the current scale. 253 if(this->scale_ != Vector3::UNIT_SCALE) 254 this->changedScale(); 146 255 // When we recreate the shape, we have to inform the parent about this to update the shape 147 256 this->updateParent(); … … 150 259 } 151 260 261 /** 262 @brief 263 Calculates the local inertia of the collision shape. 264 @todo 265 Document. 266 */ 152 267 void CollisionShape::calculateLocalInertia(float mass, btVector3& inertia) const 153 268 { -
code/trunk/src/orxonox/collisionshapes/CollisionShape.h
r7163 r8706 27 27 */ 28 28 29 /** 30 @file CollisionShape.h 31 @brief Definition of the CollisionShape class. 32 @ingroup Collisionshapes 33 */ 34 29 35 #ifndef _CollisionShape_H__ 30 36 #define _CollisionShape_H__ … … 38 44 namespace orxonox 39 45 { 46 47 /** 48 @brief 49 Wrapper for bullet collision shape class btCollisionShape. 50 51 @author 52 Reto Grieder 53 54 @see btCollisionShape 55 @ingroup Collisionshapes 56 */ 40 57 class _OrxonoxExport CollisionShape : public BaseObject, public Synchronisable 41 58 { … … 46 63 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 47 64 65 /** 66 @brief Set the position of the CollisionShape. 67 If the position changes, this causes the parent CompoundCollisionShape (if there is one) to be updated. 68 @param position A vector indicating the new position. 69 */ 48 70 inline void setPosition(const Vector3& position) 49 { this->position_ = position; this->updateParent(); } 71 { if(this->position_ == position) return; this->position_ = position; this->updateParent(); } 72 /** 73 @brief Get the position of the CollisionShape. 74 @return Returns the position of the CollisionShape as a vector. 75 */ 50 76 inline const Vector3& getPosition() const 51 77 { return this->position_; } 52 78 79 /** 80 @brief Set the orientation of the CollisionShape. 81 If the orientation changes, this causes the parent CompoundCollisionShape (if there is one) to be updated. 82 @param orientation A quaternion indicating the new orientation. 83 */ 53 84 inline void setOrientation(const Quaternion& orientation) 54 { this->orientation_ = orientation; this->updateParent(); } 85 { if(this->orientation_ == orientation) return; this->orientation_ = orientation; this->updateParent(); } 86 /** 87 @brief Get the orientation of the CollisionShape. 88 @return Returns the orientation of the CollisionShape as a quaternion. 89 */ 55 90 inline const Quaternion& getOrientation() const 56 91 { return this->orientation_; } 57 92 58 void yaw(const Degree& angle) { this->setOrientation(this->orientation_ * Quaternion(angle, Vector3::UNIT_Y)); } 59 void pitch(const Degree& angle) { this->setOrientation(this->orientation_ * Quaternion(angle, Vector3::UNIT_X)); } 60 void roll(const Degree& angle) { this->setOrientation(this->orientation_ * Quaternion(angle, Vector3::UNIT_Z)); } 93 /** 94 @brief Rotate the CollisionShape around the y-axis by the specified angle. 95 If the orientation changes, this causes the parent CompoundCollisionShape (if there is one) to be updated. 96 @param angle The angle by which the CollisionShape is rotated. 97 */ 98 void yaw(const Degree& angle) 99 { this->setOrientation(this->orientation_ * Quaternion(angle, Vector3::UNIT_Y)); } 100 /** 101 @brief Rotate the CollisionShape around the x-axis by the specified angle. 102 If the orientation changes, this causes the parent CompoundCollisionShape (if there is one) to be updated. 103 @param angle The angle by which the CollisionShape is rotated. 104 */ 105 void pitch(const Degree& angle) 106 { this->setOrientation(this->orientation_ * Quaternion(angle, Vector3::UNIT_X)); } 107 /** 108 @brief Rotate the CollisionShape around the z-axis by the specified angle. 109 If the orientation changes, this causes the parent CompoundCollisionShape (if there is one) to be updated. 110 @param angle The angle by which the CollisionShape is rotated. 111 */ 112 void roll(const Degree& angle) 113 { this->setOrientation(this->orientation_ * Quaternion(angle, Vector3::UNIT_Z)); } 61 114 62 virtual void setScale3D(const Vector3& scale); 63 virtual void setScale(float scale); 115 /** 116 @brief Scale the CollisionShape by the input vector. 117 Since the scale is a vector the CollisionShape can be scaled independently in each direction, allowing for linear distortions. 118 If the scale changes, this causes the parent CompoundCollisionShape (if there is one) to be updated. 119 Beware, non-uniform scaling (i.e. distortions) might not be supported by all CollisionShapes. 120 @param scale The scaling vector by which the CollisionShape is scaled. 121 */ 122 inline void scale3D(const Vector3& scale) 123 { this->setScale3D(this->getScale3D()*scale); } 124 void setScale3D(const Vector3& scale); // Set the scale of the CollisionShape. 125 /** 126 @brief Get the scale of the CollisionShape. 127 @return Returns a vector indicating the scale of the CollisionShape. 128 */ 64 129 inline const Vector3& getScale3D() const 65 130 { return this->scale_; } 66 131 67 void updateShape(); 132 /** 133 @brief (Uniformly) scale the CollisionShape by the input scale. 134 If the scale changes, this causes the parent CompoundCollisionShape (if there is one) to be updated. 135 @param scale The value by which the CollisionShape is scaled. 136 */ 137 inline void scale(float scale) 138 { this->setScale3D(this->getScale3D()*scale); } 139 void setScale(float scale); // Set the (uniform) scale of the CollisionShape. 140 /** 141 @brief Get the (uniform) scale of the CollisionShape. 142 This is only meaningful if the CollisionShape has uniform scaling. 143 @return Returns the (uniform) scale of the CollisionShape. Returns 0.0f if the scaling is non-uniform. 144 */ 145 inline float getScale() 146 { if(this->hasUniformScaling()) return this->scale_.x; return 0.0f; } 68 147 69 void calculateLocalInertia(float mass, btVector3& inertia) const; 148 /** 149 @brief Check whether the CollisionShape is uniformly scaled. 150 @return Returns true if the CollisionShape is uniformly scaled, false if not. 151 */ 152 inline bool hasUniformScaling() 153 { return this->uniformScale_; } 154 virtual void changedScale(); // Is called when the scale of the CollisionShape has changed. 70 155 156 void updateShape(); // Updates the shape. 157 158 void calculateLocalInertia(float mass, btVector3& inertia) const; // Calculates the local inertia of the collision shape. 159 160 /** 161 @brief Get the bullet collision shape of this CollisionShape. 162 @return Returns a pointer to the bullet collision shape of this CollisionShape. 163 */ 71 164 inline btCollisionShape* getCollisionShape() const 72 165 { return this->collisionShape_; } 73 166 74 bool hasTransform() const; 167 bool hasTransform() const; // Check whether the CollisionShape has been either moved or rotated or both. 75 168 76 bool notifyBeingAttached(CompoundCollisionShape* newParent); 77 void notifyDetached(); 169 bool notifyBeingAttached(CompoundCollisionShape* newParent); // Notifies the CollisionShape of being attached to a CompoundCollisionShape. 170 void notifyDetached(); // Notifies the CollisionShape of being detached from a CompoundCollisionShape. 78 171 79 172 protected: 80 virtual void updateParent(); 81 virtual void parentChanged(); 173 virtual void updateParent(); // Updates the CompoundCollisionShape the CollisionShape belongs to, after the CollisionShape has changed. 174 virtual void parentChanged(); // Is called when the parentID of the CollisionShape has changed. 175 176 /** 177 @brief Create a new bullet collision shape depending on the internal parameters of the specific CollisionShape. 178 @return Returns a pointer to the new bullet collision shape. 179 */ 82 180 virtual btCollisionShape* createNewShape() const = 0; 83 181 84 btCollisionShape* collisionShape_; 85 CompoundCollisionShape* parent_; 86 unsigned int parentID_; 182 btCollisionShape* collisionShape_; //!< The bullet collision shape of this CollisionShape. 183 CompoundCollisionShape* parent_; //!< The CompoundCollisionShape this CollisionShape belongs to, NULL if it doesn't belong to one. 184 unsigned int parentID_; //!< The objectID of the parent of this CollisionShape, which can either be a CompoundCollisionShape or a WorldEntity. 87 185 88 186 private: 89 187 void registerVariables(); 90 188 91 Vector3 position_; 92 Quaternion orientation_; 93 Vector3 scale_; 189 Vector3 position_; //!< The position of the CollisionShape. 190 Quaternion orientation_; //!< The orientation of the CollisionShape. 191 Vector3 scale_; //!< The scale of the CollisionShape. 192 bool uniformScale_; //!< Whether the scale is uniform. 94 193 }; 95 194 } -
code/trunk/src/orxonox/collisionshapes/CompoundCollisionShape.cc
r5929 r8706 27 27 */ 28 28 29 /** 30 @file CompoundCollisionShape.cc 31 @brief Implementation of the CompoundCollisionShape class. 32 */ 33 29 34 #include "CompoundCollisionShape.h" 30 35 … … 39 44 CreateFactory(CompoundCollisionShape); 40 45 46 /** 47 @brief 48 Constructor. Registers and initializes the object. 49 */ 41 50 CompoundCollisionShape::CompoundCollisionShape(BaseObject* creator) : CollisionShape(creator) 42 51 { … … 46 55 } 47 56 57 /** 58 @brief 59 Destructor. 60 Deletes all its children. 61 */ 48 62 CompoundCollisionShape::~CompoundCollisionShape() 49 63 { … … 70 84 } 71 85 86 /** 87 @brief 88 Attach the input CollisionShape to the CompoundCollisionShape. 89 @param shape 90 A pointer to the CollisionShape that is to be attached. 91 */ 72 92 void CompoundCollisionShape::attach(CollisionShape* shape) 73 93 { 94 // If either the input shape is NULL or we try to attach the CollisionShape to itself. 74 95 if (!shape || static_cast<CollisionShape*>(this) == shape) 75 96 return; 97 76 98 if (this->attachedShapes_.find(shape) != this->attachedShapes_.end()) 77 99 { … … 80 102 } 81 103 104 // Notify the CollisionShape that it is being attached to the CompoundCollisionShape. 82 105 if (!shape->notifyBeingAttached(this)) 83 106 return; 84 107 108 // Attach it. 85 109 this->attachedShapes_[shape] = shape->getCollisionShape(); 86 110 111 // Only actually attach if we didn't pick a CompoundCollisionShape with no content. 87 112 if (shape->getCollisionShape()) 88 113 { 89 // Only actually attach if we didn't pick a CompoundCollisionShape with no content90 114 btTransform transf(multi_cast<btQuaternion>(shape->getOrientation()), multi_cast<btVector3>(shape->getPosition())); 115 // Add the btCollisionShape of the CollisionShape as a child shape to the btCompoundShape of the CompoundCollisionShape. 91 116 this->compoundShape_->addChildShape(transf, shape->getCollisionShape()); 92 117 … … 95 120 } 96 121 122 /** 123 @brief 124 Detach the input CollisionShape form the CompoundCollisionShape. 125 @param shape 126 A pointer to the CollisionShape to be detached. 127 */ 97 128 void CompoundCollisionShape::detach(CollisionShape* shape) 98 129 { 130 // If the input CollisionShape is actually attached. 99 131 if (this->attachedShapes_.find(shape) != this->attachedShapes_.end()) 100 132 { 101 133 this->attachedShapes_.erase(shape); 102 134 if (shape->getCollisionShape()) 103 this->compoundShape_->removeChildShape(shape->getCollisionShape()); 135 this->compoundShape_->removeChildShape(shape->getCollisionShape()); // TODO: Apparently this is broken? 104 136 shape->notifyDetached(); 105 137 … … 110 142 } 111 143 144 /** 145 @brief 146 Detach all attached CollisionShapes. 147 */ 112 148 void CompoundCollisionShape::detachAll() 113 149 { … … 116 152 } 117 153 154 /** 155 @brief 156 Update the input CollisionShape that is attached to the CompoundCollisionShape. 157 This is called when the input shape's internal collision shape (a btCollisionShape) has changed. 158 @param shape 159 A pointer to the CollisionShape to be updated. 160 */ 118 161 void CompoundCollisionShape::updateAttachedShape(CollisionShape* shape) 119 162 { 120 163 if (!shape) 121 164 return; 165 122 166 std::map<CollisionShape*, btCollisionShape*>::iterator it = this->attachedShapes_.find(shape); 167 // Check whether the input shape belongs to this CompoundCollisionShape. 123 168 if (it == this->attachedShapes_.end()) 124 169 { … … 129 174 // Remove old btCollisionShape, stored in the children map 130 175 if (it->second) 131 this->compoundShape_->removeChildShape(it->second); 176 this->compoundShape_->removeChildShape(it->second); // TODO: Apparently this is broken? 177 178 // Only actually attach if we didn't pick a CompoundCollisionShape with no content 132 179 if (shape->getCollisionShape()) 133 180 { 134 // Only actually attach if we didn't pick a CompoundCollisionShape with no content135 181 btTransform transf(multi_cast<btQuaternion>(shape->getOrientation()), multi_cast<btVector3>(shape->getPosition())); 136 182 this->compoundShape_->addChildShape(transf, shape->getCollisionShape()); … … 141 187 } 142 188 189 /** 190 @brief 191 Updates the public shape, the collision shape this CompoundCollisionShape has to the outside. 192 */ 143 193 void CompoundCollisionShape::updatePublicShape() 144 194 { 145 btCollisionShape* primitive = 0; 146 bool bPrimitive = true; 147 bool bEmpty = true; 195 btCollisionShape* primitive = 0; // The primitive shape, if there is one. 196 bool bPrimitive = true; // Whether the CompoundCollisionShape has just one non-empty CollisionShape. And that shape also has no transformation. 197 bool bEmpty = true; // Whether the CompoundCollisionShape is empty. 198 // Iterate over all CollisionShapes that belong to this CompoundCollisionShape. 148 199 for (std::map<CollisionShape*, btCollisionShape*>::const_iterator it = this->attachedShapes_.begin(); it != this->attachedShapes_.end(); ++it) 149 200 { 201 // TODO: Make sure this is correct. 150 202 if (it->second) 151 203 { 152 204 bEmpty = false; 153 if (!it->first->hasTransform() && !bPrimitive)205 if (!it->first->hasTransform() && bPrimitive) 154 206 primitive = it->second; 155 207 else 208 { 156 209 bPrimitive = false; 210 break; 211 } 157 212 } 158 213 } 214 215 // If there is no non-empty CollisionShape. 159 216 if (bEmpty) 160 217 { 218 // If there was none all along, nothing needs to be changed. 161 219 if (this->collisionShape_ == 0) 162 {163 this->collisionShape_ = 0;164 220 return; 165 }166 221 this->collisionShape_ = 0; 167 222 } 223 // If the CompoundCollisionShape is just a primitive. 224 // Only one shape to be added, no transform; return it directly. 168 225 else if (bPrimitive) 169 {170 // --> Only one shape to be added, no transform; return it directly171 226 this->collisionShape_ = primitive; 172 }227 // Make sure we use the compound shape when returning a btCollisionShape. 173 228 else 174 {175 // Make sure we use the compound shape when returning a btCollisionShape176 229 this->collisionShape_ = this->compoundShape_; 177 } 230 178 231 this->updateParent(); 179 232 } 180 233 234 /** 235 @brief 236 Get the attached CollisionShape at the given index. 237 @param index 238 The index of the desired CollisionShape. 239 @return 240 Returns a pointer to the attached CollisionShape at the given index. 241 */ 181 242 CollisionShape* CompoundCollisionShape::getAttachedShape(unsigned int index) const 182 243 { … … 190 251 return 0; 191 252 } 253 254 /** 255 @brief 256 Is called when the scale of the CompoundCollisionShape has changed. 257 Iterates over all attached CollisionShapes and scales them, then recomputes their compound shape. 258 */ 259 void CompoundCollisionShape::changedScale() 260 { 261 CollisionShape::changedScale(); 262 263 std::vector<CollisionShape*> shapes; 264 // Iterate through all attached CollisionShapes and add them to the list of shapes. 265 for(std::map<CollisionShape*, btCollisionShape*>::iterator it = this->attachedShapes_.begin(); it != this->attachedShapes_.end(); it++) 266 shapes.push_back(it->first); 267 268 // Delete the compound shape and create a new one. 269 delete this->compoundShape_; 270 this->compoundShape_ = new btCompoundShape(); 271 272 // Re-attach all CollisionShapes. 273 for(std::vector<CollisionShape*>::iterator it = shapes.begin(); it != shapes.end(); it++) 274 { 275 CollisionShape* shape = *it; 276 shape->setScale3D(this->getScale3D()); 277 // Only actually attach if we didn't pick a CompoundCollisionShape with no content. 278 if (shape->getCollisionShape()) 279 { 280 btTransform transf(multi_cast<btQuaternion>(shape->getOrientation()), multi_cast<btVector3>(shape->getPosition())); 281 // Add the btCollisionShape of the CollisionShape as a child shape to the btCompoundShape of the CompoundCollisionShape. 282 this->compoundShape_->addChildShape(transf, shape->getCollisionShape()); 283 } 284 } 285 286 this->updatePublicShape(); 287 288 /* 289 // Iterate through all attached CollisionShapes 290 for(std::map<CollisionShape*, btCollisionShape*>::const_iterator it = this->attachedShapes_.begin(); it != this->attachedShapes_.end(); it++) 291 { 292 // Rescale the CollisionShape. 293 it->first->setScale3D(this->getScale3D()); 294 this->updateAttachedShape(it->first); 295 } 296 297 this->updatePublicShape();*/ 298 } 192 299 } -
code/trunk/src/orxonox/collisionshapes/CompoundCollisionShape.h
r5781 r8706 27 27 */ 28 28 29 /** 30 @file CompoundCollisionShape.h 31 @brief Definition of the CompoundCollisionShape class. 32 @ingroup Collisionshapes 33 */ 34 29 35 #ifndef _CompoundCollisionShape_H__ 30 36 #define _CompoundCollisionShape_H__ … … 38 44 namespace orxonox 39 45 { 46 47 /** 48 @brief 49 Wrapper for the bullet compound collision shape class btCompoundShape. 50 51 @author 52 Reto Grieder 53 54 @see btCompoundShape 55 @ingroup Collisionshapes 56 */ 40 57 class _OrxonoxExport CompoundCollisionShape : public CollisionShape 41 58 { … … 53 70 void updateAttachedShape(CollisionShape* shape); 54 71 72 virtual void changedScale(); 73 55 74 private: 56 75 void updatePublicShape(); -
code/trunk/src/orxonox/collisionshapes/WorldEntityCollisionShape.cc
r5929 r8706 43 43 this->worldEntityOwner_ = creator; 44 44 // suppress synchronisation 45 this->setSyncMode( 0x0);45 this->setSyncMode(ObjectDirection::None); 46 46 } 47 47 -
code/trunk/src/orxonox/controllers/ArtificialController.cc
r8351 r8706 381 381 } 382 382 } 383 384 if (distance < 10) 385 { 386 this->positionReached(); 387 } 383 388 } 384 389 … … 387 392 this->moveToPosition(this->targetPosition_); 388 393 } 389 390 394 391 395 /** -
code/trunk/src/orxonox/controllers/ArtificialController.h
r7163 r8706 97 97 void moveToTargetPosition(); 98 98 99 virtual void positionReached() {} 100 99 101 void removeFromFormation(); 100 102 void unregisterSlave(); -
code/trunk/src/orxonox/controllers/Controller.h
r6417 r8706 50 50 { return this->player_; } 51 51 52 virtual inline void hit(Pawn* originator, btManifoldPoint& contactpoint, float damage) {}; 52 virtual void hit(Pawn* originator, btManifoldPoint& contactpoint, float damage) {}; 53 54 /* Override needed for different visual effects (e.g. in "NewHumanController.cc") depending on 55 the DIFFERENT AMOUNT OF DAMAGE done to the shield and to the health of "victim" (see Projectile.cc, Pawn.cc) 56 57 // virtual inline void hit(Pawn* originator, btManifoldPoint& contactpoint, float damage, float healthdamage, float shielddamage) {}; 58 */ 53 59 54 60 void setGodMode( bool mode ){ this->bGodMode_ = mode; } -
code/trunk/src/orxonox/controllers/HumanController.cc
r8079 r8706 42 42 extern const std::string __CC_fire_name = "fire"; 43 43 extern const std::string __CC_suicide_name = "suicide"; 44 const std::string __CC_boost_name = "boost"; 44 45 45 46 SetConsoleCommand("HumanController", "moveFrontBack", &HumanController::moveFrontBack ).addShortcut().setAsInputCommand(); … … 51 52 SetConsoleCommand("HumanController", __CC_fire_name, &HumanController::fire ).addShortcut().keybindMode(KeybindMode::OnHold); 52 53 SetConsoleCommand("HumanController", "reload", &HumanController::reload ).addShortcut(); 53 SetConsoleCommand("HumanController", "boost", &HumanController::boost).addShortcut().keybindMode(KeybindMode::OnHold);54 SetConsoleCommand("HumanController", __CC_boost_name, &HumanController::keepBoost ).addShortcut().keybindMode(KeybindMode::OnHold); 54 55 SetConsoleCommand("HumanController", "greet", &HumanController::greet ).addShortcut(); 55 56 SetConsoleCommand("HumanController", "switchCamera", &HumanController::switchCamera ).addShortcut(); … … 66 67 67 68 HumanController* HumanController::localController_s = 0; 69 /*static*/ const float HumanController::BOOSTING_TIME = 0.1f; 68 70 69 71 HumanController::HumanController(BaseObject* creator) : Controller(creator) … … 71 73 RegisterObject(HumanController); 72 74 73 controlPaused_ = false; 75 this->controlPaused_ = false; 76 this->boosting_ = false; 77 this->boosting_ = false; 74 78 75 79 HumanController::localController_s = this; 80 this->boostingTimeout_.setTimer(HumanController::BOOSTING_TIME, false, createExecutor(createFunctor(&HumanController::terminateBoosting, this))); 81 this->boostingTimeout_.stopTimer(); 76 82 } 77 83 … … 163 169 } 164 170 165 void HumanController::boost() 166 { 167 if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) 168 HumanController::localController_s->controllableEntity_->boost(); 171 /** 172 @brief 173 Static method,keeps boosting. 174 */ 175 /*static*/ void HumanController::keepBoost() 176 { 177 if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) 178 HumanController::localController_s->keepBoosting(); 179 } 180 181 /** 182 @brief 183 Starts, or keeps the boosting mode. 184 Resets the boosting timeout and ells the ControllableEntity to boost (or not boost anymore). 185 */ 186 void HumanController::keepBoosting(void) 187 { 188 if(this->boostingTimeout_.isActive()) 189 { 190 this->boostingTimeout_.stopTimer(); 191 this->boostingTimeout_.startTimer(); 192 } 193 else 194 { 195 this->boosting_ = true; 196 this->boostingTimeout_.startTimer(); 197 198 this->controllableEntity_->boost(this->boosting_); 199 COUT(4) << "Start boosting" << endl; 200 } 201 } 202 203 /** 204 @brief 205 Terminates the boosting mode. 206 */ 207 void HumanController::terminateBoosting(void) 208 { 209 this->boosting_ = false; 210 this->boostingTimeout_.stopTimer(); 211 212 this->controllableEntity_->boost(this->boosting_); 213 COUT(4) << "Stop boosting" << endl; 169 214 } 170 215 -
code/trunk/src/orxonox/controllers/HumanController.h
r8079 r8706 32 32 #include "OrxonoxPrereqs.h" 33 33 34 #include "tools/Timer.h" 34 35 #include "tools/interfaces/Tickable.h" 35 36 #include "Controller.h" … … 64 65 static void reload(); 65 66 66 static void boost(); 67 static void keepBoost(); // Static method, keeps boosting. 68 /** 69 @brief Check whether the HumanController is in boosting mode. 70 @return Returns true if it is, false if not. 71 */ 72 inline bool isBoosting(void) 73 { return this->boosting_; } 74 void keepBoosting(void); 75 void terminateBoosting(void); 76 67 77 static void greet(); 68 78 static void switchCamera(); … … 92 102 static HumanController* localController_s; 93 103 bool controlPaused_; 104 105 private: 106 bool boosting_; // Whether the HumanController is in boosting mode or not. 107 Timer boostingTimeout_; // A timer to check whether the player is no longer boosting. 108 static const float BOOSTING_TIME; // The time after it is checked, whether the player is no longer boosting. 109 94 110 }; // tolua_export 95 111 } // tolua_export -
code/trunk/src/orxonox/gamestates/GSRoot.cc
r8327 r8706 45 45 46 46 static const std::string __CC_setTimeFactor_name = "setTimeFactor"; 47 static const std::string __CC_getTimeFactor_name = "getTimeFactor"; 47 48 static const std::string __CC_setPause_name = "setPause"; 48 49 static const std::string __CC_pause_name = "pause"; … … 52 53 SetConsoleCommand("printObjects", &GSRoot::printObjects).hide(); 53 54 SetConsoleCommand(__CC_setTimeFactor_name, &GSRoot::setTimeFactor).accessLevel(AccessLevel::Master).defaultValues(1.0); 55 SetConsoleCommand(__CC_getTimeFactor_name, &GSRoot::getTimeFactor).accessLevel(AccessLevel::Master); 54 56 SetConsoleCommand(__CC_setPause_name, &GSRoot::setPause ).accessLevel(AccessLevel::Master).hide(); 55 57 SetConsoleCommand(__CC_pause_name, &GSRoot::pause ).accessLevel(AccessLevel::Master); … … 89 91 90 92 ModifyConsoleCommand(__CC_setTimeFactor_name).setObject(this); 93 ModifyConsoleCommand(__CC_getTimeFactor_name).setObject(this); 91 94 ModifyConsoleCommand(__CC_setPause_name).setObject(this); 92 95 ModifyConsoleCommand(__CC_pause_name).setObject(this); … … 96 99 { 97 100 ModifyConsoleCommand(__CC_setTimeFactor_name).setObject(0); 101 ModifyConsoleCommand(__CC_getTimeFactor_name).setObject(0); 98 102 ModifyConsoleCommand(__CC_setPause_name).setObject(0); 99 103 ModifyConsoleCommand(__CC_pause_name).setObject(0); … … 151 155 this->timeFactorPauseBackup_ = factor; 152 156 } 157 } 158 159 float GSRoot::getTimeFactor() 160 { 161 return TimeFactorListener::getTimeFactor(); 153 162 } 154 163 -
code/trunk/src/orxonox/gamestates/GSRoot.h
r8079 r8706 54 54 void pause(); 55 55 56 float getTimeFactor(); 57 56 58 static void delayedStartMainMenu(void); 57 59 -
code/trunk/src/orxonox/gametypes/Dynamicmatch.cc
r8327 r8706 151 151 //Give new pig boost 152 152 SpaceShip* spaceship = dynamic_cast<SpaceShip*>(victim); 153 if (spaceship && spaceship->getEngine()) 154 { 155 spaceship->getEngine()->setSpeedFactor(5); 156 WeakPtr<Engine>* ptr = new WeakPtr<Engine>(spaceship->getEngine()); 157 ExecutorPtr executor = createExecutor(createFunctor(&Dynamicmatch::resetSpeedFactor, this)); 158 executor->setDefaultValue(0, ptr); 159 new Timer(10, false, executor, true); 160 } 153 grantPigBoost(spaceship); 161 154 } 162 155 … … 252 245 //Give new pig boost 253 246 SpaceShip* spaceship = dynamic_cast<SpaceShip*>(victim); 254 if (spaceship && spaceship->getEngine()) 255 { 256 spaceship->getEngine()->setSpeedFactor(5); 257 WeakPtr<Engine>* ptr = new WeakPtr<Engine>(spaceship->getEngine()); 258 ExecutorPtr executor = createExecutor(createFunctor(&Dynamicmatch::resetSpeedFactor, this)); 259 executor->setDefaultValue(0, ptr); 260 new Timer(10, false, executor, true); 261 } 262 247 grantPigBoost(spaceship); 263 248 } 264 249 // killer vs piggy … … 321 306 } 322 307 308 void Dynamicmatch::grantPigBoost(orxonox::SpaceShip* spaceship) 309 { 310 // Give pig boost 311 if (spaceship) 312 { 313 spaceship->setSpeedFactor(5); 314 WeakPtr<SpaceShip>* ptr = new WeakPtr<SpaceShip>(spaceship); 315 ExecutorPtr executor = createExecutor(createFunctor(&Dynamicmatch::resetSpeedFactor, this)); 316 executor->setDefaultValue(0, ptr); 317 new Timer(10, false, executor, true); 318 } 319 } 320 323 321 void Dynamicmatch::playerStartsControllingPawn(PlayerInfo* player, Pawn* pawn) //set party + colouring 324 322 { … … 597 595 } 598 596 599 void Dynamicmatch::resetSpeedFactor(WeakPtr< Engine>* ptr)// helper function597 void Dynamicmatch::resetSpeedFactor(WeakPtr<SpaceShip>* ptr)// helper function 600 598 { 601 599 if (*ptr) -
code/trunk/src/orxonox/gametypes/Dynamicmatch.h
r7163 r8706 73 73 virtual void furtherInstructions();*/ 74 74 virtual void rewardPig(); 75 void resetSpeedFactor(WeakPtr<Engine>* ptr); 75 void grantPigBoost(SpaceShip* spaceship); // Added this, since it's used twice on different occasions. 76 void resetSpeedFactor(WeakPtr<SpaceShip>* ptr); 76 77 void tick (float dt);// used to end the game 77 78 SpawnPoint* getBestSpawnPoint(PlayerInfo* player) const; -
code/trunk/src/orxonox/gametypes/Gametype.cc
r8327 r8706 121 121 } 122 122 123 if (this->gtinfo_->bStartCountdownRunning_ && !this->gtinfo_->bStarted_) 124 this->gtinfo_->startCountdown_ -= dt; 125 126 if (!this->gtinfo_->bStarted_) 123 if (this->gtinfo_->isStartCountdownRunning() && !this->gtinfo_->hasStarted()) 124 this->gtinfo_->countdownStartCountdown(dt); 125 126 if (!this->gtinfo_->hasStarted()) 127 { 128 for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it) 129 { 130 // Inform the GametypeInfo that the player is ready to spawn. 131 if(it->first->isHumanPlayer() && it->first->isReadyToSpawn()) 132 this->gtinfo_->playerReadyToSpawn(it->first); 133 } 134 127 135 this->checkStart(); 128 else if (!this->gtinfo_->bEnded_) 136 } 137 else if (!this->gtinfo_->hasEnded()) 129 138 this->spawnDeadPlayersIfRequested(); 130 139 … … 136 145 this->addBots(this->numberOfBots_); 137 146 138 this->gtinfo_-> bStarted_ = true;147 this->gtinfo_->start(); 139 148 140 149 this->spawnPlayersIfRequested(); … … 143 152 void Gametype::end() 144 153 { 145 this->gtinfo_-> bEnded_ = true;154 this->gtinfo_->end(); 146 155 147 156 for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it) … … 173 182 { 174 183 this->players_[player].state_ = PlayerState::Joined; 184 this->gtinfo_->playerEntered(player); 175 185 } 176 186 … … 270 280 } 271 281 282 if(victim->getPlayer()->isHumanPlayer()) 283 this->gtinfo_->pawnKilled(victim->getPlayer()); 284 272 285 ControllableEntity* entity = this->defaultControllableEntity_.fabricate(victim->getCreator()); 273 286 if (victim->getCamera()) … … 306 319 SpawnPoint* Gametype::getBestSpawnPoint(PlayerInfo* player) const 307 320 { 321 // If there is at least one SpawnPoint. 308 322 if (this->spawnpoints_.size() > 0) 309 323 { 324 // Fallback spawn point if there is no active one, choose a random one. 310 325 SpawnPoint* fallbackSpawnPoint = NULL; 311 326 unsigned int randomspawn = static_cast<unsigned int>(rnd(static_cast<float>(this->spawnpoints_.size()))); 312 327 unsigned int index = 0; 313 std:: set<SpawnPoint*> activeSpawnPoints = this->spawnpoints_;328 std::vector<SpawnPoint*> activeSpawnPoints; 314 329 for (std::set<SpawnPoint*>::const_iterator it = this->spawnpoints_.begin(); it != this->spawnpoints_.end(); ++it) 315 330 { … … 317 332 fallbackSpawnPoint = (*it); 318 333 319 if ( !(*it)->isActive())320 activeSpawnPoints. erase(*it);334 if (*it != NULL && (*it)->isActive()) 335 activeSpawnPoints.push_back(*it); 321 336 322 337 ++index; 323 338 } 324 339 325 randomspawn = static_cast<unsigned int>(rnd(static_cast<float>(this->spawnpoints_.size()))); 326 index = 0; 327 for (std::set<SpawnPoint*>::const_iterator it = activeSpawnPoints.begin(); it != activeSpawnPoints.end(); ++it) 328 { 329 if (index == randomspawn) 330 return (*it); 331 332 ++index; 333 } 334 340 if(activeSpawnPoints.size() > 0) 341 { 342 randomspawn = static_cast<unsigned int>(rnd(static_cast<float>(activeSpawnPoints.size()))); 343 return activeSpawnPoints[randomspawn]; 344 } 345 346 COUT(2) << "Warning: Fallback SpawnPoint was used, because there were no active SpawnPoints." << endl; 335 347 return fallbackSpawnPoint; 336 348 } … … 346 358 it->second.state_ = PlayerState::Dead; 347 359 348 if (!it->first->isReadyToSpawn() || !this->gtinfo_-> bStarted_)360 if (!it->first->isReadyToSpawn() || !this->gtinfo_->hasStarted()) 349 361 { 350 362 this->spawnPlayerAsDefaultPawn(it->first); … … 357 369 void Gametype::checkStart() 358 370 { 359 if (!this->gtinfo_-> bStarted_)360 { 361 if (this->gtinfo_-> bStartCountdownRunning_)362 { 363 if (this->gtinfo_-> startCountdown_ <= 0)364 { 365 this->gtinfo_-> bStartCountdownRunning_ = false;366 this->gtinfo_->s tartCountdown_ = 0;371 if (!this->gtinfo_->hasStarted()) 372 { 373 if (this->gtinfo_->isStartCountdownRunning()) 374 { 375 if (this->gtinfo_->getStartCountdown() <= 0.0f) 376 { 377 this->gtinfo_->stopStartCountdown(); 378 this->gtinfo_->setStartCountdown(0.0f);; 367 379 this->start(); 368 380 } … … 389 401 // If in developer's mode, there is no start countdown. 390 402 if(Core::getInstance().inDevMode()) 391 this-> gtinfo_->startCountdown_ = 0;403 this->start(); 392 404 else 393 this->gtinfo_->s tartCountdown_ = this->initialStartCountdown_;394 this->gtinfo_-> bStartCountdownRunning_ = true;405 this->gtinfo_->setStartCountdown(this->initialStartCountdown_); 406 this->gtinfo_->startStartCountdown(); 395 407 } 396 408 } … … 402 414 { 403 415 for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it) 416 { 404 417 if (it->first->isReadyToSpawn() || this->bForceSpawn_) 405 418 this->spawnPlayer(it->first); 419 } 406 420 } 407 421 … … 422 436 player->startControl(spawnpoint->spawn()); 423 437 this->players_[player].state_ = PlayerState::Alive; 438 439 if(player->isHumanPlayer()) 440 this->gtinfo_->playerSpawned(player); 441 424 442 this->playerPostSpawn(player); 425 443 } -
code/trunk/src/orxonox/gametypes/Gametype.h
r8178 r8706 78 78 79 79 inline bool hasStarted() const 80 { return this->gtinfo_-> bStarted_; }80 { return this->gtinfo_->hasStarted(); } 81 81 inline bool hasEnded() const 82 { return this->gtinfo_-> bEnded_; }82 { return this->gtinfo_->hasEnded(); } 83 83 84 84 virtual void start(); … … 114 114 115 115 inline bool isStartCountdownRunning() const 116 { return this->gtinfo_-> bStartCountdownRunning_; }116 { return this->gtinfo_->isStartCountdownRunning(); } 117 117 inline float getStartCountdown() const 118 { return this->gtinfo_-> startCountdown_; }118 { return this->gtinfo_->getStartCountdown(); } 119 119 120 120 inline void setHUDTemplate(const std::string& name) 121 { this->gtinfo_-> hudtemplate_ = name; }121 { this->gtinfo_->setHUDTemplate(name); } 122 122 inline const std::string& getHUDTemplate() const 123 { return this->gtinfo_-> hudtemplate_; }123 { return this->gtinfo_->getHUDTemplate(); } 124 124 125 125 void addBots(unsigned int amount); -
code/trunk/src/orxonox/gametypes/LastTeamStanding.cc
r8351 r8706 55 55 this->setHUDTemplate("lastTeamStandingHUD"); 56 56 } 57 57 58 58 LastTeamStanding::~LastTeamStanding() 59 59 { 60 } 60 } 61 61 62 62 void LastTeamStanding::playerEntered(PlayerInfo* player) … … 69 69 else 70 70 playerLives_[player]=getMinLives();//new players only get minimum of lives */ 71 71 72 72 this->timeToAct_[player] = timeRemaining; 73 73 this->playerDelayTime_[player] = respawnDelay; 74 74 this->inGame_[player] = true; 75 75 unsigned int team = getTeam(player); 76 if( team < 0|| team > teams_) // make sure getTeam returns a regular value76 if(team >= eachTeamsPlayers.size()) // make sure getTeam returns a regular value 77 77 return; 78 78 if(this->eachTeamsPlayers[team]==0) //if a player is the first in his group, a new team is alive … … 91 91 this->inGame_.erase(player); 92 92 unsigned int team = getTeam(player); 93 if( team < 0|| team > teams_) // make sure getTeam returns a regular value93 if(team >= eachTeamsPlayers.size()) // make sure getTeam returns a regular value 94 94 return valid_player; 95 95 this->eachTeamsPlayers[team]--; // a player left the team … … 107 107 bool allow = TeamDeathmatch::allowPawnDeath(victim, originator); 108 108 if(!allow) {return allow;} 109 109 110 110 playerLives_[victim->getPlayer()] = playerLives_[victim->getPlayer()] - 1; //player lost a live 111 111 this->inGame_[victim->getPlayer()] = false; //if player dies, he isn't allowed to respawn immediately … … 113 113 { 114 114 unsigned int team = getTeam(victim->getPlayer()); 115 if(team < 0|| team > teams_) // make sure getTeam returns a regular value115 if(team >= eachTeamsPlayers.size()) // make sure getTeam returns a regular value 116 116 return allow; 117 117 this->eachTeamsPlayers[team]--; … … 140 140 const std::string& message = ""; // resets Camper-Warning-message 141 141 this->gtinfo_->sendFadingMessage(message,it->first->getClientID()); 142 } 142 } 143 143 } 144 144 return allow; … … 163 163 return; 164 164 TeamDeathmatch::playerStartsControllingPawn(player,pawn); 165 165 166 166 this->timeToAct_[player] = timeRemaining + 3.0f + respawnDelay;//reset timer 167 167 this->playerDelayTime_[player] = respawnDelay; 168 168 169 169 std::map<PlayerInfo*, Player>::iterator it = this->players_.find(player); 170 170 if (it != this->players_.end()) … … 174 174 const std::string& message = ""; // resets Camper-Warning-message 175 175 this->gtinfo_->sendFadingMessage(message,it->first->getClientID()); 176 } 176 } 177 177 } 178 178 … … 187 187 } 188 188 for (std::map<PlayerInfo*, float>::iterator it = this->timeToAct_.begin(); it != this->timeToAct_.end(); ++it) 189 { 189 { 190 190 if (playerGetLives(it->first) <= 0)//Players without lives shouldn't be affected by time. 191 continue; 191 continue; 192 192 it->second -= dt;//Decreases punishment time. 193 if (!inGame_[it->first])//Manages respawn delay - player is forced to respawn after the delaytime is used up. 193 if (!inGame_[it->first])//Manages respawn delay - player is forced to respawn after the delaytime is used up. 194 194 { 195 195 playerDelayTime_[it->first] -= dt; … … 309 309 return 0; 310 310 } 311 311 312 312 void LastTeamStanding::setConfigValues() 313 313 { -
code/trunk/src/orxonox/graphics/Billboard.cc
r7492 r8706 23 23 * Fabian 'x3n' Landau 24 24 * Co-authors: 25 * ...25 * Maurus Kaufmann 26 26 * 27 27 */ … … 30 30 31 31 #include "OgreBillboard.h" 32 #include "OgreBillboardSet.h"33 32 34 33 #include "core/CoreIncludes.h" … … 46 45 47 46 this->colour_ = ColourValue::White; 48 //this->rotation_ = 0;47 this->rotation_ = 0; 49 48 50 49 this->registerVariables(); … … 66 65 XMLPortParam(Billboard, "material", setMaterial, getMaterial, xmlelement, mode); 67 66 XMLPortParam(Billboard, "colour", setColour, getColour, xmlelement, mode).defaultValues(ColourValue::White); 68 //XMLPortParam(Billboard, "rotation", setRotation, getRotation, xmlelement, mode).defaultValues(0);67 XMLPortParam(Billboard, "rotation", setRotation, getRotation, xmlelement, mode).defaultValues(0); 69 68 } 70 69 … … 73 72 registerVariable(this->material_, VariableDirection::ToClient, new NetworkCallback<Billboard>(this, &Billboard::changedMaterial)); 74 73 registerVariable(this->colour_, VariableDirection::ToClient, new NetworkCallback<Billboard>(this, &Billboard::changedColour)); 75 //registerVariable(this->rotation_, VariableDirection::ToClient, new NetworkCallback<Billboard>(this, &Billboard::changedRotation));74 registerVariable(this->rotation_, VariableDirection::ToClient, new NetworkCallback<Billboard>(this, &Billboard::changedRotation)); 76 75 } 77 76 … … 89 88 this->attachOgreObject(this->billboard_.getBillboardSet()); 90 89 this->billboard_.setVisible(this->isVisible()); 91 //this->changedRotation();90 this->changedRotation(); 92 91 } 93 92 } … … 114 113 } 115 114 116 /* 115 117 116 void Billboard::changedRotation() 118 117 { … … 128 127 } 129 128 } 130 */ 129 131 130 132 131 void Billboard::changedVisibility() … … 136 135 this->billboard_.setVisible(this->isVisible()); 137 136 } 137 138 void Billboard::setBillboardType(Ogre::BillboardType bbt) 139 { 140 Ogre::BillboardSet* bSet = this->billboard_.getBillboardSet(); 141 if( bSet != NULL ) 142 { 143 bSet->setBillboardType(bbt); 144 } 145 } 146 147 void Billboard::setCommonDirection(Vector3 vec) 148 { 149 Ogre::BillboardSet* bSet = this->billboard_.getBillboardSet(); 150 if( bSet != NULL ) 151 { 152 bSet->setCommonDirection( vec ); 153 } 154 } 155 156 void Billboard::setCommonUpVector(Vector3 vec) 157 { 158 Ogre::BillboardSet* bSet = this->billboard_.getBillboardSet(); 159 if( bSet != NULL ) 160 { 161 bSet->setCommonUpVector( vec ); 162 } 163 } 164 165 void Billboard::setDefaultDimensions(float width, float height) 166 { 167 Ogre::BillboardSet* bSet = this->billboard_.getBillboardSet(); 168 if( bSet != NULL ) 169 { 170 bSet->setDefaultDimensions(width, height); 171 } 172 } 138 173 } -
code/trunk/src/orxonox/graphics/Billboard.h
r7492 r8706 23 23 * Fabian 'x3n' Landau 24 24 * Co-authors: 25 * ...25 * Maurus Kaufmann 26 26 * 27 27 */ … … 31 31 32 32 #include "OrxonoxPrereqs.h" 33 34 #include "OgreBillboardSet.h" 33 35 34 36 #include "util/Math.h" … … 62 64 { return this->colour_; } 63 65 64 /* 66 65 67 inline void setRotation(const Radian& rotation) 66 68 { this->rotation_ = rotation; this->changedRotation(); } 67 69 inline const Radian& getRotation() const 68 70 { return this->rotation_; } 69 */ 71 70 72 71 73 virtual void setTeamColour(const ColourValue& colour) 72 74 { this->setColour(colour); } 75 76 void setBillboardType(Ogre::BillboardType bbt); 77 78 void setCommonDirection(Vector3 vec); //!< normalised Vector vec as argument 79 80 void setCommonUpVector(Vector3 vec); //!< normalised Vector vec as argument 81 82 void setDefaultDimensions(float width, float height); 83 73 84 74 85 protected: … … 81 92 void registerVariables(); 82 93 void changedMaterial(); 83 //void changedRotation();94 void changedRotation(); 84 95 85 96 BillboardSet billboard_; 86 97 std::string material_; 87 98 ColourValue colour_; 88 //Radian rotation_;99 Radian rotation_; 89 100 }; 90 101 } -
code/trunk/src/orxonox/graphics/Camera.cc
r8079 r8706 71 71 this->lastDtLagged_ = false; 72 72 73 this->setSyncMode( 0x0);73 this->setSyncMode(ObjectDirection::None); 74 74 75 75 this->setConfigValues(); -
code/trunk/src/orxonox/graphics/Camera.h
r8079 r8706 40 40 namespace orxonox 41 41 { 42 class _OrxonoxExport Camera : public StaticEntity, public Tickable, public TimeFactorListener, public WindowEventListener 42 43 class _OrxonoxExport Camera : public StaticEntity, public Tickable, public TimeFactorListener, public WindowEventListener 43 44 { 44 45 friend class CameraManager; -
code/trunk/src/orxonox/infos/GametypeInfo.cc
r8327 r8706 23 23 * Fabian 'x3n' Landau 24 24 * Co-authors: 25 * ...25 * Damian 'Mozork' Frick 26 26 * 27 27 */ 28 29 /** 30 @file GametypeInfo.cc 31 @brief Implementation of the GametypeInfo class 32 */ 28 33 29 34 #include "GametypeInfo.h" … … 31 36 #include "core/CoreIncludes.h" 32 37 #include "core/GameMode.h" 38 #include "network/Host.h" 33 39 #include "network/NetworkFunction.h" 34 #include "network/Host.h" 40 #include "util/Convert.h" 41 42 #include "controllers/HumanController.h" 35 43 #include "interfaces/GametypeMessageListener.h" 44 #include "interfaces/NotificationListener.h" 45 46 #include "PlayerInfo.h" 36 47 37 48 namespace orxonox … … 45 56 registerMemberNetworkFunction(GametypeInfo, dispatchFadingMessage); 46 57 58 registerMemberNetworkFunction(GametypeInfo, changedReadyToSpawn); 59 registerMemberNetworkFunction(GametypeInfo, changedSpawned); 60 61 /*static*/ const std::string GametypeInfo::NOTIFICATION_SENDER("gameinfo"); 62 63 /** 64 @brief 65 Registers and initializes the object. 66 */ 47 67 GametypeInfo::GametypeInfo(BaseObject* creator) : Info(creator) 48 68 { 49 69 RegisterObject(GametypeInfo); 50 70 51 71 this->bStarted_ = false; 52 72 this->bEnded_ = false; 53 this->startCountdown_ = 0 ;73 this->startCountdown_ = 0.0f; 54 74 this->bStartCountdownRunning_ = false; 75 this->counter_ = 0; 76 this->spawned_ = false; 77 this->readyToSpawn_ = false; 55 78 56 79 this->registerVariables(); … … 63 86 void GametypeInfo::registerVariables() 64 87 { 65 registerVariable(this->bStarted_, VariableDirection::ToClient); 66 registerVariable(this->bEnded_, VariableDirection::ToClient); 88 registerVariable(this->bStarted_, VariableDirection::ToClient, new NetworkCallback<GametypeInfo>(this, &GametypeInfo::changedStarted)); 89 registerVariable(this->bEnded_, VariableDirection::ToClient, new NetworkCallback<GametypeInfo>(this, &GametypeInfo::changedEnded)); 90 registerVariable(this->bStartCountdownRunning_, VariableDirection::ToClient, new NetworkCallback<GametypeInfo>(this, &GametypeInfo::changedStartCountdownRunning)); 67 91 registerVariable(this->startCountdown_, VariableDirection::ToClient); 68 registerVariable(this-> bStartCountdownRunning_, VariableDirection::ToClient);92 registerVariable(this->counter_, VariableDirection::ToClient, new NetworkCallback<GametypeInfo>(this, &GametypeInfo::changedCountdownCounter)); 69 93 registerVariable(this->hudtemplate_, VariableDirection::ToClient); 70 94 } 95 96 /** 97 @brief 98 Is called when the game has changed to started. 99 */ 100 void GametypeInfo::changedStarted(void) 101 { 102 NotificationListener::sendCommand("clear", GametypeInfo::NOTIFICATION_SENDER); 103 } 104 105 /** 106 @brief 107 Is called when the game has changed to ended. 108 */ 109 void GametypeInfo::changedEnded(void) 110 { 111 // If the game has ended, a "Game has ended" notification is displayed. 112 if(this->hasEnded()) 113 NotificationListener::sendNotification("Game has ended", GametypeInfo::NOTIFICATION_SENDER); 114 } 115 116 /** 117 @brief 118 Is called when the start countdown has been either started or stopped. 119 */ 120 void GametypeInfo::changedStartCountdownRunning(void) 121 { 122 // Send first countdown notification if the countdown has started. 123 if(this->isReadyToSpawn() && !this->hasStarted() && this->isStartCountdownRunning() && !this->hasEnded()) 124 NotificationListener::sendNotification(multi_cast<std::string>(this->counter_), GametypeInfo::NOTIFICATION_SENDER); 125 } 126 127 /** 128 @brief 129 Is called when the start countdown counter has changed. 130 */ 131 void GametypeInfo::changedCountdownCounter(void) 132 { 133 // Send countdown notification if the counter has gone down. 134 if(this->isReadyToSpawn() && !this->hasStarted() && this->isStartCountdownRunning() && !this->hasEnded()) 135 NotificationListener::sendNotification(multi_cast<std::string>(this->counter_), GametypeInfo::NOTIFICATION_SENDER); 136 } 137 138 /** 139 @brief 140 Inform the GametypeInfo that the local player has changed its ready to spawn status. 141 @param ready 142 Whether the player has become ready to spawn or not. 143 */ 144 void GametypeInfo::changedReadyToSpawn(bool ready) 145 { 146 if(this->readyToSpawn_ == ready) 147 return; 148 149 this->readyToSpawn_ = ready; 150 151 // Send "Waiting for other players" if the player is ready to spawn but the game has not yet started nor is the countdown running. 152 if(this->readyToSpawn_ && !this->hasStarted() && !this->isStartCountdownRunning() && !this->hasEnded()) 153 NotificationListener::sendNotification("Waiting for other players", GametypeInfo::NOTIFICATION_SENDER); 154 // Send current countdown if the player is ready to spawn and the countdown has already started. 155 else if(this->readyToSpawn_ && !this->hasStarted() && this->isStartCountdownRunning() && !this->hasEnded()) 156 NotificationListener::sendNotification(multi_cast<std::string>(this->counter_), GametypeInfo::NOTIFICATION_SENDER); 157 } 158 159 /** 160 @brief 161 Inform the GametypeInfo that the game has started. 162 */ 163 void GametypeInfo::start(void) 164 { 165 if(this->bStarted_) 166 return; 167 168 this->bStarted_ = true; 169 this->changedStarted(); 170 } 171 172 /** 173 @brief 174 Inform the GametypeInfo that the game has ended. 175 */ 176 void GametypeInfo::end(void) 177 { 178 if(this->bEnded_) 179 return; 180 181 this->bEnded_ = true; 182 this->changedEnded(); 183 } 184 185 /** 186 @brief 187 Set the start countdown to the input value. 188 @param countdown 189 The countdown to be set. 190 */ 191 void GametypeInfo::setStartCountdown(float countdown) 192 { 193 if(this->startCountdown_ == countdown || countdown < 0.0f) 194 return; 195 196 this->startCountdown_ = countdown; 197 // Set the counter to the ceiling of the current countdown. 198 this->counter_ = std::ceil(countdown); 199 this->changedCountdownCounter(); 200 } 201 202 /** 203 @brief 204 Count down the start countdown by the specified value. 205 @param countDown 206 The amount by which we count down. 207 */ 208 void GametypeInfo::countdownStartCountdown(float countDown) 209 { 210 float newCountdown = this->startCountdown_ - countDown; 211 // If we have switched integers or arrived at zero, we also count down the start countdown counter. 212 if(ceil(newCountdown) != ceil(this->startCountdown_) || newCountdown <= 0.0f) 213 this->countDown(); 214 this->startCountdown_ = newCountdown; 215 } 216 217 /** 218 @brief 219 Count down the start countdown counter. 220 */ 221 void GametypeInfo::countDown() 222 { 223 if(this->counter_ == 0) 224 return; 225 226 this->counter_--; 227 this->changedCountdownCounter(); 228 } 229 230 /** 231 @brief 232 Inform the GametypeInfo about the start of the start countdown. 233 */ 234 void GametypeInfo::startStartCountdown(void) 235 { 236 if(GameMode::isMaster()) 237 { 238 if(this->bStartCountdownRunning_) 239 return; 240 241 this->bStartCountdownRunning_ = true; 242 this->changedStartCountdownRunning(); 243 } 244 } 245 246 /** 247 @brief 248 Inform the GametypeInfo about the stop of the start countdown. 249 */ 250 void GametypeInfo::stopStartCountdown(void) 251 { 252 if(GameMode::isMaster()) 253 { 254 if(!this->bStartCountdownRunning_) 255 return; 256 257 this->bStartCountdownRunning_ = false; 258 this->changedStartCountdownRunning(); 259 } 260 } 261 262 /** 263 @brief 264 Inform the GametypeInfo about a player that is ready to spawn. 265 @param player 266 The player that is ready to spawn. 267 */ 268 void GametypeInfo::playerReadyToSpawn(PlayerInfo* player) 269 { 270 if(GameMode::isMaster()) 271 { 272 // If the player has spawned already. 273 if(this->spawnedPlayers_.find(player) != this->spawnedPlayers_.end()) 274 return; 275 276 this->spawnedPlayers_.insert(player); 277 this->setReadyToSpawnHelper(player, true); 278 } 279 } 280 281 /** 282 @brief 283 Inform the GametypeInfo about a player whose Pawn has been killed. 284 @param player 285 The player whose Pawn has been killed. 286 */ 287 void GametypeInfo::pawnKilled(PlayerInfo* player) 288 { 289 if(GameMode::isMaster()) 290 { 291 NotificationListener::sendNotification("Press [Fire] to respawn", GametypeInfo::NOTIFICATION_SENDER, notificationMessageType::info, notificationSendMode::network, player->getClientID()); 292 // Remove the player from the list of players that have spawned, since it currently is not. 293 this->spawnedPlayers_.erase(player); 294 this->setReadyToSpawnHelper(player, false); 295 this->setSpawnedHelper(player, false); 296 } 297 } 298 299 /** 300 @brief 301 Inform the GametypeInfo about a player that has spawned. 302 @param player 303 The player that has spawned. 304 */ 305 void GametypeInfo::playerSpawned(PlayerInfo* player) 306 { 307 if(GameMode::isMaster()) 308 { 309 if(this->hasStarted() && !this->hasEnded()) 310 311 this->setSpawnedHelper(player, true); 312 } 313 } 314 315 /** 316 @brief 317 Inform the GametypeInfo that the local player has changed its spawned status. 318 @param spawned 319 Whether the local player has changed to spawned or to not spawned. 320 */ 321 void GametypeInfo::changedSpawned(bool spawned) 322 { 323 if(this->spawned_ == spawned) 324 return; 325 326 this->spawned_ = spawned; 327 // Clear the notifications if the Player has spawned. 328 if(this->spawned_ && !this->hasEnded()) 329 NotificationListener::sendCommand("clear", GametypeInfo::NOTIFICATION_SENDER); 330 } 331 332 /** 333 @brief 334 Inform the GametypeInfo about a player that has entered, 335 @param player 336 The player that has entered. 337 */ 338 void GametypeInfo::playerEntered(PlayerInfo* player) 339 { 340 if(GameMode::isMaster()) 341 { 342 if( player->isHumanPlayer() ) 343 { 344 // Display "Press [Fire] to start the match" if the game has not yet ended. 345 if(!this->hasEnded()) 346 NotificationListener::sendNotification("Press [Fire] to start the match", GametypeInfo::NOTIFICATION_SENDER, notificationMessageType::info, notificationSendMode::network, player->getClientID()); 347 // Else display "Game has ended". 348 else 349 NotificationListener::sendNotification("Game has ended", GametypeInfo::NOTIFICATION_SENDER, notificationMessageType::info, notificationSendMode::network, player->getClientID()); 350 } 351 } 352 } 353 354 /** 355 @brief 356 Helper method. Sends changedReadyToSpawn notifiers over the network. 357 @param player 358 The player that has changed its ready to spawn status. 359 @param ready 360 The new ready to spawn status. 361 */ 362 void GametypeInfo::setReadyToSpawnHelper(PlayerInfo* player, bool ready) 363 { 364 if(GameMode::isMaster()) 365 { 366 if(player->getClientID() == CLIENTID_SERVER) 367 this->changedReadyToSpawn(ready); 368 else 369 callMemberNetworkFunction(GametypeInfo, changedReadyToSpawn, this->getObjectID(), player->getClientID(), ready); 370 } 371 } 372 373 /** 374 @brief 375 Helper method. Sends changedSpawned notifiers over the network. 376 @param player 377 The player that has changed its spawned status. 378 @param ready 379 The new spawned status. 380 */ 381 void GametypeInfo::setSpawnedHelper(PlayerInfo* player, bool spawned) 382 { 383 if(GameMode::isMaster()) 384 { 385 if(player->getClientID() == CLIENTID_SERVER) 386 this->changedSpawned(spawned); 387 else 388 callMemberNetworkFunction(GametypeInfo, changedSpawned, this->getObjectID(), player->getClientID(), spawned); 389 } 390 } 391 392 // Announce messages. 393 // TODO: Replace with notifications. 71 394 72 395 void GametypeInfo::sendAnnounceMessage(const std::string& message) -
code/trunk/src/orxonox/infos/GametypeInfo.h
r7163 r8706 23 23 * Fabian 'x3n' Landau 24 24 * Co-authors: 25 * ...25 * Damian 'Mozork' Frick 26 26 * 27 27 */ 28 29 /** 30 @file GametypeInfo.h 31 @brief Definition of the GametypeInfo class 32 */ 28 33 29 34 #ifndef _GametypeInfo_H__ … … 33 38 34 39 #include <string> 40 35 41 #include "Info.h" 36 42 37 43 namespace orxonox 38 44 { 45 46 /** 47 @brief 48 The GametypeInfo class keeps track of the state of the game and provides facilities to inform the player about it. 49 50 @author 51 Fabian 'x3n' Landau 52 @author 53 Damian 'Mozork' Frick 54 */ 39 55 class _OrxonoxExport GametypeInfo : public Info 40 56 { … … 45 61 virtual ~GametypeInfo(); 46 62 63 /** 64 @brief Get whether the game has started yet. 65 @return Returns true if the game has started, false if not. 66 */ 47 67 inline bool hasStarted() const 48 68 { return this->bStarted_; } 69 void changedStarted(void); // Is called when the game has changed to started. 70 71 /** 72 @brief Get whether the game has ended yet. 73 @return Returns true if the game has ended, false if not. 74 */ 49 75 inline bool hasEnded() const 50 76 { return this->bEnded_; } 77 void changedEnded(void); // Is called when the game has changed to ended. 51 78 79 /** 80 @brief Get whether the start countdown is currently running. 81 @return Returns true if the countdown is running, false if not. 82 */ 52 83 inline bool isStartCountdownRunning() const 53 84 { return this->bStartCountdownRunning_; } 85 void changedStartCountdownRunning(void); // Is called when the start countdown has been either started or stopped. 86 87 /** 88 @brief Get the current value of the start countdown. 89 @return Returns the current value of the start countdown. 90 */ 54 91 inline float getStartCountdown() const 55 92 { return this->startCountdown_; } 93 94 /** 95 @brief Get the current start countdown counter. 96 The start countdown counter only has integer values that correspond to the actually displayed countdown. 97 @return Returns the current integer countdown counter. 98 */ 99 inline unsigned int getStartCountdownCounter() const 100 { return this->counter_; } 101 void changedCountdownCounter(void); // Is called when the start countdown counter has changed. 102 103 /** 104 @brief Get whether the local player is ready to spawn. 105 @return Returns true if the player is ready to spawn, false if not. 106 */ 107 inline bool isReadyToSpawn() const 108 { return this->readyToSpawn_; } 109 void changedReadyToSpawn(bool ready); // Inform the GametypeInfo that the local player has changed its spawned status. 110 111 /** 112 @brief Get whether the local player is spawned. 113 @return Returns true if the local player is currently spawned, false if not. 114 */ 115 inline bool isSpawned() const 116 { return this->spawned_; } 117 void changedSpawned(bool spawned); // Inform the GametypeInfo that the local player has changed its spawned status. 56 118 57 119 inline const std::string& getHUDTemplate() const … … 70 132 void dispatchStaticMessage(const std::string& message,const ColourValue& colour); 71 133 void dispatchFadingMessage(const std::string& message); 134 135 protected: 136 void start(void); // Inform the GametypeInfo that the game has started. 137 void end(void); // Inform the GametypeInfo that the game has ended. 138 void setStartCountdown(float countdown); // Set the start countdown to the input value. 139 void countdownStartCountdown(float countDown); // Count down the start countdown by the specified value. 140 void countDown(); // Count down the start countdown counter. 141 void startStartCountdown(void); // Inform the GametypeInfo about the start of the start countdown. 142 void stopStartCountdown(void); // Inform the GametypeInfo about the stop of the start countdown. 143 void playerReadyToSpawn(PlayerInfo* player); // Inform the GametypeInfo about a player that is ready to spawn. 144 void pawnKilled(PlayerInfo* player); // Inform the GametypeInfo about a player whose Pawn has been killed. 145 void playerSpawned(PlayerInfo* player); // Inform the GametypeInfo about a player that has spawned. 146 void playerEntered(PlayerInfo* player); // Inform the GametypeInfo about a player that has entered, 147 148 inline void setHUDTemplate(const std::string& templateName) 149 { this->hudtemplate_ = templateName; }; 72 150 73 151 private: 74 152 void registerVariables(); 153 void setSpawnedHelper(PlayerInfo* player, bool spawned); // Helper method. Sends changedReadyToSpawn notifiers over the network. 154 void setReadyToSpawnHelper(PlayerInfo* player, bool ready); // Helper method. Sends changedSpawned notifiers over the network. 75 155 76 bool bStarted_; 77 bool bEnded_; 78 bool bStartCountdownRunning_; 79 float startCountdown_; 156 static const std::string NOTIFICATION_SENDER; //!< The name of the sender for the sending of notifications. 157 158 bool bStarted_; //!< Whether the game has started, 159 bool bEnded_; //!< Whether the game has ended. 160 bool bStartCountdownRunning_; //!< Whether the start countdown is running. 161 float startCountdown_; //!< The current value of the start countdown. 162 unsigned int counter_; //!< The current integer value of the start countdown, the start countdown counter. 80 163 std::string hudtemplate_; 164 165 std::set<PlayerInfo*> spawnedPlayers_; //!< A set of players that are currently spawned. 166 bool spawned_; //!< Whether the local Player is currently spawned. 167 bool readyToSpawn_; //!< Whether the local Player is ready to spawn. 81 168 }; 82 169 } -
code/trunk/src/orxonox/infos/PlayerInfo.cc
r8327 r8706 51 51 this->controllableEntity_ = 0; 52 52 this->controllableEntityID_ = OBJECTID_UNKNOWN; 53 this->oldControllableEntity_ = 0;54 53 55 54 this->gtinfo_ = 0; … … 151 150 return; 152 151 153 if (this->oldControllableEntity_)152 while (this->previousControllableEntity_.size() > 0) 154 153 this->stopTemporaryControl(); 154 155 155 if (this->controllableEntity_) 156 156 this->stopControl(); … … 177 177 return; 178 178 179 assert( this->oldControllableEntity_==0 ); 180 181 this->oldControllableEntity_ = this->controllableEntity_; 179 this->controllableEntity_->destroyHud(); // HACK-ish 180 this->previousControllableEntity_.push_back(WeakPtr<ControllableEntity>(this->controllableEntity_)); 182 181 this->controllableEntity_ = entity; 183 182 this->controllableEntityID_ = entity->getObjectID(); … … 194 193 void PlayerInfo::stopControl() 195 194 { 196 if ( this->oldControllableEntity_)195 while ( this->previousControllableEntity_.size() > 0) 197 196 this->stopTemporaryControl(); 198 197 … … 215 214 } 216 215 216 void PlayerInfo::pauseControl() 217 { 218 ControllableEntity* entity = this->controllableEntity_; 219 220 if (!entity) 221 return; 222 223 this->controllableEntity_->getController()->setActive(false); 224 //this->controllableEntity_->getController()->setControllableEntity(NULL); 225 this->controllableEntity_->setController(0); 226 } 227 217 228 void PlayerInfo::stopTemporaryControl() 218 229 { 219 230 ControllableEntity* entity = this->controllableEntity_; 220 231 221 assert( this->controllableEntity_ && this->oldControllableEntity_);222 if( !entity || !this->oldControllableEntity_)232 assert(this->controllableEntity_ != NULL); 233 if( !entity || this->previousControllableEntity_.size() == 0 ) 223 234 return; 224 235 225 236 this->controllableEntity_->setController(0); 237 this->controllableEntity_->destroyHud(); // HACK-ish 226 238 227 this->controllableEntity_ = this->oldControllableEntity_; 239 // this->controllableEntity_ = this->previousControllableEntity_.back(); 240 do { 241 this->controllableEntity_ = this->previousControllableEntity_.back(); 242 } while(this->controllableEntity_ == NULL && this->previousControllableEntity_.size() > 0); 228 243 this->controllableEntityID_ = this->controllableEntity_->getObjectID(); 229 this-> oldControllableEntity_ = 0;230 231 if ( this->controllableEntity_ && this->controller_)244 this->previousControllableEntity_.pop_back(); 245 246 if ( this->controllableEntity_ != NULL && this->controller_ != NULL) 232 247 this->controller_->setControllableEntity(this->controllableEntity_); 248 249 // HACK-ish 250 if(this->controllableEntity_ != NULL) 251 this->controllableEntity_->createHud(); 233 252 234 253 if ( GameMode::isMaster() ) -
code/trunk/src/orxonox/infos/PlayerInfo.h
r7163 r8706 68 68 void startControl(ControllableEntity* entity); 69 69 void stopControl(); 70 void pauseControl(); 70 71 void startTemporaryControl(ControllableEntity* entity); 71 72 void stopTemporaryControl(); … … 98 99 Controller* controller_; 99 100 ControllableEntity* controllableEntity_; 100 ControllableEntity* oldControllableEntity_;101 std::vector< WeakPtr<ControllableEntity> > previousControllableEntity_; //!< List of the previous ControllableEntities if repeatedly startTemporary control was called. The ControllableEntity at the back is the most recent. 101 102 unsigned int controllableEntityID_; 102 103 -
code/trunk/src/orxonox/interfaces/CMakeLists.txt
r7504 r8706 1 1 ADD_SOURCE_FILES(ORXONOX_SRC_FILES 2 2 InterfaceCompilation.cc 3 NotificationListener.cc 3 4 Pickupable.cc 4 5 PickupCarrier.cc -
code/trunk/src/orxonox/interfaces/InterfaceCompilation.cc
r7606 r8706 42 42 #include "core/CoreIncludes.h" 43 43 44 #include "infos/PlayerInfo.h" 45 #include "worldentities/pawns/Pawn.h" 46 44 47 namespace orxonox 45 48 { … … 59 62 RegisterRootObject(PlayerTrigger); 60 63 61 this->player_ = NULL;62 64 this->isForPlayer_ = false; 65 } 66 67 void PlayerTrigger::setTriggeringPawn(Pawn* pawn) 68 { 69 assert(pawn); 70 this->pawn_ = WeakPtr<Pawn>(pawn); 71 if (pawn) 72 this->player_ = WeakPtr<PlayerInfo>(pawn->getPlayer()); 63 73 } 64 74 … … 86 96 RegisterRootObject(Rewardable); 87 97 } 88 89 //----------------------------90 // NotificationListener91 //----------------------------92 NotificationListener::NotificationListener()93 {94 RegisterRootObject(NotificationListener);95 }96 98 } -
code/trunk/src/orxonox/interfaces/NotificationListener.h
r7552 r8706 21 21 * 22 22 * Author: 23 * Fabian 'x3n' Landau23 * Damian 'Mozork' Frick 24 24 * Co-authors: 25 25 * ... … … 48 48 namespace orxonox 49 49 { 50 class Notification; 50 // TODO: Document. 51 namespace notificationMessageType 52 { 53 enum Value { 54 info, 55 important 56 }; 57 } 58 59 namespace notificationSendMode 60 { 61 enum Value { 62 local, 63 network, 64 broadcast 65 }; 66 } 67 68 namespace notificationCommand 69 { 70 enum Value { 71 none, 72 clear 73 }; 74 } 51 75 76 // TODO: Update doc. 52 77 /** 53 78 @brief 54 79 NotificationListener interface. 55 80 56 The NotificationListener interface presents a means to being informed when @ref orxonox::Notification "Notifications" in the target set of this NotificationListener change. (e.g. @ref orxonox::Notification "Notifications" were added or removed) 57 When inheriting from a NotificationListener it is important to register (in the constructor) and unregister (in the destructor) it to and from the @ref orxonox::NotificationManager "NotificationManager". 81 The NotificationListener interface (or more precisely abstract class) presents a means of being informed when a new @ref orxonox::Notification "Notification" is sent. 82 The NotificationListener can be used to send a new notification message (with NotificationListener::sendNotification() ) or a new notification command (with NotificationListener::sendCommand() ). Each NotificationListener is then informed about the new @ref orxonox::Notification "Notification" and can take appropriate action. Currently the only NotificationListener ist the @ref orxonox::NotificationManager "NotificationManager" singleton. 83 84 When inheriting from a NotificationListener it is important to provide an appropriate implementation of registerNotification() and executeCommand(). 58 85 59 86 @author 60 Fabian 'x3n' Landau61 87 Damian 'Mozork' Frick 88 62 89 @ingroup Notifications 90 @todo Consistent terminology between message, notification and command. 63 91 */ 64 92 class _OrxonoxExport NotificationListener : virtual public OrxonoxClass … … 69 97 70 98 /** 71 @brief Get the senders that are targets of this NotificationListener. 72 @return Returns the set of senders that are targets of this NotificationListener. 99 @brief Sends a Notification with the specified message to the specified client from the specified sender. 100 @param message The message that should be sent. 101 @param sender The sender that sent the notification. Default is 'none'. 102 @param messageType The type of the message, can be either 'info' or 'important'. Default is 'info'. 103 @param sendMode The mode in which the notification is sent, can be 'local' to send the notification to the client where this function is executed, 'network' if the notification is to be sent to the client with the specified clientID, or 'broadcast' if the notification should be sent to all hosts. Default is notificationSendMode::local. 104 @param clientId The id of the client the notification should be sent to. Default is 0. 73 105 */ 74 virtual const std::set<std::string> & getTargetsSet(void) = 0; 106 static void sendNotification(const std::string& message, const std::string& sender = NotificationListener::NONE, notificationMessageType::Value messageType = notificationMessageType::info, notificationSendMode::Value sendMode = notificationSendMode::local, unsigned int clientId = 0) 107 { NotificationListener::sendNetworkHelper(message, sender, sendMode, clientId, false, messageType); } 108 /** 109 @brief Sends a specified command to the specified client from the specified sender. 110 @param command The command that should be sent (and later executed). 111 @param sender The sender that sent the notification. Default is 'none'. 112 @param sendMode The mode in which the command is sent, can be 'local' to send the command to the client where this function is executed, 'network' if the command is to be sent to the client with the specified clientID, or 'broadcast' if the command should be sent to all hosts. Default is notificationSendMode::local. 113 @param clientId The id of the client the command should be sent to. Default is 0. 114 */ 115 static void sendCommand(const std::string& command, const std::string& sender = NotificationListener::NONE, notificationSendMode::Value sendMode = notificationSendMode::local, unsigned int clientId = 0) 116 { NotificationListener::sendNetworkHelper(command, sender, sendMode, clientId, true); } 75 117 118 static void sendHelper(const std::string& message, const std::string& sender, bool isCommand = false, unsigned int messageMode = 0); // Helper method to register a notification/execute a command with all NotificationListeners after it has been sent over the network. 119 120 //TODO: Make protected? 121 76 122 /** 77 @brief Updates the whole NotificationListener. 78 This is called by the @ref orxonox::NotificationManager "NotificationManager" when the @ref orxonox::Notification "Notifications" have changed so much, that the NotificationListener may have to re-initialize his operations. 123 @brief Registers a notification with the NotificationListener. 124 This needs to be overloaded by each class inheriting from NotificationListener. 125 @param message The notification's message. 126 @param sender The sender of the notification. 127 @param type The type of the notification. 128 @return Returns true if the notification was successfully registered, false if not. 79 129 */ 80 virtual void update(void) = 0; 130 virtual bool registerNotification(const std::string& message, const std::string& sender, notificationMessageType::Value type) 131 { return false; } 81 132 /** 82 @brief Updates the NotificationListener, when a new Notification has come in at the specified time. 83 @param notification A pointer to the @ref orxonox::Notification "Notification". 84 @param time The time the @ref orxonox::Notification "Notification" has come in. 133 @brief Executes a command with the NotificationListener 134 This needs to be overloaded by each class inheriting from NotificationListener. 135 @param command The command to be executed. 136 @param sender The sender of the command. 137 @return Returns true if the command was successfully executed, false if not. 85 138 */ 86 virtual void update(Notification* notification, const std::time_t & time) = 0; 139 virtual bool executeCommand(notificationCommand::Value command, const std::string& sender) { return false; } 140 141 public: 142 143 static const std::string ALL; //!< Static string to indicate a sender that sends to all NotificationQueues. 144 static const std::string NONE; //!< Static string to indicate a sender that sends to no specific NotificationQueues. 145 146 //! Commands 147 static const std::string COMMAND_CLEAR; 148 static const std::string COMMAND_NONE; 149 150 protected: 151 static void sendNetworkHelper(const std::string& message, const std::string& sender, notificationSendMode::Value sendMode, unsigned int clientId, bool isCommand = false, notificationMessageType::Value messageType = notificationMessageType::info); // Helper method to send both notifications and commands over the network. 152 153 static notificationCommand::Value str2Command(const std::string& string); // Helper method. Converts a string into the enum for a command. 154 static const std::string& command2Str(notificationCommand::Value command); // Helper method. Converts a command enum into its corresponding string. 87 155 }; 88 156 } -
code/trunk/src/orxonox/interfaces/PlayerTrigger.h
r7601 r8706 39 39 40 40 #include "core/OrxonoxClass.h" 41 #include "core/WeakPtr.h" 41 42 42 43 namespace orxonox … … 44 45 /** 45 46 @brief 46 PlayerTrigger is an interface if implemented by a specific trigger can be used to recover the Player (or more preciselythe @ref orxonox::Pawn "Pawn") that triggered it.47 PlayerTrigger is an interface if implemented by a specific trigger can be used to recover the Player (or the @ref orxonox::Pawn "Pawn") that triggered it. 47 48 48 49 @author … … 58 59 59 60 /** 60 @brief Returns the playerthat triggered the PlayerTrigger.61 @brief Returns the Pawn that triggered the PlayerTrigger. 61 62 @return Returns a pointer to the Pawn that triggered the PlayerTrigger. 62 63 */ 63 inline Pawn* getTriggeringPlayer(void) const 64 inline Pawn* getTriggeringPawn(void) const 65 { return this->pawn_.get(); } 66 67 /** 68 @brief Returns the player that triggered the PlayerTrigger. 69 @return Returns a pointer to the PlayerInfo that triggered the PlayerTrigger. 70 */ 71 inline PlayerInfo* getTriggeringPlayer(void) const 64 72 { return this->player_; } 65 73 66 74 /** 67 @brief Checks whether the PlayerTrigger normally returns a Pawn .68 @return Returns true if the PlayerTrigger normally returns a Pawn .75 @brief Checks whether the PlayerTrigger normally returns a Pawn/PlayerInfo. 76 @return Returns true if the PlayerTrigger normally returns a Pawn/PlayerInfo. 69 77 */ 70 78 inline bool isForPlayer(void) const … … 76 84 @param player A pointer to the Pawn that triggered the PlayerTrigger. 77 85 */ 78 inline void setTriggeringPlayer(Pawn* player) 79 { this->player_ = player; } 86 void setTriggeringPawn(Pawn* pawn); 80 87 81 88 /** … … 87 94 88 95 private: 89 Pawn* player_; //!< The player that triggered the PlayerTrigger. 96 WeakPtr<PlayerInfo> player_; //!< The player that triggered the PlayerTrigger. 97 WeakPtr<Pawn> pawn_; //!< The Pawn that triggered the PlayerTrigger. 90 98 bool isForPlayer_; //!< Is true when the PlayerTrigger should be set to normally be triggered by Pawns. 91 99 -
code/trunk/src/orxonox/items/Engine.cc
r8079 r8706 35 35 #include "Scene.h" 36 36 #include "worldentities/pawns/SpaceShip.h" 37 #include " tools/Shader.h"37 #include "core/Template.h" 38 38 39 39 namespace orxonox … … 47 47 this->ship_ = 0; 48 48 this->shipID_ = OBJECTID_UNKNOWN; 49 this->relativePosition_ = Vector3(0,0,0); 49 50 50 51 this->boostFactor_ = 1.5; … … 62 63 this->accelerationUpDown_ = 0.0; 63 64 64 this->boostBlur_ = 0;65 66 65 this->speedAdd_ = 0.0; 67 66 this->speedMultiply_ = 1.0; … … 73 72 Engine::~Engine() 74 73 { 75 if (this->isInitialized() && this->ship_) 76 { 77 this->ship_->setEngine(0); 78 79 if (this->boostBlur_) 80 this->boostBlur_->destroy(); 74 if (this->isInitialized()) 75 { 76 if (this->ship_ && this->ship_->hasEngine(this)) 77 this->ship_->removeEngine(this); 81 78 } 82 79 } … … 98 95 XMLPortParam(Engine, "accelerationleftright", setAccelerationLeftRight, setAccelerationLeftRight, xmlelement, mode); 99 96 XMLPortParam(Engine, "accelerationupdown", setAccelerationUpDown, setAccelerationUpDown, xmlelement, mode); 97 98 XMLPortParam(Engine, "position", setRelativePosition, getRelativePosition, xmlelement, mode); 99 XMLPortParam(Engine, "template", setEngineTemplate, getEngineTemplate, xmlelement, mode); 100 100 } 101 101 102 102 void Engine::setConfigValues() 103 103 { 104 SetConfigValueExternal(bEnableMotionBlur_, "GraphicsSettings", "enableMotionBlur", true)105 .description("Enable or disable the motion blur effect when moving very fast")106 .callback(this, &Engine::changedEnableMotionBlur);107 SetConfigValueExternal(blurStrength_, "GraphicsSettings", "blurStrength", 3.0f)108 .description("Defines the strength of the motion blur effect");109 104 } 110 105 … … 163 158 SUPER(Engine, tick, dt); 164 159 165 const Vector3& direction = this->getDirection(); 160 Vector3 direction = this->getDirection(); 161 float directionLength = direction.length(); 162 if (directionLength > 1.0f) 163 direction /= directionLength; // normalize 164 166 165 Vector3 velocity = this->ship_->getLocalVelocity(); 167 166 Vector3 acceleration = Vector3::ZERO; … … 202 201 } 203 202 204 this->ship_->setAcceleration(this->ship_->getOrientation() * (acceleration*this->getSpeedMultiply()+Vector3(0,0,-this->getSpeedAdd()))); 205 206 if (!this->ship_->getPermanentBoost()) 207 this->ship_->setBoost(false); 208 this->ship_->setSteeringDirection(Vector3::ZERO); 209 210 if (this->bEnableMotionBlur_ && !this->boostBlur_ && this->ship_->hasLocalController() && this->ship_->hasHumanController()) 211 { 212 this->boostBlur_ = new Shader(this->ship_->getScene()->getSceneManager()); 213 this->boostBlur_->setCompositorName("Radial Blur"); 214 } 215 216 if (this->boostBlur_ && this->maxSpeedFront_ != 0 && this->boostFactor_ != 1) 217 { 218 float blur = this->blurStrength_ * clamp((-velocity.z - this->maxSpeedFront_) / ((this->boostFactor_ - 1) * this->maxSpeedFront_), 0.0f, 1.0f); 219 220 this->boostBlur_->setVisible(blur > 0); 221 this->boostBlur_->setParameter(0, 0, "sampleStrength", blur); 203 // NOTE: Bullet always uses global coordinates. 204 this->ship_->addAcceleration(this->ship_->getOrientation() * (acceleration*this->getSpeedMultiply()+Vector3(0,0,-this->getSpeedAdd())), this->ship_->getOrientation() * this->relativePosition_); 205 206 // Hack to reset a temporary variable "direction" 207 this->ship_->oneEngineTickDone(); 208 if(!this->ship_->hasEngineTicksRemaining()) 209 { 210 this->ship_->setSteeringDirection(Vector3::ZERO); 211 this->ship_->resetEngineTicks(); 222 212 } 223 213 } … … 226 216 { 227 217 SUPER(Engine, changedActivity); 228 229 if (this->boostBlur_)230 this->boostBlur_->setVisible(this->isVisible());231 218 } 232 219 … … 238 225 { 239 226 this->shipID_ = ship->getObjectID(); 240 if (ship->getEngine() != this) 241 ship->setEngine(this); 242 243 if (this->boostBlur_) 244 { 245 this->boostBlur_->destroy(); 246 this->boostBlur_ = 0; 247 } 227 if (!ship->hasEngine(this)) 228 ship->addEngine(this); 248 229 } 249 230 } … … 267 248 } 268 249 269 void Engine::changedEnableMotionBlur() 270 { 271 if (!this->bEnableMotionBlur_) 272 { 273 this->boostBlur_->destroy(); 274 this->boostBlur_ = 0; 250 void Engine::loadEngineTemplate() 251 { 252 if(!this->engineTemplate_.empty()) 253 { 254 COUT(4)<<"Loading an engine template: "<<this->engineTemplate_<<"\n"; 255 Template *temp = Template::getTemplate(this->engineTemplate_); 256 if(temp) 257 { 258 this->addTemplate(temp); 259 } 275 260 } 276 261 } -
code/trunk/src/orxonox/items/Engine.h
r8079 r8706 54 54 inline SpaceShip* getShip() const 55 55 { return this->ship_; } 56 57 inline void setRelativePosition(const Vector3 &position) 58 { this->relativePosition_ = position; } 59 inline Vector3& getRelativePosition() 60 { return this->relativePosition_; } 56 61 57 62 inline void setBoostFactor(float factor) … … 119 124 { this->speedMultiply_=speedMultiply; } 120 125 126 127 inline void setEngineTemplate(const std::string& temp) 128 { this->engineTemplate_ = temp; this->loadEngineTemplate(); } 129 inline const std::string& getEngineTemplate() const 130 { return this->engineTemplate_; } 131 121 132 protected: 122 133 virtual std::vector<PickupCarrier*>* getCarrierChildren(void) const 123 134 { return new std::vector<PickupCarrier*>(); } 124 135 virtual PickupCarrier* getCarrierParent(void) const; 136 137 void loadEngineTemplate(); 125 138 126 139 private: 127 140 void registerVariables(); 128 141 void networkcallback_shipID(); 129 void changedEnableMotionBlur(); 142 143 std::string engineTemplate_; 130 144 131 145 SpaceShip* ship_; 132 146 unsigned int shipID_; 147 Vector3 relativePosition_; 133 148 134 149 float boostFactor_; … … 148 163 float accelerationLeftRight_; 149 164 float accelerationUpDown_; 150 151 Shader* boostBlur_;152 float blurStrength_;153 bool bEnableMotionBlur_;154 165 }; 155 166 } -
code/trunk/src/orxonox/overlays/OrxonoxOverlay.cc
r8351 r8706 137 137 XMLPortParam(OrxonoxOverlay, "correctaspect", setAspectCorrection, getAspectCorrection, xmlelement, mode); 138 138 XMLPortParam(OrxonoxOverlay, "background", setBackgroundMaterial, getBackgroundMaterial, xmlelement, mode); 139 XMLPortParam(OrxonoxOverlay, "backgroundtex", setBackgroundTexture, getBackgroundTexture, xmlelement, mode); 139 140 } 140 141 … … 163 164 if (this->background_) 164 165 return this->background_->getMaterialName(); 166 else 167 return BLANKSTRING; 168 } 169 170 //! Sets the background texture name and creates a new material if necessary 171 void OrxonoxOverlay::setBackgroundTexture(const std::string& texture) 172 { 173 if (this->background_ && this->background_->getMaterial().isNull() && !texture.empty()) 174 { 175 // create new material 176 const std::string& materialname = "generated_material" + getUniqueNumberString(); 177 Ogre::MaterialPtr material = static_cast<Ogre::MaterialPtr>(Ogre::MaterialManager::getSingleton().create(materialname, "General")); 178 material->getTechnique(0)->getPass(0)->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA); 179 Ogre::TextureUnitState* textureUnitState_ = material->getTechnique(0)->getPass(0)->createTextureUnitState(); 180 textureUnitState_->setTextureName(texture); 181 textureUnitState_->setNumMipmaps(0); 182 this->background_->setMaterialName(materialname); 183 } 184 } 185 186 //! Returns the the texture name of the background 187 const std::string& OrxonoxOverlay::getBackgroundTexture() const 188 { 189 if (this->background_) 190 { 191 Ogre::TextureUnitState* tempTx = this->background_->getMaterial()->getTechnique(0)->getPass(0)->getTextureUnitState(0); 192 return tempTx->getTextureName(); 193 } 165 194 else 166 195 return BLANKSTRING; … … 406 435 } 407 436 408 void OrxonoxOverlay::setBackgroundAlpha(float alpha) { 437 void OrxonoxOverlay::setBackgroundAlpha(float alpha) 438 { 409 439 Ogre::MaterialPtr ptr = this->background_->getMaterial(); 410 440 Ogre::TextureUnitState* tempTx = ptr->getTechnique(0)->getPass(0)->getTextureUnitState(0); 411 441 tempTx->setAlphaOperation(Ogre::LBX_MODULATE, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, alpha); 412 442 } 443 444 void OrxonoxOverlay::setBackgroundColour(ColourValue colour) 445 { 446 Ogre::MaterialPtr ptr = this->background_->getMaterial(); 447 Ogre::TextureUnitState* tempTx = ptr->getTechnique(0)->getPass(0)->getTextureUnitState(0); 448 tempTx->setColourOperationEx(Ogre::LBX_MODULATE, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, colour); 449 } 413 450 } -
code/trunk/src/orxonox/overlays/OrxonoxOverlay.h
r8309 r8706 160 160 const std::string& getBackgroundMaterial() const; 161 161 162 void setBackgroundTexture(const std::string& texture); 163 const std::string& getBackgroundTexture() const; 164 162 165 void setBackgroundAlpha(float alpha); 166 167 void setBackgroundColour(ColourValue colour); 163 168 164 169 virtual void changedVisibility(); -
code/trunk/src/orxonox/sound/AmbientSound.cc
r8351 r8706 82 82 { 83 83 this->ambientSource_ = source; 84 this->moodChanged( this->getMood());84 this->moodChanged(MoodManager::getInstance().getMood()); 85 85 } 86 86 … … 89 89 if (GameMode::playsSound()) 90 90 { 91 const std::string& path = "ambient/" + MoodManager::getInstance().getMood()+ '/' + this->ambientSource_;91 const std::string& path = "ambient/" + mood + '/' + this->ambientSource_; 92 92 shared_ptr<ResourceInfo> fileInfo = Resource::getInfo(path); 93 93 if (fileInfo != NULL) -
code/trunk/src/orxonox/weaponsystem/Munition.cc
r7896 r8706 253 253 bool Munition::canAddMunition(unsigned int amount) const 254 254 { 255 // TODO: 'amount' is not used 256 255 257 if (!this->bAllowMunitionRefilling_) 256 258 return false; … … 334 336 bool Munition::canAddMagazines(unsigned int amount) const 335 337 { 338 // TODO: 'amount' is not used 339 336 340 if (this->bStackMunition_) 337 341 // If we stack munition, we can always add new magazines because they contribute directly to the munition -
code/trunk/src/orxonox/weaponsystem/WeaponMode.cc
r7847 r8706 66 66 67 67 this->damage_ = 0; 68 this->healthdamage_ = 0; 69 this->shielddamage_ = 0; 68 70 69 71 this->muzzleOffset_ = Vector3::ZERO; … … 106 108 107 109 XMLPortParam(WeaponMode, "damage", setDamage, getDamage, xmlelement, mode); 110 XMLPortParam(WeaponMode, "healthdamage", setHealthDamage, getHealthDamage, xmlelement, mode); 111 XMLPortParam(WeaponMode, "shielddamage", setShieldDamage, getShieldDamage, xmlelement, mode); 108 112 XMLPortParam(WeaponMode, "muzzleoffset", setMuzzleOffset, getMuzzleOffset, xmlelement, mode); 109 113 } -
code/trunk/src/orxonox/weaponsystem/WeaponMode.h
r7163 r8706 104 104 // Fire 105 105 inline void setDamage(float damage) 106 { this->damage_ = damage; 106 { this->damage_ = damage;} 107 107 inline float getDamage() const 108 108 { return this->damage_; } 109 inline void setHealthDamage(float healthdamage) 110 { this->healthdamage_ = healthdamage; } 111 inline float getHealthDamage() const 112 { return this->healthdamage_; } 113 114 inline void setShieldDamage(float shielddamage) 115 { this->shielddamage_ = shielddamage;} 116 inline float getShieldDamage() const 117 { return this->shielddamage_; } 109 118 110 119 inline void setMuzzleOffset(const Vector3& offset) … … 146 155 147 156 float damage_; 157 float healthdamage_; 158 float shielddamage_; 148 159 Vector3 muzzleOffset_; 149 160 -
code/trunk/src/orxonox/weaponsystem/WeaponSlot.cc
r5929 r8706 46 46 this->weapon_ = 0; 47 47 48 this->setSyncMode( 0x0);48 this->setSyncMode(ObjectDirection::None); 49 49 } 50 50 -
code/trunk/src/orxonox/worldentities/CMakeLists.txt
r8458 r8706 12 12 SpawnPoint.cc 13 13 TeamSpawnPoint.cc 14 SpaceBoundaries.cc15 14 ) 16 15 -
code/trunk/src/orxonox/worldentities/CameraPosition.cc
r5929 r8706 46 46 this->bRenderCamera_ = false; 47 47 48 this->setSyncMode( 0x0);48 this->setSyncMode(ObjectDirection::None); 49 49 } 50 50 -
code/trunk/src/orxonox/worldentities/ControllableEntity.cc
r7892 r8706 84 84 this->client_angular_velocity_ = Vector3::ZERO; 85 85 86 87 86 this->setConfigValues(); 88 87 this->setPriority( Priority::VeryHigh ); … … 121 120 122 121 XMLPortParam(ControllableEntity, "hudtemplate", setHudTemplate, getHudTemplate, xmlelement, mode); 123 XMLPortParam(ControllableEntity, "camerapositiontemplate", setCameraPositionTemplate, getCameraPositionTem kplate, xmlelement, mode);122 XMLPortParam(ControllableEntity, "camerapositiontemplate", setCameraPositionTemplate, getCameraPositionTemplate, xmlelement, mode); 124 123 125 124 XMLPortObject(ControllableEntity, CameraPosition, "camerapositions", addCameraPosition, getCameraPosition, xmlelement, mode); … … 171 170 } 172 171 return 0; 172 } 173 174 unsigned int ControllableEntity::getCurrentCameraIndex() const 175 { 176 if (this->cameraPositions_.size() <= 0) 177 return 0; 178 179 unsigned int counter = 0; 180 for (std::list<SmartPtr<CameraPosition> >::const_iterator it = this->cameraPositions_.begin(); it != this->cameraPositions_.end(); ++it) 181 { 182 if ((*it) == this->currentCameraPosition_) 183 break; 184 counter++; 185 } 186 if (counter >= this->cameraPositions_.size()) 187 return 0; 188 189 return counter; 190 } 191 192 bool ControllableEntity::setCameraPosition(unsigned int index) 193 { 194 if(this->camera_ != NULL && this->cameraPositions_.size() > 0) 195 { 196 if(index >= this->cameraPositions_.size()) 197 index = 0; 198 199 CameraPosition* position = this->getCameraPosition(index); 200 position->attachCamera(this->camera_); 201 this->currentCameraPosition_ = position; 202 return true; 203 } 204 205 return false; 173 206 } 174 207 … … 373 406 } 374 407 408 this->createHud(); 409 } 410 411 // HACK-ish 412 void ControllableEntity::createHud(void) 413 { 375 414 if (!this->hud_ && GameMode::showsGraphics()) 376 415 { … … 381 420 this->hud_->setOwner(this); 382 421 } 422 } 423 } 424 425 void ControllableEntity::destroyHud(void) 426 { 427 if (this->hud_ != NULL) 428 { 429 this->hud_->destroy(); 430 this->hud_ = NULL; 383 431 } 384 432 } -
code/trunk/src/orxonox/worldentities/ControllableEntity.h
r7889 r8706 93 93 virtual void reload() {} 94 94 95 virtual void boost() {} 95 /** 96 @brief Tells the ControllableEntity to either start or stop boosting. 97 This doesn't mean, that the ControllableEntity will do so, there might be additional restrictions on boosting, but if it can, then it will. 98 @param bBoost If true the ControllableEntity is told to start boosting, if false it is told to stop. 99 */ 100 virtual void boost(bool bBoost) {} 101 96 102 virtual void greet() {} 97 103 virtual void switchCamera(); … … 110 116 inline const std::list<SmartPtr<CameraPosition> >& getCameraPositions() const 111 117 { return this->cameraPositions_; } 118 unsigned int getCurrentCameraIndex() const; 119 bool setCameraPosition(unsigned int index); 112 120 113 121 inline void setCameraPositionTemplate(const std::string& name) 114 122 { this->cameraPositionTemplate_ = name; } 115 inline const std::string& getCameraPositionTem kplate() const123 inline const std::string& getCameraPositionTemplate() const 116 124 { return this->cameraPositionTemplate_; } 117 125 … … 168 176 inline void setHudTemplate(const std::string& name) 169 177 { this->hudtemplate_ = name; } 178 // HACK-ish 179 void createHud(void); 180 void destroyHud(void); 170 181 171 182 Ogre::SceneNode* cameraPositionRootNode_; -
code/trunk/src/orxonox/worldentities/MobileEntity.cc
r7163 r8706 143 143 { 144 144 if (this->isDynamic()) 145 { 145 146 this->physicalBody_->applyCentralForce(btVector3(acceleration.x * this->getMass(), acceleration.y * this->getMass(), acceleration.z * this->getMass())); 146 147 } 148 149 // If not bullet-managed (deprecated? SpaceShip doesn't use this anymore for movement) 147 150 this->linearAcceleration_ = acceleration; 151 } 152 153 void MobileEntity::addAcceleration(const Vector3 &acceleration, const Vector3 &relativePosition) 154 { 155 if(this->isDynamic()) 156 { 157 this->physicalBody_->applyForce(this->getMass() * btVector3(acceleration.x, acceleration.y, acceleration.z), btVector3(relativePosition.x, relativePosition.y, relativePosition.z)); 158 } 148 159 } 149 160 -
code/trunk/src/orxonox/worldentities/MobileEntity.h
r5781 r8706 70 70 { return this->linearAcceleration_; } 71 71 72 // Added for making N engines work with spaceships 73 void addAcceleration(const Vector3& acceleration, const Vector3 &relativePosition); 74 inline void addAcceleration(float x, float y, float z) 75 { this->addAcceleration(Vector3(x, y, z), Vector3(0,0,0)); } 76 // Getter function above 77 72 78 void setAngularAcceleration(const Vector3& acceleration); 73 79 inline void setAngularAcceleration(float x, float y, float z) … … 83 89 { this->setAngularVelocity(this->getAngularVelocity().normalisedCopy() * rate.valueRadians()); } 84 90 inline Degree getRotationRate() const 85 { return Degree(this->getAngularVelocity().length()); }91 { return Radian(this->getAngularVelocity().length()); } 86 92 87 93 inline void setRotationAxis(const Vector3& axis) -
code/trunk/src/orxonox/worldentities/SpawnPoint.cc
r5929 r8706 50 50 COUT(1) << "Error: SpawnPoint has no Gametype" << std::endl; 51 51 52 this->setSyncMode( 0x0);52 this->setSyncMode(ObjectDirection::None); 53 53 } 54 54 -
code/trunk/src/orxonox/worldentities/WorldEntity.cc
r7937 r8706 642 642 void WorldEntity::setScale3D(const Vector3& scale) 643 643 { 644 /* 645 HACK HACK HACK 646 if (bScalePhysics && this->hasPhysics() && scale != Vector3::UNIT_SCALE) 647 { 648 CCOUT(2) << "Warning: Cannot set the scale of a physical object: Not yet implemented. Ignoring scaling." << std::endl; 649 return; 650 } 651 HACK HACK HACK 652 */ 644 // If physics is enabled scale the attached CollisionShape. 645 /*if (this->hasPhysics() && this->collisionShape_ != NULL) 646 { 647 this->collisionShape_->setScale3D(scale); 648 }*/ 649 653 650 this->node_->setScale(scale); 654 651 -
code/trunk/src/orxonox/worldentities/pawns/Pawn.cc
r8351 r8706 23 23 * Fabian 'x3n' Landau 24 24 * Co-authors: 25 * ...25 * Simon Miescher 26 26 * 27 27 */ … … 64 64 this->maxHealth_ = 0; 65 65 this->initialHealth_ = 0; 66 66 67 this->shieldHealth_ = 0; 68 this->initialShieldHealth_ = 0; 69 this->maxShieldHealth_ = 100; //otherwise shield might increase to float_max 67 70 this->shieldAbsorption_ = 0.5; 71 72 this->reloadRate_ = 0; 73 this->reloadWaitTime_ = 1.0f; 74 this->reloadWaitCountdown_ = 0; 68 75 69 76 this->lastHitOriginator_ = 0; … … 109 116 110 117 XMLPortParam(Pawn, "shieldhealth", setShieldHealth, getShieldHealth, xmlelement, mode).defaultValues(0); 118 XMLPortParam(Pawn, "initialshieldhealth", setInitialShieldHealth, getInitialShieldHealth, xmlelement, mode).defaultValues(0); 119 XMLPortParam(Pawn, "maxshieldhealth", setMaxShieldHealth, getMaxShieldHealth, xmlelement, mode).defaultValues(100); 111 120 XMLPortParam(Pawn, "shieldabsorption", setShieldAbsorption, getShieldAbsorption, xmlelement, mode).defaultValues(0); 112 121 … … 118 127 XMLPortObject(Pawn, WeaponSet, "weaponsets", addWeaponSet, getWeaponSet, xmlelement, mode); 119 128 XMLPortObject(Pawn, WeaponPack, "weapons", addWeaponPackXML, getWeaponPack, xmlelement, mode); 129 130 XMLPortParam(Pawn, "reloadrate", setReloadRate, getReloadRate, xmlelement, mode).defaultValues(0); 131 XMLPortParam(Pawn, "reloadwaittime", setReloadWaitTime, getReloadWaitTime, xmlelement, mode).defaultValues(1.0f); 120 132 } 121 133 … … 124 136 registerVariable(this->bAlive_, VariableDirection::ToClient); 125 137 registerVariable(this->health_, VariableDirection::ToClient); 126 registerVariable(this-> initialHealth_,VariableDirection::ToClient);138 registerVariable(this->maxHealth_, VariableDirection::ToClient); 127 139 registerVariable(this->shieldHealth_, VariableDirection::ToClient); 140 registerVariable(this->maxShieldHealth_, VariableDirection::ToClient); 128 141 registerVariable(this->shieldAbsorption_, VariableDirection::ToClient); 129 142 registerVariable(this->bReload_, VariableDirection::ToServer); … … 137 150 this->bReload_ = false; 138 151 152 // TODO: use the existing timer functions instead 153 if(this->reloadWaitCountdown_ > 0) 154 { 155 this->decreaseReloadCountdownTime(dt); 156 } 157 else 158 { 159 this->addShieldHealth(this->getReloadRate() * dt); 160 this->resetReloadCountdown(); 161 } 162 139 163 if (GameMode::isMaster()) 164 { 140 165 if (this->health_ <= 0 && bAlive_) 141 166 { 142 this->fireEvent(); // Event to notify anyone who want 's to know about the death.167 this->fireEvent(); // Event to notify anyone who wants to know about the death. 143 168 this->death(); 144 169 } 170 } 145 171 } 146 172 … … 168 194 } 169 195 196 170 197 void Pawn::setHealth(float health) 171 198 { 172 this->health_ = std::min(health, this->maxHealth_); 173 } 174 175 void Pawn::damage(float damage, Pawn* originator) 199 this->health_ = std::min(health, this->maxHealth_); //Health can't be set to a value bigger than maxHealth, otherwise it will be reduced at first hit 200 } 201 202 void Pawn::setShieldHealth(float shieldHealth) 203 { 204 this->shieldHealth_ = std::min(shieldHealth, this->maxShieldHealth_); 205 } 206 207 void Pawn::setMaxShieldHealth(float maxshieldhealth) 208 { 209 this->maxShieldHealth_ = maxshieldhealth; 210 } 211 212 void Pawn::setReloadRate(float reloadrate) 213 { 214 this->reloadRate_ = reloadrate; 215 } 216 217 void Pawn::setReloadWaitTime(float reloadwaittime) 218 { 219 this->reloadWaitTime_ = reloadwaittime; 220 } 221 222 void Pawn::decreaseReloadCountdownTime(float dt) 223 { 224 this->reloadWaitCountdown_ -= dt; 225 } 226 227 void Pawn::damage(float damage, float healthdamage, float shielddamage, Pawn* originator) 176 228 { 177 229 if (this->getGametype() && this->getGametype()->allowPawnDamage(this, originator)) 178 230 { 179 //share the dealt damage to the shield and the Pawn. 180 float shielddamage = damage*this->shieldAbsorption_; 181 float healthdamage = damage*(1-this->shieldAbsorption_); 182 183 // In case the shield can not take all the shield damage. 184 if (shielddamage > this->getShieldHealth()) 231 if (shielddamage >= this->getShieldHealth()) 185 232 { 186 healthdamage += shielddamage-this->getShieldHealth();187 233 this->setShieldHealth(0); 234 this->setHealth(this->health_ - (healthdamage + damage)); 188 235 } 189 190 this->setHealth(this->health_ - healthdamage); 191 192 if (this->getShieldHealth() > 0) 236 else 193 237 { 194 238 this->setShieldHealth(this->shieldHealth_ - shielddamage); 239 240 // remove remaining shieldAbsorpton-Part of damage from shield 241 shielddamage = damage * this->shieldAbsorption_; 242 shielddamage = std::min(this->getShieldHealth(),shielddamage); 243 this->setShieldHealth(this->shieldHealth_ - shielddamage); 244 245 // set remaining damage to health 246 this->setHealth(this->health_ - (damage - shielddamage) - healthdamage); 195 247 } 196 248 197 249 this->lastHitOriginator_ = originator; 198 199 // play damage effect 200 } 201 } 202 203 void Pawn::hit(Pawn* originator, const Vector3& force, float damage) 250 } 251 } 252 253 // TODO: Still valid? 254 /* HIT-Funktionen 255 Die hit-Funktionen muessen auch in src/orxonox/controllers/Controller.h angepasst werden! (Visuelle Effekte) 256 257 */ 258 259 void Pawn::hit(Pawn* originator, const Vector3& force, float damage, float healthdamage, float shielddamage) 204 260 { 205 261 if (this->getGametype() && this->getGametype()->allowPawnHit(this, originator) && (!this->getController() || !this->getController()->getGodMode()) ) 206 262 { 207 this->damage(damage, originator);263 this->damage(damage, healthdamage, shielddamage, originator); 208 264 this->setVelocity(this->getVelocity() + force); 209 210 // play hit effect 211 } 212 } 213 214 void Pawn::hit(Pawn* originator, btManifoldPoint& contactpoint, float damage) 265 } 266 } 267 268 269 void Pawn::hit(Pawn* originator, btManifoldPoint& contactpoint, float damage, float healthdamage, float shielddamage) 215 270 { 216 271 if (this->getGametype() && this->getGametype()->allowPawnHit(this, originator) && (!this->getController() || !this->getController()->getGodMode()) ) 217 272 { 218 this->damage(damage, originator);273 this->damage(damage, healthdamage, shielddamage, originator); 219 274 220 275 if ( this->getController() ) 221 this->getController()->hit(originator, contactpoint, damage); 222 223 // play hit effect 224 } 225 } 276 this->getController()->hit(originator, contactpoint, damage); // changed to damage, why shielddamage? 277 } 278 } 279 226 280 227 281 void Pawn::kill() -
code/trunk/src/orxonox/worldentities/pawns/Pawn.h
r7889 r8706 72 72 { return this->initialHealth_; } 73 73 74 inline void setShieldHealth(float shieldHealth)75 { this->shieldHealth_ = shieldHealth; } 74 virtual void setShieldHealth(float shieldHealth); 75 76 76 inline float getShieldHealth() 77 77 { return this->shieldHealth_; } 78 79 inline void addShieldHealth(float amount) 80 { this->setShieldHealth(this->shieldHealth_ + amount); } 81 82 inline bool hasShield() 83 { return (this->getShieldHealth() > 0); } 84 85 virtual void setMaxShieldHealth(float maxshieldhealth); 86 inline float getMaxShieldHealth() const 87 { return this->maxShieldHealth_; } 88 89 inline void setInitialShieldHealth(float initialshieldhealth) 90 { this->initialShieldHealth_ = initialshieldhealth; this->setShieldHealth(initialshieldhealth); } 91 inline float getInitialShieldHealth() const 92 { return this->initialShieldHealth_; } 93 94 inline void restoreInitialShieldHealth() 95 { this->setShieldHealth(this->initialShieldHealth_); } 96 inline void restoreMaxShieldHealth() 97 { this->setShieldHealth(this->maxShieldHealth_); } 78 98 79 99 inline void setShieldAbsorption(float shieldAbsorption) … … 82 102 { return this->shieldAbsorption_; } 83 103 104 // TODO: Rename to shieldRechargeRate 105 virtual void setReloadRate(float reloadrate); 106 inline float getReloadRate() const 107 { return this->reloadRate_; } 108 109 virtual void setReloadWaitTime(float reloadwaittime); 110 inline float getReloadWaitTime() const 111 { return this->reloadWaitTime_; } 112 113 inline void resetReloadCountdown() 114 { this->reloadWaitCountdown_ = 0; } 115 116 inline void startReloadCountdown() 117 { this->reloadWaitCountdown_ = this->getReloadWaitTime(); } // TODO: Implement in Projectile.cc 118 119 virtual void decreaseReloadCountdownTime(float dt); 120 84 121 inline ControllableEntity* getLastHitOriginator() const 85 122 { return this->lastHitOriginator_; } 86 123 87 virtual void hit(Pawn* originator, const Vector3& force, float damage); 88 virtual void hit(Pawn* originator, btManifoldPoint& contactpoint, float damage); 124 //virtual void hit(Pawn* originator, const Vector3& force, float damage); 125 //virtual void hit(Pawn* originator, btManifoldPoint& contactpoint, float damage); 126 virtual void hit(Pawn* originator, const Vector3& force, float damage, float healthdamage = 0.0f, float shielddamage = 0.0f); 127 virtual void hit(Pawn* originator, btManifoldPoint& contactpoint, float damage, float healthdamage = 0.0f, float shielddamage = 0.0f); 128 89 129 virtual void kill(); 90 130 … … 142 182 virtual void spawneffect(); 143 183 144 virtual void damage(float damage, Pawn* originator = 0); 184 //virtual void damage(float damage, Pawn* originator = 0); 185 virtual void damage(float damage, float healthdamage = 0.0f, float shielddamage = 0.0f, Pawn* originator = NULL); 145 186 146 187 bool bAlive_; … … 154 195 float maxHealth_; 155 196 float initialHealth_; 197 156 198 float shieldHealth_; 199 float maxShieldHealth_; 200 float initialShieldHealth_; 157 201 float shieldAbsorption_; // Has to be between 0 and 1 202 float reloadRate_; 203 float reloadWaitTime_; 204 float reloadWaitCountdown_; 158 205 159 206 WeakPtr<Pawn> lastHitOriginator_; -
code/trunk/src/orxonox/worldentities/pawns/SpaceShip.cc
r7860 r8706 35 35 #include "core/Template.h" 36 36 #include "core/XMLPort.h" 37 #include "tools/Shader.h" 38 #include "util/Debug.h" // TODO: Needed? 39 #include "util/Math.h" 40 41 #include "graphics/Camera.h" 37 42 #include "items/Engine.h" 43 44 #include "CameraManager.h" 45 #include "Scene.h" 38 46 39 47 namespace orxonox … … 42 50 CreateFactory(SpaceShip); 43 51 44 SpaceShip::SpaceShip(BaseObject* creator) : Pawn(creator) 52 SpaceShip::SpaceShip(BaseObject* creator) : Pawn(creator), boostBlur_(NULL) 45 53 { 46 54 RegisterObject(SpaceShip); … … 53 61 this->localAngularAcceleration_.setValue(0, 0, 0); 54 62 this->bBoost_ = false; 55 this->bPermanentBoost_ = false;56 63 this->steering_ = Vector3::ZERO; 57 this->engine_ = 0;58 64 59 65 this->boostPower_ = 10.0f; … … 64 70 this->bBoostCooldown_ = false; 65 71 72 this->lift_ = 1.0f; // factor of the lift, standard is 1 73 this->stallSpeed_ = 220.0f; // max speed where lift is added 74 66 75 this->bInvertYAxis_ = false; 67 76 … … 74 83 this->enableCollisionCallback(); 75 84 85 this->engineTicksNotDone = 0; 76 86 this->setConfigValues(); 77 87 this->registerVariables(); 88 89 this->cameraOriginalPosition_ = Vector3::UNIT_SCALE; 90 this->cameraOriginalOrientation_ = Quaternion::IDENTITY; 91 92 this->shakeFrequency_ = 15; 93 this->shakeAmplitude_ = 5; 94 this->shakeDt_ = 0; 78 95 } 79 96 80 97 SpaceShip::~SpaceShip() 81 98 { 82 if (this->isInitialized() && this->engine_) 83 this->engine_->destroy(); 99 if (this->isInitialized()) 100 { 101 this->removeAllEngines(); 102 103 if (this->boostBlur_) 104 this->boostBlur_->destroy(); 105 } 84 106 } 85 107 … … 88 110 SUPER(SpaceShip, XMLPort, xmlelement, mode); 89 111 90 XMLPortParam(SpaceShip, "engine", setEngineTemplate, getEngineTemplate, xmlelement, mode);112 //XMLPortParam(SpaceShip, "engine", setEngineTemplate, getEngineTemplate, xmlelement, mode); 91 113 XMLPortParamVariable(SpaceShip, "primaryThrust", primaryThrust_, xmlelement, mode); 92 114 XMLPortParamVariable(SpaceShip, "auxilaryThrust", auxilaryThrust_, xmlelement, mode); … … 96 118 XMLPortParamVariable(SpaceShip, "boostRate", boostRate_, xmlelement, mode); 97 119 XMLPortParamVariable(SpaceShip, "boostCooldownDuration", boostCooldownDuration_, xmlelement, mode); 120 XMLPortParamVariable(SpaceShip, "shakeFrequency", shakeFrequency_, xmlelement, mode); 121 XMLPortParamVariable(SpaceShip, "shakeAmplitude", shakeAmplitude_, xmlelement, mode); 122 XMLPortParamVariable(SpaceShip, "lift", lift_, xmlelement, mode); 123 XMLPortParamVariable(SpaceShip, "stallSpeed", stallSpeed_, xmlelement, mode); 124 125 XMLPortObject(SpaceShip, Engine, "engines", addEngine, getEngine, xmlelement, mode); 98 126 } 99 127 … … 103 131 registerVariable(this->auxilaryThrust_, VariableDirection::ToClient); 104 132 registerVariable(this->rotationThrust_, VariableDirection::ToClient); 133 // TODO: Synchronization of boost needed? 134 registerVariable(this->boostPower_, VariableDirection::ToClient); 135 registerVariable(this->boostPowerRate_, VariableDirection::ToClient); 136 registerVariable(this->boostRate_, VariableDirection::ToClient); 137 registerVariable(this->boostCooldownDuration_, VariableDirection::ToClient); 138 registerVariable(this->shakeFrequency_, VariableDirection::ToClient); 139 registerVariable(this->shakeAmplitude_, VariableDirection::ToClient); 140 registerVariable(this->lift_, VariableDirection::ToClient); 141 registerVariable(this->stallSpeed_, VariableDirection::ToClient); 105 142 } 106 143 … … 108 145 { 109 146 SetConfigValue(bInvertYAxis_, false).description("Set this to true for joystick-like mouse behaviour (mouse up = ship down)."); 147 148 SetConfigValueExternal(bEnableMotionBlur_, "GraphicsSettings", "enableMotionBlur", true) 149 .description("Enable or disable the motion blur effect when moving very fast") 150 .callback(this, &SpaceShip::changedEnableMotionBlur); 151 SetConfigValueExternal(blurStrength_, "GraphicsSettings", "blurStrength", 3.0f) 152 .description("Defines the strength of the motion blur effect"); 110 153 } 111 154 … … 128 171 if (this->hasLocalController()) 129 172 { 130 /* 131 this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() * getMass() * this->auxilaryThrust_); 132 this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() * getMass() * this->auxilaryThrust_); 133 if (this->localLinearAcceleration_.z() > 0) 134 this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->auxilaryThrust_); 135 else 136 this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->primaryThrust_); 137 this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * this->localLinearAcceleration_); 138 this->localLinearAcceleration_.setValue(0, 0, 0); 139 */ 173 // Handle mouse look 140 174 if (!this->isInMouseLook()) 141 175 { … … 143 177 this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * this->localAngularAcceleration_); 144 178 } 145 146 179 this->localAngularAcceleration_.setValue(0, 0, 0); 147 180 181 // Charge boostPower 148 182 if(!this->bBoostCooldown_ && this->boostPower_ < this->initialBoostPower_) 149 183 { 150 184 this->boostPower_ += this->boostPowerRate_*dt; 151 185 } 186 // Use boostPower 152 187 if(this->bBoost_) 153 188 { … … 155 190 if(this->boostPower_ <= 0.0f) 156 191 { 157 this->b Boost_ = false;192 this->boost(false); 158 193 this->bBoostCooldown_ = true; 159 194 this->timer_.setTimer(this->boostCooldownDuration_, false, createExecutor(createFunctor(&SpaceShip::boostCooledDown, this))); 160 195 } 161 } 196 197 this->shakeCamera(dt); 198 } 199 200 // Enable Blur depending on settings 201 if (this->bEnableMotionBlur_ && !this->boostBlur_ && this->hasLocalController() && this->hasHumanController()) 202 { 203 this->boostBlur_ = new Shader(this->getScene()->getSceneManager()); 204 this->boostBlur_->setCompositorName("Radial Blur"); 205 } 206 207 if (this->boostBlur_) // && this->maxSpeedFront_ != 0 && this->boostFactor_ != 1) 208 { 209 // TODO: this->maxSpeedFront_ gets fastest engine 210 float blur = this->blurStrength_ * clamp((-this->getLocalVelocity().z - 0.0f /*this->maxSpeedFront_*/) / ((150.0f /*boostFactor_*/ - 1) * 1.5f /*this->maxSpeedFront_*/), 0.0f, 1.0f); 211 212 // Show and hide blur effect depending on state of booster 213 if(this->bBoost_) 214 this->boostBlur_->setVisible(blur > 0); 215 else 216 this->boostBlur_->setVisible(false); 217 218 this->boostBlur_->setParameter(0, 0, "sampleStrength", blur); 219 } 220 } 221 } 222 223 void SpaceShip::moveFrontBack(const Vector2& value) 224 { 225 this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() - value.x); 226 this->steering_.z -= value.x; 227 } 228 229 void SpaceShip::moveRightLeft(const Vector2& value) 230 { 231 this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() + value.x); 232 this->steering_.x += value.x; 233 } 234 235 void SpaceShip::moveUpDown(const Vector2& value) 236 { 237 this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() + value.x); 238 this->steering_.y += value.x; 239 } 240 241 void SpaceShip::rotateYaw(const Vector2& value) 242 { 243 this->localAngularAcceleration_.setY(this->localAngularAcceleration_.y() + value.x); 244 245 Pawn::rotateYaw(value); 246 247 //This function call adds a lift to the ship when it is rotating to make it's movement more "realistic" and enhance the feeling. 248 if (abs(this-> getLocalVelocity().z) < stallSpeed_) {this->moveRightLeft(-lift_ / 5 * value * sqrt(abs(this-> getLocalVelocity().z)));} 249 } 250 251 void SpaceShip::rotatePitch(const Vector2& value) 252 { 253 this->localAngularAcceleration_.setX(this->localAngularAcceleration_.x() + value.x*0.8f); 254 255 Pawn::rotatePitch(value); 256 257 //This function call adds a lift to the ship when it is pitching to make it's movement more "realistic" and enhance the feeling. 258 if (abs(this-> getLocalVelocity().z) < stallSpeed_) {this->moveUpDown(lift_ / 5 * value * sqrt(abs(this-> getLocalVelocity().z)));} 259 } 260 261 void SpaceShip::rotateRoll(const Vector2& value) 262 { 263 this->localAngularAcceleration_.setZ(this->localAngularAcceleration_.z() + value.x); 264 265 Pawn::rotateRoll(value); 266 } 267 268 void SpaceShip::fire() 269 { 270 } 271 272 /** 273 @brief 274 Starts or stops boosting. 275 @param bBoost 276 Whether to start or stop boosting. 277 */ 278 void SpaceShip::boost(bool bBoost) 279 { 280 if(bBoost && !this->bBoostCooldown_) 281 { 282 this->bBoost_ = true; 283 Camera* camera = CameraManager::getInstance().getActiveCamera(); 284 this->cameraOriginalPosition_ = camera->getPosition(); 285 this->cameraOriginalOrientation_ = camera->getOrientation(); 286 } 287 if(!bBoost) 288 { 289 this->bBoost_ = false; 290 this->resetCamera(); 162 291 } 163 292 } … … 167 296 this->bBoostCooldown_ = false; 168 297 } 169 170 void SpaceShip::moveFrontBack(const Vector2& value) 171 { 172 this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() - value.x); 173 this->steering_.z = -value.x; 174 } 175 176 void SpaceShip::moveRightLeft(const Vector2& value) 177 { 178 this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() + value.x); 179 this->steering_.x = value.x; 180 } 181 182 void SpaceShip::moveUpDown(const Vector2& value) 183 { 184 this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() + value.x); 185 this->steering_.y = value.x; 186 } 187 188 void SpaceShip::rotateYaw(const Vector2& value) 189 { 190 this->localAngularAcceleration_.setY(this->localAngularAcceleration_.y() + value.x); 191 192 Pawn::rotateYaw(value); 193 } 194 195 void SpaceShip::rotatePitch(const Vector2& value) 196 { 197 this->localAngularAcceleration_.setX(this->localAngularAcceleration_.x() + value.x); 198 199 Pawn::rotatePitch(value); 200 } 201 202 void SpaceShip::rotateRoll(const Vector2& value) 203 { 204 this->localAngularAcceleration_.setZ(this->localAngularAcceleration_.z() + value.x); 205 206 Pawn::rotateRoll(value); 207 } 208 209 // TODO: something seems to call this function every tick, could probably handled a little more efficiently! 210 void SpaceShip::setBoost(bool bBoost) 211 { 212 if(bBoost == this->bBoost_) 298 299 void SpaceShip::shakeCamera(float dt) 300 { 301 //make sure the ship is only shaking if it's moving 302 if (this->getVelocity().squaredLength() > 80.0f) 303 { 304 this->shakeDt_ += dt; 305 306 float frequency = this->shakeFrequency_ * (this->getVelocity().squaredLength()); 307 308 if (this->shakeDt_ >= 1.0f/frequency) 309 { 310 this->shakeDt_ -= 1.0f/frequency; 311 } 312 313 Degree angle = Degree(sin(this->shakeDt_ *2.0f* math::pi * frequency) * this->shakeAmplitude_); 314 315 //COUT(0) << "Angle: " << angle << std::endl; 316 Camera* camera = this->getCamera(); 317 318 //Shaking Camera effect 319 if (camera != 0) 320 { 321 camera->setOrientation(Vector3::UNIT_X, angle); 322 } 323 } 324 } 325 326 void SpaceShip::resetCamera() 327 { 328 Camera *camera = this->getCamera(); 329 330 if (camera == 0) 331 { 332 COUT(2) << "Failed to reset camera!"; 213 333 return; 214 215 if(bBoost) 216 this->boost(); 334 } 335 336 this->shakeDt_ = 0; 337 camera->setPosition(this->cameraOriginalPosition_); 338 camera->setOrientation(this->cameraOriginalOrientation_); 339 } 340 341 void SpaceShip::backupCamera() 342 { 343 Camera* camera = CameraManager::getInstance().getActiveCamera(); 344 if(camera != NULL) 345 { 346 this->cameraOriginalPosition_ = camera->getPosition(); 347 this->cameraOriginalOrientation_ = camera->getOrientation(); 348 } 349 } 350 351 void SpaceShip::addEngine(orxonox::Engine* engine) 352 { 353 //COUT(0)<<"Adding an Engine: " << engine << endl; 354 this->engineList_.push_back(engine); 355 engine->addToSpaceShip(this); 356 this->resetEngineTicks(); 357 } 358 359 bool SpaceShip::hasEngine(Engine* engine) 360 { 361 for(unsigned int i=0; i<this->engineList_.size(); i++) 362 { 363 if(this->engineList_[i]==engine) 364 return true; 365 } 366 return false; 367 } 368 369 Engine* SpaceShip::getEngine(unsigned int i) 370 { 371 if(this->engineList_.size()>=i) 372 return 0; 217 373 else 218 { 219 this->bBoost_ = false; 220 } 221 } 222 223 void SpaceShip::fire() 224 { 225 } 226 227 void SpaceShip::boost() 228 { 229 if(!this->bBoostCooldown_) 230 this->bBoost_ = true; 231 } 232 233 void SpaceShip::loadEngineTemplate() 234 { 235 if (!this->enginetemplate_.empty()) 236 { 237 Template* temp = Template::getTemplate(this->enginetemplate_); 238 239 if (temp) 240 { 241 Identifier* identifier = temp->getBaseclassIdentifier(); 242 243 if (identifier) 244 { 245 BaseObject* object = identifier->fabricate(this); 246 this->engine_ = orxonox_cast<Engine*>(object); 247 248 if (this->engine_) 249 { 250 this->engine_->addTemplate(temp); 251 this->engine_->addToSpaceShip(this); 252 } 253 else 254 { 255 object->destroy(); 256 } 257 } 258 } 259 } 260 } 261 262 void SpaceShip::setEngine(Engine* engine) 263 { 264 this->engine_ = engine; 265 if (engine && engine->getShip() != this) 266 engine->addToSpaceShip(this); 374 return this->engineList_[i]; 375 } 376 377 void SpaceShip::removeAllEngines() 378 { 379 while(this->engineList_.size()) 380 this->engineList_.back()->destroy(); 381 } 382 383 void SpaceShip::removeEngine(Engine* engine) 384 { 385 for(std::vector<Engine*>::iterator it=this->engineList_.begin(); it!=this->engineList_.end(); ++it) 386 { 387 if(*it==engine) 388 { 389 this->engineList_.erase(it); 390 return; 391 } 392 } 393 } 394 395 void SpaceShip::setSpeedFactor(float factor) 396 { 397 for(unsigned int i=0; i<this->engineList_.size(); i++) 398 this->engineList_[i]->setSpeedFactor(factor); 399 } 400 float SpaceShip::getSpeedFactor() // Calculate mean SpeedFactor. 401 { 402 float ret = 0; unsigned int i = 0; 403 for(; i<this->engineList_.size(); i++) 404 ret += this->engineList_[i]->getSpeedFactor(); 405 ret /= (float)i; 406 return ret; 407 } 408 float SpaceShip::getMaxSpeedFront() 409 { 410 float ret=0; 411 for(unsigned int i=0; i<this->engineList_.size(); i++) 412 { 413 if(this->engineList_[i]->getMaxSpeedFront() > ret) 414 ret = this->engineList_[i]->getMaxSpeedFront(); 415 } 416 return ret; 417 } 418 419 float SpaceShip::getBoostFactor() 420 { 421 float ret = 0; unsigned int i=0; 422 for(; i<this->engineList_.size(); i++) 423 ret += this->engineList_[i]->getBoostFactor(); 424 ret /= (float)i; 425 return ret; 267 426 } 268 427 … … 270 429 { 271 430 std::vector<PickupCarrier*>* list = new std::vector<PickupCarrier*>(); 272 list->push_back(this->engine_); 431 for(unsigned int i=0; i<this->engineList_.size(); i++) 432 list->push_back(this->engineList_[i]); 273 433 return list; 274 434 } 435 436 void SpaceShip::changedEnableMotionBlur() 437 { 438 if (!this->bEnableMotionBlur_) 439 { 440 this->boostBlur_->destroy(); 441 this->boostBlur_ = 0; 442 } 443 } 444 275 445 } -
code/trunk/src/orxonox/worldentities/pawns/SpaceShip.h
r7801 r8706 59 59 60 60 virtual void fire(); 61 virtual void boost( );61 virtual void boost(bool bBoost); // Starts or stops boosting. 62 62 63 void setEngine(Engine* engine); 64 inline Engine* getEngine() const 65 { return this->engine_; } 63 void addEngine(Engine* engine); 64 bool hasEngine(Engine* engine); 65 Engine* getEngine(unsigned int i); // This one's for XMLPort 66 inline const std::vector<Engine*>& getEngineList() 67 { return this->engineList_; } 68 void removeEngine(Engine* engine); 69 void removeAllEngines(); 70 71 void setSpeedFactor(float factor); 72 float getSpeedFactor(); // Gets mean speed factor 73 float getMaxSpeedFront(); // gets largest speed forward 74 float getBoostFactor(); // gets mean boost factor 66 75 67 76 inline void setSteeringDirection(const Vector3& direction) … … 69 78 inline const Vector3& getSteeringDirection() const 70 79 { return this->steering_; } 80 inline void resetEngineTicks() 81 { this->engineTicksNotDone = this->engineList_.size(); } 82 inline void oneEngineTickDone() 83 { this->engineTicksNotDone--; } 84 inline bool hasEngineTicksRemaining() 85 { return (this->engineTicksNotDone>0); } 71 86 72 void setBoost(bool bBoost);73 87 inline bool getBoost() const 74 88 { return this->bBoost_; } 75 89 76 inline void setEngineTemplate(const std::string& temp)77 { this->enginetemplate_ = temp; this->loadEngineTemplate(); }78 inline const std::string& getEngineTemplate() const79 { return this-> enginetemplate_; }90 inline float getBoostPower() const 91 { return this->boostPower_; } 92 inline float getInitialBoostPower() const 93 { return this->initialBoostPower_; } 80 94 81 inline void setPermanentBoost(bool bPermanent) 82 { this->bPermanentBoost_ = bPermanent; } 83 inline bool getPermanentBoost() const 84 { return this->bPermanentBoost_; } 95 inline bool isBoostCoolingDown() const 96 { return bBoostCooldown_; } 85 97 86 98 protected: … … 90 102 bool bBoost_; 91 103 bool bBoostCooldown_; 92 bool bPermanentBoost_;93 104 float boostPower_; 94 105 float initialBoostPower_; … … 96 107 float boostPowerRate_; 97 108 float boostCooldownDuration_; 109 float lift_; 110 float stallSpeed_; 98 111 Vector3 steering_; 99 112 float primaryThrust_; … … 103 116 btVector3 localAngularAcceleration_; 104 117 118 float shakeFrequency_; 119 float shakeAmplitude_; 120 105 121 private: 106 122 void registerVariables(); 107 123 virtual bool isCollisionTypeLegal(WorldEntity::CollisionType type) const; 124 125 //All things booster 126 void changedEnableMotionBlur(); 127 void boostCooledDown(void); 128 129 void resetCamera(); 130 void backupCamera(); 131 void shakeCamera(float dt); 108 132 109 void loadEngineTemplate();110 111 void boostCooledDown(void);133 Shader* boostBlur_; 134 float blurStrength_; 135 bool bEnableMotionBlur_; 112 136 113 std:: string enginetemplate_;114 Engine* engine_;137 std::vector<Engine*> engineList_; 138 int engineTicksNotDone; // Used for knowing when to reset temporary variables. 115 139 Timer timer_; 140 Vector3 cameraOriginalPosition_; 141 Quaternion cameraOriginalOrientation_; 142 143 float shakeDt_; 116 144 }; 117 145 }
Note: See TracChangeset
for help on using the changeset viewer.