summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2010-07-31 09:40:43 +0000
committerrubidium <rubidium@openttd.org>2010-07-31 09:40:43 +0000
commite469a94a2df943c5595e91b2752782cfa4b2ff3f (patch)
treefac840c8181287080cea264e90915aa361596f88
parentf7794e313f993bbb8394bfc6c27f6cd00fc534a0 (diff)
downloadopenttd-e469a94a2df943c5595e91b2752782cfa4b2ff3f.tar.xz
(svn r20253) -Codechange: change GRFConfig::windows_paletted into a bitmask/bitset
-rw-r--r--src/gfxinit.cpp2
-rw-r--r--src/newgrf.cpp6
-rw-r--r--src/newgrf_config.cpp5
-rw-r--r--src/newgrf_config.h26
-rw-r--r--src/newgrf_gui.cpp4
-rw-r--r--src/saveload/newgrf_sl.cpp2
6 files changed, 28 insertions, 17 deletions
diff --git a/src/gfxinit.cpp b/src/gfxinit.cpp
index 42043299f..1bb99f38a 100644
--- a/src/gfxinit.cpp
+++ b/src/gfxinit.cpp
@@ -180,7 +180,7 @@ static void LoadSpriteTables()
GRFConfig *top = _grfconfig;
GRFConfig *master = new GRFConfig(used_set->files[GFT_EXTRA].filename);
FillGRFDetails(master, false);
- master->windows_paletted = (used_set->palette == PAL_WINDOWS);
+ master->palette = (used_set->palette == PAL_WINDOWS) ? GRFP_USE_WINDOWS : GRFP_USE_DOS;
ClrBit(master->flags, GCF_INIT_ONLY);
master->next = top;
_grfconfig = master;
diff --git a/src/newgrf.cpp b/src/newgrf.cpp
index 5b967d5ea..3a2001b71 100644
--- a/src/newgrf.cpp
+++ b/src/newgrf.cpp
@@ -4415,7 +4415,7 @@ bool GetGlobalVariable(byte param, uint32 *value)
}
case 0x0D: // TTD Version, 00=DOS, 01=Windows
- *value = _cur_grfconfig->windows_paletted;
+ *value = _cur_grfconfig->palette & GRFP_USE_MASK;
return true;
case 0x0E: // Y-offset for train sprites
@@ -4869,7 +4869,7 @@ static void GRFInfo(ByteReader *buf)
_cur_grfconfig->status = _cur_stage < GLS_RESERVE ? GCS_INITIALISED : GCS_ACTIVATED;
/* Do swap the GRFID for displaying purposes since people expect that */
- DEBUG(grf, 1, "GRFInfo: Loaded GRFv%d set %08X - %s (palette: %s)", version, BSWAP32(grfid), name, _cur_grfconfig->windows_paletted ? "Windows" : "DOS");
+ DEBUG(grf, 1, "GRFInfo: Loaded GRFv%d set %08X - %s (palette: %s)", version, BSWAP32(grfid), name, (_cur_grfconfig->palette & GRFP_USE_MASK) ? "Windows" : "DOS");
}
/* Action 0x0A */
@@ -6974,7 +6974,7 @@ void LoadNewGRFFile(GRFConfig *config, uint file_index, GrfLoadingStage stage)
FioOpenFile(file_index, filename);
_file_index = file_index; // XXX
- _palette_remap_grf[_file_index] = (config->windows_paletted != (_use_palette == PAL_WINDOWS));
+ _palette_remap_grf[_file_index] = ((config->palette & GRFP_USE_MASK) != (_use_palette == PAL_WINDOWS));
_cur_grfconfig = config;
diff --git a/src/newgrf_config.cpp b/src/newgrf_config.cpp
index 9ce1962ce..c7a4f01b0 100644
--- a/src/newgrf_config.cpp
+++ b/src/newgrf_config.cpp
@@ -43,7 +43,7 @@ GRFConfig::GRFConfig(const GRFConfig &config) :
grf_bugs(config.grf_bugs),
num_params(config.num_params),
num_valid_params(config.num_valid_params),
- windows_paletted(config.windows_paletted)
+ palette(config.palette)
{
MemCpyT<uint8>(this->original_md5sum, config.original_md5sum, lengthof(this->original_md5sum));
MemCpyT<uint32>(this->param, config.param, lengthof(this->param));
@@ -92,7 +92,8 @@ const char *GRFConfig::GetDescription() const
*/
void GRFConfig::SetSuitablePalette()
{
- this->windows_paletted = (_use_palette == PAL_WINDOWS);
+ PaletteType pal = _use_palette;
+ SB(this->palette, GRFP_USE_BIT, 1, pal == PAL_WINDOWS ? GRFP_USE_WINDOWS : GRFP_USE_DOS);
}
GRFConfig *_all_grfs;
diff --git a/src/newgrf_config.h b/src/newgrf_config.h
index 3c851a139..c9d2079a0 100644
--- a/src/newgrf_config.h
+++ b/src/newgrf_config.h
@@ -49,6 +49,16 @@ enum GRFListCompatibility {
GLC_NOT_FOUND ///< At least one GRF couldn't be found (higher priority than GLC_COMPATIBLE)
};
+/** Information that can/has to be stored about a GRF's palette. */
+enum GRFPalette {
+ GRFP_USE_BIT = 0, ///< The bit used for storing the palette to use.
+
+ GRFP_USE_DOS = 0x0, ///< The palette state is set to use the DOS palette.
+ GRFP_USE_WINDOWS = 0x1, ///< The palette state is set to use the Windows palette.
+ GRFP_USE_MASK = 0x1, ///< Bitmask to get only the use palette use states.
+};
+
+
/** Basic data to distinguish a GRF. Used in the server list window */
struct GRFIdentifier {
uint32 grfid; ///< GRF ID (defined by Action 0x08)
@@ -94,15 +104,15 @@ struct GRFConfig : ZeroedMemoryAllocator {
struct GRFText *info; ///< NOSAVE: GRF info (author, copyright, ...) (Action 0x08)
GRFError *error; ///< NOSAVE: Error/Warning during GRF loading (Action 0x0B)
- uint8 flags; ///< NOSAVE: GCF_Flags, bitset
- GRFStatus status; ///< NOSAVE: GRFStatus, enum
- uint32 grf_bugs; ///< NOSAVE: bugs in this GRF in this run, @see enum GRFBugs
- uint32 param[0x80]; ///< GRF parameters
- uint8 num_params; ///< Number of used parameters
- uint8 num_valid_params; ///< Number of valid parameters (action 0x14)
- bool windows_paletted; ///< Whether the NewGRF is Windows paletted or not
+ uint8 flags; ///< NOSAVE: GCF_Flags, bitset
+ GRFStatus status; ///< NOSAVE: GRFStatus, enum
+ uint32 grf_bugs; ///< NOSAVE: bugs in this GRF in this run, @see enum GRFBugs
+ uint32 param[0x80]; ///< GRF parameters
+ uint8 num_params; ///< Number of used parameters
+ uint8 num_valid_params; ///< NOSAVE: Number of valid parameters (action 0x14)
+ uint8 palette; ///< GRFPalette, bitset
- struct GRFConfig *next; ///< NOSAVE: Next item in the linked list
+ struct GRFConfig *next; ///< NOSAVE: Next item in the linked list
bool IsOpenTTDBaseGRF() const;
diff --git a/src/newgrf_gui.cpp b/src/newgrf_gui.cpp
index 77bcedb63..dec6ca9d8 100644
--- a/src/newgrf_gui.cpp
+++ b/src/newgrf_gui.cpp
@@ -96,7 +96,7 @@ static void ShowNewGRFInfo(const GRFConfig *c, uint x, uint y, uint right, uint
y = DrawStringMultiLine(x, right, y, bottom, STR_NEWGRF_SETTINGS_PARAMETER);
/* Draw the palette of the NewGRF */
- SetDParamStr(0, c->windows_paletted ? "Windows" : "DOS");
+ SetDParamStr(0, (c->palette & GRFP_USE_WINDOWS) ? "Windows" : "DOS");
y = DrawStringMultiLine(x, right, y, bottom, STR_NEWGRF_SETTINGS_PALETTE);
}
@@ -592,7 +592,7 @@ struct NewGRFWindow : public QueryStringBaseWindow {
case SNGRFS_TOGGLE_PALETTE:
if (this->active_sel != NULL || !this->editable) {
- this->active_sel->windows_paletted ^= true;
+ this->active_sel->palette ^= GRFP_USE_MASK;
this->SetDirty();
}
break;
diff --git a/src/saveload/newgrf_sl.cpp b/src/saveload/newgrf_sl.cpp
index f132bc03f..c66d7739b 100644
--- a/src/saveload/newgrf_sl.cpp
+++ b/src/saveload/newgrf_sl.cpp
@@ -24,7 +24,7 @@ static const SaveLoad _grfconfig_desc[] = {
SLE_ARR(GRFConfig, ident.md5sum, SLE_UINT8, 16),
SLE_ARR(GRFConfig, param, SLE_UINT32, 0x80),
SLE_VAR(GRFConfig, num_params, SLE_UINT8),
- SLE_CONDVAR(GRFConfig, windows_paletted, SLE_BOOL, 101, SL_MAX_VERSION),
+ SLE_CONDVAR(GRFConfig, palette, SLE_UINT8, 101, SL_MAX_VERSION),
SLE_END()
};