diff --git a/src/graphics/fixed_pipeline_renderer.cpp b/src/graphics/fixed_pipeline_renderer.cpp index 64c085431..8f4330007 100644 --- a/src/graphics/fixed_pipeline_renderer.cpp +++ b/src/graphics/fixed_pipeline_renderer.cpp @@ -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 igetNumKarts() // Set the viewport back to the full screen for race gui diff --git a/src/graphics/irr_driver.cpp b/src/graphics/irr_driver.cpp index c1982112f..406e86cb2 100644 --- a/src/graphics/irr_driver.cpp +++ b/src/graphics/irr_driver.cpp @@ -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(); diff --git a/src/graphics/post_processing.cpp b/src/graphics/post_processing.cpp index 6be63bc03..c4e158678 100644 --- a/src/graphics/post_processing.cpp +++ b/src/graphics/post_processing.cpp @@ -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())) { diff --git a/src/graphics/shader_based_renderer.cpp b/src/graphics/shader_based_renderer.cpp index 745c33fd2..095da2974 100644 --- a/src/graphics/shader_based_renderer.cpp +++ b/src/graphics/shader_based_renderer.cpp @@ -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 >& lines = diff --git a/src/items/flyable.cpp b/src/items/flyable.cpp index 63fad155c..01fb5b67b 100644 --- a/src/items/flyable.cpp +++ b/src/items/flyable.cpp @@ -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 diff --git a/src/items/rubber_band.cpp b/src/items/rubber_band.cpp index 7869307f4..3556db9bc 100644 --- a/src/items/rubber_band.cpp +++ b/src/items/rubber_band.cpp @@ -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()) diff --git a/src/karts/abstract_kart.cpp b/src/karts/abstract_kart.cpp index dbb76eb1b..231c73175 100644 --- a/src/karts/abstract_kart.cpp +++ b/src/karts/abstract_kart.cpp @@ -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 diff --git a/src/karts/abstract_kart_animation.cpp b/src/karts/abstract_kart_animation.cpp index e4ec8391d..ce2aabaf0 100644 --- a/src/karts/abstract_kart_animation.cpp +++ b/src/karts/abstract_kart_animation.cpp @@ -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 diff --git a/src/karts/controller/spare_tire_ai.cpp b/src/karts/controller/spare_tire_ai.cpp index b331d8137..09210fabc 100644 --- a/src/karts/controller/spare_tire_ai.cpp +++ b/src/karts/controller/spare_tire_ai.cpp @@ -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()) diff --git a/src/karts/kart.cpp b/src/karts/kart.cpp index 157858209..fe8573227 100644 --- a/src/karts/kart.cpp +++ b/src/karts/kart.cpp @@ -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) { diff --git a/src/modes/world.cpp b/src/modes/world.cpp index 5e5d55335..0f98652ab 100644 --- a/src/modes/world.cpp +++ b/src/modes/world.cpp @@ -189,7 +189,7 @@ void World::init() Scripting::ScriptEngine::getInstance()->loadScript(script_path, true); main_loop->renderGUI(1200); // Create the physics - Physics::getInstance(); + 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; igetPhysicsFPS(); 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(); diff --git a/src/physics/physical_object.cpp b/src/physics/physical_object.cpp index 589c5d2cc..2afdbbc1d 100644 --- a/src/physics/physical_object.cpp +++ b/src/physics/physical_object.cpp @@ -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 diff --git a/src/physics/physics.cpp b/src/physics/physics.cpp index a26bc2874..a834c31ea 100644 --- a/src/physics/physics.cpp +++ b/src/physics/physics.cpp @@ -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. diff --git a/src/physics/physics.hpp b/src/physics/physics.hpp index 424b50daf..d75f1d752 100644 --- a/src/physics/physics.hpp +++ b/src/physics/physics.hpp @@ -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 { 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; - 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);} diff --git a/src/physics/triangle_mesh.cpp b/src/physics/triangle_mesh.cpp index 4b9d0c6d0..b4f31d181 100644 --- a/src/physics/triangle_mesh.cpp +++ b/src/physics/triangle_mesh.cpp @@ -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; diff --git a/src/tracks/track.cpp b/src/tracks/track.cpp index 2fdb0a964..314593937 100644 --- a/src/tracks/track.cpp +++ b/src/tracks/track.cpp @@ -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); diff --git a/src/utils/debug.cpp b/src/utils/debug.cpp index 50812620c..b83ee0b05 100644 --- a/src/utils/debug.cpp +++ b/src/utils/debug.cpp @@ -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;