Archive for the ‘Code’ Category

2009-09-01

LD15: Rock Warrior

15th Ludum Dare 48 hour game development competition was held last weekend, and it got total of 144 entries! This time given theme was “Caverns”. I continued with my tongue-in-cheek-named “warrior” series of prototype games and created Rock Warrior. Hopefully next time I don’t want to make a prototype about rock music…

Anyway, a mini-post-mortem of the Rock Warrior development can be read from the separate page about the game. Including a downloadable version, source code and a YouTube video.

2009-08-24

Code Gotchas: Unsigned Alert

So, the solution for my previous blog post about the borderline integer was to use simply an unsigned integer. However, even such a simple change may have some more unexpected results. Or maybe not even possible?

The Java language actually leaves out unsigned types. It’s not a big deal, but there are a few cases which may be slightly problemous, such as the previously mentioned borderline integer. And it is kind of annoying to have bytes in range -128..127 (easily fixed to 0..255 by anding with 0xff and assigning to int). But anyway, let’s move to the actual reason why I wanted to write this post.

Recently I had to fix some bug caused by combination of unsigned ints and floats. Consider the following code:

unsigned int u = 3;
float f = -u;
// and next just do something with f
// ...

Looks pretty simple and innocent, doesn’t it? Just take a value, negate it and put to a float and then use it. Well, let’s add this following code to check out, including an integer version of the negated value just for comparison:

int i = -u;
printf("%f\n", f);
printf("%d\n", i);

And when we run that, we get the following printed as the result:

4294967296.000000
-3

Pretty amazing — and not quite what you expected?

This particular result felt kind of illogical to me. But when thinking about the reason for such behavior, I guess it once again boils to the fact that the negate operator just works at the bit level and doesn’t care if the type is signed or unsigned, which is like syntactic sugar, so to say. Then I thought that maybe compiler should magically notice what’s going on and make the result of -value a signed integer.

On the other hand, it still makes sense that the type stays the same, when thinking about some other examples such as constant-var or var1-var2. Well, I’m not sure if it makes sense or not, but at least this makes it a bit easier to understand why there isn’t some implicit signedness conversion added. :-) So in any case, the intermediate result is that the negation of unsigned value ends up being unsigned, i.e. most likely a large value counting down from (unsigned int)~0. And then the end result is that value converted to float, as seen in the example.

I haven’t bothered to check from C89/C99 standards if they have something to say about this thing. And before you shout that the compiler will warn you, it actually might not. Of the above example, if you use at least warning level 2, Visual C++ will happily tell you warning C4146: unary minus operator applied to unsigned type, result still unsigned. But GCC won’t say anything even with -Wall -ansi -pedantic!

I’m curious to know if it would actually break something if there would be some sort of automatic/silent switch to signed int from unsigned int in cases like that, except in cases where the result value is put back to an unsigned int. Any thoughts are welcome.

2009-08-20

Code Gotchas: Borderline integer

Sometimes one finds a weird bug which “shouldn’t happen” but still does. And after more or less tedious debugging session the bug is found, and analyzing it shows it’s probably quite logical why the thing happened after all.

Even if it may be stressful to try find such nasty problems, in the end I’m usually fascinated by such weird minute details. Here is one such finding.

For this one I’ll present just the pure problem without a “solution” first, which I’ll add later. Feel free to add a comment and describe what you think — this one is actually really obvious.
(more…)

2009-07-22

Advancing Wall of Doom

Tsunami Warrior paper prototyping
Back in April I took part in the 14th Ludum Dare 48 hour game development compo, and the theme was “Advancing Wall of Doom”. I finally got around to writing about it to here as well.

Read on more from the game page. Also the source code is there for peeking.

2009-06-05

Turska 2.0

Turska is one of these things I have been tinkering with, but for some reason have neglected to mention here until now. It is a silly little UI/framework library meant to be small and easy to use, mainly aimed for games which have modest UI requirements anyway.

The very first version of the library was featured in Truck Dismount™ back in 2003, and the library was a simple component object/event based system back then. Later I got interested of the IMGUI concept and abandoned the old API to recreate it. Along the years it has always been open source – first hosted in SourceForge.net and nowadays in Google code.

Now I have finally upgraded the library version to 2.0.0 (this version is also known as Turs2). Check out the Turska home page if you want to know more.

2008-05-11

11th Ludum Dare – warrior

Warrior
The Ludum Dare 48 hour game development competition was again held three weeks ago, for the 11th time. The theme was minimalism, and I created a game called warrior.

It did quite well, achieving 1st place in graphics and technical votes, 2nd place for polish, and 3rd place for both audio and journal.

2007-08-13

Assembly 2007 – Seminar slides, 4KB intro, Company news

Rose Shank
Assembly’07 is over. I held a seminar presentation there about Immediate Mode Graphical User Interfaces (IMGUI for short), together with Jari Komppa. You can check out the slides.

With XMunkki I once again created a 4 KB intro, Rose Shank (download Windows zip). What’s special about the creation is the fact that it was created in a custom language which uses LISP syntax (Lisp-ahtava aka IL4). The code is compiled into a custom minimal bytecode and a VM for that particular case. Respect to XMunkki – he is the brains behind that nice little system which we have talked about for some years, and he finally got around to implementing it!

If you hadn’t heard yet, I recently also quit working for my previous employer Sulake Corporation and co-founded Secret Exit Ltd together with Jani Kahrama. We created a prototype of one of our game concepts for the Assembly Game Development competition. Cinnamon Beats took the 3rd place although it’s still in pre-alpha and we have received many positive comments about the game.

Update: Sources for Rose Shank are available.
You can also view a YouTube video of it!

2007-02-17

Andromedary source release

With my friend XMunkki we decided to release the source code to Andromedary, our 4 KB intro which came to 2nd place in Assembly’2006 event. Download it now and don’t forget to check out other 4 KB development resources in the IN4K site.

2006-06-05

8th Ludum Dare results for Lone Warrior

We finally got the results from the 8th Ludum Dare 48h game development competition. I’m glad to tell you that my creation, Lone Warrior, got 3rd place in three categories: Production, Graphics and Sound, with voting scores of 4.13, 4.09 and 3.73! (respectively, out of 5.00)

2005-11-11

Pogo Sticker awarded in MindTrek – IN4K launched

I’m happy to announce that my game Pogo Sticker won the MindTrek 2005 casual game competition!

Other news – we launched the IN4K web site a few days ago. If you’re interested in 4 KB intro development, check it out.


3rd party advertisement:
(not chosen by me, picked by Google for you)