Make atlastool write names to the table, so that name-based lookup is possible.

This commit is contained in:
Henrik Rydgard
2012-10-31 10:14:59 +01:00
parent 2c3f569a9f
commit 95f0f869f7
+36 -33
View File
@@ -443,6 +443,7 @@ struct FontDesc {
results[i].ex - results[i].sx, results[i].ey - results[i].sy, (i - first_char_id + 32));
}
fprintf(fil, " },\n");
fprintf(fil, " \"%s\", // name\n", name.c_str());
fprintf(fil, "};\n");
}
@@ -464,13 +465,14 @@ struct ImageDesc {
int i = result_index;
float toffx = 0.5f / tw;
float toffy = 0.5f / th;
fprintf(fil, " {%ff, %ff, %ff, %ff, %d, %d},\n",
fprintf(fil, " {%ff, %ff, %ff, %ff, %d, %d, \"%s\"},\n",
results[i].sx / tw + toffx,
results[i].sy / th + toffy,
results[i].ex / tw - toffx,
results[i].ey / th - toffy,
results[i].ex - results[i].sx,
results[i].ey - results[i].sy);
results[i].ey - results[i].sy,
name.c_str());
}
void OutputHeader(FILE *fil, int index) {
@@ -578,66 +580,67 @@ int main(int argc, char **argv) {
// Sort items by ID.
sort(results.begin(), results.end());
FILE *cpp_fil = fopen((out_prefix + "_atlas.cpp").c_str(), "wb");
fprintf(cpp_fil, "// C++ generated by atlastool from %s (hrydgard@gmail.com)\n\n", argv[1]);
fprintf(cpp_fil, "#include \"%s\"\n\n", (out_prefix + "_atlas.h").c_str());
FILE *cpp_file = fopen((out_prefix + "_atlas.cpp").c_str(), "wb");
fprintf(cpp_file, "// C++ generated by atlastool from %s (hrydgard@gmail.com)\n\n", argv[1]);
fprintf(cpp_file, "#include \"%s\"\n\n", (out_prefix + "_atlas.h").c_str());
for (int i = 0; i < (int)fonts.size(); i++) {
FontDesc &xfont = fonts[i];
xfont.ComputeHeight(results, distmult);
xfont.OutputSelf(cpp_fil, dest.width(), dest.height(), results);
xfont.OutputSelf(cpp_file, dest.width(), dest.height(), results);
}
if (fonts.size()) {
fprintf(cpp_fil, "const AtlasFont *%s_fonts[%i] = {\n", atlas_name, (int)fonts.size());
fprintf(cpp_file, "const AtlasFont *%s_fonts[%i] = {\n", atlas_name, (int)fonts.size());
for (int i = 0; i < (int)fonts.size(); i++) {
fonts[i].OutputIndex(cpp_fil);
fonts[i].OutputIndex(cpp_file);
}
fprintf(cpp_fil, "};\n");
fprintf(cpp_file, "};\n");
}
if (images.size()) {
fprintf(cpp_fil, "const AtlasImage %s_images[%i] = {\n", atlas_name, (int)images.size());
fprintf(cpp_file, "const AtlasImage %s_images[%i] = {\n", atlas_name, (int)images.size());
for (int i = 0; i < (int)images.size(); i++) {
images[i].OutputSelf(cpp_fil, dest.width(), dest.height(), results);
images[i].OutputSelf(cpp_file, dest.width(), dest.height(), results);
}
fprintf(cpp_fil, "};\n");
fprintf(cpp_file, "};\n");
}
fprintf(cpp_fil, "const Atlas %s_atlas = {\n", atlas_name);
fprintf(cpp_fil, " \"%s\",\n", image_name.c_str());
fprintf(cpp_file, "const Atlas %s_atlas = {\n", atlas_name);
fprintf(cpp_file, " \"%s\",\n", image_name.c_str());
if (fonts.size()) {
fprintf(cpp_fil, " %s_fonts, %i,\n", atlas_name, (int)fonts.size());
fprintf(cpp_file, " %s_fonts, %i,\n", atlas_name, (int)fonts.size());
} else {
fprintf(cpp_fil, " 0, 0,\n");
fprintf(cpp_file, " 0, 0,\n");
}
if (images.size()) {
fprintf(cpp_fil, " %s_images, %i,\n", atlas_name, (int)images.size());
fprintf(cpp_file, " %s_images, %i,\n", atlas_name, (int)images.size());
} else {
fprintf(cpp_fil, " 0, 0,\n");
fprintf(cpp_file, " 0, 0,\n");
}
fprintf(cpp_fil, "};\n");
fprintf(cpp_file, "};\n");
// Should output a list pointing to all the fonts as well.
fclose(cpp_fil);
FILE *h_fil = fopen((out_prefix + "_atlas.h").c_str(), "wb");
fprintf(h_fil, "// Header generated by atlastool from %s (hrydgard@gmail.com)\n\n", argv[1]);
fprintf(h_fil, "#pragma once\n");
fprintf(h_fil, "#include \"gfx/texture_atlas.h\"\n\n");
fclose(cpp_file);
FILE *h_file = fopen((out_prefix + "_atlas.h").c_str(), "wb");
fprintf(h_file, "// Header generated by atlastool from %s (hrydgard@gmail.com)\n\n", argv[1]);
fprintf(h_file, "#pragma once\n");
fprintf(h_file, "#include \"gfx/texture_atlas.h\"\n\n");
if (fonts.size()) {
fprintf(h_fil, "// FONTS_%s\n", atlas_name);
fprintf(h_file, "// FONTS_%s\n", atlas_name);
for (int i = 0; i < (int)fonts.size(); i++) {
fonts[i].OutputHeader(h_fil, i);
fonts[i].OutputHeader(h_file, i);
}
fprintf(h_fil, "\n\n");
fprintf(h_file, "\n\n");
}
if (images.size()) {
fprintf(h_fil, "// IMAGES_%s\n", atlas_name);
fprintf(h_file, "// IMAGES_%s\n", atlas_name);
for (int i = 0; i < (int)images.size(); i++) {
images[i].OutputHeader(h_fil, i);
images[i].OutputHeader(h_file, i);
}
fprintf(h_fil, "\n\n");
fprintf(h_file, "\n\n");
}
fprintf(h_fil, "extern const Atlas %s_atlas;\n", atlas_name);
fprintf(h_fil, "extern const AtlasImage %s_images[%i];\n", atlas_name, (int)images.size());
fclose(h_fil);
fprintf(h_file, "extern const Atlas %s_atlas;\n", atlas_name);
fprintf(h_file, "extern const AtlasImage %s_images[%i];\n", atlas_name, (int)images.size());
fclose(h_file);
// TODO: Turn into C++ arrays.
}