(svn r19255) -Codechange: encapsulate GRFIdentifier in GRFConfig instead of subclassing it
This commit is contained in:
@@ -69,7 +69,7 @@ static bool CalcGRFMD5Sum(GRFConfig *config)
|
||||
size -= len;
|
||||
checksum.Append(buffer, len);
|
||||
}
|
||||
checksum.Finish(config->md5sum);
|
||||
checksum.Finish(config->ident.md5sum);
|
||||
|
||||
FioFCloseFile(f);
|
||||
|
||||
@@ -89,7 +89,7 @@ bool FillGRFDetails(GRFConfig *config, bool is_static)
|
||||
LoadNewGRFFile(config, CONFIG_SLOT, GLS_FILESCAN);
|
||||
|
||||
/* Skip if the grfid is 0 (not read) or 0xFFFFFFFF (ttdp system grf) */
|
||||
if (config->grfid == 0 || config->grfid == 0xFFFFFFFF || config->IsOpenTTDBaseGRF()) return false;
|
||||
if (config->ident.grfid == 0 || config->ident.grfid == 0xFFFFFFFF || config->IsOpenTTDBaseGRF()) return false;
|
||||
|
||||
if (is_static) {
|
||||
/* Perform a 'safety scan' for static GRFs */
|
||||
@@ -200,7 +200,7 @@ static void RemoveDuplicatesFromGRFConfigList(GRFConfig *list)
|
||||
if (list == NULL) return;
|
||||
|
||||
for (prev = list, cur = list->next; cur != NULL; prev = cur, cur = cur->next) {
|
||||
if (cur->grfid != list->grfid) continue;
|
||||
if (cur->ident.grfid != list->ident.grfid) continue;
|
||||
|
||||
prev->next = cur->next;
|
||||
ClearGRFConfig(&cur);
|
||||
@@ -257,35 +257,35 @@ GRFListCompatibility IsGoodGRFConfigList()
|
||||
GRFListCompatibility res = GLC_ALL_GOOD;
|
||||
|
||||
for (GRFConfig *c = _grfconfig; c != NULL; c = c->next) {
|
||||
const GRFConfig *f = FindGRFConfig(c->grfid, c->md5sum);
|
||||
const GRFConfig *f = FindGRFConfig(c->ident.grfid, c->ident.md5sum);
|
||||
if (f == NULL) {
|
||||
char buf[256];
|
||||
|
||||
/* If we have not found the exactly matching GRF try to find one with the
|
||||
* same grfid, as it most likely is compatible */
|
||||
f = FindGRFConfig(c->grfid);
|
||||
f = FindGRFConfig(c->ident.grfid);
|
||||
if (f != NULL) {
|
||||
md5sumToString(buf, lastof(buf), c->md5sum);
|
||||
DEBUG(grf, 1, "NewGRF %08X (%s) not found; checksum %s. Compatibility mode on", BSWAP32(c->grfid), c->filename, buf);
|
||||
md5sumToString(buf, lastof(buf), c->ident.md5sum);
|
||||
DEBUG(grf, 1, "NewGRF %08X (%s) not found; checksum %s. Compatibility mode on", BSWAP32(c->ident.grfid), c->filename, buf);
|
||||
SetBit(c->flags, GCF_COMPATIBLE);
|
||||
|
||||
/* Non-found has precedence over compatibility load */
|
||||
if (res != GLC_NOT_FOUND) res = GLC_COMPATIBLE;
|
||||
GamelogGRFCompatible(f);
|
||||
GamelogGRFCompatible(&f->ident);
|
||||
goto compatible_grf;
|
||||
}
|
||||
|
||||
/* No compatible grf was found, mark it as disabled */
|
||||
md5sumToString(buf, lastof(buf), c->md5sum);
|
||||
DEBUG(grf, 0, "NewGRF %08X (%s) not found; checksum %s", BSWAP32(c->grfid), c->filename, buf);
|
||||
md5sumToString(buf, lastof(buf), c->ident.md5sum);
|
||||
DEBUG(grf, 0, "NewGRF %08X (%s) not found; checksum %s", BSWAP32(c->ident.grfid), c->filename, buf);
|
||||
|
||||
GamelogGRFRemove(c->grfid);
|
||||
GamelogGRFRemove(c->ident.grfid);
|
||||
|
||||
c->status = GCS_NOT_FOUND;
|
||||
res = GLC_NOT_FOUND;
|
||||
} else {
|
||||
compatible_grf:
|
||||
DEBUG(grf, 1, "Loading GRF %08X from %s", BSWAP32(f->grfid), f->filename);
|
||||
DEBUG(grf, 1, "Loading GRF %08X from %s", BSWAP32(f->ident.grfid), f->filename);
|
||||
/* The filename could be the filename as in the savegame. As we need
|
||||
* to load the GRF here, we need the correct filename, so overwrite that
|
||||
* in any case and set the name and info when it is not set already.
|
||||
@@ -294,7 +294,7 @@ compatible_grf:
|
||||
if (!HasBit(c->flags, GCF_COPY)) {
|
||||
free(c->filename);
|
||||
c->filename = strdup(f->filename);
|
||||
memcpy(c->md5sum, f->md5sum, sizeof(c->md5sum));
|
||||
memcpy(c->ident.md5sum, f->ident.md5sum, sizeof(c->ident.md5sum));
|
||||
if (c->name == NULL && f->name != NULL) c->name = strdup(f->name);
|
||||
if (c->info == NULL && f->info != NULL) c->info = strdup(f->info);
|
||||
c->error = NULL;
|
||||
@@ -333,7 +333,7 @@ bool GRFFileScanner::AddFile(const char *filename, size_t basepath_length)
|
||||
GRFConfig **pd, *d;
|
||||
bool stop = false;
|
||||
for (pd = &_all_grfs; (d = *pd) != NULL; pd = &d->next) {
|
||||
if (c->grfid == d->grfid && memcmp(c->md5sum, d->md5sum, sizeof(c->md5sum)) == 0) added = false;
|
||||
if (c->ident.grfid == d->ident.grfid && memcmp(c->ident.md5sum, d->ident.md5sum, sizeof(c->ident.md5sum)) == 0) added = false;
|
||||
/* Because there can be multiple grfs with the same name, make sure we checked all grfs with the same name,
|
||||
* before inserting the entry. So insert a new grf at the end of all grfs with the same name, instead of
|
||||
* just after the first with the same name. Avoids doubles in the list. */
|
||||
@@ -419,10 +419,10 @@ void ScanNewGRFFiles()
|
||||
const GRFConfig *FindGRFConfig(uint32 grfid, const uint8 *md5sum)
|
||||
{
|
||||
for (const GRFConfig *c = _all_grfs; c != NULL; c = c->next) {
|
||||
if (c->grfid == grfid) {
|
||||
if (c->ident.grfid == grfid) {
|
||||
if (md5sum == NULL) return c;
|
||||
|
||||
if (memcmp(md5sum, c->md5sum, sizeof(c->md5sum)) == 0) return c;
|
||||
if (memcmp(md5sum, c->ident.md5sum, sizeof(c->ident.md5sum)) == 0) return c;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -486,7 +486,7 @@ GRFConfig *GetGRFConfig(uint32 grfid, uint32 mask)
|
||||
GRFConfig *c;
|
||||
|
||||
for (c = _grfconfig; c != NULL; c = c->next) {
|
||||
if ((c->grfid & mask) == (grfid & mask)) return c;
|
||||
if ((c->ident.grfid & mask) == (grfid & mask)) return c;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
@@ -517,5 +517,5 @@ static const uint32 OPENTTD_GRAPHICS_BASE_GRF_ID = BSWAP32(0xFF4F5400);
|
||||
*/
|
||||
bool GRFConfig::IsOpenTTDBaseGRF() const
|
||||
{
|
||||
return (this->grfid & 0x00FFFFFF) == OPENTTD_GRAPHICS_BASE_GRF_ID;
|
||||
return (this->ident.grfid & 0x00FFFFFF) == OPENTTD_GRAPHICS_BASE_GRF_ID;
|
||||
}
|
||||
|
Reference in New Issue
Block a user