Mercurial > hg > openttd
changeset 4353:29e729966b22 draft
(svn r6054) Change the sign sorter in a similar way as the other sorters: Remember a list of pointers to signs instead of a list of SignIDs - This removes a layer of indirection
Also make the sign list static
author | tron <tron@openttd.org> |
---|---|
date | Tue, 22 Aug 2006 20:39:18 +0000 |
parents | 8ee35b76f02e |
children | 957b7fc45ad6 |
files | graph_gui.c signs.h |
diffstat | 2 files changed, 17 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/graph_gui.c +++ b/graph_gui.c @@ -1095,25 +1095,23 @@ } -static uint16 _num_sign_sort; +static const Sign **_sign_sort; +static uint _num_sign_sort; static char _bufcache[64]; -static uint16 _last_sign_idx; +static const Sign *_last_sign; static int CDECL SignNameSorter(const void *a, const void *b) { + const Sign *sign0 = *(const Sign**)a; + const Sign *sign1 = *(const Sign**)b; char buf1[64]; - Sign *si; - const SignID cmp1 = *(const SignID *)a; - const SignID cmp2 = *(const SignID *)b; - si = GetSign(cmp1); - GetString(buf1, si->str); + GetString(buf1, sign0->str); - if (cmp2 != _last_sign_idx) { - _last_sign_idx = cmp2; - si = GetSign(cmp2); - GetString(_bufcache, si->str); + if (sign1 != _last_sign) { + _last_sign = sign1; + GetString(_bufcache, sign1->str); } return strcmp(buf1, _bufcache); // sort by name @@ -1122,21 +1120,18 @@ static void GlobalSortSignList(void) { const Sign *si; - uint32 n = 0; - - _num_sign_sort = 0; + uint n = 0; /* Create array for sorting */ _sign_sort = realloc(_sign_sort, GetSignPoolSize() * sizeof(_sign_sort[0])); - if (_sign_sort == NULL) + if (_sign_sort == NULL) { error("Could not allocate memory for the sign-sorting-list"); - - FOR_ALL_SIGNS(si) { - _sign_sort[n++] = si->index; - _num_sign_sort++; } - qsort(_sign_sort, n, sizeof(_sign_sort[0]), SignNameSorter); + FOR_ALL_SIGNS(si) _sign_sort[n++] = si; + _num_sign_sort = n; + + qsort((void*)_sign_sort, n, sizeof(_sign_sort[0]), SignNameSorter); _sign_sort_dirty = false; @@ -1164,12 +1159,11 @@ } { - const Sign *si; uint16 i; /* Start drawing the signs */ for (i = w->vscroll.pos; i < w->vscroll.cap + w->vscroll.pos && i < w->vscroll.count; i++) { - si = GetSign(_sign_sort[i]); + const Sign *si = _sign_sort[i]; if (si->owner != OWNER_NONE) DrawPlayerIcon(si->owner, 4, y + 1); @@ -1194,7 +1188,7 @@ if (id_v >= w->vscroll.count) return; - si = GetSign(_sign_sort[id_v]); + si = _sign_sort[id_v]; ScrollMainWindowToTile(TileVirtXY(si->x, si->y)); } break; }