Sign in to follow this  
Monkan

Where to store constants?

Recommended Posts

Monkan    1087
Hi,

Another question.
I want to store a gravity constant in my game that affects many things in different place so I want a constant variable that is accessible from many places. I was about to make a header file called constants that literally just has const float GRAVITY = n;
I thought this looked a bit stupid and out of place.

How do people normally do this? Or is this fine and I'm just having a sly bout of o.c.d.?

Cheers

Share this post


Link to post
Share on other sites
Telastyn    3777
[quote name='Monkan' timestamp='1311188772' post='4838099']
I was about to make a header file called constants that literally just has const float GRAVITY = n;
[/quote]

That seems like an acceptable solution. As long as you're using some named constant, that's what really matters with regards to the impact on your design.

Share this post


Link to post
Share on other sites
alvaro    21246
Why are many parts of your code concerned with the value of gravity? Other than the part of your simulation that computes the forces acting on each object, I can't imagine where else it might appear.

Share this post


Link to post
Share on other sites
ChurchSkiz    1101
Alvaro hit it on the head, the only thing that should "know" the gravity is the physics system that applies it. Pass the object you want into your physics simulator and have it do the calculation you want.

ie

Player P;
PhysicsSystem physics;
physics.calculateGravityEffect(P);

As far as storing constants, a good way to do it is to store the values in a text file with other constants. That way you can make simple design/testing changes without having to recompile.

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