From c02695e56d3d5298407f6cdb9e5854b0aa695492 Mon Sep 17 00:00:00 2001 From: Allofich Date: Mon, 4 Jul 2016 14:39:44 +0900 Subject: [PATCH] Cleanups and fixes --- apps/openmw/mwworld/action.cpp | 36 ++++--------------------- apps/openmw/mwworld/action.hpp | 3 +-- apps/openmw/mwworld/actiontrap.cpp | 16 +++++------ apps/openmw/mwworld/worldimp.cpp | 43 ++++++++++-------------------- apps/openmw/mwworld/worldimp.hpp | 8 +++--- 5 files changed, 30 insertions(+), 76 deletions(-) diff --git a/apps/openmw/mwworld/action.cpp b/apps/openmw/mwworld/action.cpp index 35cd99de7d..028080d7af 100644 --- a/apps/openmw/mwworld/action.cpp +++ b/apps/openmw/mwworld/action.cpp @@ -17,7 +17,7 @@ MWWorld::Action::Action (bool keepSound, const Ptr& target) : mKeepSound (keepSo MWWorld::Action::~Action() {} -void MWWorld::Action::execute (const Ptr& actor) +void MWWorld::Action::execute (const Ptr& actor, float distanceToObject, bool useDistance) { if(!mSoundId.empty()) { @@ -41,36 +41,10 @@ void MWWorld::Action::execute (const Ptr& actor) ); } } - - executeImp(actor); -} - -void MWWorld::Action::execute (const Ptr& actor, float distanceToObject) -{ - if(!mSoundId.empty()) - { - if(mKeepSound && actor == MWMechanics::getPlayer()) - MWBase::Environment::get().getSoundManager()->playSound(mSoundId, 1.0, 1.0, - MWBase::SoundManager::Play_TypeSfx, MWBase::SoundManager::Play_Normal, mSoundOffset - ); - else - { - bool local = mTarget.isEmpty() || !mTarget.isInCell(); // no usable target - if(mKeepSound) - MWBase::Environment::get().getSoundManager()->playSound3D( - (local ? actor : mTarget).getRefData().getPosition().asVec3(), - mSoundId, 1.0, 1.0, MWBase::SoundManager::Play_TypeSfx, - MWBase::SoundManager::Play_Normal, mSoundOffset - ); - else - MWBase::Environment::get().getSoundManager()->playSound3D(local ? actor : mTarget, - mSoundId, 1.0, 1.0, MWBase::SoundManager::Play_TypeSfx, - MWBase::SoundManager::Play_Normal, mSoundOffset - ); - } - } - - executeImp(actor, distanceToObject); + if (useDistance) + executeImp(actor, distanceToObject); + else + executeImp(actor); } void MWWorld::Action::setSound (const std::string& id) diff --git a/apps/openmw/mwworld/action.hpp b/apps/openmw/mwworld/action.hpp index 867c1e27c6..39df539cd3 100644 --- a/apps/openmw/mwworld/action.hpp +++ b/apps/openmw/mwworld/action.hpp @@ -37,8 +37,7 @@ namespace MWWorld virtual bool isNullAction() { return false; } ///< Is running this action a no-op? (default false) - void execute (const Ptr& actor); - void execute (const Ptr& actor, float distanceToObject); + void execute (const Ptr& actor, float distanceToObject = 0, bool useDistance = false); void setSound (const std::string& id); void setSoundOffset(float offset); diff --git a/apps/openmw/mwworld/actiontrap.cpp b/apps/openmw/mwworld/actiontrap.cpp index 0279eea3ec..a8b937c0a0 100644 --- a/apps/openmw/mwworld/actiontrap.cpp +++ b/apps/openmw/mwworld/actiontrap.cpp @@ -1,40 +1,36 @@ #include "actiontrap.hpp" #include "../mwmechanics/spellcasting.hpp" + #include "../mwbase/environment.hpp" #include "../mwbase/world.hpp" namespace MWWorld { - void ActionTrap::executeImp(const Ptr &actor, float distance) { osg::Vec3f actorPosition(actor.getRefData().getPosition().asVec3()); osg::Vec3f trapPosition(mTrapSource.getRefData().getPosition().asVec3()); float activationDistance = MWBase::Environment::get().getWorld()->getMaxActivationDistance(); - // GUI calcs if object in activation distance include object and player geometry - //const float fudgeFactor = 1.25f; - - // Hack: if actor is beyond activation range, then assume actor is using telekinesis - // to open door/container. - // Note, can't just detonate the trap at the trapped object's location and use the blast + // Note: can't just detonate the trap at the trapped object's location and use the blast // radius, because for most trap spells this is 1 foot, much less than the activation distance. + // Using the activation distance as the trap range. + if (distance < activationDistance) { - // assume actor touched trap + // actor activated object within range of trap MWMechanics::CastSpell cast(mTrapSource, actor); cast.mHitPosition = actorPosition; cast.cast(mSpellId); } else { - // assume telekinesis used + // actor activated object outside range of trap MWMechanics::CastSpell cast(mTrapSource, mTrapSource); cast.mHitPosition = trapPosition; cast.cast(mSpellId); } mTrapSource.getCellRef().setTrap(""); } - } diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index f3ed54eaf9..e54c75afe9 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -1,5 +1,4 @@ #include "worldimp.hpp" -#include #include #include @@ -151,7 +150,7 @@ namespace MWWorld mSky (true), mCells (mStore, mEsm), mGodMode(false), mScriptsEnabled(true), mContentFiles (contentFiles), mActivationDistanceOverride (activationDistanceOverride), mStartupScript(startupScript), - mStartCell (startCell), mTeleportEnabled(true), + mStartCell (startCell), mDistanceToFacedObject(0), mTeleportEnabled(true), mLevitationEnabled(true), mGoToJail(false), mDaysInPrison(0) { mPhysics = new MWPhysics::PhysicsSystem(resourceSystem, rootNode); @@ -1012,10 +1011,11 @@ namespace MWWorld MWWorld::Ptr World::getFacedObject() { MWWorld::Ptr facedObject; + float distanceToObject; if (MWBase::Environment::get().getWindowManager()->isGuiMode() && MWBase::Environment::get().getWindowManager()->isConsoleMode()) - facedObject = getFacedObject(getMaxActivationDistance() * 50, false); + facedObject = getFacedObject(getMaxActivationDistance() * 50, distanceToObject, false); else { float telekinesisRangeBonus = @@ -1024,7 +1024,6 @@ namespace MWWorld telekinesisRangeBonus = feetToGameUnits(telekinesisRangeBonus); float activationDistance = getMaxActivationDistance() + telekinesisRangeBonus; - float distanceToObject; facedObject = getFacedObject(activationDistance, distanceToObject, true); @@ -1036,6 +1035,8 @@ namespace MWWorld return 0; } + mDistanceToFacedObject = distanceToObject; + mFacedObject = facedObject; return facedObject; } @@ -1718,22 +1719,6 @@ namespace MWWorld } } - MWWorld::Ptr World::getFacedObject(float maxDistance, bool ignorePlayer) - { - maxDistance += mRendering->getCameraDistance(); - - if (MWBase::Environment::get().getWindowManager()->isGuiMode()) - { - float x, y; - MWBase::Environment::get().getWindowManager()->getMousePosition(x, y); - return mRendering->castCameraToViewportRay(x, y, maxDistance, ignorePlayer).mHitObject; - } - else - { - return mRendering->castCameraToViewportRay(0.5f, 0.5f, maxDistance, ignorePlayer).mHitObject; - } - } - MWWorld::Ptr World::getFacedObject(float maxDistance, float& distance, bool ignorePlayer) { maxDistance += mRendering->getCameraDistance(); @@ -3228,20 +3213,20 @@ namespace MWWorld if (object.getRefData().activate()) { boost::shared_ptr action = (object.getClass().activate(object, actor)); - if (object.getCellRef().getTrap() != "") // If the object is trapped, do a distance check to account for opening with telekinesis + if (object.getCellRef().getTrap() != "") { - float distanceToObject; - if (actor == getPlayerPtr()) // If the actor doing the activation is the player, get distance using the raycast in getFacedObject() - MWWorld::Ptr result = getFacedObject(1.0f, distanceToObject, true); - else // Otherwise do a position-based distance check + // For the distance check to a trapped object, use the raycast-derived distance if we have it + if (actor == getPlayerPtr() && (object == mFacedObject)) + action->execute (actor, mDistanceToFacedObject, true); + else // Otherwise use a position comparison { osg::Vec3f actorPosition(actor.getRefData().getPosition().asVec3()); osg::Vec3f objectPosition(object.getRefData().getPosition().asVec3()); - distanceToObject = (objectPosition - actorPosition).length(); - } - action->execute (actor, distanceToObject); + action->execute (actor, (objectPosition - actorPosition).length(), true); + } } - action->execute (actor); + else + action->execute (actor); } } diff --git a/apps/openmw/mwworld/worldimp.hpp b/apps/openmw/mwworld/worldimp.hpp index d5c3c7815a..b1cc081203 100644 --- a/apps/openmw/mwworld/worldimp.hpp +++ b/apps/openmw/mwworld/worldimp.hpp @@ -128,10 +128,6 @@ namespace MWWorld void updateWindowManager (); void updatePlayer(bool paused); - /// Return faced object - MWWorld::Ptr getFacedObject(float maxDistance, bool ignorePlayer=true); - - /// Return faced object and distance from player to it MWWorld::Ptr getFacedObject(float maxDistance, float& distanceToObject, bool ignorePlayer=true); public: // FIXME @@ -160,6 +156,10 @@ namespace MWWorld const std::vector& content, ContentLoader& contentLoader); float mSwimHeightScale; + + float mDistanceToFacedObject; + MWWorld::Ptr mFacedObject; + bool isUnderwater(const MWWorld::ConstPtr &object, const float heightRatio) const; ///< helper function for implementing isSwimming(), isSubmerged(), isWading()