do not use different vocabulary (enable/disable vs. pause/unpause) for the behavior's enabled-state default tip

Thu, 09 Oct 2025 19:22:21 +0200

author
Mike Becker <universe@uap-core.de>
date
Thu, 09 Oct 2025 19:22:21 +0200
changeset 279
97a1a7fb4f1a
parent 278
634fa2996d4e

do not use different vocabulary (enable/disable vs. pause/unpause) for the behavior's enabled-state

demo/snake/snake.c file | annotate | diff | comparison | revisions
src/ascension/behavior.h file | annotate | diff | comparison | revisions
src/behavior.c file | annotate | diff | comparison | revisions
--- a/demo/snake/snake.c	Thu Oct 09 19:15:02 2025 +0200
+++ b/demo/snake/snake.c	Thu Oct 09 19:22:21 2025 +0200
@@ -186,13 +186,13 @@
     );
     asc_behavior_add(node, .func = fps_counter_update, .interval = asc_seconds(1));
     asc_behavior_add(node, fps_counter_tie_to_corner);
-    asc_behavior_pause_all_while_hidden(node);
+    asc_behavior_disable_all_while_hidden(node);
     asc_ui_add_node(node);
     return node;
 }
 
 static void game_over_text_keep_centered(AscBehavior *behavior) {
-    if (!behavior->unpaused && !asc_active_window->resized) return;
+    if (!behavior->reactivated && !asc_active_window->resized) return;
 
     AscSceneNode *node = behavior->node;
     // center the "game over" text in the game field viewport
@@ -214,7 +214,7 @@
     );
 
     asc_scene_node_hide(node);
-    asc_behavior_add(node, game_over_text_keep_centered, .pause_while_hidden = true);
+    asc_behavior_add(node, game_over_text_keep_centered, .disable_while_hidden = true);
     asc_ui_add_node(node);
 
     return node;
@@ -486,7 +486,7 @@
     asc_behavior_add(node, player_main_behavior, .always_enabled = true);
     asc_behavior_add(node, player_controls);
     asc_behavior_add(node, player_move);
-    asc_behavior_pause_all_while_hidden(node);
+    asc_behavior_disable_all_while_hidden(node);
 
     return player;
 }
--- a/src/ascension/behavior.h	Thu Oct 09 19:15:02 2025 +0200
+++ b/src/ascension/behavior.h	Thu Oct 09 19:22:21 2025 +0200
@@ -49,14 +49,14 @@
     uint64_t last_execution;
     uint64_t interval;
     cxmutstr name;
-    bool pause_while_hidden;
+    bool disable_while_hidden;
     bool always_enabled;
     bool enabled;
     bool killed;
     /**
      * Indicates whether the next execution is the first execution after the behavior has been disabled temporarily.
      */
