Changeset - r15582:6daf5f9adce7
[Not reviewed]
master
0 3 0
rubidium - 14 years ago 2010-07-31 09:36:09
rubidium@openttd.org
(svn r20252) -Codechange: deduplicate logic for setting a suitable (initial) palette for NewGRFs
3 files changed with 16 insertions and 4 deletions:
0 comments (0 inline, 0 general)
src/newgrf_config.cpp
Show inline comments
 
@@ -82,12 +82,22 @@ const char *GRFConfig::GetName() const
 
 */
 
const char *GRFConfig::GetDescription() const
 
{
 
	return GetGRFStringFromGRFText(this->info);
 
}
 

	
 
/**
 
 * Set the palette of this GRFConfig to something suitable.
 
 * That is either the setting coming from the NewGRF or
 
 * the globally used palette.
 
 */
 
void GRFConfig::SetSuitablePalette()
 
{
 
 this->windows_paletted = (_use_palette == PAL_WINDOWS);
 
}
 

	
 
GRFConfig *_all_grfs;
 
GRFConfig *_grfconfig;
 
GRFConfig *_grfconfig_newgame;
 
GRFConfig *_grfconfig_static;
 

	
 
/**
 
@@ -130,14 +140,14 @@ GRFError::~GRFError()
 
 * graphics set governing the palette in the config after all).
 
 * As a result of this we update the settings from the config
 
 * once we have determined the palette.
 
 */
 
void UpdateNewGRFConfigPalette()
 
{
 
	for (GRFConfig *c = _grfconfig_newgame; c != NULL; c = c->next) c->windows_paletted = (_use_palette == PAL_WINDOWS);
 
	for (GRFConfig *c = _grfconfig_static;  c != NULL; c = c->next) c->windows_paletted = (_use_palette == PAL_WINDOWS);
 
	for (GRFConfig *c = _grfconfig_newgame; c != NULL; c = c->next) c->SetSuitablePalette();
 
	for (GRFConfig *c = _grfconfig_static;  c != NULL; c = c->next) c->SetSuitablePalette();
 
}
 

	
 
/** Calculate the MD5 sum for a GRF, and store it in the config.
 
 * @param config GRF to compute.
 
 * @return MD5 sum was successfully computed
 
 */
 
@@ -188,13 +198,13 @@ bool FillGRFDetails(GRFConfig *config, b
 
		LoadNewGRFFile(config, 62, GLS_SAFETYSCAN);
 

	
 
		/* GCF_UNSAFE is set if GLS_SAFETYSCAN finds unsafe actions */
 
		if (HasBit(config->flags, GCF_UNSAFE)) return false;
 
	}
 

	
 
	config->windows_paletted = (_use_palette == PAL_WINDOWS);
 
	config->SetSuitablePalette();
 

	
 
	return CalcGRFMD5Sum(config);
 
}
 

	
 

	
 
/** Clear a GRF Config list, freeing all nodes.
src/newgrf_config.h
Show inline comments
 
@@ -105,12 +105,14 @@ struct GRFConfig : ZeroedMemoryAllocator
 
	struct GRFConfig *next; ///< NOSAVE: Next item in the linked list
 

	
 
	bool IsOpenTTDBaseGRF() const;
 

	
 
	const char *GetName() const;
 
	const char *GetDescription() const;
 

	
 
	void SetSuitablePalette();
 
};
 

	
 
extern GRFConfig *_all_grfs;          ///< First item in list of all scanned NewGRFs
 
extern GRFConfig *_grfconfig;         ///< First item in list of current GRF set up
 
extern GRFConfig *_grfconfig_newgame; ///< First item in list of default GRF set up
 
extern GRFConfig *_grfconfig_static;  ///< First item in list of static GRF set up
src/saveload/newgrf_sl.cpp
Show inline comments
 
@@ -44,13 +44,13 @@ static void Save_NGRF()
 
static void Load_NGRF_common(GRFConfig *&grfconfig)
 
{
 
	ClearGRFConfigList(&grfconfig);
 
	while (SlIterateArray() != -1) {
 
		GRFConfig *c = new GRFConfig();
 
		SlObject(c, _grfconfig_desc);
 
		if (CheckSavegameVersion(101)) c->windows_paletted = (_use_palette == PAL_WINDOWS);
 
		if (CheckSavegameVersion(101)) c->SetSuitablePalette();
 
		AppendToGRFConfigList(&grfconfig, c);
 
	}
 
}
 

	
 
static void Load_NGRF()
 
{
0 comments (0 inline, 0 general)