Jump to content
  • Advertisement
Alundra

Self managed object, bad practice in C++?

Recommended Posts

I use the pattern of "self management" quite often. However, as you noticed yourself you need to ensure things like a keyframe being only assigned to a single track. So you would need to put the whole management in the keyframe them, both adding and removing.

(IMHO, it doesn't make sense for keyframe on a time track objects)

 

For my home-grown game engine, I've made this into a general solution. Where you can have sort of "smart pointers" to objects that get set to NULL when you delete the object. Or lists of these objects where the entry in the list gets removed when you delete the object.

https://github.com/daid/SeriousProton2/blob/master/include/sp2/pointer.h

 

My primary example of why this is useful is when you have objects in a game, for example a lot of enemies, and all those enemies have a target. And that target can be deleted. Now, knowing as a targeted object that you can be targeted to clean up those specific pointers is quite error prone.

 

Next to that, I make a lot of use of the std::shared_ptr<> which is extremely useful if you just want the object to be destroyed once nobody references it any more.

 

But it the end, for keyframes, I would manage them for a full 100% from the track.

Share this post


Link to post
Share on other sites
Advertisement

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • 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!