mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-16 00:12:51 +00:00
(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
This commit is contained in:
parent
213c71be3f
commit
f2b804f0a6
40
graph_gui.c
40
graph_gui.c
@ -1095,25 +1095,23 @@ void ShowPerformanceRatingDetail(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static uint16 _num_sign_sort;
|
static const Sign **_sign_sort;
|
||||||
|
static uint _num_sign_sort;
|
||||||
|
|
||||||
static char _bufcache[64];
|
static char _bufcache[64];
|
||||||
static uint16 _last_sign_idx;
|
static const Sign *_last_sign;
|
||||||
|
|
||||||
static int CDECL SignNameSorter(const void *a, const void *b)
|
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];
|
char buf1[64];
|
||||||
Sign *si;
|
|
||||||
const SignID cmp1 = *(const SignID *)a;
|
|
||||||
const SignID cmp2 = *(const SignID *)b;
|
|
||||||
|
|
||||||
si = GetSign(cmp1);
|
GetString(buf1, sign0->str);
|
||||||
GetString(buf1, si->str);
|
|
||||||
|
|
||||||
if (cmp2 != _last_sign_idx) {
|
if (sign1 != _last_sign) {
|
||||||
_last_sign_idx = cmp2;
|
_last_sign = sign1;
|
||||||
si = GetSign(cmp2);
|
GetString(_bufcache, sign1->str);
|
||||||
GetString(_bufcache, si->str);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return strcmp(buf1, _bufcache); // sort by name
|
return strcmp(buf1, _bufcache); // sort by name
|
||||||
@ -1122,21 +1120,18 @@ static int CDECL SignNameSorter(const void *a, const void *b)
|
|||||||
static void GlobalSortSignList(void)
|
static void GlobalSortSignList(void)
|
||||||
{
|
{
|
||||||
const Sign *si;
|
const Sign *si;
|
||||||
uint32 n = 0;
|
uint n = 0;
|
||||||
|
|
||||||
_num_sign_sort = 0;
|
|
||||||
|
|
||||||
/* Create array for sorting */
|
/* Create array for sorting */
|
||||||
_sign_sort = realloc(_sign_sort, GetSignPoolSize() * sizeof(_sign_sort[0]));
|
_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");
|
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;
|
_sign_sort_dirty = false;
|
||||||
|
|
||||||
@ -1164,12 +1159,11 @@ static void SignListWndProc(Window *w, WindowEvent *e)
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
const Sign *si;
|
|
||||||
uint16 i;
|
uint16 i;
|
||||||
|
|
||||||
/* Start drawing the signs */
|
/* Start drawing the signs */
|
||||||
for (i = w->vscroll.pos; i < w->vscroll.cap + w->vscroll.pos && i < w->vscroll.count; i++) {
|
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)
|
if (si->owner != OWNER_NONE)
|
||||||
DrawPlayerIcon(si->owner, 4, y + 1);
|
DrawPlayerIcon(si->owner, 4, y + 1);
|
||||||
@ -1194,7 +1188,7 @@ static void SignListWndProc(Window *w, WindowEvent *e)
|
|||||||
if (id_v >= w->vscroll.count)
|
if (id_v >= w->vscroll.count)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
si = GetSign(_sign_sort[id_v]);
|
si = _sign_sort[id_v];
|
||||||
ScrollMainWindowToTile(TileVirtXY(si->x, si->y));
|
ScrollMainWindowToTile(TileVirtXY(si->x, si->y));
|
||||||
} break;
|
} break;
|
||||||
}
|
}
|
||||||
|
1
signs.h
1
signs.h
@ -51,7 +51,6 @@ static inline bool IsValidSignID(uint index)
|
|||||||
#define FOR_ALL_SIGNS(ss) FOR_ALL_SIGNS_FROM(ss, 0)
|
#define FOR_ALL_SIGNS(ss) FOR_ALL_SIGNS_FROM(ss, 0)
|
||||||
|
|
||||||
VARDEF bool _sign_sort_dirty;
|
VARDEF bool _sign_sort_dirty;
|
||||||
VARDEF SignID *_sign_sort;
|
|
||||||
|
|
||||||
void UpdateAllSignVirtCoords(void);
|
void UpdateAllSignVirtCoords(void);
|
||||||
void PlaceProc_Sign(TileIndex tile);
|
void PlaceProc_Sign(TileIndex tile);
|
||||||
|
Loading…
Reference in New Issue
Block a user