What's wrong with this code?

Here’s a short function:

 inline int SecondsToEnergy( float time )
 {
   return FastFloorfToInt( time * (float)(1 << kEnergyFixedPoint) );
 }

It’s used in the particle system, and converts particle lifetime to an internal fixed point representation (10 bits for fractional part, i.e. kEnergyFixedPoint=10).

Some of the emitted particles are okay on a Mac, but completely not visible on Windows. This function is to blame.

Of course, what’s wrong is the possible overflow in float-to-int conversion. Whenever someone tries to use lifetime longer than about 2097151, the conversion to signed 32 bit integer is undefined. It seems to clamp result in gcc and produce something like -1 in msvc.

Using multiple compilers can be hard, but it can also help in finding obscure bugs. Ha!


Wii or spirit of evil

Watched an old Russian film Viy yesterday. Is it just me, or is the pronunciation strikingly similar to one console that is coming out soon? Wii or Spirit of Evil!


Quote of the month

At work the other day:

Jesus says: use the debugger!


A steam of random things

Awards: Hey, we’ve got a “runner up” award in Apple Design Awards 2006, Best Use of Graphics category! Yeah, a runner up is more like “the first of the losers”, but oh well. Got beaten by modo 201, which probably is a fair trade. It’s just that we thought we’d be in Best Developer Tool category, but that is apparently for text editors and scripting languages :)

Demos: In the other news, fellow ReJ with TBL just won Assembly 2006 demo competition with an Amiga demo, putting all PC demos faces’ to dust. Check it out. Art direction over hardware capabilities, one more time.

Drivers: why oh why the graphics drivers must be so bad? The other day I was thinking why can’t they auto-update themselves (with an option to turn it off for corporate users etc.). Now you’ve got a (not so recent!) driver that is able to parse vertex programs wrong, and a user who does not have a clue that he should update it. It’s bad enough to have a bug in the first place, but auto-update at least would fix…

Or you have a driver that says “I’m OpenGL 1.2!” but the 3D texture functions are null. And it’s the most recent driver for a particular graphics card that you can buy today! And it’s not even a hard problem! What the developers are thinking - they go over the required GL 1.2 functionality, see that some is actually missing and decide “ah, screw it, we’ll say it’s 1.2 anyways”?!

I just don’t get it. I could use some enlightenment on this.


Painting and wallpapering

We repainted our living room and did one wall in wallpaper (real actual ones, not for the desktop). This is fun but takes a couple of days to get done, half of that time spent moving stuff outside the room and moving it back afterwards.

One thing I learned is that painting with semi-glossy paint is very different from painting with matte one. Semi-glossy is very sensitive to paint strokes, pressure and a lot of other things, and if you’re not extremely careful you’ll get a wall that looks like with a varying gloss or specular power. Of course, varying specular exponent would be cool in a shader demo of 2001, but it’s not a cool thing to have on your room wall. And it’s not 2001 anymore either!

After that we just went for a week to Crete. Here’s an assortment of small random pictures. Now back to work!