Turn physics into a singleton get for 2 processes
This commit is contained in:
parent
63bad92765
commit
6a635e1a56
@ -71,7 +71,7 @@ void FixedPipelineRenderer::render(float dt, bool is_loading)
|
||||
// is not set up properly. This is only used for
|
||||
// the bullet debug view.
|
||||
if (UserConfigParams::m_artist_debug_mode)
|
||||
Physics::getInstance()->draw();
|
||||
Physics::get()->draw();
|
||||
} // for i<world->getNumKarts()
|
||||
|
||||
// Set the viewport back to the full screen for race gui
|
||||
|
@ -2022,9 +2022,9 @@ void IrrDriver::update(float dt, bool is_loading)
|
||||
irr_driver->getActualScreenSize().Height);
|
||||
}
|
||||
|
||||
if (!is_loading && Physics::getInstance())
|
||||
if (!is_loading && Physics::get())
|
||||
{
|
||||
IrrDebugDrawer* debug_drawer = Physics::getInstance()->getDebugDrawer();
|
||||
IrrDebugDrawer* debug_drawer = Physics::get()->getDebugDrawer();
|
||||
if (debug_drawer != NULL && debug_drawer->debugEnabled())
|
||||
{
|
||||
debug_drawer->beginNextFrame();
|
||||
|
@ -1193,7 +1193,7 @@ FrameBuffer *PostProcessing::render(scene::ICameraSceneNode * const camnode,
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDisable(GL_BLEND);
|
||||
|
||||
Physics *physics = Physics::getInstance();
|
||||
Physics *physics = Physics::get();
|
||||
|
||||
if (isRace && UserConfigParams::m_dof && (physics == NULL || !physics->isDebug()))
|
||||
{
|
||||
|
@ -500,12 +500,12 @@ void ShaderBasedRenderer::debugPhysics()
|
||||
// the bullet debug view, since otherwise the camera
|
||||
// is not set up properly. This is only used for
|
||||
// the bullet debug view.
|
||||
if(Physics::getInstance())
|
||||
if(Physics::get())
|
||||
{
|
||||
if (UserConfigParams::m_artist_debug_mode)
|
||||
Physics::getInstance()->draw();
|
||||
Physics::get()->draw();
|
||||
|
||||
IrrDebugDrawer* debug_drawer = Physics::getInstance()->getDebugDrawer();
|
||||
IrrDebugDrawer* debug_drawer = Physics::get()->getDebugDrawer();
|
||||
if (debug_drawer != NULL && debug_drawer->debugEnabled())
|
||||
{
|
||||
const std::map<video::SColor, std::vector<float> >& lines =
|
||||
|
@ -156,7 +156,7 @@ void Flyable::createPhysics(float forw_offset, const Vec3 &velocity,
|
||||
m_shape = shape;
|
||||
createBody(m_mass, trans, m_shape, restitution);
|
||||
m_user_pointer.set(this);
|
||||
Physics::getInstance()->addBody(getBody());
|
||||
Physics::get()->addBody(getBody());
|
||||
|
||||
m_body->setGravity(gravity);
|
||||
if (gravity.length2() != 0.0f && m_do_terrain_info)
|
||||
@ -237,7 +237,7 @@ void Flyable::removePhysics()
|
||||
}
|
||||
if (m_body.get())
|
||||
{
|
||||
Physics::getInstance()->removeBody(m_body.get());
|
||||
Physics::get()->removeBody(m_body.get());
|
||||
m_body.reset();
|
||||
}
|
||||
} // removePhysics
|
||||
|
@ -233,7 +233,7 @@ void RubberBand::checkForHit(const Vec3 &k, const Vec3 &p)
|
||||
m_owner->getBody()->getBroadphaseHandle()->m_collisionFilterGroup = 0;
|
||||
|
||||
// Do the raycast
|
||||
Physics::getInstance()->getPhysicsWorld()->rayTest(k, p, ray_callback);
|
||||
Physics::get()->getPhysicsWorld()->rayTest(k, p, ray_callback);
|
||||
// Reset collision groups
|
||||
m_plunger->getBody()->getBroadphaseHandle()->m_collisionFilterGroup = old_plunger_group;
|
||||
if(m_owner->getBody()->getBroadphaseHandle())
|
||||
|
@ -113,7 +113,7 @@ void AbstractKart::changeKart(const std::string& new_ident,
|
||||
// Reset previous kart (including delete old animation above)
|
||||
reset();
|
||||
// Remove kart body
|
||||
Physics::getInstance()->removeKart(this);
|
||||
Physics::get()->removeKart(this);
|
||||
loadKartProperties(new_ident, handicap, ri);
|
||||
} // changeKart
|
||||
|
||||
|
@ -64,7 +64,7 @@ AbstractKartAnimation::AbstractKartAnimation(AbstractKart* kart,
|
||||
{
|
||||
m_created_transform = kart->getTrans();
|
||||
kart->setKartAnimation(this);
|
||||
Physics::getInstance()->removeKart(m_kart);
|
||||
Physics::get()->removeKart(m_kart);
|
||||
kart->getSkidding()->reset();
|
||||
kart->getSlipstream()->reset();
|
||||
if (kart->isSquashed())
|
||||
@ -97,7 +97,7 @@ AbstractKartAnimation::~AbstractKartAnimation()
|
||||
m_kart->setTrans(transform);
|
||||
// Reset all btKart members (bounce back ticks / rotation ticks..)
|
||||
m_kart->getVehicle()->reset();
|
||||
Physics::getInstance()->addKart(m_kart);
|
||||
Physics::get()->addKart(m_kart);
|
||||
}
|
||||
} // ~AbstractKartAnimation
|
||||
|
||||
|
@ -115,7 +115,7 @@ void SpareTireAI::spawn(int ticks_to_last)
|
||||
findDefaultPath();
|
||||
m_timer = ticks_to_last;
|
||||
|
||||
Physics::getInstance()->addKart(m_kart);
|
||||
Physics::get()->addKart(m_kart);
|
||||
m_kart->startEngineSFX();
|
||||
m_kart->getKartGFX()->reset();
|
||||
if (m_kart->getNode())
|
||||
|
@ -285,7 +285,7 @@ Kart::~Kart()
|
||||
// Ghost karts don't have a body
|
||||
if(m_body)
|
||||
{
|
||||
Physics::getInstance()->removeKart(this);
|
||||
Physics::get()->removeKart(this);
|
||||
}
|
||||
|
||||
delete m_max_speed;
|
||||
@ -317,8 +317,8 @@ void Kart::reset()
|
||||
// don't have one).
|
||||
if(m_body)
|
||||
{
|
||||
Physics::getInstance()->removeKart(this);
|
||||
Physics::getInstance()->addKart(this);
|
||||
Physics::get()->removeKart(this);
|
||||
Physics::get()->addKart(this);
|
||||
}
|
||||
|
||||
m_min_nitro_ticks = 0;
|
||||
@ -748,7 +748,7 @@ void Kart::createPhysics()
|
||||
// Create the actual vehicle
|
||||
// -------------------------
|
||||
m_vehicle_raycaster.reset(
|
||||
new btKartRaycaster(Physics::getInstance()->getPhysicsWorld(),
|
||||
new btKartRaycaster(Physics::get()->getPhysicsWorld(),
|
||||
stk_config->m_smooth_normals &&
|
||||
Track::getCurrentTrack()->smoothNormals()));
|
||||
m_vehicle.reset(new btKart(m_body.get(), m_vehicle_raycaster.get(), this));
|
||||
@ -1308,7 +1308,7 @@ void Kart::eliminate()
|
||||
{
|
||||
if (!getKartAnimation())
|
||||
{
|
||||
Physics::getInstance()->removeKart(this);
|
||||
Physics::get()->removeKart(this);
|
||||
}
|
||||
if (m_stars_effect)
|
||||
{
|
||||
|
@ -189,7 +189,7 @@ void World::init()
|
||||
Scripting::ScriptEngine::getInstance()->loadScript(script_path, true);
|
||||
main_loop->renderGUI(1200);
|
||||
// Create the physics
|
||||
Physics::getInstance<Physics>();
|
||||
Physics::create();
|
||||
main_loop->renderGUI(1300);
|
||||
unsigned int num_karts = RaceManager::get()->getNumberOfKarts();
|
||||
//assert(num_karts > 0);
|
||||
@ -634,7 +634,7 @@ World::~World()
|
||||
|
||||
// In case that the track is not found, Physics was not instantiated,
|
||||
// but kill handles this correctly.
|
||||
Physics::kill();
|
||||
Physics::destroy();
|
||||
|
||||
Scripting::ScriptEngine::kill();
|
||||
|
||||
@ -756,7 +756,7 @@ void World::resetAllKarts()
|
||||
{
|
||||
// Reset the physics 'remaining' time to 0 so that the number
|
||||
// of timesteps is reproducible if doing a physics-based history run
|
||||
Physics::getInstance()->getPhysicsWorld()->resetLocalTime();
|
||||
Physics::get()->getPhysicsWorld()->resetLocalTime();
|
||||
|
||||
// If track checking is requested, check all rescue positions if
|
||||
// they are high enough.
|
||||
@ -831,7 +831,7 @@ void World::resetAllKarts()
|
||||
(*i)->getNormal() * -g : Vec3(0, -g, 0));
|
||||
}
|
||||
for(int i=0; i<stk_config->getPhysicsFPS(); i++)
|
||||
Physics::getInstance()->update(1);
|
||||
Physics::get()->update(1);
|
||||
|
||||
for ( KartList::iterator i=m_karts.begin(); i!=m_karts.end(); i++)
|
||||
{
|
||||
@ -1146,7 +1146,7 @@ void World::update(int ticks)
|
||||
PROFILER_POP_CPU_MARKER();
|
||||
|
||||
PROFILER_PUSH_CPU_MARKER("World::update (physics)", 0xa0, 0x7F, 0x00);
|
||||
Physics::getInstance()->update(ticks);
|
||||
Physics::get()->update(ticks);
|
||||
PROFILER_POP_CPU_MARKER();
|
||||
|
||||
PROFILER_POP_CPU_MARKER();
|
||||
|
@ -193,7 +193,7 @@ PhysicalObject::PhysicalObject(bool is_dynamic,
|
||||
// ----------------------------------------------------------------------------
|
||||
PhysicalObject::~PhysicalObject()
|
||||
{
|
||||
Physics::getInstance()->removeBody(m_body);
|
||||
Physics::get()->removeBody(m_body);
|
||||
delete m_body;
|
||||
delete m_motion_state;
|
||||
|
||||
@ -591,7 +591,7 @@ void PhysicalObject::init(const PhysicalObject::Settings& settings)
|
||||
m_body->setActivationState(DISABLE_DEACTIVATION);
|
||||
}
|
||||
|
||||
Physics::getInstance()->addBody(m_body);
|
||||
Physics::get()->addBody(m_body);
|
||||
m_body_added = true;
|
||||
if(m_triangle_mesh)
|
||||
m_triangle_mesh->setBody(m_body);
|
||||
@ -749,7 +749,7 @@ void PhysicalObject::removeBody()
|
||||
{
|
||||
if (m_body_added)
|
||||
{
|
||||
Physics::getInstance()->removeBody(m_body);
|
||||
Physics::get()->removeBody(m_body);
|
||||
m_body_added = false;
|
||||
}
|
||||
} // Remove body
|
||||
@ -761,7 +761,7 @@ void PhysicalObject::addBody()
|
||||
if (!m_body_added)
|
||||
{
|
||||
m_body_added = true;
|
||||
Physics::getInstance()->addBody(m_body);
|
||||
Physics::get()->addBody(m_body);
|
||||
}
|
||||
} // Add body
|
||||
|
||||
|
@ -43,6 +43,31 @@
|
||||
#include "tracks/track.hpp"
|
||||
#include "tracks/track_object.hpp"
|
||||
#include "utils/profiler.hpp"
|
||||
#include "utils/stk_process.hpp"
|
||||
|
||||
//=============================================================================
|
||||
Physics* g_physics[PT_COUNT];
|
||||
// ----------------------------------------------------------------------------
|
||||
Physics* Physics::get()
|
||||
{
|
||||
ProcessType type = STKProcess::getType();
|
||||
return g_physics[type];
|
||||
} // get
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void Physics::create()
|
||||
{
|
||||
ProcessType type = STKProcess::getType();
|
||||
g_physics[type] = new Physics();
|
||||
} // create
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void Physics::destroy()
|
||||
{
|
||||
ProcessType type = STKProcess::getType();
|
||||
delete g_physics[type];
|
||||
g_physics[type] = NULL;
|
||||
} // destroy
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Initialise physics.
|
||||
|
@ -32,7 +32,6 @@
|
||||
#include "physics/irr_debug_drawer.hpp"
|
||||
#include "physics/stk_dynamics_world.hpp"
|
||||
#include "physics/user_pointer.hpp"
|
||||
#include "utils/singleton.hpp"
|
||||
|
||||
class AbstractKart;
|
||||
class STKDynamicsWorld;
|
||||
@ -42,7 +41,6 @@ class Vec3;
|
||||
* \ingroup physics
|
||||
*/
|
||||
class Physics : public btSequentialImpulseConstraintSolver
|
||||
, public AbstractSingleton<Physics>
|
||||
{
|
||||
private:
|
||||
/** Bullet can report the same collision more than once (up to 4
|
||||
@ -149,16 +147,17 @@ private:
|
||||
btDefaultCollisionConfiguration *m_collision_conf;
|
||||
CollisionList m_all_collisions;
|
||||
|
||||
/** Singleton. */
|
||||
static Physics *m_physics;
|
||||
|
||||
Physics();
|
||||
virtual ~Physics();
|
||||
|
||||
// Give the singleton access to the constructor
|
||||
friend class AbstractSingleton<Physics>;
|
||||
|
||||
public:
|
||||
// ----------------------------------------------------------------------------------------
|
||||
static Physics* get();
|
||||
// ----------------------------------------------------------------------------------------
|
||||
static void create();
|
||||
// ----------------------------------------------------------------------------------------
|
||||
static void destroy();
|
||||
// ----------------------------------------------------------------------------------------
|
||||
void init (const Vec3 &min_world, const Vec3 &max_world);
|
||||
void addKart (const AbstractKart *k);
|
||||
void addBody (btRigidBody* b) {m_dynamics_world->addRigidBody(b);}
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "main_loop.hpp"
|
||||
#include "physics/physics.hpp"
|
||||
#include "utils/constants.hpp"
|
||||
#include "utils/log.hpp"
|
||||
#include "utils/time.hpp"
|
||||
|
||||
#include "btBulletDynamicsCommon.h"
|
||||
@ -199,7 +200,7 @@ void TriangleMesh::createPhysicalBody(float friction,
|
||||
info.m_friction = friction;
|
||||
|
||||
m_body=new RigidBodyTriangleMesh(this, info);
|
||||
Physics::getInstance()->addBody(m_body);
|
||||
Physics::get()->addBody(m_body);
|
||||
|
||||
m_body->setUserPointer(&m_user_pointer);
|
||||
m_body->setCollisionFlags(m_body->getCollisionFlags() |
|
||||
@ -219,7 +220,7 @@ void TriangleMesh::removeAll()
|
||||
// Don't free the physical body if it was created outside this object.
|
||||
if(m_body && m_free_body)
|
||||
{
|
||||
Physics::getInstance()->removeBody(m_body);
|
||||
Physics::get()->removeBody(m_body);
|
||||
delete m_body;
|
||||
delete m_motion_state;
|
||||
m_body = NULL;
|
||||
|
@ -1282,7 +1282,7 @@ bool Track::loadMainTrack(const XMLNode &root)
|
||||
// could be relaxed to fix this, it is not certain how the physics
|
||||
// will handle items that are out of the AABB
|
||||
m_aabb_max.setY(m_aabb_max.getY()+30.0f);
|
||||
Physics::getInstance()->init(m_aabb_min, m_aabb_max);
|
||||
Physics::get()->init(m_aabb_min, m_aabb_max);
|
||||
|
||||
ModelDefinitionLoader lodLoader(this);
|
||||
|
||||
|
@ -260,7 +260,7 @@ bool handleContextMenuAction(s32 cmd_id)
|
||||
}
|
||||
|
||||
World *world = World::getWorld();
|
||||
Physics *physics = Physics::getInstance();
|
||||
Physics *physics = Physics::get();
|
||||
SP::SPShader* nv = NULL;
|
||||
#ifndef SERVER_ONLY
|
||||
if (SP::getNormalVisualizer())
|
||||
@ -317,7 +317,7 @@ bool handleContextMenuAction(s32 cmd_id)
|
||||
{
|
||||
irr_driver->resetDebugModes();
|
||||
|
||||
Physics *physics = Physics::getInstance();
|
||||
Physics *physics = Physics::get();
|
||||
if (!physics) return false;
|
||||
physics->setDebugMode(IrrDebugDrawer::DM_NO_KARTS_GRAPHICS);
|
||||
break;
|
||||
|
Loading…
x
Reference in New Issue
Block a user