Update to 1.11.0-beta1

This commit is contained in:
dP
2021-01-23 17:31:11 +03:00
parent d3c06c25c8
commit 5e4506f493
1045 changed files with 23534 additions and 60345 deletions
+33 -82
View File
@@ -21,23 +21,13 @@
#include "textfile_gui.h"
#include "thread.h"
#include "newgrf_config.h"
#include "newgrf_text.h"
#include "fileio_func.h"
#include "fios.h"
#include "safeguards.h"
/** Create a new GRFTextWrapper. */
GRFTextWrapper::GRFTextWrapper() :
text(nullptr)
{
}
/** Cleanup a GRFTextWrapper object. */
GRFTextWrapper::~GRFTextWrapper()
{
CleanUpGRFText(this->text);
}
/**
* Create a new GRFConfig.
@@ -45,15 +35,9 @@ GRFTextWrapper::~GRFTextWrapper()
* is copied so the original string isn't needed after the constructor.
*/
GRFConfig::GRFConfig(const char *filename) :
name(new GRFTextWrapper()),
info(new GRFTextWrapper()),
url(new GRFTextWrapper()),
num_valid_params(lengthof(param))
{
if (filename != nullptr) this->filename = stredup(filename);
this->name->AddRef();
this->info->AddRef();
this->url->AddRef();
}
/**
@@ -79,9 +63,6 @@ GRFConfig::GRFConfig(const GRFConfig &config) :
MemCpyT<uint8>(this->original_md5sum, config.original_md5sum, lengthof(this->original_md5sum));
MemCpyT<uint32>(this->param, config.param, lengthof(this->param));
if (config.filename != nullptr) this->filename = stredup(config.filename);
this->name->AddRef();
this->info->AddRef();
this->url->AddRef();
if (config.error != nullptr) this->error = new GRFError(*config.error);
for (uint i = 0; i < config.param_info.size(); i++) {
if (config.param_info[i] == nullptr) {
@@ -100,9 +81,6 @@ GRFConfig::~GRFConfig()
free(this->filename);
delete this->error;
}
this->name->Release();
this->info->Release();
this->url->Release();
for (uint i = 0; i < this->param_info.size(); i++) delete this->param_info[i];
}
@@ -125,7 +103,7 @@ void GRFConfig::CopyParams(const GRFConfig &src)
*/
const char *GRFConfig::GetName() const
{
const char *name = GetGRFStringFromGRFText(this->name->text);
const char *name = GetGRFStringFromGRFText(this->name);
return StrEmpty(name) ? this->filename : name;
}
@@ -135,7 +113,7 @@ const char *GRFConfig::GetName() const
*/
const char *GRFConfig::GetDescription() const
{
return GetGRFStringFromGRFText(this->info->text);
return GetGRFStringFromGRFText(this->info);
}
/**
@@ -144,7 +122,7 @@ const char *GRFConfig::GetDescription() const
*/
const char *GRFConfig::GetURL() const
{
return GetGRFStringFromGRFText(this->url->text);
return GetGRFStringFromGRFText(this->url);
}
/** Set the default value for all parameters as specified by action14. */
@@ -201,7 +179,8 @@ uint _missing_extra_graphics = 0;
*/
GRFError::GRFError(StringID severity, StringID message) :
message(message),
severity(severity)
severity(severity),
param_value()
{
}
@@ -210,30 +189,21 @@ GRFError::GRFError(StringID severity, StringID message) :
* @param error The GRFError object to make a copy of.
*/
GRFError::GRFError(const GRFError &error) :
ZeroedMemoryAllocator(),
custom_message(error.custom_message),
data(error.data),
message(error.message),
severity(error.severity)
{
if (error.custom_message != nullptr) this->custom_message = stredup(error.custom_message);
if (error.data != nullptr) this->data = stredup(error.data);
memcpy(this->param_value, error.param_value, sizeof(this->param_value));
}
GRFError::~GRFError()
{
free(this->custom_message);
free(this->data);
}
/**
* Create a new empty GRFParameterInfo object.
* @param nr The newgrf parameter that is changed.
*/
GRFParameterInfo::GRFParameterInfo(uint nr) :
name(nullptr),
desc(nullptr),
name(),
desc(),
type(PTYPE_UINT_ENUM),
min_value(0),
max_value(UINT32_MAX),
@@ -241,6 +211,7 @@ GRFParameterInfo::GRFParameterInfo(uint nr) :
param_nr(nr),
first_bit(0),
num_bit(32),
value_names(),
complete_labels(false)
{}
@@ -250,8 +221,8 @@ GRFParameterInfo::GRFParameterInfo(uint nr) :
* @param info The GRFParameterInfo object to make a copy of.
*/
GRFParameterInfo::GRFParameterInfo(GRFParameterInfo &info) :
name(DuplicateGRFText(info.name)),
desc(DuplicateGRFText(info.desc)),
name(info.name),
desc(info.desc),
type(info.type),
min_value(info.min_value),
max_value(info.max_value),
@@ -259,23 +230,9 @@ GRFParameterInfo::GRFParameterInfo(GRFParameterInfo &info) :
param_nr(info.param_nr),
first_bit(info.first_bit),
num_bit(info.num_bit),
value_names(info.value_names),
complete_labels(info.complete_labels)
{
for (uint i = 0; i < info.value_names.size(); i++) {
SmallPair<uint32, GRFText *> *data = info.value_names.data() + i;
this->value_names.Insert(data->first, DuplicateGRFText(data->second));
}
}
/** Cleanup all parameter info. */
GRFParameterInfo::~GRFParameterInfo()
{
CleanUpGRFText(this->name);
CleanUpGRFText(this->desc);
for (uint i = 0; i < this->value_names.size(); i++) {
SmallPair<uint32, GRFText *> *data = this->value_names.data() + i;
CleanUpGRFText(data->second);
}
}
/**
@@ -303,7 +260,7 @@ void GRFParameterInfo::SetValue(struct GRFConfig *config, uint32 value)
} else {
SB(config->param[this->param_nr], this->first_bit, this->num_bit, value);
}
config->num_params = max<uint>(config->num_params, this->param_nr + 1);
config->num_params = std::max<uint>(config->num_params, this->param_nr + 1);
SetWindowDirty(WC_GAME_OPTIONS, WN_GAME_OPTIONS_NEWGRF_STATE);
}
@@ -382,7 +339,7 @@ static bool CalcGRFMD5Sum(GRFConfig *config, Subdirectory subdir)
if (f == nullptr) return false;
long start = ftell(f);
size = min(size, GRFGetSizeOfDataSection(f));
size = std::min(size, GRFGetSizeOfDataSection(f));
if (start < 0 || fseek(f, start, SEEK_SET) < 0) {
FioFCloseFile(f);
@@ -598,12 +555,8 @@ compatible_grf:
free(c->filename);
c->filename = stredup(f->filename);
memcpy(c->ident.md5sum, f->ident.md5sum, sizeof(c->ident.md5sum));
c->name->Release();
c->name = f->name;
c->name->AddRef();
c->info->Release();
c->info = f->name;
c->info->AddRef();
c->error = nullptr;
c->version = f->version;
c->min_loadable_version = f->min_loadable_version;
@@ -633,7 +586,7 @@ public:
{
}
bool AddFile(const char *filename, size_t basepath_length, const char *tar_filename) override;
bool AddFile(const std::string &filename, size_t basepath_length, const std::string &tar_filename) override;
/** Do the scan for GRFs. */
static uint DoScan()
@@ -647,9 +600,9 @@ public:
}
};
bool GRFFileScanner::AddFile(const char *filename, size_t basepath_length, const char *tar_filename)
bool GRFFileScanner::AddFile(const std::string &filename, size_t basepath_length, const std::string &tar_filename)
{
GRFConfig *c = new GRFConfig(filename + basepath_length);
GRFConfig *c = new GRFConfig(filename.c_str() + basepath_length);
bool added = true;
if (FillGRFDetails(c, false)) {
@@ -686,7 +639,7 @@ bool GRFFileScanner::AddFile(const char *filename, size_t basepath_length, const
_modal_progress_paint_mutex.lock();
const char *name = nullptr;
if (c->name != nullptr) name = GetGRFStringFromGRFText(c->name->text);
if (c->name != nullptr) name = GetGRFStringFromGRFText(c->name);
if (name == nullptr) name = c->filename;
UpdateNewGRFScanStatus(this->num_scanned, name);
@@ -820,8 +773,12 @@ const GRFConfig *FindGRFConfig(uint32 grfid, FindGRFConfigMode mode, const uint8
/** Structure for UnknownGRFs; this is a lightweight variant of GRFConfig */
struct UnknownGRF : public GRFIdentifier {
UnknownGRF *next; ///< The next unknown GRF.
GRFTextWrapper *name; ///< Name of the GRF.
GRFTextWrapper name; ///< Name of the GRF.
UnknownGRF() = default;
UnknownGRF(const UnknownGRF &other) = default;
UnknownGRF(UnknownGRF &&other) = default;
UnknownGRF(uint32 grfid, const uint8 *_md5sum) : GRFIdentifier(grfid, _md5sum), name(new GRFTextList) {}
};
/**
@@ -841,30 +798,24 @@ struct UnknownGRF : public GRFIdentifier {
* and MD5 checksum or nullptr when it does not exist and create is false.
* This value must NEVER be freed by the caller.
*/
GRFTextWrapper *FindUnknownGRFName(uint32 grfid, uint8 *md5sum, bool create)
GRFTextWrapper FindUnknownGRFName(uint32 grfid, uint8 *md5sum, bool create)
{
UnknownGRF *grf;
static UnknownGRF *unknown_grfs = nullptr;
static std::vector<UnknownGRF> unknown_grfs;
for (grf = unknown_grfs; grf != nullptr; grf = grf->next) {
if (grf->grfid == grfid) {
if (memcmp(md5sum, grf->md5sum, sizeof(grf->md5sum)) == 0) return grf->name;
for (const auto &grf : unknown_grfs) {
if (grf.grfid == grfid) {
if (memcmp(md5sum, grf.md5sum, sizeof(grf.md5sum)) == 0) return grf.name;
}
}
if (!create) return nullptr;
grf = CallocT<UnknownGRF>(1);
grf->grfid = grfid;
grf->next = unknown_grfs;
grf->name = new GRFTextWrapper();
grf->name->AddRef();
unknown_grfs.emplace_back(grfid, md5sum);
UnknownGRF &grf = unknown_grfs.back();
AddGRFTextToList(&grf->name->text, UNKNOWN_GRF_NAME_PLACEHOLDER);
memcpy(grf->md5sum, md5sum, sizeof(grf->md5sum));
AddGRFTextToList(grf.name, UNKNOWN_GRF_NAME_PLACEHOLDER);
unknown_grfs = grf;
return grf->name;
return grf.name;
}
/**