[Orxonox-commit 2008] r6725 - in code/trunk: data/levels/includes src/modules/pickup src/orxonox/interfaces src/orxonox/pickup
dafrick at orxonox.net
dafrick at orxonox.net
Tue Apr 13 22:39:54 CEST 2010
Author: dafrick
Date: 2010-04-13 22:39:54 +0200 (Tue, 13 Apr 2010)
New Revision: 6725
Modified:
code/trunk/data/levels/includes/pickups.oxi
code/trunk/src/modules/pickup/PickupManager.cc
code/trunk/src/modules/pickup/PickupManager.h
code/trunk/src/modules/pickup/PickupRepresentation.cc
code/trunk/src/orxonox/interfaces/Pickupable.cc
code/trunk/src/orxonox/pickup/PickupIdentifier.cc
Log:
Resolved bug, that caused orxonox to crash whenever a level with pickups was loaded twice in one session.
Also some more debug/info output, commenting and cleanup.
Modified: code/trunk/data/levels/includes/pickups.oxi
===================================================================
--- code/trunk/data/levels/includes/pickups.oxi 2010-04-13 20:11:36 UTC (rev 6724)
+++ code/trunk/data/levels/includes/pickups.oxi 2010-04-13 20:39:54 UTC (rev 6725)
@@ -71,46 +71,46 @@
<!-- Speed pickups -->
-<PickupRepresentation
- name = "Small Speed Boost"
- description = "Multiplies Speed of the Ship by a small amount."
- spawnerTemplate = "smallspeedpickupRepresentation"
->
- <pickup>
- <SpeedPickup template=smallspeedpickup />
- </pickup>
-</PickupRepresentation>
-
-<PickupRepresentation
- name = "Medium Speed Boost"
- description = "Multiplies Speed of the Ship by a bigger amount."
- spawnerTemplate = "mediumspeedpickupRepresentation"
->
- <pickup>
- <SpeedPickup template=mediumspeedpickup />
- </pickup>
-</PickupRepresentation>
-
-<PickupRepresentation
- name = "Huge Speed Boost"
- description = "Multiplies Speed of the Ship by a huge amount."
- spawnerTemplate = "hugespeedpickupRepresentation"
->
- <pickup>
- <SpeedPickup template=hugespeedpickup />
- </pickup>
-</PickupRepresentation>
-
-<PickupRepresentation
- name = "Small Jump Boost"
- description = "Boosts the Ship with a massive amount for a very short time."
- spawnerTemplate = "smalljumppickupRepresentation"
->
- <pickup>
- <SpeedPickup template=smalljumppickup />
- </pickup>
+<PickupRepresentation
+ name = "Small Speed Boost"
+ description = "Multiplies Speed of the Ship by a small amount."
+ spawnerTemplate = "smallspeedpickupRepresentation"
+>
+ <pickup>
+ <SpeedPickup template=smallspeedpickup />
+ </pickup>
</PickupRepresentation>
+<PickupRepresentation
+ name = "Medium Speed Boost"
+ description = "Multiplies Speed of the Ship by a bigger amount."
+ spawnerTemplate = "mediumspeedpickupRepresentation"
+>
+ <pickup>
+ <SpeedPickup template=mediumspeedpickup />
+ </pickup>
+</PickupRepresentation>
+
+<PickupRepresentation
+ name = "Huge Speed Boost"
+ description = "Multiplies Speed of the Ship by a huge amount."
+ spawnerTemplate = "hugespeedpickupRepresentation"
+>
+ <pickup>
+ <SpeedPickup template=hugespeedpickup />
+ </pickup>
+</PickupRepresentation>
+
+<PickupRepresentation
+ name = "Small Jump Boost"
+ description = "Boosts the Ship with a massive amount for a very short time."
+ spawnerTemplate = "smalljumppickupRepresentation"
+>
+ <pickup>
+ <SpeedPickup template=smalljumppickup />
+ </pickup>
+</PickupRepresentation>
+
<!-- Invisible pickups -->
<PickupRepresentation
Modified: code/trunk/src/modules/pickup/PickupManager.cc
===================================================================
--- code/trunk/src/modules/pickup/PickupManager.cc 2010-04-13 20:11:36 UTC (rev 6724)
+++ code/trunk/src/modules/pickup/PickupManager.cc 2010-04-13 20:39:54 UTC (rev 6725)
@@ -50,7 +50,7 @@
// Register tolua_open function when loading the library
DeclareToluaInterface(Pickup);
- ManageScopedSingleton(PickupManager, ScopeID::Root, false);
+ ManageScopedSingleton(PickupManager, ScopeID::Graphics, false);
/*static*/ const std::string PickupManager::guiName_s = "PickupInventory";
@@ -63,6 +63,8 @@
RegisterRootObject(PickupManager);
this->defaultRepresentation_ = new PickupRepresentation();
+
+ COUT(3) << "PickupManager created." << std::endl;
}
/**
@@ -74,6 +76,10 @@
{
if(this->defaultRepresentation_ != NULL)
this->defaultRepresentation_->destroy();
+
+ this->representations_.clear();
+
+ COUT(3) << "PickupManager destroyed." << std::endl;
}
/**
@@ -88,8 +94,8 @@
Returns true if successful and false if not.
*/
bool PickupManager::registerRepresentation(const PickupIdentifier* identifier, PickupRepresentation* representation)
- {
- if(this->representations_.find(identifier) != this->representations_.end()) //!< If the Pickupable already has a RepresentationRegistered.
+ {
+ if(identifier == NULL || representation == NULL || this->representations_.find(identifier) != this->representations_.end()) //!< If the Pickupable already has a Representation registered.
return false;
this->representations_[identifier] = representation;
@@ -100,6 +106,31 @@
/**
@brief
+ Unegisters a PickupRepresentation together with the PickupIdentifier of the Pickupable the PickupRepresentation represents.
+ @param identifier
+ The PickupIdentifier identifying the Pickupable.
+ @param representation
+ A pointer to the PickupRepresentation.
+ @return
+ Returns true if successful and false if not.
+ */
+ bool PickupManager::unregisterRepresentation(const PickupIdentifier* identifier, PickupRepresentation* representation)
+ {
+ if(identifier == NULL || representation == NULL)
+ return false;
+
+ std::map<const PickupIdentifier*, PickupRepresentation*, PickupIdentifierCompare>::iterator it = this->representations_.find(identifier);
+ if(it == this->representations_.end()) //!< If the Pickupable is not registered in the first place.
+ return false;
+
+ this->representations_.erase(it);
+
+ COUT(4) << "PickupRepresentation " << representation << " unregistered with the PickupManager." << std::endl;
+ return true;
+ }
+
+ /**
+ @brief
Get the PickupRepresentation representing the Pickupable with the input PickupIdentifier.
@param identifier
The PickupIdentifier.
Modified: code/trunk/src/modules/pickup/PickupManager.h
===================================================================
--- code/trunk/src/modules/pickup/PickupManager.h 2010-04-13 20:11:36 UTC (rev 6724)
+++ code/trunk/src/modules/pickup/PickupManager.h 2010-04-13 20:39:54 UTC (rev 6725)
@@ -66,6 +66,7 @@
static PickupManager& getInstance() { return Singleton<PickupManager>::getInstance(); } // tolua_export
bool registerRepresentation(const PickupIdentifier* identifier, PickupRepresentation* representation); //!< Registers a PickupRepresentation together with the PickupIdentifier of the Pickupable the PickupRepresentation represents.
+ bool unregisterRepresentation(const PickupIdentifier* identifier, PickupRepresentation* representation); //!< Unegisters a PickupRepresentation together with the PickupIdentifier of the Pickupable the PickupRepresentation represents.
PickupRepresentation* getRepresentation(const PickupIdentifier* identifier); //!< Get the PickupRepresentation representing the Pickupable with the input PickupIdentifier.
// tolua_begin
Modified: code/trunk/src/modules/pickup/PickupRepresentation.cc
===================================================================
--- code/trunk/src/modules/pickup/PickupRepresentation.cc 2010-04-13 20:11:36 UTC (rev 6724)
+++ code/trunk/src/modules/pickup/PickupRepresentation.cc 2010-04-13 20:39:54 UTC (rev 6725)
@@ -48,7 +48,7 @@
Constructor. Registers the object and initializes its member variables.
This is primarily for use of the PickupManager in creating a default PickupRepresentation.
*/
- PickupRepresentation::PickupRepresentation() : BaseObject(NULL), spawnerRepresentation_(NULL)
+ PickupRepresentation::PickupRepresentation() : BaseObject(NULL), spawnerRepresentation_(NULL), pickup_(NULL)
{
RegisterObject(PickupRepresentation);
@@ -59,7 +59,7 @@
@brief
Default Constructor. Registers the object and initializes its member variables.
*/
- PickupRepresentation::PickupRepresentation(BaseObject* creator) : BaseObject(creator), spawnerRepresentation_(NULL)
+ PickupRepresentation::PickupRepresentation(BaseObject* creator) : BaseObject(creator), spawnerRepresentation_(NULL), pickup_(NULL)
{
RegisterObject(PickupRepresentation);
@@ -74,6 +74,9 @@
{
if(this->spawnerRepresentation_ != NULL)
this->spawnerRepresentation_->destroy();
+
+ if(this->pickup_ != NULL)
+ PickupManager::getInstance().unregisterRepresentation(this->pickup_->getPickupIdentifier(), this);
}
/**
@@ -86,7 +89,6 @@
this->name_ = "Pickup";
this->spawnerTemplate_ = "";
this->inventoryRepresentation_ = "Default";
- this->pickup_ = NULL;
}
/**
Modified: code/trunk/src/orxonox/interfaces/Pickupable.cc
===================================================================
--- code/trunk/src/orxonox/interfaces/Pickupable.cc 2010-04-13 20:11:36 UTC (rev 6724)
+++ code/trunk/src/orxonox/interfaces/Pickupable.cc 2010-04-13 20:39:54 UTC (rev 6725)
@@ -45,7 +45,7 @@
@brief
Constructor. Registers the objects and initializes its member variables.
*/
- Pickupable::Pickupable() : used_(false), pickedUp_(false)
+ Pickupable::Pickupable() : pickupIdentifier_(NULL), used_(false), pickedUp_(false)
{
RegisterRootObject(Pickupable);
@@ -68,6 +68,9 @@
this->getCarrier()->drop(this, false);
this->setCarrier(NULL);
}
+
+ if(this->pickupIdentifier_ != NULL)
+ this->pickupIdentifier_->destroy();
}
/**
Modified: code/trunk/src/orxonox/pickup/PickupIdentifier.cc
===================================================================
--- code/trunk/src/orxonox/pickup/PickupIdentifier.cc 2010-04-13 20:11:36 UTC (rev 6724)
+++ code/trunk/src/orxonox/pickup/PickupIdentifier.cc 2010-04-13 20:39:54 UTC (rev 6725)
@@ -47,12 +47,15 @@
{
RegisterRootObject(PickupIdentifier);
+ if(pickup == NULL)
+ COUT(1) << "Error, PickupIdentifier was created without a valid Pickupable." << std::endl;
+
this->pickup_ = pickup;
}
PickupIdentifier::~PickupIdentifier()
{
-
+
}
/**
@@ -65,6 +68,30 @@
*/
int PickupIdentifier::compare(const PickupIdentifier* identifier) const
{
+ if(identifier == NULL)
+ {
+ return 1;
+ COUT(1) << "Error in PickupIdentifier::compare: Input Identifier is NULL." << std::endl;
+ }
+
+ if(identifier->pickup_ == NULL && this->pickup_ == NULL)
+ {
+ return 0;
+ COUT(1) << "Error in PickupIdentifier::compare: Pickup stored by Identifier is NULL." << std::endl;
+ }
+
+ if(identifier->pickup_ == NULL)
+ {
+ return 1;
+ COUT(1) << "Error in PickupIdentifier::compare: Pickup stored by Identifier is NULL." << std::endl;
+ }
+
+ if(this->pickup_ == NULL)
+ {
+ return -1;
+ COUT(1) << "Error in PickupIdentifier::compare: Pickup stored by Identifier is NULL." << std::endl;
+ }
+
//! If the classIdentifiers are not the same (meaning the PickupIdentifiers identify different classes), the obviously the two Pickupables identified by the PickupIdentifiers cannot be the same. An ordering is established through the alphabetical ordering of the respective classnames.
if(!identifier->pickup_->getIdentifier()->isExactlyA(this->pickup_->getIdentifier()))
return this->pickup_->getIdentifier()->getName().compare(identifier->pickup_->getIdentifier()->getName());
@@ -90,7 +117,7 @@
return it->second.compare(identifier->parameters_.find(it->first)->second);
}
- return false;
+ return 0;
}
/**
More information about the Orxonox-commit
mailing list