Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualrip-off

Posted 23 November 2012 - 08:09 AM

I'd recommend against putting the dimensions in the string, if it can be avoided. Better to have type safety.

Cape's code has the right idea, but is incorrect. I believe the following would be more correct:
struct TextureKey
{
	std::string name;
	int width;
	int height;
};

bool operator<(const TextureKey &a, const TextureKey &b)
{
    // Incorrect: return (a.width < b.width) || (a.height < b.height) || (a.name < b.name);
    if(a.width < b.width)
    {
        return true;
    }
    else if(a.width == b.width)
    {
         if(a.height < b.height)
         {
             return true;
         }
         else if(a.height == b.height)
         {
             return a.name < b.name;
         }
    }
    return false;
}

map<TextureKey, TexturePtr> textureCache;

#1rip-off

Posted 23 November 2012 - 06:54 AM

I'd recommend against putting the dimensions in the string, if it can be avoided. Better to have type safety.

Cape's code has the right idea, but is incorrect. I believe the following would be more correct:
struct TextureKey
{
    std::string name;
    int width;
    int height;
};

bool operator<(const TextureKey &a, const TextureKey &b)
{
    return (a.width < b.width) || (a.height < b.height) || (a.name < b.name);
}

map<TextureKey, TexturePtr> textureCache;

PARTNERS