Merge branch 'master' into jgrpp

# Conflicts:
#	projects/openttd_vs140.vcxproj.filters
#	projects/openttd_vs141.vcxproj.filters
#	projects/openttd_vs142.vcxproj.filters
#	src/base_consist.h
#	src/company_base.h
#	src/newgrf_config.cpp
#	src/newgrf_config.h
#	src/openttd.cpp
#	src/saveload/saveload.cpp
#	src/saveload/saveload.h
#	src/saveload/station_sl.cpp
#	src/settings.cpp
#	src/signs_base.h
#	src/string.cpp
#	src/string_func.h
#	src/table/misc_settings.ini
#	src/table/settings.h.preamble
#	src/town_cmd.cpp
#	src/vehicle.cpp
#	src/vehicle_cmd.cpp
#	src/video/cocoa/cocoa_v.mm
#	src/video/null_v.cpp
This commit is contained in:
Jonathan G Rennison
2020-05-21 20:19:57 +01:00
162 changed files with 2519 additions and 1448 deletions

View File

@@ -21,6 +21,7 @@
#include "textfile_gui.h"
#include "thread.h"
#include "newgrf_config.h"
#include "newgrf_text.h"
#include "fileio_func.h"
#include "fios.h"
@@ -35,17 +36,6 @@
#include "safeguards.h"
/** Create a new GRFTextWrapper. */
GRFTextWrapper::GRFTextWrapper() :
text(nullptr)
{
}
/** Cleanup a GRFTextWrapper object. */
GRFTextWrapper::~GRFTextWrapper()
{
CleanUpGRFText(this->text);
}
/**
* Create a new GRFConfig.
@@ -53,15 +43,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();
}
/**
@@ -87,9 +71,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) {
@@ -109,9 +90,6 @@ GRFConfig::~GRFConfig()
delete this->error;
}
free(this->full_filename);
this->name->Release();
this->info->Release();
this->url->Release();
for (uint i = 0; i < this->param_info.size(); i++) delete this->param_info[i];
}
@@ -134,7 +112,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;
}
@@ -144,7 +122,7 @@ const char *GRFConfig::GetName() const
*/
const char *GRFConfig::GetDescription() const
{
return GetGRFStringFromGRFText(this->info->text);
return GetGRFStringFromGRFText(this->info);
}
/**
@@ -153,7 +131,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. */
@@ -212,7 +190,8 @@ bool _grf_bug_too_many_strings = false;
*/
GRFError::GRFError(StringID severity, StringID message) :
message(message),
severity(severity)
severity(severity),
param_value()
{
}
@@ -221,30 +200,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),
@@ -252,6 +222,7 @@ GRFParameterInfo::GRFParameterInfo(uint nr) :
param_nr(nr),
first_bit(0),
num_bit(32),
value_names(),
complete_labels(false)
{}
@@ -261,8 +232,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),
@@ -270,23 +241,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);
}
}
/**
@@ -689,12 +646,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;
@@ -798,7 +751,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);
@@ -932,8 +885,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) {}
};
/**
@@ -953,30 +910,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;
}
/**