Do not store a btTransform into Projectile class: reduce its size by 112 bytes

pull/593/head
fredzio 4 years ago
parent 20aefb5f5f
commit 744cfc6a51

@ -3,14 +3,11 @@
#include <BulletCollision/CollisionShapes/btSphereShape.h> #include <BulletCollision/CollisionShapes/btSphereShape.h>
#include <BulletCollision/CollisionDispatch/btCollisionWorld.h> #include <BulletCollision/CollisionDispatch/btCollisionWorld.h>
#include <LinearMath/btVector3.h>
#include <components/misc/convert.hpp> #include <components/misc/convert.hpp>
#include "../mwworld/class.hpp" #include "../mwworld/class.hpp"
#include "collisiontype.hpp" #include "collisiontype.hpp"
#include "memory"
#include "mtphysics.hpp" #include "mtphysics.hpp"
#include "projectile.hpp" #include "projectile.hpp"
@ -55,7 +52,9 @@ void Projectile::commitPositionChange()
std::scoped_lock lock(mMutex); std::scoped_lock lock(mMutex);
if (mTransformUpdatePending) if (mTransformUpdatePending)
{ {
mCollisionObject->setWorldTransform(mLocalTransform); auto& trans = mCollisionObject->getWorldTransform();
trans.setOrigin(Misc::Convert::toBullet(mPosition));
mCollisionObject->setWorldTransform(trans);
mTransformUpdatePending = false; mTransformUpdatePending = false;
} }
} }
@ -63,14 +62,14 @@ void Projectile::commitPositionChange()
void Projectile::setPosition(const osg::Vec3f &position) void Projectile::setPosition(const osg::Vec3f &position)
{ {
std::scoped_lock lock(mMutex); std::scoped_lock lock(mMutex);
mLocalTransform.setOrigin(Misc::Convert::toBullet(position)); mPosition = position;
mTransformUpdatePending = true; mTransformUpdatePending = true;
} }
osg::Vec3f Projectile::getPosition() const osg::Vec3f Projectile::getPosition() const
{ {
std::scoped_lock lock(mMutex); std::scoped_lock lock(mMutex);
return Misc::Convert::toOsg(mLocalTransform.getOrigin()); return mPosition;
} }
bool Projectile::canTraverseWater() const bool Projectile::canTraverseWater() const

@ -6,12 +6,13 @@
#include <mutex> #include <mutex>
#include <optional> #include <optional>
#include <LinearMath/btVector3.h>
#include "ptrholder.hpp" #include "ptrholder.hpp"
class btCollisionObject; class btCollisionObject;
class btCollisionShape; class btCollisionShape;
class btConvexShape; class btConvexShape;
class btVector3;
namespace osg namespace osg
{ {
@ -76,7 +77,6 @@ namespace MWPhysics
btConvexShape* mConvexShape; btConvexShape* mConvexShape;
std::unique_ptr<btCollisionObject> mCollisionObject; std::unique_ptr<btCollisionObject> mCollisionObject;
btTransform mLocalTransform;
bool mTransformUpdatePending; bool mTransformUpdatePending;
bool mCanCrossWaterSurface; bool mCanCrossWaterSurface;
bool mCrossedWaterSurface; bool mCrossedWaterSurface;
@ -84,6 +84,7 @@ namespace MWPhysics
MWWorld::Ptr mCaster; MWWorld::Ptr mCaster;
MWWorld::Ptr mHitTarget; MWWorld::Ptr mHitTarget;
std::optional<btVector3> mWaterHitPosition; std::optional<btVector3> mWaterHitPosition;
osg::Vec3f mPosition;
btVector3 mHitPosition; btVector3 mHitPosition;
btVector3 mHitNormal; btVector3 mHitNormal;

Loading…
Cancel
Save