2014-08-24 13:27:09 -04:00
|
|
|
///Main header for reading .nif files
|
2010-01-04 14:48:18 +01:00
|
|
|
|
2013-02-24 13:51:56 -08:00
|
|
|
#ifndef OPENMW_COMPONENTS_NIF_NIFFILE_HPP
|
|
|
|
#define OPENMW_COMPONENTS_NIF_NIFFILE_HPP
|
2010-01-04 14:48:18 +01:00
|
|
|
|
2010-09-02 22:30:39 +02:00
|
|
|
#include <stdexcept>
|
2010-01-04 14:48:18 +01:00
|
|
|
#include <vector>
|
2014-08-24 13:27:09 -04:00
|
|
|
#include <iostream>
|
2010-01-04 14:48:18 +01:00
|
|
|
|
2015-02-17 17:08:55 +01:00
|
|
|
#include <components/files/constrainedfilestream.hpp>
|
|
|
|
|
2010-06-03 20:44:55 +02:00
|
|
|
#include "record.hpp"
|
2010-01-04 19:35:11 +01:00
|
|
|
|
2010-01-06 12:28:37 +01:00
|
|
|
namespace Nif
|
|
|
|
{
|
|
|
|
|
2010-01-04 14:48:18 +01:00
|
|
|
class NIFFile
|
|
|
|
{
|
2012-07-02 21:41:21 -07:00
|
|
|
enum NIFVersion {
|
|
|
|
VER_MW = 0x04000002 // Morrowind NIFs
|
2010-01-04 14:48:18 +01:00
|
|
|
};
|
|
|
|
|
2012-07-02 21:41:21 -07:00
|
|
|
/// Nif file version
|
2014-10-19 02:54:27 -04:00
|
|
|
unsigned int ver;
|
2010-01-04 14:48:18 +01:00
|
|
|
|
2014-08-24 13:27:09 -04:00
|
|
|
/// File name, used for error messages and opening the file
|
2012-07-02 21:41:21 -07:00
|
|
|
std::string filename;
|
2010-01-04 14:48:18 +01:00
|
|
|
|
2012-07-02 21:41:21 -07:00
|
|
|
/// Record list
|
|
|
|
std::vector<Record*> records;
|
2010-01-04 14:48:18 +01:00
|
|
|
|
2014-08-24 13:27:09 -04:00
|
|
|
/// Root list. This is a select portion of the pointers from records
|
2013-04-06 10:17:09 -07:00
|
|
|
std::vector<Record*> roots;
|
|
|
|
|
2015-03-25 15:39:41 +01:00
|
|
|
bool mUseSkinning;
|
|
|
|
|
2012-07-02 21:41:21 -07:00
|
|
|
/// Parse the file
|
|
|
|
void parse();
|
2010-01-07 19:11:03 +01:00
|
|
|
|
2014-10-19 02:54:27 -04:00
|
|
|
/// 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);
|
|
|
|
|
2014-08-24 13:27:09 -04:00
|
|
|
///Private Copy Constructor
|
2013-01-05 10:58:50 -08:00
|
|
|
NIFFile (NIFFile const &);
|
2014-08-24 13:27:09 -04:00
|
|
|
///\overload
|
2013-01-05 10:58:50 -08:00
|
|
|
void operator = (NIFFile const &);
|
|
|
|
|
2015-02-17 17:08:55 +01:00
|
|
|
Files::IStreamPtr mStream;
|
|
|
|
|
2012-07-02 21:41:21 -07:00
|
|
|
public:
|
2014-08-24 13:27:09 -04:00
|
|
|
/// Used if file parsing fails
|
2012-07-02 21:41:21 -07:00
|
|
|
void fail(const std::string &msg)
|
2010-01-04 14:48:18 +01:00
|
|
|
{
|
2014-12-12 01:36:10 -05:00
|
|
|
std::string err = " NIFFile Error: " + msg;
|
2012-07-02 21:41:21 -07:00
|
|
|
err += "\nFile: " + filename;
|
|
|
|
throw std::runtime_error(err);
|
2010-01-04 14:48:18 +01:00
|
|
|
}
|
2014-08-24 13:27:09 -04:00
|
|
|
/// Used when something goes wrong, but not catastrophically so
|
2012-07-12 06:47:38 -07:00
|
|
|
void warn(const std::string &msg)
|
|
|
|
{
|
2014-12-12 01:36:10 -05:00
|
|
|
std::cerr << " NIFFile Warning: " << msg <<std::endl
|
2013-01-05 13:03:05 -08:00
|
|
|
<< "File: " << filename <<std::endl;
|
2012-07-12 06:47:38 -07:00
|
|
|
}
|
|
|
|
|
2015-02-17 17:08:55 +01:00
|
|
|
/// Open a NIF stream. The name is used for error messages.
|
|
|
|
NIFFile(Files::IStreamPtr stream, const std::string &name);
|
2013-01-05 10:58:50 -08:00
|
|
|
~NIFFile();
|
|
|
|
|
2012-07-02 21:41:21 -07:00
|
|
|
/// Get a given record
|
2014-06-05 18:53:12 +04:00
|
|
|
Record *getRecord(size_t index) const
|
2012-07-02 21:41:21 -07:00
|
|
|
{
|
|
|
|
Record *res = records.at(index);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
/// Number of records
|
2014-06-05 18:53:12 +04:00
|
|
|
size_t numRecords() const { return records.size(); }
|
2013-04-06 10:17:09 -07:00
|
|
|
|
|
|
|
/// Get a given root
|
2014-06-05 18:53:12 +04:00
|
|
|
Record *getRoot(size_t index=0) const
|
2013-04-06 10:17:09 -07:00
|
|
|
{
|
|
|
|
Record *res = roots.at(index);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
/// Number of roots
|
2014-06-05 18:53:12 +04:00
|
|
|
size_t numRoots() const { return roots.size(); }
|
2014-10-19 02:40:18 -04:00
|
|
|
|
2015-03-25 15:39:41 +01:00
|
|
|
/// Set whether there is skinning contained in this NIF file.
|
|
|
|
/// @note This is just a hint for users of the NIF file and has no effect on the loading procedure.
|
|
|
|
void setUseSkinning(bool skinning);
|
|
|
|
|
|
|
|
bool getUseSkinning() const;
|
|
|
|
|
2014-10-19 02:40:18 -04:00
|
|
|
/// Get the name of the file
|
|
|
|
std::string getFilename(){ return filename; }
|
2010-01-04 14:48:18 +01:00
|
|
|
};
|
2015-04-25 01:28:01 +02:00
|
|
|
typedef boost::shared_ptr<Nif::NIFFile> NIFFilePtr;
|
2010-01-06 12:28:37 +01:00
|
|
|
|
2012-07-12 06:47:38 -07:00
|
|
|
|
|
|
|
|
2010-01-06 12:28:37 +01:00
|
|
|
} // Namespace
|
2010-01-04 14:48:18 +01:00
|
|
|
#endif
|