mirror of https://github.com/OpenTTD/OpenTTD.git
Codechange: No need to convert GRFConfigList to a vector.
GRFConfigList is now already a vector, so gamelog's GenerateGRFList is no longer necessary.
This commit is contained in:
parent
43c7975e47
commit
4eb1eca8e2
|
@ -584,20 +584,6 @@ void Gamelog::GRFAddList(const GRFConfigList &newg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Generates GRFList
|
|
||||||
* @param grfc the GRFConfigList.
|
|
||||||
*/
|
|
||||||
static std::vector<std::shared_ptr<const GRFConfig>> GenerateGRFList(const GRFConfigList &grfc)
|
|
||||||
{
|
|
||||||
std::vector<std::shared_ptr<const GRFConfig>> list;
|
|
||||||
for (const auto &g : grfc) {
|
|
||||||
if (IsLoggableGrfConfig(g.get())) list.push_back(g);
|
|
||||||
}
|
|
||||||
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compares two NewGRF lists and logs any change
|
* Compares two NewGRF lists and logs any change
|
||||||
* @param oldc original GRF list
|
* @param oldc original GRF list
|
||||||
|
@ -605,66 +591,63 @@ static std::vector<std::shared_ptr<const GRFConfig>> GenerateGRFList(const GRFCo
|
||||||
*/
|
*/
|
||||||
void Gamelog::GRFUpdate(const GRFConfigList &oldc, const GRFConfigList &newc)
|
void Gamelog::GRFUpdate(const GRFConfigList &oldc, const GRFConfigList &newc)
|
||||||
{
|
{
|
||||||
std::vector<std::shared_ptr<const GRFConfig>> ol = GenerateGRFList(oldc);
|
|
||||||
std::vector<std::shared_ptr<const GRFConfig>> nl = GenerateGRFList(newc);
|
|
||||||
|
|
||||||
uint o = 0, n = 0;
|
uint o = 0, n = 0;
|
||||||
|
|
||||||
while (o < ol.size() && n < nl.size()) {
|
while (o < oldc.size() && n < newc.size()) {
|
||||||
const auto &og = ol[o];
|
const auto &og = oldc[o];
|
||||||
const auto &ng = nl[n];
|
const auto &ng = newc[n];
|
||||||
|
|
||||||
if (og->ident.grfid != ng->ident.grfid) {
|
if (og->ident.grfid != ng->ident.grfid) {
|
||||||
uint oi, ni;
|
uint oi, ni;
|
||||||
for (oi = 0; oi < ol.size(); oi++) {
|
for (oi = 0; oi < oldc.size(); oi++) {
|
||||||
if (ol[oi]->ident.grfid == nl[n]->ident.grfid) break;
|
if (oldc[oi]->ident.grfid == newc[n]->ident.grfid) break;
|
||||||
}
|
}
|
||||||
if (oi < o) {
|
if (oi < o) {
|
||||||
/* GRF was moved, this change has been logged already */
|
/* GRF was moved, this change has been logged already */
|
||||||
n++;
|
n++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (oi == ol.size()) {
|
if (oi == oldc.size()) {
|
||||||
/* GRF couldn't be found in the OLD list, GRF was ADDED */
|
/* GRF couldn't be found in the OLD list, GRF was ADDED */
|
||||||
this->GRFAdd(nl[n++].get());
|
this->GRFAdd(newc[n++].get());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for (ni = 0; ni < nl.size(); ni++) {
|
for (ni = 0; ni < newc.size(); ni++) {
|
||||||
if (nl[ni]->ident.grfid == ol[o]->ident.grfid) break;
|
if (newc[ni]->ident.grfid == oldc[o]->ident.grfid) break;
|
||||||
}
|
}
|
||||||
if (ni < n) {
|
if (ni < n) {
|
||||||
/* GRF was moved, this change has been logged already */
|
/* GRF was moved, this change has been logged already */
|
||||||
o++;
|
o++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (ni == nl.size()) {
|
if (ni == newc.size()) {
|
||||||
/* GRF couldn't be found in the NEW list, GRF was REMOVED */
|
/* GRF couldn't be found in the NEW list, GRF was REMOVED */
|
||||||
this->GRFRemove(ol[o++]->ident.grfid);
|
this->GRFRemove(oldc[o++]->ident.grfid);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* o < oi < ol->n
|
/* o < oi < ol->n
|
||||||
* n < ni < nl->n */
|
* n < ni < nl->n */
|
||||||
assert(ni > n && ni < nl.size());
|
assert(ni > n && ni < newc.size());
|
||||||
assert(oi > o && oi < ol.size());
|
assert(oi > o && oi < oldc.size());
|
||||||
|
|
||||||
ni -= n; // number of GRFs it was moved downwards
|
ni -= n; // number of GRFs it was moved downwards
|
||||||
oi -= o; // number of GRFs it was moved upwards
|
oi -= o; // number of GRFs it was moved upwards
|
||||||
|
|
||||||
if (ni >= oi) { // prefer the one that is moved further
|
if (ni >= oi) { // prefer the one that is moved further
|
||||||
/* GRF was moved down */
|
/* GRF was moved down */
|
||||||
this->GRFMove(ol[o++]->ident.grfid, ni);
|
this->GRFMove(oldc[o++]->ident.grfid, ni);
|
||||||
} else {
|
} else {
|
||||||
this->GRFMove(nl[n++]->ident.grfid, -(int)oi);
|
this->GRFMove(newc[n++]->ident.grfid, -(int)oi);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (og->ident.md5sum != ng->ident.md5sum) {
|
if (og->ident.md5sum != ng->ident.md5sum) {
|
||||||
/* md5sum changed, probably loading 'compatible' GRF */
|
/* md5sum changed, probably loading 'compatible' GRF */
|
||||||
this->GRFCompatible(&nl[n]->ident);
|
this->GRFCompatible(&newc[n]->ident);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (og->num_params != ng->num_params || og->param == ng->param) {
|
if (og->num_params != ng->num_params || og->param == ng->param) {
|
||||||
this->GRFParameters(ol[o]->ident.grfid);
|
this->GRFParameters(oldc[o]->ident.grfid);
|
||||||
}
|
}
|
||||||
|
|
||||||
o++;
|
o++;
|
||||||
|
@ -672,8 +655,8 @@ void Gamelog::GRFUpdate(const GRFConfigList &oldc, const GRFConfigList &newc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while (o < ol.size()) this->GRFRemove(ol[o++]->ident.grfid); // remaining GRFs were removed ...
|
while (o < oldc.size()) this->GRFRemove(oldc[o++]->ident.grfid); // remaining GRFs were removed ...
|
||||||
while (n < nl.size()) this->GRFAdd (nl[n++].get()); // ... or added
|
while (n < newc.size()) this->GRFAdd (newc[n++].get()); // ... or added
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue