Преглед на файлове

app: auto-refresh gfx every 40 ms so vid plays

darkfi преди 11 месеца
родител
ревизия
53e768e3fb
променени са 3 файла, в които са добавени 29 реда и са изтрити 2 реда
  1. 3 1
      bin/app/src/app/schema/test.rs
  2. 8 1
      bin/app/src/gfx/anim.rs
  3. 18 0
      bin/app/src/gfx/mod.rs

+ 3 - 1
bin/app/src/app/schema/test.rs

@@ -35,12 +35,14 @@ const LIGHTMODE: bool = false;
 mod ui_consts {
     pub const CHATDB_PATH: &str = "/data/data/darkfi.app/chatdb/";
     pub const KING_PATH: &str = "king.png";
+    pub const VID_PATH: &str = "forest/forest_{frame}.png";
 }
 
 #[cfg(not(target_os = "android"))]
 mod ui_consts {
     pub const CHATDB_PATH: &str = "chatdb";
     pub const KING_PATH: &str = "assets/king.png";
+    pub const VID_PATH: &str = "assets/forest/forest_{frame}.png";
 }
 
 use ui_consts::*;
@@ -255,7 +257,7 @@ pub async fn make(app: &App, window: SceneNodePtr, i18n_fish: &I18nBabelFish) {
     prop.set_f32(atom, Role::App, 1, 400.).unwrap();
     prop.set_f32(atom, Role::App, 2, 600.).unwrap();
     prop.set_f32(atom, Role::App, 3, 600.).unwrap();
-    node.set_property_str(atom, Role::App, "path", "assets/forest/forest_{frame}.png").unwrap();
+    node.set_property_str(atom, Role::App, "path", VID_PATH).unwrap();
     node.set_property_u32(atom, Role::App, "z_index", 1).unwrap();
     node.set_property_u32(atom, Role::App, "length", 357).unwrap();
     let node = node.setup(|me| Video::new(me, app.render_api.clone(), app.ex.clone())).await;

+ 8 - 1
bin/app/src/gfx/anim.rs

@@ -55,12 +55,19 @@ pub(super) struct GfxSeqAnim {
     /// Timer between frames
     timer: std::time::Instant,
     current_idx: usize,
+    pub(super) is_visible: bool,
 }
 
 impl GfxSeqAnim {
     pub fn new(frames_len: usize, oneshot: bool) -> Self {
         let frames = vec![None; frames_len];
-        Self { oneshot, frames, timer: std::time::Instant::now(), current_idx: 0 }
+        Self {
+            oneshot,
+            frames,
+            timer: std::time::Instant::now(),
+            current_idx: 0,
+            is_visible: false,
+        }
     }
 
     pub fn set(

+ 18 - 0
bin/app/src/gfx/mod.rs

@@ -702,6 +702,7 @@ impl<'a> RenderContext<'a> {
                 }
                 GfxDrawInstruction::Animation(anim_id) => {
                     let anim = self.anims.get_mut(&anim_id).unwrap();
+                    anim.is_visible = true;
                     if let Some(dc) = anim.tick() {
                         self.draw_call(&dc, indent + 1, is_debug);
                     }
@@ -958,6 +959,18 @@ impl Stage {
         });
         god.fg_runtime.push_task(sink_task);
 
+        #[cfg(target_os = "android")]
+        {
+            // For animations do periodic refresh every 40 ms
+            let refresh_task = god.fg_ex.spawn(async move {
+                loop {
+                    darkfi::system::msleep(40).await;
+                    miniquad::window::schedule_update();
+                }
+            });
+            god.fg_runtime.push_task(refresh_task);
+        }
+
         let white_texture = ctx.new_texture_from_rgba8(1, 1, &[255, 255, 255, 255]);
 
         let mut shader_meta: ShaderMeta = shader::meta();
@@ -1565,6 +1578,11 @@ impl EventHandler for Stage {
 
         let (screen_w, screen_h) = miniquad::window::screen_size();
 
+        // Mark all anims as invisible
+        for (_, anim) in self.anims.iter_mut() {
+            anim.is_visible = false;
+        }
+
         let mut render_ctx = RenderContext {
             ctx: &mut self.ctx,
             draw_calls: &self.draw_calls,