mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-19 21:23:52 +00:00
Split nif_file in h/cpp
This commit is contained in:
parent
769eae99b3
commit
6a34b0f2bf
3 changed files with 59 additions and 34 deletions
57
nif/nif_file.cpp
Normal file
57
nif/nif_file.cpp
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
/*
|
||||||
|
OpenMW - The completely unofficial reimplementation of Morrowind
|
||||||
|
Copyright (C) 2008-2010 Nicolay Korslund
|
||||||
|
Email: < korslund@gmail.com >
|
||||||
|
WWW: http://openmw.sourceforge.net/
|
||||||
|
|
||||||
|
This file (nif_file.cpp) is part of the OpenMW package.
|
||||||
|
|
||||||
|
OpenMW is distributed as free software: you can redistribute it
|
||||||
|
and/or modify it under the terms of the GNU General Public License
|
||||||
|
version 3, as published by the Free Software Foundation.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful, but
|
||||||
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
version 3 along with this program. If not, see
|
||||||
|
http://www.gnu.org/licenses/ .
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "nif_file.h"
|
||||||
|
|
||||||
|
#include "../tools/stringops.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
void NIFFile::parse()
|
||||||
|
{
|
||||||
|
// Check the header string
|
||||||
|
const char* head = getString(40);
|
||||||
|
if(!begins(head, "NetImmerse File Format"))
|
||||||
|
fail("Invalid NIF header");
|
||||||
|
|
||||||
|
// Get BCD version
|
||||||
|
ver = getInt();
|
||||||
|
if(ver != VER_MW)
|
||||||
|
fail("Unsupported NIF version");
|
||||||
|
|
||||||
|
// Number of records
|
||||||
|
int recNum = getInt();
|
||||||
|
records.resize(recNum);
|
||||||
|
|
||||||
|
for(int i=0;i<recNum;i++)
|
||||||
|
{
|
||||||
|
SString rec = getString();
|
||||||
|
|
||||||
|
cout << i << ": " << rec.toString() << endl;
|
||||||
|
|
||||||
|
if(rec == "NiNode") cout << " got a node!\n";
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
|
@ -28,14 +28,9 @@
|
||||||
#include "../mangle/stream/stream.h"
|
#include "../mangle/stream/stream.h"
|
||||||
#include "../mangle/stream/filters/buffer_stream.h"
|
#include "../mangle/stream/filters/buffer_stream.h"
|
||||||
#include "../mangle/tools/str_exception.h"
|
#include "../mangle/tools/str_exception.h"
|
||||||
#include "../tools/stringops.h"
|
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
// Only used during development. Remove later.
|
|
||||||
#include <iostream>
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
using namespace Mangle::Stream;
|
using namespace Mangle::Stream;
|
||||||
|
|
||||||
// A simple array implementation containing a pointer and a
|
// A simple array implementation containing a pointer and a
|
||||||
|
@ -105,33 +100,7 @@ class NIFFile
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parse the file
|
/// Parse the file
|
||||||
void parse()
|
void parse();
|
||||||
{
|
|
||||||
// Check the header string
|
|
||||||
const char* head = getString(40);
|
|
||||||
if(!begins(head, "NetImmerse File Format"))
|
|
||||||
fail("Invalid NIF header");
|
|
||||||
|
|
||||||
// Get BCD version
|
|
||||||
ver = getInt();
|
|
||||||
if(ver != VER_MW)
|
|
||||||
fail("Unsupported NIF version");
|
|
||||||
|
|
||||||
// Number of records
|
|
||||||
int recNum = getInt();
|
|
||||||
records.resize(recNum);
|
|
||||||
|
|
||||||
for(int i=0;i<recNum;i++)
|
|
||||||
{
|
|
||||||
SString rec = getString();
|
|
||||||
|
|
||||||
cout << i << ": " << rec.toString() << endl;
|
|
||||||
|
|
||||||
if(rec == "NiNode") cout << " got a node!\n";
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// Open a NIF stream. The name is used for error messages.
|
/// Open a NIF stream. The name is used for error messages.
|
||||||
|
@ -176,5 +145,4 @@ class NIFFile
|
||||||
const char *getString(int size)
|
const char *getString(int size)
|
||||||
{ return (const char*)inp->getPtr(size); }
|
{ return (const char*)inp->getPtr(size); }
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -3,7 +3,7 @@ GCC=g++
|
||||||
all: niftool
|
all: niftool
|
||||||
|
|
||||||
niftool: niftool.cpp ../nif_file.h
|
niftool: niftool.cpp ../nif_file.h
|
||||||
$(GCC) $< ../../tools/stringops.cpp -o $@
|
$(GCC) $< ../nif_file.cpp ../../tools/stringops.cpp -o $@
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm niftool
|
rm niftool
|
||||||
|
|
Loading…
Reference in a new issue