Просмотр исходного кода

app: only do an initial draw when epoch == 1

darkfi 1 год назад
Родитель
Сommit
b8d2706a76

+ 0 - 6
bin/app/src/android.rs

@@ -67,12 +67,6 @@ fn send(id: usize, ev: AndroidSuggestEvent) {
     let _ = sender.try_send(ev);
 }
 
-pub fn clear_state() {
-    let mut globals = &mut GLOBALS.lock();
-    globals.senders.clear();
-    globals.next_id = 0;
-}
-
 unsafe impl Send for GlobalData {}
 unsafe impl Sync for GlobalData {}
 

+ 6 - 4
bin/app/src/app/mod.rs

@@ -36,7 +36,7 @@ use crate::android;
 use crate::{
     error::Error,
     expr::Op,
-    gfx::{GraphicsEventPublisherPtr, RenderApi, Vertex},
+    gfx::{GraphicsEventPublisherPtr, RenderApi, Vertex, EpochIndex},
     plugin::PluginSettings,
     prop::{
         Property, PropertyAtomicGuard, PropertyBool, PropertyStr, PropertySubType, PropertyType,
@@ -148,8 +148,8 @@ impl App {
     }
 
     /// Begins the draw of the tree, and then starts the UI procs.
-    pub async fn start(self: Arc<Self>, event_pub: GraphicsEventPublisherPtr) {
-        d!("Starting app");
+    pub async fn start(self: Arc<Self>, event_pub: GraphicsEventPublisherPtr, epoch: EpochIndex) {
+        d!("Starting app epoch={epoch}");
         let atom = &mut PropertyAtomicGuard::new();
 
         let window_node = self.sg_root.clone().lookup_node("/window").unwrap();
@@ -163,7 +163,9 @@ impl App {
 
         // Access drawable in window node and call draw()
         self.init();
-        self.trigger_draw().await;
+        if epoch == 1 {
+            self.trigger_draw().await;
+        }
 
         self.start_procs(event_pub).await;
         i!("App started");

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

@@ -29,7 +29,7 @@ use crate::{
     error::Error,
     expr::{self, Compiler, Op},
     gfx::{GraphicsEventPublisherPtr, Rectangle, RenderApi, Vertex},
-    mesh::{Color, MeshBuilder},
+    mesh::{Color, COLOR_PURPLE, MeshBuilder},
     prop::{
         Property, PropertyAtomicGuard, PropertyBool, PropertyFloat32, PropertyStr, PropertySubType,
         PropertyType, Role,
@@ -102,6 +102,14 @@ pub async fn make(app: &App, window: SceneNodePtr) {
         expr::load_var("h"),
         [c, c, c, 1.],
     );
+    shape.add_outline(
+        expr::const_f32(0.),
+        expr::const_f32(0.),
+        expr::load_var("w"),
+        expr::load_var("h"),
+        1.,
+        COLOR_PURPLE
+    );
     let node =
         node.setup(|me| VectorArt::new(me, shape, app.render_api.clone(), app.ex.clone())).await;
     layer_node.clone().link(node);
@@ -481,6 +489,7 @@ pub async fn make(app: &App, window: SceneNodePtr) {
     layer_node.clone().link(node);
     */
 
+    /*
     // Text edit
     let node = create_chatedit("editz");
     node.set_property_bool(atom, Role::App, "is_active", true).unwrap();
@@ -553,4 +562,5 @@ pub async fn make(app: &App, window: SceneNodePtr) {
         })
         .await;
     layer_node.clone().link(node);
+    */
 }

+ 6 - 5
bin/app/src/gfx/mod.rs

@@ -684,14 +684,12 @@ impl Stage {
     pub fn new() -> Self {
         let mut ctx: Box<dyn RenderingBackend> = window::new_rendering_backend();
 
-        // This will start the app to start. Needed since we cannot get window size for init
-        // until window is created.
         let god = GOD.get().unwrap();
-        god.start_app();
-
         // Start a new epoch. This is a brand new UI run.
         let epoch = god.render_api.next_epoch();
-
+        // This will start the app to start. Needed since we cannot get window size for init
+        // until window is created.
+        god.start_app(epoch);
         let method_rep = god.method_rep.clone();
         let event_pub = god.event_pub.clone();
         drop(god);
@@ -952,6 +950,7 @@ impl EventHandler for Stage {
     }
 
     fn resize_event(&mut self, width: f32, height: f32) {
+        t!("resize_event({width}, {height})");
         let filename = get_window_size_filename();
         if let Some(parent) = filename.parent() {
             let _ = std::fs::create_dir_all(parent);
@@ -1004,12 +1003,14 @@ impl EventHandler for Stage {
     }
 
     fn force_reload(&mut self) {
+        t!("force_reload");
         let god = GOD.get().unwrap();
         god.stop_app();
         //god.start_app();
         drop(god);
         self.clear();
         *self = Self::new();
+        t!("force_reload [DONE]");
     }
 }
 

+ 5 - 9
bin/app/src/main.rs

@@ -69,6 +69,7 @@ mod util;
 use crate::{
     app::{App, AppPtr},
     net::ZeroMQAdapter,
+    gfx::EpochIndex,
     prop::{
         Property, PropertyAtomicGuard, PropertyBool, PropertyStr, PropertySubType, PropertyType,
         Role,
@@ -213,8 +214,8 @@ impl God {
     }
 
     /// Start the app. Can only happen once the window is ready.
-    pub fn start_app(&self) {
-        info!(target: "main", "Restarting the app");
+    pub fn start_app(&self, epoch: EpochIndex) {
+        info!(target: "main", "Starting the app");
         #[cfg(target_os = "android")]
         {
             use crate::android::{get_appdata_path, get_external_storage_path};
@@ -238,21 +239,16 @@ impl God {
         let app = self.app.clone();
         let cv = self.cv_app_is_setup.clone();
         let event_pub = self.event_pub.clone();
-        let app_task = self.fg_ex.spawn(async move {
+        smol::block_on(async move {
             cv.wait().await;
-            app.start(event_pub).await;
+            app.start(event_pub, epoch).await;
         });
-        self.fg_runtime.push_task(app_task);
     }
 
     /// Put the app to sleep until the next restart.
     pub fn stop_app(&self) {
         self.fg_runtime.stop();
         self.app.stop();
-
-        #[cfg(target_os = "android")]
-        android::clear_state();
-
         info!(target: "main", "App stopped");
     }
 }

+ 1 - 0
bin/app/src/mesh.rs

@@ -35,6 +35,7 @@ pub const COLOR_LIGHTGREY: Color = [0.7, 0.7, 0.7, 1.];
 pub const COLOR_GREEN: Color = [0., 1., 0., 1.];
 pub const COLOR_BLUE: Color = [0., 0., 1., 1.];
 pub const COLOR_PINK: Color = [0.8, 0.3, 0.8, 1.];
+pub const COLOR_PURPLE: Color = [1., 0., 1., 1.];
 pub const COLOR_WHITE: Color = [1., 1., 1., 1.];
 #[allow(dead_code)]
 pub const COLOR_BLACK: Color = [1., 1., 1., 1.];