From bb8277920b8c5c5c2f5264e3372e183a846cab7d Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 29 Apr 2013 03:31:46 -0700 Subject: [PATCH] Manage the player's NpcAnimation object in the RenderingManager It may be more appropriate to manage it in MWRender::Actors with the other Animation-based objects, but that will need some (minor) interface changes. --- apps/openmw/mwrender/player.cpp | 13 ++++---- apps/openmw/mwrender/player.hpp | 5 +-- apps/openmw/mwrender/renderingmanager.cpp | 38 ++++++++++++++--------- apps/openmw/mwrender/renderingmanager.hpp | 2 ++ 4 files changed, 34 insertions(+), 24 deletions(-) diff --git a/apps/openmw/mwrender/player.cpp b/apps/openmw/mwrender/player.cpp index 153d4af49..7eb7156ab 100644 --- a/apps/openmw/mwrender/player.cpp +++ b/apps/openmw/mwrender/player.cpp @@ -15,7 +15,7 @@ namespace MWRender { - Player::Player (Ogre::Camera *camera, Ogre::SceneNode* node) + Player::Player (Ogre::Camera *camera) : mCamera(camera), mCameraNode(NULL), mFirstPersonView(true), @@ -35,7 +35,6 @@ namespace MWRender Player::~Player() { - delete mAnimation; } void Player::rotateCamera(const Ogre::Vector3 &rot, bool adjust) @@ -273,11 +272,13 @@ namespace MWRender void Player::setAnimation(NpcAnimation *anim) { - anim->setViewMode((mVanity.enabled || mPreviewMode || !mFirstPersonView) ? - NpcAnimation::VM_Normal : NpcAnimation::VM_FirstPerson); - - delete mAnimation; + // If we're switching to a new NpcAnimation, ensure the old one is + // using a normal view mode + if(mAnimation && mAnimation != anim) + mAnimation->setViewMode(NpcAnimation::VM_Normal); mAnimation = anim; + mAnimation->setViewMode((mVanity.enabled || mPreviewMode || !mFirstPersonView) ? + NpcAnimation::VM_Normal : NpcAnimation::VM_FirstPerson); } void Player::setHeight(float height) diff --git a/apps/openmw/mwrender/player.hpp b/apps/openmw/mwrender/player.hpp index 3c645230b..8675e0760 100644 --- a/apps/openmw/mwrender/player.hpp +++ b/apps/openmw/mwrender/player.hpp @@ -49,8 +49,7 @@ namespace MWRender void setLowHeight(bool low = true); public: - - Player (Ogre::Camera *camera, Ogre::SceneNode* mNode); + Player(Ogre::Camera *camera); ~Player(); /// Set where the player is looking at. Uses Morrowind (euler) angles @@ -89,8 +88,6 @@ namespace MWRender void setCameraDistance(); void setAnimation(NpcAnimation *anim); - NpcAnimation *getAnimation() const - { return mAnimation; } void setHeight(float height); float getHeight(); diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index 252e29666..2e168caed 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -53,8 +53,9 @@ RenderingManager::RenderingManager (OEngine::Render::OgreRenderer& _rend, const const boost::filesystem::path& cacheDir, OEngine::Physic::PhysicEngine* engine,MWWorld::Fallback* fallback) : mRendering(_rend) , mFallback(fallback) - , mObjects(mRendering,mFallback) + , mObjects(mRendering, mFallback) , mActors(mRendering, this) + , mPlayerAnimation(NULL) , mAmbientMode(0) , mSunEnabled(0) , mPhysicsEngine(engine) @@ -148,14 +149,13 @@ RenderingManager::RenderingManager (OEngine::Render::OgreRenderer& _rend, const applyCompositors(); - SceneNode *rt = mRendering.getScene()->getRootSceneNode(); - mRootNode = rt; + mRootNode = mRendering.getScene()->getRootSceneNode(); + mRootNode->createChildSceneNode("player"); mObjects.setRootNode(mRootNode); mActors.setRootNode(mRootNode); - Ogre::SceneNode *playerNode = mRootNode->createChildSceneNode ("player"); - mPlayer = new MWRender::Player (mRendering.getCamera(), playerNode); + mPlayer = new MWRender::Player(mRendering.getCamera()); mShadows = new Shadows(&mRendering); @@ -183,6 +183,7 @@ RenderingManager::~RenderingManager () mRendering.getWindow()->removeListener(this); mRendering.removeWindowEventListener(this); + delete mPlayerAnimation; delete mPlayer; delete mSkyManager; delete mDebugging; @@ -866,14 +867,23 @@ void RenderingManager::setupPlayer(const MWWorld::Ptr &ptr) void RenderingManager::renderPlayer(const MWWorld::Ptr &ptr) { - MWRender::NpcAnimation *anim = - new MWRender::NpcAnimation( - ptr, ptr.getRefData ().getBaseNode (), - MWWorld::Class::get(ptr).getInventoryStore(ptr), RV_Actors - ); - mPlayer->setAnimation(anim); - mWater->removeEmitter (ptr); - mWater->addEmitter (ptr); + if(!mPlayerAnimation) + { + mPlayerAnimation = new NpcAnimation(ptr, ptr.getRefData().getBaseNode(), + MWWorld::Class::get(ptr).getInventoryStore(ptr), + RV_Actors); + } + else + { + // Reconstruct the NpcAnimation in-place + mPlayerAnimation->~NpcAnimation(); + new(mPlayerAnimation) NpcAnimation(ptr, ptr.getRefData().getBaseNode(), + MWWorld::Class::get(ptr).getInventoryStore(ptr), + RV_Actors); + } + mPlayer->setAnimation(mPlayerAnimation); + mWater->removeEmitter(ptr); + mWater->addEmitter(ptr); // apply race height MWBase::Environment::get().getWorld()->scaleObject(ptr, 1.f); } @@ -914,7 +924,7 @@ Animation* RenderingManager::getAnimation(const MWWorld::Ptr &ptr) { Animation *anim = mActors.getAnimation(ptr); if(!anim && ptr.getRefData().getHandle() == "player") - anim = mPlayer->getAnimation(); + anim = mPlayerAnimation; return anim; } diff --git a/apps/openmw/mwrender/renderingmanager.hpp b/apps/openmw/mwrender/renderingmanager.hpp index 20ec0d9ae..c7e27a405 100644 --- a/apps/openmw/mwrender/renderingmanager.hpp +++ b/apps/openmw/mwrender/renderingmanager.hpp @@ -238,6 +238,8 @@ class RenderingManager: private RenderingInterface, public Ogre::WindowEventList MWRender::Objects mObjects; MWRender::Actors mActors; + MWRender::NpcAnimation *mPlayerAnimation; + // 0 normal, 1 more bright, 2 max int mAmbientMode;