Skip to main content
gamedev.net
🔒 Locked

Adding Objects To Managers

Started by Winegums Mar 22, 2007 at 9:00 PM 1 replies 500+ views
Original Post
Winegums
Winegums
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.
Sneftel
Sneftel
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.
Telastyn
Telastyn
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.