3 ms·
The title led me to think it might be a single file, but still this is good stuff. You could probably make it a single file if you used the wonderfully obscure
by rwmj 5y ago
The title led me to think it might be a single file, but still this is good stuff.
You could probably make it a single file if you used the wonderfully obscure XPM image format for your sprites and assets. It is both a C source fragment and an image format in one! https://en.wikipedia.org/wiki/X_PixMap https://en.wikipedia.org/wiki/X_PixMap
- mkotowski 5y agoWhat are upsides of using this format instead of a more generic array of pixels (something like output of imagemagick to .h files or PPM files)? BTW I know one can use resource files (.rc) on Windows to embed various resources, but is there an analogous mechanism for linux binaries?
- yissp 5y agoThe examples in the wiki article show the difference pretty well. XPM lets you sort-of see what the image is just by looking at the source file. E.G. compare this static char blarg_bits[] = { 0x13, 0x00, 0x15, 0x00, 0x93, 0xcd, 0x55, 0xa5, 0x93, 0xc5, 0x00, 0x80, 0x00, 0x60 }; with this static char * blarg_xpm[] = { "16 7 2 1", "* c #000000", ". c #ffffff", "**..*...........", "*.*.*...........", "**..*..**.**..**", "*.*.*.*.*.*..*.*", "**..*..**.*...**", "...............*", ".............**." };
- electroly 5y agoOn Linux you can use "ld -o myobj.o -r -b binary myfile.dat" and it will generate a linkable object file that contains your file data as a byte array. However, other platforms do it other ways, so it's generally easier to use "xxd" from the vim package to generate a C source file with a literal array, similar to the way that XPM works. That will work on all platforms.
- MLafayette 5y ago> The title led me to think it might be a single file You think Node.js is a single file?
- tsherif 5y agoThat's an interesting idea. Probably won't change the format for this project, but something I might consider in future ones. Thanks for the tip!