Jump to content
  • Advertisement
Sign in to follow this  
MadsGustaf

Any algorithm to find value of a datamember from a class in a vector?

This topic is 3800 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

I have a vector of sprites, each sprite has a pointer to a body (that is handled by the physics engine). I have done a conditional loop using the physics engine, to decide if i should destroy the body, so i have an iterator to the body, but i need to also find the sprite with the pointer to this body. Is there an algorithm for doing that? i was thinking of find() at first. I know that each sprite has its uniqe body.

Share this post


Link to post
Share on other sites
Advertisement
A back pointer would work. Sending a signal to the sprite would also work, how does the physics engine update the sprite when something changes?

Share this post


Link to post
Share on other sites
If I understand you correctly, you're probably best off, in this case, using the address of the iterator to the body (ie: &(*iter) ) and manually looping through your sprite vector looking for that value.

I believe (and someone is sure to correct me if I'm wrong :) ) that find is going to look for values of the vector's type. If the sprite IS the pointer to the body then you can use the aforementioned address and the find algorithm to search your vector for that value.

I would guess, however, that your sprite is a more complicated object. In that case find isn't going to work with the pointer to your body unless you override the == operator on your sprite class to comapre a sprite object with a body pointer (which might be more work than it's worth).


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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!