Probably Dance

I can program and like games

Category: Programming

Storing information in a .png

Spore did a neat thing where they stored the creature information in a .png file that was a picture taken of the creature. So to share the creature you had to share the image, which is pretty cool. And it turns out that it’s really easy to do. Well if you are already using libpng that is.

I implemented it for the game Leshy, but we only used the feature for the auto save functionality of the editor, because the game didn’t have loading and saving. (simply because it would have been too much effort to program a menu that allows you to load and save)

Autosave file for Leshy editor

Auto save file for the Leshy editor. This is the actual save file. I could load the level from this image.

Read the rest of this entry »

My “Way Too Generic Serializer”

I wrote a serializer for my engine that is extremely convenient and generic.

A piece of serialization code in the engine looks something like this:

class PlaceMode
{
public:

    // ...

    SERIALIZE_FUNCTION(1)
    {
        SERIALIZE_START();
        if (version < 1) SERIALIZE_BASE(State);
        else             SERIALIZE_BASE(EditorState);
        SERIALIZE(archetypeNames);
        SERIALIZE(lastPosition);
        SERIALIZE_END();
    }

private:
    std::vector<std::string> archetypeNames;
    Vector4 lastPosition;
};

Read the rest of this entry »

Template Metaprogramming, Reflection in C++0x

So I’ve been working on the serialization code for our engine. And I’m finally understanding the more complex aspects of template metaprogramming, and it turns out that there are some neat things you can do with it that aren’t directly related to serialization.

OK let’s say you have an editor in your game, and in this editor you have a button “Add Component” which adds a new component to an entity. That button would open a pop-up menu, where you can select from all your component types and after selecting one, a new instance of that component-class is created and added to the entity. How do you populate that list? My solution using template metaprogramming and reflection is after the jump:

Read the rest of this entry »