Dynamic Constants

By shadez / moonhazard

Hello folks. Let me introduce you the latest trick I invented a few weeks ago. Basically it's a way to make constant variables dynamic. Yes, you heard correctly. Actually it is pretty simple as well, it is just important to keep in mind that your variables aren't THAT constant anymore.

What can you do with dynamic constants then? Well, the adventages are not that good, but let's just say that it helps alot to break the chains that surround your program. Let's imagine a situation:

const float GRAVITATION_Y = 9.81;
character_y_velocity += GRAVITATION_Y;

Obviously you're doing fine with your gravitation. Programmers usually tend to use gravitation as constant, but what the fuck happens if you are in space or at north pole? Because the gravitation has changed, this 9.81 is not working very well anymore. Unless you want to use silly non-constant variables and rename all GRAVITATION_Ys to gravitation_y (if you have a similar naming convention), fine. Real coders are more clever and make their constants dynamic.


Of course that does not work. Just a little trick (you need to include mmsystem.h and import winmm.lib):

WHDD temp;
temp = _WHDDSetSynch(GRAVITATION_Y);
_WHDDSynch(GRAVITATION_Y, (float*)&temp, 2.12);

And you're done! Hope you'll find this article useful...

- shadez / moonhazard