-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathpacker.c3
49 lines (43 loc) · 1.33 KB
/
packer.c3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
module packer;
import common;
import std::io;
import std::io::file;
import std::collections::list;
extern fn char *stbi_load(ZString filename, int *x, int *y, int *comp, int req_comp);
const String[] IMAGE_FILES = {
"assets/images/custom/bomb.png",
"assets/images/custom/key.png",
"assets/images/custom/null.png",
"assets/images/custom/particle.png",
"assets/images/custom/player.png",
"assets/images/custom/wall.png",
};
DString pack;
Assets assets;
fn int main() {
foreach(filename: IMAGE_FILES) {
int x, y;
int comp = 4;
char *pixels = stbi_load((ZString)filename, &x, &y, null, comp);
int size = x*y*comp;
usz offset = pack.len();
assets.push({filename, offset, x, y});
pack.append_chars((String)pixels[0..size-1]);
if (pixels == null) {
io::printf("ERROR: could not load file %s\n", filename);
return 1;
}
}
io::printfn("Asset[] assets = {");
foreach (asset: assets) {
io::printfn(" {\"%s\", %d, %d, %d},", asset.filename, asset.offset, asset.width, asset.height);
}
io::printfn("};");
io::printf("char[*] pack = {");
String pack_view = pack.str_view();
for (usz i = 0; i < pack_view.len; ++i) {
io::printf("%d,", pack_view[i]);
}
io::printfn("};");
return 0;
}