Jelajahi Sumber

update World according to physics implementation

mikymod 12 tahun lalu
induk
melakukan
53664116f1
2 mengubah file dengan 38 tambahan dan 6 penghapusan
  1. 26 5
      engine/World.cpp
  2. 12 1
      engine/World.h

+ 26 - 5
engine/World.cpp

@@ -50,10 +50,13 @@ UnitId World::spawn_unit(const char* name, const Vector3& pos, const Quaternion&
 	UnitResource* ur = (UnitResource*) device()->resource_manager()->lookup(UNIT_EXTENSION, name);
 
 	// Create a new scene graph
-	SceneGraph* graph = m_graph_manager.create_scene_graph();
+	SceneGraph* sg = m_scenegraph_manager.create_scene_graph();
+
+	// Create a new physics graph
+	PhysicsGraph* pg = m_physicsgraph_manager.create_physics_graph();
 
 	// Allocate memory for unit
-	Unit* unit = CE_NEW(m_unit_pool, Unit)(*this, *graph, ur, Matrix4x4(rot, pos));
+	Unit* unit = CE_NEW(m_unit_pool, Unit)(*this, *sg, *pg, ur, Matrix4x4(rot, pos));
 
 	// Create Id for the unit
 	const UnitId unit_id = m_units.create(unit);
@@ -69,8 +72,8 @@ void World::destroy_unit(UnitId id)
 
 	Unit* unit = m_units.lookup(id);
 
-	// Destory unit's scene graph
-	m_graph_manager.destroy_scene_graph(&unit->m_scene_graph);
+	// Destry unit's scene graph
+	m_scenegraph_manager.destroy_scene_graph(&unit->m_scene_graph);
 
 	unit->destroy();
 	CE_DELETE(m_unit_pool, unit);
@@ -127,11 +130,17 @@ Sprite* World::lookup_sprite(SpriteId sprite)
 	return m_render_world.lookup_sprite(sprite);
 }
 
+//-----------------------------------------------------------------------------
+Actor* World::lookup_actor(ActorId actor)
+{
+	return m_physics_world.lookup_actor(actor);
+}
+
 //-----------------------------------------------------------------------------
 void World::update(float /*dt*/)
 {
 	// Update scene graphs
-	m_graph_manager.update();
+	m_scenegraph_manager.update();
 }
 
 //-----------------------------------------------------------------------------
@@ -192,6 +201,18 @@ void World::destroy_sprite(SpriteId id)
 	m_render_world.destroy_sprite(id);
 }
 
+//-----------------------------------------------------------------------------
+ActorId	World::create_actor(PhysicsGraph& pg, int32_t node, ActorType::Enum type)
+{
+	return m_physics_world.create_actor(pg, node, type);
+}
+
+//-----------------------------------------------------------------------------
+void World::destroy_actor(ActorId id)
+{
+	m_physics_world.destroy_actor(id);
+}
+
 //-----------------------------------------------------------------------------
 SoundId World::play_sound(const char* name, const bool loop, const float volume, const Vector3& pos, const float range)
 {

+ 12 - 1
engine/World.h

@@ -34,9 +34,12 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "Camera.h"
 #include "Vector.h"
 #include "RenderWorld.h"
+#include "PhysicsWorld.h"
 #include "SoundRenderer.h"
 #include "PoolAllocator.h"
 #include "SceneGraphManager.h"
+#include "PhysicsGraphManager.h"
+#include "PhysicsTypes.h"
 
 namespace crown
 {
@@ -50,6 +53,7 @@ typedef Id CameraId;
 typedef Id MeshId;
 typedef Id SoundId;
 typedef Id SpriteId;
+typedef Id ActorId;
 
 struct Sound
 {
@@ -72,6 +76,7 @@ struct UnitToSound
 
 class Mesh;
 class Sprite;
+class Actor;
 class Vector3;
 class Quaternion;
 
@@ -92,6 +97,7 @@ public:
 	Camera*								lookup_camera(CameraId camera);
 	Mesh*								lookup_mesh(MeshId mesh);
 	Sprite*								lookup_sprite(SpriteId sprite);
+	Actor*								lookup_actor(ActorId actor);
 
 	RenderWorld&						render_world();
 	void								update(float dt);
@@ -106,6 +112,9 @@ public:
 	SpriteId							create_sprite(ResourceId id, SceneGraph& sg, int32_t node);
 	void								destroy_sprite(SpriteId id);
 
+	ActorId								create_actor(PhysicsGraph& pg, int32_t node, ActorType::Enum type);
+	void								destroy_actor(ActorId id);
+
 	SoundId								play_sound(const char* name, const bool loop = false, const float volume = 1.0f, const Vector3& pos = Vector3::ZERO, const float range = 50.0f);
 	void								stop_sound(SoundId sound);
 	void								link_sound(SoundId sound, Unit* unit, int32_t node);
@@ -123,12 +132,14 @@ private:
 	IdArray<MAX_CAMERAS, Camera*>		m_cameras;
 	IdArray<MAX_SOUNDS, Sound> 			m_sounds;
 
-	SceneGraphManager					m_graph_manager;
+	SceneGraphManager					m_scenegraph_manager;
+	PhysicsGraphManager					m_physicsgraph_manager;
 
 	// Connections
 	List<UnitToSound>					m_unit_to_sound;
 
 	RenderWorld							m_render_world;
+	PhysicsWorld						m_physics_world;
 };
 
 } // namespace crown