1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-05 17:45:34 +00:00

Use some const references where appropriate

This commit is contained in:
Chris Robinson 2013-02-07 16:18:29 -08:00
parent cbdd459500
commit d47d2216f2
3 changed files with 41 additions and 34 deletions

View file

@ -409,8 +409,8 @@ namespace MWWorld
void PhysicsSystem::rotateObject (const Ptr& ptr) void PhysicsSystem::rotateObject (const Ptr& ptr)
{ {
Ogre::SceneNode* node = ptr.getRefData().getBaseNode(); Ogre::SceneNode* node = ptr.getRefData().getBaseNode();
std::string handle = node->getName(); const std::string &handle = node->getName();
Ogre::Quaternion rotation = node->getOrientation(); const Ogre::Quaternion &rotation = node->getOrientation();
if (OEngine::Physic::PhysicActor* act = mEngine->getCharacter(handle)) if (OEngine::Physic::PhysicActor* act = mEngine->getCharacter(handle))
{ {
//Needs to be changed //Needs to be changed
@ -428,7 +428,7 @@ namespace MWWorld
void PhysicsSystem::scaleObject (const Ptr& ptr) void PhysicsSystem::scaleObject (const Ptr& ptr)
{ {
Ogre::SceneNode* node = ptr.getRefData().getBaseNode(); Ogre::SceneNode* node = ptr.getRefData().getBaseNode();
std::string handle = node->getName(); const std::string &handle = node->getName();
if(handleToMesh.find(handle) != handleToMesh.end()) if(handleToMesh.find(handle) != handleToMesh.end())
{ {
removeObject(handle); removeObject(handle);

View file

@ -27,8 +27,9 @@ namespace Physic
COL_RAYCASTING = BIT(3) COL_RAYCASTING = BIT(3)
}; };
PhysicActor::PhysicActor(std::string name, std::string mesh, PhysicEngine* engine, Ogre::Vector3 position, Ogre::Quaternion rotation, float scale): PhysicActor::PhysicActor(const std::string &name, const std::string &mesh, PhysicEngine *engine, const Ogre::Vector3 &position, const Ogre::Quaternion &rotation, float scale)
mName(name), mEngine(engine), mMesh(mesh), mBoxScaledTranslation(0,0,0), mBoxRotationInverse(0,0,0,0), mBody(0), onGround(false), collisionMode(false), mBoxRotation(0,0,0,0), verticalForce(0.0f) : mName(name), mEngine(engine), mMesh(mesh), mBoxScaledTranslation(0,0,0), mBoxRotationInverse(0,0,0,0)
, mBody(0), onGround(false), collisionMode(false), mBoxRotation(0,0,0,0), verticalForce(0.0f)
{ {
mBody = mEngine->createAndAdjustRigidBody(mMesh, mName, scale, position, rotation, &mBoxScaledTranslation, &mBoxRotation); mBody = mEngine->createAndAdjustRigidBody(mMesh, mName, scale, position, rotation, &mBoxScaledTranslation, &mBoxRotation);
Ogre::Quaternion inverse = mBoxRotation.Inverse(); Ogre::Quaternion inverse = mBoxRotation.Inverse();
@ -38,7 +39,8 @@ namespace Physic
PhysicActor::~PhysicActor() PhysicActor::~PhysicActor()
{ {
if(mBody){ if(mBody)
{
mEngine->dynamicsWorld->removeRigidBody(mBody); mEngine->dynamicsWorld->removeRigidBody(mBody);
delete mBody; delete mBody;
} }
@ -321,18 +323,21 @@ namespace Physic
mHeightFieldMap.erase(name); mHeightFieldMap.erase(name);
} }
void PhysicEngine::adjustRigidBody(RigidBody* body, Ogre::Vector3 position, Ogre::Quaternion rotation, void PhysicEngine::adjustRigidBody(RigidBody* body, const Ogre::Vector3 &position, const Ogre::Quaternion &rotation,
Ogre::Vector3 scaledBoxTranslation, Ogre::Quaternion boxRotation){ const Ogre::Vector3 &scaledBoxTranslation, const Ogre::Quaternion &boxRotation)
{
btTransform tr; btTransform tr;
rotation = rotation * boxRotation; Ogre::Quaternion boxrot = rotation * boxRotation;
Ogre::Vector3 transrot = rotation * scaledBoxTranslation; Ogre::Vector3 transrot = boxrot * scaledBoxTranslation;
Ogre::Vector3 newPosition = transrot + position; Ogre::Vector3 newPosition = transrot + position;
tr.setOrigin(btVector3(newPosition.x, newPosition.y, newPosition.z)); tr.setOrigin(btVector3(newPosition.x, newPosition.y, newPosition.z));
tr.setRotation(btQuaternion(rotation.x,rotation.y,rotation.z,rotation.w)); tr.setRotation(btQuaternion(boxrot.x,boxrot.y,boxrot.z,boxrot.w));
body->setWorldTransform(tr); body->setWorldTransform(tr);
} }
void PhysicEngine::boxAdjustExternal(std::string mesh, RigidBody* body, float scale, Ogre::Vector3 position, Ogre::Quaternion rotation){ void PhysicEngine::boxAdjustExternal(const std::string &mesh, RigidBody* body,
float scale, const Ogre::Vector3 &position, const Ogre::Quaternion &rotation)
{
std::string sid = (boost::format("%07.3f") % scale).str(); std::string sid = (boost::format("%07.3f") % scale).str();
std::string outputstring = mesh + sid; std::string outputstring = mesh + sid;
//std::cout << "The string" << outputstring << "\n"; //std::cout << "The string" << outputstring << "\n";
@ -345,7 +350,8 @@ namespace Physic
adjustRigidBody(body, position, rotation, shape->boxTranslation * scale, shape->boxRotation); adjustRigidBody(body, position, rotation, shape->boxTranslation * scale, shape->boxRotation);
} }
RigidBody* PhysicEngine::createAndAdjustRigidBody(std::string mesh,std::string name,float scale, Ogre::Vector3 position, Ogre::Quaternion rotation, RigidBody* PhysicEngine::createAndAdjustRigidBody(const std::string &mesh, const std::string &name,
float scale, const Ogre::Vector3 &position, const Ogre::Quaternion &rotation,
Ogre::Vector3* scaledBoxTranslation, Ogre::Quaternion* boxRotation) Ogre::Vector3* scaledBoxTranslation, Ogre::Quaternion* boxRotation)
{ {
std::string sid = (boost::format("%07.3f") % scale).str(); std::string sid = (boost::format("%07.3f") % scale).str();
@ -406,7 +412,7 @@ namespace Physic
} }
} }
void PhysicEngine::removeRigidBody(std::string name) void PhysicEngine::removeRigidBody(const std::string &name)
{ {
RigidBodyContainer::iterator it = ObjectMap.find(name); RigidBodyContainer::iterator it = ObjectMap.find(name);
if (it != ObjectMap.end() ) if (it != ObjectMap.end() )
@ -426,7 +432,7 @@ namespace Physic
} }
} }
void PhysicEngine::deleteRigidBody(std::string name) void PhysicEngine::deleteRigidBody(const std::string &name)
{ {
RigidBodyContainer::iterator it = ObjectMap.find(name); RigidBodyContainer::iterator it = ObjectMap.find(name);
if (it != ObjectMap.end() ) if (it != ObjectMap.end() )
@ -446,7 +452,7 @@ namespace Physic
} }
} }
RigidBody* PhysicEngine::getRigidBody(std::string name) RigidBody* PhysicEngine::getRigidBody(const std::string &name)
{ {
RigidBodyContainer::iterator it = ObjectMap.find(name); RigidBodyContainer::iterator it = ObjectMap.find(name);
if (it != ObjectMap.end() ) if (it != ObjectMap.end() )
@ -469,8 +475,8 @@ namespace Physic
} }
} }
void PhysicEngine::addCharacter(std::string name, std::string mesh, void PhysicEngine::addCharacter(const std::string &name, const std::string &mesh,
Ogre::Vector3 position, float scale, Ogre::Quaternion rotation) const Ogre::Vector3 &position, float scale, const Ogre::Quaternion &rotation)
{ {
// Remove character with given name, so we don't make memory // Remove character with given name, so we don't make memory
// leak when character would be added twice // leak when character would be added twice
@ -483,7 +489,7 @@ namespace Physic
PhysicActorMap[name] = newActor; PhysicActorMap[name] = newActor;
} }
void PhysicEngine::removeCharacter(std::string name) void PhysicEngine::removeCharacter(const std::string &name)
{ {
//std::cout << "remove"; //std::cout << "remove";
PhysicActorContainer::iterator it = PhysicActorMap.find(name); PhysicActorContainer::iterator it = PhysicActorMap.find(name);
@ -499,7 +505,7 @@ namespace Physic
} }
} }
PhysicActor* PhysicEngine::getCharacter(std::string name) PhysicActor* PhysicEngine::getCharacter(const std::string &name)
{ {
PhysicActorContainer::iterator it = PhysicActorMap.find(name); PhysicActorContainer::iterator it = PhysicActorMap.find(name);
if (it != PhysicActorMap.end() ) if (it != PhysicActorMap.end() )

View file

@ -60,7 +60,7 @@ namespace Physic
class PhysicActor class PhysicActor
{ {
public: public:
PhysicActor(std::string name, std::string mesh, PhysicEngine *engine, Ogre::Vector3 position, Ogre::Quaternion rotation, float scale); PhysicActor(const std::string &name, const std::string &mesh, PhysicEngine *engine, const Ogre::Vector3 &position, const Ogre::Quaternion &rotation, float scale);
~PhysicActor(); ~PhysicActor();
@ -178,19 +178,21 @@ namespace Physic
* Creates a RigidBody. It does not add it to the simulation. * Creates a RigidBody. It does not add it to the simulation.
* After created, the body is set to the correct rotation, position, and scale * After created, the body is set to the correct rotation, position, and scale
*/ */
RigidBody* createAndAdjustRigidBody(std::string mesh,std::string name,float scale, Ogre::Vector3 position, Ogre::Quaternion rotation, RigidBody* createAndAdjustRigidBody(const std::string &mesh, const std::string &name,
float scale, const Ogre::Vector3 &position, const Ogre::Quaternion &rotation,
Ogre::Vector3* scaledBoxTranslation = 0, Ogre::Quaternion* boxRotation = 0); Ogre::Vector3* scaledBoxTranslation = 0, Ogre::Quaternion* boxRotation = 0);
/** /**
* Adjusts a rigid body to the right position and rotation * Adjusts a rigid body to the right position and rotation
*/ */
void adjustRigidBody(RigidBody* body, Ogre::Vector3 position, Ogre::Quaternion rotation, void adjustRigidBody(RigidBody* body, const Ogre::Vector3 &position, const Ogre::Quaternion &rotation,
Ogre::Vector3 scaledBoxTranslation = Ogre::Vector3::ZERO, Ogre::Quaternion boxRotation = Ogre::Quaternion::IDENTITY); const Ogre::Vector3 &scaledBoxTranslation = Ogre::Vector3::ZERO,
const Ogre::Quaternion &boxRotation = Ogre::Quaternion::IDENTITY);
/** /**
Mainly used to (but not limited to) adjust rigid bodies based on box shapes to the right position and rotation. Mainly used to (but not limited to) adjust rigid bodies based on box shapes to the right position and rotation.
*/ */
void boxAdjustExternal(std::string mesh, RigidBody* body, float scale, Ogre::Vector3 position, Ogre::Quaternion rotation); void boxAdjustExternal(const std::string &mesh, RigidBody* body, float scale, const Ogre::Vector3 &position, const Ogre::Quaternion &rotation);
/** /**
* Add a HeightField to the simulation * Add a HeightField to the simulation
*/ */
@ -211,35 +213,35 @@ namespace Physic
/** /**
* Remove a RigidBody from the simulation. It does not delete it, and does not remove it from the RigidBodyMap. * Remove a RigidBody from the simulation. It does not delete it, and does not remove it from the RigidBodyMap.
*/ */
void removeRigidBody(std::string name); void removeRigidBody(const std::string &name);
/** /**
* Delete a RigidBody, and remove it from RigidBodyMap. * Delete a RigidBody, and remove it from RigidBodyMap.
*/ */
void deleteRigidBody(std::string name); void deleteRigidBody(const std::string &name);
/** /**
* Return a pointer to a given rigid body. * Return a pointer to a given rigid body.
* TODO:check if exist * TODO:check if exist
*/ */
RigidBody* getRigidBody(std::string name); RigidBody* getRigidBody(const std::string &name);
/** /**
* Create and add a character to the scene, and add it to the ActorMap. * Create and add a character to the scene, and add it to the ActorMap.
*/ */
void addCharacter(std::string name, std::string mesh, void addCharacter(const std::string &name, const std::string &mesh,
Ogre::Vector3 position, float scale, Ogre::Quaternion rotation); const Ogre::Vector3 &position, float scale, const Ogre::Quaternion &rotation);
/** /**
* Remove a character from the scene. TODO:delete it! for now, a small memory leak^^ done? * Remove a character from the scene. TODO:delete it! for now, a small memory leak^^ done?
*/ */
void removeCharacter(std::string name); void removeCharacter(const std::string &name);
/** /**
* Return a pointer to a character * Return a pointer to a character
* TODO:check if the actor exist... * TODO:check if the actor exist...
*/ */
PhysicActor* getCharacter(std::string name); PhysicActor* getCharacter(const std::string &name);
/** /**
* This step the simulation of a given time. * This step the simulation of a given time.
@ -307,7 +309,6 @@ namespace Physic
BtOgre::DebugDrawer* mDebugDrawer; BtOgre::DebugDrawer* mDebugDrawer;
bool isDebugCreated; bool isDebugCreated;
bool mDebugActive; bool mDebugActive;
}; };