[Orxonox-commit 1803] r6521 - in code/branches/pickup3/src: libraries/core modules/pickup orxonox/interfaces
dafrick at orxonox.net
dafrick at orxonox.net
Mon Mar 15 07:33:11 CET 2010
Author: dafrick
Date: 2010-03-15 07:33:11 +0100 (Mon, 15 Mar 2010)
New Revision: 6521
Modified:
code/branches/pickup3/src/libraries/core/Super.h
code/branches/pickup3/src/modules/pickup/Pickup.cc
code/branches/pickup3/src/modules/pickup/Pickup.h
code/branches/pickup3/src/modules/pickup/PickupCollection.cc
code/branches/pickup3/src/modules/pickup/PickupCollection.h
code/branches/pickup3/src/orxonox/interfaces/PickupCarrier.h
code/branches/pickup3/src/orxonox/interfaces/Pickupable.cc
code/branches/pickup3/src/orxonox/interfaces/Pickupable.h
Log:
Added changedPickedUp method to Pickupable to solve a problem in PickupCollection, which, for the most part, works now.
Modified: code/branches/pickup3/src/libraries/core/Super.h
===================================================================
--- code/branches/pickup3/src/libraries/core/Super.h 2010-03-14 09:27:41 UTC (rev 6520)
+++ code/branches/pickup3/src/libraries/core/Super.h 2010-03-15 06:33:11 UTC (rev 6521)
@@ -276,6 +276,9 @@
#define SUPER_changedCarrier(classname, functionname, ...) \
SUPER_NOARGS(classname, functionname)
+ #define SUPER_changedPickedUp(classname, functionname, ...) \
+ SUPER_NOARGS(classname, functionname)
+
// (1/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <--
@@ -538,6 +541,10 @@
SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(12, changedCarrier, false)
()
SUPER_FUNCTION_GLOBAL_DECLARATION_PART2;
+
+ SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(13, changedPickedUp, false)
+ ()
+ SUPER_FUNCTION_GLOBAL_DECLARATION_PART2;
// (2/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <--
@@ -595,6 +602,7 @@
SUPER_INTRUSIVE_DECLARATION(changedUsed);
SUPER_INTRUSIVE_DECLARATION(clone);
SUPER_INTRUSIVE_DECLARATION(changedCarrier);
+ SUPER_INTRUSIVE_DECLARATION(changedPickedUp);
// (3/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <--
Modified: code/branches/pickup3/src/modules/pickup/Pickup.cc
===================================================================
--- code/branches/pickup3/src/modules/pickup/Pickup.cc 2010-03-14 09:27:41 UTC (rev 6520)
+++ code/branches/pickup3/src/modules/pickup/Pickup.cc 2010-03-15 06:33:11 UTC (rev 6521)
@@ -181,11 +181,11 @@
/**
@brief
Should be called when the pickup has transited from picked up to dropped or the other way around.
- Any Class overwriting this method must call its SUPER function by adding SUPER(Classname, changedCarrier); to their changedCarrier method.
+ Any Class overwriting this method must call its SUPER function by adding SUPER(Classname, changedPickedUp); to their changedPickedUp method.
*/
- void Pickup::changedCarrier(void)
+ void Pickup::changedPickedUp(void)
{
- SUPER(Pickup, changedCarrier);
+ SUPER(Pickup, changedPickedUp);
//! Sets the Pickup to used if the Pickup has activation type 'immediate' and gets picked up.
if(this->getCarrier() != NULL && this->isPickedUp() && this->isImmediate())
Modified: code/branches/pickup3/src/modules/pickup/Pickup.h
===================================================================
--- code/branches/pickup3/src/modules/pickup/Pickup.h 2010-03-14 09:27:41 UTC (rev 6520)
+++ code/branches/pickup3/src/modules/pickup/Pickup.h 2010-03-15 06:33:11 UTC (rev 6521)
@@ -116,7 +116,7 @@
inline bool isContinuous(void)
{ return this->getDurationTypeDirect() == pickupDurationType::continuous; }
- virtual void changedCarrier(void); //!< Should be called when the pickup has transited from picked up to dropped or the other way around.
+ virtual void changedPickedUp(void); //!< Should be called when the pickup has transited from picked up to dropped or the other way around.
virtual void clone(OrxonoxClass*& item); //!< Creates a duplicate of the Pickup.
Modified: code/branches/pickup3/src/modules/pickup/PickupCollection.cc
===================================================================
--- code/branches/pickup3/src/modules/pickup/PickupCollection.cc 2010-03-14 09:27:41 UTC (rev 6520)
+++ code/branches/pickup3/src/modules/pickup/PickupCollection.cc 2010-03-15 06:33:11 UTC (rev 6521)
@@ -137,7 +137,6 @@
return this->pickups_[index]; //TODO. Does this work?
}
- //TODO: Steal description from Pickupable.
void PickupCollection::changedUsed(void)
{
SUPER(PickupCollection, changedUsed);
@@ -149,18 +148,28 @@
}
}
- void PickupCollection::changedCarrier()
+ void PickupCollection::changedCarrier(void)
{
SUPER(PickupCollection, changedCarrier);
- //! Change the carrier for all Pickupables this PickupCollection consists of.
+ //! Change used for all Pickupables this PickupCollection consists of.
for(std::vector<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
{
(*it)->setCarrier(this->getCarrier());
}
}
- //TODO: Steal description from Pickupable.
+ void PickupCollection::changedPickedUp()
+ {
+ SUPER(PickupCollection, changedPickedUp);
+
+ //! Change the carrier for all Pickupables this PickupCollection consists of.
+ for(std::vector<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
+ {
+ (*it)->setPickedUp(this->isPickedUp());
+ }
+ }
+
void PickupCollection::clone(OrxonoxClass*& item)
{
if(item == NULL)
Modified: code/branches/pickup3/src/modules/pickup/PickupCollection.h
===================================================================
--- code/branches/pickup3/src/modules/pickup/PickupCollection.h 2010-03-14 09:27:41 UTC (rev 6520)
+++ code/branches/pickup3/src/modules/pickup/PickupCollection.h 2010-03-15 06:33:11 UTC (rev 6521)
@@ -57,8 +57,8 @@
virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
virtual void changedUsed(void);
-
virtual void changedCarrier(void);
+ virtual void changedPickedUp(void);
virtual void clone(OrxonoxClass*& item);
Modified: code/branches/pickup3/src/orxonox/interfaces/PickupCarrier.h
===================================================================
--- code/branches/pickup3/src/orxonox/interfaces/PickupCarrier.h 2010-03-14 09:27:41 UTC (rev 6520)
+++ code/branches/pickup3/src/orxonox/interfaces/PickupCarrier.h 2010-03-15 06:33:11 UTC (rev 6521)
@@ -45,7 +45,7 @@
namespace orxonox
{
-
+
class Pickup;
class HealthPickup;
class MetaPickup;
@@ -174,7 +174,10 @@
*/
virtual const Vector3& getCarrierPosition(void) = 0;
- //TODO: Remove.
+ /**
+ @brief Get all Pickupables this PickupCarrier has.
+ @return Returns the set of all Pickupables this PickupCarrier has.
+ */
std::set<Pickupable*>& getPickups(void)
{ return this->pickups_; }
Modified: code/branches/pickup3/src/orxonox/interfaces/Pickupable.cc
===================================================================
--- code/branches/pickup3/src/orxonox/interfaces/Pickupable.cc 2010-03-14 09:27:41 UTC (rev 6520)
+++ code/branches/pickup3/src/orxonox/interfaces/Pickupable.cc 2010-03-15 06:33:11 UTC (rev 6521)
@@ -171,12 +171,50 @@
return false;
COUT(4) << "Pickupable (&" << this << ") got picked up by a PickupCarrier (&" << carrier << ")." << std::endl;
+ this->setCarrier(carrier);
this->setPickedUp(true);
- this->setCarrier(carrier);
return true;
}
/**
+ @brief
+ Helper method to set the Pickupable to either picked up or not picked up.
+ @param pickedUp
+ The value this->pickedUp_ should be set to.
+ @return
+ Returns true if the pickedUp status was changed, false if not.
+ */
+ bool Pickupable::setPickedUp(bool pickedUp)
+ {
+ if(this->pickedUp_ == pickedUp)
+ return false;
+
+ COUT(4) << "Pickupable (&" << this << ") set to pickedUp " << pickedUp << "." << std::endl;
+
+ this->pickedUp_ = pickedUp;
+ this->changedPickedUp();
+ return true;
+ }
+
+ /**
+ @brief
+ Sets the carrier of the pickup.
+ @param carrier
+ Sets the input PickupCarrier as the carrier of the pickup.
+ */
+ inline bool Pickupable::setCarrier(PickupCarrier* carrier)
+ {
+ if(this->carrier_ == carrier)
+ return false;
+
+ COUT(4) << "Pickupable (&" << this << ") changed Carrier (& " << carrier << ")." << std::endl;
+
+ this->carrier_ = carrier;
+ this->changedCarrier();
+ return true;
+ }
+
+ /**
@brief
Sets the Pickupable to not picked up or dropped.
This method will be called by the PickupCarrier dropping the Pickupable.
@@ -204,32 +242,12 @@
return true;
}
-
/**
@brief
- Sets the carrier of the pickup.
- @param carrier
- Sets the input PickupCarrier as the carrier of the pickup.
- @return
- Returns true if the carrier was changed, false if not.
- */
- bool Pickupable::setCarrier(PickupCarrier* carrier)
- {
- if(this->getCarrier() == carrier)
- return false;
-
- this->carrier_ = carrier;
- this->changedCarrier();
- return true;
- }
-
- /**
- @brief
Creates a duplicate of the Pickupable.
@return
Returns the clone of this pickup as a pointer to a Pickupable.
*/
- //TODO: Does this work?
Pickupable* Pickupable::clone(void)
{
OrxonoxClass* item = NULL;
Modified: code/branches/pickup3/src/orxonox/interfaces/Pickupable.h
===================================================================
--- code/branches/pickup3/src/orxonox/interfaces/Pickupable.h 2010-03-14 09:27:41 UTC (rev 6520)
+++ code/branches/pickup3/src/orxonox/interfaces/Pickupable.h 2010-03-15 06:33:11 UTC (rev 6521)
@@ -69,14 +69,31 @@
Any Class overwriting this method must call its SUPER function by adding SUPER(Classname, changedUsed); to their changdeUsed method.
*/
virtual void changedUsed(void) {}
- bool setUsed(bool used); //!< Sets the Pickupable to used or unused, depending on the input.
/**
+ @brief Get the carrier of the pickup.
+ @return Returns a pointer to the carrier of the pickup.
+ */
+ inline PickupCarrier* getCarrier(void)
+ { return this->carrier_; }
+ /**
+ @brief Should be called when the pickup has changed its PickupCarrier.
+ Any Class overwriting this method must call its SUPER function by adding SUPER(Classname, changedCarrier); to their changedCarrier method.
+ */
+ virtual void changedCarrier(void) {}
+
+ /**
@brief Returns whether the Pickupable is currently picked up.
@return Returns true if the Pickupable is currently picked up, false if not.
*/
inline bool isPickedUp(void)
{ return this->pickedUp_; }
+ /**
+ @brief Should be called when the pickup has transited from picked up to dropped or the other way around.
+ Any Class overwriting this method must call its SUPER function by adding SUPER(Classname, changedPickedUp); to their changedPickedUp method.
+ */
+ virtual void changedPickedUp(void) {}
+
//TODO: Better private, or protected?
bool pickedUp(PickupCarrier* carrier); //!< Sets the Pickupable to picked up.
bool dropped(void); //!< Sets the Pickupable to not picked up or dropped.
@@ -86,20 +103,6 @@
bool addTarget(PickupCarrier* target); //!< Add a PickupCarrier as target of this pickup.
bool addTarget(Identifier* identifier); //!< Add a class, representetd by the input Identifier, as target of this pickup.
- /**
- @brief Get the carrier of the pickup.
- @return Returns a pointer to the carrier of the pickup.
- */
- inline PickupCarrier* getCarrier(void)
- { return this->carrier_; }
- /**
- @brief Should be called when the pickup has transited from picked up to dropped or the other way around.
- Any Class overwriting this method must call its SUPER function by adding SUPER(Classname, changedCarrier); to their changedCarrier method.
- */
- virtual void changedCarrier(void) {}
- //TODO: Maybe private?
- bool setCarrier(PickupCarrier* carrier); //!< Sets the carrier of the pickup.
-
Pickupable* clone(void); //!< Creates a duplicate of the Pickupable.
virtual void clone(OrxonoxClass*& item); //!< Creates a duplicate of the input OrxonoxClass.
@@ -112,6 +115,11 @@
virtual void destroy(void)
{ delete this; }
+
+ //TODO: Make them work as protected.
+ bool setUsed(bool used); //!< Sets the Pickupable to used or unused, depending on the input.
+ bool setPickedUp(bool pickedUp); //!< Helper method to set the Pickupable to either picked up or not picked up.
+ bool setCarrier(PickupCarrier* carrier); //!< Sets the carrier of the pickup.
protected:
/**
@@ -133,12 +141,6 @@
PickupIdentifier* pickupIdentifier_; //!< The PickupIdentifier of this Pickupable.
private:
- /**
- @brief Helper method to set the Pickupable to either picked up or not picked up.
- @param pickedUp The value this->pickedUp_ should be set to.
- */
- inline void setPickedUp(bool pickedUp)
- { this->pickedUp_ = pickedUp; }
bool used_; //!< Whether the pickup is currently in use or not.
bool pickedUp_; //!< Whether the pickup is currently picked up or not.
@@ -150,6 +152,7 @@
SUPER_FUNCTION(10, Pickupable, changedUsed, false);
SUPER_FUNCTION(12, Pickupable, changedCarrier, false);
+ SUPER_FUNCTION(13, Pickupable, changedPickedUp, false);
}
#endif /* _Pickupable_H__ */
More information about the Orxonox-commit
mailing list