From 973af0138095c4a6cbc2b25dd501f7446d7af9c9 Mon Sep 17 00:00:00 2001 From: Stefan Stefanov Date: Sun, 21 Apr 2024 19:17:27 +0300 Subject: [PATCH] update the generator tool & added unmarshalling a whole directory --- .vscode/settings.json | 6 +-- .vscode/tasks.json | 14 ++++++ scripts/build_generator_debug.bat | 2 +- .../aseprite_odin_generator.odin | 19 +++---- src/aseprite_odin_generator/atlas.png | Bin 10897 -> 10891 bytes src/aseprite_odin_generator/big.png | Bin 515 -> 0 bytes src/generator.odin | 47 ++++++++++-------- 7 files changed, 49 insertions(+), 39 deletions(-) delete mode 100644 src/aseprite_odin_generator/big.png diff --git a/.vscode/settings.json b/.vscode/settings.json index 9e476f8..e820f0f 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,7 +1,7 @@ { "workbench.colorCustomizations": { - "activityBar.background": "#322C2D", - "titleBar.activeBackground": "#463E3F", - "titleBar.activeForeground": "#FAFAFA" + "activityBar.background": "#322C2D", + "titleBar.activeBackground": "#463E3F", + "titleBar.activeForeground": "#FAFAFA" } } \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index f7cc3f0..9ad0a34 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -31,6 +31,20 @@ }, "group": "build" }, + { + "label": "Clean build folder(s)", + "type": "shell", + "windows": { + "command": "cd ${workspaceFolder}\\build && rm game*; cd ${workspaceFolder} && rm aseprite_odin_generator*", + }, + // "linux": { + // "command": "${workspaceFolder}/scripts/build_release.sh", + // }, + // "osx": { + // "command": "${workspaceFolder}/scripts/build_release.sh", + // }, + "group": "build" + }, { "label": "Build Hot Reload", "type": "shell", diff --git a/scripts/build_generator_debug.bat b/scripts/build_generator_debug.bat index ecaabef..2340f93 100644 --- a/scripts/build_generator_debug.bat +++ b/scripts/build_generator_debug.bat @@ -1,2 +1,2 @@ @echo off -odin build src/main_release -define:RAYLIB_SHARED=false -out:build/game_debug.exe -no-bounds-check -subsystem:windows -debug +odin build src/aseprite_odin_generator -define:RAYLIB_SHARED=true -out:build_generator/aseprite_odin_generator.exe -debug diff --git a/src/aseprite_odin_generator/aseprite_odin_generator.odin b/src/aseprite_odin_generator/aseprite_odin_generator.odin index b0012e9..d897541 100644 --- a/src/aseprite_odin_generator/aseprite_odin_generator.odin +++ b/src/aseprite_odin_generator/aseprite_odin_generator.odin @@ -23,22 +23,15 @@ main :: proc() { fmt.panicf("Couldn't load file!") } - doc: ase.Document - read, um_err := ase.unmarshal_from_slice(ase_file, &doc) - if um_err != nil { - fmt.panicf("Couldn't unmarshall file!") - } else { - fmt.printfln("Read {0} bytes from file", read) - } - - fmt.println("Header:\n\t", doc.header) - // fmt.println("Frames:\n\t", doc.frames) + cwd := os.get_current_directory() + target_dir := strings.concatenate({cwd, "\\src\\aseprite_odin_generator\\"}) atlas: rl.Image = rl.GenImageColor(ATLAS_SIZE, ATLAS_SIZE, rl.BLANK) + atlas_entries: [dynamic]gen.AtlasEntry + gen.unmarshall_aseprite_dir(target_dir, &atlas_entries) - atlas_entry := gen.atlas_entry_from_compressed_cells(doc) - // Packs the cells & blits them to the atlas - gen.pack_atlas_entries({atlas_entry}, &atlas) + + gen.pack_atlas_entries(atlas_entries[:], &atlas, 10, 10) rl.ExportImage(atlas, EXPORT_PATH) } diff --git a/src/aseprite_odin_generator/atlas.png b/src/aseprite_odin_generator/atlas.png index 36bbf354ebf3a6e00211ffc6ee1a28c9efde7c5c..afb2d717bfef7045898ca774d537aaa5911f7546 100644 GIT binary patch literal 10891 zcmeI2|5FoZ9>)TWxJ<3>+2b^G)wyyLP^r~sWIgA^9Ho4-1kj2c-#mfblO;>&pKzW1 z<;hN-eV)(f^ZvX)ubIrGMypXvMByR;fFvV5H3t9$J|X}OgdY1s!cGT;FP(9?SQu<1VLmFmJ?HsCo_HnxR7?j`?Z*>e%jQjc4D# zS$8-(>+kdjhZRCXrPG?gZQcHt|J?uO_6H?pp=5WG3&)&!6C%Nm8`-5*_1!vbubBGi zJ|n{o=12!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H?R;y?1S()^`_x)LWo)w;M?BuFFPM8-?YY_cDhWeE-4+M%}*nr_xtGChz zc2C=Z^yp|%I;gY8=Vk`7Z2k*RF$bxxdl0Nle1J>pdaH4a#iL&c4LUCeGp^pbpPDDE zWS0do;@NDl_nfe-wPL9M%f6UI+-;I+OeK#3Th>IQi#LbN%@d*r-%&1dvGKl~xV;zb z1ME#C{4&3Z`c@P;1@YBm zCBrbU4P}b=p9t9~j5tCl?>dyzJG;}0Xy>&}B)_jd)w1%2{NvcaVusM+j_!Dp2zpd{& R%Kg<8GCg-HgEmVfX (atlas_entr } /* - Takes in a slice of entries, an output texture, the width & height + Takes in a slice of entries, an output texture and offsets (offset_x/y) */ -pack_atlas_entries :: proc( - entries: []AtlasEntry, - atlas: ^rl.Image, - offset_x: int = 0, - offset_y: int = 0, -) { +pack_atlas_entries :: proc(entries: []AtlasEntry, atlas: ^rl.Image, offset_x: i32, offset_y: i32) { all_entries: [dynamic]rl.Image // it's fine to store it like this, rl.Image just stores a pointer to the data { for entry in entries { @@ -100,7 +102,7 @@ pack_atlas_entries :: proc( cellIdx: int for &entry, entryIdx in entries { for &cell in entry.cells { - // I can probably infer this information with just the id of the rect but I'm being lazy right now + // I can probably infer this information with just the id of the rect but I'm being lazy right now map_insert(&rect_idx_to_entry_and_cell, cellIdx, EntryAndCell{&entry, &cell}) rects[cellIdx].id = auto_cast entryIdx cellIdx += 1 @@ -109,13 +111,13 @@ pack_atlas_entries :: proc( for entry, entryIdx in all_entries { entry_stb_rect := &rects[entryIdx] - entry_stb_rect.w = auto_cast entry.width - entry_stb_rect.h = auto_cast entry.height + entry_stb_rect.w = stbrp.Coord(entry.width + offset_x * 2) + entry_stb_rect.h = stbrp.Coord(entry.height + offset_y * 2) } ctx: stbrp.Context - stbrp.init_target(&ctx, atlas.width, atlas.height, &nodes[0], auto_cast num_entries) - res := stbrp.pack_rects(&ctx, &rects[0], auto_cast num_entries) + stbrp.init_target(&ctx, atlas.width, atlas.height, &nodes[0], i32(num_entries)) + res := stbrp.pack_rects(&ctx, &rects[0], i32(num_entries)) if res == 1 { fmt.println("Packed everything successfully!") fmt.printfln("Rects: {0}", rects[:]) @@ -135,11 +137,12 @@ pack_atlas_entries :: proc( } // Placing it in the atlas in the calculated offsets (in the packing step) dst_rect := rl.Rectangle { - auto_cast rect.x, - auto_cast rect.y, + auto_cast rect.x + auto_cast offset_x, + auto_cast rect.y + auto_cast offset_y, auto_cast cell.width, auto_cast cell.height, } + fmt.printfln("Src rect: {0}\nDst rect:{1}", src_rect, dst_rect) rl.ImageDraw(atlas, cell^, src_rect, dst_rect, rl.WHITE) }