mirror of https://github.com/OpenTTD/OpenTTD
Add: store base graphics parameters in openttd.cfg.
parent
f09fda1ff0
commit
de3f29d7b2
|
@ -96,6 +96,7 @@ struct BaseSet {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FillSetDetails(const IniFile &ini, const std::string &path, const std::string &full_filename, bool allow_empty_filename = true);
|
bool FillSetDetails(const IniFile &ini, const std::string &path, const std::string &full_filename, bool allow_empty_filename = true);
|
||||||
|
void CopyCompatibleConfig([[maybe_unused]] const T &src) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the description for the given ISO code.
|
* Get the description for the given ISO code.
|
||||||
|
@ -253,6 +254,7 @@ public:
|
||||||
bool FillSetDetails(const IniFile &ini, const std::string &path, const std::string &full_filename);
|
bool FillSetDetails(const IniFile &ini, const std::string &path, const std::string &full_filename);
|
||||||
GRFConfig *GetExtraConfig() const { return this->extra_cfg.get(); }
|
GRFConfig *GetExtraConfig() const { return this->extra_cfg.get(); }
|
||||||
GRFConfig &GetOrCreateExtraConfig() const;
|
GRFConfig &GetOrCreateExtraConfig() const;
|
||||||
|
void CopyCompatibleConfig(const GraphicsSet &src);
|
||||||
|
|
||||||
static MD5File::ChecksumResult CheckMD5(const MD5File *file, Subdirectory subdir);
|
static MD5File::ChecksumResult CheckMD5(const MD5File *file, Subdirectory subdir);
|
||||||
};
|
};
|
||||||
|
@ -264,6 +266,8 @@ public:
|
||||||
struct Ini {
|
struct Ini {
|
||||||
std::string name;
|
std::string name;
|
||||||
uint32_t shortname; ///< unique key for base set
|
uint32_t shortname; ///< unique key for base set
|
||||||
|
uint32_t extra_version; ///< version of the extra GRF
|
||||||
|
std::vector<uint32_t> extra_params; ///< parameters for the extra GRF
|
||||||
};
|
};
|
||||||
static inline Ini ini_data;
|
static inline Ini ini_data;
|
||||||
|
|
||||||
|
|
|
@ -198,6 +198,9 @@ bool BaseMedia<Tbase_set>::AddFile(const std::string &filename, size_t basepath_
|
||||||
*prev = set;
|
*prev = set;
|
||||||
set->next = duplicate->next;
|
set->next = duplicate->next;
|
||||||
|
|
||||||
|
/* Keep baseset configuration, if compatible */
|
||||||
|
set->CopyCompatibleConfig(*duplicate);
|
||||||
|
|
||||||
/* If the duplicate set is currently used (due to rescanning this can happen)
|
/* If the duplicate set is currently used (due to rescanning this can happen)
|
||||||
* update the currently used set to the new one. This will 'lie' about the
|
* update the currently used set to the new one. This will 'lie' about the
|
||||||
* version number until a new game is started which isn't a big problem */
|
* version number until a new game is started which isn't a big problem */
|
||||||
|
|
|
@ -193,6 +193,7 @@ static void LoadSpriteTables()
|
||||||
|
|
||||||
/* Baseset extra graphics */
|
/* Baseset extra graphics */
|
||||||
GRFConfig *extra = new GRFConfig(used_set->GetOrCreateExtraConfig());
|
GRFConfig *extra = new GRFConfig(used_set->GetOrCreateExtraConfig());
|
||||||
|
if (extra->num_params == 0) extra->SetParameterDefaults();
|
||||||
ClrBit(extra->flags, GCF_INIT_ONLY);
|
ClrBit(extra->flags, GCF_INIT_ONLY);
|
||||||
|
|
||||||
extra->next = top;
|
extra->next = top;
|
||||||
|
@ -388,6 +389,15 @@ GRFConfig &GraphicsSet::GetOrCreateExtraConfig() const
|
||||||
return *this->extra_cfg;
|
return *this->extra_cfg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GraphicsSet::CopyCompatibleConfig(const GraphicsSet &src)
|
||||||
|
{
|
||||||
|
const GRFConfig *src_cfg = src.GetExtraConfig();
|
||||||
|
if (src_cfg == nullptr || src_cfg->num_params == 0) return;
|
||||||
|
GRFConfig &dest_cfg = this->GetOrCreateExtraConfig();
|
||||||
|
if (dest_cfg.IsCompatible(src_cfg->version)) return;
|
||||||
|
dest_cfg.CopyParams(*src_cfg);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculate and check the MD5 hash of the supplied GRF.
|
* Calculate and check the MD5 hash of the supplied GRF.
|
||||||
* @param file The file get the hash of.
|
* @param file The file get the hash of.
|
||||||
|
|
|
@ -66,6 +66,12 @@ GRFConfig::GRFConfig(const GRFConfig &config) :
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GRFConfig::SetParams(const std::vector<uint32_t> &pars)
|
||||||
|
{
|
||||||
|
this->num_params = static_cast<uint8_t>(std::min(this->param.size(), pars.size()));
|
||||||
|
std::copy(pars.begin(), pars.begin() + this->num_params, this->param.begin());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return whether this NewGRF can replace an older version of the same NewGRF.
|
* Return whether this NewGRF can replace an older version of the same NewGRF.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -174,6 +174,7 @@ struct GRFConfig : ZeroedMemoryAllocator {
|
||||||
struct GRFConfig *next; ///< NOSAVE: Next item in the linked list
|
struct GRFConfig *next; ///< NOSAVE: Next item in the linked list
|
||||||
|
|
||||||
bool IsCompatible(uint32_t old_version) const;
|
bool IsCompatible(uint32_t old_version) const;
|
||||||
|
void SetParams(const std::vector<uint32_t> &pars);
|
||||||
void CopyParams(const GRFConfig &src);
|
void CopyParams(const GRFConfig &src);
|
||||||
|
|
||||||
std::optional<std::string> GetTextfile(TextfileType type) const;
|
std::optional<std::string> GetTextfile(TextfileType type) const;
|
||||||
|
|
|
@ -706,6 +706,12 @@ int openttd_main(int argc, char *argv[])
|
||||||
} else if (BaseGraphics::ini_data.shortname != 0) {
|
} else if (BaseGraphics::ini_data.shortname != 0) {
|
||||||
graphics_set = BaseGraphics::ini_data.name;
|
graphics_set = BaseGraphics::ini_data.name;
|
||||||
valid_graphics_set = BaseGraphics::SetSetByShortname(BaseGraphics::ini_data.shortname);
|
valid_graphics_set = BaseGraphics::SetSetByShortname(BaseGraphics::ini_data.shortname);
|
||||||
|
if (valid_graphics_set && !BaseGraphics::ini_data.extra_params.empty()) {
|
||||||
|
GRFConfig &extra_cfg = BaseGraphics::GetUsedSet()->GetOrCreateExtraConfig();
|
||||||
|
if (extra_cfg.IsCompatible(BaseGraphics::ini_data.extra_version)) {
|
||||||
|
extra_cfg.SetParams(BaseGraphics::ini_data.extra_params);
|
||||||
|
}
|
||||||
|
}
|
||||||
} else if (!BaseGraphics::ini_data.name.empty()) {
|
} else if (!BaseGraphics::ini_data.name.empty()) {
|
||||||
graphics_set = BaseGraphics::ini_data.name;
|
graphics_set = BaseGraphics::ini_data.name;
|
||||||
valid_graphics_set = BaseGraphics::SetSetByName(BaseGraphics::ini_data.name);
|
valid_graphics_set = BaseGraphics::SetSetByName(BaseGraphics::ini_data.name);
|
||||||
|
|
|
@ -999,6 +999,20 @@ static void GraphicsSetLoadConfig(IniFile &ini)
|
||||||
if (const IniItem *item = group->GetItem("shortname"); item != nullptr && item->value && item->value->size() == 8) {
|
if (const IniItem *item = group->GetItem("shortname"); item != nullptr && item->value && item->value->size() == 8) {
|
||||||
BaseGraphics::ini_data.shortname = BSWAP32(std::strtoul(item->value->c_str(), nullptr, 16));
|
BaseGraphics::ini_data.shortname = BSWAP32(std::strtoul(item->value->c_str(), nullptr, 16));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (const IniItem *item = group->GetItem("extra_version"); item != nullptr && item->value) BaseGraphics::ini_data.extra_version = std::strtoul(item->value->c_str(), nullptr, 10);
|
||||||
|
|
||||||
|
if (const IniItem *item = group->GetItem("extra_params"); item != nullptr && item->value) {
|
||||||
|
auto &extra_params = BaseGraphics::ini_data.extra_params;
|
||||||
|
extra_params.resize(lengthof(GRFConfig::param));
|
||||||
|
int count = ParseIntList(item->value->c_str(), &extra_params.front(), extra_params.size());
|
||||||
|
if (count < 0) {
|
||||||
|
SetDParamStr(0, BaseGraphics::ini_data.name);
|
||||||
|
ShowErrorMessage(STR_CONFIG_ERROR, STR_CONFIG_ERROR_ARRAY, WL_CRITICAL);
|
||||||
|
count = 0;
|
||||||
|
}
|
||||||
|
extra_params.resize(count);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1187,6 +1201,12 @@ static void GraphicsSetSaveConfig(IniFile &ini)
|
||||||
|
|
||||||
group.GetOrCreateItem("name").SetValue(used_set->name);
|
group.GetOrCreateItem("name").SetValue(used_set->name);
|
||||||
group.GetOrCreateItem("shortname").SetValue(fmt::format("{:08X}", BSWAP32(used_set->shortname)));
|
group.GetOrCreateItem("shortname").SetValue(fmt::format("{:08X}", BSWAP32(used_set->shortname)));
|
||||||
|
|
||||||
|
const GRFConfig *extra_cfg = used_set->GetExtraConfig();
|
||||||
|
if (extra_cfg != nullptr && extra_cfg->num_params > 0) {
|
||||||
|
group.GetOrCreateItem("extra_version").SetValue(fmt::format("{}", extra_cfg->version));
|
||||||
|
group.GetOrCreateItem("extra_params").SetValue(GRFBuildParamList(extra_cfg));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Save a GRF configuration to the given group name */
|
/* Save a GRF configuration to the given group name */
|
||||||
|
|
Loading…
Reference in New Issue