Merge pull request #5 from greye/cross-cell

fix and unify object cell change update in mwrender
actorid
ChrisKCat 12 years ago
commit aab7cf137b

@ -149,10 +149,10 @@ Animation* Actors::getAnimation(const MWWorld::Ptr &ptr)
return NULL; return NULL;
} }
void Actors::updateObjectCell(const MWWorld::Ptr &ptr) void Actors::updateObjectCell(const MWWorld::Ptr &old, const MWWorld::Ptr &cur)
{ {
Ogre::SceneNode *node; Ogre::SceneNode *node;
MWWorld::CellStore *newCell = ptr.getCell(); MWWorld::CellStore *newCell = cur.getCell();
CellSceneNodeMap::const_iterator celliter = mCellSceneNodes.find(newCell); CellSceneNodeMap::const_iterator celliter = mCellSceneNodes.find(newCell);
if(celliter != mCellSceneNodes.end()) if(celliter != mCellSceneNodes.end())
@ -162,15 +162,15 @@ void Actors::updateObjectCell(const MWWorld::Ptr &ptr)
node = mMwRoot->createChildSceneNode(); node = mMwRoot->createChildSceneNode();
mCellSceneNodes[newCell] = node; mCellSceneNodes[newCell] = node;
} }
node->addChild(ptr.getRefData().getBaseNode()); node->addChild(cur.getRefData().getBaseNode());
PtrAnimationMap::iterator iter = mAllActors.find(ptr); PtrAnimationMap::iterator iter = mAllActors.find(old);
if(iter != mAllActors.end()) if(iter != mAllActors.end())
{ {
Animation *anim = iter->second; Animation *anim = iter->second;
mAllActors.erase(iter); mAllActors.erase(iter);
anim->updatePtr(ptr); anim->updatePtr(cur);
mAllActors[ptr] = anim; mAllActors[cur] = anim;
} }
} }

@ -42,7 +42,7 @@ namespace MWRender
void update (float duration); void update (float duration);
/// Updates containing cell for object rendering data /// Updates containing cell for object rendering data
void updateObjectCell(const MWWorld::Ptr &ptr); void updateObjectCell(const MWWorld::Ptr &old, const MWWorld::Ptr &cur);
Animation* getAnimation(const MWWorld::Ptr &ptr); Animation* getAnimation(const MWWorld::Ptr &ptr);
}; };

@ -533,10 +533,10 @@ void Objects::rebuildStaticGeometry()
} }
} }
void Objects::updateObjectCell(const MWWorld::Ptr &ptr) void Objects::updateObjectCell(const MWWorld::Ptr &old, const MWWorld::Ptr &cur)
{ {
Ogre::SceneNode *node; Ogre::SceneNode *node;
MWWorld::CellStore *newCell = ptr.getCell(); MWWorld::CellStore *newCell = cur.getCell();
if(mCellSceneNodes.find(newCell) == mCellSceneNodes.end()) { if(mCellSceneNodes.find(newCell) == mCellSceneNodes.end()) {
node = mMwRoot->createChildSceneNode(); node = mMwRoot->createChildSceneNode();
@ -544,6 +544,6 @@ void Objects::updateObjectCell(const MWWorld::Ptr &ptr)
} else { } else {
node = mCellSceneNodes[newCell]; node = mCellSceneNodes[newCell];
} }
node->addChild(ptr.getRefData().getBaseNode()); node->addChild(cur.getRefData().getBaseNode());
} }

@ -95,7 +95,7 @@ public:
void rebuildStaticGeometry(); void rebuildStaticGeometry();
/// Updates containing cell for object rendering data /// Updates containing cell for object rendering data
void updateObjectCell(const MWWorld::Ptr &ptr); void updateObjectCell(const MWWorld::Ptr &old, const MWWorld::Ptr &cur);
}; };
} }
#endif #endif

@ -302,23 +302,19 @@ bool RenderingManager::rotateObject( const MWWorld::Ptr &ptr, Ogre::Vector3 &rot
} }
void void
RenderingManager::moveObjectToCell( RenderingManager::updateObjectCell(const MWWorld::Ptr &old, const MWWorld::Ptr &cur)
const MWWorld::Ptr& ptr,
const Ogre::Vector3& pos,
MWWorld::CellStore *store)
{ {
Ogre::SceneNode *child = Ogre::SceneNode *child =
mRendering.getScene()->getSceneNode(ptr.getRefData().getHandle()); mRendering.getScene()->getSceneNode(old.getRefData().getHandle());
Ogre::SceneNode *parent = child->getParentSceneNode(); Ogre::SceneNode *parent = child->getParentSceneNode();
parent->removeChild(child); parent->removeChild(child);
if (MWWorld::Class::get(ptr).isActor()) { if (MWWorld::Class::get(old).isActor()) {
mActors.updateObjectCell(ptr); mActors.updateObjectCell(old, cur);
} else { } else {
mObjects.updateObjectCell(ptr); mObjects.updateObjectCell(old, cur);
} }
child->setPosition(pos);
} }
void RenderingManager::update (float duration, bool paused) void RenderingManager::update (float duration, bool paused)

@ -123,9 +123,10 @@ class RenderingManager: private RenderingInterface, public Ogre::WindowEventList
void setWaterHeight(const float height); void setWaterHeight(const float height);
void toggleWater(); void toggleWater();
/// Moves object rendering part to proper container /// Updates object rendering after cell change
/// \param store Cell the object was in previously (\a ptr has already been updated to the new cell). /// \param old Object reference in previous cell
void moveObjectToCell (const MWWorld::Ptr& ptr, const Ogre::Vector3& position, MWWorld::CellStore *store); /// \param cur Object reference in new cell
void updateObjectCell(const MWWorld::Ptr &old, const MWWorld::Ptr &cur);
void update (float duration, bool paused); void update (float duration, bool paused);

@ -770,7 +770,8 @@ namespace MWWorld
MWWorld::Ptr copy = MWWorld::Ptr copy =
MWWorld::Class::get(ptr).copyToCell(ptr, newCell); MWWorld::Class::get(ptr).copyToCell(ptr, newCell);
mRendering->moveObjectToCell(copy, vec, currCell); mRendering->updateObjectCell(ptr, copy);
MWBase::MechanicsManager *mechMgr = MWBase::Environment::get().getMechanicsManager(); MWBase::MechanicsManager *mechMgr = MWBase::Environment::get().getMechanicsManager();
mechMgr->updateCell(copy); mechMgr->updateCell(copy);

Loading…
Cancel
Save