summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralberth <alberth@openttd.org>2010-05-16 18:50:37 +0000
committeralberth <alberth@openttd.org>2010-05-16 18:50:37 +0000
commit32713624133e86024b90521702fe1173943243c1 (patch)
tree8b14cf65ae1b49ed8b746a2f87af39bc22276e3f
parent9c3b9690fb856506190a4fe51dec573ddb6d9b7b (diff)
downloadopenttd-32713624133e86024b90521702fe1173943243c1.tar.xz
(svn r19835) -Codechange: Extract grfident equality check to its own method.
-rw-r--r--src/newgrf_config.cpp6
-rw-r--r--src/newgrf_config.h12
2 files changed, 13 insertions, 5 deletions
diff --git a/src/newgrf_config.cpp b/src/newgrf_config.cpp
index c3c3f4310..8f4d70f19 100644
--- a/src/newgrf_config.cpp
+++ b/src/newgrf_config.cpp
@@ -452,11 +452,7 @@ void ScanNewGRFFiles()
const GRFConfig *FindGRFConfig(uint32 grfid, const uint8 *md5sum)
{
for (const GRFConfig *c = _all_grfs; c != NULL; c = c->next) {
- if (c->ident.grfid == grfid) {
- if (md5sum == NULL) return c;
-
- if (memcmp(md5sum, c->ident.md5sum, sizeof(c->ident.md5sum)) == 0) return c;
- }
+ if (c->ident.HasGrfIdentifier(grfid, md5sum)) return c;
}
return NULL;
diff --git a/src/newgrf_config.h b/src/newgrf_config.h
index 0d97f0e44..e41fec1c0 100644
--- a/src/newgrf_config.h
+++ b/src/newgrf_config.h
@@ -53,6 +53,18 @@ enum GRFListCompatibility {
struct GRFIdentifier {
uint32 grfid; ///< GRF ID (defined by Action 0x08)
uint8 md5sum[16]; ///< MD5 checksum of file to distinguish files with the same GRF ID (eg. newer version of GRF)
+
+ /** Does the identification match the provided values?
+ * @param grfid Expected grfid.
+ * @param md5sum Expected md5sum, may be \c NULL (in which case, do not check it).
+ * @return the object has the provided grfid and md5sum.
+ */
+ FORCEINLINE bool HasGrfIdentifier(uint32 grfid, const uint8 *md5sum) const
+ {
+ if (this->grfid != grfid) return false;
+ if (md5sum == NULL) return true;
+ return memcmp(md5sum, this->md5sum, sizeof(this->md5sum)) == 0;
+ }
};
/** Information about why GRF had problems during initialisation */