Merge branch 'remove_evil_const_cast' into 'master'

clean up code; purge const_cast

See merge request OpenMW/openmw!175
pull/578/head
Bret Curtis 5 years ago
commit 63bdc84f91

@ -45,7 +45,7 @@ void ESMStore::load(ESM::ESMReader &esm, Loading::Listener* listener)
const std::vector<ESM::Header::MasterData> &masters = esm.getGameFiles();
std::vector<ESM::ESMReader> *allPlugins = esm.getGlobalReaderList();
for (size_t j = 0; j < masters.size(); j++) {
ESM::Header::MasterData &mast = const_cast<ESM::Header::MasterData&>(masters[j]);
const ESM::Header::MasterData &mast = masters[j];
std::string fname = mast.name;
int index = ~0;
for (int i = 0; i < esm.getIndex(); i++) {
@ -63,7 +63,7 @@ void ESMStore::load(ESM::ESMReader &esm, Loading::Listener* listener)
+ ", but it has not been loaded yet. Please check your load order.";
esm.fail(fstring);
}
mast.index = index;
esm.addParentFileIndex(index);
}
// Loop through all records

@ -3,6 +3,7 @@
#include <string>
#include <cstring>
#include <vector>
#include <stdint.h>
#include <string.h>
@ -126,6 +127,7 @@ struct ESM_Context
// actually contribute to a specific cell. Therefore, we need to store the index
// of the file belonging to this contest. See CellStore::(list/load)refs for details.
int index;
std::vector<int> parentFileIndices;
// True if subName has been read but not used.
bool subCached;

@ -20,8 +20,7 @@ ESM_Context ESMReader::getContext()
}
ESMReader::ESMReader()
: mIdx(0)
, mRecordFlags(0)
: mRecordFlags(0)
, mBuffer(50*1024)
, mGlobalReaderList(nullptr)
, mEncoder(nullptr)

@ -79,13 +79,15 @@ public:
// terrain palette, but ESMReader does not pass a reference to the correct plugin
// to the individual load() methods. This hack allows to pass this reference
// indirectly to the load() method.
int mIdx;
void setIndex(const int index) {mIdx = index; mCtx.index = index;}
int getIndex() {return mIdx;}
void setIndex(const int index) { mCtx.index = index;}
int getIndex() {return mCtx.index;}
void setGlobalReaderList(std::vector<ESMReader> *list) {mGlobalReaderList = list;}
std::vector<ESMReader> *getGlobalReaderList() {return mGlobalReaderList;}
void addParentFileIndex(int index) { mCtx.parentFileIndices.push_back(index); }
const std::vector<int>& getParentFileIndices() const { return mCtx.parentFileIndices; }
/*************************************************************************
*
* Medium-level reading shortcuts

@ -21,12 +21,12 @@ namespace
// If we have an index value that does not make sense, assume that it was an addition
// by the present plugin (but a faulty one)
if (local && local <= reader.getGameFiles().size())
if (local && local <= reader.getParentFileIndices().size())
{
// If the most significant 8 bits are used, then this reference already exists.
// In this case, do not spawn a new reference, but overwrite the old one.
refNum.mIndex &= 0x00ffffff; // delete old plugin ID
refNum.mContentFile = reader.getGameFiles()[local-1].index;
refNum.mContentFile = reader.getParentFileIndices()[local-1];
}
else
{

Loading…
Cancel
Save