Jump to content
  • Advertisement
Sign in to follow this  
mind in a box

Finding the key from the resource in a std::map

This topic is 3078 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

He all!

Can I somehow find the Key-Value in a std::map when I have the resource it holds?

Here is my scenario:

TheMap[L"Stone.png"]=SomeTexture;


but the blocks of my game only get the pointer to the texture. Now I want to save the world and I need to know the texture they have got.

Share this post


Link to post
Share on other sites
Advertisement
Or, instead of a map you could stores the string 'key' value within the texture and use a std::set instead. That way you still just store pointers to the texture in the blocks, but they can follow this pointer to get to the key string.

Share this post


Link to post
Share on other sites
Or make a second map PointerToName[SomeTexture] = L"Stone.png";

Or make the name a member variable of the texture...

Share this post


Link to post
Share on other sites
Thank you for all the suggestions! [smile]
I implemented SiCrane's approach. The std::map isn't very big, so it's okay to loop it for each block one time.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!