Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10559


Ignore:
Timestamp:
Aug 29, 2015, 6:55:25 PM (9 years ago)
Author:
landauf
Message:

these two classes used pointers to weakptrs - why? just use normal weakptrs, that makes more sense

Location:
code/branches/core7/src/modules
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core7/src/modules/objects/triggers/DistanceMultiTrigger.cc

    r9667 r10559  
    100100
    101101        // Check for objects that were in range but no longer are. Iterate through all objects, that are in range.
    102         for(std::map<WorldEntity*, WeakPtr<WorldEntity>* >::iterator it = this->range_.begin(); it != this->range_.end(); )
     102        for(std::set<WeakPtr<WorldEntity> >::iterator it = this->range_.begin(); it != this->range_.end(); )
    103103        {
    104             WorldEntity* entity = it->second->get();
    105             WorldEntity* key = it->first;
    106             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.
     104            WorldEntity* entity = *it;
     105
    107106            // If the entity no longer exists.
    108107            if(entity == NULL)
    109108            {
    110                 this->removeFromRange(key);
     109                this->range_.erase(it++);
    111110                continue;
    112111            }
     
    116115            if (distanceVec.length() > this->distance_)
    117116            {
    118                 // If for some reason the entity could not be removed.
    119                 if(!this->removeFromRange(key))
    120                     continue;
     117                this->range_.erase(it++);
    121118
    122119                // If no queue has been created, yet.
     
    129126                state->originator = entity;
    130127                queue->push(state);
     128            }
     129            else
     130            {
     131                ++it;
    131132            }
    132133        }
     
    260261    bool DistanceMultiTrigger::addToRange(WorldEntity* entity)
    261262    {
    262         WeakPtr<WorldEntity>* weakptr = new WeakPtr<WorldEntity>(entity);
    263         std::pair<std::map<WorldEntity*, WeakPtr<WorldEntity>* >::iterator, bool> pair = this->range_.insert(std::pair<WorldEntity*, WeakPtr<WorldEntity>* >(entity, weakptr));
    264 
    265         if(!pair.second)
    266         {
    267             delete weakptr;
    268             return false;
    269         }
    270 
    271         return true;
    272     }
    273 
    274     /**
    275     @brief
    276         Remove a given entity from the set of entities, that currently are in range of the DistanceMultiTrigger.
    277     @param entity
    278         A pointer ot the entity.
    279     @return
    280         Returns true if successful.
    281     */
    282     bool DistanceMultiTrigger::removeFromRange(WorldEntity* entity)
    283     {
    284         WeakPtr<WorldEntity>* weakptr = this->range_.find(entity)->second;
    285         bool erased = this->range_.erase(entity) > 0;
    286         if(erased)
    287             delete weakptr;
    288         return erased;
    289     }
    290 
     263        std::pair<std::set<WeakPtr<WorldEntity> >::iterator, bool> pair = this->range_.insert(entity);
     264        return pair.second;
     265    }
    291266}
  • code/branches/core7/src/modules/objects/triggers/DistanceMultiTrigger.h

    r9667 r10559  
    140140
    141141            bool addToRange(WorldEntity* entity); // Add a given entity to the entities, that currently are in range of the DistanceMultiTrigger.
    142             bool removeFromRange(WorldEntity* entity); // Remove a given entity from the set of entities, that currently are in range of the DistanceMultiTrigger.
    143142
    144143        private:
     
    154153            ClassTreeMask beaconMask_; //!< A mask, that only accepts DistanceTriggerBeacons.
    155154
    156             std::map<WorldEntity*, WeakPtr<WorldEntity>* > range_; //!< The set of entities that currently are in range of the DistanceMultiTrigger.
     155            std::set<WeakPtr<WorldEntity> > range_; //!< The set of entities that currently are in range of the DistanceMultiTrigger.
    157156
    158157    };
  • code/branches/core7/src/modules/pickup/PickupManager.cc

    r10478 r10559  
    9696
    9797        // Destroying all the WeakPointers that are still there.
    98         for(std::map<uint32_t, WeakPtr<Pickupable>*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
    99             delete it->second;
    10098        this->pickups_.clear();
    10199
     
    288286            // Add the Pickupable to the indexes_ and pickups_ lists.
    289287            this->indexes_[pickup] = index;
    290             this->pickups_[index] = new WeakPtr<Pickupable>(pickup);
     288            this->pickups_[index] = pickup;
    291289        }
    292290        else // If it was dropped, it is removed from the required lists.
     
    296294            index = it->second;
    297295
    298             // Remove the Pickupable form the indexes_ and pickups_ list.
    299             WeakPtr<Pickupable>* ptr = this->pickups_[index];
     296            // Remove the Pickupable from the indexes_ and pickups_ list.
    300297            this->indexes_.erase(it);
    301298            this->pickups_.erase(index);
    302             delete ptr;
    303299        }
    304300
     
    402398            if(this->pickups_.empty())
    403399                return;
    404             Pickupable* pickupable = this->pickups_.find(pickup)->second->get();
     400            Pickupable* pickupable = this->pickups_.find(pickup)->second;
    405401            if(pickupable != NULL)
    406402                pickupable->drop();
     
    445441            if(this->pickups_.empty())
    446442                return;
    447             Pickupable* pickupable = this->pickups_.find(pickup)->second->get();
     443            Pickupable* pickupable = this->pickups_.find(pickup)->second;
    448444            if(pickupable != NULL)
    449445                pickupable->setUsed(use);
  • code/branches/core7/src/modules/pickup/PickupManager.h

    r9667 r10559  
    161161            std::map<uint32_t, PickupInventoryContainer*>::iterator pickupsIterator_; //!< An iterator pointing to the current Pickupable in pickupsList_.
    162162
    163             std::map<uint32_t, WeakPtr<Pickupable>*> pickups_; //!< Map linking a number identifying a Pickupable to a weak pointer of a Pickupable.
     163            std::map<uint32_t, WeakPtr<Pickupable> > pickups_; //!< Map linking a number identifying a Pickupable to a weak pointer of a Pickupable.
    164164            std::map<Pickupable*, uint32_t> indexes_;//!< Map linking Pickupable to the number identifying it.
    165165
Note: See TracChangeset for help on using the changeset viewer.