Fix the use of deprecated C++ functions (#1138)

This commit is contained in:
diath 2021-04-01 00:38:36 +02:00 committed by GitHub
parent 67b7dbfcfe
commit b37623cd86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 30 additions and 26 deletions

View File

@ -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;
};

View File

@ -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;

View File

@ -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);
}
}

View File

@ -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;

View File

@ -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)

View File

@ -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;

View File

@ -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