views:

216

answers:

4

Hello all, let me tell you a bit about where this question came from. I have been playing around with the SDK of Serious Sam 2, a first person shooter which runs on the Serious Engine 2. This engine introduces something called MetaData. MetaData is used in the engine to serialize classes and be able to edit them in the editor environment (Serious Editor 2). So for example, instead of:

class CSomeGameItem : CEntity
{
    public:
    int iHealthToGive;
}

Which will not show up in the editor, you would do:

meta ver(1) class CSomeGameItem : CEntity _("Some game item")
{
public:
    meta int iHealthToGive; _("Amount of health to give")
}

Now when making a level, you can insert a "Some game item" entity into your level, and edit the one property it has. Now, I know Croteam (the developers of said game and engine) are using an extra compiler (Mdc, meta data compiler) to inject extra information about classes and their variables into the dll files, to make this metadata system possible. Does anyone have any clue as to how they did this?

Oh, btw, the meta, ver() and _() keywords are #define'd to nothing in their code, so the "normal" compiler ignores them.

+1  A: 

If this engine runs on Windows, one idea that comes to mind is resources. There are Windows APIs to modify the contents of resources of an exe or dll. Also, the API allows to read resources from an 'external' exe/dll. That way, the extra compiler would store meta data as resources in the compiled exe. And the development kit would read that metad data from "base" exe/dll.

Now, I have nerver of that stuff before so I might be light years away from how it actually works.

Serge - appTranslator
+1  A: 

To get a definitive answer, study the PE File Format. This is the low level file format for binaries on Win32. ie. DLLs, EXEs, COM, etc.

There are many books that discribe PE File layout and features. And many tools that allow you to explore it.

The short answer is that at the lowest level, PE File format allows you to embed data into the binary that can be extracted at run times. DLLs and Exe will often embed their icons and localization text. These are often called resources.

A good place to start is the Resource File section on MSDN. Also research "Resource Scripts (*.rc files)" and the "Resource Compiler (rc.exe)".

kervin
A: 

This looks somewhat similar to Qt's moc (meta object compiler). In Qt's case, it generates extra C++ source files which are then compiled and linked together with the original source files.

A possible implementation in your example would be for the generated files to implement a set of functions which can be called to get the extra information, to set the properties, and so on.

CesarB
A: 

Just a stab in the dark here, since I've never looked at the sdk, but I'm guessing that there's a two pass-system happening - once with a C++ compiler, and once with a custom metadata processor that can look for the meta tags and process the associated class names, instance member names and _() tags. Likely some sort of configuration file is created, and either left on the side, or embedded as a resource file. The custom metadata pass could also just be a C++ code generator which creates code to enable pseudo-reflection for each class.

Eclipse