diff --git a/src/client/creatures.h b/src/client/creatures.h index c52b24de..ae295a3a 100644 --- a/src/client/creatures.h +++ b/src/client/creatures.h @@ -72,7 +72,7 @@ protected: private: stdext::dynamic_storage<uint8> m_attribs; - std::unordered_map<Position, CreatureTypePtr, PositionHasher> m_creatures; + std::unordered_map<Position, CreatureTypePtr, Position::Hasher> m_creatures; friend class CreatureManager; }; @@ -137,7 +137,7 @@ protected: private: std::vector<CreatureTypePtr> m_creatures; - std::unordered_map<Position, SpawnPtr, PositionHasher> m_spawns; + std::unordered_map<Position, SpawnPtr, Position::Hasher> m_spawns; stdext::boolean<false> m_loaded, m_spawnLoaded; CreatureTypePtr m_nullCreature; }; diff --git a/src/client/declarations.h b/src/client/declarations.h index e55db9f3..3f9442c4 100644 --- a/src/client/declarations.h +++ b/src/client/declarations.h @@ -85,9 +85,9 @@ typedef std::list<TownPtr> TownList; typedef std::list<ItemPtr> ItemList; typedef std::list<TilePtr> TileList; typedef std::vector<ItemPtr> ItemVector; -typedef std::unordered_map<Position, TilePtr, PositionHasher> TileMap; -typedef std::unordered_map<Position, CreatureTypePtr, PositionHasher> CreatureMap; -typedef std::unordered_map<Position, SpawnPtr, PositionHasher> SpawnMap; +typedef std::unordered_map<Position, TilePtr, Position::Hasher> TileMap; +typedef std::unordered_map<Position, CreatureTypePtr, Position::Hasher> CreatureMap; +typedef std::unordered_map<Position, SpawnPtr, Position::Hasher> SpawnMap; // net class ProtocolLogin; diff --git a/src/client/map.cpp b/src/client/map.cpp index b283d830..d396e588 100644 --- a/src/client/map.cpp +++ b/src/client/map.cpp @@ -718,18 +718,20 @@ std::tuple<std::vector<Otc::Direction>, Otc::PathFindResult> Map::findPath(const // as described in http://en.wikipedia.org/wiki/A*_search_algorithm struct Node { + using Pair = std::pair<Node *, float>; + Node(const Position& pos) : cost(0), totalCost(0), pos(pos), prev(nullptr), dir(Otc::InvalidDirection) { } float cost; float totalCost; Position pos; Node *prev; Otc::Direction dir; - }; - struct LessNode : std::binary_function<std::pair<Node*, float>, std::pair<Node*, float>, bool> { - bool operator()(std::pair<Node*, float> a, std::pair<Node*, float> b) const { - return b.second < a.second; - } + struct Compare { + bool operator() (const Pair &a, const Pair &b) const { + return b.second < a.second; + } + }; }; std::tuple<std::vector<Otc::Direction>, Otc::PathFindResult> ret; @@ -762,8 +764,8 @@ std::tuple<std::vector<Otc::Direction>, Otc::PathFindResult> Map::findPath(const } } - std::unordered_map<Position, Node*, PositionHasher> nodes; - std::priority_queue<std::pair<Node*, float>, std::deque<std::pair<Node*, float>>, LessNode> searchList; + std::unordered_map<Position, Node*, Position::Hasher> nodes; + std::priority_queue<Node::Pair, std::deque<Node::Pair>, Node::Compare> searchList; Node *currentNode = new Node(startPos); currentNode->pos = startPos; @@ -856,7 +858,7 @@ std::tuple<std::vector<Otc::Direction>, Otc::PathFindResult> Map::findPath(const neighborNode->cost = cost; neighborNode->totalCost = neighborNode->cost + neighborPos.distance(goalPos); neighborNode->dir = walkDir; - searchList.push(std::make_pair(neighborNode, neighborNode->totalCost)); + searchList.emplace(neighborNode, neighborNode->totalCost); } } diff --git a/src/client/map.h b/src/client/map.h index a7ce119b..f7734fc3 100644 --- a/src/client/map.h +++ b/src/client/map.h @@ -253,7 +253,7 @@ private: std::vector<AnimatedTextPtr> m_animatedTexts; std::vector<StaticTextPtr> m_staticTexts; std::vector<MapViewPtr> m_mapViews; - std::unordered_map<Position, std::string, PositionHasher> m_waypoints; + std::unordered_map<Position, std::string, Position::Hasher> m_waypoints; uint8 m_animationFlags; uint32 m_zoneFlags; diff --git a/src/client/position.h b/src/client/position.h index e015e9d8..72910af8 100644 --- a/src/client/position.h +++ b/src/client/position.h @@ -243,12 +243,14 @@ public: int x; int y; short z; -}; -struct PositionHasher : std::unary_function<Position, std::size_t> { - std::size_t operator()(const Position& pos) const { - return (((pos.x * 8192) + pos.y) * 16) + pos.z; - } + // NOTE: This does not increase the size of the struct. + struct Hasher + { + std::size_t operator() (const Position& pos) const { + return (((pos.x * 8192) + pos.y) * 16) + pos.z; + } + }; }; inline std::ostream& operator<<(std::ostream& out, const Position& pos) diff --git a/src/framework/core/eventdispatcher.h b/src/framework/core/eventdispatcher.h index bb0de018..00c89b94 100644 --- a/src/framework/core/eventdispatcher.h +++ b/src/framework/core/eventdispatcher.h @@ -43,7 +43,7 @@ private: std::deque<EventPtr> m_eventList; int m_pollEventsSize; stdext::boolean<false> m_disabled; - std::priority_queue<ScheduledEventPtr, std::deque<ScheduledEventPtr>, lessScheduledEvent> m_scheduledEventList; + std::priority_queue<ScheduledEventPtr, std::deque<ScheduledEventPtr>, ScheduledEvent::Compare> m_scheduledEventList; }; extern EventDispatcher g_dispatcher; diff --git a/src/framework/core/scheduledevent.h b/src/framework/core/scheduledevent.h index d64a7864..ad46ae70 100644 --- a/src/framework/core/scheduledevent.h +++ b/src/framework/core/scheduledevent.h @@ -40,6 +40,12 @@ public: int cyclesExecuted() { return m_cyclesExecuted; } int maxCycles() { return m_maxCycles; } + struct Compare { + bool operator() (const ScheduledEventPtr &a, const ScheduledEventPtr &b) const { + return b->ticks() < a->ticks(); + } + }; + private: ticks_t m_ticks; int m_delay; @@ -47,10 +53,4 @@ private: int m_cyclesExecuted; }; -struct lessScheduledEvent : std::binary_function<ScheduledEventPtr, ScheduledEventPtr&, bool> { - bool operator()(const ScheduledEventPtr& a, const ScheduledEventPtr& b) { - return b->ticks() < a->ticks(); - } -}; - #endif