[Bf-blender-cvs] [2fa8e2686e1] xr-controller-support: Rename "threshold" to "float_threshold"

Peter Kim noreply at git.blender.org
Tue May 18 15:07:12 CEST 2021


Commit: 2fa8e2686e18adcfed7f693464a0c83224ac8f54
Author: Peter Kim
Date:   Sun May 16 03:12:56 2021 +0900
Branches: xr-controller-support
https://developer.blender.org/rB2fa8e2686e18adcfed7f693464a0c83224ac8f54

Rename "threshold" to "float_threshold"

===================================================================

M	source/blender/makesrna/intern/rna_xr.c
M	source/blender/windowmanager/WM_api.h
M	source/blender/windowmanager/xr/intern/wm_xr_actions.c
M	source/blender/windowmanager/xr/intern/wm_xr_intern.h
M	source/blender/windowmanager/xr/intern/wm_xr_session.c

===================================================================

diff --git a/source/blender/makesrna/intern/rna_xr.c b/source/blender/makesrna/intern/rna_xr.c
index 19824ee8110..8269ad3fcee 100644
--- a/source/blender/makesrna/intern/rna_xr.c
+++ b/source/blender/makesrna/intern/rna_xr.c
@@ -429,10 +429,11 @@ static bool rna_XrSessionState_action_create(bContext *C,
     }
   }
 
+  const bool is_float_action = (type == XR_FLOAT_INPUT || type == XR_VECTOR2F_INPUT);
   wmOperatorType *ot = NULL;
   IDProperty *op_properties = NULL;
 
