瀏覽代碼

Add physics_config to ResourcePackage

Daniele Bartolini 11 年之前
父節點
當前提交
71b9980113
共有 5 個文件被更改,包括 35 次插入8 次删除
  1. 0 5
      engine/Device.cpp
  2. 0 3
      engine/Device.h
  3. 8 0
      engine/resource/PackageResource.cpp
  4. 17 0
      engine/resource/PackageResource.h
  5. 10 0
      engine/resource/ResourcePackage.h

+ 0 - 5
engine/Device.cpp

@@ -177,9 +177,6 @@ void Device::init()
 	CE_LOGD("Crown Engine initialized.");
 	CE_LOGD("Initializing Game...");
 
-	m_physics_config = m_resource_manager->load(PHYSICS_CONFIG_EXTENSION, "global");
-	m_resource_manager->flush();
-
 	m_is_init = true;
 	start();
 
@@ -198,8 +195,6 @@ void Device::shutdown()
 	// Shutdowns the game
 	m_lua_environment->call_global("shutdown", 0);
 
-	m_resource_manager->unload(m_physics_config);
-
 	CE_LOGD("Releasing audio...");
 	audio_system::shutdown();
 

+ 0 - 3
engine/Device.h

@@ -218,9 +218,6 @@ protected:
 	Bundle* m_resource_bundle;
 	WorldManager* m_world_manager;
 
-	// Configuration resources
-	ResourceId m_physics_config;
-
 private:
 
 	// Disable copying

+ 8 - 0
engine/resource/PackageResource.cpp

@@ -56,6 +56,7 @@ void compile(Filesystem& fs, const char* resource_path, File* out_file)
 	const uint32_t num_materials = root.key("material").size();
 	const uint32_t num_fonts     = root.key("font").size();
 	const uint32_t num_levels    = root.key("level").size();
+	const uint32_t num_phyconfs  = root.key("physics_config").size();
 
 	// Write header
 	bw.write(num_textures);
@@ -98,6 +99,10 @@ void compile(Filesystem& fs, const char* resource_path, File* out_file)
 	offt += sizeof(ResourceId) * num_fonts;
 	bw.write(offt);
 
+	bw.write(num_phyconfs);
+	offt += sizeof(ResourceId) * num_phyconfs;
+	bw.write(offt);
+
 	// Write resource ids
 	for (uint32_t i = 0; i < num_textures; i++)
 		bw.write(root.key("texture")[i].to_resource_id("texture"));
@@ -128,6 +133,9 @@ void compile(Filesystem& fs, const char* resource_path, File* out_file)
 
 	for (uint32_t i = 0; i < num_levels; i++)
 		bw.write(root.key("level")[i].to_resource_id("level"));
+
+	for (uint32_t i = 0; i < num_phyconfs; i++)
+		bw.write(root.key("physics_config")[i].to_resource_id("physics_config"));
 }
 
 } // namespace package_resource

+ 17 - 0
engine/resource/PackageResource.h

@@ -58,6 +58,8 @@ struct PackageHeader
 	uint32_t fonts_offset;
 	uint32_t num_levels;
 	uint32_t levels_offset;
+	uint32_t num_physics_configs;
+	uint32_t physics_configs_offset;
 };
 
 struct PackageResource
@@ -153,6 +155,12 @@ struct PackageResource
 		return ((PackageHeader*) this)->num_levels;
 	}
 
+	//-----------------------------------------------------------------------------
+	uint32_t num_physics_configs() const
+	{
+		return ((PackageHeader*) this)->num_physics_configs;
+	}
+
 	//-----------------------------------------------------------------------------
 	ResourceId get_texture_id(uint32_t i) const
 	{
@@ -243,6 +251,15 @@ struct PackageResource
 		return begin[i];
 	}
 
+	//-----------------------------------------------------------------------------
+	ResourceId get_physics_config_id(uint32_t i) const
+	{
+		CE_ASSERT(i < num_physics_configs(), "Index out of bounds");
+
+		ResourceId* begin = (ResourceId*) ((char*) this + ((PackageHeader*) this)->physics_configs_offset);
+		return begin[i];
+	}
+
 private:
 
 	// Disable construction

+ 10 - 0
engine/resource/ResourcePackage.h

@@ -105,11 +105,21 @@ public:
 		{
 			m_resource_manager->load(LEVEL_TYPE, m_package->get_level_id(i));
 		}
+
+		for (uint32_t i = 0; i < m_package->num_physics_configs(); i++)
+		{
+			m_resource_manager->load(PHYSICS_CONFIG_TYPE, m_package->get_physics_config_id(i));
+		}
 	}
 
 	/// Unloads all the resources in the package.
 	void unload()
 	{
+		for (uint32_t i = 0; i < m_package->num_physics_configs(); i++)
+		{
+			m_resource_manager->unload(m_package->get_physics_config_id(i));
+		}
+
 		for (uint32_t i = 0; i < m_package->num_levels(); i++)
 		{
 			m_resource_manager->unload(m_package->get_level_id(i));