Codechange: store the GRFConfig of the base graphics, once loaded.

pull/615/head
frosch 8 months ago committed by frosch
parent 0b7ecf6102
commit f09fda1ff0

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

@ -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);
@ -365,6 +365,29 @@ bool GraphicsSet::FillSetDetails(const IniFile &ini, const std::string &path, co
return ret;
}
/**
* 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.

Loading…
Cancel
Save