Jump to content

  • Log In with Google      Sign In   
  • Create Account

We need your help!

We need 7 developers from Canada and 18 more from Australia to help us complete a research survey.

Support our site by taking a quick sponsored survey and win a chance at a $50 Amazon gift card. Click here to get started!


CAPE

Member Since 26 Jan 2007
Offline Last Active Mar 11 2013 03:54 AM

#5003465 Loading and caching resources

Posted by CAPE on 23 November 2012 - 06:32 AM

I don't know how you store your texture pointers, but with an string identifier, i guessing map<string, TexturPtr>. This will need to be extended to support additional data to use as the identifier.

Here u can implement a functor to create your own comparison function. Its easy to create, you can variate between different types, and is manageble. The problem that occurs is that that you will need to implement a key-struct for each type and combination. But as you currently need to create a load function for each resource type, this I guess will be a minor problem.

struct TextureKey
{
   string name;   //texture name
   int sizeX, sizeY; //texture size
   bool operator<(const TextureKey &a, const TextureKey &b)
   {
	  return std::strcmp(a.name, b.name) < 0 &amp;&amp; a.sizeX == b.sizeX &amp;&amp; a.sizeY == b.sizeY;
   }
};

...

map<TextureKey, TexturePtr> mTexturePtrs;

(Have not tried the above code, but it looks right :) )


PARTNERS