Просмотр исходного кода

Rename data() and lookup() to get()

Daniele Bartolini 11 лет назад
Родитель
Сommit
c4c7465294

+ 3 - 3
engine/Device.cpp

@@ -426,7 +426,7 @@ ResourcePackage* Device::create_resource_package(const char* name)
 	ResourceId package_id = m_resource_manager->load("package", name);
 	m_resource_manager->flush();
 
-	PackageResource* package_res = (PackageResource*) m_resource_manager->data(package_id);
+	PackageResource* package_res = (PackageResource*) m_resource_manager->get(package_id);
 	ResourcePackage* package = CE_NEW(default_allocator(), ResourcePackage)(*m_resource_manager, package_id, package_res);
 
 	return package;
@@ -464,12 +464,12 @@ void Device::reload(const char* type, const char* name)
 		}
 
 		ResourceId old_res_id = m_resource_manager->resource_id(type, name);
-		const void* old_res = m_resource_manager->data(old_res_id);
+		const void* old_res = m_resource_manager->get(old_res_id);
 		m_resource_manager->unload(old_res_id, true);
 
 		ResourceId res_id = m_resource_manager->load(type, name);
 		m_resource_manager->flush();
-		const void* new_res = m_resource_manager->data(res_id);
+		const void* new_res = m_resource_manager->get(res_id);
 
 		uint32_t type_hash = string::murmur2_32(type, string::strlen(type), 0);
 

+ 1 - 1
engine/audio/backend/ALSoundWorld.cpp

@@ -236,7 +236,7 @@ public:
 
 	virtual SoundInstanceId play(const char* name, bool loop, float volume, const Vector3& pos)
 	{
-		return play((SoundResource*) device()->resource_manager()->lookup(SOUND_EXTENSION, name), loop, volume, pos);
+		return play((SoundResource*) device()->resource_manager()->get(SOUND_EXTENSION, name), loop, volume, pos);
 	}
 
 	SoundInstanceId play(SoundResource* sr, bool loop, float volume, const Vector3& pos)

+ 1 - 1
engine/audio/backend/SLESSoundWorld.cpp

@@ -379,7 +379,7 @@ public:
 
 	virtual SoundInstanceId play(const char* name, bool loop, float volume, const Vector3& /*pos*/)
 	{
-		return play((SoundResource*) device()->resource_manager()->lookup(SOUND_EXTENSION, name), loop, volume);
+		return play((SoundResource*) device()->resource_manager()->get(SOUND_EXTENSION, name), loop, volume);
 	}
 
 	SoundInstanceId play(SoundResource* sr, bool loop, float volume)

+ 1 - 1
engine/lua/LuaEnvironment.cpp

@@ -54,7 +54,7 @@ void LuaEnvironment::load_and_execute(const char* res_name)
 	// Load the resource
 	ResourceId res_id = resman->load("lua", res_name);
 	resman->flush();
-	LuaResource* lr = (LuaResource*) resman->data(res_id);
+	LuaResource* lr = (LuaResource*) resman->get(res_id);
 	
 	lua_pushcfunction(m_L, lua_system::error_handler);
 	luaL_loadbuffer(m_L, (const char*) lr->program(), lr->size(), res_name);

+ 1 - 1
engine/lua/LuaSystem.cpp

@@ -128,7 +128,7 @@ namespace lua_system
 		const ResourceId lua_res = device()->resource_manager()->load("lua", filename);
 		device()->resource_manager()->flush();
 
-		const LuaResource* lr = (LuaResource*) device()->resource_manager()->data(lua_res);
+		const LuaResource* lr = (LuaResource*) device()->resource_manager()->get(lua_res);
 		luaL_loadbuffer(L, (const char*) lr->program(), lr->size(), "");
 
 		device()->resource_manager()->unload(lua_res);

+ 1 - 1
engine/physics/Actor.cpp

