From b34d77ca3fe5236378e116eba3e4f6402eb89609 Mon Sep 17 00:00:00 2001 From: truelight Date: Tue, 22 Aug 2006 16:38:50 +0000 Subject: (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother --- graph_gui.c | 37 +++++++++--------- main_gui.c | 6 +-- oldloader.c | 8 ++-- openttd.c | 4 +- openttd.h | 1 + signs.c | 122 ++++++++++++++++++++++++++++++------------------------------ signs.h | 21 +++++------ viewport.c | 88 +++++++++++++++++++++---------------------- 8 files changed, 144 insertions(+), 143 deletions(-) diff --git a/graph_gui.c b/graph_gui.c index 6de4a1e75..ff606b794 100644 --- a/graph_gui.c +++ b/graph_gui.c @@ -1103,17 +1103,17 @@ static uint16 _last_sign_idx; static int CDECL SignNameSorter(const void *a, const void *b) { char buf1[64]; - SignStruct *ss; - const uint16 cmp1 = *(const uint16 *)a; - const uint16 cmp2 = *(const uint16 *)b; + Sign *si; + const SignID cmp1 = *(const SignID *)a; + const SignID cmp2 = *(const SignID *)b; - ss = GetSign(cmp1); - GetString(buf1, ss->str); + si = GetSign(cmp1); + GetString(buf1, si->str); if (cmp2 != _last_sign_idx) { _last_sign_idx = cmp2; - ss = GetSign(cmp2); - GetString(_bufcache, ss->str); + si = GetSign(cmp2); + GetString(_bufcache, si->str); } return strcmp(buf1, _bufcache); // sort by name @@ -1121,7 +1121,7 @@ static int CDECL SignNameSorter(const void *a, const void *b) static void GlobalSortSignList(void) { - const SignStruct *ss; + const Sign *si; uint32 n = 0; _num_sign_sort = 0; @@ -1131,8 +1131,8 @@ static void GlobalSortSignList(void) if (_sign_sort == NULL) error("Could not allocate memory for the sign-sorting-list"); - FOR_ALL_SIGNS(ss) { - _sign_sort[n++] = ss->index; + FOR_ALL_SIGNS(si) { + _sign_sort[n++] = si->index; _num_sign_sort++; } @@ -1163,17 +1163,18 @@ static void SignListWndProc(Window *w, WindowEvent *e) return; } - { const SignStruct *ss; + { + 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++) { - ss = GetSign(_sign_sort[i]); + si = GetSign(_sign_sort[i]); - if (ss->owner != OWNER_NONE) - DrawPlayerIcon(ss->owner, 4, y + 1); + if (si->owner != OWNER_NONE) + DrawPlayerIcon(si->owner, 4, y + 1); - DrawString(22, y, ss->str, 8); + DrawString(22, y, si->str, 8); y += 10; } } @@ -1183,7 +1184,7 @@ static void SignListWndProc(Window *w, WindowEvent *e) switch (e->click.widget) { case 3: { uint32 id_v = (e->click.pt.y - 15) / 10; - SignStruct *ss; + const Sign *si; if (id_v >= w->vscroll.cap) return; @@ -1193,8 +1194,8 @@ static void SignListWndProc(Window *w, WindowEvent *e) if (id_v >= w->vscroll.count) return; - ss = GetSign(_sign_sort[id_v]); - ScrollMainWindowToTile(TileVirtXY(ss->x, ss->y)); + si = GetSign(_sign_sort[id_v]); + ScrollMainWindowToTile(TileVirtXY(si->x, si->y)); } break; } } break; diff --git a/main_gui.c b/main_gui.c index e1b9393da..3f4c5f216 100644 --- a/main_gui.c +++ b/main_gui.c @@ -346,11 +346,11 @@ void ShowNetworkNeedCompanyPassword(void) #endif /* ENABLE_NETWORK */ -void ShowRenameSignWindow(const SignStruct *ss) +void ShowRenameSignWindow(const Sign *si) { - _rename_id = ss->index; + _rename_id = si->index; _rename_what = 0; - ShowQueryString(ss->str, STR_280B_EDIT_SIGN_TEXT, 30, 180, 1, 0, CS_ALPHANUMERAL); + ShowQueryString(si->str, STR_280B_EDIT_SIGN_TEXT, 30, 180, 1, 0, CS_ALPHANUMERAL); } void ShowRenameWaypointWindow(const Waypoint *wp) diff --git a/oldloader.c b/oldloader.c index 8a8a4c59d..4f66c6c6d 100644 --- a/oldloader.c +++ b/oldloader.c @@ -1233,10 +1233,10 @@ static bool LoadOldVehicle(LoadgameState *ls, int num) } static const OldChunks sign_chunk[] = { - OCL_SVAR( OC_UINT16, SignStruct, str ), - OCL_SVAR( OC_FILE_U16 | OC_VAR_I32,SignStruct, x ), - OCL_SVAR( OC_FILE_U16 | OC_VAR_I32,SignStruct, y ), - OCL_SVAR( OC_FILE_U16 | OC_VAR_I8, SignStruct, z ), + OCL_SVAR( OC_UINT16, Sign, str ), + OCL_SVAR( OC_FILE_U16 | OC_VAR_I32,Sign, x ), + OCL_SVAR( OC_FILE_U16 | OC_VAR_I32,Sign, y ), + OCL_SVAR( OC_FILE_U16 | OC_VAR_I8, Sign, z ), OCL_NULL( 6 ), // Width of sign, no longer in use diff --git a/openttd.c b/openttd.c index 4a7357991..12552f152 100644 --- a/openttd.c +++ b/openttd.c @@ -1091,9 +1091,9 @@ static void UpdateVoidTiles(void) // since savegame version 6.0 each sign has an "owner", signs without owner (from old games are set to 255) static void UpdateSignOwner(void) { - SignStruct *ss; + Sign *si; - FOR_ALL_SIGNS(ss) ss->owner = OWNER_NONE; + FOR_ALL_SIGNS(si) si->owner = OWNER_NONE; } extern void UpdateOldAircraft( void ); diff --git a/openttd.h b/openttd.h index 79f33febc..950844eb8 100644 --- a/openttd.h +++ b/openttd.h @@ -49,6 +49,7 @@ typedef uint32 PalSpriteID; ///< The number of a sprite plus all the mapping bit typedef uint32 CursorID; typedef uint16 EngineID; ///< All enginenumbers should be of this type typedef uint16 EngineRenewID; +typedef uint16 SignID; typedef uint16 UnitID; ///< All unitnumber stuff is of this type (or anyway, should be) typedef uint32 WindowNumber; diff --git a/signs.c b/signs.c index 34e0262d4..95583a493 100644 --- a/signs.c +++ b/signs.c @@ -10,7 +10,7 @@ #include "command.h" #include "variables.h" -static SignStruct *_new_sign_struct; +static Sign *_new_sign; enum { /* Max signs: 64000 (4 * 16000) */ @@ -23,26 +23,26 @@ enum { */ static void SignPoolNewBlock(uint start_item) { - SignStruct *ss; + Sign *si; /* We don't use FOR_ALL here, because FOR_ALL skips invalid items. * TODO - This is just a temporary stage, this will be removed. */ - for (ss = GetSign(start_item); ss != NULL; ss = (ss->index + 1 < GetSignPoolSize()) ? GetSign(ss->index + 1) : NULL) ss->index = start_item++; + for (si = GetSign(start_item); si != NULL; si = (si->index + 1 < GetSignPoolSize()) ? GetSign(si->index + 1) : NULL) si->index = start_item++; } /* Initialize the sign-pool */ -MemoryPool _sign_pool = { "Signs", SIGN_POOL_MAX_BLOCKS, SIGN_POOL_BLOCK_SIZE_BITS, sizeof(SignStruct), &SignPoolNewBlock, NULL, 0, 0, NULL }; +MemoryPool _sign_pool = { "Signs", SIGN_POOL_MAX_BLOCKS, SIGN_POOL_BLOCK_SIZE_BITS, sizeof(Sign), &SignPoolNewBlock, NULL, 0, 0, NULL }; /** * * Update the coordinate of one sign * */ -static void UpdateSignVirtCoords(SignStruct *ss) +static void UpdateSignVirtCoords(Sign *si) { - Point pt = RemapCoords(ss->x, ss->y, ss->z); - SetDParam(0, ss->str); - UpdateViewportSignPos(&ss->sign, pt.x, pt.y - 6, STR_2806); + Point pt = RemapCoords(si->x, si->y, si->z); + SetDParam(0, si->str); + UpdateViewportSignPos(&si->sign, pt.x, pt.y - 6, STR_2806); } /** @@ -52,9 +52,9 @@ static void UpdateSignVirtCoords(SignStruct *ss) */ void UpdateAllSignVirtCoords(void) { - SignStruct *ss; + Sign *si; - FOR_ALL_SIGNS(ss) UpdateSignVirtCoords(ss); + FOR_ALL_SIGNS(si) UpdateSignVirtCoords(si); } @@ -62,15 +62,15 @@ void UpdateAllSignVirtCoords(void) * * Marks the region of a sign as dirty * - * @param ss Pointer to the SignStruct + * @param si Pointer to the Sign */ -static void MarkSignDirty(SignStruct *ss) +static void MarkSignDirty(Sign *si) { MarkAllViewportsDirty( - ss->sign.left - 6, - ss->sign.top - 3, - ss->sign.left + ss->sign.width_1 * 4 + 12, - ss->sign.top + 45); + si->sign.left - 6, + si->sign.top - 3, + si->sign.left + si->sign.width_1 * 4 + 12, + si->sign.top + 45); } /** @@ -79,20 +79,20 @@ static void MarkSignDirty(SignStruct *ss) * * @return The pointer to the new sign, or NULL if there is no more free space */ -static SignStruct *AllocateSign(void) +static Sign *AllocateSign(void) { - SignStruct *ss; + Sign *si; /* We don't use FOR_ALL here, because FOR_ALL skips invalid items. * TODO - This is just a temporary stage, this will be removed. */ - for (ss = GetSign(0); ss != NULL; ss = (ss->index + 1 < GetSignPoolSize()) ? GetSign(ss->index + 1) : NULL) { - if (!IsValidSign(ss)) { - uint index = ss->index; + for (si = GetSign(0); si != NULL; si = (si->index + 1 < GetSignPoolSize()) ? GetSign(si->index + 1) : NULL) { + if (!IsValidSign(si)) { + uint index = si->index; - memset(ss, 0, sizeof(SignStruct)); - ss->index = index; + memset(si, 0, sizeof(Sign)); + si->index = index; - return ss; + return si; } } @@ -112,27 +112,27 @@ static SignStruct *AllocateSign(void) */ int32 CmdPlaceSign(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) { - SignStruct *ss; + Sign *si; /* Try to locate a new sign */ - ss = AllocateSign(); - if (ss == NULL) return_cmd_error(STR_2808_TOO_MANY_SIGNS); + si = AllocateSign(); + if (si == NULL) return_cmd_error(STR_2808_TOO_MANY_SIGNS); /* When we execute, really make the sign */ if (flags & DC_EXEC) { int x = TileX(tile) * TILE_SIZE; int y = TileY(tile) * TILE_SIZE; - ss->str = STR_280A_SIGN; - ss->x = x; - ss->y = y; - ss->owner = _current_player; // owner of the sign; just eyecandy - ss->z = GetSlopeZ(x,y); - UpdateSignVirtCoords(ss); - MarkSignDirty(ss); + si->str = STR_280A_SIGN; + si->x = x; + si->y = y; + si->owner = _current_player; // owner of the sign; just eyecandy + si->z = GetSlopeZ(x,y); + UpdateSignVirtCoords(si); + MarkSignDirty(si); InvalidateWindow(WC_SIGN_LIST, 0); _sign_sort_dirty = true; - _new_sign_struct = ss; + _new_sign = si; } return 0; @@ -157,18 +157,18 @@ int32 CmdRenameSign(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) if (str == 0) return CMD_ERROR; if (flags & DC_EXEC) { - SignStruct *ss = GetSign(p1); + Sign *si = GetSign(p1); /* Delete the old name */ - DeleteName(ss->str); + DeleteName(si->str); /* Assign the new one */ - ss->str = str; - ss->owner = _current_player; + si->str = str; + si->owner = _current_player; /* Update; mark sign dirty twice, because it can either becom longer, or shorter */ - MarkSignDirty(ss); - UpdateSignVirtCoords(ss); - MarkSignDirty(ss); + MarkSignDirty(si); + UpdateSignVirtCoords(si); + MarkSignDirty(si); InvalidateWindow(WC_SIGN_LIST, 0); _sign_sort_dirty = true; } else { @@ -177,13 +177,13 @@ int32 CmdRenameSign(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) } } else { /* Delete sign */ if (flags & DC_EXEC) { - SignStruct *ss = GetSign(p1); + Sign *si = GetSign(p1); /* Delete the name */ - DeleteName(ss->str); - ss->str = 0; + DeleteName(si->str); + si->str = 0; - MarkSignDirty(ss); + MarkSignDirty(si); InvalidateWindow(WC_SIGN_LIST, 0); _sign_sort_dirty = true; } @@ -200,7 +200,7 @@ int32 CmdRenameSign(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) void CcPlaceSign(bool success, TileIndex tile, uint32 p1, uint32 p2) { if (success) { - ShowRenameSignWindow(_new_sign_struct); + ShowRenameSignWindow(_new_sign); ResetObjectToPlace(); } } @@ -228,13 +228,13 @@ void InitializeSigns(void) } static const SaveLoad _sign_desc[] = { - SLE_VAR(SignStruct, str, SLE_UINT16), - SLE_CONDVAR(SignStruct, x, SLE_FILE_I16 | SLE_VAR_I32, 0, 4), - SLE_CONDVAR(SignStruct, y, SLE_FILE_I16 | SLE_VAR_I32, 0, 4), - SLE_CONDVAR(SignStruct, x, SLE_INT32, 5, SL_MAX_VERSION), - SLE_CONDVAR(SignStruct, y, SLE_INT32, 5, SL_MAX_VERSION), - SLE_CONDVAR(SignStruct, owner, SLE_UINT8, 6, SL_MAX_VERSION), - SLE_VAR(SignStruct, z, SLE_UINT8), + SLE_VAR(Sign, str, SLE_UINT16), + SLE_CONDVAR(Sign, x, SLE_FILE_I16 | SLE_VAR_I32, 0, 4), + SLE_CONDVAR(Sign, y, SLE_FILE_I16 | SLE_VAR_I32, 0, 4), + SLE_CONDVAR(Sign, x, SLE_INT32, 5, SL_MAX_VERSION), + SLE_CONDVAR(Sign, y, SLE_INT32, 5, SL_MAX_VERSION), + SLE_CONDVAR(Sign, owner, SLE_UINT8, 6, SL_MAX_VERSION), + SLE_VAR(Sign, z, SLE_UINT8), SLE_END() }; @@ -245,11 +245,11 @@ static const SaveLoad _sign_desc[] = { */ static void Save_SIGN(void) { - SignStruct *ss; + Sign *si; - FOR_ALL_SIGNS(ss) { - SlSetArrayIndex(ss->index); - SlObject(ss, _sign_desc); + FOR_ALL_SIGNS(si) { + SlSetArrayIndex(si->index); + SlObject(si, _sign_desc); } } @@ -262,13 +262,13 @@ static void Load_SIGN(void) { int index; while ((index = SlIterateArray()) != -1) { - SignStruct *ss; + Sign *si; if (!AddBlockIfNeeded(&_sign_pool, index)) error("Signs: failed loading savegame: too many signs"); - ss = GetSign(index); - SlObject(ss, _sign_desc); + si = GetSign(index); + SlObject(si, _sign_desc); } _sign_sort_dirty = true; diff --git a/signs.h b/signs.h index 726fa2695..78d1e32e4 100644 --- a/signs.h +++ b/signs.h @@ -5,26 +5,25 @@ #include "pool.h" -typedef struct SignStruct { +typedef struct Sign { StringID str; ViewportSign sign; int32 x; int32 y; byte z; - PlayerID owner; // placed by this player. Anyone can delete them though. - // OWNER_NONE for gray signs from old games. + PlayerID owner; // placed by this player. Anyone can delete them though. OWNER_NONE for gray signs from old games. - uint16 index; -} SignStruct; + SignID index; +} Sign; extern MemoryPool _sign_pool; /** * Get the pointer to the sign with index 'index' */ -static inline SignStruct *GetSign(uint index) +static inline Sign *GetSign(SignID index) { - return (SignStruct*)GetItemFromPool(&_sign_pool, index); + return (Sign *)GetItemFromPool(&_sign_pool, index); } /** @@ -43,21 +42,21 @@ static inline bool IsSignIndex(uint index) /** * Check if a Sign really exists. */ -static inline bool IsValidSign(const SignStruct* ss) +static inline bool IsValidSign(const Sign *si) { - return ss->str != STR_NULL; + return si->str != STR_NULL; } #define FOR_ALL_SIGNS_FROM(ss, start) for (ss = GetSign(start); ss != NULL; ss = (ss->index + 1 < GetSignPoolSize()) ? GetSign(ss->index + 1) : NULL) if (IsValidSign(ss)) #define FOR_ALL_SIGNS(ss) FOR_ALL_SIGNS_FROM(ss, 0) VARDEF bool _sign_sort_dirty; -VARDEF uint16 *_sign_sort; +VARDEF SignID *_sign_sort; void UpdateAllSignVirtCoords(void); void PlaceProc_Sign(TileIndex tile); /* misc.c */ -void ShowRenameSignWindow(const SignStruct *ss); +void ShowRenameSignWindow(const Sign *si); #endif /* SIGNS_H */ diff --git a/viewport.c b/viewport.c index ecbee6f22..8f4326d4f 100644 --- a/viewport.c +++ b/viewport.c @@ -883,7 +883,7 @@ static void ViewportAddStationNames(DrawPixelInfo *dpi) static void ViewportAddSigns(DrawPixelInfo *dpi) { - SignStruct *ss; + Sign *si; int left, top, right, bottom; StringSpriteToDraw *sstd; @@ -896,32 +896,32 @@ static void ViewportAddSigns(DrawPixelInfo *dpi) bottom = top + dpi->height; if (dpi->zoom < 1) { - FOR_ALL_SIGNS(ss) { - if (bottom > ss->sign.top && - top < ss->sign.top + 12 && - right > ss->sign.left && - left < ss->sign.left + ss->sign.width_1) { + FOR_ALL_SIGNS(si) { + if (bottom > si->sign.top && + top < si->sign.top + 12 && + right > si->sign.left && + left < si->sign.left + si->sign.width_1) { - sstd=AddStringToDraw(ss->sign.left + 1, ss->sign.top + 1, STR_2806, ss->str, 0, 0); + sstd=AddStringToDraw(si->sign.left + 1, si->sign.top + 1, STR_2806, si->str, 0, 0); if (sstd != NULL) { - sstd->width = ss->sign.width_1; - sstd->color = (ss->owner==OWNER_NONE)?14:_player_colors[ss->owner]; + sstd->width = si->sign.width_1; + sstd->color = (si->owner == OWNER_NONE) ? 14 : _player_colors[si->owner]; } } } } else if (dpi->zoom == 1) { right += 2; bottom += 2; - FOR_ALL_SIGNS(ss) { - if (bottom > ss->sign.top && - top < ss->sign.top + 24 && - right > ss->sign.left && - left < ss->sign.left + ss->sign.width_1*2) { + FOR_ALL_SIGNS(si) { + if (bottom > si->sign.top && + top < si->sign.top + 24 && + right > si->sign.left && + left < si->sign.left + si->sign.width_1 * 2) { - sstd=AddStringToDraw(ss->sign.left + 1, ss->sign.top + 1, STR_2806, ss->str, 0, 0); + sstd=AddStringToDraw(si->sign.left + 1, si->sign.top + 1, STR_2806, si->str, 0, 0); if (sstd != NULL) { - sstd->width = ss->sign.width_1; - sstd->color = (ss->owner==OWNER_NONE)?14:_player_colors[ss->owner]; + sstd->width = si->sign.width_1; + sstd->color = (si->owner == OWNER_NONE) ? 14 : _player_colors[si->owner]; } } } @@ -929,16 +929,16 @@ static void ViewportAddSigns(DrawPixelInfo *dpi) right += 4; bottom += 5; - FOR_ALL_SIGNS(ss) { - if (bottom > ss->sign.top && - top < ss->sign.top + 24 && - right > ss->sign.left && - left < ss->sign.left + ss->sign.width_2*4) { + FOR_ALL_SIGNS(si) { + if (bottom > si->sign.top && + top < si->sign.top + 24 && + right > si->sign.left && + left < si->sign.left + si->sign.width_2 * 4) { - sstd=AddStringToDraw(ss->sign.left + 1, ss->sign.top + 1, STR_2002, ss->str, 0, 0); + sstd=AddStringToDraw(si->sign.left + 1, si->sign.top + 1, STR_2002, si->str, 0, 0); if (sstd != NULL) { - sstd->width = ss->sign.width_2 | 0x8000; - sstd->color = (ss->owner==OWNER_NONE)?14:_player_colors[ss->owner]; + sstd->width = si->sign.width_2 | 0x8000; + sstd->color = (si->owner == OWNER_NONE) ? 14 : _player_colors[si->owner]; } } } @@ -1563,7 +1563,7 @@ static bool CheckClickOnStation(const ViewPort *vp, int x, int y) static bool CheckClickOnSign(const ViewPort *vp, int x, int y) { - const SignStruct *ss; + const Sign *si; if (!(_display_opt & DO_SHOW_SIGNS)) return false; @@ -1571,36 +1571,36 @@ static bool CheckClickOnSign(const ViewPort *vp, int x, int y) x = x - vp->left + vp->virtual_left; y = y - vp->top + vp->virtual_top; - FOR_ALL_SIGNS(ss) { - if (y >= ss->sign.top && - y < ss->sign.top + 12 && - x >= ss->sign.left && - x < ss->sign.left + ss->sign.width_1) { - ShowRenameSignWindow(ss); + FOR_ALL_SIGNS(si) { + if (y >= si->sign.top && + y < si->sign.top + 12 && + x >= si->sign.left && + x < si->sign.left + si->sign.width_1) { + ShowRenameSignWindow(si); return true; } } } else if (vp->zoom == 1) { x = (x - vp->left + 1) * 2 + vp->virtual_left; y = (y - vp->top + 1) * 2 + vp->virtual_top; - FOR_ALL_SIGNS(ss) { - if (y >= ss->sign.top && - y < ss->sign.top + 24 && - x >= ss->sign.left && - x < ss->sign.left + ss->sign.width_1 * 2) { - ShowRenameSignWindow(ss); + FOR_ALL_SIGNS(si) { + if (y >= si->sign.top && + y < si->sign.top + 24 && + x >= si->sign.left && + x < si->sign.left + si->sign.width_1 * 2) { + ShowRenameSignWindow(si); return true; } } } else { x = (x - vp->left + 3) * 4 + vp->virtual_left; y = (y - vp->top + 3) * 4 + vp->virtual_top; - FOR_ALL_SIGNS(ss) { - if (y >= ss->sign.top && - y < ss->sign.top + 24 && - x >= ss->sign.left && - x < ss->sign.left + ss->sign.width_2 * 4) { - ShowRenameSignWindow(ss); + FOR_ALL_SIGNS(si) { + if (y >= si->sign.top && + y < si->sign.top + 24 && + x >= si->sign.left && + x < si->sign.left + si->sign.width_2 * 4) { + ShowRenameSignWindow(si); return true; } } -- cgit v1.2.3-70-g09d2