# ---------------------------------------------
[slide] [background $bbright $bbright $bbright]
+[animation fade]
[rect color 40 40 40 x 0 w 100 y 35 h 30]
[rect color 0 0 0 x 0 w 100 y 40 h 20]
# Introduce what Onyx is, the design goals, the improvements over C, etc.
[slide]
+[animation swipe]
[rect color 40 40 40 x 8 w 84 y 5 h 95]
[rect color 0 0 0 x 0 w 100 y 5 h 10]
[text_style header]
# BRIEFLY introduce WASM and its capabilities
[slide]
+[animation swipe]
[rect color 40 40 40 x 8 w 84 y 5 h 95]
[rect color 0 0 0 x 0 w 100 y 5 h 10]
[text_style header]
# High-level language features and design that make it super cozy to program in.
[slide]
+[animation swipe]
[rect color 40 40 40 x 8 w 84 y 5 h 95]
[rect color 0 0 0 x 0 w 100 y 5 h 10]
[text_style header]
# Hello, World!
[slide]
+[animation swipe]
[rect color 40 40 40 x 8 w 84 y 5 h 95]
[rect color 0 0 0 x 0 w 100 y 5 h 10]
[text_style header]
# * Running engine
[slide]
+[animation swipe]
[rect color 40 40 40 x 8 w 84 y 5 h 95]
[rect color 0 0 0 x 0 w 100 y 5 h 10]
[text_style header]
# Projects done in Onyx
[slide]
+[animation swipe]
[rect color 40 40 40 x 8 w 84 y 5 h 95]
[rect color 0 0 0 x 0 w 100 y 5 h 10]
[text_style header]
variables := map.make(str, u32);
defer map.free(^variables);
+ animations := map.make(str, #type (Allocator) -> ^Slide_Animation, default=null_proc, hash_count=2);
+ defer map.free(^animations);
+ map.put(^animations, "swipe", Slide_Animation_Swipe.make);
+ map.put(^animations, "fade", Slide_Animation_Fade.make);
+
parse_context := ParseContext.{ ^show_reader, ^variables };
current_slide: ^Slide = null;
if current_slide != null {
background_color = current_slide.background;
- flush_items(current_slide, ^current_slide_items);
+ flush_items(current_slide, ^current_slide_items, slideshow);
}
current_slide = slideshow_insert_slide(slideshow);
map.put(^variables, var_name, var_value);
}
+ elseif command_name == "animation" {
+ anim_name := read_word(^show_reader, numeric_allowed=true);
+
+ if map.has(^animations, anim_name) {
+ allocator := alloc.arena.make_allocator(^slideshow.arena);
+ current_slide.animation = (map.get(^animations, anim_name))(allocator);
+ } else {
+ printf("Unknown animation: '%s'\n", anim_name);
+
+ current_slide.animation = null;
+ }
+ }
else {
printf("******** Unknown command: '%s'.\n", command_name);
}
}
}
- flush_items(current_slide, ^current_slide_items);
+ flush_items(current_slide, ^current_slide_items, slideshow);
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);
+ flush_items :: (slide: ^Slide, items: ^[..] ^Slide_Item, slideshow: ^Slideshow) {
+ allocator := alloc.arena.make_allocator(^slideshow.arena);
+ slide.items = memory.make_slice(#type ^Slide_Item, items.count, allocator = allocator);
+
for idx: items.count {
slide.items[idx] = items.data[idx];
}
background : Color;
aspect_ratio : f32 = 1;
- animation_generator : (i32, i32) -> ^Slide_Animation;
+ animation: ^Slide_Animation;
items : [] ^Slide_Item;
}
current_slide = math.clamp(current_slide, 0, slides.count - 1);
if old_slide != current_slide {
- if slides[current_slide].animation_generator == null_proc do return;
+ current_animation = slides[old_slide].animation;
- current_animation = slides[current_slide].animation_generator(old_slide, current_slide);
+ if current_animation != null {
+ current_animation->init(old_slide, current_slide);
+ }
}
}
if current_animation == null do return;
if current_animation->update() {
- cfree(current_animation);
current_animation = null;
}
}
-slide_init :: (use slide: ^Slide, background_color := Color.{0, 0, 0, 1}, item_count := 4, aspect := 1.0f) {
+slide_init :: (use slide: ^Slide,
+ background_color := Color.{0, 0, 0, 1},
+ item_count := 0,
+ aspect := 1.0f) {
+
background = background_color;
aspect_ratio = aspect;
-
- animation_generator = fade_animation_make;
+ animation = null;
if item_count > 0 {
- items = memory.make_slice(#type ^Slide_Item, item_count);
+ // @GlobalVariable
+ allocator := alloc.arena.make_allocator(^the_slideshow.arena);
+ items = memory.make_slice(#type ^Slide_Item, item_count, allocator=allocator);
memory.set(items.data, 0, items.count * sizeof ^Slide_Item);
} else {
//
Slide_Animation :: struct {
- render : (anim: ^Slide_Animation, slideshow: ^Slideshow) -> void;
+ init : (anim: ^Slide_Animation, source: i32, target: i32) -> void;
update : (anim: ^Slide_Animation) -> bool;
+ render : (anim: ^Slide_Animation, slideshow: ^Slideshow) -> void;
source_slide : i32 = -1;
target_slide : i32 = -1;
Slide_Animation_Swipe :: struct {
use base := Slide_Animation.{
+ init = swipe_animation_init,
update = swipe_animation_update,
render = swipe_animation_render
};
t : f32 = 0;
dt : f32 = 0.03;
-}
-swipe_animation_make :: (source := -1, target := -1) -> ^Slide_Animation {
- anim := new(Slide_Animation_Swipe);
- *anim = Slide_Animation_Swipe.{};
- anim.source_slide = source;
- anim.target_slide = target;
+ make :: (allocator := context.allocator) -> ^Slide_Animation_Swipe {
+ anim := new(Slide_Animation_Swipe, allocator=allocator);
+ *anim = Slide_Animation_Swipe.{};
+
+ return anim;
+ }
+}
- return anim;
+#private_file
+swipe_animation_init :: (use anim: ^Slide_Animation_Swipe, source := -1, target := -1) {
+ source_slide = source;
+ target_slide = target;
+
+ t = 0;
}
#private_file
Slide_Animation_Fade :: struct {
use base := Slide_Animation.{
+ init = fade_animation_init,
update = fade_animation_update,
render = fade_animation_render
};
t : f32 = 0;
dt : f32 = 0.03;
-}
-fade_animation_make :: (source := -1, target := -1) -> ^Slide_Animation {
- anim := new(Slide_Animation_Fade);
- *anim = Slide_Animation_Fade.{};
- anim.source_slide = source;
- anim.target_slide = target;
+ make :: (allocator := context.allocator) -> ^Slide_Animation_Fade {
+ anim := new(Slide_Animation_Fade, allocator=allocator);
+ *anim = Slide_Animation_Fade.{};
+
+ return anim;
+ }
+}
+
+#private_file
+fade_animation_init :: (use anim: ^Slide_Animation_Fade, source := -1, target := -1) {
+ source_slide = source;
+ target_slide = target;
- return anim;
+ t = 0;
}
#private_file