Jump to content
  • Advertisement
Sign in to follow this  
Winegums

Adding Objects To Managers

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

Hi, I'm currently writing a physics manager to manage all objects' collisions in a scene. The manager is a singleton, and I have been trying to think of a good way to add objects to the list. Ideally each object would be able to add itself to the manager in it's constructor, but i can't see a way of doing this since, unfortunatley, you can't pass the 'this' keyword as a parameter :/ anyone have any tips (or experiences) on how to fix this? maybe i'm just oblivious to it, but no sollutions are jumping off the screen at me. obviously i could have theManager::AddObject(theObject* someObject) but I wanted the objects to be somewhat self managing.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Winegums
The manager is a singleton
It is? You'll never want to have multiple independent physics simulations?
Quote:
Ideally each object would be able to add itself to the manager in it's constructor, but i can't see a way of doing this since, unfortunatley, you can't pass the 'this' keyword as a parameter
Sure you can. You just need to be careful.
Quote:
anyone have any tips (or experiences) on how to fix this?
Yeah, don't do it automatically. There are lots and lots of situations in which you will want to have an object which is NOT part of the simulation. If you can't think of any now, trust me-- you will in a couple of months. Manually register objects that need to be part of a simulation.

Share this post


Link to post
Share on other sites
I agree with Sneftel's advice.

I've seen other scenarios though where objects used by the manager are just handles to data used by the manager for stuff (rendering, playing, sending) and need to be tied to something which does stuff with them (even if it's "some temporary outside of the main simulation"). For such situations, I've found the factory pattern a good way for the manager to set that invariant on the data handles it provides to the programmer.

Though... yeah, probably not best for physics.

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!