@@ -165,7 +165,7 @@ void Actor::create_objects()
 			}
 			case PhysicsShapeType::CONVEX_MESH:
 			{
-				MeshResource* resource = (MeshResource*) device()->resource_manager()->data(shape.resource);
+				MeshResource* resource = (MeshResource*) device()->resource_manager()->get(shape.resource);
 
 				PxConvexMeshDesc convex_mesh_desc;
 				convex_mesh_desc.points.count		= resource->num_vertices();

+ 1 - 1
engine/physics/PhysicsWorld.cpp

@@ -280,7 +280,7 @@ PhysicsWorld::PhysicsWorld(World& world)
 	m_controller_manager = PxCreateControllerManager(*m_scene);
 	CE_ASSERT(m_controller_manager != NULL, "Failed to create PhysX controller manager");
 
-	m_resource = (PhysicsConfigResource*) device()->resource_manager()->lookup("physics_config", "global");
+	m_resource = (PhysicsConfigResource*) device()->resource_manager()->get("physics_config", "global");
 
 	#if defined(CROWN_DEBUG) || defined(CROWN_DEVELOPMENT)
 		m_scene->setVisualizationParameter(PxVisualizationParameter::eSCALE, 1);

+ 5 - 5
engine/renderers/Gui.cpp

@@ -232,8 +232,8 @@ void Gui::draw_image(const char* material, const Vector3& pos, const Vector2& si
 	inds[4] = 2;
 	inds[5] = 3;
 
-	const MaterialResource* mr = (MaterialResource*) device()->resource_manager()->lookup("material", material);
-	const TextureResource* tr = (TextureResource*) device()->resource_manager()->data(mr->get_texture_layer(0));
+	const MaterialResource* mr = (MaterialResource*) device()->resource_manager()->get("material", material);
+	const TextureResource* tr = (TextureResource*) device()->resource_manager()->get(mr->get_texture_layer(0));
 
 	r->set_layer_view(1, matrix4x4::IDENTITY);
 	r->set_layer_projection(1, m_projection);
@@ -257,7 +257,7 @@ void Gui::draw_text(const char* str, const char* font, uint32_t font_size, const
 {
 	Renderer* r = device()->renderer();
 
-	const FontResource* resource = (FontResource*) device()->resource_manager()->lookup("font", font);
+	const FontResource* resource = (FontResource*) device()->resource_manager()->get("font", font);
 	Vector2 m_pen;
 
 	const float scale = ((float)font_size / (float)resource->font_size());
@@ -357,8 +357,8 @@ void Gui::draw_text(const char* str, const char* font, uint32_t font_size, const
 		}
 	}
 
-	const MaterialResource* mr = (MaterialResource*) device()->resource_manager()->data(resource->material());
-	const TextureResource* tr = (TextureResource*) device()->resource_manager()->data(mr->get_texture_layer(0));
+	const MaterialResource* mr = (MaterialResource*) device()->resource_manager()->get(resource->material());
+	const TextureResource* tr = (TextureResource*) device()->resource_manager()->get(mr->get_texture_layer(0));
 
 	r->set_layer_view(1, matrix4x4::IDENTITY);
 	r->set_layer_projection(1, m_projection);

+ 1 - 1
engine/renderers/Material.cpp

@@ -55,7 +55,7 @@ const MaterialResource* Material::resource()
 void Material::bind(Renderer& r, UniformId uniform)
 {
 	const ResourceId tr_id = m_resource->get_texture_layer(0);
-	const TextureResource* tr = (TextureResource*) device()->resource_manager()->data(tr_id);
+	const TextureResource* tr = (TextureResource*) device()->resource_manager()->get(tr_id);
 
 	r.set_texture(0, uniform, tr->texture(), TEXTURE_FILTER_LINEAR | TEXTURE_WRAP_U_CLAMP_REPEAT | TEXTURE_WRAP_V_CLAMP_REPEAT);
 }

+ 10 - 10
engine/resource/ResourceManager.cpp

@@ -83,7 +83,15 @@ void ResourceManager::unload(ResourceId name, bool force)
 }
 
 //-----------------------------------------------------------------------------
-const void* ResourceManager::lookup(const char* type, const char* name) const
+bool ResourceManager::has(ResourceId name) const
+{
+	ResourceEntry* entry = find(name);
+
+	return entry != NULL;
+}
+
+//-----------------------------------------------------------------------------
+const void* ResourceManager::get(const char* type, const char* name) const
 {
 	ResourceId id = resource_id(type, name);
 	ResourceEntry* entry = find(id);
@@ -95,15 +103,7 @@ const void* ResourceManager::lookup(const char* type, const char* name) const
 }
 
 //-----------------------------------------------------------------------------
-bool ResourceManager::has(ResourceId name) const
-{
-	ResourceEntry* entry = find(name);
-
-	return entry != NULL;
-}
-
-//-----------------------------------------------------------------------------
-const void* ResourceManager::data(ResourceId name) const
+const void* ResourceManager::get(ResourceId name) const
 {
 	CE_ASSERT(has(name), "Resource not loaded: " "%.16"PRIx64"", name.id);
 

+ 26 - 26
engine/resource/ResourceManager.h

@@ -61,13 +61,13 @@ class ResourceManager
 public:
 
 	/// The resources will be loaded from @a bundle.
-							ResourceManager(Bundle& bundle, uint32_t seed);
-							~ResourceManager();
+	ResourceManager(Bundle& bundle, uint32_t seed);
+	~ResourceManager();
 
 	/// Loads the resource by @a type and @a name and returns its ResourceId.
 	/// @note
 	/// You have to call is_loaded() to check if the loading process is actually completed.
-	ResourceId				load(const char* type, const char* name);
+	ResourceId load(const char* type, const char* name);
 
 	/// Unloads the resource @a name, freeing up all the memory associated by it
 	/// and eventually any global object associated with it.
@@ -75,63 +75,63 @@ public:
 	/// is greater than 1.
 	/// @warning
 	/// Use @a force option only if you know - exactly - what you are doing.
-	void					unload(ResourceId name, bool force = false);
-
-	/// Returns the resource instance associated to the given @a type and @a name.
-	const void*				lookup(const char* type, const char* name) const;
+	void unload(ResourceId name, bool force = false);
 
 	/// Returns whether the manager has the @a name resource into
 	/// its list of resources.
 	/// @warning
 	/// Having a resource does not mean that the resource is
 	/// ready to be used; See is_loaded().
-	bool					has(ResourceId name) const;
+	bool has(ResourceId name) const;
+
+	/// Returns the resource instance associated to the given @a type and @a name.
+	const void* get(const char* type, const char* name) const;
 
 	/// Returns the data associated with the @a name resource.
 	/// You will have to cast the returned pointer accordingly.
-	const void*				data(ResourceId name) const;
-	
+	const void* get(ResourceId name) const;
+
 	/// Returns whether the @a name resource is loaded (i.e. whether
 	/// you can use the data associated with it).
-	bool					is_loaded(ResourceId name) const;
+	bool is_loaded(ResourceId name) const;
 
 	/// Returns the number of references to the resource @a name;
-	uint32_t				references(ResourceId name) const;
+	uint32_t references(ResourceId name) const;
 
 	/// Forces all of the loading requests to complete before preceeding.
-	void					flush();
+	void flush();
 
 	/// Returns the seed used to generate resource name hashes.
-	uint32_t				seed() const;
+	uint32_t seed() const;
 
-	ResourceId				resource_id(const char* type, const char* name) const;
+	ResourceId resource_id(const char* type, const char* name) const;
 
 private:
 
 
 	// Returns the entry of the given id.
-	ResourceEntry*			find(ResourceId id) const;
+	ResourceEntry* find(ResourceId id) const;
 
 	// Polls the resource loader for loaded resources.
-	void					poll_resource_loader();
+	void poll_resource_loader();
 
 	// Loads the resource by name and type and returns its ResourceId.
-	ResourceId				load(uint32_t type, ResourceId name);
-	void					online(ResourceId name, void* resource);
+	ResourceId load(uint32_t type, ResourceId name);
+	void online(ResourceId name, void* resource);
 
 private:
 
-	ProxyAllocator			m_resource_heap;
-	ResourceLoader			m_loader;
-	uint32_t				m_seed;
+	ProxyAllocator m_resource_heap;
+	ResourceLoader m_loader;
+	uint32_t m_seed;
 
-	Queue<PendingRequest>	m_pendings;
-	Array<ResourceEntry>		m_resources;
+	Queue<PendingRequest> m_pendings;
+	Array<ResourceEntry> m_resources;
 
 private:
 
-	friend class			ResourcePackage;
-	friend class			Device;
+	friend class ResourcePackage;
+	friend class Device;
 };
 
 } // namespace crown

+ 1 - 1
engine/tests/decoders.cpp

@@ -12,7 +12,7 @@ int main(int argc, char** argv)
 	ResourceId rid = engine->resource_manager()->load("sound", "sounds/untrue");
 	engine->resource_manager()->flush();
 
-	SoundResource* stream = (SoundResource*)engine->resource_manager()->data(rid);
+	SoundResource* stream = (SoundResource*)engine->resource_manager()->get(rid);
 
 	OggDecoder decoder((char*)stream->data(), stream->size());
 

+ 4 - 4
engine/world/Unit.cpp

@@ -171,13 +171,13 @@ void Unit::create_renderable_objects()
 
 		if (renderable.type == UnitRenderable::MESH)
 		{
-			MeshResource* mr = (MeshResource*) device()->resource_manager()->data(renderable.resource);
+			MeshResource* mr = (MeshResource*) device()->resource_manager()->get(renderable.resource);
 			MeshId mesh = m_world.render_world()->create_mesh(mr, m_scene_graph, renderable.node);
 			add_mesh(renderable.name, mesh);
 		}
 		else if (renderable.type == UnitRenderable::SPRITE)
 		{
-			SpriteResource* sr = (SpriteResource*) device()->resource_manager()->data(renderable.resource);
+			SpriteResource* sr = (SpriteResource*) device()->resource_manager()->get(renderable.resource);
 			SpriteId sprite = m_world.render_world()->create_sprite(sr, m_scene_graph, renderable.node);
 			add_sprite(renderable.name, sprite);
 		}
@@ -190,7 +190,7 @@ void Unit::create_renderable_objects()
 	// Create materials
 	if (m_resource->material_resource().id != 0)
 	{
-		MaterialResource* mr = (MaterialResource*) device()->resource_manager()->data(m_resource->material_resource());
+		MaterialResource* mr = (MaterialResource*) device()->resource_manager()->get(m_resource->material_resource());
 		add_material(string::murmur2_32("default", string::strlen("default"), 0), m_world.render_world()->create_material(mr));
 	}
 }
