Mercurial > hg > openttd
changeset 7266:550b96f71f7f draft
(svn r10587) -Codechange: move the string/dparam related stuff from variables.h to strings.h
author | rubidium <rubidium@openttd.org> |
---|---|
date | Mon, 16 Jul 2007 09:16:58 +0000 |
parents | 58f096a8b659 |
children | 9a57f3459771 |
files | src/aircraft_cmd.cpp src/aircraft_gui.cpp src/autoreplace_gui.cpp src/bridge_gui.cpp src/command.cpp src/depot_gui.cpp src/disaster_cmd.cpp src/economy.cpp src/engine_gui.cpp src/graph_gui.cpp src/industry_cmd.cpp src/intro_gui.cpp src/main_gui.cpp src/misc_gui.cpp src/music_gui.cpp src/network/network_client.cpp src/news_gui.cpp src/openttd.cpp src/order_gui.cpp src/player_gui.cpp src/rail_gui.cpp src/road_cmd.cpp src/road_gui.cpp src/roadveh_cmd.cpp src/settings.cpp src/ship_cmd.cpp src/ship_gui.cpp src/signs.cpp src/smallmap_gui.cpp src/stdafx.h src/strings.cpp src/strings.h src/subsidy_gui.cpp src/timetable_gui.cpp src/train_cmd.cpp src/train_gui.cpp src/tunnelbridge_cmd.cpp src/variables.h src/water_cmd.cpp |
diffstat | 39 files changed, 125 insertions(+), 83 deletions(-) [+] |
line wrap: on
line diff
--- a/src/aircraft_cmd.cpp +++ b/src/aircraft_cmd.cpp @@ -10,6 +10,7 @@ #include "functions.h" #include "landscape.h" #include "station_map.h" +#include "strings.h" #include "table/strings.h" #include "map.h" #include "tile.h"
--- a/src/aircraft_gui.cpp +++ b/src/aircraft_gui.cpp @@ -9,6 +9,7 @@ #include "functions.h" #include "table/sprites.h" #include "table/strings.h" +#include "strings.h" #include "map.h" #include "window.h" #include "gui.h"
--- a/src/autoreplace_gui.cpp +++ b/src/autoreplace_gui.cpp @@ -8,6 +8,7 @@ #include "functions.h" #include "table/sprites.h" #include "table/strings.h" +#include "strings.h" #include "window.h" #include "gui.h" #include "command.h"
--- a/src/bridge_gui.cpp +++ b/src/bridge_gui.cpp @@ -5,6 +5,7 @@ #include "stdafx.h" #include "openttd.h" #include "table/strings.h" +#include "strings.h" #include "functions.h" #include "map.h" #include "window.h"
--- a/src/command.cpp +++ b/src/command.cpp @@ -5,6 +5,7 @@ #include "stdafx.h" #include "openttd.h" #include "table/strings.h" +#include "strings.h" #include "functions.h" #include "landscape.h" #include "map.h"
--- a/src/depot_gui.cpp +++ b/src/depot_gui.cpp @@ -10,6 +10,7 @@ #include "ship.h" #include "aircraft.h" #include "table/strings.h" +#include "strings.h" #include "table/sprites.h" #include "gui.h" #include "gfx.h"
--- a/src/disaster_cmd.cpp +++ b/src/disaster_cmd.cpp @@ -23,6 +23,7 @@ #include "industry_map.h" #include "station_map.h" #include "table/strings.h" +#include "strings.h" #include "map.h" #include "tile.h" #include "vehicle.h"
--- a/src/economy.cpp +++ b/src/economy.cpp @@ -538,7 +538,7 @@ int32 price; DrawStringCentered(w->width>>1, 1, STR_7059_TRANSPORT_COMPANY_MERGER, 0); - COPY_IN_DPARAM(0,WP(w,news_d).ni->params, 2); + CopyInDParam(0,WP(w,news_d).ni->params, 2); SetDParam(2, p->index); price = WP(w,news_d).ni->params[2]; SetDParam(3, price); @@ -552,7 +552,7 @@ case NB_BBANKRUPT: DrawStringCentered(w->width>>1, 1, STR_705C_BANKRUPT, 0); - COPY_IN_DPARAM(0,WP(w,news_d).ni->params, 2); + CopyInDParam(0,WP(w,news_d).ni->params, 2); DrawStringMultiCenter( ((w->width - 101) >> 1) + 98, 90, @@ -563,7 +563,7 @@ case NB_BNEWCOMPANY: DrawStringCentered(w->width>>1, 1, STR_705E_NEW_TRANSPORT_COMPANY_LAUNCHED, 0); SetDParam(0, p->index); - COPY_IN_DPARAM(1,WP(w,news_d).ni->params, 2); + CopyInDParam(1,WP(w,news_d).ni->params, 2); DrawStringMultiCenter( ((w->width - 101) >> 1) + 98, 90, @@ -589,20 +589,20 @@ case NB_BMERGER: SetDParam(0, STR_7059_TRANSPORT_COMPANY_MERGER); SetDParam(1, STR_705A_HAS_BEEN_SOLD_TO_FOR); - COPY_IN_DPARAM(2,ni->params, 2); + CopyInDParam(2,ni->params, 2); SetDParam(4, p->index); - COPY_IN_DPARAM(5,ni->params + 2, 1); + CopyInDParam(5,ni->params + 2, 1); return STR_02B6; case NB_BBANKRUPT: SetDParam(0, STR_705C_BANKRUPT); SetDParam(1, STR_705D_HAS_BEEN_CLOSED_DOWN_BY); - COPY_IN_DPARAM(2,ni->params, 2); + CopyInDParam(2,ni->params, 2); return STR_02B6; case NB_BNEWCOMPANY: SetDParam(0, STR_705E_NEW_TRANSPORT_COMPANY_LAUNCHED); SetDParam(1, STR_705F_STARTS_CONSTRUCTION_NEAR); SetDParam(2, p->index); - COPY_IN_DPARAM(3,ni->params, 2); + CopyInDParam(3,ni->params, 2); return STR_02B6; default: NOT_REACHED();
--- a/src/engine_gui.cpp +++ b/src/engine_gui.cpp @@ -5,6 +5,7 @@ #include "stdafx.h" #include "openttd.h" #include "table/strings.h" +#include "strings.h" #include "table/sprites.h" #include "functions.h" #include "window.h"
--- a/src/graph_gui.cpp +++ b/src/graph_gui.cpp @@ -5,6 +5,7 @@ #include "stdafx.h" #include "openttd.h" #include "table/strings.h" +#include "strings.h" #include "table/sprites.h" #include "functions.h" #include "window.h"
--- a/src/industry_cmd.cpp +++ b/src/industry_cmd.cpp @@ -9,6 +9,7 @@ #include "industry_map.h" #include "station_map.h" #include "table/strings.h" +#include "strings.h" #include "table/sprites.h" #include "map.h" #include "tile.h"
--- a/src/intro_gui.cpp +++ b/src/intro_gui.cpp @@ -5,6 +5,7 @@ #include "stdafx.h" #include "openttd.h" #include "table/strings.h" +#include "strings.h" #include "table/sprites.h" #include "functions.h" #include "window.h"
--- a/src/main_gui.cpp +++ b/src/main_gui.cpp @@ -1917,7 +1917,7 @@ if (ni->display_mode == 3) { str = _get_news_string_callback[ni->callback](ni); } else { - COPY_IN_DPARAM(0, ni->params, lengthof(ni->params)); + CopyInDParam(0, ni->params, lengthof(ni->params)); str = ni->string_id; }
--- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -13,6 +13,7 @@ #include "strings.h" #include "table/sprites.h" #include "table/strings.h" +#include "strings.h" #include "table/tree_land.h" #include "map.h" #include "window.h" @@ -500,9 +501,9 @@ { switch (e->event) { case WE_PAINT: - COPY_IN_DPARAM(0, _errmsg_decode_params, lengthof(_errmsg_decode_params)); + CopyInDParam(0, _errmsg_decode_params, lengthof(_errmsg_decode_params)); DrawWindowWidgets(w); - COPY_IN_DPARAM(0, _errmsg_decode_params, lengthof(_errmsg_decode_params)); + CopyInDParam(0, _errmsg_decode_params, lengthof(_errmsg_decode_params)); if (!IsWindowOfPrototype(w, _errmsg_face_widgets)) { DrawStringMultiCenter( 120, @@ -569,7 +570,7 @@ _errmsg_message_1 = msg_1; _errmsg_message_2 = msg_2; - COPY_OUT_DPARAM(_errmsg_decode_params, 0, lengthof(_errmsg_decode_params)); + CopyOutDParam(_errmsg_decode_params, 0, lengthof(_errmsg_decode_params)); _errmsg_duration = _patches.errmsg_duration; if (!_errmsg_duration) return; @@ -1235,9 +1236,9 @@ switch (e->event) { case WE_PAINT: - COPY_IN_DPARAM(0, q->params, lengthof(q->params)); + CopyInDParam(0, q->params, lengthof(q->params)); DrawWindowWidgets(w); - COPY_IN_DPARAM(0, q->params, lengthof(q->params)); + CopyInDParam(0, q->params, lengthof(q->params)); DrawStringMultiCenter(w->width / 2, (w->height / 2) - 10, q->message, w->width - 2); break; @@ -1315,7 +1316,7 @@ /* Create a backup of the variadic arguments to strings because it will be * overridden pretty often. We will copy these back for drawing */ - COPY_OUT_DPARAM(WP(w, query_d).params, 0, lengthof(WP(w, query_d).params)); + CopyOutDParam(WP(w, query_d).params, 0, lengthof(WP(w, query_d).params)); w->widget[QUERY_WIDGET_CAPTION].data = caption; WP(w, query_d).message = message; WP(w, query_d).proc = callback;
--- a/src/music_gui.cpp +++ b/src/music_gui.cpp @@ -6,6 +6,7 @@ #include "openttd.h" #include "table/strings.h" #include "table/sprites.h" +#include "strings.h" #include "functions.h" #include "fileio.h" #include "window.h"
--- a/src/network/network_client.cpp +++ b/src/network/network_client.cpp @@ -5,6 +5,7 @@ #include "../stdafx.h" #include "../debug.h" #include "../string.h" +#include "../openttd.h" #include "../strings.h" #include "network_data.h" #include "core/tcp.h"
--- a/src/news_gui.cpp +++ b/src/news_gui.cpp @@ -124,7 +124,7 @@ DrawStringRightAligned(428, 1, STR_01FF, 0); if (!(ni->flags & NF_VIEWPORT)) { - COPY_IN_DPARAM(0, ni->params, lengthof(ni->params)); + CopyInDParam(0, ni->params, lengthof(ni->params)); DrawStringMultiCenter(215, ni->display_mode == NM_NORMAL ? 76 : 56, ni->string_id, w->width - 4); } else { @@ -141,7 +141,7 @@ (ni->flags & NF_INCOLOR ? PALETTE_TO_TRANSPARENT : PALETTE_TO_STRUCT_GREY) | (1 << USE_COLORTABLE) ); - COPY_IN_DPARAM(0, ni->params, lengthof(ni->params)); + CopyInDParam(0, ni->params, lengthof(ni->params)); DrawStringMultiCenter(w->width / 2, 20, ni->string_id, w->width - 4); } break; @@ -155,11 +155,11 @@ default: { DrawWindowWidgets(w); if (!(ni->flags & NF_VIEWPORT)) { - COPY_IN_DPARAM(0, ni->params, lengthof(ni->params)); + CopyInDParam(0, ni->params, lengthof(ni->params)); DrawStringMultiCenter(140, 38, ni->string_id, 276); } else { DrawWindowViewport(w); - COPY_IN_DPARAM(0, ni->params, lengthof(ni->params)); + CopyInDParam(0, ni->params, lengthof(ni->params)); DrawStringMultiCenter(w->width / 2, w->height - 16, ni->string_id, w->width - 4); } break; @@ -300,7 +300,7 @@ ni->data_a = data_a; ni->data_b = data_b; ni->date = _date; - COPY_OUT_DPARAM(ni->params, 0, lengthof(ni->params)); + CopyOutDParam(ni->params, 0, lengthof(ni->params)); w = FindWindowById(WC_MESSAGE_HISTORY, 0); if (w == NULL) return; @@ -611,7 +611,7 @@ if (ni->display_mode == 3) { str = _get_news_string_callback[ni->callback](ni); } else { - COPY_IN_DPARAM(0, ni->params, lengthof(ni->params)); + CopyInDParam(0, ni->params, lengthof(ni->params)); str = ni->string_id; }
--- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -9,13 +9,13 @@ #include "debug.h" #include "driver.h" #include "saveload.h" -#include "strings.h" #include "map.h" #include "tile.h" #include "void_map.h" #include "helpers.hpp" #include "openttd.h" +#include "strings.h" #include "bridge_map.h" #include "functions.h" #include "mixer.h"
--- a/src/order_gui.cpp +++ b/src/order_gui.cpp @@ -8,6 +8,7 @@ #include "station_map.h" #include "table/sprites.h" #include "table/strings.h" +#include "strings.h" #include "functions.h" #include "map.h" #include "tile.h"
--- a/src/player_gui.cpp +++ b/src/player_gui.cpp @@ -6,6 +6,7 @@ #include "openttd.h" #include "table/sprites.h" #include "table/strings.h" +#include "strings.h" #include "functions.h" #include "window.h" #include "gui.h"
--- a/src/rail_gui.cpp +++ b/src/rail_gui.cpp @@ -6,6 +6,7 @@ #include "openttd.h" #include "table/sprites.h" #include "table/strings.h" +#include "strings.h" #include "functions.h" #include "landscape.h" #include "date.h"
--- a/src/road_cmd.cpp +++ b/src/road_cmd.cpp @@ -12,6 +12,7 @@ #include "sprite.h" #include "table/sprites.h" #include "table/strings.h" +#include "strings.h" #include "functions.h" #include "window.h" #include "map.h"
--- a/src/road_gui.cpp +++ b/src/road_gui.cpp @@ -6,6 +6,7 @@ #include "openttd.h" #include "table/sprites.h" #include "table/strings.h" +#include "strings.h" #include "functions.h" #include "map.h" #include "tile.h"
--- a/src/roadveh_cmd.cpp +++ b/src/roadveh_cmd.cpp @@ -11,6 +11,7 @@ #include "roadveh.h" #include "station_map.h" #include "table/strings.h" +#include "strings.h" #include "map.h" #include "tile.h" #include "vehicle.h"
--- a/src/settings.cpp +++ b/src/settings.cpp @@ -29,6 +29,7 @@ #include "string.h" #include "variables.h" #include "network/network.h" +#include "strings.h" #include "settings.h" #include "command.h" #include "console.h"
--- a/src/ship_cmd.cpp +++ b/src/ship_cmd.cpp @@ -6,6 +6,7 @@ #include "openttd.h" #include "ship.h" #include "table/strings.h" +#include "strings.h" #include "functions.h" #include "landscape.h" #include "map.h"
--- a/src/ship_gui.cpp +++ b/src/ship_gui.cpp @@ -8,6 +8,7 @@ #include "functions.h" #include "ship.h" #include "table/strings.h" +#include "strings.h" #include "table/sprites.h" #include "gui.h" #include "vehicle.h"
--- a/src/signs.cpp +++ b/src/signs.cpp @@ -5,6 +5,7 @@ #include "stdafx.h" #include "openttd.h" #include "table/strings.h" +#include "strings.h" #include "functions.h" #include "landscape.h" #include "player.h"
--- a/src/smallmap_gui.cpp +++ b/src/smallmap_gui.cpp @@ -10,6 +10,7 @@ #include "industry_map.h" #include "station_map.h" #include "table/strings.h" +#include "strings.h" #include "table/sprites.h" #include "landscape.h" #include "map.h"
--- a/src/stdafx.h +++ b/src/stdafx.h @@ -349,4 +349,8 @@ #define _stricmp stricmp #endif /* !defined(MORHPOS) */ +#if !defined(MAX_PATH) +# define MAX_PATH 260 +#endif + #endif /* STDAFX_H */
--- a/src/strings.cpp +++ b/src/strings.cpp @@ -38,6 +38,7 @@ DynamicLanguages _dynlang; char _userstring[128]; +uint64 _decode_parameters[20]; static char *StationGetSpecialString(char *buff, int x, const char* last); static char *GetSpecialTownNameString(char *buff, int ind, uint32 seed, const char* last);
--- a/src/strings.h +++ b/src/strings.h @@ -5,13 +5,78 @@ #ifndef STRINGS_H #define STRINGS_H -char *InlineString(char *buf, uint16 string); -char *GetString(char *buffr, uint16 string, const char* last); +char *InlineString(char *buf, StringID string); +char *GetString(char *buffr, StringID string, const char* last); extern char _userstring[128]; void InjectDParam(int amount); -int32 GetParamInt32(); + +static inline void SetDParamX(uint64 *s, uint n, uint64 v) +{ + s[n] = v; +} + +static inline void SetDParam(uint n, uint64 v) +{ + extern uint64 _decode_parameters[20]; + + assert(n < lengthof(_decode_parameters)); + _decode_parameters[n] = v; +} + +/* Used to bind a C string name to a dparam number. + * NOTE: This has a short lifetime. You can't + * use this string much later or it will be gone. */ +void SetDParamStr(uint n, const char *str); + +/** This function takes a C-string and allocates a temporary string ID. + * The duration of the bound string is valid only until the next call to GetString, + * so be careful. */ +StringID BindCString(const char *str); + +static inline uint64 GetDParamX(const uint64 *s, uint n) +{ + return s[n]; +} + +static inline uint64 GetDParam(uint n) +{ + extern uint64 _decode_parameters[20]; + + assert(n < lengthof(_decode_parameters)); + return _decode_parameters[n]; +} + +static inline void CopyInDParam(int offs, const uint64 *src, int num) +{ + extern uint64 _decode_parameters[20]; + memcpy(_decode_parameters + offs, src, sizeof(uint64) * (num)); +} + +static inline void CopyOutDParam(uint64 *dst, int offs, int num) +{ + extern uint64 _decode_parameters[20]; + memcpy(dst, _decode_parameters + offs, sizeof(uint64) * (num)); +} + + +/** Information about a language */ +struct Language { + char *name; ///< The internal name of the language + char *file; ///< The name of the language as it appears on disk +}; + +/** Used for dynamic language support */ +struct DynamicLanguages { + int num; ///< Number of languages + int curr; ///< Currently selected language index + char curr_file[MAX_PATH]; ///< Currently selected language file name without path (needed for saving the filename of the loaded language). + StringID dropdown[MAX_LANG + 1]; ///< List of languages in the settings gui + Language ent[MAX_LANG]; ///< Information about the languages +}; + +extern DynamicLanguages _dynlang; // defined in strings.cpp bool ReadLanguagePack(int index); void InitializeLanguagePacks();
--- a/src/subsidy_gui.cpp +++ b/src/subsidy_gui.cpp @@ -5,6 +5,7 @@ #include "stdafx.h" #include "openttd.h" #include "table/strings.h" +#include "strings.h" #include "functions.h" #include "window.h" #include "station.h"
--- a/src/timetable_gui.cpp +++ b/src/timetable_gui.cpp @@ -7,6 +7,7 @@ #include "functions.h" #include "variables.h" #include "table/strings.h" +#include "strings.h" #include "command.h" #include "date.h" #include "engine.h"
--- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -11,6 +11,7 @@ #include "gui.h" #include "station_map.h" #include "table/strings.h" +#include "strings.h" #include "map.h" #include "tile.h" #include "tunnel_map.h"
--- a/src/train_gui.cpp +++ b/src/train_gui.cpp @@ -8,6 +8,7 @@ #include "functions.h" #include "table/sprites.h" #include "table/strings.h" +#include "strings.h" #include "window.h" #include "gui.h" #include "vehicle.h"
--- a/src/tunnelbridge_cmd.cpp +++ b/src/tunnelbridge_cmd.cpp @@ -12,6 +12,7 @@ #include "road_map.h" #include "table/sprites.h" #include "table/strings.h" +#include "strings.h" #include "functions.h" #include "map.h" #include "landscape.h"
--- a/src/variables.h +++ b/src/variables.h @@ -8,9 +8,6 @@ #include "yapf/yapf_settings.h" /* ********* START OF SAVE REGION */ -#if !defined(MAX_PATH) -# define MAX_PATH 260 -#endif #include "gfx.h" @@ -292,8 +289,6 @@ VARDEF StringID _error_message; VARDEF Money _additional_cash_required; -VARDEF uint64 _decode_parameters[20]; - VARDEF bool _rightclick_emulate; /* IN/OUT parameters to commands */ @@ -320,23 +315,6 @@ VARDEF char _ini_videodriver[32], _ini_musicdriver[32], _ini_sounddriver[32]; -/** Information about a language */ -struct Language { - char *name; ///< The internal name of the language - char *file; ///< The name of the language as it appears on disk -}; - -/** Used for dynamic language support */ -struct DynamicLanguages { - int num; ///< Number of languages - int curr; ///< Currently selected language index - char curr_file[MAX_PATH]; ///< Currently selected language file name without path (needed for saving the filename of the loaded language). - StringID dropdown[MAX_LANG + 1]; ///< List of languages in the settings gui - Language ent[MAX_LANG]; ///< Information about the languages -}; - -extern DynamicLanguages _dynlang; // defined in strings.cpp - VARDEF int _num_resolutions; VARDEF uint16 _resolutions[32][2]; VARDEF uint16 _cur_resolution[2]; @@ -348,43 +326,6 @@ VARDEF char *_log_file; -static inline void SetDParamX(uint64 *s, uint n, uint64 v) -{ - s[n] = v; -} - -static inline uint64 GetDParamX(const uint64 *s, uint n) -{ - return s[n]; -} - -static inline void SetDParam(uint n, uint64 v) -{ - assert(n < lengthof(_decode_parameters)); - _decode_parameters[n] = v; -} - -static inline uint64 GetDParam(uint n) -{ - assert(n < lengthof(_decode_parameters)); - return _decode_parameters[n]; -} - -/* Used to bind a C string name to a dparam number. - * NOTE: This has a short lifetime. You can't - * use this string much later or it will be gone. */ -void SetDParamStr(uint n, const char *str); - -/** This function takes a C-string and allocates a temporary string ID. - * The duration of the bound string is valid only until the next acll to GetString, - * so be careful. */ -StringID BindCString(const char *str); - - -#define COPY_IN_DPARAM(offs, src, num) memcpy(_decode_parameters + offs, src, sizeof(uint64) * (num)) -#define COPY_OUT_DPARAM(dst, offs, num) memcpy(dst, _decode_parameters + offs, sizeof(uint64) * (num)) - - #define SET_EXPENSES_TYPE(x) _yearly_expenses_type = x; /* landscape.cpp */