mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-21 10:23:56 +00:00
Merge remote-tracking branch 'emperorarthur/nif-cleanup'
This commit is contained in:
commit
154cac506c
11 changed files with 180 additions and 143 deletions
|
@ -19,7 +19,7 @@ add_component_dir (bsa
|
|||
)
|
||||
|
||||
add_component_dir (nif
|
||||
controlled effect niftypes record controller extra node record_ptr data niffile property nifkey data node
|
||||
controlled effect niftypes record controller extra node record_ptr data niffile property nifkey data node base
|
||||
)
|
||||
|
||||
add_component_dir (nifcache
|
||||
|
|
91
components/nif/base.hpp
Normal file
91
components/nif/base.hpp
Normal file
|
@ -0,0 +1,91 @@
|
|||
///This file holds the main classes of NIF Records used by everything else.
|
||||
#ifndef OPENMW_COMPONENTS_NIF_BASE_HPP
|
||||
#define OPENMW_COMPONENTS_NIF_BASE_HPP
|
||||
|
||||
#include "record.hpp"
|
||||
#include "niffile.hpp"
|
||||
#include "recordptr.hpp"
|
||||
#include "nifstream.hpp"
|
||||
#include "nifkey.hpp"
|
||||
|
||||
namespace Nif
|
||||
{
|
||||
/** A record that can have extra data. The extra data objects
|
||||
themselves descend from the Extra class, and all the extra data
|
||||
connected to an object form a linked list
|
||||
*/
|
||||
class Extra : public Record
|
||||
{
|
||||
public:
|
||||
ExtraPtr extra;
|
||||
|
||||
void read(NIFStream *nif) { extra.read(nif); }
|
||||
void post(NIFFile *nif) { extra.post(nif); }
|
||||
};
|
||||
|
||||
class Controller : public Record
|
||||
{
|
||||
public:
|
||||
ControllerPtr next;
|
||||
int flags;
|
||||
float frequency, phase;
|
||||
float timeStart, timeStop;
|
||||
ControlledPtr target;
|
||||
|
||||
void read(NIFStream *nif)
|
||||
{
|
||||
next.read(nif);
|
||||
|
||||
flags = nif->getUShort();
|
||||
|
||||
frequency = nif->getFloat();
|
||||
phase = nif->getFloat();
|
||||
timeStart = nif->getFloat();
|
||||
timeStop = nif->getFloat();
|
||||
|
||||
target.read(nif);
|
||||
}
|
||||
|
||||
void post(NIFFile *nif)
|
||||
{
|
||||
Record::post(nif);
|
||||
next.post(nif);
|
||||
target.post(nif);
|
||||
}
|
||||
};
|
||||
|
||||
/// Anything that has a controller
|
||||
class Controlled : public Extra
|
||||
{
|
||||
public:
|
||||
ControllerPtr controller;
|
||||
|
||||
void read(NIFStream *nif)
|
||||
{
|
||||
Extra::read(nif);
|
||||
controller.read(nif);
|
||||
}
|
||||
|
||||
void post(NIFFile *nif)
|
||||
{
|
||||
Extra::post(nif);
|
||||
controller.post(nif);
|
||||
}
|
||||
};
|
||||
|
||||
/// Has name, extra-data and controller
|
||||
class Named : public Controlled
|
||||
{
|
||||
public:
|
||||
std::string name;
|
||||
|
||||
void read(NIFStream *nif)
|
||||
{
|
||||
name = nif->getString();
|
||||
Controlled::read(nif);
|
||||
}
|
||||
};
|
||||
typedef Named NiSequenceStreamHelper;
|
||||
|
||||
} // Namespace
|
||||
#endif
|
|
@ -24,45 +24,71 @@
|
|||
#ifndef OPENMW_COMPONENTS_NIF_CONTROLLED_HPP
|
||||
#define OPENMW_COMPONENTS_NIF_CONTROLLED_HPP
|
||||
|
||||
#include "extra.hpp"
|
||||
#include "controller.hpp"
|
||||
#include "base.hpp"
|
||||
|
||||
namespace Nif
|
||||
{
|
||||
|
||||
/// Anything that has a controller
|
||||
class Controlled : public Extra
|
||||
class NiSourceTexture : public Named
|
||||
{
|
||||
public:
|
||||
ControllerPtr controller;
|
||||
// Is this an external (references a separate texture file) or
|
||||
// internal (data is inside the nif itself) texture?
|
||||
bool external;
|
||||
|
||||
std::string filename; // In case of external textures
|
||||
NiPixelDataPtr data; // In case of internal textures
|
||||
|
||||
/* Pixel layout
|
||||
0 - Palettised
|
||||
1 - High color 16
|
||||
2 - True color 32
|
||||
3 - Compressed
|
||||
4 - Bumpmap
|
||||
5 - Default */
|
||||
int pixel;
|
||||
|
||||
/* Mipmap format
|
||||
0 - no
|
||||
1 - yes
|
||||
2 - default */
|
||||
int mipmap;
|
||||
|
||||
/* Alpha
|
||||
0 - none
|
||||
1 - binary
|
||||
2 - smooth
|
||||
3 - default (use material alpha, or multiply material with texture if present)
|
||||
*/
|
||||
int alpha;
|
||||
|
||||
void read(NIFStream *nif)
|
||||
{
|
||||
Extra::read(nif);
|
||||
controller.read(nif);
|
||||
Named::read(nif);
|
||||
|
||||
external = !!nif->getChar();
|
||||
if(external)
|
||||
filename = nif->getString();
|
||||
else
|
||||
{
|
||||
nif->getChar(); // always 1
|
||||
data.read(nif);
|
||||
}
|
||||
|
||||
pixel = nif->getInt();
|
||||
mipmap = nif->getInt();
|
||||
alpha = nif->getInt();
|
||||
|
||||
nif->getChar(); // always 1
|
||||
}
|
||||
|
||||
void post(NIFFile *nif)
|
||||
{
|
||||
Extra::post(nif);
|
||||
controller.post(nif);
|
||||
Named::post(nif);
|
||||
data.post(nif);
|
||||
}
|
||||
};
|
||||
|
||||
/// Has name, extra-data and controller
|
||||
class Named : public Controlled
|
||||
{
|
||||
public:
|
||||
std::string name;
|
||||
|
||||
void read(NIFStream *nif)
|
||||
{
|
||||
name = nif->getString();
|
||||
Controlled::read(nif);
|
||||
}
|
||||
};
|
||||
typedef Named NiSequenceStreamHelper;
|
||||
|
||||
class NiParticleGrowFade : public Controlled
|
||||
{
|
||||
public:
|
||||
|
@ -147,5 +173,7 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // Namespace
|
||||
#endif
|
||||
|
|
|
@ -24,44 +24,11 @@
|
|||
#ifndef OPENMW_COMPONENTS_NIF_CONTROLLER_HPP
|
||||
#define OPENMW_COMPONENTS_NIF_CONTROLLER_HPP
|
||||
|
||||
#include "record.hpp"
|
||||
#include "niffile.hpp"
|
||||
#include "recordptr.hpp"
|
||||
#include "base.hpp"
|
||||
|
||||
namespace Nif
|
||||
{
|
||||
|
||||
class Controller : public Record
|
||||
{
|
||||
public:
|
||||
ControllerPtr next;
|
||||
int flags;
|
||||
float frequency, phase;
|
||||
float timeStart, timeStop;
|
||||
ControlledPtr target;
|
||||
|
||||
void read(NIFStream *nif)
|
||||
{
|
||||
next.read(nif);
|
||||
|
||||
flags = nif->getUShort();
|
||||
|
||||
frequency = nif->getFloat();
|
||||
phase = nif->getFloat();
|
||||
timeStart = nif->getFloat();
|
||||
timeStop = nif->getFloat();
|
||||
|
||||
target.read(nif);
|
||||
}
|
||||
|
||||
void post(NIFFile *nif)
|
||||
{
|
||||
Record::post(nif);
|
||||
next.post(nif);
|
||||
target.post(nif);
|
||||
}
|
||||
};
|
||||
|
||||
class NiParticleSystemController : public Controller
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -24,73 +24,11 @@
|
|||
#ifndef OPENMW_COMPONENTS_NIF_DATA_HPP
|
||||
#define OPENMW_COMPONENTS_NIF_DATA_HPP
|
||||
|
||||
#include "controlled.hpp"
|
||||
#include "nifstream.hpp"
|
||||
#include "nifkey.hpp"
|
||||
#include "base.hpp"
|
||||
|
||||
namespace Nif
|
||||
{
|
||||
|
||||
class NiSourceTexture : public Named
|
||||
{
|
||||
public:
|
||||
// Is this an external (references a separate texture file) or
|
||||
// internal (data is inside the nif itself) texture?
|
||||
bool external;
|
||||
|
||||
std::string filename; // In case of external textures
|
||||
NiPixelDataPtr data; // In case of internal textures
|
||||
|
||||
/* Pixel layout
|
||||
0 - Palettised
|
||||
1 - High color 16
|
||||
2 - True color 32
|
||||
3 - Compressed
|
||||
4 - Bumpmap
|
||||
5 - Default */
|
||||
int pixel;
|
||||
|
||||
/* Mipmap format
|
||||
0 - no
|
||||
1 - yes
|
||||
2 - default */
|
||||
int mipmap;
|
||||
|
||||
/* Alpha
|
||||
0 - none
|
||||
1 - binary
|
||||
2 - smooth
|
||||
3 - default (use material alpha, or multiply material with texture if present)
|
||||
*/
|
||||
int alpha;
|
||||
|
||||
void read(NIFStream *nif)
|
||||
{
|
||||
Named::read(nif);
|
||||
|
||||
external = !!nif->getChar();
|
||||
if(external)
|
||||
filename = nif->getString();
|
||||
else
|
||||
{
|
||||
nif->getChar(); // always 1
|
||||
data.read(nif);
|
||||
}
|
||||
|
||||
pixel = nif->getInt();
|
||||
mipmap = nif->getInt();
|
||||
alpha = nif->getInt();
|
||||
|
||||
nif->getChar(); // always 1
|
||||
}
|
||||
|
||||
void post(NIFFile *nif)
|
||||
{
|
||||
Named::post(nif);
|
||||
data.post(nif);
|
||||
}
|
||||
};
|
||||
|
||||
// Common ancestor for several data classes
|
||||
class ShapeData : public Record
|
||||
{
|
||||
|
|
|
@ -24,26 +24,11 @@
|
|||
#ifndef OPENMW_COMPONENTS_NIF_EXTRA_HPP
|
||||
#define OPENMW_COMPONENTS_NIF_EXTRA_HPP
|
||||
|
||||
#include "record.hpp"
|
||||
#include "niffile.hpp"
|
||||
#include "recordptr.hpp"
|
||||
#include "base.hpp"
|
||||
|
||||
namespace Nif
|
||||
{
|
||||
|
||||
/** A record that can have extra data. The extra data objects
|
||||
themselves decend from the Extra class, and all the extra data
|
||||
connected to an object form a linked list
|
||||
*/
|
||||
class Extra : public Record
|
||||
{
|
||||
public:
|
||||
ExtraPtr extra;
|
||||
|
||||
void read(NIFStream *nif) { extra.read(nif); }
|
||||
void post(NIFFile *nif) { extra.post(nif); }
|
||||
};
|
||||
|
||||
class NiVertWeightsExtraData : public Extra
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -109,6 +109,23 @@ static std::map<std::string,RecordFactoryEntry> makeFactory()
|
|||
///Make the factory map used for parsing the file
|
||||
static const std::map<std::string,RecordFactoryEntry> factories = makeFactory();
|
||||
|
||||
/// Get the file's version in a human readable form
|
||||
std::string NIFFile::printVersion(unsigned int version)
|
||||
{
|
||||
union ver_quad
|
||||
{
|
||||
uint32_t full;
|
||||
uint8_t quad[4];
|
||||
} version_out;
|
||||
|
||||
version_out.full = version;
|
||||
|
||||
return Ogre::StringConverter::toString(version_out.quad[3])
|
||||
+"." + Ogre::StringConverter::toString(version_out.quad[2])
|
||||
+"." + Ogre::StringConverter::toString(version_out.quad[1])
|
||||
+"." + Ogre::StringConverter::toString(version_out.quad[0]);
|
||||
}
|
||||
|
||||
void NIFFile::parse()
|
||||
{
|
||||
NIFStream nif (this, Ogre::ResourceGroupManager::getSingleton().openResource(filename));
|
||||
|
@ -119,10 +136,9 @@ void NIFFile::parse()
|
|||
fail("Invalid NIF header");
|
||||
|
||||
// Get BCD version
|
||||
ver = nif.getInt();
|
||||
ver = nif.getUInt();
|
||||
if(ver != VER_MW)
|
||||
fail("Unsupported NIF version");
|
||||
|
||||
fail("Unsupported NIF version: " + printVersion(ver));
|
||||
// Number of records
|
||||
size_t recNum = nif.getInt();
|
||||
records.resize(recNum);
|
||||
|
|
|
@ -19,7 +19,7 @@ class NIFFile
|
|||
};
|
||||
|
||||
/// Nif file version
|
||||
int ver;
|
||||
unsigned int ver;
|
||||
|
||||
/// File name, used for error messages and opening the file
|
||||
std::string filename;
|
||||
|
@ -33,6 +33,10 @@ class NIFFile
|
|||
/// Parse the file
|
||||
void parse();
|
||||
|
||||
/// Get the file's version in a human readable form
|
||||
///\returns A string containing a human readable NIF version number
|
||||
std::string printVersion(unsigned int version);
|
||||
|
||||
///Private Copy Constructor
|
||||
NIFFile (NIFFile const &);
|
||||
///\overload
|
||||
|
@ -74,6 +78,9 @@ public:
|
|||
}
|
||||
/// Number of roots
|
||||
size_t numRoots() const { return roots.size(); }
|
||||
|
||||
/// Get the name of the file
|
||||
std::string getFilename(){ return filename; }
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include <OgreVector4.h>
|
||||
#include <OgreMatrix3.h>
|
||||
#include <OgreQuaternion.h>
|
||||
#include <OgreStringConverter.h>
|
||||
|
||||
#include "niftypes.hpp"
|
||||
|
||||
|
@ -142,7 +143,8 @@ public:
|
|||
std::vector<char> str (length+1, 0);
|
||||
|
||||
if(inp->read(&str[0], length) != length)
|
||||
throw std::runtime_error ("string length in NIF file does not match");
|
||||
throw std::runtime_error (": String length in NIF file "+ file->getFilename() +" does not match! Expected length: "
|
||||
+ Ogre::StringConverter::toString(length));
|
||||
|
||||
return &str[0];
|
||||
}
|
||||
|
|
|
@ -4,9 +4,12 @@
|
|||
#include <OgreMatrix4.h>
|
||||
|
||||
#include "controlled.hpp"
|
||||
#include "extra.hpp"
|
||||
#include "data.hpp"
|
||||
#include "property.hpp"
|
||||
#include "niftypes.hpp"
|
||||
#include "controller.hpp"
|
||||
#include "base.hpp"
|
||||
|
||||
namespace Nif
|
||||
{
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
#ifndef OPENMW_COMPONENTS_NIF_PROPERTY_HPP
|
||||
#define OPENMW_COMPONENTS_NIF_PROPERTY_HPP
|
||||
|
||||
#include "controlled.hpp"
|
||||
#include "base.hpp"
|
||||
|
||||
namespace Nif
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue