work on asset packer
|
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
|
Before Width: | Height: | Size: 35 KiB After Width: | Height: | Size: 35 KiB |
|
Before Width: | Height: | Size: 247 B After Width: | Height: | Size: 247 B |
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 176 B After Width: | Height: | Size: 176 B |
|
Before Width: | Height: | Size: 452 B After Width: | Height: | Size: 452 B |
|
Before Width: | Height: | Size: 656 B After Width: | Height: | Size: 656 B |
|
Before Width: | Height: | Size: 425 KiB After Width: | Height: | Size: 425 KiB |
@ -13,8 +13,13 @@ Pack_Request :: struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Loaded_Pack :: struct {
|
Loaded_Pack :: struct {
|
||||||
|
name : string;
|
||||||
nameHash : u32 = 0;
|
nameHash : u32 = 0;
|
||||||
content : Load_Package;
|
content : Load_Package;
|
||||||
|
textures : [..]sg_image;
|
||||||
|
sounds : [..]Audio_Data;
|
||||||
|
//fonts : [..]Font??;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Asset_Manager :: struct {
|
Asset_Manager :: struct {
|
||||||
@ -31,10 +36,30 @@ packcb :: (res: *sfetch_response_t) #c_call {
|
|||||||
mem.data = res.data.ptr;
|
mem.data = res.data.ptr;
|
||||||
pack: Loaded_Pack;
|
pack: Loaded_Pack;
|
||||||
pack.nameHash = hash.get_hash(g_asset_manager.packQueue[0].name);
|
pack.nameHash = hash.get_hash(g_asset_manager.packQueue[0].name);
|
||||||
|
pack.name = g_asset_manager.packQueue[0].name;
|
||||||
success := init_from_memory(*pack.content, mem, sprint("%", g_asset_manager.packQueue[0].name));
|
success := init_from_memory(*pack.content, mem, sprint("%", g_asset_manager.packQueue[0].name));
|
||||||
if !success then print("Failed to load pack!!\n");
|
if !success then print("Failed to load pack!!\n");
|
||||||
array_add(*g_asset_manager.loadedPacks, pack);
|
array_add(*g_asset_manager.loadedPacks, pack);
|
||||||
array_unordered_remove_by_index(*g_asset_manager.packQueue, 0);
|
array_unordered_remove_by_index(*g_asset_manager.packQueue, 0);
|
||||||
|
|
||||||
|
add_resources_from_pack(*pack);
|
||||||
|
}
|
||||||
|
|
||||||
|
add_resources_from_pack :: (pack: *Loaded_Pack) {
|
||||||
|
add_new_spritesheets_from_pack(*pack.content, pack.name);
|
||||||
|
load_color_lut_images(*pack.content, pack.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
find_pack_by_name :: (name: string) -> (bool, Loaded_Pack) {
|
||||||
|
nameHash := get_hash(name);
|
||||||
|
asset_pack : Loaded_Pack;
|
||||||
|
for g_asset_manager.loadedPacks {
|
||||||
|
if it.nameHash == nameHash {
|
||||||
|
return true, it;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
print("Was unable to find pack: %\n", name);
|
||||||
|
return false, .{};
|
||||||
}
|
}
|
||||||
|
|
||||||
#scope_export
|
#scope_export
|
||||||
@ -80,4 +105,77 @@ load_pack :: (name: string, shouldBlock: bool = true, shouldBlockEngine: bool =
|
|||||||
|
|
||||||
// Asset management:
|
// Asset management:
|
||||||
|
|
||||||
|
#scope_file
|
||||||
|
#scope_export
|
||||||
|
|
||||||
|
create_texture_from_pack :: (pack: string, path: string) -> (sg_image, s32, s32) {
|
||||||
|
pack_ok, pack := find_pack_by_name(pack);
|
||||||
|
ok, entry := table_find(*pack.content.lookup, path);
|
||||||
|
if !ok {
|
||||||
|
print("Failed to find texture % from pack...\n", path);
|
||||||
|
img : sg_image;
|
||||||
|
return img, 0, 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
x : s32;
|
||||||
|
y : s32;
|
||||||
|
channels : s32;
|
||||||
|
data := stbi.stbi_load_from_memory(entry.data.data, xx entry.data.count, *x, *y, *channels, 4);
|
||||||
|
img := sg_alloc_image();
|
||||||
|
|
||||||
|
subimg : [6][16]sg_range;
|
||||||
|
subimg[0][0] = .{
|
||||||
|
ptr = data,
|
||||||
|
size = xx (x * y * 4)
|
||||||
|
};
|
||||||
|
|
||||||
|
sg_init_image(img, *(sg_image_desc.{
|
||||||
|
width = x,
|
||||||
|
height = y,
|
||||||
|
pixel_format = sg_pixel_format.RGBA8,
|
||||||
|
data = .{
|
||||||
|
subimage = subimg
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
stbi.stbi_image_free(data);
|
||||||
|
|
||||||
|
return img, x, y;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// get_texture_pointer :: (pack: string, path: string) -> (ready: bool, texture: *sg_image) {
|
||||||
|
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
|
add_font_from_pack :: (pack: string, path: string) {
|
||||||
|
pack_ok, pack := find_pack_by_name(pack);
|
||||||
|
if !pack_ok then return;
|
||||||
|
for _, key : pack.content.lookup {
|
||||||
|
print("Key: %\n", key);
|
||||||
|
}
|
||||||
|
ok, entry := table_find(*pack.content.lookup, path);
|
||||||
|
if !ok {
|
||||||
|
print("Failed to find font % from pack...\n", path);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
state.font_default.fons_font = fonsAddFontMem(state.fons, "sans", entry.data.data, xx entry.data.count, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
load_string_from_pack :: (pack: string, path: string) -> string {
|
||||||
|
print("Warning: you are circumventing the asset management system....\n");
|
||||||
|
pack_ok, pack := find_pack_by_name(pack);
|
||||||
|
if !pack_ok return "";
|
||||||
|
|
||||||
|
ok, entry := table_find(*pack.content.lookup, path);
|
||||||
|
if !ok {
|
||||||
|
print("Failed to load string from pack: %\n", path);
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
s: string;
|
||||||
|
s.data = entry.data.data;
|
||||||
|
s.count = entry.data.count;
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|||||||
@ -8,7 +8,7 @@ Wav :: #import "Wav_File";
|
|||||||
audio_info : Wav.Waveformatex;
|
audio_info : Wav.Waveformatex;
|
||||||
|
|
||||||
load_wav_file :: () {
|
load_wav_file :: () {
|
||||||
audio := load_string_from_pack("./game/resources/sound/music/monoco.wav");
|
audio := load_string_from_pack("game_core", "sound/music/monoco.wav");
|
||||||
format, samples, success := Wav.get_wav_header(audio);
|
format, samples, success := Wav.get_wav_header(audio);
|
||||||
if !success print("Failed to load wav file!!!!!\n");
|
if !success print("Failed to load wav file!!!!!\n");
|
||||||
audio_info = format;
|
audio_info = format;
|
||||||
|
|||||||
56
src/load.jai
@ -3,62 +3,8 @@ g_asset_pack : Load_Package;
|
|||||||
#scope_export
|
#scope_export
|
||||||
|
|
||||||
init_after_mandatory_done : bool = false;
|
init_after_mandatory_done : bool = false;
|
||||||
|
init_after_core_done : bool = false;
|
||||||
|
|
||||||
add_font_from_pack :: (path: string) {
|
|
||||||
ok, entry := table_find(*g_asset_pack.lookup, path);
|
|
||||||
if !ok {
|
|
||||||
print("Failed to find font % from pack...\n", path);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
state.font_default.fons_font = fonsAddFontMem(state.fons, "sans", entry.data.data, xx entry.data.count, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
create_texture_from_pack :: (path: string) -> (sg_image, s32, s32) {
|
|
||||||
ok, entry := table_find(*g_asset_pack.lookup, path);
|
|
||||||
if !ok {
|
|
||||||
print("Failed to find texture % from pack...\n", path);
|
|
||||||
img : sg_image;
|
|
||||||
return img, 0, 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
x : s32;
|
|
||||||
y : s32;
|
|
||||||
channels : s32;
|
|
||||||
data := stbi.stbi_load_from_memory(entry.data.data, xx entry.data.count, *x, *y, *channels, 4);
|
|
||||||
img := sg_alloc_image();
|
|
||||||
|
|
||||||
subimg : [6][16]sg_range;
|
|
||||||
subimg[0][0] = .{
|
|
||||||
ptr = data,
|
|
||||||
size = xx (x * y * 4)
|
|
||||||
};
|
|
||||||
|
|
||||||
sg_init_image(img, *(sg_image_desc.{
|
|
||||||
width = x,
|
|
||||||
height = y,
|
|
||||||
pixel_format = sg_pixel_format.RGBA8,
|
|
||||||
data = .{
|
|
||||||
subimage = subimg
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
|
|
||||||
stbi.stbi_image_free(data);
|
|
||||||
|
|
||||||
return img, x, y;
|
|
||||||
}
|
|
||||||
|
|
||||||
load_string_from_pack :: (path: string) -> string {
|
|
||||||
ok, entry := table_find(*g_asset_pack.lookup, path);
|
|
||||||
if !ok {
|
|
||||||
print("Failed to load string from pack: %\n", path);
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
s: string;
|
|
||||||
s.data = entry.data.data;
|
|
||||||
s.count = entry.data.count;
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
asset_list :: () -> string #expand {
|
asset_list :: () -> string #expand {
|
||||||
count := 0;
|
count := 0;
|
||||||
|
|||||||
30
src/main.jai
@ -110,13 +110,19 @@ init :: () {
|
|||||||
|
|
||||||
useless_mem : [1]u8;
|
useless_mem : [1]u8;
|
||||||
debug_font = get_font_at_size(useless_mem, 15);
|
debug_font = get_font_at_size(useless_mem, 15);
|
||||||
load_pack("assets", true, true);
|
load_pack("boot", true, true);
|
||||||
|
load_pack("core", true, false);
|
||||||
|
load_pack("game_core", true, false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
init_after_asset_pack :: () {
|
init_after_mandatory :: () {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
init_after_core :: () {
|
||||||
init_plane_textures();
|
init_plane_textures();
|
||||||
add_font_from_pack("./resources/DroidSerif-Regular.ttf");
|
add_font_from_pack("boot", "DroidSerif-Regular.ttf");
|
||||||
ui_init_font_fields(*state.font_default);
|
ui_init_font_fields(*state.font_default);
|
||||||
|
|
||||||
init_ui();
|
init_ui();
|
||||||
@ -133,9 +139,7 @@ init_after_asset_pack :: () {
|
|||||||
}
|
}
|
||||||
init_editor();
|
init_editor();
|
||||||
lworlds();
|
lworlds();
|
||||||
init_spritesheets();
|
|
||||||
init_rendering();
|
init_rendering();
|
||||||
load_color_lut_images();
|
|
||||||
load_post_process_from_pack();
|
load_post_process_from_pack();
|
||||||
|
|
||||||
audio_init();
|
audio_init();
|
||||||
@ -157,12 +161,22 @@ frame :: () {
|
|||||||
|
|
||||||
asset_manager_tick();
|
asset_manager_tick();
|
||||||
|
|
||||||
if mandatory_loads_done() && !init_after_mandatory_done {
|
if !mandatory_loads_done() then return;
|
||||||
init_after_asset_pack();
|
|
||||||
|
if !init_after_mandatory_done {
|
||||||
|
init_after_mandatory();
|
||||||
init_after_mandatory_done = true;
|
init_after_mandatory_done = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if !mandatory_loads_done() then return;
|
if show_loading_screen() {
|
||||||
|
print("Should show loading screen....\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if !init_after_core_done {
|
||||||
|
init_after_core();
|
||||||
|
init_after_core_done = true;
|
||||||
|
}
|
||||||
|
|
||||||
fonsClearState(state.fons);
|
fonsClearState(state.fons);
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
should_ignore_file :: (name: string) -> bool {
|
|
||||||
#import "String";
|
#import "String";
|
||||||
|
|
||||||
|
should_ignore_file :: (name: string) -> bool {
|
||||||
|
|
||||||
ok, left, right := split_from_right(name, #char ".");
|
ok, left, right := split_from_right(name, #char ".");
|
||||||
if right == "aseprite" {
|
if right == "aseprite" {
|
||||||
@ -11,48 +11,45 @@ should_ignore_file :: (name: string) -> bool {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
util :: #import "File_Utilities";
|
||||||
|
#import "Hash_Table";
|
||||||
|
|
||||||
|
packs : Table(string, Create_Package);
|
||||||
|
|
||||||
|
file_visit_handler :: (info: *util.File_Visit_Info, user_data: bool) {
|
||||||
|
if should_ignore_file(info.short_name) then return;
|
||||||
|
|
||||||
|
_, _, packPath := split_from_left(info.full_name, "/resources/");
|
||||||
|
_, packName, fileName := split_from_left(packPath, "/");
|
||||||
|
|
||||||
|
if !table_contains(*packs, packName) {
|
||||||
|
package : Create_Package;
|
||||||
|
init(*package);
|
||||||
|
table_set(*packs, packName, package);
|
||||||
|
}
|
||||||
|
|
||||||
|
packPtr := table_find_pointer(*packs, packName);
|
||||||
|
|
||||||
|
file, ok := read_entire_file(info.full_name);
|
||||||
|
if !ok {
|
||||||
|
print("Failed in loading file to pack: %\n", fileName);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
filedata : []u8;
|
||||||
|
filedata.count = file.count;
|
||||||
|
filedata.data = file.data;
|
||||||
|
add(packPtr, fileName, filedata);
|
||||||
|
}
|
||||||
|
|
||||||
create_pack :: () {
|
create_pack :: () {
|
||||||
#import "Simple_Package";
|
#import "Simple_Package";
|
||||||
#import "File";
|
#import "File";
|
||||||
util :: #import "File_Utilities";
|
|
||||||
|
|
||||||
files_to_pack := util.file_list("./resources", true);
|
util.visit_files("./resources", true, true, file_visit_handler);
|
||||||
|
util.visit_files("./game/resources", true, true, file_visit_handler);
|
||||||
|
|
||||||
files_to_pack_game := util.file_list("./game/resources", true);
|
for pack, key : packs {
|
||||||
|
write(*pack, tprint("./packs/%.pack", key));
|
||||||
package: Create_Package;
|
|
||||||
defer deinit(*package);
|
|
||||||
init(*package);
|
|
||||||
|
|
||||||
|
|
||||||
for files_to_pack {
|
|
||||||
if should_ignore_file(it) then continue;
|
|
||||||
file, ok := read_entire_file(it);
|
|
||||||
if !ok {
|
|
||||||
print("Failed in loading file to pack: %\n", it);
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
filedata : []u8;
|
|
||||||
filedata.count = file.count;
|
|
||||||
filedata.data = file.data;
|
|
||||||
add(*package, it, filedata);
|
|
||||||
}
|
|
||||||
|
|
||||||
for files_to_pack_game {
|
|
||||||
if should_ignore_file(it) then continue;
|
|
||||||
file, ok := read_entire_file(it);
|
|
||||||
if !ok {
|
|
||||||
print("Failed in loading file to pack: %\n", it);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
filedata : []u8;
|
|
||||||
filedata.count = file.count;
|
|
||||||
filedata.data = file.data;
|
|
||||||
add(*package, it, filedata);
|
|
||||||
}
|
|
||||||
|
|
||||||
print("Packing % engine files -> ./packs/assets.pack\n", files_to_pack.count);
|
|
||||||
print("Packing % game files -> ./packs/assets.pack\n", files_to_pack_game.count);
|
|
||||||
|
|
||||||
write(*package, "./packs/assets.pack");
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -92,24 +92,20 @@ Aseprite_Sheet :: struct {
|
|||||||
meta : Aseprite_Sheet_Info;
|
meta : Aseprite_Sheet_Info;
|
||||||
}
|
}
|
||||||
|
|
||||||
init_spritesheets :: () {
|
add_new_spritesheets_from_pack :: (pack: *Load_Package, packName: string) {
|
||||||
add_new_spritesheets_from_pack();
|
|
||||||
}
|
|
||||||
|
|
||||||
add_new_spritesheets_from_pack :: () {
|
|
||||||
String :: #import "String";
|
String :: #import "String";
|
||||||
|
|
||||||
for v : g_asset_pack.lookup {
|
for v : pack.lookup {
|
||||||
isSpritesheet, remainder := String.contains(v.name, "/sprites/");
|
isSpritesheet, remainder := String.contains(v.name, "sprites/");
|
||||||
isData := String.contains(remainder, ".json");
|
isData := String.contains(remainder, ".json");
|
||||||
if isSpritesheet && isData {
|
if isSpritesheet && isData {
|
||||||
print("Adding sheet: %\n", remainder);
|
print("Adding sheet: %\n", remainder);
|
||||||
is_ok, name_without_fileformat := split_from_right(v.name, #char ".");
|
is_ok, name_without_fileformat := split_from_right(v.name, #char ".");
|
||||||
sheet_image_name := sprint("%.png", name_without_fileformat);
|
sheet_image_name := sprint("%.png", name_without_fileformat);
|
||||||
sheet_image, sheet_w, sheet_h := create_texture_from_pack(sheet_image_name);
|
sheet_image, sheet_w, sheet_h := create_texture_from_pack(packName, sheet_image_name);
|
||||||
|
|
||||||
|
|
||||||
s := load_string_from_pack(v.name);
|
s := load_string_from_pack(packName, v.name);
|
||||||
success, sheet := Jaison.json_parse_string(s, Aseprite_Sheet,, temp);
|
success, sheet := Jaison.json_parse_string(s, Aseprite_Sheet,, temp);
|
||||||
|
|
||||||
for sheet.meta.frameTags {
|
for sheet.meta.frameTags {
|
||||||
|
|||||||
@ -1063,7 +1063,7 @@ create_ssao_pipeline :: () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
init_plane_textures :: () {
|
init_plane_textures :: () {
|
||||||
gPipelines.plane.bind.images[2] = create_texture_from_pack("./resources/utiltex/water_small.png");
|
gPipelines.plane.bind.images[2] = create_texture_from_pack("core", "utiltex/water_small.png");
|
||||||
}
|
}
|
||||||
|
|
||||||
g_plane_gbuffer_vertex_buffer : sg_buffer;
|
g_plane_gbuffer_vertex_buffer : sg_buffer;
|
||||||
|
|||||||
@ -33,7 +33,7 @@ Post_Process :: struct {
|
|||||||
current_post_process : Post_Process;
|
current_post_process : Post_Process;
|
||||||
|
|
||||||
load_post_process_from_pack :: () {
|
load_post_process_from_pack :: () {
|
||||||
s := load_string_from_pack("./game/resources/postprocess.json");
|
s := load_string_from_pack("game_core", "postprocess.json");
|
||||||
success, pp:= Jaison.json_parse_string(s, Post_Process,, temp);
|
success, pp:= Jaison.json_parse_string(s, Post_Process,, temp);
|
||||||
if success {
|
if success {
|
||||||
current_post_process = pp;
|
current_post_process = pp;
|
||||||
@ -53,15 +53,14 @@ LUT_list : [..]Color_LUT;
|
|||||||
LUT_name_list : [..]string;
|
LUT_name_list : [..]string;
|
||||||
g_current_lut_texture_index : s32 = 0;
|
g_current_lut_texture_index : s32 = 0;
|
||||||
|
|
||||||
load_color_lut_images :: () {
|
load_color_lut_images :: (pack: *Load_Package, packName: string) {
|
||||||
for v : g_asset_pack.lookup {
|
for v : pack.lookup {
|
||||||
isSpritesheet := String.contains(v.name, ".colorgrade.png");
|
isSpritesheet := String.contains(v.name, ".colorgrade.png");
|
||||||
noop, remainder := String.contains(v.name, "/resources/");
|
|
||||||
if isSpritesheet {
|
if isSpritesheet {
|
||||||
print("Adding LUT: %\n", remainder);
|
print("Adding LUT: %\n", v.name);
|
||||||
img, w, h := create_texture_from_pack(v.name);
|
img, w, h := create_texture_from_pack(packName, v.name);
|
||||||
newSheet := Color_LUT.{
|
newSheet := Color_LUT.{
|
||||||
name = remainder,
|
name = v.name,
|
||||||
image = img,
|
image = img,
|
||||||
};
|
};
|
||||||
array_add(*LUT_list, newSheet);
|
array_add(*LUT_list, newSheet);
|
||||||
|
|||||||
@ -95,7 +95,7 @@ striles :: () {
|
|||||||
|
|
||||||
ltriles :: () {
|
ltriles :: () {
|
||||||
Jaison :: #import "Jaison";
|
Jaison :: #import "Jaison";
|
||||||
s := load_string_from_pack("./game/resources/triles.json");
|
s := load_string_from_pack("game_core", "triles.json");
|
||||||
success, triles := Jaison.json_parse_string(s, [..]TrileSerialize,, temp);
|
success, triles := Jaison.json_parse_string(s, [..]TrileSerialize,, temp);
|
||||||
for triles {
|
for triles {
|
||||||
set_trile(sprint("%",it.name), trile_from_serialize_form(it));
|
set_trile(sprint("%",it.name), trile_from_serialize_form(it));
|
||||||
|
|||||||
@ -53,7 +53,7 @@ sworlds :: () {
|
|||||||
} @Command
|
} @Command
|
||||||
|
|
||||||
lworlds :: () {
|
lworlds :: () {
|
||||||
s := load_string_from_pack("./game/resources/worlds.json");
|
s := load_string_from_pack("game_core", "worlds.json");
|
||||||
success, worlds := Jaison.json_parse_string(s, [..]World_Serialized,, temp);
|
success, worlds := Jaison.json_parse_string(s, [..]World_Serialized,, temp);
|
||||||
for worlds {
|
for worlds {
|
||||||
w : World;
|
w : World;
|
||||||
|
|||||||