diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index 03a4181b5..32ed17c5b 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -21,7 +21,8 @@ source_group(game FILES ${GAME} ${GAME_HEADER}) add_openmw_dir (mwrender actors objects renderingmanager animation sky npcanimation vismask -# debugging camera creatureanimation activatoranimation + creatureanimation +# debugging camera activatoranimation # renderinginterface localmap occlusionquery water shadows # characterpreview globalmap ripplesimulation refraction # terrainstorage renderconst effectmanager weaponanimation diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 9a7f023e6..fe6180299 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -497,6 +497,7 @@ void OMW::Engine::go() { double dt = frameTimer.time_s(); frameTimer.setStartTick(); + //dt = std::min(dt, 0.2f); // frameRenderingQueued(dt); MWBase::Environment::get().getWorld()->update(dt, false); @@ -507,18 +508,6 @@ void OMW::Engine::go() mViewer.frame(/*simulationTime*/); } - /* - Ogre::Timer timer; - while (!MWBase::Environment::get().getStateManager()->hasQuitRequest()) - { - float dt = timer.getMilliseconds()/1000.f; - dt = std::min(dt, 0.2f); - - timer.reset(); - Ogre::Root::getSingleton().renderOneFrame(dt); - } - */ - // Save user settings settings.saveUser(settingspath); diff --git a/apps/openmw/mwrender/creatureanimation.cpp b/apps/openmw/mwrender/creatureanimation.cpp index 7260fc6d1..9ccdf390e 100644 --- a/apps/openmw/mwrender/creatureanimation.cpp +++ b/apps/openmw/mwrender/creatureanimation.cpp @@ -1,11 +1,13 @@ #include "creatureanimation.hpp" -#include -#include -#include - #include +#include + +#include +#include +#include + #include "../mwbase/world.hpp" #include "../mwworld/class.hpp" @@ -16,45 +18,46 @@ namespace MWRender { -CreatureAnimation::CreatureAnimation(const MWWorld::Ptr &ptr, const std::string& model) - : Animation(ptr, ptr.getRefData().getBaseNode()) +CreatureAnimation::CreatureAnimation(const MWWorld::Ptr &ptr, + const std::string& model, Resource::ResourceSystem* resourceSystem) + : Animation(ptr, osg::ref_ptr(ptr.getRefData().getBaseNode()), resourceSystem) { - MWWorld::LiveCellRef *ref = mPtr.get(); + //MWWorld::LiveCellRef *ref = mPtr.get(); if(!model.empty()) { - setObjectRoot(model, false); - setRenderProperties(mObjectRoot, RV_Actors, RQG_Main, RQG_Alpha); + setObjectRoot(model /* , baseonly = false */); + //setRenderProperties(mObjectRoot, RV_Actors, RQG_Main, RQG_Alpha); - if((ref->mBase->mFlags&ESM::Creature::Bipedal)) - addAnimSource("meshes\\xbase_anim.nif"); - addAnimSource(model); + //if((ref->mBase->mFlags&ESM::Creature::Bipedal)) + // addAnimSource("meshes\\xbase_anim.nif"); + //addAnimSource(model); } } -CreatureWeaponAnimation::CreatureWeaponAnimation(const MWWorld::Ptr &ptr, const std::string& model) - : Animation(ptr, ptr.getRefData().getBaseNode()) +CreatureWeaponAnimation::CreatureWeaponAnimation(const MWWorld::Ptr &ptr, const std::string& model, Resource::ResourceSystem* resourceSystem) + : Animation(ptr, osg::ref_ptr(ptr.getRefData().getBaseNode()), resourceSystem) , mShowWeapons(false) , mShowCarriedLeft(false) { - MWWorld::LiveCellRef *ref = mPtr.get(); + //MWWorld::LiveCellRef *ref = mPtr.get(); if(!model.empty()) { - setObjectRoot(model, false); - setRenderProperties(mObjectRoot, RV_Actors, RQG_Main, RQG_Alpha); + setObjectRoot(model /* , baseonly = false*/); + //setRenderProperties(mObjectRoot, RV_Actors, RQG_Main, RQG_Alpha); - if((ref->mBase->mFlags&ESM::Creature::Bipedal)) - addAnimSource("meshes\\xbase_anim.nif"); - addAnimSource(model); + //if((ref->mBase->mFlags&ESM::Creature::Bipedal)) + // addAnimSource("meshes\\xbase_anim.nif"); + //addAnimSource(model); mPtr.getClass().getInventoryStore(mPtr).setListener(this, mPtr); updateParts(); } - mWeaponAnimationTime = Ogre::SharedPtr(new WeaponAnimationTime(this)); + //mWeaponAnimationTime = Ogre::SharedPtr(new WeaponAnimationTime(this)); } void CreatureWeaponAnimation::showWeapons(bool showWeapon) @@ -77,8 +80,8 @@ void CreatureWeaponAnimation::showCarriedLeft(bool show) void CreatureWeaponAnimation::updateParts() { - mWeapon.setNull(); - mShield.setNull(); + mWeapon.reset(); + mShield.reset(); if (mShowWeapons) updatePart(mWeapon, MWWorld::InventoryStore::Slot_CarriedRight); @@ -86,9 +89,9 @@ void CreatureWeaponAnimation::updateParts() updatePart(mShield, MWWorld::InventoryStore::Slot_CarriedLeft); } -void CreatureWeaponAnimation::updatePart(NifOgre::ObjectScenePtr& scene, int slot) +void CreatureWeaponAnimation::updatePart(PartHolderPtr& scene, int slot) { - if (!mSkelBase) + if (!mObjectRoot) return; MWWorld::InventoryStore& inv = mPtr.getClass().getInventoryStore(mPtr); @@ -96,7 +99,7 @@ void CreatureWeaponAnimation::updatePart(NifOgre::ObjectScenePtr& scene, int slo if (it == inv.end()) { - scene.setNull(); + scene.reset(); return; } MWWorld::Ptr item = *it; @@ -107,13 +110,16 @@ void CreatureWeaponAnimation::updatePart(NifOgre::ObjectScenePtr& scene, int slo else bonename = "Shield Bone"; - scene = NifOgre::Loader::createObjects(mSkelBase, bonename, bonename, mInsert, item.getClass().getModel(item)); - Ogre::Vector3 glowColor = getEnchantmentColor(item); + osg::ref_ptr node = mResourceSystem->getSceneManager()->createInstance(item.getClass().getModel(item)); + SceneUtil::attach(node, mObjectRoot, bonename, bonename); - setRenderProperties(scene, RV_Actors, RQG_Main, RQG_Alpha, 0, - !item.getClass().getEnchantment(item).empty(), &glowColor); + scene.reset(new PartHolder(node)); + + if (!item.getClass().getEnchantment(item).empty()) + addGlow(node, getEnchantmentColor(item)); // Crossbows start out with a bolt attached + // FIXME: code duplicated from NpcAnimation if (slot == MWWorld::InventoryStore::Slot_CarriedRight && item.getTypeName() == typeid(ESM::Weapon).name() && item.get()->mBase->mData.mType == ESM::Weapon::MarksmanCrossbow) @@ -121,12 +127,14 @@ void CreatureWeaponAnimation::updatePart(NifOgre::ObjectScenePtr& scene, int slo MWWorld::ContainerStoreIterator ammo = inv.getSlot(MWWorld::InventoryStore::Slot_Ammunition); if (ammo != inv.end() && ammo->get()->mBase->mData.mType == ESM::Weapon::Bolt) attachArrow(); - else - mAmmunition.setNull(); + //else + // mAmmunition.setNull(); } - else - mAmmunition.setNull(); + //else + //mAmmunition.setNull(); + // FIXME: code duplicated from NpcAnimation + /* if(scene->mSkelBase) { Ogre::SkeletonInstance *skel = scene->mSkelBase->getSkeleton(); @@ -149,7 +157,9 @@ void CreatureWeaponAnimation::updatePart(NifOgre::ObjectScenePtr& scene, int slo } updateSkeletonInstance(mSkelBase->getSkeleton(), skel); } + */ + /* std::vector >::iterator ctrl(scene->mControllers.begin()); for(;ctrl != scene->mControllers.end();++ctrl) { @@ -161,45 +171,39 @@ void CreatureWeaponAnimation::updatePart(NifOgre::ObjectScenePtr& scene, int slo ctrl->setSource(Ogre::SharedPtr(new NullAnimationTime())); } } + */ } +/* void CreatureWeaponAnimation::configureAddedObject(NifOgre::ObjectScenePtr object, MWWorld::Ptr ptr, int slot) { - Ogre::Vector3 glowColor = getEnchantmentColor(ptr); + //Ogre::Vector3 glowColor = getEnchantmentColor(ptr); - setRenderProperties(object, RV_Actors, RQG_Main, RQG_Alpha, 0, - !ptr.getClass().getEnchantment(ptr).empty(), &glowColor); + //setRenderProperties(object, RV_Actors, RQG_Main, RQG_Alpha, 0, + // !ptr.getClass().getEnchantment(ptr).empty(), &glowColor); } +*/ void CreatureWeaponAnimation::attachArrow() { - WeaponAnimation::attachArrow(mPtr); + //WeaponAnimation::attachArrow(mPtr); } void CreatureWeaponAnimation::releaseArrow() { - WeaponAnimation::releaseArrow(mPtr); + //WeaponAnimation::releaseArrow(mPtr); } -Ogre::Vector3 CreatureWeaponAnimation::runAnimation(float duration) +osg::Vec3f CreatureWeaponAnimation::runAnimation(float duration) { + /* Ogre::Vector3 ret = Animation::runAnimation(duration); if (mSkelBase) pitchSkeleton(mPtr.getRefData().getPosition().rot[0], mSkelBase->getSkeleton()); + */ - if (!mWeapon.isNull()) - { - for (unsigned int i=0; imControllers.size(); ++i) - mWeapon->mControllers[i].update(); - } - if (!mShield.isNull()) - { - for (unsigned int i=0; imControllers.size(); ++i) - mShield->mControllers[i].update(); - } - - return ret; + return osg::Vec3f(); } } diff --git a/apps/openmw/mwrender/creatureanimation.hpp b/apps/openmw/mwrender/creatureanimation.hpp index 6201c7af4..ccb553d99 100644 --- a/apps/openmw/mwrender/creatureanimation.hpp +++ b/apps/openmw/mwrender/creatureanimation.hpp @@ -15,17 +15,17 @@ namespace MWRender class CreatureAnimation : public Animation { public: - CreatureAnimation(const MWWorld::Ptr& ptr, const std::string &model); + CreatureAnimation(const MWWorld::Ptr &ptr, const std::string& model, Resource::ResourceSystem* resourceSystem); virtual ~CreatureAnimation() {} }; // For creatures with weapons and shields // Animation is already virtual anyway, so might as well make a separate class. // Most creatures don't need weapons/shields, so this will save some memory. - class CreatureWeaponAnimation : public Animation, public WeaponAnimation, public MWWorld::InventoryStoreListener + class CreatureWeaponAnimation : public Animation/*, public WeaponAnimation*/, public MWWorld::InventoryStoreListener { public: - CreatureWeaponAnimation(const MWWorld::Ptr& ptr, const std::string &model); + CreatureWeaponAnimation(const MWWorld::Ptr &ptr, const std::string& model, Resource::ResourceSystem* resourceSystem); virtual ~CreatureWeaponAnimation() {} virtual void equipmentChanged() { updateParts(); } @@ -35,31 +35,31 @@ namespace MWRender void updateParts(); - void updatePart(NifOgre::ObjectScenePtr& scene, int slot); + void updatePart(PartHolderPtr& scene, int slot); virtual void attachArrow(); virtual void releaseArrow(); - virtual Ogre::Vector3 runAnimation(float duration); + virtual osg::Vec3f runAnimation(float duration); /// A relative factor (0-1) that decides if and how much the skeleton should be pitched /// to indicate the facing orientation of the character. - virtual void setPitchFactor(float factor) { mPitchFactor = factor; } + //virtual void setPitchFactor(float factor) { mPitchFactor = factor; } - virtual void setWeaponGroup(const std::string& group) { mWeaponAnimationTime->setGroup(group); } + //virtual void setWeaponGroup(const std::string& group) { mWeaponAnimationTime->setGroup(group); } // WeaponAnimation - virtual NifOgre::ObjectScenePtr getWeapon() { return mWeapon; } - virtual void showWeapon(bool show) { showWeapons(show); } - virtual void configureAddedObject(NifOgre::ObjectScenePtr object, MWWorld::Ptr ptr, int slot); + //virtual NifOgre::ObjectScenePtr getWeapon() { return mWeapon; } + //virtual void showWeapon(bool show) { showWeapons(show); } + //virtual void configureAddedObject(NifOgre::ObjectScenePtr object, MWWorld::Ptr ptr, int slot); private: - NifOgre::ObjectScenePtr mWeapon; - NifOgre::ObjectScenePtr mShield; + PartHolderPtr mWeapon; + PartHolderPtr mShield; bool mShowWeapons; bool mShowCarriedLeft; - Ogre::SharedPtr mWeaponAnimationTime; + //Ogre::SharedPtr mWeaponAnimationTime; }; } diff --git a/apps/openmw/mwrender/npcanimation.cpp b/apps/openmw/mwrender/npcanimation.cpp index c413d9334..eeb5298b8 100644 --- a/apps/openmw/mwrender/npcanimation.cpp +++ b/apps/openmw/mwrender/npcanimation.cpp @@ -1,15 +1,5 @@ #include "npcanimation.hpp" -#include -#include -#include -#include -#include -#include -#include -#include -#include - #include #include @@ -575,18 +565,6 @@ void NpcAnimation::addFirstPersonOffset(const Ogre::Vector3 &offset) mFirstPersonOffset += offset; } -class SetObjectGroup { - int mGroup; - -public: - SetObjectGroup(int group) : mGroup(group) { } - - void operator()(Ogre::MovableObject *obj) const - { - obj->getUserObjectBindings().setUserAny(Ogre::Any(mGroup)); - } -}; - Animation::PartHolderPtr NpcAnimation::insertBoundedPart(const std::string& model, int group, const std::string& bonename, const std::string& bonefilter, bool enchantedGlow, osg::Vec4f* glowColor) { osg::ref_ptr instance = mResourceSystem->getSceneManager()->createInstance(model); diff --git a/apps/openmw/mwrender/objects.cpp b/apps/openmw/mwrender/objects.cpp index 4564e3a97..3d11662aa 100644 --- a/apps/openmw/mwrender/objects.cpp +++ b/apps/openmw/mwrender/objects.cpp @@ -26,6 +26,7 @@ #include "renderconst.hpp" #include "animation.hpp" #include "npcanimation.hpp" +#include "creatureanimation.hpp" namespace { @@ -194,7 +195,13 @@ void Objects::insertCreature(const MWWorld::Ptr &ptr, const std::string &mesh, b insertBegin(ptr); // CreatureAnimation - std::auto_ptr anim (new ObjectAnimation(ptr, mesh, mResourceSystem)); + std::auto_ptr anim; + + if (weaponsShields) + anim.reset(new CreatureWeaponAnimation(ptr, mesh, mResourceSystem)); + else + anim.reset(new CreatureAnimation(ptr, mesh, mResourceSystem)); + mObjects.insert(std::make_pair(ptr, anim.release())); }