[Bf-blender-cvs] [3eb2bc2c3fd] master: Cleanup: Move lineart_cpu.c to C++

Hans Goudey noreply at git.blender.org
Sun Nov 13 21:27:56 CET 2022


Commit: 3eb2bc2c3fd1170b0bfe8f96db3a285aff9759d2
Author: Hans Goudey
Date:   Sun Nov 13 14:16:15 2022 -0600
Branches: master
https://developer.blender.org/rB3eb2bc2c3fd1170b0bfe8f96db3a285aff9759d2

Cleanup: Move lineart_cpu.c to C++

To enable further mesh data structure refactoring-- access to loose
edges in particular.

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

M	source/blender/gpencil_modifiers/CMakeLists.txt
M	source/blender/gpencil_modifiers/MOD_gpencil_lineart.h
M	source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h
R091	source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c	source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.cc
M	source/blender/gpencil_modifiers/intern/lineart/lineart_intern.h
M	source/blender/makesdna/DNA_object_types.h

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

diff --git a/source/blender/gpencil_modifiers/CMakeLists.txt b/source/blender/gpencil_modifiers/CMakeLists.txt
index 8dbac602c06..8c85d977263 100644
--- a/source/blender/gpencil_modifiers/CMakeLists.txt
+++ b/source/blender/gpencil_modifiers/CMakeLists.txt
@@ -67,7 +67,7 @@ set(SRC
   # Lineart code
   intern/lineart/lineart_chain.c
   intern/lineart/lineart_cpp_bridge.cc
-  intern/lineart/lineart_cpu.c
+  intern/lineart/lineart_cpu.cc
   intern/lineart/lineart_ops.c
   intern/lineart/lineart_shadow.c
   intern/lineart/lineart_util.c
diff --git a/source/blender/gpencil_modifiers/MOD_gpencil_lineart.h b/source/blender/gpencil_modifiers/MOD_gpencil_lineart.h
index 713f070de77..0c284f8e540 100644
--- a/source/blender/gpencil_modifiers/MOD_gpencil_lineart.h
+++ b/source/blender/gpencil_modifiers/MOD_gpencil_lineart.h
@@ -10,6 +10,10 @@
 
 /* Operator types should be in exposed header. */
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 void OBJECT_OT_lineart_bake_strokes(struct wmOperatorType *ot);
 void OBJECT_OT_lineart_bake_strokes_all(struct wmOperatorType *ot);
 void OBJECT_OT_lineart_clear(struct wmOperatorType *ot);
@@ -20,3 +24,7 @@ void WM_operatortypes_lineart(void);
 struct LineartCache;
 
 void MOD_lineart_clear_cache(struct LineartCache **lc);
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h b/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h
index 22037d10a71..97a3a782131 100644
--- a/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h
+++ b/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h
@@ -14,6 +14,10 @@
 
 #include <math.h>
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 typedef struct LineartStaticMemPoolNode {
   Link item;
   size_t size;
@@ -74,6 +78,7 @@ typedef enum eLineArtElementNodeFlag {
   LRT_ELEMENT_NO_INTERSECTION = (1 << 2),
   LRT_ELEMENT_INTERSECTION_DATA = (1 << 3),
 } eLineArtElementNodeFlag;
+ENUM_OPERATORS(eLineArtElementNodeFlag, LRT_ELEMENT_INTERSECTION_DATA);
 
 typedef struct LineartElementLinkNode {
   struct LineartElementLinkNode *next, *prev;
@@ -929,3 +934,7 @@ void MOD_lineart_gpencil_generate(LineartCache *cache,
 float MOD_lineart_chain_compute_length(LineartEdgeChain *ec);
 
 void ED_operatortypes_lineart(void);
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.cc
similarity index 91%
rename from source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
rename to source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.cc
index 4b5c40c0e38..b4025454022 100644
--- a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
+++ b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.cc
@@ -49,12 +49,12 @@
 
 #include "lineart_intern.h"
 
-typedef struct LineartIsecSingle {
+struct LineartIsecSingle {
   double v1[3], v2[3];
   LineartTriangle *tri1, *tri2;
-} LineartIsecSingle;
+};
 
-typedef struct LineartIsecThread {
+struct LineartIsecThread {
   int thread_id;
 
   /* Scheduled work range. */
@@ -71,13 +71,13 @@ typedef struct LineartIsecThread {
 
   /* For individual thread reference. */
   LineartData *ld;
-} LineartIsecThread;
+};
 
-typedef struct LineartIsecData {
+struct LineartIsecData {
   LineartData *ld;
   LineartIsecThread *threads;
   int thread_count;
-} LineartIsecData;
+};
 
 static void lineart_bounding_area_link_edge(LineartData *ld,
                                             LineartBoundingArea *root_ba,
@@ -105,7 +105,7 @@ static void lineart_bounding_area_link_triangle(LineartData *ld,
                                                 int recursive,
                                                 int recursive_level,
                                                 bool do_intersection,
-                                                struct LineartIsecThread *th);
+                                                LineartIsecThread *th);
 
 static void lineart_free_bounding_area_memory(LineartBoundingArea *ba, bool recursive);
 
@@ -155,7 +155,7 @@ void lineart_edge_cut(LineartData *ld,
                       uchar mat_occlusion,
                       uint32_t shadow_bits)
 {
-  LineartEdgeSegment *seg, *i_seg, *next_seg, *prev_seg;
+  LineartEdgeSegment *i_seg, *prev_seg;
   LineartEdgeSegment *cut_start_before = 0, *cut_end_before = 0;
   LineartEdgeSegment *new_seg1 = 0, *new_seg2 = 0;
   int untouched = 0;
@@ -184,13 +184,13 @@ void lineart_edge_cut(LineartData *ld,
   /* Begin looking for starting position of the segment. */
   /* Not using a list iteration macro because of it more clear when using for loops to iterate
    * through the segments. */
-  for (seg = e->segments.first; seg; seg = seg->next) {
+  LISTBASE_FOREACH (LineartEdgeSegment *, seg, &e->segments) {
     if (LRT_DOUBLE_CLOSE_ENOUGH(seg->ratio, start)) {
       cut_start_before = seg;
       new_seg1 = cut_start_before;
       break;
     }
-    if (seg->next == NULL) {
+    if (seg->next == nullptr) {
       break;
     }
     i_seg = seg->next;
@@ -203,7 +203,7 @@ void lineart_edge_cut(LineartData *ld,
   if (!cut_start_before && LRT_DOUBLE_CLOSE_ENOUGH(1, end)) {
     untouched = 1;
   }
-  for (seg = cut_start_before; seg; seg = seg->next) {
+  for (LineartEdgeSegment *seg = cut_start_before; seg; seg = seg->next) {
     /* We tried to cut ratio existing cutting point (e.g. where the line's occluded by a triangle
      * strip). */
     if (LRT_DOUBLE_CLOSE_ENOUGH(seg->ratio, end)) {
@@ -228,10 +228,10 @@ void lineart_edge_cut(LineartData *ld,
   }
 
   /* When we still can't find any existing cut in the line, we allocate new ones. */
-  if (new_seg1 == NULL) {
+  if (new_seg1 == nullptr) {
     new_seg1 = lineart_give_segment(ld);
   }
-  if (new_seg2 == NULL) {
+  if (new_seg2 == nullptr) {
     if (untouched) {
       new_seg2 = new_seg1;
       cut_end_before = new_seg2;
@@ -244,7 +244,7 @@ void lineart_edge_cut(LineartData *ld,
   if (cut_start_before) {
     if (cut_start_before != new_seg1) {
       /* Insert cutting points for when a new cut is needed. */
-      i_seg = cut_start_before->prev ? cut_start_before->prev : NULL;
+      i_seg = cut_start_before->prev ? cut_start_before->prev : nullptr;
       if (i_seg) {
         new_seg1->occlusion = i_seg->occlusion;
         new_seg1->material_mask_bits = i_seg->material_mask_bits;
@@ -257,7 +257,7 @@ void lineart_edge_cut(LineartData *ld,
   else {
     /* We have yet to reach a existing cutting point even after we searched the whole line, so we
      * append the new cut to the end. */
-    i_seg = e->segments.last;
+    i_seg = static_cast<LineartEdgeSegment *>(e->segments.last);
     new_seg1->occlusion = i_seg->occlusion;
     new_seg1->material_mask_bits = i_seg->material_mask_bits;
     new_seg1->shadow_mask_bits = i_seg->shadow_mask_bits;
@@ -266,7 +266,7 @@ void lineart_edge_cut(LineartData *ld,
   if (cut_end_before) {
     /* The same manipulation as on "cut_start_before". */
     if (cut_end_before != new_seg2) {
-      i_seg = cut_end_before->prev ? cut_end_before->prev : NULL;
+      i_seg = cut_end_before->prev ? cut_end_before->prev : nullptr;
       if (i_seg) {
         new_seg2->occlusion = i_seg->occlusion;
         new_seg2->material_mask_bits = i_seg->material_mask_bits;
@@ -276,7 +276,7 @@ void lineart_edge_cut(LineartData *ld,
     }
   }
   else {
-    i_seg = e->segments.last;
+    i_seg = static_cast<LineartEdgeSegment *>(e->segments.last);
     new_seg2->occlusion = i_seg->occlusion;
     new_seg2->material_mask_bits = i_seg->material_mask_bits;
     new_seg2->shadow_mask_bits = i_seg->shadow_mask_bits;
@@ -297,7 +297,7 @@ void lineart_edge_cut(LineartData *ld,
   }
 
   /* Register 1 level of occlusion for all touched segments. */
-  for (seg = new_seg1; seg && seg != new_seg2; seg = seg->next) {
+  for (LineartEdgeSegment *seg = new_seg1; seg && seg != new_seg2; seg = seg->next) {
     seg->occlusion += mat_occlusion;
     seg->material_mask_bits |= material_mask_bits;
 
@@ -319,9 +319,8 @@ void lineart_edge_cut(LineartData *ld,
 
   /* Reduce adjacent cutting points of the same level, which saves memory. */
   int8_t min_occ = 127;
-  prev_seg = NULL;
-  for (seg = e->segments.first; seg; seg = next_seg) {
-    next_seg = seg->next;
+  prev_seg = nullptr;
+  LISTBASE_FOREACH_MUTABLE (LineartEdgeSegment *, seg, &e->segments) {
 
     if (prev_seg && prev_seg->occlusion == seg->occlusion &&
         prev_seg->material_mask_bits == seg->material_mask_bits &&
@@ -352,8 +351,8 @@ BLI_INLINE bool lineart_occlusion_is_adjacent_intersection(LineartEdge *e, Linea
 static void lineart_bounding_area_triangle_reallocate(LineartBoundingArea *ba)
 {
   ba->max_triangle_count *= 2;
-  ba->linked_triangles = MEM_recallocN(ba->linked_triangles,
-                                       sizeof(LineartTriangle *) * ba->max_triangle_count);
+  ba->linked_triangles = static_cast<LineartTriangle **>(
+      MEM_recallocN(ba->linked_triangles, sizeof(LineartTriangle *) * ba->max_triangle_count));
 }
 
 static void lineart_bounding_area_line_add(LineartBoundingArea *ba, LineartEdge *e)
@@ -365,8 +364,8 @@ static void lineart_bounding_area_line_add(LineartBoundingArea *ba, LineartEdge
     return;
   }
   if (ba->line_count >= ba->max_line_count) {
-    LineartEdge **new_array = MEM_mallocN(sizeof(LineartEdge *) * ba->max_line_count * 2,
-                                          "new ba_line_array");
+    LineartEdge **new_array = static_cast<LineartEdge **>(
+        MEM_malloc_arrayN(ba->max_line_count * 2, sizeof(LineartEdge *), __func__));
     memcpy(new_array, ba->linked_lines, sizeof(LineartEdge *) * ba->max_line_count);
     ba->max_line_count *= 2;
     MEM_freeN(ba->linked_lines);
@@ -443,7 +442,7 @@ static int lineart_occlusion_make_task_info(LineartData *ld, LineartRenderTaskIn
   return res;
 }
 
-static void lineart_occlusion_worker(TaskPool *__restrict UNUSED(pool), LineartRenderTaskInfo *rti)
+static void lineart_occlusion_worker(TaskPool *__restrict /*pool*/, LineartRenderTaskInfo *rti)
 {
   LineartData *ld = rti->ld;
   LineartEdge *eip;
@@ -464,16 +463,16 @@ static void lineart_occlusion_w

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list