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.
actorid
Chris Robinson 12 years ago
parent ba3a67f84b
commit bb8277920b

@ -15,7 +15,7 @@
namespace MWRender namespace MWRender
{ {
Player::Player (Ogre::Camera *camera, Ogre::SceneNode* node) Player::Player (Ogre::Camera *camera)
: mCamera(camera), : mCamera(camera),
mCameraNode(NULL), mCameraNode(NULL),
mFirstPersonView(true), mFirstPersonView(true),
@ -35,7 +35,6 @@ namespace MWRender
Player::~Player() Player::~Player()
{ {
delete mAnimation;
} }
void Player::rotateCamera(const Ogre::Vector3 &rot, bool adjust) void Player::rotateCamera(const Ogre::Vector3 &rot, bool adjust)
@ -273,11 +272,13 @@ namespace MWRender
void Player::setAnimation(NpcAnimation *anim) void Player::setAnimation(NpcAnimation *anim)
{ {
anim->setViewMode((mVanity.enabled || mPreviewMode || !mFirstPersonView) ? // If we're switching to a new NpcAnimation, ensure the old one is
NpcAnimation::VM_Normal : NpcAnimation::VM_FirstPerson); // using a normal view mode
if(mAnimation && mAnimation != anim)
delete mAnimation; mAnimation->setViewMode(NpcAnimation::VM_Normal);
mAnimation = anim; mAnimation = anim;
mAnimation->setViewMode((mVanity.enabled || mPreviewMode || !mFirstPersonView) ?
NpcAnimation::VM_Normal : NpcAnimation::VM_FirstPerson);
} }
void Player::setHeight(float height) void Player::setHeight(float height)

@ -49,8 +49,7 @@ namespace MWRender
void setLowHeight(bool low = true); void setLowHeight(bool low = true);
public: public:
Player(Ogre::Camera *camera);
Player (Ogre::Camera *camera, Ogre::SceneNode* mNode);
~Player(); ~Player();
/// Set where the player is looking at. Uses Morrowind (euler) angles /// Set where the player is looking at. Uses Morrowind (euler) angles
@ -89,8 +88,6 @@ namespace MWRender
void setCameraDistance(); void setCameraDistance();
void setAnimation(NpcAnimation *anim); void setAnimation(NpcAnimation *anim);
NpcAnimation *getAnimation() const
{ return mAnimation; }
void setHeight(float height); void setHeight(float height);
float getHeight(); float getHeight();

@ -53,8 +53,9 @@ RenderingManager::RenderingManager (OEngine::Render::OgreRenderer& _rend, const
const boost::filesystem::path& cacheDir, OEngine::Physic::PhysicEngine* engine,MWWorld::Fallback* fallback) const boost::filesystem::path& cacheDir, OEngine::Physic::PhysicEngine* engine,MWWorld::Fallback* fallback)
: mRendering(_rend) : mRendering(_rend)
, mFallback(fallback) , mFallback(fallback)
, mObjects(mRendering,mFallback) , mObjects(mRendering, mFallback)
, mActors(mRendering, this) , mActors(mRendering, this)
, mPlayerAnimation(NULL)
, mAmbientMode(0) , mAmbientMode(0)
, mSunEnabled(0) , mSunEnabled(0)
, mPhysicsEngine(engine) , mPhysicsEngine(engine)
@ -148,14 +149,13 @@ RenderingManager::RenderingManager (OEngine::Render::OgreRenderer& _rend, const
applyCompositors(); applyCompositors();
SceneNode *rt = mRendering.getScene()->getRootSceneNode(); mRootNode = mRendering.getScene()->getRootSceneNode();
mRootNode = rt; mRootNode->createChildSceneNode("player");
mObjects.setRootNode(mRootNode); mObjects.setRootNode(mRootNode);
mActors.setRootNode(mRootNode); mActors.setRootNode(mRootNode);
Ogre::SceneNode *playerNode = mRootNode->createChildSceneNode ("player"); mPlayer = new MWRender::Player(mRendering.getCamera());
mPlayer = new MWRender::Player (mRendering.getCamera(), playerNode);
mShadows = new Shadows(&mRendering); mShadows = new Shadows(&mRendering);
@ -183,6 +183,7 @@ RenderingManager::~RenderingManager ()
mRendering.getWindow()->removeListener(this); mRendering.getWindow()->removeListener(this);
mRendering.removeWindowEventListener(this); mRendering.removeWindowEventListener(this);
delete mPlayerAnimation;
delete mPlayer; delete mPlayer;
delete mSkyManager; delete mSkyManager;
delete mDebugging; delete mDebugging;
@ -866,14 +867,23 @@ void RenderingManager::setupPlayer(const MWWorld::Ptr &ptr)
void RenderingManager::renderPlayer(const MWWorld::Ptr &ptr) void RenderingManager::renderPlayer(const MWWorld::Ptr &ptr)
{ {
MWRender::NpcAnimation *anim = if(!mPlayerAnimation)
new MWRender::NpcAnimation( {
ptr, ptr.getRefData ().getBaseNode (), mPlayerAnimation = new NpcAnimation(ptr, ptr.getRefData().getBaseNode(),
MWWorld::Class::get(ptr).getInventoryStore(ptr), RV_Actors MWWorld::Class::get(ptr).getInventoryStore(ptr),
); RV_Actors);
mPlayer->setAnimation(anim); }
mWater->removeEmitter (ptr); else
mWater->addEmitter (ptr); {
// 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 // apply race height
MWBase::Environment::get().getWorld()->scaleObject(ptr, 1.f); MWBase::Environment::get().getWorld()->scaleObject(ptr, 1.f);
} }
@ -914,7 +924,7 @@ Animation* RenderingManager::getAnimation(const MWWorld::Ptr &ptr)
{ {
Animation *anim = mActors.getAnimation(ptr); Animation *anim = mActors.getAnimation(ptr);
if(!anim && ptr.getRefData().getHandle() == "player") if(!anim && ptr.getRefData().getHandle() == "player")
anim = mPlayer->getAnimation(); anim = mPlayerAnimation;
return anim; return anim;
} }

@ -238,6 +238,8 @@ class RenderingManager: private RenderingInterface, public Ogre::WindowEventList
MWRender::Objects mObjects; MWRender::Objects mObjects;
MWRender::Actors mActors; MWRender::Actors mActors;
MWRender::NpcAnimation *mPlayerAnimation;
// 0 normal, 1 more bright, 2 max // 0 normal, 1 more bright, 2 max
int mAmbientMode; int mAmbientMode;

Loading…
Cancel
Save