diff --git a/src/editor/animation_studio.jai b/src/editor/animation_studio.jai deleted file mode 100644 index 7daf3ee..0000000 --- a/src/editor/animation_studio.jai +++ /dev/null @@ -1,144 +0,0 @@ -#scope_file - -current_sheet : s32 = 0; -current_sheet_last_frame : s32 = -1; -current_sheet_ptr : *Spritesheet; - -step_offset_y : s32 = 0; -scale : float = 5; - -#scope_export - -tick_animation_studio :: () { - if input_button_states[Key_Code.ARROW_UP] & .START { - step_offset_y -= 1; - } - if input_button_states[Key_Code.ARROW_DOWN] & .START { - step_offset_y += 1; - } - - scale += mouse_delta_z; - scale = clamp(scale, 1, 10); - -} - -add_anim :: (name: string) { - anim_name := sprint("%", name); - animation := Animation.{ - name = anim_name, - spritesheet = current_sheet_ptr.name, - fps = 1 - }; - table_add(*g_animations, sprint("%", anim_name), animation); -} @Command - -sanim :: () { - Jaison :: #import "Jaison"; - anims : [..]Animation; - anims.allocator = temp; - for v : g_animations { - array_add(*anims, v); - } - #if OS != .WASM { - file :: #import "File"; - json := Jaison.json_write_string(anims, " ",, temp); - file.write_entire_file("./game/resources/animations.json", json); - } -} @Command - -lanim :: () { - Jaison :: #import "Jaison"; - s := load_string_from_pack("./game/resources/animations.json"); - success, anims := Jaison.json_parse_string(s, [..]Animation,, temp); - if !success then return; - for anims { - print("Loaded %\n", it.name); - - ids : [..]u32; - for id : it.ids { - array_add(*ids, id); - } - - name_cpy := sprint("%", it.name); - newAnimation := Animation.{ - name = name_cpy, - fps = it.fps, - spritesheet = sprint("%", it.spritesheet), - ids = ids - }; - table_add(*g_animations, name_cpy, newAnimation); - } -} @Command - -draw_animation_picker :: (theme: *GR.Overall_Theme) { - r := GR.get_rect(ui_w(80,0), ui_h(5,0), ui_w(20, 0), ui_h(95, 0)); - ui_add_mouse_occluder(r); - draw_bg_rectangle(r, theme); - r.h = ui_h(5,0); - - i := 0; - for v : g_animations { - GR.button(r, v.name, *theme.button_theme, i); - r.y += r.h; - i += 1; - } -} - -draw_animation_studio_ui :: (theme: *GR.Overall_Theme) { - if g_spritesheets.count < 1 then return; - - r := GR.get_rect(0, ui_h(5,0), ui_w(20, 0), ui_h(95, 0)); - ui_add_mouse_occluder(r); - draw_bg_rectangle(r, theme); - - sheets : [..]string; - sheets.allocator = temp; - - for v : g_spritesheets { - array_add(*sheets, v.name); - } - - r2 := r; - r2.h = ui_h(5,0); - r2.w = r.w; - GR.dropdown(r2, sheets, *current_sheet, *theme.dropdown_theme); - - if current_sheet != current_sheet_last_frame { - current_sheet_ptr = table_find_pointer(*g_spritesheets, sheets[current_sheet]); - } - - number_theme : GR.Number_Input_Theme; - - r2.y += r2.h * 1.1; - GR.label(r2, "Step X", *theme.label_theme); - r2.y += r2.h * 1.1; - GR.number_input(r2, tprint("%", current_sheet_ptr.step_x), *current_sheet_ptr.step_x, 0, 128, *number_theme); - r2.y += r2.h * 1.1; - GR.label(r2, "Step Y", *theme.label_theme); - r2.y += r2.h * 1.1; - GR.number_input(r2, tprint("%", current_sheet_ptr.step_y), *current_sheet_ptr.step_y, 0, 128, *number_theme); - - r2.y += r2.h * 1.1; - GR.label(r2, "Frames", *theme.label_theme); - r2.y += r2.h * 1.1; - GR.label(r2, "FPS", *theme.label_theme); - - uiTex := New(Ui_Texture ,,temp); - uiTex.tex = current_sheet_ptr.sheet; - if uiTex.tex.id != INVALID_ID { - menu_offset := Vector2.{ui_w(20,0), ui_h(5,0)}; - zone_r := GR.get_rect(menu_offset.x, menu_offset.y, ui_w(80,0), ui_h(95,0)); - draw_rectangle(zone_r, .{1.0, 0.0, 1.0, 1.0}); - set_shader_for_images(uiTex); - - img_r := zone_r; - img_r.y -= step_offset_y * cast(s32)current_sheet_ptr.step_y * scale; - img_r.w = current_sheet_ptr.w * scale; - img_r.h = current_sheet_ptr.h * scale; - - immediate_quad(.{img_r.x, img_r.y}, .{img_r.x + img_r.w, img_r.y}, .{img_r.x + img_r.w, img_r.y + img_r.h}, .{img_r.x, img_r.y + img_r.h}); - set_shader_for_color(); - } - draw_animation_picker(theme); -} - diff --git a/src/editor/editor.jai b/src/editor/editor.jai index 9186fad..5a9e37b 100644 --- a/src/editor/editor.jai +++ b/src/editor/editor.jai @@ -3,7 +3,6 @@ #load "picker.jai"; #load "trile_editor.jai"; #load "level_editor.jai"; - #load "animation_studio.jai"; } #if HAS_TACOMA { #load "tacoma.jai"; } #load "console.jai"; @@ -15,7 +14,6 @@ Editor_View :: enum { Closed_Editor; Trile_Editor; Level_Editor; - Animation_Editor; Material_Editor; }; @@ -52,10 +50,6 @@ draw_editor_ui :: (theme: *GR.Overall_Theme) { if GR.button(r, "Trile studio", *t_button_selectable(theme, current_editor_view == .Trile_Editor)) then current_editor_view = .Trile_Editor; - r.x -= r.w; - if GR.button(r, "Animation studio", *t_button_selectable(theme, current_editor_view == .Animation_Editor)) - then current_editor_view = .Animation_Editor; - r.x -= r.w; if GR.button(r, "Material studio", *t_button_selectable(theme, current_editor_view == .Material_Editor)) then current_editor_view = .Material_Editor; @@ -66,8 +60,6 @@ draw_editor_ui :: (theme: *GR.Overall_Theme) { draw_trile_editor_ui(theme); case .Level_Editor; draw_level_editor_ui(theme); - case .Animation_Editor; - draw_animation_studio_ui(theme); } } draw_profiler(); @@ -88,7 +80,6 @@ draw_editor :: () { draw_trile_editor(); case .Level_Editor; draw_level_editor(); - case .Animation_Editor; } } } @@ -105,8 +96,6 @@ tick_editor_ui :: () { tick_trile_editor(); case .Level_Editor; tick_level_editor(); - case .Animation_Editor; - tick_animation_studio(); } } } diff --git a/src/editor/level_editor.jai b/src/editor/level_editor.jai index 12c1dcf..4dbe5e7 100644 --- a/src/editor/level_editor.jai +++ b/src/editor/level_editor.jai @@ -178,7 +178,7 @@ draw_tacoma_tab :: (theme: *GR.Overall_Theme, total_r: GR.Rect) { #if HAS_TACOMA { if GR.button(r, "Render with Tacoma", *theme.button_theme) { cam := get_level_editor_camera(); - gen_reference(tacomaResolution, tacomaResolution, .{tacomaExposure, tacomaContrast, tacomaSaturation, 1.0, 1.0}, .{cam.target, cam.position, tacomaSamples, true}, curworld.world.*); + gen_reference(tacomaResolution, tacomaResolution, .{cam.target, cam.position, tacomaSamples, true}, curworld.world.*); } r.y += r.h; if current_screenshot.valid { diff --git a/src/editor/tacoma.jai b/src/editor/tacoma.jai index d3a652d..8de85b6 100644 --- a/src/editor/tacoma.jai +++ b/src/editor/tacoma.jai @@ -14,32 +14,7 @@ Tacoma_Screenshot :: struct { current_screenshot : Tacoma_Screenshot; -post_process_pipeline :: (color: Vector3, post_process: Post_Process) -> Vector3 { - vec3 :: (f: float) -> Vector3 { - return .{f,f,f}; - } - - v := color; - v *= pow(2.0, post_process.exposure); - v *= 0.6; - a : float = 2.51; - b : float = 0.03; - c : float = 2.43; - d : float = 0.59; - e : float = 0.14; - pre_clamp := (v*(a*v+vec3(b)))/(v*(c*v+vec3(d))+vec3(e)); - sdr : Vector3; - sdr.x = clamp(pre_clamp.x, 0.0, 1.0); - sdr.y = clamp(pre_clamp.y, 0.0, 1.0); - sdr.z = clamp(pre_clamp.z, 0.0, 1.0); - - sdr = vec3(0.5) + post_process.contrast * (sdr - vec3(0.5)); - LUMINANCE := Vector3.{0.2126, 0.7152, 0.0722}; - grayscale := dot(sdr, LUMINANCE); - return lerp(vec3(grayscale), sdr, post_process.saturation); -} - -gen_reference :: (w: s32, h: s32, postprocess: Post_Process, conf: Tacoma.Gen_Config, world: World) { +gen_reference :: (w: s32, h: s32, conf: Tacoma.Gen_Config, world: World) { // Trile BLASes. trile_list : [..]Tacoma.Trile_Data; trile_list.allocator = temp; @@ -100,8 +75,6 @@ gen_reference :: (w: s32, h: s32, postprocess: Post_Process, conf: Tacoma.Gen_Co color.y = data[it * 4 + 1]; color.z = data[it * 4 + 2]; - color = post_process_pipeline(color, postprocess); - data[it * 4 + 0] = color.x; data[it * 4 + 1] = color.y; data[it * 4 + 2] = color.z; diff --git a/src/main.jai b/src/main.jai index 25fa9ce..9e853d0 100644 --- a/src/main.jai +++ b/src/main.jai @@ -120,7 +120,6 @@ init_after_asset_pack :: () { init_editor(); lworlds(); init_spritesheets(); - lanim(); init_rendering(); load_color_lut_images(); load_post_process_from_pack(); diff --git a/src/meta/pack.jai b/src/meta/pack.jai index 9a03ae1..7bce7e2 100644 --- a/src/meta/pack.jai +++ b/src/meta/pack.jai @@ -1,3 +1,16 @@ +should_ignore_file :: (name: string) -> bool { + #import "String"; + + + ok, left, right := split_from_right(name, #char "."); + if right == "aseprite" { + print("Ignoring % as aseprite file...\n", name); + return true; + } + + return false; +} + create_pack :: () { #import "Simple_Package"; #import "File"; @@ -13,6 +26,7 @@ create_pack :: () { 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); @@ -25,6 +39,7 @@ create_pack :: () { } 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); diff --git a/src/rendering/animation.jai b/src/rendering/animation.jai index 2417d52..cfa649f 100644 --- a/src/rendering/animation.jai +++ b/src/rendering/animation.jai @@ -1,65 +1,85 @@ -g_spritesheets : Table(string, Spritesheet); g_animations: Table(string, Animation); String :: #import "String"; -Spritesheet :: struct { - name : string; - step_x : u32 = 32; - step_y : u32 = 32; - w : s32 = 0; - h : s32 = 0; - sheet : sg_image; +Frame :: struct { + x: s32; + y: s32; + w: s32; + h: s32; + duration_ms : s32; } Animation :: struct { - name : string; - spritesheet : string; - ids : [..]u32; - fps : float; + name : string; + sheet : sg_image; + sheet_w : s32; + sheet_h : s32; + frames : [..]Frame; } -load_spritesheets :: () { - Jaison :: #import "Jaison"; - s := load_string_from_pack("./game/resources/spritesheets.json"); - success, sheets := Jaison.json_parse_string(s, [..]Spritesheet,, temp); - if !success then return; - for sheets { - print("Loaded %\n", it.name); - img, w, h := create_texture_from_pack(tprint("./game/resources/sprites/%", it.name)); - name_cpy := sprint("%", it.name); - newSheet := Spritesheet.{ - name = name_cpy, - step_x = it.step_x, - step_y = it.step_y, - sheet = img, - w = w, - h = h, - }; - table_add(*g_spritesheets, name_cpy, newSheet); - } +Aseprite_Frame_Data :: struct { + x: s32; + y: s32; + w: s32; + h: s32; +} + +Aseprite_Frame :: struct { + duration : s32; + frame : Aseprite_Frame_Data; +} + +Aseprite_Frame_Tag :: struct { + name : string; + from : s32; + to : s32; +} + +Aseprite_Sheet_Info :: struct { + frameTags : [..]Aseprite_Frame_Tag; +} + +Aseprite_Sheet :: struct { + frames : [..]Aseprite_Frame; + meta : Aseprite_Sheet_Info; } init_spritesheets :: () { - load_spritesheets(); add_new_spritesheets_from_pack(); } add_new_spritesheets_from_pack :: () { for v : g_asset_pack.lookup { isSpritesheet, remainder := String.contains(v.name, "/sprites/"); - if isSpritesheet { - ok, sheet := table_find_new(*g_spritesheets, remainder); - if !ok { - print("Adding sheet: %\n", remainder); - img, w, h := create_texture_from_pack(v.name); - newSheet := Spritesheet.{ - name = remainder, - sheet = img, - w = w, - h = h, - }; - table_add(*g_spritesheets, remainder, newSheet); + isData := String.contains(remainder, ".json"); + if isSpritesheet && isData { + print("Adding sheet: %\n", remainder); + is_ok, name_without_fileformat := split_from_right(v.name, #char "."); + sheet_image_name := sprint("%.png", name_without_fileformat); + sheet_image, sheet_w, sheet_h := create_texture_from_pack(sheet_image_name); + + + s := load_string_from_pack(v.name); + success, sheet := Jaison.json_parse_string(s, Aseprite_Sheet,, temp); + + for sheet.meta.frameTags { + anim : Animation; + anim.name = sprint("%", it.name); + anim.sheet = sheet_image; + anim.sheet_w = sheet_w; + anim.sheet_h = sheet_h; + for idx : it.from..it.to { + frameData := sheet.frames[idx]; + array_add(*anim.frames, Frame.{ + frameData.frame.x, + frameData.frame.y, + frameData.frame.w, + frameData.frame.h, + frameData.duration + }); + } + table_add(*g_animations, anim.name, anim); } } }