Skip to content

Commit

Permalink
GRAPHICS: Move createNode() into class Model
Browse files Browse the repository at this point in the history
  • Loading branch information
DrMcCoy committed Mar 20, 2014
1 parent f8c472f commit 4027c00
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 37 deletions.
29 changes: 29 additions & 0 deletions src/graphics/aurora/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,35 @@ void Model::showBoundingBox(bool show) {
}
}

void Model::createNode(NodeEntity *&nodeEntity, State *state, Common::UString name, Ogre::SceneNode *parent) {
if (name.empty())
name = Common::generateIDRandomString();

// Create a node entitiy in this state
std::pair<NodeEntities::iterator, bool> node = state->nodeEntities.insert(std::make_pair(name, NodeEntity()));
nodeEntity = &node.first->second;

// Copy the SceneNode from the root state if it exists
NodeEntities::iterator rootNodeEntity = _states[""]->nodeEntities.find(name);
if (rootNodeEntity != _states[""]->nodeEntities.end())
nodeEntity->node = rootNodeEntity->second.node;

// If we don't have a SceneNode now, create a new one
if (!nodeEntity->node) {
nodeEntity->node = parent->createChildSceneNode();
nodeEntity->node->setVisible(false);
}

// If this node doesn't exist in the root state, create it
if (rootNodeEntity ==_states[""]->nodeEntities.end()) {
std::pair<NodeEntities::iterator, bool> newRootNode;
newRootNode = _states[""]->nodeEntities.insert(std::make_pair(name, NodeEntity()));

newRootNode.first->second.node = nodeEntity->node;
newRootNode.first->second.dontRender = true;
}
}

Ogre::Entity *Model::createEntity(const VertexDeclaration &vertexDecl, const Ogre::MaterialPtr &material) {
// Create a mesh according to the vertex declaration

Expand Down
1 change: 1 addition & 0 deletions src/graphics/aurora/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ class Model : public Renderable {

// General loading helpers

void createNode(NodeEntity *&nodeEntity, State *state, Common::UString name, Ogre::SceneNode *parent);
Ogre::Entity *createEntity(const VertexDeclaration &vertexDecl, const Ogre::MaterialPtr &material);

static void readValue(Common::SeekableReadStream &stream, uint32 &value);
Expand Down
19 changes: 1 addition & 18 deletions src/graphics/aurora/model_kotor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,23 +229,6 @@ void Model_KotOR::load(ParserContext &ctx) {
loadNode(ctx, _rootNode);
}

void Model_KotOR::createNode(ParserContext &ctx, Common::UString name, Ogre::SceneNode *parent) {
if (name.empty())
name = Common::generateIDRandomString();

std::pair<NodeEntities::iterator, bool> node = ctx.state->nodeEntities.insert(std::make_pair(name, NodeEntity()));
ctx.nodeEntity = &node.first->second;

NodeEntities::iterator rootNodeEntity = _states[""]->nodeEntities.find(name);
if (rootNodeEntity != _states[""]->nodeEntities.end())
ctx.nodeEntity->node = rootNodeEntity->second.node;

if (!ctx.nodeEntity->node)
ctx.nodeEntity->node = parent->createChildSceneNode();

ctx.nodeEntity->node->setVisible(false);
}

void Model_KotOR::loadNode(ParserContext &ctx, Ogre::SceneNode *parent) {
uint16 flags = ctx.mdl->readUint16LE();
uint16 superNode = ctx.mdl->readUint16LE();
Expand All @@ -257,7 +240,7 @@ void Model_KotOR::loadNode(ParserContext &ctx, Ogre::SceneNode *parent) {

debugC(5, kDebugGraphics, "Node \"%s\" in state \"%s\"", name.c_str(), ctx.state->name.c_str());

createNode(ctx, name, parent);
createNode(ctx.nodeEntity, ctx.state, name, parent);

ctx.mdl->skip(6 + 4); // Unknown + parent pointer

Expand Down
2 changes: 0 additions & 2 deletions src/graphics/aurora/model_kotor.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ class Model_KotOR : public Model {
void readMesh(ParserContext &ctx);
void readNodeControllers(ParserContext &ctx, uint32 offset, uint32 count, std::vector<float> &data);

void createNode(ParserContext &ctx, Common::UString name, Ogre::SceneNode *parent);

static void readStrings(Common::SeekableReadStream &mdl, const std::vector<uint32> &offsets,
uint32 offset, std::vector<Common::UString> &strings);
};
Expand Down
18 changes: 2 additions & 16 deletions src/graphics/aurora/model_nwn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,20 +352,6 @@ void Model_NWN::loadASCII(ParserContext &ctx) {
// TODO: Animations / states
}

void Model_NWN::createNode(ParserContext &ctx, const Common::UString &name, Ogre::SceneNode *parent) {
std::pair<NodeEntities::iterator, bool> node = ctx.state->nodeEntities.insert(std::make_pair(name, NodeEntity()));
ctx.nodeEntity = &node.first->second;

NodeEntities::iterator rootNodeEntity = _states[""]->nodeEntities.find(name);
if (rootNodeEntity != _states[""]->nodeEntities.end())
ctx.nodeEntity->node = rootNodeEntity->second.node;

if (!ctx.nodeEntity->node)
ctx.nodeEntity->node = parent->createChildSceneNode();

ctx.nodeEntity->node->setVisible(false);
}

void Model_NWN::loadBinaryNode(ParserContext &ctx, Ogre::SceneNode *parent) {
ctx.mdl->skip(24); // Function pointers

Expand All @@ -377,7 +363,7 @@ void Model_NWN::loadBinaryNode(ParserContext &ctx, Ogre::SceneNode *parent) {

debugC(5, kDebugGraphics, "Node \"%s\" in state \"%s\"", name.c_str(), ctx.state->name.c_str());

createNode(ctx, name, parent);
createNode(ctx.nodeEntity, ctx.state, name, parent);

ctx.mdl->skip(8); // Parent pointers

Expand Down Expand Up @@ -999,7 +985,7 @@ void Model_NWN::loadASCIINode(ParserContext &ctx, Ogre::SceneNode *parent,
name.c_str(), parentName.c_str());
}

createNode(ctx, name, parent);
createNode(ctx.nodeEntity, ctx.state, name, parent);

ctx.nodeEntity->dontRender = !render;

Expand Down
1 change: 0 additions & 1 deletion src/graphics/aurora/model_nwn.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ class Model_NWN : public Model {
void processASCIIMesh(ParserContext &ctx, MeshASCII &mesh);

void nodeInherit(ParserContext &ctx, const Common::UString &name);
void createNode(ParserContext &ctx, const Common::UString &name, Ogre::SceneNode *parent);
};

} // End of namespace Aurora
Expand Down

0 comments on commit 4027c00

Please sign in to comment.