Macros and Lambdas

Time for a short post on using lambdas to construct macros… that was a sentence that will be able to trigger 2 camps in one go :D

Defer

First of, using lambdas to implement a defer() is really neat, however others has already written about that so that I don’t have to!

A Defer Statement For C++11

Call once

So from my end I’ll start of with a quick one for constructing a macro that only does something once, lets call it IS_FIRST_CALL(). This can be used for things such as only logging something once or just asserting once. I’ll leave it to the reader to decide if this is a “good” thing but it is absolutely things I have seen “in the wild”.

Read More

When selecting a theme is your biggest problem!

I have been using pellican to generate and maintain my blog sinces its inception and it has been mainly fine. However after getting a new machine and starting to fiddle with a new post I started noticing things such as installation being far from optimal and it no longer generating a functioning site after updating pellican.

After an update all line-breaks in code-segments just got removed, did I configure something wrong, what to do to fix it? Don’t know and Im not really keen on finding out.

Read More

"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