[Bf-blender-cvs] [545d4698790] master: Cleanup: Move wm_event_system.c to C++

Hans Goudey noreply at git.blender.org
Sun Jun 5 16:54:23 CEST 2022


Commit: 545d46987900e8ae42bac39ba591b352b1880d8d
Author: Hans Goudey
Date:   Sun Jun 5 16:47:42 2022 +0200
Branches: master
https://developer.blender.org/rB545d46987900e8ae42bac39ba591b352b1880d8d

Cleanup: Move wm_event_system.c to C++

This allows the use of C++ data structures to simplify code and
improve performance.

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

M	source/blender/windowmanager/CMakeLists.txt
M	source/blender/windowmanager/WM_types.h
R090	source/blender/windowmanager/intern/wm_event_system.c	source/blender/windowmanager/intern/wm_event_system.cc

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

diff --git a/source/blender/windowmanager/CMakeLists.txt b/source/blender/windowmanager/CMakeLists.txt
index 73a5f1e6f8d..4c553d0edfe 100644
--- a/source/blender/windowmanager/CMakeLists.txt
+++ b/source/blender/windowmanager/CMakeLists.txt
@@ -39,7 +39,7 @@ set(SRC
   intern/wm_dragdrop.c
   intern/wm_draw.c
   intern/wm_event_query.c
-  intern/wm_event_system.c
+  intern/wm_event_system.cc
   intern/wm_files.c
   intern/wm_files_link.c
   intern/wm_gesture.c
diff --git a/source/blender/windowmanager/WM_types.h b/source/blender/windowmanager/WM_types.h
index 9e9f195c430..aebd62ee91b 100644
--- a/source/blender/windowmanager/WM_types.h
+++ b/source/blender/windowmanager/WM_types.h
@@ -616,6 +616,7 @@ typedef enum eWM_EventFlag {
    */
   WM_EVENT_FORCE_DRAG_THRESHOLD = (1 << 2),
 } eWM_EventFlag;
+ENUM_OPERATORS(eWM_EventFlag, WM_EVENT_FORCE_DRAG_THRESHOLD);
 
 typedef struct wmTabletData {
   /** 0=EVT_TABLET_NONE, 1=EVT_TABLET_STYLUS, 2=EVT_TABLET_ERASER. */
diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.cc
similarity index 90%
rename from source/blender/windowmanager/intern/wm_event_system.c
rename to source/blender/windowmanager/intern/wm_event_system.cc
index b28ae16c5a1..b39272c4cd7 100644
--- a/source/blender/windowmanager/intern/wm_event_system.c
+++ b/source/blender/windowmanager/intern/wm_event_system.cc
@@ -9,9 +9,9 @@
  * Also some operator reports utility functions.
  */
 
-#include <math.h>
-#include <stdlib.h>
-#include <string.h>
+#include <cmath>
+#include <cstdlib>
+#include <cstring>
 
 #include "DNA_listBase.h"
 #include "DNA_scene_types.h"
@@ -116,11 +116,11 @@ wmEvent *wm_event_add_ex(wmWindow *win,
                          const wmEvent *event_to_add,
                          const wmEvent *event_to_add_after)
 {
-  wmEvent *event = MEM_mallocN(sizeof(wmEvent), "wmEvent");
+  wmEvent *event = MEM_new<wmEvent>(__func__);
 
   *event = *event_to_add;
 
-  if (event_to_add_after == NULL) {
+  if (event_to_add_after == nullptr) {
     BLI_addtail(&win->event_queue, event);
   }
   else {
@@ -133,14 +133,14 @@ wmEvent *wm_event_add_ex(wmWindow *win,
 
 wmEvent *wm_event_add(wmWindow *win, const wmEvent *event_to_add)
 {
-  return wm_event_add_ex(win, event_to_add, NULL);
+  return wm_event_add_ex(win, event_to_add, nullptr);
 }
 
 wmEvent *WM_event_add_simulate(wmWindow *win, const wmEvent *event_to_add)
 {
   if ((G.f & G_FLAG_EVENT_SIMULATE) == 0) {
     BLI_assert_unreachable();
-    return NULL;
+    return nullptr;
   }
   wmEvent *event = wm_event_add(win, event_to_add);
 
@@ -166,7 +166,7 @@ static void wm_event_custom_free(wmEvent *event)
 
   /* NOTE: pointer to #ListBase struct elsewhere. */
   if (event->custom == EVT_DATA_DRAGDROP) {
-    ListBase *lb = event->customdata;
+    ListBase *lb = static_cast<ListBase *>(event->customdata);
     WM_drag_free_list(lb);
   }
   else {
@@ -177,7 +177,7 @@ static void wm_event_custom_free(wmEvent *event)
 static void wm_event_custom_clear(wmEvent *event)
 {
   event->custom = 0;
-  event->customdata = NULL;
+  event->customdata = nullptr;
   event->customdata_free = false;
 }
 
@@ -209,7 +209,7 @@ static void wm_event_free_last_handled(wmWindow *win, wmEvent *event)
    * As this function should be interchangeable with #wm_event_free. */
 #ifndef NDEBUG
   {
-    wmEvent *event_copy = MEM_dupallocN(event);
+    wmEvent *event_copy = static_cast<wmEvent *>(MEM_dupallocN(event));
     MEM_freeN(event);
     event = event_copy;
   }
@@ -227,8 +227,8 @@ static void wm_event_free_last_handled(wmWindow *win, wmEvent *event)
 
 static void wm_event_free_last(wmWindow *win)
 {
-  wmEvent *event = BLI_poptail(&win->event_queue);
-  if (event != NULL) {
+  wmEvent *event = static_cast<wmEvent *>(BLI_poptail(&win->event_queue));
+  if (event != nullptr) {
     wm_event_free(event);
   }
 }
@@ -236,7 +236,7 @@ static void wm_event_free_last(wmWindow *win)
 void wm_event_free_all(wmWindow *win)
 {
   wmEvent *event;
-  while ((event = BLI_pophead(&win->event_queue))) {
+  while ((event = static_cast<wmEvent *>(BLI_pophead(&win->event_queue)))) {
     wm_event_free(event);
   }
 }
@@ -270,7 +270,7 @@ void WM_event_add_notifier_ex(wmWindowManager *wm, const wmWindow *win, uint typ
     return;
   }
 
-  wmNotifier *note = MEM_callocN(sizeof(wmNotifier), "notifier");
+  wmNotifier *note = MEM_cnew<wmNotifier>(__func__);
 
   BLI_addtail(&wm->notifier_queue, note);
 
@@ -293,13 +293,13 @@ void WM_event_add_notifier(const bContext *C, uint type, void *reference)
 void WM_main_add_notifier(unsigned int type, void *reference)
 {
   Main *bmain = G_MAIN;
-  wmWindowManager *wm = bmain->wm.first;
+  wmWindowManager *wm = static_cast<wmWindowManager *>(bmain->wm.first);
 
   if (!wm || wm_test_duplicate_notifier(wm, type, reference)) {
     return;
   }
 
-  wmNotifier *note = MEM_callocN(sizeof(wmNotifier), "notifier");
+  wmNotifier *note = MEM_cnew<wmNotifier>(__func__);
 
   BLI_addtail(&wm->notifier_queue, note);
 
@@ -314,7 +314,7 @@ void WM_main_add_notifier(unsigned int type, void *reference)
 void WM_main_remove_notifier_reference(const void *reference)
 {
   Main *bmain = G_MAIN;
-  wmWindowManager *wm = bmain->wm.first;
+  wmWindowManager *wm = static_cast<wmWindowManager *>(bmain->wm.first);
 
   if (wm) {
     LISTBASE_FOREACH_MUTABLE (wmNotifier *, note, &wm->notifier_queue) {
@@ -341,8 +341,8 @@ static void wm_main_remap_assetlist(ID *old_id, ID *new_id, void *UNUSED(user_da
 
 static void wm_main_remap_msgbus_notify(ID *old_id, ID *new_id, void *user_data)
 {
-  struct wmMsgBus *mbus = user_data;
-  if (new_id != NULL) {
+  wmMsgBus *mbus = static_cast<wmMsgBus *>(user_data);
+  if (new_id != nullptr) {
     WM_msg_id_update(mbus, old_id, new_id);
   }
   else {
@@ -350,7 +350,7 @@ static void wm_main_remap_msgbus_notify(ID *old_id, ID *new_id, void *user_data)
   }
 }
 
-void WM_main_remap_editor_id_reference(const struct IDRemapper *mappings)
+void WM_main_remap_editor_id_reference(const IDRemapper *mappings)
 {
   Main *bmain = G_MAIN;
 
@@ -362,9 +362,9 @@ void WM_main_remap_editor_id_reference(const struct IDRemapper *mappings)
     }
   }
 
-  BKE_id_remapper_iter(mappings, wm_main_remap_assetlist, NULL);
+  BKE_id_remapper_iter(mappings, wm_main_remap_assetlist, nullptr);
 
-  wmWindowManager *wm = bmain->wm.first;
+  wmWindowManager *wm = static_cast<wmWindowManager *>(bmain->wm.first);
   if (wm && wm->message_bus) {
     BKE_id_remapper_iter(mappings, wm_main_remap_msgbus_notify, wm->message_bus);
   }
@@ -372,7 +372,7 @@ void WM_main_remap_editor_id_reference(const struct IDRemapper *mappings)
 
 static void wm_notifier_clear(wmNotifier *note)
 {
-  /* NULL the entire notifier, only leaving (`next`, `prev`) members intact. */
+  /* nullptr the entire notifier, only leaving (`next`, `prev`) members intact. */
   memset(((char *)note) + sizeof(Link), 0, sizeof(*note) - sizeof(Link));
 }
 
@@ -435,22 +435,22 @@ void wm_event_do_refresh_wm_and_depsgraph(bContext *C)
 
   wm_event_do_depsgraph(C, false);
 
-  CTX_wm_window_set(C, NULL);
+  CTX_wm_window_set(C, nullptr);
 }
 
 static void wm_event_execute_timers(bContext *C)
 {
   wmWindowManager *wm = CTX_wm_manager(C);
-  if (UNLIKELY(wm == NULL)) {
+  if (UNLIKELY(wm == nullptr)) {
     return;
   }
 
   /* Set the first window as context, so that there is some minimal context. This avoids crashes
    * when calling code that assumes that there is always a window in the context (which many
    * operators do). */
-  CTX_wm_window_set(C, wm->windows.first);
+  CTX_wm_window_set(C, static_cast<wmWindow *>(wm->windows.first));
   BLI_timer_execute();
-  CTX_wm_window_set(C, NULL);
+  CTX_wm_window_set(C, nullptr);
 }
 
 void wm_event_do_notifiers(bContext *C)
@@ -459,7 +459,7 @@ void wm_event_do_notifiers(bContext *C)
   wm_event_execute_timers(C);
 
   wmWindowManager *wm = CTX_wm_manager(C);
-  if (wm == NULL) {
+  if (wm == nullptr) {
     return;
   }
 
@@ -489,7 +489,7 @@ void wm_event_do_notifiers(bContext *C)
       if (note->window == win) {
         if (note->category == NC_SCREEN) {
           if (note->data == ND_WORKSPACE_SET) {
-            WorkSpace *ref_ws = note->reference;
+            WorkSpace *ref_ws = static_cast<WorkSpace *>(note->reference);
 
             UI_popup_handlers_remove_all(C, &win->modalhandlers);
 
@@ -499,7 +499,7 @@ void wm_event_do_notifiers(bContext *C)
             }
           }
           else if (note->data == ND_WORKSPACE_DELETE) {
-            WorkSpace *workspace = note->reference;
+            WorkSpace *workspace = static_cast<WorkSpace *>(note->reference);
 
             ED_workspace_delete(
                 workspace, CTX_data_main(C), C, wm); /* XXX: hum, think this over! */
@@ -508,7 +508,8 @@ void wm_event_do_notifiers(bContext *C)
             }
           }
           else if (note->data == ND_LAYOUTBROWSE) {
-            bScreen *ref_screen = BKE_workspace_layout_screen_get(note->reference);
+            bScreen *ref_screen = BKE_workspace_layout_screen_get(
+                static_cast<WorkSpaceLayout *>(note->reference));
 
             /* Free popup handlers only T35434. */
             UI_popup_handlers_remove_all(C, &win->modalhandlers);
@@ -520,7 +521,7 @@ void wm_event_do_notifiers(bContext *C)
           }
           else if (note->data == ND_LAYOUTDELETE) {
             WorkSpace *workspace = WM_window_get_active_workspace(win);
-            WorkSpaceLayout *layout = note->reference;
+            WorkSpaceLayout *layout = static_cast<WorkSpaceLayout *>(note->reference);
 
             ED_workspace_layout_delete(workspace, layout, C); /* XXX: hum, think this over! */
             if (G.debug & G_DEBUG_EVENTS) {
@@ -530,7 +531,8 @@ void wm_event_do_notifiers(bContext *C)
         }
       }
 
-      if (note->window == win || (note->window == NULL && (ELEM(note->reference, NULL, scene)))) {
+      if (note->window == win ||
+          (note->window == nullptr && (ELEM(note->reference, nullptr, scene)))) {
         if (note->category == NC_SCENE) {
           if (note->data == ND_FRAME) {
             do_anim = true;
@@ -546,7 +548,7 @@ void wm_event_do_notifiers(bContext *C)
       /* Onl

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list