Tool update: psdslayer 1.1

A while ago I posted psdlayerstga 1.0. I have now updated it to support saving to PNG files, which is also now the default output format. The tool also got renamed to psdslayer, since I was constantly imagining, and even mistyping, the name to be “psd slayer” rather than “psd layers“. And I find it funny.
Read the rest of this entry »


Steps and Pulses

A few years ago I read the book Texturing and Modeling: A Procedural Approach (Ebert et al.) and found some low level “step” and “pulse” primitives used for generating procedural graphics. It didn’t take a long time to notice that those are actually really useful in many other situations as well.

A generic pattern is that some value changes its value from a to b over t iterations, and you want something other to move along from c to d in the same time. Implementation is easier when the transition from a to b is just normalized to [0..1]. After that it’s really easy to map it to any range just by another multiplication (dc) and adding an offset (c).

The “boxStep” function does the normalization part described above. However, just linear movement is actually quite boring, so the funky part here is that you can just switch “boxStep” to a “smoothStep” and there we go, movement along a smooth curve which feels better. Or you can map the boxStep result to a different function which takes in a value in the [0..1] range and outputs a value in the same range, e.g. sqrt().

Read the rest of this entry »


Tool: psdlayerstga

UPDATE: psdlayerstga has been renamed to psdslayer with addition of saving the layers as png files. Get the new tool from here.

I took DrPetter’s PSDImage code for extracting layers from PSD images, and combined it with stb_image just for saving out the layers easily as TGA files. And then I included some simple options and output of the metadata (i.e. name and position of each layer). Result is a little command-line utility, “psdlayerstga”. Use it for anything, but do so at your own risk. (The PSDImage code uses that same license, and stb_image is public domain.)

Download here, including C/C++ source and a pre-built executable for windows:
Go get newer version (psdslayer) from here.

Edit: Don’t miss psdparse below (suggested by Toby), an alternative tool for the same task.


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.


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:


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.


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.
Read the rest of this entry »


My stuff for Assembly 2009

4K intros for Asm09
Last week I attended the Assembly’09 summer event, like I have done every year since 1992. Although this time I didn’t make a game and didn’t hold a seminar session, I still contributed in the 4K intro competition… twice, actually.

Again I worked with XMunkki on an intro called Dream Creditor, which ended up at the fourth place in the competition (Download Windows zip / YouTube video). Additionally I made a tongue-in-cheek-production with little marching elephants called Irrelephant. Audience seemed to like it a lot so it placed on the 3rd place! (Download Windows zip / YouTube video). You can probably also easily spot that my little 2D walker prototype (from my previous post) ended up as part of this production.


Simple 2D walker prototyping

Like I said, I’d post a bit about some prototyping. Nowadays I’m usually using Processing for small prototypes. Some years ago I used to use EVALDRAW for little algorithmic tests. I love it for the immediate feedback when working with it, and also the different modes it provides.

But after I started to like more the whole concept of isolated first-stage prototypes, I felt EVALDRAW wasn’t just enough for all of my needs. After pondering with some alternatives I ended up “standardizing” on Processing, although it would still have a lot to learn from EVALDRAW. :-) However the one cool thing with Processing is that you can export your creation to be a stand-alone mini-app or even to a web page. As long as you have installed Java.

Lately when working with some ideas for a platformer game, I wanted to make some tests for a “walker”. To be exact, the simple kind which would just use some carefully chosen formulas like sine curves to move feet and body.
Read the rest of this entry »


Skipping Asm’09 GameDev compo

Not a game
I have attended the Assembly event every year starting from 1992. Starting from 2002 they have also arranged a game development competition. I have participated in that compo every year – my first one there was Stair Dismount™ (which was also the winning game).

However, this year I won’t be taking part. I actually have been churning out code for a week or two for an entry. But the submission deadline was on last Sunday and I just didn’t have enough of anything playable to have a first submission… Updates are allowed, so it wouldn’t have been an issue to submit something half-finished, but I was far from that.

I have one long-standing idea for a nice additive feature to a normal side-scrolling platformer, which is what I had in mind. That’ll wait for another time. On the image right you can see a small glimpse of the test code I made – although the image doesn’t really tell anything. Even the tile graphics are taken from free graphics sets of Lost Garden (thanks!). But I’ll probably post a bit more about my prototyping tests later, as I had fun time making some new stuff as well as polishing some old code.

PS. For a few years I have also held seminars at the event. This year I was asked to talk about iPhone and our company experiences, but I felt I’m not the right guy to have that talk so I passed on the opportunity. I recommend you go and listen to scoopr‘s iPhone development talk (he’s my colleague).


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.

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