(svn r10587) -Codechange: move the string/dparam related stuff from variables.h to strings.h

pull/155/head
rubidium 17 years ago
parent 1f447d10b4
commit df009178d4

@ -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"

@ -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"

@ -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"

@ -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"

@ -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"

@ -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"

@ -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"

@ -538,7 +538,7 @@ void DrawNewsBankrupcy(Window *w)
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 @@ void DrawNewsBankrupcy(Window *w)
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 @@ void DrawNewsBankrupcy(Window *w)
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 @@ StringID GetNewsStringBankrupcy(const NewsItem *ni)
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();

@ -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"

@ -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"

@ -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"

@ -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"

@ -1917,7 +1917,7 @@ static bool DrawScrollingStatusText(const NewsItem *ni, int pos)
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;
}

@ -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 @@ static void ErrmsgWndProc(Window *w, WindowEvent *e)
{
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 @@ void ShowErrorMessage(StringID msg_1, StringID msg_2, int x, int y)
_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 @@ static void QueryWndProc(Window *w, WindowEvent *e)
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 @@ void ShowQuery(StringID caption, StringID message, Window *parent, void (*callba
/* 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;

@ -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"

@ -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"

@ -124,7 +124,7 @@ static void NewsWindowProc(Window *w, WindowEvent *e)
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 @@ static void NewsWindowProc(Window *w, WindowEvent *e)
(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 @@ static void NewsWindowProc(Window *w, WindowEvent *e)
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 @@ void AddNewsItem(StringID string, uint32 flags, uint data_a, uint data_b)
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 @@ static void DrawNewsString(int x, int y, uint16 color, const NewsItem *ni, uint
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;
}

@ -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"

@ -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"

@ -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"

@ -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"

@ -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"

@ -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"

@ -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"

@ -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"

@ -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"

@ -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"

@ -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"

@ -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"

@ -349,4 +349,8 @@ CDECL error(const char *str, ...);
#define _stricmp stricmp
#endif /* !defined(MORHPOS) */
#if !defined(MAX_PATH)
# define MAX_PATH 260
#endif
#endif /* STDAFX_H */

@ -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);

@ -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();

@ -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"

@ -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"

@ -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"

@ -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"

@ -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"

@ -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 bool _news_ticker_sound;
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 Vehicle *_place_clicked_vehicle;
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 *_highscore_file;
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 */

@ -10,6 +10,7 @@
#include "station_map.h"
#include "table/sprites.h"
#include "table/strings.h"
#include "strings.h"
#include "functions.h"
#include "landscape.h"
#include "map.h"

Loading…
Cancel
Save