Exemple #1
0
bool ResourcesManager::AddResource(const gd::String & name, const gd::String & filename)
{
    if ( HasResource(name) ) return false;

    std::shared_ptr<ImageResource> image(new ImageResource);
    image->SetFile(filename);
    image->SetName(name);

    resources.push_back(image);

    return true;
}
bool ResourcesManager::AddResource(const gd::String & name, const gd::String & filename, const gd::String & kind)
{
    if ( HasResource(name) ) return false;

    std::shared_ptr<Resource> res = CreateResource(kind);
    res->SetFile(filename);
    res->SetName(name);

    resources.push_back(res);

    return true;
}
Exemple #3
0
CDuiImgBase * DuiResProviderPE::LoadImage( LPCTSTR strType,UINT uID )
{
    if(!HasResource(strType,uID)) return NULL;
    CDuiImgBase *pImg=GetImageDecoder()->CreateDuiImage(strType);
    if(pImg)
    {
        if(!pImg->LoadFromResource(m_hResInst,strType,uID))
        {
            GetImageDecoder()->DestoryDuiImage(pImg);
            pImg=NULL;
        }
    }
    return pImg;
}
Exemple #4
0
CDuiImgBase * DuiResProviderFiles::LoadImage( LPCTSTR strType,UINT uID )
{
    if(!HasResource(strType,uID)) return NULL;
    CDuiImgBase * pImg=GetImageDecoder()->CreateDuiImage(strType);
    if(pImg)
    {
        CDuiStringT strPath=GetRes(strType,uID);
        if(!pImg->LoadFromFile(strPath))
        {
            GetImageDecoder()->DestoryDuiImage(pImg);
            pImg=NULL;
        }
    }
    return pImg;
}
bool ResourcesManager::AddResource(const gd::Resource & resource)
{
    if ( HasResource(resource.GetName()) ) return false;

    try
    {
        const Resource & castedResource = dynamic_cast<const Resource&>(resource);
        std::shared_ptr<Resource> newResource = std::shared_ptr<Resource>(castedResource.Clone());
        if ( newResource == std::shared_ptr<Resource>() ) return false;

        resources.push_back(newResource);
    }
    catch(...) { std::cout << "WARNING: Tried to add a resource which is not a GD C++ Platform Resource to a GD C++ Platform project"; std::cout << char(7); }

    return true;
}
Exemple #6
0
bool KEYImporter::HasResource(const char* resname, const ResourceDesc &type)
{
	return HasResource(resname, type.GetKeyType());
}
Exemple #7
0
void ResourceManager::HandleRequestCompletion() {
	if (!m_Stream->IsComplete()) {
		return;
	}

	// Locks the buffer handle
    ResourceBufferHandle bufHandle = m_Stream->AcquireBufferHandle();

    if (!bufHandle.IsError()) {
    	// Allocates and copies memory for the data loaded

    	ASSERT(!HasResource(bufHandle.GetPath()));

    	ResourceType_t type = bufHandle.GetType();

    	if (type == kResourceTypePng) {
    		// Creates a texture from the png data; png data is discarded

    		// Reads the png data

    		PngReader reader;

			reader.InitReader(bufHandle.GetData(), bufHandle.GetSize());

			ImageHeader header;
			bool headerRead = reader.ReadHeader(&header);
			ASSERT(headerRead);

			size_t pngDataSize = header.size;

			byte_t* pngData = new byte_t[pngDataSize];

			bool dataRead = reader.ReadData(pngData);
			ASSERT(dataRead);


			// Creates the texture with the data
			if (header.colorType == kImageColorRGBA) {
				m_TexRegistryPtr->CreateTexture(bufHandle.GetPath(), kTextureColorRGBA, header.width, header.height, (const void*)pngData);
			}
			else if (header.colorType == kImageColorRGB) {
				m_TexRegistryPtr->CreateTexture(bufHandle.GetPath(), kTextureColorRGB, header.width, header.height, (const void*)pngData);
			}


			// Stores the png resource as a resource with null data

			ResourceId_t id = CreateResourceId(bufHandle.GetPath());

			Resource res;
			res.m_Data = nullptr;

			m_Registry.Insert(id, res);

			delete[] pngData;
    	}
    	else {

    		// Stores all other types of data in a resource

    		ResourceId_t id = CreateResourceId(bufHandle.GetPath());

    		void* allocMem = m_Allocator.Alloc(bufHandle.GetSize());
    		memcpy(allocMem, (void*)bufHandle.GetData(), bufHandle.GetSize());

	    	Resource res;
	    	res.m_Data = (byte_t*)allocMem;
	    	
	    	m_Registry.Insert(id, res);
    	}
    }
    else {
    	LOG_PRINT("ResourceManager: error loading \'%s\' during async io", bufHandle.GetPath());
    	return;
    }

    // Unlocks the buffer handle
    m_Stream->ReleaseBufferHandle(bufHandle);
}