diff options
author | glx <glx@openttd.org> | 2019-04-11 21:26:02 +0200 |
---|---|---|
committer | PeterN <peter@fuzzle.org> | 2019-04-13 12:49:18 +0100 |
commit | 2db88953e7e0e521b4514f356038eeb36b299dff (patch) | |
tree | 0f058052645065811ffa58deaee2e592583587b5 /src/network | |
parent | b9b34f676b96e29ec91711bd7ff74d2492424655 (diff) | |
download | openttd-2db88953e7e0e521b4514f356038eeb36b299dff.tar.xz |
Codechange: use std::sort() in GUIList
Diffstat (limited to 'src/network')
-rw-r--r-- | src/network/network_content_gui.cpp | 22 | ||||
-rw-r--r-- | src/network/network_gui.cpp | 50 |
2 files changed, 36 insertions, 36 deletions
diff --git a/src/network/network_content_gui.cpp b/src/network/network_content_gui.cpp index f3eb597a6..875a5b77c 100644 --- a/src/network/network_content_gui.cpp +++ b/src/network/network_content_gui.cpp @@ -405,28 +405,28 @@ class NetworkContentListWindow : public Window, ContentCallback { } /** Sort content by name. */ - static int CDECL NameSorter(const ContentInfo * const *a, const ContentInfo * const *b) + static bool NameSorter(const ContentInfo * const &a, const ContentInfo * const &b) { - return strnatcmp((*a)->name, (*b)->name, true); // Sort by name (natural sorting). + return strnatcmp(a->name, b->name, true) < 0; // Sort by name (natural sorting). } /** Sort content by type. */ - static int CDECL TypeSorter(const ContentInfo * const *a, const ContentInfo * const *b) + static bool TypeSorter(const ContentInfo * const &a, const ContentInfo * const &b) { int r = 0; - if ((*a)->type != (*b)->type) { - r = strnatcmp(content_type_strs[(*a)->type], content_type_strs[(*b)->type]); + if (a->type != b->type) { + r = strnatcmp(content_type_strs[a->type], content_type_strs[b->type]); } - if (r == 0) r = NameSorter(a, b); - return r; + if (r == 0) return NameSorter(a, b); + return r < 0; } /** Sort content by state. */ - static int CDECL StateSorter(const ContentInfo * const *a, const ContentInfo * const *b) + static bool StateSorter(const ContentInfo * const &a, const ContentInfo * const &b) { - int r = (*a)->state - (*b)->state; - if (r == 0) r = TypeSorter(a, b); - return r; + int r = a->state - b->state; + if (r == 0) return TypeSorter(a, b); + return r < 0; } /** Sort the content list */ diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp index 2e85f7966..50678e8a6 100644 --- a/src/network/network_gui.cpp +++ b/src/network/network_gui.cpp @@ -277,10 +277,10 @@ protected: } /** Sort servers by name. */ - static int CDECL NGameNameSorter(NetworkGameList * const *a, NetworkGameList * const *b) + static bool NGameNameSorter(NetworkGameList * const &a, NetworkGameList * const &b) { - int r = strnatcmp((*a)->info.server_name, (*b)->info.server_name, true); // Sort by name (natural sorting). - return r == 0 ? (*a)->address.CompareTo((*b)->address) : r; + int r = strnatcmp(a->info.server_name, b->info.server_name, true); // Sort by name (natural sorting). + return r == 0 ? a->address.CompareTo(b->address) < 0: r < 0; } /** @@ -288,60 +288,60 @@ protected: * server. If the two servers have the same amount, the one with the * higher maximum is preferred. */ - static int CDECL NGameClientSorter(NetworkGameList * const *a, NetworkGameList * const *b) + static bool NGameClientSorter(NetworkGameList * const &a, NetworkGameList * const &b) { /* Reverse as per default we are interested in most-clients first */ - int r = (*a)->info.clients_on - (*b)->info.clients_on; + int r = a->info.clients_on - b->info.clients_on; - if (r == 0) r = (*a)->info.clients_max - (*b)->info.clients_max; - if (r == 0) r = NGameNameSorter(a, b); + if (r == 0) r = a->info.clients_max - b->info.clients_max; + if (r == 0) return NGameNameSorter(a, b); - return r; + return r < 0; } /** Sort servers by map size */ - static int CDECL NGameMapSizeSorter(NetworkGameList * const *a, NetworkGameList * const *b) + static bool NGameMapSizeSorter(NetworkGameList * const &a, NetworkGameList * const &b) { /* Sort by the area of the map. */ - int r = ((*a)->info.map_height) * ((*a)->info.map_width) - ((*b)->info.map_height) * ((*b)->info.map_width); + int r = (a->info.map_height) * (a->info.map_width) - (b->info.map_height) * (b->info.map_width); - if (r == 0) r = (*a)->info.map_width - (*b)->info.map_width; - return (r != 0) ? r : NGameClientSorter(a, b); + if (r == 0) r = a->info.map_width - b->info.map_width; + return (r != 0) ? r < 0 : NGameClientSorter(a, b); } /** Sort servers by current date */ - static int CDECL NGameDateSorter(NetworkGameList * const *a, NetworkGameList * const *b) + static bool NGameDateSorter(NetworkGameList * const &a, NetworkGameList * const &b) { - int r = (*a)->info.game_date - (*b)->info.game_date; - return (r != 0) ? r : NGameClientSorter(a, b); + int r = a->info.game_date - b->info.game_date; + return (r != 0) ? r < 0 : NGameClientSorter(a, b); } /** Sort servers by the number of days the game is running */ - static int CDECL NGameYearsSorter(NetworkGameList * const *a, NetworkGameList * const *b) + static bool NGameYearsSorter(NetworkGameList * const &a, NetworkGameList * const &b) { - int r = (*a)->info.game_date - (*a)->info.start_date - (*b)->info.game_date + (*b)->info.start_date; - return (r != 0) ? r : NGameDateSorter(a, b); + int r = a->info.game_date - a->info.start_date - b->info.game_date + b->info.start_date; + return (r != 0) ? r < 0: NGameDateSorter(a, b); } /** * Sort servers by joinability. If both servers are the * same, prefer the non-passworded server first. */ - static int CDECL NGameAllowedSorter(NetworkGameList * const *a, NetworkGameList * const *b) + static bool NGameAllowedSorter(NetworkGameList * const &a, NetworkGameList * const &b) { /* The servers we do not know anything about (the ones that did not reply) should be at the bottom) */ - int r = StrEmpty((*a)->info.server_revision) - StrEmpty((*b)->info.server_revision); + int r = StrEmpty(a->info.server_revision) - StrEmpty(b->info.server_revision); /* Reverse default as we are interested in version-compatible clients first */ - if (r == 0) r = (*b)->info.version_compatible - (*a)->info.version_compatible; + if (r == 0) r = b->info.version_compatible - a->info.version_compatible; /* The version-compatible ones are then sorted with NewGRF compatible first, incompatible last */ - if (r == 0) r = (*b)->info.compatible - (*a)->info.compatible; + if (r == 0) r = b->info.compatible - a->info.compatible; /* Passworded servers should be below unpassworded servers */ - if (r == 0) r = (*a)->info.use_password - (*b)->info.use_password; + if (r == 0) r = a->info.use_password - b->info.use_password; /* Finally sort on the number of clients of the server */ - if (r == 0) r = -NGameClientSorter(a, b); + if (r == 0) return NGameClientSorter(a, b); - return r; + return r < 0; } /** Sort the server list */ |