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

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

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

@ -79,13 +79,15 @@ public:
// terrain palette, but ESMReader does not pass a reference to the correct plugin // 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 // to the individual load() methods. This hack allows to pass this reference
// indirectly to the load() method. // indirectly to the load() method.
int mIdx; void setIndex(const int index) { mCtx.index = index;}
void setIndex(const int index) {mIdx = index; mCtx.index = index;} int getIndex() {return mCtx.index;}
int getIndex() {return mIdx;}
void setGlobalReaderList(std::vector<ESMReader> *list) {mGlobalReaderList = list;} void setGlobalReaderList(std::vector<ESMReader> *list) {mGlobalReaderList = list;}
std::vector<ESMReader> *getGlobalReaderList() {return mGlobalReaderList;} 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 * 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 // 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) // 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. // 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. // In this case, do not spawn a new reference, but overwrite the old one.
refNum.mIndex &= 0x00ffffff; // delete old plugin ID refNum.mIndex &= 0x00ffffff; // delete old plugin ID
refNum.mContentFile = reader.getGameFiles()[local-1].index; refNum.mContentFile = reader.getParentFileIndices()[local-1];
} }
else else
{ {

Loading…
Cancel
Save