Преглед изворни кода

Add World::physics_world()

Daniele Bartolini пре 12 година
родитељ
комит
341754442f
2 измењених фајлова са 18 додато и 6 уклоњено
  1. 15 5
      engine/World.cpp
  2. 3 1
      engine/World.h

+ 15 - 5
engine/World.cpp

@@ -41,7 +41,6 @@ World::World()
 	, m_camera_pool(default_allocator(), MAX_CAMERAS, sizeof(Camera), CE_ALIGNOF(Camera))
 	, m_unit_to_sound(default_allocator())
 {
-	create_actor(0, ActorType::DYNAMIC);
 }
 
 //-----------------------------------------------------------------------------
@@ -73,7 +72,6 @@ void World::destroy_unit(UnitId id)
 	// Destry unit's scene graph
 	m_scenegraph_manager.destroy_scene_graph(&unit->m_scene_graph);
 
-	unit->destroy();
 	CE_DELETE(m_unit_pool, unit);
 	m_units.destroy(id);
 }
@@ -137,8 +135,14 @@ Actor* World::lookup_actor(ActorId actor)
 //-----------------------------------------------------------------------------
 void World::update(float dt)
 {
+	// Update units
+	for (Unit** uu = m_units.begin(); uu != m_units.end(); uu++)
+	{
+		(*uu)->update();
+	}
+
 	// Update scene graphs
-	m_scenegraph_manager.update();
+	//m_scenegraph_manager.update();
 
 	// Update physics world
 	m_physics_world.update(dt);
@@ -203,9 +207,9 @@ void World::destroy_sprite(SpriteId id)
 }
 
 //-----------------------------------------------------------------------------
-ActorId	World::create_actor(int32_t node, ActorType::Enum type)
+ActorId	World::create_actor(ActorType::Enum type)
 {
-	return m_physics_world.create_actor(node, type);
+	return m_physics_world.create_actor(type);
 }
 
 //-----------------------------------------------------------------------------
@@ -305,4 +309,10 @@ void World::set_sound_volume(SoundId id, const float vol)
 	sound.volume = vol;
 }
 
+//-----------------------------------------------------------------------------
+PhysicsWorld* World::physics_world()
+{
+	return &m_physics_world;
+}
+
 } // namespace crown

+ 3 - 1
engine/World.h

@@ -111,7 +111,7 @@ public:
 	SpriteId							create_sprite(ResourceId id, SceneGraph& sg, int32_t node);
 	void								destroy_sprite(SpriteId id);
 
-	ActorId								create_actor(int32_t node, ActorType::Enum type);
+	ActorId								create_actor(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);
@@ -122,6 +122,8 @@ public:
 	void								set_sound_range(SoundId sound, const float range);
 	void								set_sound_volume(SoundId sound, const float vol);
 
+	PhysicsWorld*						physics_world();
+
 private:
 
 	PoolAllocator						m_unit_pool;