示例#1
0
JQuadPtr ResourceManagerImpl::RetrieveCard(MTGCard * card, int style, int submode)
{
    //Cards are never, ever resource managed, so just check cache.
    if (!card || options[Options::DISABLECARDS].number) return JQuadPtr();

    submode = submode | TEXTURE_SUB_CARD;

    //static std::ostringstream filename;
    //filename.str("");
    string filename;
    filename.reserve(4096);
    //filename << setlist[card->setId] << "/" << card->getImageName();
    filename.append(setlist[card->setId]);
    filename.append("/");
    filename.append(card->getImageName());
    int id = card->getMTGId();

    //Aliases.
    if (style == RETRIEVE_THUMB)
    {
        submode = submode | TEXTURE_SUB_THUMB;
        style = RETRIEVE_NORMAL;
    }

    JQuadPtr jq = RetrieveQuad(filename, 0, 0, 0, 0, "", style, submode | TEXTURE_SUB_5551, id);

    lastError = textureWCache.mError;
    if (jq)
    {
        jq->SetHotSpot(static_cast<float> (jq->mTex->mWidth / 2), static_cast<float> (jq->mTex->mHeight / 2));
        return jq;
    }

    return JQuadPtr();
}
示例#2
0
JQuadPtr ResourceManagerImpl::RetrieveQuad(const string& filename, float offX, float offY, float width, float height, string resname,
        int style, int submode, int id)
{
    //Lookup managed resources, but only with a real resname.
    if (resname.size() && (style == RETRIEVE_MANAGE || style == RETRIEVE_RESOURCE))
    {
        JQuadPtr quad = GetQuad(resname);
        if (quad.get() || style == RETRIEVE_RESOURCE) return quad;
    }

    //Aliases.
    if (style == RETRIEVE_THUMB)
    {
        submode = submode | TEXTURE_SUB_THUMB;
        style = RETRIEVE_NORMAL;
    }

    //Resname defaults to filename.
    if (!resname.size()) resname = filename;

    //No quad, but we have a managed texture for this!
    WCachedTexture* jtex = textureWCache.Retrieve(id, filename, style, submode);

    lastError = textureWCache.mError;

    //Somehow, jtex wasn't promoted.
    if (style == RETRIEVE_MANAGE && jtex && !jtex->isPermanent()) return JQuadPtr();

    //Make this quad, overwriting any similarly resname'd quads.
    if (jtex)
    {
        JQuadPtr quad = jtex->GetQuad(offX, offY, width, height, resname);

        if (!quad.get())
            return quad;

        if (style == RETRIEVE_MANAGE && resname != "")
        {
            WManagedQuad mq;
            mq.resname = resname;
            mq.texture = jtex;
            AddQuadToManaged(mq);
        }

        if (style == RETRIEVE_LOCK)
            jtex->lock();
        else if (style == RETRIEVE_UNLOCK)
            jtex->unlock();
        else if (style == RETRIEVE_MANAGE) jtex->deadbolt();

        return quad;
    }

    //Texture doesn't exist, so no quad.
    return JQuadPtr();
}
示例#3
0
JQuadPtr WCachedTexture::GetQuad(float offX, float offY, float width, float height, const string& resname)
{
    if (!texture) return JQuadPtr();

    if (width == 0.0f || width > static_cast<float> (texture->mWidth)) width = static_cast<float> (texture->mWidth);
    if (height == 0.0f || height > static_cast<float> (texture->mHeight)) height = static_cast<float> (texture->mHeight);

    // If we're fetching a card resource, but it's not available yet, we'll be attempting to get the Quad from the temporary back image.
    // If that's the case, don't stash a separate tracked quad entry for each card name in the the Back/BackThumbnail's resource
    string resource(resname);
    if (mFilename == kGenericCard || mFilename == kGenericThumbCard)
    {
        // if we're the back or thumb_back file, but we've been asked for a card ID, then assign it
        // a placeholder ID.  Reason being, hotspots on quads are different (ie centered) for card images, so we'll store a separate quad for cards 
        if (resname != kGenericCardID && resname != kGenericCardThumbnailID)
            resource = kPlaceholderID;
    }

	std::map<string, JQuadPtr>::iterator iter = mTrackedQuads.find(resource);
	if (iter != mTrackedQuads.end())
		return iter->second;

	JQuadPtr quad(NEW JQuad(texture, offX, offY, width, height));

    //Update JQ's values to what we called this with.
    quad->SetTextureRect(offX, offY, width, height);
	mTrackedQuads.insert(std::pair<string, JQuadPtr>(resource, quad));
    return quad;

}