From: Brendan Hansen Date: Sat, 20 Feb 2021 01:57:00 +0000 (-0600) Subject: random addition and efficiency gains X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=d2ddaf9f336b36ff508a6bea270047f4ca1909a1;p=onyx-prez.git random addition and efficiency gains --- diff --git a/dist/prez.wasm b/dist/prez.wasm index 598ac5a..5a1bf64 100644 Binary files a/dist/prez.wasm and b/dist/prez.wasm differ diff --git a/initial.prez b/initial.prez index 8fa408a..ddecafc 100644 --- a/initial.prez +++ b/initial.prez @@ -1,3 +1,5 @@ +[aspect_ratio 4 3] + [slide] [background 60 60 60] -[text_style undefind font_name "monospace" font_size 48 font_attr bold centered] +[text_style inherit font_name "monospace" font_size 48 font_attr bold centered] [y 50] Drop a presentation file here! diff --git a/onyx.prez b/onyx.prez index 8af1ebf..a5d7fac 100644 --- a/onyx.prez +++ b/onyx.prez @@ -60,7 +60,7 @@ [y 30] It defines: [text_style inherit padding 15] -▪ A Virtual Instruction Set Architecture +▪ Virtual Instruction Set Architecture ▪ Linear Memory Model ▪ Arbitrary imports ▪ Safe indirect function calls diff --git a/src/show_parser.onyx b/src/show_parser.onyx index a3c5d27..310930e 100644 --- a/src/show_parser.onyx +++ b/src/show_parser.onyx @@ -25,16 +25,22 @@ parse_slideshow :: (source: str, slideshow: ^Slideshow) { text_styles := map.make(str, Slide_Item_Text, default_text_style); defer map.free(^text_styles); + map.put(^text_styles, "inherit", default_text_style); variables := map.make(str, u32); defer map.free(^variables); parse_context := ParseContext.{ ^show_reader, ^variables }; - current_slide: ^Slide; - current_item_idx := 0; + current_slide: ^Slide = null; current_text_style: Slide_Item_Text; + current_slide_items := array.make(#type ^Slide_Item, 8); + defer array.free(^current_slide_items); + + aspect_ratio := 1.0f; + y_increment := 0.05f; + while !stream_end_of_file(^show_stream) { skip_whitespace(^show_reader); defer skip_whitespace(^show_reader); @@ -48,23 +54,39 @@ parse_slideshow :: (source: str, slideshow: ^Slideshow) { command_name := read_word(^show_reader, allocator=parse_alloc); if command_name == "slide" { - prev_slide := ^slideshow.slides[slideshow.slides.count - 1]; + background_color := Color.{ 0, 0, 0 }; + + if current_slide != null { + background_color = current_slide.background; + flush_items(current_slide, ^current_slide_items); + } + current_slide = slideshow_insert_slide(slideshow); - current_item_idx = 0; - // @Robustness @Incomplete: Currently, there is a fixed number of items - // on EVERY slide, which both wastes memory for small slides, and limits - // how many things can be in a slide. - slide_init(current_slide, background_color=prev_slide.background, item_count = 16); + // @NOTE: item_count is 0 because the items will be allocated and inserted later + slide_init(current_slide, + item_count = 0, + background_color = background_color, + aspect = aspect_ratio); } elseif command_name == "background" { r, g, b := parse_color(^parse_context); current_slide.background = Color.{ r, g, b }; } elseif command_name == "y" { - y := read_u32(^show_reader); + y := parse_numeric_value(^parse_context); current_text_style.y_pos = cast(f32) y / 100; } + elseif command_name == "y_inc" { + y := parse_numeric_value(^parse_context); + y_increment = cast(f32) y / 100; + } + elseif command_name == "aspect_ratio" { + w := parse_numeric_value(^parse_context); + h := parse_numeric_value(^parse_context); + + aspect_ratio = cast(f32) w / cast(f32) h; + } elseif command_name == "text_style" { text_style_name := read_word(^show_reader, numeric_allowed=true); if !map.has(^text_styles, text_style_name) { @@ -100,16 +122,14 @@ parse_slideshow :: (source: str, slideshow: ^Slideshow) { new_slide_image.kind = Slide_Item.Kind.Image; parse_image_style(^parse_context, ^new_slide_image.image, parse_alloc); - current_slide.items[current_item_idx] = new_slide_image; - current_item_idx += 1; + array.push(^current_slide_items, new_slide_image); } elseif command_name == "rect" { new_slide_rect := slideshow_make_item(slideshow); new_slide_rect.kind = Slide_Item.Kind.Rect; parse_rect_style(^parse_context, ^new_slide_rect.rect, parse_alloc); - current_slide.items[current_item_idx] = new_slide_rect; - current_item_idx += 1; + array.push(^current_slide_items, new_slide_rect); } elseif command_name == "var" { var_name := read_word(^show_reader, numeric_allowed=true); @@ -130,24 +150,32 @@ parse_slideshow :: (source: str, slideshow: ^Slideshow) { case #default { // @Memory - text := read_line(^show_reader); + text_allocator := alloc.arena.make_allocator(^slideshow.arena); + text := read_line(^show_reader, text_allocator); new_slide_text := slideshow_make_item(slideshow); new_slide_text.text = current_text_style; new_slide_text.text.text = text; // Oofta... - current_slide.items[current_item_idx] = new_slide_text; - current_item_idx += 1; + array.push(^current_slide_items, new_slide_text); - // @Robustness - // This feels like the right amount, but obviously this should change - // depending on font size, window height, etc... - current_text_style.y_pos += .05; + current_text_style.y_pos += y_increment; } } } + flush_items(current_slide, ^current_slide_items); + printf("Total slide count: %i\n", slideshow.slides.count); + + flush_items :: (slide: ^Slide, items: ^[..] ^Slide_Item) { + slide.items = memory.make_slice(#type ^Slide_Item, items.count); + for idx: items.count { + slide.items[idx] = items.data[idx]; + } + + array.clear(items); + } } #private_file diff --git a/src/slides.onyx b/src/slides.onyx index 0af702f..ce54db5 100644 --- a/src/slides.onyx +++ b/src/slides.onyx @@ -25,7 +25,8 @@ Slideshow :: struct { } Slide :: struct { - background: Color; + background : Color; + aspect_ratio : f32 = 1; items : [] ^Slide_Item; } @@ -51,7 +52,7 @@ Slide_Item_Base :: struct { Slide_Item_Text :: struct { use base := Slide_Item_Base.{ Slide_Item.Kind.Text }; - color : Color = Color.{ 1, 1, 1 }; + color := Color.{ 1, 1, 1 }; font_name : str; font_size : u32; @@ -163,11 +164,17 @@ slideshow_load_image :: (use s: ^Slideshow, image_name: str, image_path: str) -> return image; } -slide_init :: (use slide: ^Slide, background_color := Color.{0, 0, 0, 1}, item_count := 4) { +slide_init :: (use slide: ^Slide, background_color := Color.{0, 0, 0, 1}, item_count := 4, aspect := 1.0f) { background = background_color; + aspect_ratio = aspect; - items = memory.make_slice(#type ^Slide_Item, item_count); - memory.set(items.data, 0, items.count * sizeof ^Slide_Item); + if item_count > 0 { + items = memory.make_slice(#type ^Slide_Item, item_count); + memory.set(items.data, 0, items.count * sizeof ^Slide_Item); + + } else { + items.count = 0; + } } slide_render :: (use slide: ^Slide) {