@@ -200,7 +200,7 @@ void Unit::create_physics_objects()
 {
 	if (m_resource->physics_resource().id != 0)
 	{
-		const PhysicsResource* pr = (PhysicsResource*) device()->resource_manager()->data(m_resource->physics_resource());
+		const PhysicsResource* pr = (PhysicsResource*) device()->resource_manager()->get(m_resource->physics_resource());
 
 		// Create controller if any
 		if (pr->has_controller())

+ 2 - 2
engine/world/World.cpp

@@ -83,7 +83,7 @@ UnitId World::spawn_unit(const char* name, const Vector3& pos, const Quaternion&
 //-----------------------------------------------------------------------------
 UnitId World::spawn_unit(ResourceId id, const Vector3& pos, const Quaternion& rot)
 {
-	UnitResource* ur = (UnitResource*) device()->resource_manager()->data(id);
+	UnitResource* ur = (UnitResource*) device()->resource_manager()->get(id);
 	return spawn_unit(id, ur, pos, rot);
 }
 
@@ -273,7 +273,7 @@ void World::destroy_debug_line(DebugLine* line)
 //-----------------------------------------------------------------------------
 void World::load_level(const char* name)
 {
-	const LevelResource* res = (LevelResource*) device()->resource_manager()->lookup(LEVEL_EXTENSION, name);
+	const LevelResource* res = (LevelResource*) device()->resource_manager()->get(LEVEL_EXTENSION, name);
 
 	for (uint32_t i = 0; i < res->num_units(); i++)
 	{