Changeset - r28058:09cc94fbd2eb
[Not reviewed]
master
0 2 0
frosch - 14 months ago 2023-10-02 12:28:16
frosch@openttd.org
Codechange: store the GRFConfig of the base graphics, once loaded.
2 files changed with 45 insertions and 12 deletions:
0 comments (0 inline, 0 general)
src/base_media_base.h
Show inline comments
 
@@ -237,12 +237,22 @@ enum BlitterType {
 
	BLT_32BPP,      ///< Base set has both 8 bpp and 32 bpp sprites.
 
};
 

	
 
struct GRFConfig;
 

	
 
/** All data of a graphics set. */
 
struct GraphicsSet : BaseSet<GraphicsSet, MAX_GFT, true> {
 
private:
 
	mutable std::unique_ptr<GRFConfig> extra_cfg; ///< Parameters for extra GRF
 
public:
 
	PaletteType palette;       ///< Palette of this graphics set
 
	BlitterType blitter;       ///< Blitter of this graphics set
 

	
 
	GraphicsSet();
 
	~GraphicsSet();
 

	
 
	bool FillSetDetails(const IniFile &ini, const std::string &path, const std::string &full_filename);
 
	GRFConfig *GetExtraConfig() const { return this->extra_cfg.get(); }
 
	GRFConfig &GetOrCreateExtraConfig() const;
 

	
 
	static MD5File::ChecksumResult CheckMD5(const MD5File *file, Subdirectory subdir);
 
};
src/gfxinit.cpp
Show inline comments
 
@@ -192,18 +192,7 @@ static void LoadSpriteTables()
 
	ClrBit(master->flags, GCF_INIT_ONLY);
 

	
 
	/* Baseset extra graphics */
 
	GRFConfig *extra = new GRFConfig(used_set->files[GFT_EXTRA].filename.c_str());
 

	
 
	/* We know the palette of the base set, so if the base NewGRF is not
 
	 * setting one, use the palette of the base set and not the global
 
	 * one which might be the wrong palette for this base NewGRF.
 
	 * The value set here might be overridden via action14 later. */
 
	switch (used_set->palette) {
 
		case PAL_DOS:     extra->palette |= GRFP_GRF_DOS;     break;
 
		case PAL_WINDOWS: extra->palette |= GRFP_GRF_WINDOWS; break;
 
		default: break;
 
	}
 
	FillGRFDetails(extra, false, BASESET_DIR);
 
	GRFConfig *extra = new GRFConfig(used_set->GetOrCreateExtraConfig());
 
	ClrBit(extra->flags, GCF_INIT_ONLY);
 

	
 
	extra->next = top;
 
@@ -347,6 +336,17 @@ void GfxLoadSprites()
 
	UpdateCursorSize();
 
}
 

	
 
GraphicsSet::GraphicsSet()
 
	: BaseSet<GraphicsSet, MAX_GFT, true>{}, palette{}, blitter{}
 
{
 
	// instantiate here, because unique_ptr needs a complete type
 
}
 

	
 
GraphicsSet::~GraphicsSet()
 
{
 
	// instantiate here, because unique_ptr needs a complete type
 
}
 

	
 
bool GraphicsSet::FillSetDetails(const IniFile &ini, const std::string &path, const std::string &full_filename)
 
{
 
	bool ret = this->BaseSet<GraphicsSet, MAX_GFT, true>::FillSetDetails(ini, path, full_filename, false);
 
@@ -366,6 +366,29 @@ bool GraphicsSet::FillSetDetails(const I
 
}
 

	
 
/**
 
 * Return configuration for the extra GRF, or lazily create it.
 
 * @return NewGRF configuration
 
 */
 
GRFConfig &GraphicsSet::GetOrCreateExtraConfig() const
 
{
 
	if (!this->extra_cfg) {
 
		this->extra_cfg.reset(new GRFConfig(this->files[GFT_EXTRA].filename));
 

	
 
		/* We know the palette of the base set, so if the base NewGRF is not
 
		 * setting one, use the palette of the base set and not the global
 
		 * one which might be the wrong palette for this base NewGRF.
 
		 * The value set here might be overridden via action14 later. */
 
		switch (this->palette) {
 
			case PAL_DOS:     this->extra_cfg->palette |= GRFP_GRF_DOS;     break;
 
			case PAL_WINDOWS: this->extra_cfg->palette |= GRFP_GRF_WINDOWS; break;
 
			default: break;
 
		}
 
		FillGRFDetails(this->extra_cfg.get(), false, BASESET_DIR);
 
	}
 
	return *this->extra_cfg;
 
}
 

	
 
/**
 
 * Calculate and check the MD5 hash of the supplied GRF.
 
 * @param file The file get the hash of.
 
 * @param subdir The sub directory to get the files from.
0 comments (0 inline, 0 general)