diff options
author | Xanadu <none@none> | 2010-05-30 04:23:27 +0200 |
---|---|---|
committer | Xanadu <none@none> | 2010-05-30 04:23:27 +0200 |
commit | 7fbeef3d09dac072aec046519a90d95f0572fcf6 (patch) | |
tree | 9808843d603e64ef863e823c89b764d0bab8dcf1 /src/game/Object.h | |
parent | 14382dd1fe74c500d26b597e8de1498dcc30da68 (diff) |
Cleaned up and unified various sort predicates and moved them to Trinity namespace, replaced priority queues with sorts and purged some unused code.
--HG--
branch : trunk
Diffstat (limited to 'src/game/Object.h')
-rw-r--r-- | src/game/Object.h | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/game/Object.h b/src/game/Object.h index bda53fd655a..c5a412c3ab7 100644 --- a/src/game/Object.h +++ b/src/game/Object.h @@ -711,4 +711,33 @@ class WorldObject : public Object, public WorldLocation uint16 m_notifyflags; uint16 m_executed_notifies; }; + +namespace Trinity +{ + template<class T> + void RandomResizeList(std::list<T> &_list, uint32 _size) + { + while (_list.size() > _size) + { + typename std::list<T>::iterator itr = _list.begin(); + advance(itr, urand(0, _list.size() - 1)); + _list.erase(itr); + } + } + + // Binary predicate to sort WorldObjects based on the distance to a reference WorldObject + class ObjectDistanceOrderPred + { + public: + ObjectDistanceOrderPred(const WorldObject *pRefObj, bool ascending = true) : m_refObj(pRefObj), m_ascending(ascending) {} + bool operator()(const WorldObject *pLeft, const WorldObject *pRight) const + { + return m_ascending ? m_refObj->GetDistanceOrder(pLeft, pRight) : !m_refObj->GetDistanceOrder(pLeft, pRight); + } + private: + const WorldObject *m_refObj; + const bool m_ascending; + }; +} + #endif |