mirror of https://github.com/OpenMW/openmw.git
Started porting NIF records from D.
parent
f1d40fdf32
commit
2d92d39f05
@ -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 (controlled.h) 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/ .
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _NIF_CONTROLLED_H_
|
||||||
|
#define _NIF_CONTROLLED_H_
|
||||||
|
|
||||||
|
#include "extra.h"
|
||||||
|
|
||||||
|
namespace Nif
|
||||||
|
{
|
||||||
|
|
||||||
|
/// Anything that has a controller
|
||||||
|
struct Controlled : Extra
|
||||||
|
{
|
||||||
|
ControllerPtr controller;
|
||||||
|
|
||||||
|
void read(NIFFile *nif)
|
||||||
|
{
|
||||||
|
Extra::read(nif);
|
||||||
|
controller.read(nif);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/// Has name, extra-data and controller
|
||||||
|
struct Named : Controlled
|
||||||
|
{
|
||||||
|
SString name;
|
||||||
|
|
||||||
|
void read(NIFFile *nif)
|
||||||
|
{
|
||||||
|
name = nif->getString();
|
||||||
|
Controlled::read(nif);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // Namespace
|
||||||
|
#endif
|
@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
OpenMW - The completely unofficial reimplementation of Morrowind
|
||||||
|
Copyright (C) 2008-2010 Nicolay Korslund
|
||||||
|
Email: < korslund@gmail.com >
|
||||||
|
WWW: http://openmw.sourceforge.net/
|
||||||
|
|
||||||
|
This file (extra.h) 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/ .
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _NIF_EXTRA_H_
|
||||||
|
#define _NIF_EXTRA_H_
|
||||||
|
|
||||||
|
#include "record.h"
|
||||||
|
#include "nif_file.h"
|
||||||
|
#include "record_ptr.h"
|
||||||
|
|
||||||
|
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
|
||||||
|
*/
|
||||||
|
struct Extra : Record
|
||||||
|
{
|
||||||
|
ExtraPtr extra;
|
||||||
|
|
||||||
|
void read(NIFFile *nif) { extra.read(nif); }
|
||||||
|
};
|
||||||
|
|
||||||
|
} // Namespace
|
||||||
|
#endif
|
@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
OpenMW - The completely unofficial reimplementation of Morrowind
|
||||||
|
Copyright (C) 2008-2010 Nicolay Korslund
|
||||||
|
Email: < korslund@gmail.com >
|
||||||
|
WWW: http://openmw.sourceforge.net/
|
||||||
|
|
||||||
|
This file (node.h) 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/ .
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _NIF_NODE_H_
|
||||||
|
#define _NIF_NODE_H_
|
||||||
|
|
||||||
|
#include "controlled.h"
|
||||||
|
|
||||||
|
namespace Nif
|
||||||
|
{
|
||||||
|
|
||||||
|
/** A Node is an object that's part of the main NIF tree. It has
|
||||||
|
parent node (unless it's the root), and transformation (location
|
||||||
|
and rotation) relative to it's parent.
|
||||||
|
*/
|
||||||
|
struct Node : Named
|
||||||
|
{
|
||||||
|
// Not done
|
||||||
|
|
||||||
|
void read(NIFFile *nif)
|
||||||
|
{
|
||||||
|
Named::read(nif);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // Namespace
|
||||||
|
#endif
|
@ -0,0 +1,88 @@
|
|||||||
|
/*
|
||||||
|
OpenMW - The completely unofficial reimplementation of Morrowind
|
||||||
|
Copyright (C) 2008-2010 Nicolay Korslund
|
||||||
|
Email: < korslund@gmail.com >
|
||||||
|
WWW: http://openmw.sourceforge.net/
|
||||||
|
|
||||||
|
This file (record_ptr.h) 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/ .
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _NIF_RECORD_PTR_H_
|
||||||
|
#define _NIF_RECORD_PTR_H_
|
||||||
|
|
||||||
|
#include "nif_file.h"
|
||||||
|
|
||||||
|
namespace Nif
|
||||||
|
{
|
||||||
|
template <class X>
|
||||||
|
class RecordPtrT
|
||||||
|
{
|
||||||
|
int index;
|
||||||
|
X* ptr;
|
||||||
|
NIFFile *nif;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
RecordPtrT() : index(-2), ptr(NULL) {}
|
||||||
|
|
||||||
|
/// Read the index from the nif
|
||||||
|
void read(NIFFile *_nif)
|
||||||
|
{
|
||||||
|
// Can only read the index once
|
||||||
|
assert(index == -2);
|
||||||
|
|
||||||
|
// Store the NIFFile pointer for later
|
||||||
|
nif = _nif;
|
||||||
|
|
||||||
|
// And the index, of course
|
||||||
|
index = nif->getInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Look up the actual object from the index
|
||||||
|
X* operator->()
|
||||||
|
{
|
||||||
|
// Have we found the pointer already?
|
||||||
|
if(ptr == NULL)
|
||||||
|
{
|
||||||
|
// Get the record
|
||||||
|
assert(index >= 0);
|
||||||
|
Record *r = nif->getRecord(index);
|
||||||
|
|
||||||
|
// And cast it
|
||||||
|
ptr = dynamic_cast<X*>(r);
|
||||||
|
assert(ptr != NULL);
|
||||||
|
}
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Pointers are allowed to be empty
|
||||||
|
bool empty() { return index == -1; }
|
||||||
|
|
||||||
|
int getIndex() { return index; }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class Extra;
|
||||||
|
class Controller;
|
||||||
|
class Node;
|
||||||
|
|
||||||
|
typedef RecordPtrT<Extra> ExtraPtr;
|
||||||
|
typedef RecordPtrT<Controller> ControllerPtr;
|
||||||
|
typedef RecordPtrT<Node> NodePtr;
|
||||||
|
|
||||||
|
} // Namespace
|
||||||
|
#endif
|
Loading…
Reference in New Issue