-  if (op[0] && (type == XR_FLOAT_INPUT || type == XR_VECTOR2F_INPUT)) {
+  if (op[0] && is_float_action) {
     char idname[OP_MAX_TYPENAME];
     WM_operator_bl_idname(idname, op);
     ot = WM_operatortype_find(idname, true);
@@ -457,7 +458,7 @@ static bool rna_XrSessionState_action_create(bContext *C,
                              type,
                              count_subaction_paths,
                              subaction_paths,
-                             threshold,
+                             is_float_action ? &threshold : NULL,
                              ot,
                              op_properties,
                              op_flag);
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h
index ba91c36d5d0..877eb21d443 100644
--- a/source/blender/windowmanager/WM_api.h
+++ b/source/blender/windowmanager/WM_api.h
@@ -992,7 +992,7 @@ bool WM_xr_action_create(wmXrData *xr,
                          eXrActionType type,
                          unsigned int count_subaction_paths,
                          const char **subaction_paths,
-                         float threshold,
+                         const float *float_threshold,
                          struct wmOperatorType *ot,
                          struct IDProperty *op_properties,
                          eXrOpFlag op_flag);
diff --git a/source/blender/windowmanager/xr/intern/wm_xr_actions.c b/source/blender/windowmanager/xr/intern/wm_xr_actions.c
index cbece313930..51ed3dcfd3c 100644
--- a/source/blender/windowmanager/xr/intern/wm_xr_actions.c
+++ b/source/blender/windowmanager/xr/intern/wm_xr_actions.c
@@ -68,7 +68,7 @@ static wmXrAction *action_create(const char *action_name,
                                  eXrActionType type,
                                  unsigned int count_subaction_paths,
                                  const char **subaction_paths,
-                                 float threshold,
+                                 const float *float_threshold,
                                  wmOperatorType *ot,
                                  IDProperty *op_properties,
                                  eXrOpFlag op_flag)
@@ -109,8 +109,11 @@ static wmXrAction *action_create(const char *action_name,
   action->states = MEM_calloc_arrayN(count, size, "XrAction_States");
   action->states_prev = MEM_calloc_arrayN(count, size, "XrAction_StatesPrev");
 
-  action->threshold = threshold;
-  CLAMP(action->threshold, 0.0f, 1.0f);
+  if (float_threshold) {
+    BLI_assert(type == XR_FLOAT_INPUT || type == XR_VECTOR2F_INPUT);
+    action->float_threshold = *float_threshold;
+    CLAMP(action->float_threshold, 0.0f, 1.0f);
+  }
 
   action->ot = ot;
   action->op_properties = op_properties;
@@ -195,7 +198,7 @@ bool WM_xr_action_create(wmXrData *xr,
                          eXrActionType type,
                          unsigned int count_subaction_paths,
                          const char **subaction_paths,
-                         float threshold,
+                         const float *float_threshold,
                          wmOperatorType *ot,
                          IDProperty *op_properties,
                          eXrOpFlag op_flag)
@@ -208,7 +211,7 @@ bool WM_xr_action_create(wmXrData *xr,
                                      type,
                                      count_subaction_paths,
                                      subaction_paths,
-                                     threshold,
+                                     float_threshold,
                                      ot,
                                      op_properties,
                                      op_flag);
diff --git a/source/blender/windowmanager/xr/intern/wm_xr_intern.h b/source/blender/windowmanager/xr/intern/wm_xr_intern.h
index 083ae0cee6b..9b577c12f25 100644
--- a/source/blender/windowmanager/xr/intern/wm_xr_intern.h
+++ b/source/blender/windowmanager/xr/intern/wm_xr_intern.h
@@ -139,8 +139,8 @@ typedef struct wmXrAction {
   /** Previous states, stored to determine XR events. */
   void *states_prev;
 
-  /** Input threshold for float actions. */
-  float threshold;
+  /** Input threshold for float/vector2f actions. */
+  float float_threshold;
 
   /** The currently active subaction path (if any) for modal actions. */
   char **active_modal_path;
diff --git a/source/blender/windowmanager/xr/intern/wm_xr_session.c b/source/blender/windowmanager/xr/intern/wm_xr_session.c
index 78abc05a338..cf2d4300df0 100644
--- a/source/blender/windowmanager/xr/intern/wm_xr_session.c
+++ b/source/blender/windowmanager/xr/intern/wm_xr_session.c
@@ -726,8 +726,8 @@ static void wm_xr_session_events_dispatch(const XrSessionSettings *settings,
           case XR_FLOAT_INPUT: {
             const float *state = &((float *)action->states)[i];
             float *state_prev = &((float *)action->states_prev)[i];
-            if (fabsf(*state) > action->threshold) {
-              if (fabsf(*state_prev) <= action->threshold) {
+            if (fabsf(*state) > action->float_threshold) {
+              if (fabsf(*state_prev) <= action->float_threshold) {
                 if (modal || action->op_flag == XR_OP_PRESS) {
                   val = KM_PRESS;
                   press_start = true;
@@ -743,7 +743,7 @@ static void wm_xr_session_events_dispatch(const XrSessionSettings *settings,
                 press_start = false;
               }
             }
-            else if (fabsf(*state_prev) > action->threshold) {
+            else if (fabsf(*state_prev) > action->float_threshold) {
               if (modal || action->op_flag == XR_OP_RELEASE) {
                 val = KM_RELEASE;
                 press_start = false;
@@ -761,8 +761,8 @@ static void wm_xr_session_events_dispatch(const XrSessionSettings *settings,
           case XR_VECTOR2F_INPUT: {
             const float(*state)[2] = &((float(*)[2])action->states)[i];
             float(*state_prev)[2] = &((float(*)[2])action->states_prev)[i];
-            if (len_v2(*state) > action->threshold) {
-              if (len_v2(*state_prev) <= action->threshold) {
+            if (len_v2(*state) > action->float_threshold) {
+              if (len_v2(*state_prev) <= action->float_threshold) {
                 if (modal || action->op_flag == XR_OP_PRESS) {
                   val = KM_PRESS;
                   press_start = true;
@@ -778,7 +778,7 @@ static void wm_xr_session_events_dispatch(const XrSessionSettings *settings,
                 press_start = false;
               }
             }
-            else if (len_v2(*state_prev) > action->threshold) {
+            else if (len_v2(*state_prev) > action->float_threshold) {
               if (modal || action->op_flag == XR_OP_RELEASE) {
                 val = KM_RELEASE;
                 press_start = false;



More information about the Bf-blender-cvs mailing list