tweakval ftw.

Alright, I’m in. I’ve got a case of iced coffee drinks and a clear schedule for the weekend. Looking forward to this.

Also, I learned a really neat trick today (just in time for LD) and thought I’d share. In an earlier post during the “advancing wall” contest, I mentioned my experiment with trying to tune the gameplay using automatically reloading config files. That didn’t really work out so well, it worked but it was too much of a pain to add each new value to the config file. I think I only had one or two in the end. Waste of time.

But… Ben Garney, who inspired the  approach in the first place, commented and pointed me to this thread which discusses a really neat way to handle this.

tweakval

Click the image to expand to readable size.

Basically, everywhere you put a constant that you want to tune, you can instead use a macro like _TV( 4.2 ) instead. The _TV stands for tweakable value. In a release build it does nothing, but in a debug build, it checks if the source file changed and updates automagically.  You can see a simple example of usage in the screenshot, I’m editing and saving the values in the source, and the printfs in the console reflect the changes.

I just hacked this together so it’s probably a little flaky, it’s pretty much untested.  It should work on linux as well, if you’re using gcc 4.3 or above, but I haven’t tried it yet.  I’ve added this to my ld code dump, you just need the .h and .cpp file if you want to try it, or you can probably roll your own.

Comments

28. Aug 2009 · 07:54 UTC
Cool, I’ve been meaning to investigate this ever since reading that thread, but (predictably) have never gotten around to it.
28. Aug 2009 · 08:12 UTC
This is awesome! Does it still work if you do something like #define ZOMBIE_SPEED (_TV(10)) and then use ZOMBIE_SPEED several times?
jovoc
28. Aug 2009 · 15:16 UTC
No, #defines won’t work because it depends on the __COUNTER__ macro which would get expanded differently every time you use ZOMBIE_SPEED. The best way to do that is just make a local like “const int ZOMBIE_SPEED = _TV(10);” Or if you need it to be used everywhere, make it a global and just don’t make it const and then reassign the value somewhere in your mainloop. You can always change it to a #define later once you’re done tweaking that value.
28. Aug 2009 · 15:49 UTC
Cool! I’m glad to see that that is working for you! :) The MollyRocket guys are really smart. 😉
professor opinion
28. Aug 2009 · 16:16 UTC
Umm.. ever heard of a config file? Yeesh… sorry, this seems a little crazy. A lot crazy, actually.
SpaceManiac
28. Aug 2009 · 19:48 UTC
I’m using this.