equal
deleted
inserted
replaced
149 if (r == 0) r = strcasecmp(cmp1->info.server_name, cmp2->info.server_name); |
149 if (r == 0) r = strcasecmp(cmp1->info.server_name, cmp2->info.server_name); |
150 |
150 |
151 return (_internal_sort_order & 1) ? -r : r; |
151 return (_internal_sort_order & 1) ? -r : r; |
152 } |
152 } |
153 |
153 |
154 static NGameNameSortFunction* const _ngame_sorter[] = { |
|
155 &NGameNameSorter, |
|
156 &NGameClientSorter, |
|
157 &NGameAllowedSorter |
|
158 }; |
|
159 |
|
160 /** (Re)build the network game list as its amount has changed because |
154 /** (Re)build the network game list as its amount has changed because |
161 * an item has been added or deleted for example |
155 * an item has been added or deleted for example |
162 * @param ngl list_d struct that contains all necessary information for sorting */ |
156 * @param ngl list_d struct that contains all necessary information for sorting */ |
163 static void BuildNetworkGameList(network_ql_d *nqld) |
157 static void BuildNetworkGameList(network_ql_d *nqld) |
164 { |
158 { |
186 nqld->l.flags |= VL_RESORT; |
180 nqld->l.flags |= VL_RESORT; |
187 } |
181 } |
188 |
182 |
189 static void SortNetworkGameList(network_ql_d *nqld) |
183 static void SortNetworkGameList(network_ql_d *nqld) |
190 { |
184 { |
|
185 static NGameNameSortFunction* const ngame_sorter[] = { |
|
186 &NGameNameSorter, |
|
187 &NGameClientSorter, |
|
188 &NGameAllowedSorter |
|
189 }; |
|
190 |
191 NetworkGameList *item; |
191 NetworkGameList *item; |
192 uint i; |
192 uint i; |
193 |
193 |
194 if (!(nqld->l.flags & VL_RESORT)) return; |
194 if (!(nqld->l.flags & VL_RESORT)) return; |
|
195 if (nqld->l.list_length == 0) return; |
195 |
196 |
196 _internal_sort_order = nqld->l.flags & VL_DESC; |
197 _internal_sort_order = nqld->l.flags & VL_DESC; |
197 qsort(nqld->sort_list, nqld->l.list_length, sizeof(nqld->sort_list[0]), _ngame_sorter[nqld->l.sort_type]); |
198 qsort(nqld->sort_list, nqld->l.list_length, sizeof(nqld->sort_list[0]), ngame_sorter[nqld->l.sort_type]); |
198 |
199 |
199 /* After sorting ngl->sort_list contains the sorted items. Put these back |
200 /* After sorting ngl->sort_list contains the sorted items. Put these back |
200 * into the original list. Basically nothing has changed, we are only |
201 * into the original list. Basically nothing has changed, we are only |
201 * shuffling the ->next pointers */ |
202 * shuffling the ->next pointers */ |
202 _network_game_list = nqld->sort_list[0]; |
203 _network_game_list = nqld->sort_list[0]; |