A simple command line tool that generates a C++ source file from arbitrary resources.
Call the tool using the following command line:
resourceGenerator outputFile -type<resource> [-type<resource>...]
Where availables types are:
-b<resource> A binary file.
-t<resource> A text file.
Let's use the following level.tmx
file as input of the tool:
<?xml version="1.0" encoding="UTF-8"?>
<map width="48" height="36" tilewidth="16" tileheight="16">
<tileset firstgid="1" name="Tileset" tilewidth="16" tileheight="16" tilecount="9" columns="3">
<image source="tileset.png" width="48" height="48"/>
</tileset>
</map>
The command line will be:
resourceGenerator resources.cpp -tlevel.tmx
Once the command executed, the file resources.cpp
will contain the following:
#include <stdlib.h>
extern "C" const unsigned char level_tmx[] =
{
0x3c, 0x3f, 0x78, 0x6d, 0x6c, 0x20, 0x76, 0x65, 0x72, 0x73,
0x69, 0x6f, 0x6e, 0x3d, 0x22, 0x31, 0x2e, 0x30, 0x22, 0x20,
0x65, 0x6e, 0x63, 0x6f, 0x64, 0x69, 0x6e, 0x67, 0x3d, 0x22,
0x55, 0x54, 0x46, 0x2d, 0x38, 0x22, 0x3f, 0x3e, 0x0a, 0x3c,
0x6d, 0x61, 0x70, 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f,
0x6e, 0x3d, 0x22, 0x31, 0x2e, 0x30, 0x22, 0x20, 0x6f, 0x72,
0x69, 0x65, 0x6e, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x3d,
0x22, 0x6f, 0x72, 0x74, 0x68, 0x6f, 0x67, 0x6f, 0x6e, 0x61,
0x6c, 0x22, 0x20, 0x72, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x6f,
0x72, 0x64, 0x65, 0x72, 0x3d, 0x22, 0x72, 0x69, 0x67, 0x68,
0x74, 0x2d, 0x64, 0x6f, 0x77, 0x6e, 0x22, 0x20, 0x77, 0x69,
0x64, 0x74, 0x68, 0x3d, 0x22, 0x34, 0x38, 0x22, 0x20, 0x68,
0x65, 0x69, 0x67, 0x68, 0x74, 0x3d, 0x22, 0x33, 0x36, 0x22,
0x20, 0x74, 0x69, 0x6c, 0x65, 0x77, 0x69, 0x64, 0x74, 0x68,
0x3d, 0x22, 0x31, 0x36, 0x22, 0x20, 0x74, 0x69, 0x6c, 0x65,
0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x3d, 0x22, 0x31, 0x36,
0x22, 0x3e, 0x0a, 0x20, 0x20, 0x3c, 0x74, 0x69, 0x6c, 0x65,
0x73, 0x65, 0x74, 0x20, 0x66, 0x69, 0x72, 0x73, 0x74, 0x67,
0x69, 0x64, 0x3d, 0x22, 0x31, 0x22, 0x20, 0x6e, 0x61, 0x6d,
0x65, 0x3d, 0x22, 0x54, 0x69, 0x6c, 0x65, 0x73, 0x65, 0x74,
0x22, 0x20, 0x74, 0x69, 0x6c, 0x65, 0x77, 0x69, 0x64, 0x74,
0x68, 0x3d, 0x22, 0x31, 0x36, 0x22, 0x20, 0x74, 0x69, 0x6c,
0x65, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x3d, 0x22, 0x31,
0x36, 0x22, 0x20, 0x74, 0x69, 0x6c, 0x65, 0x63, 0x6f, 0x75,
0x6e, 0x74, 0x3d, 0x22, 0x39, 0x22, 0x20, 0x63, 0x6f, 0x6c,
0x75, 0x6d, 0x6e, 0x73, 0x3d, 0x22, 0x33, 0x22, 0x3e, 0x0a,
0x20, 0x20, 0x20, 0x20, 0x3c, 0x69, 0x6d, 0x61, 0x67, 0x65,
0x20, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x3d, 0x22, 0x74,
0x69, 0x6c, 0x65, 0x73, 0x65, 0x74, 0x2e, 0x70, 0x6e, 0x67,
0x22, 0x20, 0x77, 0x69, 0x64, 0x74, 0x68, 0x3d, 0x22, 0x34,
0x38, 0x22, 0x20, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x3d,
0x22, 0x34, 0x38, 0x22, 0x2f, 0x3e, 0x0a, 0x20, 0x20, 0x3c,
0x2f, 0x74, 0x69, 0x6c, 0x65, 0x73, 0x65, 0x74, 0x3e, 0x0a,
0x3c, 0x2f, 0x6d, 0x61, 0x70, 0x3e, 0x0a, 0x00
};
-
Variable names are generated using the resource's name and extension. Any non alphanumeric character will be replaced by a
_
(isalnum
is used internally to do this check). -
A binary resource generates 2 variables, one for the data and one for its actual size. So, for a binary resource called
mydb.bin
,mydb_bin
andmydb_bin_size
variables will be generated. -
Unlike binary resources, a text resource generates only 1 variable (for the data). The character
'\0'
is appended to this variable, so that it can be used like any other C char array.