Browse Source

Using #cmakedefine and making the for loop more efficient

TheComet 8 years ago
parent
commit
cc8b06c8f9

+ 6 - 9
Source/ThirdParty/ik/CMakeLists.txt

@@ -25,10 +25,6 @@ include (CheckIncludeFiles)
 set (TARGET_NAME ik)
 
 check_include_files (stdint.h IK_HAVE_STDINT_H)
-# Need to do this so "0" is actually written to the config.h file instead of nothing
-if (NOT IK_HAVE_STDINT_H)
-    set (IK_HAVE_STDINT_H 0)
-endif ()
 
 # Memory debugging options, non-DEBUG and multi-config generator will set the default to FALSE
 if (CMAKE_BUILD_TYPE STREQUAL Debug)
@@ -38,19 +34,20 @@ option (IK_MEMORY_DEBUGGING "Global switch for memory options. Keep track of the
 cmake_dependent_option (IK_MEMORY_BACKTRACE "Generate backtraces for every malloc(), making it easy to track down memory leaks" "${DEFAULT_MEMORY_DEBUGGING}" "IK_MEMORY_DEBUGGING AND NOT WEB" FALSE)
 
 # Enable restrict keyword in quaternion and vector operations if not in debug
-set (IK_RESTRICT "")
-if (NOT CMAKE_BUILD_TYPE STREQUAL Debug)
+if (NOT IK_RESTRICT)
+    set (IK_RESTRICT "")
     foreach (RESTRICT_KEYWORD restrict __restrict __restrict__)
-        check_c_source_compiles ("int test (void *${RESTRICT_KEYWORD} x); int main (void) {return 0;}" IK_HAVE_RESTRICT)
-        if (IK_HAVE_RESTRICT)
+        check_c_source_compiles ("int test (void *${RESTRICT_KEYWORD} x); int main (void) {return 0;}" IK_RESTRICT_${RESTRICT_KEYWORD})
+        if (IK_RESTRICT_${RESTRICT_KEYWORD})
             set (IK_RESTRICT ${RESTRICT_KEYWORD})
             break ()
         endif ()
     endforeach ()
+    set (IK_RESTRICT ${IK_RESTRICT} CACHE STRING "Restrict Keyword")
 endif ()
 
 set (IK_REAL float CACHE STRING "Type to use for real numbers")
-option (IK_DOT_OUTPUT "When enabled, the generated chains are dumped to DOT for debug purposes")
+option (IK_DOT_OUTPUT "When enabled, the generated chains are dumped to DOT for debug purposes" OFF)
 
 # Define source files
 define_source_files (GLOB_CPP_PATTERNS src/*.c GLOB_H_PATTERNS include/ik/*.h)

+ 1 - 1
Source/ThirdParty/ik/include/ik/chain_tree.h

@@ -106,7 +106,7 @@ count_chains_exclude_root(chain_tree_t* chain_tree);
 void
 calculate_global_rotations(chain_t* chain);
 
-#if IK_DOT_OUTPUT == ON
+#ifdef IK_DOT_OUTPUT
 /*!
  * @brief Dumps the chain tree to DOT format.
  * @param[in] root The root node of the user created tree. This is a parameter

+ 17 - 19
Source/ThirdParty/ik/include/ik/config.h.in

@@ -3,36 +3,34 @@
  * --------------------------------------------------------------*/
 
 #ifndef IK_CONFIG_HPP
-#   define IK_CONFIG_HPP
+    #define IK_CONFIG_HPP
 
     /* --------------------------------------------------------------
      * build settings
      * --------------------------------------------------------------*/
 
-#   define OFF    0
-#   define ON     1
+    #define ik_real @IK_REAL@
+    #define IK_RESTRICT @IK_RESTRICT@
 
-#   define IK_HAVE_STDINT_H @IK_HAVE_STDINT_H@
-#   define IK_RESTRICT @IK_RESTRICT@
-#   define ik_real @IK_REAL@
-#   define IK_MEMORY_DEBUGGING @IK_MEMORY_DEBUGGING@
-#   if IK_MEMORY_DEBUGGING == ON
-#       define IK_MEMORY_BACKTRACE @IK_MEMORY_BACKTRACE@
-#   endif
-#   define IK_DOT_OUTPUT @IK_DOT_OUTPUT@
+    #cmakedefine IK_HAVE_STDINT_H
+    #cmakedefine IK_MEMORY_DEBUGGING
+    #cmakedefine IK_DOT_OUTPUT
+
+    #ifdef IK_MEMORY_DEBUGGING
+        #cmakedefine IK_MEMORY_BACKTRACE
+    #endif
 
     /* --------------------------------------------------------------
      * common include files
      * --------------------------------------------------------------*/
 
-#   include "ik/export.h"
-#   include "ik/types.h"
-#   include <stddef.h>
+    #include "ik/export.h"
+    #include "ik/types.h"
 
-#   if IK_HAVE_STDINT_H == ON
-#       include <stdint.h>
-#   else
-#       include "ik/pstdint.h"
-#   endif
+    #ifdef IK_HAVE_STDINT_H
+        #include <stdint.h>
+    #else
+        #include "ik/pstdint.h"
+    #endif
 
 #endif /* IK_CONFIG_HPP */

+ 2 - 2
Source/ThirdParty/ik/include/ik/memory.h

@@ -3,7 +3,7 @@
 
 #include "ik/config.h"
 
-#if IK_MEMORY_DEBUGGING == ON
+#ifdef IK_MEMORY_DEBUGGING
 #   define MALLOC malloc_wrapper
 #   define FREE   free_wrapper
 #else
@@ -33,7 +33,7 @@ ik_memory_init(void);
 IK_PUBLIC_API uintptr_t
 ik_memory_deinit(void);
 
-#if IK_MEMORY_DEBUGGING == ON
+#ifdef IK_MEMORY_DEBUGGING
 /*!
  * @brief Does the same thing as a normal call to malloc(), but does some
  * additional work to monitor and track down memory leaks.

+ 3 - 3
Source/ThirdParty/ik/src/chain_tree.c

@@ -306,7 +306,7 @@ rebuild_chain_tree(ik_solver_t* solver)
 {
     bstv_t involved_nodes;
     int involved_nodes_count;
-#if IK_DOT_OUTPUT == ON
+#ifdef IK_DOT_OUTPUT
     char buffer[20];
     static int file_name_counter = 0;
 #endif
@@ -333,7 +333,7 @@ rebuild_chain_tree(ik_solver_t* solver)
     calculate_segment_lengths(&solver->chain_tree);
 
     /* DEBUG: Save chain tree to DOT */
-#if IK_DOT_OUTPUT == ON
+#ifdef IK_DOT_OUTPUT
     sprintf(buffer, "tree%d.dot", file_name_counter++);
     dump_to_dot(solver->tree, solver->chain_tree, buffer);
 #endif
@@ -499,7 +499,7 @@ calculate_global_rotations(chain_t* chain)
 }
 
 /* ------------------------------------------------------------------------- */
-#if IK_DOT_OUTPUT == ON
+#ifdef IK_DOT_OUTPUT
 static void
 dump_chain(ik_chain_t* chain, FILE* fp)
 {

+ 9 - 9
Source/ThirdParty/ik/src/memory.c

@@ -8,7 +8,7 @@
 
 #define BACKTRACE_OMIT_COUNT 2
 
-#if IK_MEMORY_DEBUGGING == ON
+#ifdef IK_MEMORY_DEBUGGING
 static uintptr_t g_allocations = 0;
 static uintptr_t d_deg_allocations = 0;
 static uintptr_t g_ignore_bstv_malloc = 0;
@@ -18,7 +18,7 @@ typedef struct report_info_t
 {
     uintptr_t location;
     uintptr_t size;
-#   if IK_MEMORY_BACKTRACE == ON
+#   ifdef IK_MEMORY_BACKTRACE
     int backtrace_size;
     char** backtrace;
 #   endif
@@ -81,7 +81,7 @@ malloc_wrapper(intptr_t size)
 
             /* if (enabled, generate a backtrace so we know where memory leaks
             * occurred */
-#   if IK_MEMORY_BACKTRACE == ON
+#   ifdef IK_MEMORY_BACKTRACE
             if (!(info->backtrace = get_backtrace(&info->backtrace_size)))
                 fprintf(stderr, "[memory] WARNING: Failed to generate backtrace\n");
 #   endif
@@ -97,7 +97,7 @@ malloc_wrapper(intptr_t size)
                 "The matching call to FREE() will generate a warning saying\n"
                 "something is being freed that was never allocated. This is to\n"
                 "be expected and can be ignored.\n");
-#   if IK_MEMORY_BACKTRACE == ON
+#   ifdef IK_MEMORY_BACKTRACE
                 {
                     char** bt;
                     int bt_size, i;
@@ -130,7 +130,7 @@ malloc_wrapper(intptr_t size)
 
     if (info)
     {
-#   if IK_MEMORY_BACKTRACE == ON
+#   ifdef IK_MEMORY_BACKTRACE
         if (info->backtrace)
             free(info->backtrace);
 #   endif
@@ -150,7 +150,7 @@ free_wrapper(void* ptr)
         report_info_t* info = (report_info_t*)bstv_erase(&report, (uintptr_t)ptr);
         if (info)
         {
-#   if IK_MEMORY_BACKTRACE == ON
+#   ifdef IK_MEMORY_BACKTRACE
             if (info->backtrace)
                 free(info->backtrace);
             else
@@ -161,13 +161,13 @@ free_wrapper(void* ptr)
         }
         else
         {
-#   if IK_MEMORY_BACKTRACE == ON
+#   ifdef IK_MEMORY_BACKTRACE
             char** bt;
             int bt_size, i;
             fprintf(stderr, "  -----------------------------------------\n");
 #   endif
             fprintf(stderr, "  WARNING: Freeing something that was never allocated\n");
-#   if IK_MEMORY_BACKTRACE == ON
+#   ifdef IK_MEMORY_BACKTRACE
             if ((bt = get_backtrace(&bt_size)))
             {
                 fprintf(stderr, "  backtrace to where free() was called:\n");
@@ -211,7 +211,7 @@ ik_memory_deinit(void)
             printf("  un-freed memory at %p, size %p\n", (void*)info->location, (void*)info->size);
             mutated_string_and_hex_dump((void*)info->location, info->size);
 
-#   if IK_MEMORY_BACKTRACE == ON
+#   ifdef IK_MEMORY_BACKTRACE
             printf("  Backtrace to where malloc() was called:\n");
             {
                 intptr_t i;

+ 1 - 0
Source/ThirdParty/ik/src/solver_1bone.c

@@ -3,6 +3,7 @@
 #include "ik/log.h"
 #include "ik/node.h"
 #include "ik/solver_1bone.h"
+#include <stddef.h>
 #include <assert.h>
 
 /* ------------------------------------------------------------------------- */

+ 1 - 0
Source/ThirdParty/ik/src/solver_2bone.c

@@ -4,6 +4,7 @@
 #include "ik/solver_2bone.h"
 #include <assert.h>
 #include <math.h>
+#include <stddef.h>
 
 /* ------------------------------------------------------------------------- */
 int