mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-26 18:35:20 +00:00
Remove unused code. Move the cleanup of global resources used by the PhysicsEngine to PhysicsManager.
This commit is contained in:
parent
37a050873c
commit
7d133d508d
@ -255,7 +255,7 @@ namespace CSVRender
|
|||||||
std::pair<std::string, Ogre::Vector3> result = terrainUnderCursor(event->x(), event->y());
|
std::pair<std::string, Ogre::Vector3> result = terrainUnderCursor(event->x(), event->y());
|
||||||
if(result.first != "")
|
if(result.first != "")
|
||||||
{
|
{
|
||||||
// FIXME: terrain editing
|
// FIXME: terrain editing goes here
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -266,9 +266,9 @@ namespace CSVRender
|
|||||||
|
|
||||||
void MouseState::mouseDoubleClickEvent (QMouseEvent *event)
|
void MouseState::mouseDoubleClickEvent (QMouseEvent *event)
|
||||||
{
|
{
|
||||||
//event->ignore();
|
event->ignore();
|
||||||
mPhysics->toggleDebugRendering(mSceneManager);
|
//mPhysics->toggleDebugRendering(mSceneManager);
|
||||||
mParent->flagAsModified();
|
//mParent->flagAsModified();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MouseState::wheelEvent (QWheelEvent *event)
|
bool MouseState::wheelEvent (QWheelEvent *event)
|
||||||
|
@ -16,8 +16,9 @@
|
|||||||
|
|
||||||
// PLEASE NOTE:
|
// PLEASE NOTE:
|
||||||
//
|
//
|
||||||
// This file is based on libs/openengine/bullet/physic.cpp. The commit history and
|
// This file is based on libs/openengine/bullet/physic.cpp. Please see the commit
|
||||||
// credits for the code below stem from that file.
|
// history and credits for the code below, which is mostly copied from there and
|
||||||
|
// adapted for use with OpenCS.
|
||||||
|
|
||||||
namespace CSVWorld
|
namespace CSVWorld
|
||||||
{
|
{
|
||||||
@ -132,14 +133,17 @@ namespace CSVWorld
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
delete mDynamicsWorld; // FIXME: need to reference count??
|
|
||||||
|
delete mDynamicsWorld;
|
||||||
delete mSolver;
|
delete mSolver;
|
||||||
delete mCollisionConfiguration;
|
delete mCollisionConfiguration;
|
||||||
delete mDispatcher;
|
delete mDispatcher;
|
||||||
delete mBroadphase;
|
delete mBroadphase;
|
||||||
delete mShapeLoader;
|
delete mShapeLoader;
|
||||||
|
|
||||||
delete OEngine::Physic::BulletShapeManager::getSingletonPtr(); // FIXME: need to reference count
|
// NOTE: the global resources such as "BtOgre/DebugLines" and the
|
||||||
|
// BulletShapeManager singleton need to be deleted only when all physics
|
||||||
|
// engines are deleted in PhysicsManager::removeDocument()
|
||||||
}
|
}
|
||||||
|
|
||||||
int PhysicsEngine::toggleDebugRendering(Ogre::SceneManager *sceneMgr)
|
int PhysicsEngine::toggleDebugRendering(Ogre::SceneManager *sceneMgr)
|
||||||
@ -159,8 +163,8 @@ namespace CSVWorld
|
|||||||
mDebugDrawers[sceneMgr]->setDebugMode(1 /*mDebugDrawFlags*/);
|
mDebugDrawers[sceneMgr]->setDebugMode(1 /*mDebugDrawFlags*/);
|
||||||
else
|
else
|
||||||
mDebugDrawers[sceneMgr]->setDebugMode(0);
|
mDebugDrawers[sceneMgr]->setDebugMode(0);
|
||||||
|
mDynamicsWorld->debugDrawWorld();
|
||||||
|
|
||||||
mDynamicsWorld->debugDrawWorld(); // FIXME: call this now?
|
|
||||||
return mDebugDrawers[sceneMgr]->getDebugMode();
|
return mDebugDrawers[sceneMgr]->getDebugMode();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -290,9 +294,7 @@ namespace CSVWorld
|
|||||||
const Ogre::Vector3 &position, const Ogre::Quaternion &rotation)
|
const Ogre::Vector3 &position, const Ogre::Quaternion &rotation)
|
||||||
{
|
{
|
||||||
btTransform tr;
|
btTransform tr;
|
||||||
//Ogre::Quaternion boxrot = rotation * boxRotation;
|
|
||||||
Ogre::Quaternion boxrot = rotation * Ogre::Quaternion::IDENTITY;
|
Ogre::Quaternion boxrot = rotation * Ogre::Quaternion::IDENTITY;
|
||||||
//Ogre::Vector3 transrot = boxrot * scaledBoxTranslation;
|
|
||||||
Ogre::Vector3 transrot = boxrot * Ogre::Vector3::ZERO;
|
Ogre::Vector3 transrot = boxrot * Ogre::Vector3::ZERO;
|
||||||
Ogre::Vector3 newPosition = transrot + position;
|
Ogre::Vector3 newPosition = transrot + position;
|
||||||
|
|
||||||
|
@ -1,26 +1,16 @@
|
|||||||
#ifndef CSV_WORLD_PHYSICSENGINE_H
|
#ifndef CSV_WORLD_PHYSICSENGINE_H
|
||||||
#define CSV_WORLD_PHYSICSENGINE_H
|
#define CSV_WORLD_PHYSICSENGINE_H
|
||||||
|
|
||||||
//#include <vector>
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
#include <BulletDynamics/Dynamics/btRigidBody.h>
|
#include <BulletDynamics/Dynamics/btRigidBody.h>
|
||||||
//#include "BulletCollision/CollisionDispatch/btGhostObject.h"
|
|
||||||
//#include <string>
|
|
||||||
//#include "BulletCollision/CollisionShapes/btScaledBvhTriangleMeshShape.h"
|
|
||||||
//#include <boost/shared_ptr.hpp>
|
|
||||||
|
|
||||||
//#include <OgreVector3.h>
|
|
||||||
//#include <OgreQuaternion.h>
|
|
||||||
|
|
||||||
//class btRigidBody;
|
|
||||||
class btBroadphaseInterface;
|
class btBroadphaseInterface;
|
||||||
class btDefaultCollisionConfiguration;
|
class btDefaultCollisionConfiguration;
|
||||||
class btSequentialImpulseConstraintSolver;
|
class btSequentialImpulseConstraintSolver;
|
||||||
class btCollisionDispatcher;
|
class btCollisionDispatcher;
|
||||||
class btDiscreteDynamicsWorld;
|
class btDiscreteDynamicsWorld;
|
||||||
class btHeightfieldTerrainShape;
|
class btHeightfieldTerrainShape;
|
||||||
//class btCollisionObject;
|
|
||||||
|
|
||||||
namespace BtOgre
|
namespace BtOgre
|
||||||
{
|
{
|
||||||
@ -45,46 +35,6 @@ namespace OEngine
|
|||||||
|
|
||||||
namespace CSVWorld
|
namespace CSVWorld
|
||||||
{
|
{
|
||||||
|
|
||||||
// enum btIDebugDraw::DebugDrawModes
|
|
||||||
// {
|
|
||||||
// DBG_NoDebug=0,
|
|
||||||
// DBG_DrawWireframe = 1,
|
|
||||||
// DBG_DrawAabb=2,
|
|
||||||
// DBG_DrawFeaturesText=4,
|
|
||||||
// DBG_DrawContactPoints=8,
|
|
||||||
// DBG_NoDeactivation=16,
|
|
||||||
// DBG_NoHelpText = 32,
|
|
||||||
// DBG_DrawText=64,
|
|
||||||
// DBG_ProfileTimings = 128,
|
|
||||||
// DBG_EnableSatComparison = 256,
|
|
||||||
// DBG_DisableBulletLCP = 512,
|
|
||||||
// DBG_EnableCCD = 1024,
|
|
||||||
// DBG_DrawConstraints = (1 << 11),
|
|
||||||
// DBG_DrawConstraintLimits = (1 << 12),
|
|
||||||
// DBG_FastWireframe = (1<<13),
|
|
||||||
// DBG_DrawNormals = (1<<14),
|
|
||||||
// DBG_MAX_DEBUG_DRAW_MODE
|
|
||||||
// };
|
|
||||||
//
|
|
||||||
#if 0
|
|
||||||
class CSVDebugDrawer : public BtOgre::DebugDrawer
|
|
||||||
{
|
|
||||||
BtOgre::DebugDrawer *mDebugDrawer;
|
|
||||||
Ogre::SceneManager *mSceneMgr;
|
|
||||||
Ogre::SceneNode *mSceneNode;
|
|
||||||
int mDebugMode;
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
CSVDebugDrawer(Ogre::SceneManager *sceneMgr, btDiscreteDynamicsWorld *dynamicsWorld);
|
|
||||||
~CSVDebugDrawer();
|
|
||||||
|
|
||||||
void setDebugMode(int mode);
|
|
||||||
bool toggleDebugRendering();
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// This class is just an extension of normal btRigidBody in order to add extra info.
|
// This class is just an extension of normal btRigidBody in order to add extra info.
|
||||||
// When bullet give back a btRigidBody, you can just do a static_cast to RigidBody,
|
// When bullet give back a btRigidBody, you can just do a static_cast to RigidBody,
|
||||||
// so one never should use btRigidBody directly!
|
// so one never should use btRigidBody directly!
|
||||||
@ -106,12 +56,9 @@ namespace CSVWorld
|
|||||||
RigidBody* mBody;
|
RigidBody* mBody;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
// The PhysicsEngine class contain everything which is needed for Physic.
|
||||||
* The PhysicsEngine class contain everything which is needed for Physic.
|
// It's needed that Ogre Resources are set up before the PhysicsEngine is created.
|
||||||
* It's needed that Ogre Resources are set up before the PhysicsEngine is created.
|
// Note:deleting it WILL NOT delete the RigidBody!
|
||||||
* Note:deleting it WILL NOT delete the RigidBody!
|
|
||||||
* TODO:unload unused resources?
|
|
||||||
*/
|
|
||||||
class PhysicsEngine
|
class PhysicsEngine
|
||||||
{
|
{
|
||||||
//Bullet Stuff
|
//Bullet Stuff
|
||||||
@ -135,20 +82,6 @@ namespace CSVWorld
|
|||||||
std::map<Ogre::SceneManager *, BtOgre::DebugDrawer *> mDebugDrawers;
|
std::map<Ogre::SceneManager *, BtOgre::DebugDrawer *> mDebugDrawers;
|
||||||
std::map<Ogre::SceneManager *, Ogre::SceneNode *> mDebugSceneNodes;
|
std::map<Ogre::SceneManager *, Ogre::SceneNode *> mDebugSceneNodes;
|
||||||
|
|
||||||
#if 0
|
|
||||||
// from bullet
|
|
||||||
enum CollisionFilterGroups
|
|
||||||
{
|
|
||||||
DefaultFilter = 1,
|
|
||||||
StaticFilter = 2,
|
|
||||||
KinematicFilter = 4,
|
|
||||||
DebrisFilter = 8,
|
|
||||||
SensorTrigger = 16,
|
|
||||||
CharacterFilter = 32,
|
|
||||||
AllFilter = -1 //all bits sets: DefaultFilter | StaticFilter | KinematicFilter | DebrisFilter | SensorTrigger
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
enum CollisionType {
|
enum CollisionType {
|
||||||
CollisionType_Nothing = 0, //<Collide with nothing
|
CollisionType_Nothing = 0, //<Collide with nothing
|
||||||
CollisionType_World = 1<<0, //<Collide with world objects
|
CollisionType_World = 1<<0, //<Collide with world objects
|
||||||
@ -174,13 +107,6 @@ namespace CSVWorld
|
|||||||
// Adjusts a rigid body to the right position and rotation
|
// Adjusts a rigid body to the right position and rotation
|
||||||
void adjustRigidBody(RigidBody* body,
|
void adjustRigidBody(RigidBody* body,
|
||||||
const Ogre::Vector3 &position, const Ogre::Quaternion &rotation);
|
const Ogre::Vector3 &position, const Ogre::Quaternion &rotation);
|
||||||
#if 0
|
|
||||||
// Mainly used to (but not limited to) adjust rigid bodies based on box shapes
|
|
||||||
// to the right position and rotation.
|
|
||||||
void boxAdjustExternal(const std::string &mesh,
|
|
||||||
RigidBody* body, float scale, const Ogre::Vector3 &position,
|
|
||||||
const Ogre::Quaternion &rotation);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Add a HeightField to the simulation
|
// Add a HeightField to the simulation
|
||||||
void addHeightField(float* heights,
|
void addHeightField(float* heights,
|
||||||
@ -204,6 +130,7 @@ namespace CSVWorld
|
|||||||
int toggleDebugRendering(Ogre::SceneManager *sceneMgr);
|
int toggleDebugRendering(Ogre::SceneManager *sceneMgr);
|
||||||
|
|
||||||
void createDebugDraw(Ogre::SceneManager* sceneMgr);
|
void createDebugDraw(Ogre::SceneManager* sceneMgr);
|
||||||
|
|
||||||
void removeDebugDraw(Ogre::SceneManager *sceneMgr);
|
void removeDebugDraw(Ogre::SceneManager *sceneMgr);
|
||||||
|
|
||||||
// Return the closest object hit by a ray. If there are no objects,
|
// Return the closest object hit by a ray. If there are no objects,
|
||||||
@ -226,26 +153,6 @@ namespace CSVWorld
|
|||||||
// Set the debug rendering mode. 0 to turn it off.
|
// Set the debug rendering mode. 0 to turn it off.
|
||||||
// Important Note: this will crash if the Render is not yet initialised!
|
// Important Note: this will crash if the Render is not yet initialised!
|
||||||
void setDebugRenderingMode(int mode);
|
void setDebugRenderingMode(int mode);
|
||||||
#if 0
|
|
||||||
void getObjectAABB(const std::string &mesh,
|
|
||||||
float scale, btVector3 &min, btVector3 &max);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return all objects hit by a ray.
|
|
||||||
*/
|
|
||||||
std::vector< std::pair<float, std::string> > rayTest2(const btVector3 &from, const btVector3 &to, int filterGroup=0xff);
|
|
||||||
|
|
||||||
std::pair<bool, float> sphereCast (float radius, btVector3 &from, btVector3 &to);
|
|
||||||
///< @return (hit, relative distance)
|
|
||||||
|
|
||||||
std::vector<std::string> getCollisions(const std::string &name, int collisionGroup, int collisionMask);
|
|
||||||
|
|
||||||
// Get the nearest object that's inside the given object, filtering out objects of the
|
|
||||||
// provided name
|
|
||||||
std::pair<const RigidBody*,btVector3> getFilteredContact(const std::string &filter,
|
|
||||||
const btVector3 &origin,
|
|
||||||
btCollisionObject *object);
|
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#endif // CSV_WORLD_PHYSICSENGINE_H
|
#endif // CSV_WORLD_PHYSICSENGINE_H
|
||||||
|
@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
#include <OgreRoot.h>
|
||||||
|
#include <openengine/bullet/BulletShapeLoader.h>
|
||||||
|
|
||||||
#include "../render/worldspacewidget.hpp"
|
#include "../render/worldspacewidget.hpp"
|
||||||
#include "physicssystem.hpp"
|
#include "physicssystem.hpp"
|
||||||
|
|
||||||
@ -54,6 +57,18 @@ namespace CSVWorld
|
|||||||
{
|
{
|
||||||
mSceneWidgets.erase(it);
|
mSceneWidgets.erase(it);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// cleanup global resources
|
||||||
|
if(mPhysics.empty())
|
||||||
|
{
|
||||||
|
// delete the extra resources created in removeDebugDraw
|
||||||
|
if (Ogre::MaterialManager::getSingleton().resourceExists("BtOgre/DebugLines"))
|
||||||
|
Ogre::MaterialManager::getSingleton().remove("BtOgre/DebugLines");
|
||||||
|
if (Ogre::ResourceGroupManager::getSingleton().resourceGroupExists("BtOgre"))
|
||||||
|
Ogre::ResourceGroupManager::getSingleton().destroyResourceGroup("BtOgre");
|
||||||
|
|
||||||
|
delete OEngine::Physic::BulletShapeManager::getSingletonPtr();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// called from CSVRender::WorldspaceWidget() to get widgets' association with Document&
|
// called from CSVRender::WorldspaceWidget() to get widgets' association with Document&
|
||||||
|
Loading…
x
Reference in New Issue
Block a user