From b37623cd86d2dec5293bee76a082a5aada5116cf Mon Sep 17 00:00:00 2001 From: diath Date: Thu, 1 Apr 2021 00:38:36 +0200 Subject: [PATCH] Fix the use of deprecated C++ functions (#1138) --- src/client/creatures.h | 4 ++-- src/client/declarations.h | 6 +++--- src/client/map.cpp | 18 ++++++++++-------- src/client/map.h | 2 +- src/client/position.h | 12 +++++++----- src/framework/core/eventdispatcher.h | 2 +- src/framework/core/scheduledevent.h | 12 ++++++------ 7 files changed, 30 insertions(+), 26 deletions(-) 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 m_attribs; - std::unordered_map m_creatures; + std::unordered_map m_creatures; friend class CreatureManager; }; @@ -137,7 +137,7 @@ protected: private: std::vector m_creatures; - std::unordered_map m_spawns; + std::unordered_map m_spawns; stdext::boolean 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 TownList; typedef std::list ItemList; typedef std::list TileList; typedef std::vector ItemVector; -typedef std::unordered_map TileMap; -typedef std::unordered_map CreatureMap; -typedef std::unordered_map SpawnMap; +typedef std::unordered_map TileMap; +typedef std::unordered_map CreatureMap; +typedef std::unordered_map 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, Otc::PathFindResult> Map::findPath(const // as described in http://en.wikipedia.org/wiki/A*_search_algorithm struct Node { + using Pair = std::pair; + 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, bool> { - bool operator()(std::pair a, std::pair 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, Otc::PathFindResult> ret; @@ -762,8 +764,8 @@ std::tuple, Otc::PathFindResult> Map::findPath(const } } - std::unordered_map nodes; - std::priority_queue, std::deque>, LessNode> searchList; + std::unordered_map nodes; + std::priority_queue, Node::Compare> searchList; Node *currentNode = new Node(startPos); currentNode->pos = startPos; @@ -856,7 +858,7 @@ std::tuple, 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 m_animatedTexts; std::vector m_staticTexts; std::vector m_mapViews; - std::unordered_map m_waypoints; + std::unordered_map 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 { - 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 m_eventList; int m_pollEventsSize; stdext::boolean m_disabled; - std::priority_queue, lessScheduledEvent> m_scheduledEventList; + std::priority_queue, 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 { - bool operator()(const ScheduledEventPtr& a, const ScheduledEventPtr& b) { - return b->ticks() < a->ticks(); - } -}; - #endif