-    bool unpaused;
+    bool reactivated;
 };
 
 struct asc_behavior_create_args {
@@ -81,16 +81,16 @@
      */
     const char *name;
     /**
-     * Pauses execution of the behavior when the node is hidden.
+     * Disables the behavior while the node is hidden.
      * @see asc_scene_node_hide()
      */
-    bool pause_while_hidden;
+    bool disable_while_hidden;
     /**
      * Set to true if the behavior shall start disabled.
      */
     bool start_disabled;
     /**
-     * Behavior that cannot be disabled or paused (even by asc_behavior_disable_all()).
+     * Behavior that cannot be disabled (even by asc_behavior_disable_all()).
      *
      * Useful if you want to create a behavior that is always running (for example, a watchdog),
      * even when the node is hidden and/or all (other) behaviors are disabled.
@@ -104,7 +104,7 @@
 /**
  * Removes and destroys a behavior.
  *
- * If you just want to temporarily pause a behavior, use asc_behavior_disable().
+ * If you just want to temporarily disable a behavior, use asc_behavior_disable().
  *
  * @param behavior the behavior to remove
  * @see asc_behavior_disable()
@@ -158,28 +158,30 @@
 }
 
 /**
- * Pauses execution of the behavior when the node is hidden.
+ * Disables the behavior while the node is hidden.
  *
  * @param behavior the behavior
  * @see asc_scene_node_hide()
  */
-static inline void asc_behavior_pause_while_hidden(AscBehavior *behavior) {
-    behavior->pause_while_hidden = true;
+static inline void asc_behavior_disable_while_hidden(AscBehavior *behavior) {
+    behavior->disable_while_hidden = true;
 }
 
 /**
- * Do not pause execution of the behavior when the node is hidden.
+ * Do not disable execution of the behavior while the node is hidden.
  *
  * @param behavior the behavior
  * @see asc_scene_node_hide()
  */
-static inline void asc_behavior_continue_while_hidden(AscBehavior *behavior) {
-    behavior->pause_while_hidden = false;
+static inline void asc_behavior_enable_while_hidden(AscBehavior *behavior) {
+    behavior->disable_while_hidden = false;
 }
 
 /**
  * Enables all behaviors of a node.
  *
+ * This has no effect on behaviors that are added later to the node.
+ *
  * @param node the scene node
  */
 void asc_behavior_enable_all(AscSceneNode *node);
@@ -187,24 +189,30 @@
 /**
  * Disables all behaviors of a node.
  *
+ * This has no effect on behaviors that are added later to the node.
+ *
  * @param node the scene node
  */
 void asc_behavior_disable_all(AscSceneNode *node);
 
 /**
- * Pauses all behviors of a node when it gets hidden.
+ * Disables all behaviors of a node while it is hidden.
+ *
+ * This has no effect on behaviors that are added later to the node.
  *
  * @param node the scene node
  * @see asc_scene_node_hide()
  */
-void asc_behavior_pause_all_while_hidden(AscSceneNode *node);
+void asc_behavior_disable_all_while_hidden(AscSceneNode *node);
 
 /**
- * Makes all behaviors of a node continue even when the node is hidden.
+ * Enables all behaviors of a node while it is hidden.
+ *
+ * This has no effect on behaviors that are added later to the node.
  *
  * @param node the scene node
  * @see asc_scene_node_hide()
  */
-void asc_behavior_continue_all_while_hidden(AscSceneNode *node);
+void asc_behavior_enable_all_while_hidden(AscSceneNode *node);
 
 #endif
--- a/src/behavior.c	Thu Oct 09 19:15:02 2025 +0200
+++ b/src/behavior.c	Thu Oct 09 19:22:21 2025 +0200
@@ -63,14 +63,14 @@
     behavior->enabled = !args.start_disabled;
     behavior->always_enabled = args.always_enabled;
     behavior->killed = false;
-    behavior->unpaused = false;
+    behavior->reactivated = false;
     behavior->node = node;
     behavior->func = args.func;
     behavior->destroy_func = args.destroy_func;
     behavior->data = args.data;
     behavior->interval = args.interval;
     behavior->last_execution = 0;
-    behavior->pause_while_hidden = args.pause_while_hidden;
+    behavior->disable_while_hidden = args.disable_while_hidden;
     behavior->name = name;
     asc_dprintf("Create behavior: %"CX_PRIstr, CX_SFMT(behavior->name));
     return behavior;
@@ -85,21 +85,21 @@
 void asc_behavior_trigger(AscBehavior *behavior) {
     // the behavior is not enabled at the moment
     if (!behavior->enabled) {
-        behavior->unpaused = true;
+        behavior->reactivated = true;
         return;
     }
     // the behavior is not scheduled for execution
     if (behavior->last_execution + behavior->interval > asc_context.total_nanos) {
         return;
     }
-    // the behavior is paused while the node is hidden
-    if (!behavior->always_enabled && behavior->pause_while_hidden && asc_scene_node_is_hidden(behavior->node)) {
-        behavior->unpaused = true;
+    // the behavior is disable while the node is hidden
+    if (!behavior->always_enabled && behavior->disable_while_hidden && asc_scene_node_is_hidden(behavior->node)) {
+        behavior->reactivated = true;
         return;
     }
 
     behavior->func(behavior);
-    behavior->unpaused = false;
+    behavior->reactivated = false;
     behavior->last_execution = asc_context.total_nanos;
 }
 
@@ -126,16 +126,16 @@
     }
 }
 
-void asc_behavior_pause_all_while_hidden(AscSceneNode *node) {
+void asc_behavior_disable_all_while_hidden(AscSceneNode *node) {
     CxMapIterator iter = cxMapIteratorValues(node->behaviors);
     cx_foreach(AscBehavior*, behavior, iter) {
-        asc_behavior_pause_while_hidden(behavior);
+        asc_behavior_disable_while_hidden(behavior);
     }
 }
 
-void asc_behavior_continue_all_while_hidden(AscSceneNode *node) {
+void asc_behavior_enable_all_while_hidden(AscSceneNode *node) {
     CxMapIterator iter = cxMapIteratorValues(node->behaviors);
     cx_foreach(AscBehavior*, behavior, iter) {
-        asc_behavior_continue_while_hidden(behavior);
+        asc_behavior_enable_while_hidden(behavior);
     }
 }

mercurial