Accept a ConstPtr in findContainer, collision script functions, getUnderwater functions

openmw-38
scrawl 9 years ago
parent ed101ad35a
commit 388aed1748

@ -178,7 +178,7 @@ namespace MWBase
virtual MWWorld::Ptr searchPtrViaActorId (int actorId) = 0;
///< Search is limited to the active cells.
virtual MWWorld::Ptr findContainer (const MWWorld::Ptr& ptr) = 0;
virtual MWWorld::Ptr findContainer (const MWWorld::ConstPtr& ptr) = 0;
///< Return a pointer to a liveCellRef which contains \a ptr.
/// \note Search is limited to the active cells.
@ -367,10 +367,10 @@ namespace MWBase
virtual bool isFlying(const MWWorld::Ptr &ptr) const = 0;
virtual bool isSlowFalling(const MWWorld::Ptr &ptr) const = 0;
virtual bool isSwimming(const MWWorld::Ptr &object) const = 0;
virtual bool isWading(const MWWorld::Ptr &object) const = 0;
virtual bool isSwimming(const MWWorld::ConstPtr &object) const = 0;
virtual bool isWading(const MWWorld::ConstPtr &object) const = 0;
///Is the head of the creature underwater?
virtual bool isSubmerged(const MWWorld::Ptr &object) const = 0;
virtual bool isSubmerged(const MWWorld::ConstPtr &object) const = 0;
virtual bool isUnderwater(const MWWorld::CellStore* cell, const osg::Vec3f &pos) const = 0;
virtual bool isOnGround(const MWWorld::Ptr &ptr) const = 0;
@ -396,14 +396,14 @@ namespace MWBase
/// @note throws an exception when invoked on a teleport door
virtual void activateDoor(const MWWorld::Ptr& door, int state) = 0;
virtual bool getPlayerStandingOn (const MWWorld::Ptr& object) = 0; ///< @return true if the player is standing on \a object
virtual bool getActorStandingOn (const MWWorld::Ptr& object) = 0; ///< @return true if any actor is standing on \a object
virtual bool getPlayerCollidingWith(const MWWorld::Ptr& object) = 0; ///< @return true if the player is colliding with \a object
virtual bool getActorCollidingWith (const MWWorld::Ptr& object) = 0; ///< @return true if any actor is colliding with \a object
virtual void hurtStandingActors (const MWWorld::Ptr& object, float dmgPerSecond) = 0;
virtual bool getPlayerStandingOn (const MWWorld::ConstPtr& object) = 0; ///< @return true if the player is standing on \a object
virtual bool getActorStandingOn (const MWWorld::ConstPtr& object) = 0; ///< @return true if any actor is standing on \a object
virtual bool getPlayerCollidingWith(const MWWorld::ConstPtr& object) = 0; ///< @return true if the player is colliding with \a object
virtual bool getActorCollidingWith (const MWWorld::ConstPtr& object) = 0; ///< @return true if any actor is colliding with \a object
virtual void hurtStandingActors (const MWWorld::ConstPtr& object, float dmgPerSecond) = 0;
///< Apply a health difference to any actors standing on \a object.
/// To hurt actors, healthPerSecond should be a positive value. For a negative value, actors will be healed.
virtual void hurtCollidingActors (const MWWorld::Ptr& object, float dmgPerSecond) = 0;
virtual void hurtCollidingActors (const MWWorld::ConstPtr& object, float dmgPerSecond) = 0;
///< Apply a health difference to any actors colliding with \a object.
/// To hurt actors, healthPerSecond should be a positive value. For a negative value, actors will be healed.

