"ProtoThreads" with a twist.

For a long time I’v been interested in running game-specific/entity-specific code in coroutines. Something like the following.

void some_game_object_behavior( entity ent, ... )
{
    pnt3 points[] = {
        {1,1,1},
        {2,2,2},
        {3,3,3},
        {4,4,4}
    };

    int pos = 0;

    while(entity_alive(ent))
    {
        // move the entity to a position and yield coroutine while movement is ongoing.
        move_to(ent, points[pos % ARRAY_LENGTH(points)]);
        pos++;

        for(int i = 0; i < 4; ++i)
        {
            shoot_bullet(ent);
            wait_sec(ent, 2); // do nothing for 2 seconds and yield the coroutine for that duration.
        }
    }
}

The above example is slightly simplified but I hope that it get the point across, that I want to be able to suspend code-execution at specific points and wait for certain actions to complete. Writing one-off game-code in this fashion might be a good way to work, especially when adding wait_for_any() and wait_for_all() etc.

Read More

printf-based TOSTR on the stack

As I might have written before I like printf-style string-formating. It’s imho the most convenient way to format strings and it can be really powerful if needed. However something that can be a bit tedious is output:ing “composite” values such as a vec3 or quaternion as there will be quite a bunch of repetition.

printf("{ %.2f, %.2f, %.2f }", vec.x, vec.x, vec.z);

Doing this for multiple values really get verbose and its easy to make simple copy-paste-errors ( see above! ).

Read More

A story about an unexpected ABI break

This is the story of an unexpected ABI break that I thought would be worth documenting.

At Avalanche we use a small class wrapping 32bit hashes called CHashString, it is basically just a wrapper around uint32_t and one should be able to treat it as a uint32_t in code except for operations that do not make sense on a hash-value.

Why would you want a class like this you might ask, well we use it for adding a const char* c_str()-function that can be used in logging and also we use it to add custom natvis-support in visual studio so that you can just hover a CHashString and have a lookup of the hash-value performed.

Read More