design of classes and handler...

Started by
1 comment, last by Marty666 19 years, 7 months ago
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
_____ /____ /|| | || MtY | ||_____|/Marty
Advertisement
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
visit my website at www.kalmiya.com
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
_____ /____ /|| | || MtY | ||_____|/Marty

This topic is closed to new replies.

Advertisement