Archive for the ‘Code’ Category

2010-06-29

Unwrapping Values – nearest next angle from a previous angle

So, assuming you have angles previousAngle and nextAngle, and you want to transition from the first to the second smoothly. If it’s like from 358 to 2, a simple linear interpolation will awfully go through almost a full circle down from 358 to 2, when a simple four degree transition forward would have been enough, i.e. you should have been going to 362 degrees instead. So, how to figure out what’s the shortest transition?

I remember hitting against this problem numerous times, always remembering that I have solved it previously but always seem unable to find the previous solution. And I still can’t just write it out by heart.

Once again I had to solve this, so this time I tried to Google for it (“angle wrap delta”), and found out that somebody named Jason S had posted a nice generalization to a related question in Stackoverflow.com.

For your convenience, I’m posting a modified C version of the code here.
(more…)

2009-12-11

Little framework for making prototypes or an LD48 entry

If you didn’t know yet, the Ludum Dare 48 hour game development competition is held again this weekend. In the competition the idea is to make a game using a given theme, more or less from scratch. Basically most people use some small amount basecode to start up with as there’s not really that much point to make every boring bit (like how to open a window) again every time. Besides, a little framework still has less stuff than what fine tools such as Unity3D provides you with to start with. :)

So here’s my little C++ basecode/framework for making a Ludum Dare 48 hour game development competition entry. It should be equally suitable for making some other little prototype games. You’ll need to svn checkout Irrlicht and download FMOD 3 separately. The framework is meant to be used on Windows with Microsoft Visual C++ 2008 (Express Edition is enough).

framework_LD48_tonic_200912.zip

2009-11-10

Code: Tokenizer

Here’s a little C++ utility class for splitting C strings into tokens by given separators. It’s inspired by “tokenwad” taken from Sol’s CFL3, which I have used quite a few times. This version has low memory overhead as it performs only 1-2 allocations (depending if the tokenization is done in-place or a separate copy is needed).

(more…)

2009-11-09

Tool: Binary data to embeddable char array

Sometimes there’s a need to embed some little bit of binary data in the executable. The reasons may vary – perhaps it is for a resource you want to exist even if data files are missing, or it could be even something you want to “hide” from some curious wannabe-hackers.

In the past years my typical use case was as follows. I used to make “64 KB intros” (such as this one), and for those I needed to embed a few data files to the executable as object data, so that I could exploit compression of the executable packer without writing a proper compression tool myself (such as UPX).

(more…)