[Orxonox-commit 5900] r10559 - in code/branches/core7/src/modules: objects/triggers pickup
landauf at orxonox.net
landauf at orxonox.net
Sat Aug 29 18:55:26 CEST 2015
Author: landauf
Date: 2015-08-29 18:55:25 +0200 (Sat, 29 Aug 2015)
New Revision: 10559
Modified:
code/branches/core7/src/modules/objects/triggers/DistanceMultiTrigger.cc
code/branches/core7/src/modules/objects/triggers/DistanceMultiTrigger.h
code/branches/core7/src/modules/pickup/PickupManager.cc
code/branches/core7/src/modules/pickup/PickupManager.h
Log:
these two classes used pointers to weakptrs - why? just use normal weakptrs, that makes more sense
Modified: code/branches/core7/src/modules/objects/triggers/DistanceMultiTrigger.cc
===================================================================
--- code/branches/core7/src/modules/objects/triggers/DistanceMultiTrigger.cc 2015-08-29 16:45:20 UTC (rev 10558)
+++ code/branches/core7/src/modules/objects/triggers/DistanceMultiTrigger.cc 2015-08-29 16:55:25 UTC (rev 10559)
@@ -99,15 +99,14 @@
std::queue<MultiTriggerState*>* queue = NULL;
// Check for objects that were in range but no longer are. Iterate through all objects, that are in range.
- for(std::map<WorldEntity*, WeakPtr<WorldEntity>* >::iterator it = this->range_.begin(); it != this->range_.end(); )
+ for(std::set<WeakPtr<WorldEntity> >::iterator it = this->range_.begin(); it != this->range_.end(); )
{
- WorldEntity* entity = it->second->get();
- WorldEntity* key = it->first;
- it++; // Incrementing the iterator in advance, since we don't need the current anymore and we potentially are going to delete the current element thus invalidating the iterator.
+ WorldEntity* entity = *it;
+
// If the entity no longer exists.
if(entity == NULL)
{
- this->removeFromRange(key);
+ this->range_.erase(it++);
continue;
}
@@ -115,9 +114,7 @@
// If the object is no longer in range.
if (distanceVec.length() > this->distance_)
{
- // If for some reason the entity could not be removed.
- if(!this->removeFromRange(key))
- continue;
+ this->range_.erase(it++);
// If no queue has been created, yet.
if(queue == NULL)
@@ -129,6 +126,10 @@
state->originator = entity;
queue->push(state);
}
+ else
+ {
+ ++it;
+ }
}
// Check for new objects that are in range
@@ -259,33 +260,7 @@
*/
bool DistanceMultiTrigger::addToRange(WorldEntity* entity)
{
- WeakPtr<WorldEntity>* weakptr = new WeakPtr<WorldEntity>(entity);
- std::pair<std::map<WorldEntity*, WeakPtr<WorldEntity>* >::iterator, bool> pair = this->range_.insert(std::pair<WorldEntity*, WeakPtr<WorldEntity>* >(entity, weakptr));
-
- if(!pair.second)
- {
- delete weakptr;
- return false;
- }
-
- return true;
+ std::pair<std::set<WeakPtr<WorldEntity> >::iterator, bool> pair = this->range_.insert(entity);
+ return pair.second;
}
-
- /**
- @brief
- Remove a given entity from the set of entities, that currently are in range of the DistanceMultiTrigger.
- @param entity
- A pointer ot the entity.
- @return
- Returns true if successful.
- */
- bool DistanceMultiTrigger::removeFromRange(WorldEntity* entity)
- {
- WeakPtr<WorldEntity>* weakptr = this->range_.find(entity)->second;
- bool erased = this->range_.erase(entity) > 0;
- if(erased)
- delete weakptr;
- return erased;
- }
-
}
Modified: code/branches/core7/src/modules/objects/triggers/DistanceMultiTrigger.h
===================================================================
--- code/branches/core7/src/modules/objects/triggers/DistanceMultiTrigger.h 2015-08-29 16:45:20 UTC (rev 10558)
+++ code/branches/core7/src/modules/objects/triggers/DistanceMultiTrigger.h 2015-08-29 16:55:25 UTC (rev 10559)
@@ -139,7 +139,6 @@
virtual std::queue<MultiTriggerState*>* letTrigger(void); // This method is called by the MultiTrigger to get information about new trigger events that need to be looked at.
bool addToRange(WorldEntity* entity); // Add a given entity to the entities, that currently are in range of the DistanceMultiTrigger.
- bool removeFromRange(WorldEntity* entity); // Remove a given entity from the set of entities, that currently are in range of the DistanceMultiTrigger.
private:
//! Strings for the beacon modes.
@@ -153,7 +152,7 @@
std::string targetName_; //!< The target name, used in <em>single-target</em> mode.
ClassTreeMask beaconMask_; //!< A mask, that only accepts DistanceTriggerBeacons.
- std::map<WorldEntity*, WeakPtr<WorldEntity>* > range_; //!< The set of entities that currently are in range of the DistanceMultiTrigger.
+ std::set<WeakPtr<WorldEntity> > range_; //!< The set of entities that currently are in range of the DistanceMultiTrigger.
};
Modified: code/branches/core7/src/modules/pickup/PickupManager.cc
===================================================================
--- code/branches/core7/src/modules/pickup/PickupManager.cc 2015-08-29 16:45:20 UTC (rev 10558)
+++ code/branches/core7/src/modules/pickup/PickupManager.cc 2015-08-29 16:55:25 UTC (rev 10559)
@@ -95,8 +95,6 @@
this->pickupInventoryContainers_.clear();
// Destroying all the WeakPointers that are still there.
- for(std::map<uint32_t, WeakPtr<Pickupable>*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
- delete it->second;
this->pickups_.clear();
this->indexes_.clear();
@@ -287,7 +285,7 @@
index = this->getPickupIndex(); // Ge a new identifier (index) for the Pickupable.
// Add the Pickupable to the indexes_ and pickups_ lists.
this->indexes_[pickup] = index;
- this->pickups_[index] = new WeakPtr<Pickupable>(pickup);
+ this->pickups_[index] = pickup;
}
else // If it was dropped, it is removed from the required lists.
{
@@ -295,11 +293,9 @@
std::map<Pickupable*, uint32_t>::iterator it = this->indexes_.find(pickup);
index = it->second;
- // Remove the Pickupable form the indexes_ and pickups_ list.
- WeakPtr<Pickupable>* ptr = this->pickups_[index];
+ // Remove the Pickupable from the indexes_ and pickups_ list.
this->indexes_.erase(it);
this->pickups_.erase(index);
- delete ptr;
}
// If we're either in standalone mode or this is the host whom the change of the pickup's status concerns.
@@ -401,7 +397,7 @@
{
if(this->pickups_.empty())
return;
- Pickupable* pickupable = this->pickups_.find(pickup)->second->get();
+ Pickupable* pickupable = this->pickups_.find(pickup)->second;
if(pickupable != NULL)
pickupable->drop();
}
@@ -444,7 +440,7 @@
{
if(this->pickups_.empty())
return;
- Pickupable* pickupable = this->pickups_.find(pickup)->second->get();
+ Pickupable* pickupable = this->pickups_.find(pickup)->second;
if(pickupable != NULL)
pickupable->setUsed(use);
}
Modified: code/branches/core7/src/modules/pickup/PickupManager.h
===================================================================
--- code/branches/core7/src/modules/pickup/PickupManager.h 2015-08-29 16:45:20 UTC (rev 10558)
+++ code/branches/core7/src/modules/pickup/PickupManager.h 2015-08-29 16:55:25 UTC (rev 10559)
@@ -160,7 +160,7 @@
std::map<uint32_t, PickupInventoryContainer*> pickupInventoryContainers_; //!< Map linking a number identifying a Pickupable to a PickupInventoryContainer, which contains all necessary information about that Pickupable.
std::map<uint32_t, PickupInventoryContainer*>::iterator pickupsIterator_; //!< An iterator pointing to the current Pickupable in pickupsList_.
- std::map<uint32_t, WeakPtr<Pickupable>*> pickups_; //!< Map linking a number identifying a Pickupable to a weak pointer of a Pickupable.
+ std::map<uint32_t, WeakPtr<Pickupable> > pickups_; //!< Map linking a number identifying a Pickupable to a weak pointer of a Pickupable.
std::map<Pickupable*, uint32_t> indexes_;//!< Map linking Pickupable to the number identifying it.
void updateGUI(void); //!< Updates the PickupInventory GUI.
More information about the Orxonox-commit
mailing list