Fix some double-to-float Visual Studio warnings in npc.cpp. Add 'm' prefix to member variables in esm_reader.hpp.

actorid
athile 14 years ago
parent 75f77e9659
commit 27f69d0f5b

@ -16,6 +16,12 @@
#include "../mwmechanics/mechanicsmanager.hpp" #include "../mwmechanics/mechanicsmanager.hpp"
#include <OgreSceneNode.h> #include <OgreSceneNode.h>
namespace
{
const Ogre::Radian kOgrePi (Ogre::Math::PI);
const Ogre::Radian kOgrePiOverTwo (Ogre::Math::PI / Ogre::Real(2.0));
}
namespace MWClass namespace MWClass
{ {
std::string Npc::getId (const MWWorld::Ptr& ptr) const std::string Npc::getId (const MWWorld::Ptr& ptr) const
@ -107,18 +113,18 @@ namespace MWClass
std::string upperarmpath[2] = {npcName + "chest", npcName + "upper arm"}; std::string upperarmpath[2] = {npcName + "chest", npcName + "upper arm"};
if (groin){ if (groin){
cellRender.insertMesh("meshes\\" + groin->model, pos2, axis, Ogre::Radian(3.14), npcName + "groin", addresses, numbers); cellRender.insertMesh("meshes\\" + groin->model, pos2, axis, kOgrePi, npcName + "groin", addresses, numbers);
addresses2[numbers] = npcName + "groin"; addresses2[numbers] = npcName + "groin";
addresses[numbers++] = npcName + "groin"; addresses[numbers++] = npcName + "groin";
} }
if (tail) { if (tail) {
cellRender.insertMesh("tail\\" + tail->model, Ogre::Vector3(0 , 0, -76), axis, Ogre::Radian(3.14), npcName + "tail", addresses, numbers, "tail"); cellRender.insertMesh("tail\\" + tail->model, Ogre::Vector3(0 , 0, -76), axis, kOgrePi, npcName + "tail", addresses, numbers, "tail");
//std::cout << "TAIL\n"; //std::cout << "TAIL\n";
} }
//addresses[1] = npcName + "groin"; //addresses[1] = npcName + "groin";
if(upperleg){ if(upperleg){
cellRender.insertMesh ("meshes\\" + upperleg->model, Ogre::Vector3( 6, 0, -16), axis, Ogre::Radian(3.14), npcName + "upper leg", addresses, numbers); //-18 cellRender.insertMesh ("meshes\\" + upperleg->model, Ogre::Vector3( 6, 0, -16), axis, kOgrePi, npcName + "upper leg", addresses, numbers); //-18
cellRender.insertMesh ("meshes\\" + upperleg->model, Ogre::Vector3( -6, 0, -16), axis, Ogre::Radian(0), npcName + "upper leg2", addresses2, numbers); cellRender.insertMesh ("meshes\\" + upperleg->model, Ogre::Vector3( -6, 0, -16), axis, Ogre::Radian(0), npcName + "upper leg2", addresses2, numbers);
addresses2[numbers] = npcName + "upper leg2"; addresses2[numbers] = npcName + "upper leg2";
addresses[numbers++] = npcName + "upper leg"; addresses[numbers++] = npcName + "upper leg";
@ -158,9 +164,9 @@ namespace MWClass
} }
if(feet){ if(feet){
cellRender.insertMesh ("foot\\" + feet->model, Ogre::Vector3( 7, 4, -16), axis, Ogre::Radian(3.14), npcName + "foot", addresses, numbers); //9, 0, -14 cellRender.insertMesh ("foot\\" + feet->model, Ogre::Vector3( 7, 4, -16), axis, kOgrePi, npcName + "foot", addresses, numbers); //9, 0, -14
cellRender.insertMesh ("foot\\" + feet->model, Ogre::Vector3( 7, 4, -16), axis, Ogre::Radian(3.14), npcName + "foot2", addresses2, numbers); cellRender.insertMesh ("foot\\" + feet->model, Ogre::Vector3( 7, 4, -16), axis, kOgrePi, npcName + "foot2", addresses2, numbers);
addresses2[numbers] = npcName + "foot2"; addresses2[numbers] = npcName + "foot2";
addresses[numbers++] = npcName + "foot"; addresses[numbers++] = npcName + "foot";
//cellRender.scaleMesh(Ogre::Vector3(1, -1, 1), addresses, numbers); //cellRender.scaleMesh(Ogre::Vector3(1, -1, 1), addresses, numbers);
@ -169,20 +175,20 @@ namespace MWClass
if (arm){ if (arm){
//010 //010
cellRender.insertMesh("meshes\\" + arm->model, Ogre::Vector3(-12.5, 0, 104), Ogre::Vector3(0, 1, 0), Ogre::Radian(-3.14 / 2), npcName + "upper arm", upperleft, uppernumbers); //1, 0,.75 cellRender.insertMesh("meshes\\" + arm->model, Ogre::Vector3(-12.5, 0, 104), Ogre::Vector3(0, 1, 0), -kOgrePiOverTwo, npcName + "upper arm", upperleft, uppernumbers); //1, 0,.75
//cellRender.rotateMesh(Ogre::Vector3(1, 0, 0), Ogre::Radian (.45), upperarmpath, 2); //-.5, 0, -.75 //cellRender.rotateMesh(Ogre::Vector3(1, 0, 0), Ogre::Radian (.45), upperarmpath, 2); //-.5, 0, -.75
cellRender.insertMesh("meshes\\" + arm->model, Ogre::Vector3(12.5, 0, 105), Ogre::Vector3(-.5, 0, -.75), Ogre::Radian(3.14), npcName + "upper arm2", upperright, uppernumbers); cellRender.insertMesh("meshes\\" + arm->model, Ogre::Vector3(12.5, 0, 105), Ogre::Vector3(-.5, 0, -.75), kOgrePi, npcName + "upper arm2", upperright, uppernumbers);
upperleft[uppernumbers] = npcName + "upper arm"; upperleft[uppernumbers] = npcName + "upper arm";
upperright[uppernumbers++] = npcName + "upper arm2"; upperright[uppernumbers++] = npcName + "upper arm2";
cellRender.scaleMesh(Ogre::Vector3(1, -1, 1), upperleft, uppernumbers); //1 -1 1 cellRender.scaleMesh(Ogre::Vector3(1, -1, 1), upperleft, uppernumbers); //1 -1 1
cellRender.rotateMesh(Ogre::Vector3(0, .1, 0), Ogre::Radian(3.14/2), upperleft, uppernumbers); cellRender.rotateMesh(Ogre::Vector3(0, 1, 0), kOgrePiOverTwo, upperleft, uppernumbers);
} }
if (forearm) if (forearm)
{ {
//addresses[1] = npcName + "upper arm"; //addresses[1] = npcName + "upper arm";
cellRender.insertMesh("meshes\\" + forearm->model, Ogre::Vector3(-12.5, 0, 0), Ogre::Vector3(0, 0, 0), Ogre::Radian(3.14), npcName + "forearm", upperleft, uppernumbers); cellRender.insertMesh("meshes\\" + forearm->model, Ogre::Vector3(-12.5, 0, 0), Ogre::Vector3(0, 0, 0), kOgrePi, npcName + "forearm", upperleft, uppernumbers);
cellRender.insertMesh("meshes\\" + forearm->model, Ogre::Vector3(-12.5, 0, 0), Ogre::Vector3(0, 0, 0), Ogre::Radian(3.14), npcName + "forearm2", upperright, uppernumbers); cellRender.insertMesh("meshes\\" + forearm->model, Ogre::Vector3(-12.5, 0, 0), Ogre::Vector3(0, 0, 0), kOgrePi, npcName + "forearm2", upperright, uppernumbers);
upperleft[uppernumbers] = npcName + "forearm"; upperleft[uppernumbers] = npcName + "forearm";
upperright[uppernumbers++] = npcName + "forearm2"; upperright[uppernumbers++] = npcName + "forearm2";
} }
@ -192,14 +198,14 @@ namespace MWClass
{ {
if(upperleft[uppernumbers - 1].compare(npcName + "upper arm") == 0) if(upperleft[uppernumbers - 1].compare(npcName + "upper arm") == 0)
{ {
cellRender.insertMesh("meshes\\b\\B_N_Argonian_M_Forearm.nif", Ogre::Vector3(-12.5, 0, 0), Ogre::Vector3(0, 0, 0), Ogre::Radian(3.14), npcName + "forearm", upperleft, uppernumbers); cellRender.insertMesh("meshes\\b\\B_N_Argonian_M_Forearm.nif", Ogre::Vector3(-12.5, 0, 0), Ogre::Vector3(0, 0, 0), kOgrePi, npcName + "forearm", upperleft, uppernumbers);
cellRender.insertMesh("meshes\\b\\B_N_Argonian_M_Forearm.nif", Ogre::Vector3(-12.5, 0, 0), Ogre::Vector3(0, 0, 0), Ogre::Radian(3.14), npcName + "forearm2", upperright, uppernumbers); cellRender.insertMesh("meshes\\b\\B_N_Argonian_M_Forearm.nif", Ogre::Vector3(-12.5, 0, 0), Ogre::Vector3(0, 0, 0), kOgrePi, npcName + "forearm2", upperright, uppernumbers);
upperleft[uppernumbers] = npcName + "forearm"; upperleft[uppernumbers] = npcName + "forearm";
upperright[uppernumbers++] = npcName + "forearm2"; upperright[uppernumbers++] = npcName + "forearm2";
} }
cellRender.insertMesh("meshes\\" + wrist->model, Ogre::Vector3(-9.5, 0, 0), Ogre::Vector3(0, 0, 0), Ogre::Radian(3.14), npcName + "wrist", upperleft, uppernumbers); cellRender.insertMesh("meshes\\" + wrist->model, Ogre::Vector3(-9.5, 0, 0), Ogre::Vector3(0, 0, 0), kOgrePi, npcName + "wrist", upperleft, uppernumbers);
cellRender.insertMesh("meshes\\" + wrist->model, Ogre::Vector3(-9.5, 0, 0), Ogre::Vector3(0, 0, 0), Ogre::Radian(3.14), npcName + "wrist2", upperright, uppernumbers); cellRender.insertMesh("meshes\\" + wrist->model, Ogre::Vector3(-9.5, 0, 0), Ogre::Vector3(0, 0, 0), kOgrePi, npcName + "wrist2", upperright, uppernumbers);
upperleft[uppernumbers] = npcName + "wrist"; upperleft[uppernumbers] = npcName + "wrist";
upperright[uppernumbers++] = npcName + "wrist2"; upperright[uppernumbers++] = npcName + "wrist2";
} }
@ -215,11 +221,11 @@ namespace MWClass
pass = "b\\B_N_Dark Elf_M_Hands.1st.NIF"; pass = "b\\B_N_Dark Elf_M_Hands.1st.NIF";
else else
pass = hand->model; pass = hand->model;
cellRender.insertMesh("meshes\\" + pass, Ogre::Vector3(42, 1, -110), Ogre::Vector3(0, 0, 0), Ogre::Radian(3.14), npcName + "hand", upperleft, uppernumbers,false); //0, 100, -100 0,0,120 cellRender.insertMesh("meshes\\" + pass, Ogre::Vector3(42, 1, -110), Ogre::Vector3(0, 0, 0), kOgrePi, npcName + "hand", upperleft, uppernumbers,false); //0, 100, -100 0,0,120
cellRender.insertMesh("meshes\\" + pass, Ogre::Vector3(42, 1, -110), Ogre::Vector3(0, 0,0), Ogre::Radian(3.14), npcName + "hand2", upperright, uppernumbers, false); //0, 100, -100 0,0,120 cellRender.insertMesh("meshes\\" + pass, Ogre::Vector3(42, 1, -110), Ogre::Vector3(0, 0,0), kOgrePi, npcName + "hand2", upperright, uppernumbers, false); //0, 100, -100 0,0,120
upperleft[uppernumbers] = npcName + "hand"; upperleft[uppernumbers] = npcName + "hand";
upperright[uppernumbers++] = npcName + "hand2"; upperright[uppernumbers++] = npcName + "hand2";
//cellRender.rotateMesh(Ogre::Vector3(0, 0,0), Ogre::Radian(3.14), upperleft, uppernumbers); //cellRender.rotateMesh(Ogre::Vector3(0, 0,0), kOgrePi, upperleft, uppernumbers);
cellRender.scaleMesh(Ogre::Vector3(1, -1, 1), upperleft, uppernumbers); cellRender.scaleMesh(Ogre::Vector3(1, -1, 1), upperleft, uppernumbers);
cellRender.scaleMesh(Ogre::Vector3(1, -1, 1), upperright, uppernumbers); cellRender.scaleMesh(Ogre::Vector3(1, -1, 1), upperright, uppernumbers);
} }
@ -232,9 +238,9 @@ namespace MWClass
pass = "b\\B_N_Nord_M_Hands.1st.nif"; pass = "b\\B_N_Nord_M_Hands.1st.nif";
else else
pass =hands->model; //-50, 0, -120 pass =hands->model; //-50, 0, -120
cellRender.insertMesh("meshes\\" + pass, Ogre::Vector3(42, 1,-110), Ogre::Vector3(0, 0, 0), Ogre::Radian(3.14), npcName + "hand", upperleft, uppernumbers, false); //0, 100, -100 42, 0, -110 cellRender.insertMesh("meshes\\" + pass, Ogre::Vector3(42, 1,-110), Ogre::Vector3(0, 0, 0), kOgrePi, npcName + "hand", upperleft, uppernumbers, false); //0, 100, -100 42, 0, -110
//cellRender.insertMesh("meshes\\" + hands->model, Ogre::Vector3(42, 0,110), Ogre::Vector3(1, 0, 0), Ogre::Radian(3.14), npcName + "hand", upperleft, uppernumbers, false); //0, 100, -100 42, 0, -110 //cellRender.insertMesh("meshes\\" + hands->model, Ogre::Vector3(42, 0,110), Ogre::Vector3(1, 0, 0), kOgrePi, npcName + "hand", upperleft, uppernumbers, false); //0, 100, -100 42, 0, -110
cellRender.insertMesh("meshes\\" + pass, Ogre::Vector3(42, 1, -110), Ogre::Vector3(0, 0, 0), Ogre::Radian(3.14), npcName + "hand2", upperright, uppernumbers, false); //0, 100, -100 0,0,120 cellRender.insertMesh("meshes\\" + pass, Ogre::Vector3(42, 1, -110), Ogre::Vector3(0, 0, 0), kOgrePi, npcName + "hand2", upperright, uppernumbers, false); //0, 100, -100 0,0,120
upperleft[uppernumbers] = npcName + "hand"; upperleft[uppernumbers] = npcName + "hand";
upperright[uppernumbers++] = npcName + "hand2"; upperright[uppernumbers++] = npcName + "hand2";
cellRender.scaleMesh(Ogre::Vector3(1, -1, 1), upperleft, uppernumbers); cellRender.scaleMesh(Ogre::Vector3(1, -1, 1), upperleft, uppernumbers);
@ -244,7 +250,7 @@ namespace MWClass
//neck will reset chest counter //neck will reset chest counter
if(neck) if(neck)
{ {
cellRender.insertMesh ("meshes\\" + neck->model, Ogre::Vector3( 0, 0, 120), axis, Ogre::Radian(3.14), npcName + "neck", neckandup, neckNumbers); cellRender.insertMesh ("meshes\\" + neck->model, Ogre::Vector3( 0, 0, 120), axis, kOgrePi, npcName + "neck", neckandup, neckNumbers);
neckandup[neckNumbers++] = npcName + "neck"; neckandup[neckNumbers++] = npcName + "neck";
} }
cellRender.insertMesh (headModel, Ogre::Vector3( 0, 0, 5), axis, Ogre::Radian(0), npcName + "head", neckandup, neckNumbers); cellRender.insertMesh (headModel, Ogre::Vector3( 0, 0, 5), axis, Ogre::Radian(0), npcName + "head", neckandup, neckNumbers);

@ -152,15 +152,15 @@ public:
* *
*************************************************************************/ *************************************************************************/
int getVer() { return c.header.version; } int getVer() { return mCtx.header.version; }
float getFVer() { return *((float*)&c.header.version); } float getFVer() { return *((float*)&mCtx.header.version); }
int getSpecial() { return spf; } int getSpecial() { return mSpf; }
const std::string getAuthor() { return c.header.author.toString(); } const std::string getAuthor() { return mCtx.header.author.toString(); }
const std::string getDesc() { return c.header.desc.toString(); } const std::string getDesc() { return mCtx.header.desc.toString(); }
const SaveData &getSaveData() { return saveData; } const SaveData &getSaveData() { return mSaveData; }
const MasterList &getMasters() { return masters; } const MasterList &getMasters() { return mMasters; }
const NAME &retSubName() { return c.subName; } const NAME &retSubName() { return mCtx.subName; }
uint32_t getSubSize() { return c.leftSub; } uint32_t getSubSize() { return mCtx.leftSub; }
/************************************************************************* /*************************************************************************
* *
@ -174,22 +174,22 @@ public:
ESM_Context getContext() ESM_Context getContext()
{ {
// Update the file position before returning // Update the file position before returning
c.filePos = esm->tell(); mCtx.filePos = mEsm->tell();
return c; return mCtx;
} }
/** Restore a previously saved context */ /** Restore a previously saved context */
void restoreContext(const ESM_Context &rc) void restoreContext(const ESM_Context &rc)
{ {
// Reopen the file if necessary // Reopen the file if necessary
if(c.filename != rc.filename) if(mCtx.filename != rc.filename)
openRaw(rc.filename); openRaw(rc.filename);
// Copy the data // Copy the data
c = rc; mCtx = rc;
// Make sure we seek to the right place // Make sure we seek to the right place
esm->seek(c.filePos); mEsm->seek(mCtx.filePos);
} }
/** Close the file, resets all information. After calling close() /** Close the file, resets all information. After calling close()
@ -197,14 +197,14 @@ public:
*/ */
void close() void close()
{ {
esm.reset(); mEsm.reset();
c.filename.clear(); mCtx.filename.clear();
c.leftFile = 0; mCtx.leftFile = 0;
c.leftRec = 0; mCtx.leftRec = 0;
c.leftSub = 0; mCtx.leftSub = 0;
c.subCached = false; mCtx.subCached = false;
c.recName.val = 0; mCtx.recName.val = 0;
c.subName.val = 0; mCtx.subName.val = 0;
} }
/// Raw opening. Opens the file and sets everything up but doesn't /// Raw opening. Opens the file and sets everything up but doesn't
@ -212,17 +212,17 @@ public:
void openRaw(Mangle::Stream::StreamPtr _esm, const std::string &name) void openRaw(Mangle::Stream::StreamPtr _esm, const std::string &name)
{ {
close(); close();
esm = _esm; mEsm = _esm;
c.filename = name; mCtx.filename = name;
c.leftFile = esm->size(); mCtx.leftFile = mEsm->size();
// Flag certain files for special treatment, based on the file // Flag certain files for special treatment, based on the file
// name. // name.
const char *cstr = c.filename.c_str(); const char *cstr = mCtx.filename.c_str();
if(iends(cstr, "Morrowind.esm")) spf = SF_Morrowind; if(iends(cstr, "Morrowind.esm")) mSpf = SF_Morrowind;
else if(iends(cstr, "Tribunal.esm")) spf = SF_Tribunal; else if(iends(cstr, "Tribunal.esm")) mSpf = SF_Tribunal;
else if(iends(cstr, "Bloodmoon.esm")) spf = SF_Bloodmoon; else if(iends(cstr, "Bloodmoon.esm")) mSpf = SF_Bloodmoon;
else spf = SF_Other; else mSpf = SF_Other;
} }
/// Load ES file from a new stream, parses the header. Closes the /// Load ES file from a new stream, parses the header. Closes the
@ -237,10 +237,10 @@ public:
getRecHeader(); getRecHeader();
// Get the header // Get the header
getHNT(c.header, "HEDR", 300); getHNT(mCtx.header, "HEDR", 300);
if(c.header.version != VER_12 && if(mCtx.header.version != VER_12 &&
c.header.version != VER_13) mCtx.header.version != VER_13)
fail("Unsupported file format version"); fail("Unsupported file format version");
while(isNextSub("MAST")) while(isNextSub("MAST"))
@ -248,15 +248,15 @@ public:
MasterData m; MasterData m;
m.name = getHString(); m.name = getHString();
m.size = getHNLong("DATA"); m.size = getHNLong("DATA");
masters.push_back(m); mMasters.push_back(m);
} }
if(c.header.type == FT_ESS) if(mCtx.header.type == FT_ESS)
{ {
// Savegame-related data // Savegame-related data
// Player position etc // Player position etc
getHNT(saveData, "GMDT", 124); getHNT(mSaveData, "GMDT", 124);
/* Image properties, five ints. Is always: /* Image properties, five ints. Is always:
Red-mask: 0xff0000 Red-mask: 0xff0000
@ -332,7 +332,7 @@ public:
void getHT(X &x) void getHT(X &x)
{ {
getSubHeader(); getSubHeader();
if(c.leftSub != sizeof(X)) if(mCtx.leftSub != sizeof(X))
fail("getHT(): subrecord size mismatch"); fail("getHT(): subrecord size mismatch");
getT(x); getT(x);
} }
@ -371,23 +371,23 @@ public:
// them. For some reason, they break the rules, and contain a byte // them. For some reason, they break the rules, and contain a byte
// (value 0) even if the header says there is no data. If // (value 0) even if the header says there is no data. If
// Morrowind accepts it, so should we. // Morrowind accepts it, so should we.
if(c.leftSub == 0) if(mCtx.leftSub == 0)
{ {
// Skip the following zero byte // Skip the following zero byte
c.leftRec--; mCtx.leftRec--;
char c; char c;
esm->read(&c,1); mEsm->read(&c,1);
return ""; return "";
} }
return getString(c.leftSub); return getString(mCtx.leftSub);
} }
// Read the given number of bytes from a subrecord // Read the given number of bytes from a subrecord
void getHExact(void*p, int size) void getHExact(void*p, int size)
{ {
getSubHeader(); getSubHeader();
if(size !=static_cast<int> (c.leftSub)) if(size !=static_cast<int> (mCtx.leftSub))
fail("getHExact() size mismatch"); fail("getHExact() size mismatch");
getExact(p,size); getExact(p,size);
} }
@ -409,8 +409,8 @@ public:
void getSubNameIs(const char* name) void getSubNameIs(const char* name)
{ {
getSubName(); getSubName();
if(c.subName != name) if(mCtx.subName != name)
fail("Expected subrecord " + std::string(name) + " but got " + c.subName.toString()); fail("Expected subrecord " + std::string(name) + " but got " + mCtx.subName.toString());
} }
/** Checks if the next sub record name matches the parameter. If it /** Checks if the next sub record name matches the parameter. If it
@ -420,16 +420,16 @@ public:
*/ */
bool isNextSub(const char* name) bool isNextSub(const char* name)
{ {
if(!c.leftRec) return false; if(!mCtx.leftRec) return false;
getSubName(); getSubName();
// If the name didn't match, then mark the it as 'cached' so it's // If the name didn't match, then mark the it as 'cached' so it's
// available for the next call to getSubName. // available for the next call to getSubName.
c.subCached = (c.subName != name); mCtx.subCached = (mCtx.subName != name);
// If subCached is false, then subName == name. // If subCached is false, then subName == name.
return !c.subCached; return !mCtx.subCached;
} }
// Read subrecord name. This gets called a LOT, so I've optimized it // Read subrecord name. This gets called a LOT, so I've optimized it
@ -437,25 +437,25 @@ public:
void getSubName() void getSubName()
{ {
// If the name has already been read, do nothing // If the name has already been read, do nothing
if(c.subCached) if(mCtx.subCached)
{ {
c.subCached = false; mCtx.subCached = false;
return; return;
} }
// Don't bother with error checking, we will catch an EOF upon // Don't bother with error checking, we will catch an EOF upon
// reading the subrecord data anyway. // reading the subrecord data anyway.
esm->read(c.subName.name, 4); mEsm->read(mCtx.subName.name, 4);
c.leftRec -= 4; mCtx.leftRec -= 4;
} }
// This is specially optimized for LoadINFO. // This is specially optimized for LoadINFO.
bool isEmptyOrGetName() bool isEmptyOrGetName()
{ {
if(c.leftRec) if(mCtx.leftRec)
{ {
esm->read(c.subName.name, 4); mEsm->read(mCtx.subName.name, 4);
c.leftRec -= 4; mCtx.leftRec -= 4;
return false; return false;
} }
return true; return true;
@ -466,14 +466,14 @@ public:
void skipHSub() void skipHSub()
{ {
getSubHeader(); getSubHeader();
skip(c.leftSub); skip(mCtx.leftSub);
} }
// Skip sub record and check its size // Skip sub record and check its size
void skipHSubSize(int size) void skipHSubSize(int size)
{ {
skipHSub(); skipHSub();
if(static_cast<int> (c.leftSub) != size) if(static_cast<int> (mCtx.leftSub) != size)
fail("skipHSubSize() mismatch"); fail("skipHSubSize() mismatch");
} }
@ -482,17 +482,17 @@ public:
*/ */
void getSubHeader() void getSubHeader()
{ {
if(c.leftRec < 4) if(mCtx.leftRec < 4)
fail("End of record while reading sub-record header"); fail("End of record while reading sub-record header");
// Get subrecord size // Get subrecord size
getT(c.leftSub); getT(mCtx.leftSub);
// Adjust number of record bytes left // Adjust number of record bytes left
c.leftRec -= c.leftSub + 4; mCtx.leftRec -= mCtx.leftSub + 4;
// Check that sizes added up // Check that sizes added up
if(c.leftRec < 0) if(mCtx.leftRec < 0)
fail("Not enough bytes left in record for this subrecord."); fail("Not enough bytes left in record for this subrecord.");
} }
@ -501,7 +501,7 @@ public:
void getSubHeaderIs(int size) void getSubHeaderIs(int size)
{ {
getSubHeader(); getSubHeader();
if(size != static_cast<int> (c.leftSub)) if(size != static_cast<int> (mCtx.leftSub))
fail("getSubHeaderIs(): Sub header mismatch"); fail("getSubHeaderIs(): Sub header mismatch");
} }
@ -516,29 +516,29 @@ public:
{ {
if(!hasMoreRecs()) if(!hasMoreRecs())
fail("No more records, getRecName() failed"); fail("No more records, getRecName() failed");
getName(c.recName); getName(mCtx.recName);
c.leftFile -= 4; mCtx.leftFile -= 4;
// Make sure we don't carry over any old cached subrecord // Make sure we don't carry over any old cached subrecord
// names. This can happen in some cases when we skip parts of a // names. This can happen in some cases when we skip parts of a
// record. // record.
c.subCached = false; mCtx.subCached = false;
return c.recName; return mCtx.recName;
} }
// Skip the rest of this record. Assumes the name and header have // Skip the rest of this record. Assumes the name and header have
// already been read // already been read
void skipRecord() void skipRecord()
{ {
skip(c.leftRec); skip(mCtx.leftRec);
c.leftRec = 0; mCtx.leftRec = 0;
} }
// Skip an entire record, including the header (but not the name) // Skip an entire record, including the header (but not the name)
void skipHRecord() void skipHRecord()
{ {
if(!c.leftFile) return; if(!mCtx.leftFile) return;
getRecHeader(); getRecHeader();
skipRecord(); skipRecord();
} }
@ -551,26 +551,26 @@ public:
void getRecHeader(uint32_t &flags) void getRecHeader(uint32_t &flags)
{ {
// General error checking // General error checking
if(c.leftFile < 12) if(mCtx.leftFile < 12)
fail("End of file while reading record header"); fail("End of file while reading record header");
if(c.leftRec) if(mCtx.leftRec)
fail("Previous record contains unread bytes"); fail("Previous record contains unread bytes");
getUint(c.leftRec); getUint(mCtx.leftRec);
getUint(flags);// This header entry is always zero getUint(flags);// This header entry is always zero
getUint(flags); getUint(flags);
c.leftFile -= 12; mCtx.leftFile -= 12;
// Check that sizes add up // Check that sizes add up
if(c.leftFile < c.leftRec) if(mCtx.leftFile < mCtx.leftRec)
fail("Record size is larger than rest of file"); fail("Record size is larger than rest of file");
// Adjust number of bytes c.left in file // Adjust number of bytes mCtx.left in file
c.leftFile -= c.leftRec; mCtx.leftFile -= mCtx.leftRec;
} }
bool hasMoreRecs() { return c.leftFile > 0; } bool hasMoreRecs() { return mCtx.leftFile > 0; }
bool hasMoreSubs() { return c.leftRec > 0; } bool hasMoreSubs() { return mCtx.leftRec > 0; }
/************************************************************************* /*************************************************************************
@ -584,7 +584,7 @@ public:
void getExact(void*x, int size) void getExact(void*x, int size)
{ {
int t = esm->read(x, size); int t = mEsm->read(x, size);
if(t != size) if(t != size)
fail("Read error"); fail("Read error");
} }
@ -596,14 +596,14 @@ public:
std::string getString(int size) std::string getString(int size)
{ {
char *ptr = ToUTF8::getBuffer(size); char *ptr = ToUTF8::getBuffer(size);
esm->read(ptr,size); mEsm->read(ptr,size);
// Convert to UTF8 and return // Convert to UTF8 and return
return ToUTF8::getUtf8(ToUTF8::WINDOWS_1252); return ToUTF8::getUtf8(ToUTF8::WINDOWS_1252);
} }
void skip(int bytes) { esm->seek(esm->tell()+bytes); } void skip(int bytes) { mEsm->seek(mEsm->tell()+bytes); }
uint64_t getOffset() { return esm->tell(); } uint64_t getOffset() { return mEsm->tell(); }
/// Used for error handling /// Used for error handling
void fail(const std::string &msg) void fail(const std::string &msg)
@ -613,24 +613,24 @@ public:
stringstream ss; stringstream ss;
ss << "ESM Error: " << msg; ss << "ESM Error: " << msg;
ss << "\n File: " << c.filename; ss << "\n File: " << mCtx.filename;
ss << "\n Record: " << c.recName.toString(); ss << "\n Record: " << mCtx.recName.toString();
ss << "\n Subrecord: " << c.subName.toString(); ss << "\n Subrecord: " << mCtx.subName.toString();
if(esm != NULL) if(mEsm != NULL)
ss << "\n Offset: 0x" << hex << esm->tell(); ss << "\n Offset: 0x" << hex << mEsm->tell();
throw std::runtime_error(ss.str()); throw std::runtime_error(ss.str());
} }
private: private:
Mangle::Stream::StreamPtr esm; Mangle::Stream::StreamPtr mEsm;
ESM_Context c; ESM_Context mCtx;
// Special file signifier (see SpecialFile enum above) // Special file signifier (see SpecialFile enum above)
int spf; int mSpf;
SaveData saveData; SaveData mSaveData;
MasterList masters; MasterList mMasters;
}; };
} }
#endif #endif

Loading…
Cancel
Save