Skip to content

Commit

Permalink
GRAPHICS: Remove animation node caching (fix NWN animations)
Browse files Browse the repository at this point in the history
  • Loading branch information
vkremianskii authored and DrMcCoy committed Nov 23, 2017
1 parent 5c41b29 commit cc0cf9b
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 26 deletions.
19 changes: 1 addition & 18 deletions src/graphics/aurora/animation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void Animation::update(Model *model, float UNUSED(lastFrame), float nextFrame) {
float scale = model->getAnimationScale(_name);
for (NodeList::iterator n = nodeList.begin(); n != nodeList.end(); ++n) {
ModelNode *animNode = (*n)->_nodedata;
ModelNode *target = model->_animNodeMap[animNode->_nodeNumber];
ModelNode *target = model->getNode(animNode->getName());
if (!target)
continue;

Expand Down Expand Up @@ -116,23 +116,6 @@ const ModelNode *Animation::getNode(const Common::UString &node) const {
return n->second->_nodedata;
}

void Animation::makeAnimNodeMap(Model *model) {
int maxNodeNumber = -1;
for (NodeList::iterator it = nodeList.begin(); it != nodeList.end(); ++it) {
ModelNode *node = (*it)->_nodedata;
if (node->_nodeNumber > maxNodeNumber) {
maxNodeNumber = node->_nodeNumber;
}
}
if (maxNodeNumber != -1) {
model->_animNodeMap.reserve(maxNodeNumber + 1);
for (NodeList::iterator it = nodeList.begin(); it != nodeList.end(); ++it) {
ModelNode *node = (*it)->_nodedata;
model->_animNodeMap[node->_nodeNumber] = model->getNode(node->getName());
}
}
}

/** Return the dot product of two quaternions. */
static float dotQuaternion(float x1, float y1, float z1, float q1,
float x2, float y2, float z2, float q2) {
Expand Down
3 changes: 0 additions & 3 deletions src/graphics/aurora/animation.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,6 @@ class Animation {
/** Get the specified node. */
const ModelNode *getNode(const Common::UString &node) const;

/** Map node numbers to animation nodes for better performance. */
void makeAnimNodeMap(Model *model);

protected:
typedef std::list<AnimNode *> NodeList;
typedef std::map<Common::UString, AnimNode *, Common::UString::iless> NodeMap;
Expand Down
4 changes: 1 addition & 3 deletions src/graphics/aurora/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace Aurora {

Model::Model(ModelType type) : Renderable((RenderableType) type),
_type(type), _superModel(0), _currentState(0),
_currentAnimation(0), _nextAnimation(0), _drawBound(false),
_currentAnimation(0), _nextAnimation(0), _skinned(false), _drawBound(false),
_drawSkeleton(false), _drawSkeletonInvisible(false) {

_scale [0] = 1.0f; _scale [1] = 1.0f; _scale [2] = 1.0f;
Expand Down Expand Up @@ -230,13 +230,11 @@ void Model::setCurrentAnimation(Animation *anim) {

_currentAnimation = anim;
_animationLoopTime = 0.0f;
anim->makeAnimNodeMap(this);

for (NodeList::iterator n = _currentState->nodeList.begin(); n != _currentState->nodeList.end(); ++n)
if ((*n)->_attachedModel) {
(*n)->_attachedModel->_currentAnimation = anim;
(*n)->_attachedModel->_animationLoopTime = 0.0f;
anim->makeAnimNodeMap((*n)->_attachedModel);
}

}
Expand Down
2 changes: 0 additions & 2 deletions src/graphics/aurora/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,6 @@ class Model : public GLContainer, public Renderable {
float _animationLoopLength; ///< The length of one loop of the current animation.
float _animationLoopTime; ///< The time the current loop of the current animation has played.

std::vector<ModelNode *> _animNodeMap;

/** Create the list of all state names. */
void createStateNamesList(std::list<Common::UString> *stateNames = 0);
/** Create the model's bounding box. */
Expand Down

0 comments on commit cc0cf9b

Please sign in to comment.