mirror of https://github.com/OpenTTD/OpenTTD
(svn r20957) -Codechange: Add another parameter to FindGRFConfig() to define search restrictions.
parent
918da8432a
commit
3972c790c2
|
@ -126,7 +126,7 @@ static void PrintGrfInfo(char *buf, uint grfid, const uint8 *md5sum, const GRFCo
|
||||||
if (gc != NULL) {
|
if (gc != NULL) {
|
||||||
AddDebugText(buf, ", filename: %s (md5sum matches)", gc->filename);
|
AddDebugText(buf, ", filename: %s (md5sum matches)", gc->filename);
|
||||||
} else {
|
} else {
|
||||||
gc = FindGRFConfig(grfid);
|
gc = FindGRFConfig(grfid, FGCM_ANY);
|
||||||
if (gc != NULL) {
|
if (gc != NULL) {
|
||||||
AddDebugText(buf, ", filename: %s (matches GRFID only)", gc->filename);
|
AddDebugText(buf, ", filename: %s (matches GRFID only)", gc->filename);
|
||||||
} else {
|
} else {
|
||||||
|
@ -245,7 +245,7 @@ void GamelogPrint(GamelogPrintProc *proc)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GLCT_GRFADD: {
|
case GLCT_GRFADD: {
|
||||||
const GRFConfig *gc = FindGRFConfig(lc->grfadd.grfid, lc->grfadd.md5sum);
|
const GRFConfig *gc = FindGRFConfig(lc->grfadd.grfid, FGCM_EXACT, lc->grfadd.md5sum);
|
||||||
AddDebugText(buf, "Added NewGRF: ");
|
AddDebugText(buf, "Added NewGRF: ");
|
||||||
PrintGrfInfo(buf, lc->grfadd.grfid, lc->grfadd.md5sum, gc);
|
PrintGrfInfo(buf, lc->grfadd.grfid, lc->grfadd.md5sum, gc);
|
||||||
GrfIDMapping::Pair *gm = grf_names.Find(lc->grfrem.grfid);
|
GrfIDMapping::Pair *gm = grf_names.Find(lc->grfrem.grfid);
|
||||||
|
@ -272,7 +272,7 @@ void GamelogPrint(GamelogPrintProc *proc)
|
||||||
}
|
}
|
||||||
|
|
||||||
case GLCT_GRFCOMPAT: {
|
case GLCT_GRFCOMPAT: {
|
||||||
const GRFConfig *gc = FindGRFConfig(lc->grfadd.grfid, lc->grfadd.md5sum);
|
const GRFConfig *gc = FindGRFConfig(lc->grfadd.grfid, FGCM_EXACT, lc->grfadd.md5sum);
|
||||||
AddDebugText(buf, "Compatible NewGRF loaded: ");
|
AddDebugText(buf, "Compatible NewGRF loaded: ");
|
||||||
PrintGrfInfo(buf, lc->grfcompat.grfid, lc->grfcompat.md5sum, gc);
|
PrintGrfInfo(buf, lc->grfcompat.grfid, lc->grfcompat.md5sum, gc);
|
||||||
if (!grf_names.Contains(lc->grfcompat.grfid)) AddDebugText(buf, ". Gamelog inconsistency: GrfID was never added!");
|
if (!grf_names.Contains(lc->grfcompat.grfid)) AddDebugText(buf, ". Gamelog inconsistency: GrfID was never added!");
|
||||||
|
|
|
@ -690,7 +690,7 @@ DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_CHECK_NEWGRFS)
|
||||||
this->Recv_GRFIdentifier(p, &c);
|
this->Recv_GRFIdentifier(p, &c);
|
||||||
|
|
||||||
/* Check whether we know this GRF */
|
/* Check whether we know this GRF */
|
||||||
const GRFConfig *f = FindGRFConfig(c.grfid, c.md5sum);
|
const GRFConfig *f = FindGRFConfig(c.grfid, FGCM_EXACT, c.md5sum);
|
||||||
if (f == NULL) {
|
if (f == NULL) {
|
||||||
/* We do not know this GRF, bail out of initialization */
|
/* We do not know this GRF, bail out of initialization */
|
||||||
char buf[sizeof(c.md5sum) * 2 + 1];
|
char buf[sizeof(c.md5sum) * 2 + 1];
|
||||||
|
|
|
@ -32,7 +32,7 @@ ClientNetworkContentSocketHandler _network_content_client;
|
||||||
/** Wrapper function for the HasProc */
|
/** Wrapper function for the HasProc */
|
||||||
static bool HasGRFConfig(const ContentInfo *ci, bool md5sum)
|
static bool HasGRFConfig(const ContentInfo *ci, bool md5sum)
|
||||||
{
|
{
|
||||||
return FindGRFConfig(BSWAP32(ci->unique_id), md5sum ? ci->md5sum : NULL) != NULL;
|
return FindGRFConfig(BSWAP32(ci->unique_id), md5sum ? FGCM_EXACT : FGCM_ANY, md5sum ? ci->md5sum : NULL) != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -176,7 +176,7 @@ void NetworkAfterNewGRFScan()
|
||||||
for (GRFConfig *c = item->info.grfconfig; c != NULL; c = c->next) {
|
for (GRFConfig *c = item->info.grfconfig; c != NULL; c = c->next) {
|
||||||
assert(HasBit(c->flags, GCF_COPY));
|
assert(HasBit(c->flags, GCF_COPY));
|
||||||
|
|
||||||
const GRFConfig *f = FindGRFConfig(c->ident.grfid, c->ident.md5sum);
|
const GRFConfig *f = FindGRFConfig(c->ident.grfid, FGCM_EXACT, c->ident.md5sum);
|
||||||
if (f == NULL) {
|
if (f == NULL) {
|
||||||
/* Don't know the GRF, so mark game incompatible and the (possibly)
|
/* Don't know the GRF, so mark game incompatible and the (possibly)
|
||||||
* already resolved name for this GRF (another server has sent the
|
* already resolved name for this GRF (another server has sent the
|
||||||
|
|
|
@ -805,7 +805,7 @@ public:
|
||||||
for (GRFConfig *c = item->info.grfconfig; c != NULL; c = c->next) {
|
for (GRFConfig *c = item->info.grfconfig; c != NULL; c = c->next) {
|
||||||
if (c->status != GCS_NOT_FOUND) continue;
|
if (c->status != GCS_NOT_FOUND) continue;
|
||||||
|
|
||||||
const GRFConfig *f = FindGRFConfig(c->ident.grfid, c->ident.md5sum);
|
const GRFConfig *f = FindGRFConfig(c->ident.grfid, FGCM_EXACT, c->ident.md5sum);
|
||||||
if (f == NULL) {
|
if (f == NULL) {
|
||||||
missing_grfs = true;
|
missing_grfs = true;
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -182,7 +182,7 @@ DEF_UDP_RECEIVE_COMMAND(Server, PACKET_UDP_CLIENT_GET_NEWGRFS)
|
||||||
this->Recv_GRFIdentifier(p, &c);
|
this->Recv_GRFIdentifier(p, &c);
|
||||||
|
|
||||||
/* Find the matching GRF file */
|
/* Find the matching GRF file */
|
||||||
f = FindGRFConfig(c.grfid, c.md5sum);
|
f = FindGRFConfig(c.grfid, FGCM_EXACT, c.md5sum);
|
||||||
if (f == NULL) continue; // The GRF is unknown to this server
|
if (f == NULL) continue; // The GRF is unknown to this server
|
||||||
|
|
||||||
/* If the reply might exceed the size of the packet, only reply
|
/* If the reply might exceed the size of the packet, only reply
|
||||||
|
@ -362,7 +362,7 @@ DEF_UDP_RECEIVE_COMMAND(Client, PACKET_UDP_SERVER_NEWGRFS)
|
||||||
void ClientNetworkUDPSocketHandler::HandleIncomingNetworkGameInfoGRFConfig(GRFConfig *config)
|
void ClientNetworkUDPSocketHandler::HandleIncomingNetworkGameInfoGRFConfig(GRFConfig *config)
|
||||||
{
|
{
|
||||||
/* Find the matching GRF file */
|
/* Find the matching GRF file */
|
||||||
const GRFConfig *f = FindGRFConfig(config->ident.grfid, config->ident.md5sum);
|
const GRFConfig *f = FindGRFConfig(config->ident.grfid, FGCM_EXACT, config->ident.md5sum);
|
||||||
if (f == NULL) {
|
if (f == NULL) {
|
||||||
/* Don't know the GRF, so mark game incompatible and the (possibly)
|
/* Don't know the GRF, so mark game incompatible and the (possibly)
|
||||||
* already resolved name for this GRF (another server has sent the
|
* already resolved name for this GRF (another server has sent the
|
||||||
|
|
|
@ -442,13 +442,13 @@ GRFListCompatibility IsGoodGRFConfigList(GRFConfig *grfconfig)
|
||||||
GRFListCompatibility res = GLC_ALL_GOOD;
|
GRFListCompatibility res = GLC_ALL_GOOD;
|
||||||
|
|
||||||
for (GRFConfig *c = grfconfig; c != NULL; c = c->next) {
|
for (GRFConfig *c = grfconfig; c != NULL; c = c->next) {
|
||||||
const GRFConfig *f = FindGRFConfig(c->ident.grfid, c->ident.md5sum);
|
const GRFConfig *f = FindGRFConfig(c->ident.grfid, FGCM_EXACT, c->ident.md5sum);
|
||||||
if (f == NULL) {
|
if (f == NULL) {
|
||||||
char buf[256];
|
char buf[256];
|
||||||
|
|
||||||
/* If we have not found the exactly matching GRF try to find one with the
|
/* If we have not found the exactly matching GRF try to find one with the
|
||||||
* same grfid, as it most likely is compatible */
|
* same grfid, as it most likely is compatible */
|
||||||
f = FindGRFConfig(c->ident.grfid);
|
f = FindGRFConfig(c->ident.grfid, FGCM_COMPATIBLE);
|
||||||
if (f != NULL) {
|
if (f != NULL) {
|
||||||
md5sumToString(buf, lastof(buf), c->ident.md5sum);
|
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);
|
DEBUG(grf, 1, "NewGRF %08X (%s) not found; checksum %s. Compatibility mode on", BSWAP32(c->ident.grfid), c->filename, buf);
|
||||||
|
@ -614,15 +614,20 @@ void ScanNewGRFFiles()
|
||||||
/**
|
/**
|
||||||
* Find a NewGRF in the scanned list.
|
* Find a NewGRF in the scanned list.
|
||||||
* @param grfid GRFID to look for,
|
* @param grfid GRFID to look for,
|
||||||
* @param md5sum Expected MD5 sum (set to \c NULL if not relevant).
|
* @param mode Restrictions for matching grfs
|
||||||
|
* @param md5sum Expected MD5 sum
|
||||||
* @return The matching grf, if it exists in #_all_grfs, else \c NULL.
|
* @return The matching grf, if it exists in #_all_grfs, else \c NULL.
|
||||||
*/
|
*/
|
||||||
const GRFConfig *FindGRFConfig(uint32 grfid, const uint8 *md5sum)
|
const GRFConfig *FindGRFConfig(uint32 grfid, FindGRFConfigMode mode, const uint8 *md5sum)
|
||||||
{
|
{
|
||||||
|
assert((mode == FGCM_EXACT) != (md5sum == NULL));
|
||||||
const GRFConfig *best = NULL;
|
const GRFConfig *best = NULL;
|
||||||
for (const GRFConfig *c = _all_grfs; c != NULL; c = c->next) {
|
for (const GRFConfig *c = _all_grfs; c != NULL; c = c->next) {
|
||||||
|
/* if md5sum is set, we look for an exact match and continue if not found */
|
||||||
if (!c->ident.HasGrfIdentifier(grfid, md5sum)) continue;
|
if (!c->ident.HasGrfIdentifier(grfid, md5sum)) continue;
|
||||||
if (md5sum != NULL) return c;
|
/* return it, if the exact same newgrf is found, or if we do not care about finding "the best" */
|
||||||
|
if (md5sum != NULL || mode == FGCM_ANY) return c;
|
||||||
|
/* remember the newest one as "the best" */
|
||||||
if (best == NULL || c->version > best->version) best = c;
|
if (best == NULL || c->version > best->version) best = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -164,6 +164,14 @@ struct GRFConfig : ZeroedMemoryAllocator {
|
||||||
void SetSuitablePalette();
|
void SetSuitablePalette();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Method to find GRFs using FindGRFConfig */
|
||||||
|
enum FindGRFConfigMode {
|
||||||
|
FGCM_EXACT, ///< Only find Grfs matching md5sum
|
||||||
|
FGCM_COMPATIBLE, ///< Find best compatible
|
||||||
|
FGCM_NEWEST, ///< Find newest Grf
|
||||||
|
FGCM_ANY, ///< Use first found
|
||||||
|
};
|
||||||
|
|
||||||
extern GRFConfig *_all_grfs; ///< First item in list of all scanned NewGRFs
|
extern GRFConfig *_all_grfs; ///< First item in list of all scanned NewGRFs
|
||||||
extern GRFConfig *_grfconfig; ///< First item in list of current GRF set up
|
extern GRFConfig *_grfconfig; ///< First item in list of current GRF set up
|
||||||
extern GRFConfig *_grfconfig_newgame; ///< First item in list of default GRF set up
|
extern GRFConfig *_grfconfig_newgame; ///< First item in list of default GRF set up
|
||||||
|
@ -171,7 +179,7 @@ extern GRFConfig *_grfconfig_static; ///< First item in list of static GRF set
|
||||||
|
|
||||||
void ScanNewGRFFiles();
|
void ScanNewGRFFiles();
|
||||||
void CheckForMissingSprites();
|
void CheckForMissingSprites();
|
||||||
const GRFConfig *FindGRFConfig(uint32 grfid, const uint8 *md5sum = NULL);
|
const GRFConfig *FindGRFConfig(uint32 grfid, FindGRFConfigMode mode, const uint8 *md5sum = NULL);
|
||||||
GRFConfig *GetGRFConfig(uint32 grfid, uint32 mask = 0xFFFFFFFF);
|
GRFConfig *GetGRFConfig(uint32 grfid, uint32 mask = 0xFFFFFFFF);
|
||||||
GRFConfig **CopyGRFConfigList(GRFConfig **dst, const GRFConfig *src, bool init_only);
|
GRFConfig **CopyGRFConfigList(GRFConfig **dst, const GRFConfig *src, bool init_only);
|
||||||
void AppendStaticGRFConfigs(GRFConfig **dst);
|
void AppendStaticGRFConfigs(GRFConfig **dst);
|
||||||
|
|
|
@ -1035,7 +1035,7 @@ struct NewGRFWindow : public QueryStringBaseWindow {
|
||||||
bool compatible = HasBit(c->flags, GCF_COMPATIBLE);
|
bool compatible = HasBit(c->flags, GCF_COMPATIBLE);
|
||||||
if (c->status != GCS_NOT_FOUND && !compatible) continue;
|
if (c->status != GCS_NOT_FOUND && !compatible) continue;
|
||||||
|
|
||||||
const GRFConfig *f = FindGRFConfig(c->ident.grfid, compatible ? c->original_md5sum : c->ident.md5sum);
|
const GRFConfig *f = FindGRFConfig(c->ident.grfid, FGCM_EXACT, compatible ? c->original_md5sum : c->ident.md5sum);
|
||||||
if (f == NULL) continue;
|
if (f == NULL) continue;
|
||||||
|
|
||||||
*l = new GRFConfig(*f);
|
*l = new GRFConfig(*f);
|
||||||
|
@ -1211,7 +1211,7 @@ private:
|
||||||
if (_settings_client.gui.newgrf_show_old_versions) {
|
if (_settings_client.gui.newgrf_show_old_versions) {
|
||||||
*this->avails.Append() = c;
|
*this->avails.Append() = c;
|
||||||
} else {
|
} else {
|
||||||
const GRFConfig *best = FindGRFConfig(c->ident.grfid, NULL);
|
const GRFConfig *best = FindGRFConfig(c->ident.grfid, FGCM_NEWEST);
|
||||||
/*
|
/*
|
||||||
* If the best version is 0, then all NewGRF with this GRF ID
|
* If the best version is 0, then all NewGRF with this GRF ID
|
||||||
* have version 0, so for backward compatability reasons we
|
* have version 0, so for backward compatability reasons we
|
||||||
|
|
Loading…
Reference in New Issue