@ -697,7 +697,7 @@ namespace MWPhysics
return mDebugDrawEnabled;
}
void PhysicsSystem::markAsNonSolid(const MWWorld::Ptr &ptr)
void PhysicsSystem::markAsNonSolid(const MWWorld::ConstPtr &ptr)
{
ObjectMap::iterator found = mObjects.find(ptr);
if (found == mObjects.end())
@ -1027,7 +1027,7 @@ namespace MWPhysics
}
};
std::vector<MWWorld::Ptr> PhysicsSystem::getCollisions(const MWWorld::Ptr &ptr, int collisionGroup, int collisionMask) const
std::vector<MWWorld::Ptr> PhysicsSystem::getCollisions(const MWWorld::ConstPtr &ptr, int collisionGroup, int collisionMask) const
{
btCollisionObject* me = NULL;
@ -1337,7 +1337,7 @@ namespace MWPhysics
mDebugDrawer->step();
}
bool PhysicsSystem::isActorStandingOn(const MWWorld::Ptr &actor, const MWWorld::Ptr &object) const
bool PhysicsSystem::isActorStandingOn(const MWWorld::Ptr &actor, const MWWorld::ConstPtr &object) const
{
for (CollisionMap::const_iterator it = mStandingCollisions.begin(); it != mStandingCollisions.end(); ++it)
{
@ -1347,7 +1347,7 @@ namespace MWPhysics
return false;
}
void PhysicsSystem::getActorsStandingOn(const MWWorld::Ptr &object, std::vector<MWWorld::Ptr> &out) const
void PhysicsSystem::getActorsStandingOn(const MWWorld::ConstPtr &object, std::vector<MWWorld::Ptr> &out) const
{
for (CollisionMap::const_iterator it = mStandingCollisions.begin(); it != mStandingCollisions.end(); ++it)
{
@ -1356,13 +1356,13 @@ namespace MWPhysics
}
}
bool PhysicsSystem::isActorCollidingWith(const MWWorld::Ptr &actor, const MWWorld::Ptr &object) const
bool PhysicsSystem::isActorCollidingWith(const MWWorld::Ptr &actor, const MWWorld::ConstPtr &object) const
{
std::vector<MWWorld::Ptr> collisions = getCollisions(object, CollisionType_World, CollisionType_Actor);
return (std::find(collisions.begin(), collisions.end(), actor) != collisions.end());
}
void PhysicsSystem::getActorsCollidingWith(const MWWorld::Ptr &object, std::vector<MWWorld::Ptr> &out) const
void PhysicsSystem::getActorsCollidingWith(const MWWorld::ConstPtr &object, std::vector<MWWorld::Ptr> &out) const
{
std::vector<MWWorld::Ptr> collisions = getCollisions(object, CollisionType_World, CollisionType_Actor);
out.insert(out.end(), collisions.begin(), collisions.end());

@ -82,7 +82,7 @@ namespace MWPhysics
void stepSimulation(float dt);
void debugDraw();
std::vector<MWWorld::Ptr> getCollisions(const MWWorld::Ptr &ptr, int collisionGroup, int collisionMask) const; ///< get handles this object collides with
std::vector<MWWorld::Ptr> getCollisions(const MWWorld::ConstPtr &ptr, int collisionGroup, int collisionMask) const; ///< get handles this object collides with
osg::Vec3f traceDown(const MWWorld::Ptr &ptr, float maxHeight);
std::pair<MWWorld::Ptr, osg::Vec3f> getHitContact(const MWWorld::ConstPtr& actor,
@ -139,23 +139,23 @@ namespace MWPhysics
/// Return true if \a actor has been standing on \a object in this frame
/// This will trigger whenever the object is directly below the actor.
/// It doesn't matter if the actor is stationary or moving.
bool isActorStandingOn(const MWWorld::Ptr& actor, const MWWorld::Ptr& object) const;
bool isActorStandingOn(const MWWorld::Ptr& actor, const MWWorld::ConstPtr& object) const;
/// Get the handle of all actors standing on \a object in this frame.
void getActorsStandingOn(const MWWorld::Ptr& object, std::vector<MWWorld::Ptr>& out) const;
void getActorsStandingOn(const MWWorld::ConstPtr& object, std::vector<MWWorld::Ptr>& out) const;
/// Return true if \a actor has collided with \a object in this frame.
/// This will detect running into objects, but will not detect climbing stairs, stepping up a small object, etc.
bool isActorCollidingWith(const MWWorld::Ptr& actor, const MWWorld::Ptr& object) const;
bool isActorCollidingWith(const MWWorld::Ptr& actor, const MWWorld::ConstPtr& object) const;
/// Get the handle of all actors colliding with \a object in this frame.
void getActorsCollidingWith(const MWWorld::Ptr& object, std::vector<MWWorld::Ptr>& out) const;
void getActorsCollidingWith(const MWWorld::ConstPtr& object, std::vector<MWWorld::Ptr>& out) const;
bool toggleDebugRendering();
/// Mark the given object as a 'non-solid' object. A non-solid object means that
/// \a isOnSolidGround will return false for actors standing on that object.
void markAsNonSolid (const MWWorld::Ptr& ptr);
void markAsNonSolid (const MWWorld::ConstPtr& ptr);
bool isOnSolidGround (const MWWorld::Ptr& actor) const;

@ -70,6 +70,11 @@ const MWWorld::LiveCellRefBase *MWWorld::ConstPtr::getBase() const
return mRef;
}
const MWWorld::ContainerStore *MWWorld::ConstPtr::getContainerStore() const
{
return mContainerStore;
}
MWWorld::ConstPtr::operator const void *()
{
return mRef;

@ -691,10 +691,10 @@ namespace MWWorld
struct FindContainerVisitor
{
Ptr mContainedPtr;
ConstPtr mContainedPtr;
Ptr mResult;
FindContainerVisitor(const Ptr& containedPtr) : mContainedPtr(containedPtr) {}
FindContainerVisitor(const ConstPtr& containedPtr) : mContainedPtr(containedPtr) {}
bool operator() (Ptr ptr)
{
@ -708,7 +708,7 @@ namespace MWWorld
}
};
Ptr World::findContainer(const Ptr& ptr)
Ptr World::findContainer(const ConstPtr& ptr)
{
if (ptr.isInCell())
return Ptr();
@ -1967,23 +1967,23 @@ namespace MWWorld
return false;
}
bool World::isSubmerged(const MWWorld::Ptr &object) const
bool World::isSubmerged(const MWWorld::ConstPtr &object) const
{
return isUnderwater(object, 1.0f/mSwimHeightScale);
}
bool World::isSwimming(const MWWorld::Ptr &object) const
bool World::isSwimming(const MWWorld::ConstPtr &object) const
{
return isUnderwater(object, mSwimHeightScale);
}
bool World::isWading(const MWWorld::Ptr &object) const
bool World::isWading(const MWWorld::ConstPtr &object) const
{
const float kneeDeep = 0.25f;
return isUnderwater(object, kneeDeep);
}
bool World::isUnderwater(const MWWorld::Ptr &object, const float heightRatio) const
bool World::isUnderwater(const MWWorld::ConstPtr &object, const float heightRatio) const
{
osg::Vec3f pos (object.getRefData().getPosition().asVec3());
@ -2148,33 +2148,33 @@ namespace MWWorld
mDoorStates.erase(door);
}
bool World::getPlayerStandingOn (const MWWorld::Ptr& object)
bool World::getPlayerStandingOn (const MWWorld::ConstPtr& object)
{
MWWorld::Ptr player = getPlayerPtr();
return mPhysics->isActorStandingOn(player, object);
}
bool World::getActorStandingOn (const MWWorld::Ptr& object)
bool World::getActorStandingOn (const MWWorld::ConstPtr& object)
{
std::vector<MWWorld::Ptr> actors;
mPhysics->getActorsStandingOn(object, actors);
return !actors.empty();
}
bool World::getPlayerCollidingWith (const MWWorld::Ptr& object)
bool World::getPlayerCollidingWith (const MWWorld::ConstPtr& object)
{
MWWorld::Ptr player = getPlayerPtr();
return mPhysics->isActorCollidingWith(player, object);
}
bool World::getActorCollidingWith (const MWWorld::Ptr& object)
bool World::getActorCollidingWith (const MWWorld::ConstPtr& object)
{
std::vector<MWWorld::Ptr> actors;
mPhysics->getActorsCollidingWith(object, actors);
return !actors.empty();
}
void World::hurtStandingActors(const Ptr &object, float healthPerSecond)
void World::hurtStandingActors(const ConstPtr &object, float healthPerSecond)
{
if (MWBase::Environment::get().getWindowManager()->isGuiMode())
return;
@ -2204,7 +2204,7 @@ namespace MWWorld
}
}
void World::hurtCollidingActors(const Ptr &object, float healthPerSecond)
void World::hurtCollidingActors(const ConstPtr &object, float healthPerSecond)
{
if (MWBase::Environment::get().getWindowManager()->isGuiMode())
return;

@ -155,7 +155,7 @@ namespace MWWorld
const std::vector<std::string>& content, ContentLoader& contentLoader);
float mSwimHeightScale;
bool isUnderwater(const MWWorld::Ptr &object, const float heightRatio) const;
bool isUnderwater(const MWWorld::ConstPtr &object, const float heightRatio) const;
///< helper function for implementing isSwimming(), isSubmerged(), isWading()
bool mTeleportEnabled;
@ -269,7 +269,7 @@ namespace MWWorld
virtual Ptr searchPtrViaActorId (int actorId);
///< Search is limited to the active cells.
virtual MWWorld::Ptr findContainer (const MWWorld::Ptr& ptr);
virtual MWWorld::Ptr findContainer (const MWWorld::ConstPtr& ptr);
///< Return a pointer to a liveCellRef which contains \a ptr.
/// \note Search is limited to the active cells.
@ -464,10 +464,10 @@ namespace MWWorld
virtual bool isFlying(const MWWorld::Ptr &ptr) const;
virtual bool isSlowFalling(const MWWorld::Ptr &ptr) const;
///Is the head of the creature underwater?
virtual bool isSubmerged(const MWWorld::Ptr &object) const;
virtual bool isSwimming(const MWWorld::Ptr &object) const;
virtual bool isSubmerged(const MWWorld::ConstPtr &object) const;
virtual bool isSwimming(const MWWorld::ConstPtr &object) const;
virtual bool isUnderwater(const MWWorld::CellStore* cell, const osg::Vec3f &pos) const;
virtual bool isWading(const MWWorld::Ptr &object) const;
virtual bool isWading(const MWWorld::ConstPtr &object) const;
virtual bool isOnGround(const MWWorld::Ptr &ptr) const;
virtual osg::Matrixf getActorHeadTransform(const MWWorld::ConstPtr& actor) const;
@ -500,14 +500,14 @@ namespace MWWorld
/// @note throws an exception when invoked on a teleport door
virtual void activateDoor(const MWWorld::Ptr& door, int state);
virtual bool getPlayerStandingOn (const MWWorld::Ptr& object); ///< @return true if the player is standing on \a object
virtual bool getActorStandingOn (const MWWorld::Ptr& object); ///< @return true if any actor is standing on \a object
virtual bool getPlayerCollidingWith(const MWWorld::Ptr& object); ///< @return true if the player is colliding with \a object
virtual bool getActorCollidingWith (const MWWorld::Ptr& object); ///< @return true if any actor is colliding with \a object
virtual void hurtStandingActors (const MWWorld::Ptr& object, float dmgPerSecond);
virtual bool getPlayerStandingOn (const MWWorld::ConstPtr& object); ///< @return true if the player is standing on \a object
virtual bool getActorStandingOn (const MWWorld::ConstPtr& object); ///< @return true if any actor is standing on \a object
virtual bool getPlayerCollidingWith(const MWWorld::ConstPtr& object); ///< @return true if the player is colliding with \a object
virtual bool getActorCollidingWith (const MWWorld::ConstPtr& object); ///< @return true if any actor is colliding with \a object
virtual void hurtStandingActors (const MWWorld::ConstPtr& object, float dmgPerSecond);
///< Apply a health difference to any actors standing on \a object.
/// To hurt actors, healthPerSecond should be a positive value. For a negative value, actors will be healed.
virtual void hurtCollidingActors (const MWWorld::Ptr& object, float dmgPerSecond);
virtual void hurtCollidingActors (const MWWorld::ConstPtr& object, float dmgPerSecond);
///< Apply a health difference to any actors colliding with \a object.
/// To hurt actors, healthPerSecond should be a positive value. For a negative value, actors will be healed.

Loading…
Cancel
Save