Sign in to follow this  
Marty666

design of classes and handler...

Recommended Posts

Hi all, I have a question about the design of the game i'm making. I have a base class that's called cPhisicsObject. It's got location, speed, etc. and some functions to manipulate the object. I'll have a linked list of all the instances of this class (since i might want to create lots of particles and then have 'm die again). I'd like to use one handler class to update the physics of all the things in the linked list (add speed to location, add gravity to speed, etc.). Is this the proper way to do this. And if so, would it be better to make this handler class 'friend', so it wouldn't need the accessor funcitons for speed reasons? The problem is actually that I have some amount of cPhysicsObjects that I want updated every once in a while (actually every time in the main loop). But I need either: 1: Something to tell all the objects to update themselve (would be slower, since a lot of stuff will be done twice, like calculating the time that has past, although i might just give that as a parameter) or 2: Something that acesses all the objects and then updates their variables. How do you solve the problem normally? What is the proper way to do this? Thanks, Marty

Share this post


Link to post
Share on other sites
Maybe you could have a cPhysicsManager which
manages the list (or vector or whatever) of
physicsObjects(Ptr's).

Then cPhysicsManager will have an ::update (float elapsedTimeInSeconds) function
which will loop over all objects and call their
::update-function (or maybe update only visible
objects, or a few objects each frame or whatever)

CPhysicsMgr::update will then be called from the
main renderLoop with the deltaT since last frame.

Regards

Share this post


Link to post
Share on other sites
Thanks, this is what I was thinking of... Would it be the appropriate way? Can I make a static function update which goes through all objects of the cPhysics class, so that the class would be the handler/manager of all the instances? Would that be a better idear? Please give me your opinions.

thanks,
Marty

Share this post


Link to post
Share on other sites

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

Sign in to follow this