diff options
author | frosch <frosch@openttd.org> | 2010-10-17 12:12:13 +0000 |
---|---|---|
committer | frosch <frosch@openttd.org> | 2010-10-17 12:12:13 +0000 |
commit | 3972c790c2cba8c4c01ac6536e8675808f6e1c4d (patch) | |
tree | 09e55bb7f156c3cd331ee37683595583d88a2625 | |
parent | 918da8432ae709e002448c947550674e1f4ae278 (diff) | |
download | openttd-3972c790c2cba8c4c01ac6536e8675808f6e1c4d.tar.xz |
(svn r20957) -Codechange: Add another parameter to FindGRFConfig() to define search restrictions.
-rw-r--r-- | src/gamelog.cpp | 6 | ||||
-rw-r--r-- | src/network/network_client.cpp | 2 | ||||
-rw-r--r-- | src/network/network_content.cpp | 2 | ||||
-rw-r--r-- | src/network/network_gamelist.cpp | 2 | ||||
-rw-r--r-- | src/network/network_gui.cpp | 2 | ||||
-rw-r--r-- | src/network/network_udp.cpp | 4 | ||||
-rw-r--r-- | src/newgrf_config.cpp | 15 | ||||
-rw-r--r-- | src/newgrf_config.h | 10 | ||||
-rw-r--r-- | src/newgrf_gui.cpp | 4 |
9 files changed, 30 insertions, 17 deletions
diff --git a/src/gamelog.cpp b/src/gamelog.cpp index e6b0595cc..b874655d0 100644 --- a/src/gamelog.cpp +++ b/src/gamelog.cpp @@ -126,7 +126,7 @@ static void PrintGrfInfo(char *buf, uint grfid, const uint8 *md5sum, const GRFCo if (gc != NULL) { AddDebugText(buf, ", filename: %s (md5sum matches)", gc->filename); } else { - gc = FindGRFConfig(grfid); + gc = FindGRFConfig(grfid, FGCM_ANY); if (gc != NULL) { AddDebugText(buf, ", filename: %s (matches GRFID only)", gc->filename); } else { @@ -245,7 +245,7 @@ void GamelogPrint(GamelogPrintProc *proc) break; 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: "); PrintGrfInfo(buf, lc->grfadd.grfid, lc->grfadd.md5sum, gc); GrfIDMapping::Pair *gm = grf_names.Find(lc->grfrem.grfid); @@ -272,7 +272,7 @@ void GamelogPrint(GamelogPrintProc *proc) } 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: "); PrintGrfInfo(buf, lc->grfcompat.grfid, lc->grfcompat.md5sum, gc); if (!grf_names.Contains(lc->grfcompat.grfid)) AddDebugText(buf, ". Gamelog inconsistency: GrfID was never added!"); diff --git a/src/network/network_client.cpp b/src/network/network_client.cpp index 5a930d74b..d157ebe7c 100644 --- a/src/network/network_client.cpp +++ b/src/network/network_client.cpp @@ -690,7 +690,7 @@ DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_CHECK_NEWGRFS) this->Recv_GRFIdentifier(p, &c); /* 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) { /* We do not know this GRF, bail out of initialization */ char buf[sizeof(c.md5sum) * 2 + 1]; diff --git a/src/network/network_content.cpp b/src/network/network_content.cpp index 680dbfb98..93bfce132 100644 --- a/src/network/network_content.cpp +++ b/src/network/network_content.cpp @@ -32,7 +32,7 @@ ClientNetworkContentSocketHandler _network_content_client; /** Wrapper function for the HasProc */ 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; } /** diff --git a/src/network/network_gamelist.cpp b/src/network/network_gamelist.cpp index d248df429..814a5ed49 100644 --- a/src/network/network_gamelist.cpp +++ b/src/network/network_gamelist.cpp @@ -176,7 +176,7 @@ void NetworkAfterNewGRFScan() for (GRFConfig *c = item->info.grfconfig; c != NULL; c = c->next) { 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) { /* Don't know the GRF, so mark game incompatible and the (possibly) * already resolved name for this GRF (another server has sent the diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp index 6897be989..8e312e5a5 100644 --- a/src/network/network_gui.cpp +++ b/src/network/network_gui.cpp @@ -805,7 +805,7 @@ public: for (GRFConfig *c = item->info.grfconfig; c != NULL; c = c->next) { 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) { missing_grfs = true; continue; diff --git a/src/network/network_udp.cpp b/src/network/network_udp.cpp index dadf0525f..eb4fa4c3c 100644 --- a/src/network/network_udp.cpp +++ b/src/network/network_udp.cpp @@ -182,7 +182,7 @@ DEF_UDP_RECEIVE_COMMAND(Server, PACKET_UDP_CLIENT_GET_NEWGRFS) this->Recv_GRFIdentifier(p, &c); /* 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 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) { /* 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) { /* Don't know the GRF, so mark game incompatible and the (possibly) * already resolved name for this GRF (another server has sent the diff --git a/src/newgrf_config.cpp b/src/newgrf_config.cpp index eaadd6143..6e32fe054 100644 --- a/src/newgrf_config.cpp +++ b/src/newgrf_config.cpp @@ -442,13 +442,13 @@ GRFListCompatibility IsGoodGRFConfigList(GRFConfig *grfconfig) GRFListCompatibility res = GLC_ALL_GOOD; 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) { 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->ident.grfid); + f = FindGRFConfig(c->ident.grfid, FGCM_COMPATIBLE); if (f != NULL) { 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); @@ -614,15 +614,20 @@ void ScanNewGRFFiles() /** * Find a NewGRF in the scanned list. * @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. */ -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; 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 (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; } diff --git a/src/newgrf_config.h b/src/newgrf_config.h index e8b6bc86a..085791282 100644 --- a/src/newgrf_config.h +++ b/src/newgrf_config.h @@ -164,6 +164,14 @@ struct GRFConfig : ZeroedMemoryAllocator { 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 *_grfconfig; ///< First item in list of current 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 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 **CopyGRFConfigList(GRFConfig **dst, const GRFConfig *src, bool init_only); void AppendStaticGRFConfigs(GRFConfig **dst); diff --git a/src/newgrf_gui.cpp b/src/newgrf_gui.cpp index 0e7934b68..5169feb57 100644 --- a/src/newgrf_gui.cpp +++ b/src/newgrf_gui.cpp @@ -1035,7 +1035,7 @@ struct NewGRFWindow : public QueryStringBaseWindow { bool compatible = HasBit(c->flags, GCF_COMPATIBLE); 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; *l = new GRFConfig(*f); @@ -1211,7 +1211,7 @@ private: if (_settings_client.gui.newgrf_show_old_versions) { *this->avails.Append() = c; } 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 * have version 0, so for backward compatability reasons we |