Kaynağa Gözat

Declare physics_globals in separate file

Daniele Bartolini 11 yıl önce
ebeveyn
işleme
1499713cc2

+ 45 - 0
engine/physics/physics.h

@@ -0,0 +1,45 @@
+/*
+Copyright (c) 2013 Daniele Bartolini, Michele Rossi
+Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+*/
+
+#pragma once
+
+namespace crown
+{
+/// @defgroup Physics Physics
+
+/// Global physics-related functions
+///
+/// @ingroup Physics
+namespace physics_globals
+{
+	/// Initializes the physics system.
+	/// This is the place where to create and initialize per-application objects.
+	void init();
+
+	/// It should reverse the actions performed by physics_globals::init().
+	void shutdown();
+} // namespace physics_globals
+} // namespace crown

+ 11 - 10
engine/physics/physics_world.cpp

@@ -45,6 +45,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "debug_line.h"
 #include "color4.h"
 #include "int_setting.h"
+#include "physics.h"
 
 #include "PxPhysicsAPI.h"
 
@@ -81,7 +82,7 @@ namespace crown
 
 static IntSetting g_physics_debug("physics.debug", "Enable physics debug rendering.", 0, 0, 1);
 
-namespace physics_system
+namespace physics_globals
 {
 	using physx::PxFoundation;
 	using physx::PxPhysics;
@@ -233,7 +234,7 @@ namespace physics_system
 			line.clear();
 		}
 	#endif
-} // namespace physics_system
+} // namespace physics_globals
 
 //-----------------------------------------------------------------------------
 PhysicsWorld::PhysicsWorld(World& world)
@@ -256,10 +257,10 @@ PhysicsWorld::PhysicsWorld(World& world)
 	scene_limits.maxNbActors = CE_MAX_ACTORS;
 	CE_ASSERT(scene_limits.isValid(), "Scene limits is not valid");
 
-	PxSceneDesc scene_desc(physics_system::s_physics->getTolerancesScale());
+	PxSceneDesc scene_desc(physics_globals::s_physics->getTolerancesScale());
 	scene_desc.gravity = PxVec3(0.0f, -9.81f, 0.0f);
 	scene_desc.limits = scene_limits;
-	scene_desc.filterShader = physics_system::FilterShader;
+	scene_desc.filterShader = physics_globals::FilterShader;
 	scene_desc.simulationEventCallback = &m_callback;
 	scene_desc.flags = 	PxSceneFlag::eENABLE_ACTIVETRANSFORMS
 					  | PxSceneFlag::eENABLE_KINEMATIC_STATIC_PAIRS
@@ -274,7 +275,7 @@ PhysicsWorld::PhysicsWorld(World& world)
 	}
 
 	CE_ASSERT(scene_desc.isValid(), "Scene is not valid");
-	m_scene = physics_system::s_physics->createScene(scene_desc);
+	m_scene = physics_globals::s_physics->createScene(scene_desc);
 
 	// Create controller manager
 	m_controller_manager = PxCreateControllerManager(*m_scene);
@@ -319,7 +320,7 @@ void PhysicsWorld::destroy_actor(ActorId id)
 //-----------------------------------------------------------------------------
 ControllerId PhysicsWorld::create_controller(const PhysicsResource* pr, SceneGraph& sg, int32_t node)
 {
-	Controller* controller = CE_NEW(m_controllers_pool, Controller)(pr, sg, node, physics_system::s_physics, m_controller_manager);
+	Controller* controller = CE_NEW(m_controllers_pool, Controller)(pr, sg, node, physics_globals::s_physics, m_controller_manager);
 	return id_array::create(m_controllers, controller);
 }
 
@@ -333,7 +334,7 @@ void PhysicsWorld::destroy_controller(ControllerId id)
 //-----------------------------------------------------------------------------
 JointId	PhysicsWorld::create_joint(const PhysicsResource* pr, const uint32_t index, const Actor& actor_0, const Actor& actor_1)
 {
-	Joint* joint = CE_NEW(m_joints_pool, Joint)(physics_system::s_physics, pr, index, actor_0, actor_1);
+	Joint* joint = CE_NEW(m_joints_pool, Joint)(physics_globals::s_physics, pr, index, actor_0, actor_1);
 	return id_array::create(m_joints, joint);
 }
 
@@ -463,12 +464,12 @@ void PhysicsWorld::draw_debug()
 {
 	#if defined(CROWN_DEBUG)
 		if (g_physics_debug)
-			physics_system::draw_debug_lines(m_scene, *m_debug_line);
+			physics_globals::draw_debug_lines(m_scene, *m_debug_line);
 	#endif
 }
 
-PxPhysics* PhysicsWorld::physx_physics() { return physics_system::s_physics; }
-PxCooking* PhysicsWorld::physx_cooking() { return physics_system::s_cooking; }
+PxPhysics* PhysicsWorld::physx_physics() { return physics_globals::s_physics; }
+PxCooking* PhysicsWorld::physx_cooking() { return physics_globals::s_cooking; }
 PxScene* PhysicsWorld::physx_scene() { return m_scene; }
 
 } // namespace crown

+ 0 - 15
engine/physics/physics_world.h

@@ -55,21 +55,6 @@ using physx::PxCooking;
 namespace crown
 {
 
-/// @defgroup Physics Physics
-
-/// Global physics-related functions
-///
-/// @ingroup Physics
-namespace physics_system
-{
-	/// Initializes the physics system.
-	/// This is the place where to create and initialize per-application objects.
-	void init();
-
-	/// It should reverse the actions performed by physics_system::init().
-	void shutdown();
-} // namespace physics_system
-
 //-----------------------------------------------------------------------------
 struct SceneGraph;
 class World;