diff options
Diffstat (limited to 'source/blender/blenlib/intern')
-rw-r--r-- | source/blender/blenlib/intern/BLI_ghash.c | 2 | ||||
-rw-r--r-- | source/blender/blenlib/intern/boxpack2d.c | 20 | ||||
-rw-r--r-- | source/blender/blenlib/intern/dynlib.c | 103 | ||||
-rw-r--r-- | source/blender/blenlib/intern/fileops.c | 6 | ||||
-rw-r--r-- | source/blender/blenlib/intern/listbase.c | 49 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_color.c | 4 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_geom.c | 32 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_geom_inline.c | 14 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_vector_inline.c | 6 | ||||
-rw-r--r-- | source/blender/blenlib/intern/noise.c | 16 | ||||
-rw-r--r-- | source/blender/blenlib/intern/path_util.c | 54 | ||||
-rw-r--r-- | source/blender/blenlib/intern/pbvh.c | 138 | ||||
-rw-r--r-- | source/blender/blenlib/intern/string.c | 112 | ||||
-rw-r--r-- | source/blender/blenlib/intern/winstuff.c | 38 |
14 files changed, 312 insertions, 282 deletions
diff --git a/source/blender/blenlib/intern/BLI_ghash.c b/source/blender/blenlib/intern/BLI_ghash.c index f4a47ae4bf0..0c9d6230f1e 100644 --- a/source/blender/blenlib/intern/BLI_ghash.c +++ b/source/blender/blenlib/intern/BLI_ghash.c @@ -175,7 +175,7 @@ unsigned int BLI_ghashutil_inthash(const void *ptr) { key += ~(key << 9); key ^= (key >> 17); - return (unsigned int)(key & 0xffffffff); + return (unsigned int)(key & 0xffffffff); } int BLI_ghashutil_intcmp(const void *a, const void *b) { diff --git a/source/blender/blenlib/intern/boxpack2d.c b/source/blender/blenlib/intern/boxpack2d.c index 4c16363f6d3..8c7e097d239 100644 --- a/source/blender/blenlib/intern/boxpack2d.c +++ b/source/blender/blenlib/intern/boxpack2d.c @@ -174,7 +174,7 @@ void boxPack2D(boxPack *boxarray, const int len, float *tot_width, float *tot_he vertex_pack_indices = MEM_mallocN( len*3*sizeof(int), "boxPack Indices"); for (box=boxarray, box_index=0, i=0; box_index < len; box_index++, box++) { - + vert->blb = vert->brb = vert->tlb =\ vert->isect_cache[0] = vert->isect_cache[1] =\ vert->isect_cache[2] = vert->isect_cache[3] = NULL; @@ -260,17 +260,17 @@ void boxPack2D(boxPack *boxarray, const int len, float *tot_width, float *tot_he if (vert->free & quad_flags[j]) { switch (j) { case BL: - SET_BOXRIGHT(box, vert->x); - SET_BOXTOP(box, vert->y); - break; + SET_BOXRIGHT(box, vert->x); + SET_BOXTOP(box, vert->y); + break; case TR: - SET_BOXLEFT(box, vert->x); - SET_BOXBOTTOM(box, vert->y); - break; + SET_BOXLEFT(box, vert->x); + SET_BOXBOTTOM(box, vert->y); + break; case TL: - SET_BOXRIGHT(box, vert->x); - SET_BOXBOTTOM(box, vert->y); - break; + SET_BOXRIGHT(box, vert->x); + SET_BOXBOTTOM(box, vert->y); + break; case BR: SET_BOXLEFT(box, vert->x); SET_BOXTOP(box, vert->y); diff --git a/source/blender/blenlib/intern/dynlib.c b/source/blender/blenlib/intern/dynlib.c index 855fa2dfbf9..ae6589b6538 100644 --- a/source/blender/blenlib/intern/dynlib.c +++ b/source/blender/blenlib/intern/dynlib.c @@ -31,110 +31,101 @@ * \ingroup bli */ - +#include <stdio.h> #include <stdlib.h> +#include <string.h> -#include "../PIL_dynlib.h" +#include "MEM_guardedalloc.h" -#if !defined(CHAR_MAX) -#define CHAR_MAX 255 -#endif +#include "BLI_dynlib.h" + +struct DynamicLibrary { + void *handle; +}; -/* - * XXX, should use mallocN so we can see - * handle's not being released. fixme zr - */ - #ifdef WIN32 -#include <string.h> -#include <stdio.h> #include <windows.h> -struct PILdynlib { - void *handle; -}; - -PILdynlib *PIL_dynlib_open(char *name) { +DynamicLibrary *BLI_dynlib_open(char *name) +{ + DynamicLibrary *lib; void *handle= LoadLibrary(name); - if (handle) { - PILdynlib *lib= malloc(sizeof(*lib)); - lib->handle= handle; - - return lib; - } else { + if(!handle) return NULL; - } + + lib= MEM_callocN(sizeof(*lib), "Dynamic Library"); + lib->handle= handle; + + return lib; } -void *PIL_dynlib_find_symbol(PILdynlib* lib, const char *symname) { +void *BLI_dynlib_find_symbol(DynamicLibrary *lib, const char *symname) +{ return GetProcAddress(lib->handle, symname); } -char *PIL_dynlib_get_error_as_string(PILdynlib* lib) { +char *BLI_dynlib_get_error_as_string(DynamicLibrary *lib) +{ int err; /* if lib is NULL reset the last error code */ err= GetLastError(); - if (!lib) SetLastError(ERROR_SUCCESS); + if(!lib) + SetLastError(ERROR_SUCCESS); - if (err) { + if(err) { static char buf[1024]; - if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, - err, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - buf, - sizeof(buf), - NULL)) + if(FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + buf, sizeof(buf), NULL)) return buf; } return NULL; } -void PIL_dynlib_close(PILdynlib *lib) { +void BLI_dynlib_close(DynamicLibrary *lib) +{ FreeLibrary(lib->handle); - - free(lib); + MEM_freeN(lib); } -#else /* Unix */ +#else /* Unix */ #include <dlfcn.h> -struct PILdynlib { - void *handle; -}; - -PILdynlib *PIL_dynlib_open(char *name) { +DynamicLibrary *BLI_dynlib_open(char *name) +{ + DynamicLibrary *lib; void *handle= dlopen(name, RTLD_LAZY); - if (handle) { - PILdynlib *lib= malloc(sizeof(*lib)); - lib->handle= handle; - - return lib; - } else { + if(!handle) return NULL; - } + + lib= MEM_callocN(sizeof(*lib), "Dynamic Library"); + lib->handle= handle; + + return lib; } -void *PIL_dynlib_find_symbol(PILdynlib* lib, const char *symname) { +void *BLI_dynlib_find_symbol(DynamicLibrary *lib, const char *symname) +{ return dlsym(lib->handle, symname); } -char *PIL_dynlib_get_error_as_string(PILdynlib* lib) { +char *BLI_dynlib_get_error_as_string(DynamicLibrary *lib) +{ (void)lib; /* unused */ return dlerror(); } -void PIL_dynlib_close(PILdynlib *lib) { +void BLI_dynlib_close(DynamicLibrary *lib) +{ dlclose(lib->handle); - - free(lib); + MEM_freeN(lib); } #endif diff --git a/source/blender/blenlib/intern/fileops.c b/source/blender/blenlib/intern/fileops.c index 2407078fc76..2e0f4b483b1 100644 --- a/source/blender/blenlib/intern/fileops.c +++ b/source/blender/blenlib/intern/fileops.c @@ -133,13 +133,13 @@ int BLI_is_writable(const char *filename) int BLI_touch(const char *file) { - FILE *f = fopen(file,"r+b"); - if (f != NULL) { + FILE *f = fopen(file,"r+b"); + if (f != NULL) { char c = getc(f); rewind(f); putc(c,f); } else { - f = fopen(file,"wb"); + f = fopen(file,"wb"); } if (f) { fclose(f); diff --git a/source/blender/blenlib/intern/listbase.c b/source/blender/blenlib/intern/listbase.c index 15bdb4a446f..05f71e0c01f 100644 --- a/source/blender/blenlib/intern/listbase.c +++ b/source/blender/blenlib/intern/listbase.c @@ -366,14 +366,30 @@ void *BLI_findstring(const ListBase *listbase, const char *id, const int offset) if (listbase == NULL) return NULL; - link= listbase->first; - while (link) { + for (link= listbase->first; link; link= link->next) { id_iter= ((const char *)link) + offset; - if(id[0] == id_iter[0] && strcmp(id, id_iter)==0) + if (id[0] == id_iter[0] && strcmp(id, id_iter)==0) { return link; + } + } - link= link->next; + return NULL; +} +/* same as above but find reverse */ +void *BLI_rfindstring(const ListBase *listbase, const char *id, const int offset) +{ + Link *link= NULL; + const char *id_iter; + + if (listbase == NULL) return NULL; + + for (link= listbase->last; link; link= link->prev) { + id_iter= ((const char *)link) + offset; + + if (id[0] == id_iter[0] && strcmp(id, id_iter)==0) { + return link; + } } return NULL; @@ -386,15 +402,32 @@ void *BLI_findstring_ptr(const ListBase *listbase, const char *id, const int off if (listbase == NULL) return NULL; - link= listbase->first; - while (link) { + for (link= listbase->first; link; link= link->next) { /* exact copy of BLI_findstring(), except for this line */ id_iter= *((const char **)(((const char *)link) + offset)); - if(id[0] == id_iter[0] && strcmp(id, id_iter)==0) + if (id[0] == id_iter[0] && strcmp(id, id_iter)==0) { return link; + } + } - link= link->next; + return NULL; +} +/* same as above but find reverse */ +void *BLI_rfindstring_ptr(const ListBase *listbase, const char *id, const int offset) +{ + Link *link= NULL; + const char *id_iter; + + if (listbase == NULL) return NULL; + + for (link= listbase->last; link; link= link->prev) { + /* exact copy of BLI_rfindstring(), except for this line */ + id_iter= *((const char **)(((const char *)link) + offset)); + + if (id[0] == id_iter[0] && strcmp(id, id_iter)==0) { + return link; + } } return NULL; diff --git a/source/blender/blenlib/intern/math_color.c b/source/blender/blenlib/intern/math_color.c index 85636d23f6f..512086f0e17 100644 --- a/source/blender/blenlib/intern/math_color.c +++ b/source/blender/blenlib/intern/math_color.c @@ -463,14 +463,14 @@ int constrain_rgb(float *r, float *g, float *b) float w; /* Amount of white needed is w = - min(0, *r, *g, *b) */ - + w = (0 < *r) ? 0 : *r; w = (w < *g) ? w : *g; w = (w < *b) ? w : *b; w = -w; /* Add just enough white to make r, g, b all positive. */ - + if (w > 0) { *r += w; *g += w; *b += w; return 1; /* Color modified to fit RGB gamut */ diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c index 71f12d23d53..37e7a04439b 100644 --- a/source/blender/blenlib/intern/math_geom.c +++ b/source/blender/blenlib/intern/math_geom.c @@ -486,7 +486,6 @@ int isect_line_tri_v3(const float p1[3], const float p2[3], const float v0[3], c return 1; } - /* moved from effect.c test if the ray starting at p1 going in d direction intersects the triangle v0..v2 return non zero if it does @@ -527,6 +526,35 @@ int isect_ray_tri_v3(const float p1[3], const float d[3], const float v0[3], con return 1; } +int isect_ray_plane_v3(float p1[3], float d[3], float v0[3], float v1[3], float v2[3], float *lambda, int clip) +{ + float p[3], s[3], e1[3], e2[3], q[3]; + float a, f, u, v; + + sub_v3_v3v3(e1, v1, v0); + sub_v3_v3v3(e2, v2, v0); + + cross_v3_v3v3(p, d, e2); + a = dot_v3v3(e1, p); + /* note: these values were 0.000001 in 2.4x but for projection snapping on + * a human head (1BU==1m), subsurf level 2, this gave many errors - campbell */ + if ((a > -0.00000001f) && (a < 0.00000001f)) return 0; + f = 1.0f/a; + + sub_v3_v3v3(s, p1, v0); + + u = f * dot_v3v3(s, p); + + cross_v3_v3v3(q, s, e1); + + v = f * dot_v3v3(d, q); + + *lambda = f * dot_v3v3(e2, q); + if (clip && (*lambda < 0.0f)) return 0; + + return 1; +} + int isect_ray_tri_epsilon_v3(const float p1[3], const float d[3], const float v0[3], const float v1[3], const float v2[3], float *lambda, float uv[2], const float epsilon) { float p[3], s[3], e1[3], e2[3], q[3]; @@ -1761,7 +1789,7 @@ void orthographic_m4(float matrix[][4], const float left, const float right, con matrix[3][2] = -(farClip + nearClip)/Zdelta; } -void perspective_m4(float mat[][4],float left, const float right, const float bottom, const float top, const float nearClip, const float farClip) +void perspective_m4(float mat[4][4], const float left, const float right, const float bottom, const float top, const float nearClip, const float farClip) { float Xdelta, Ydelta, Zdelta; diff --git a/source/blender/blenlib/intern/math_geom_inline.c b/source/blender/blenlib/intern/math_geom_inline.c index 48fcbcfe140..41dce131c17 100644 --- a/source/blender/blenlib/intern/math_geom_inline.c +++ b/source/blender/blenlib/intern/math_geom_inline.c @@ -42,12 +42,12 @@ MINLINE void zero_sh(float r[9]) memset(r, 0, sizeof(float)*9); } -MINLINE void copy_sh_sh(float r[9], float a[9]) +MINLINE void copy_sh_sh(float r[9], const float a[9]) { memcpy(r, a, sizeof(float)*9); } -MINLINE void mul_sh_fl(float r[9], float f) +MINLINE void mul_sh_fl(float r[9], const float f) { int i; @@ -55,7 +55,7 @@ MINLINE void mul_sh_fl(float r[9], float f) r[i] *= f; } -MINLINE void add_sh_shsh(float r[9], float a[9], float b[9]) +MINLINE void add_sh_shsh(float r[9], const float a[9], const float b[9]) { int i; @@ -74,7 +74,7 @@ MINLINE float dot_shsh(float a[9], float b[9]) return r; } -MINLINE float diffuse_shv3(float sh[9], float v[3]) +MINLINE float diffuse_shv3(float sh[9], const float v[3]) { /* See formula (13) in: "An Efficient Representation for Irradiance Environment Maps" */ @@ -96,7 +96,7 @@ MINLINE float diffuse_shv3(float sh[9], float v[3]) return sum; } -MINLINE void vec_fac_to_sh(float r[9], float v[3], float f) +MINLINE void vec_fac_to_sh(float r[9], const float v[3], const float f) { /* See formula (3) in: "An Efficient Representation for Irradiance Environment Maps" */ @@ -122,7 +122,7 @@ MINLINE void vec_fac_to_sh(float r[9], float v[3], float f) copy_sh_sh(r, sh); } -MINLINE float eval_shv3(float sh[9], float v[3]) +MINLINE float eval_shv3(float sh[9], const float v[3]) { float tmp[9]; @@ -130,7 +130,7 @@ MINLINE float eval_shv3(float sh[9], float v[3]) return dot_shsh(tmp, sh); } -MINLINE void madd_sh_shfl(float r[9], float sh[3], float f) +MINLINE void madd_sh_shfl(float r[9], const float sh[3], const float f) { float tmp[9]; diff --git a/source/blender/blenlib/intern/math_vector_inline.c b/source/blender/blenlib/intern/math_vector_inline.c index 3470ec92664..dc3baf1698a 100644 --- a/source/blender/blenlib/intern/math_vector_inline.c +++ b/source/blender/blenlib/intern/math_vector_inline.c @@ -315,7 +315,7 @@ MINLINE float dot_v3v3(const float a[3], const float b[3]) MINLINE float cross_v2v2(const float a[2], const float b[2]) { - return a[0]*b[1] - a[1]*b[0]; + return a[0]*b[1] - a[1]*b[0]; } MINLINE void cross_v3_v3v3(float r[3], const float a[3], const float b[3]) @@ -447,14 +447,14 @@ MINLINE float normalize_v3(float n[3]) return normalize_v3_v3(n, n); } -MINLINE void normal_short_to_float_v3(float *out, const short *in) +MINLINE void normal_short_to_float_v3(float out[3], const short in[3]) { out[0] = in[0]*(1.0f/32767.0f); out[1] = in[1]*(1.0f/32767.0f); out[2] = in[2]*(1.0f/32767.0f); } -MINLINE void normal_float_to_short_v3(short *out, const float *in) +MINLINE void normal_float_to_short_v3(short out[3], const float in[3]) { out[0] = (short)(in[0]*32767.0f); out[1] = (short)(in[1]*32767.0f); diff --git a/source/blender/blenlib/intern/noise.c b/source/blender/blenlib/intern/noise.c index 49a09dd7b15..5d80edebbef 100644 --- a/source/blender/blenlib/intern/noise.c +++ b/source/blender/blenlib/intern/noise.c @@ -1098,7 +1098,7 @@ static float dist_Minkovsky4(float x, float y, float z, float e) /* Minkovsky, general case, slow, maybe too slow to be useful */ static float dist_Minkovsky(float x, float y, float z, float e) { - return pow(pow(fabs(x), e) + pow(fabs(y), e) + pow(fabs(z), e), 1.0/e); + return pow(pow(fabs(x), e) + pow(fabs(y), e) + pow(fabs(z), e), 1.0/e); } @@ -1275,18 +1275,18 @@ static float voronoi_CrS(float x, float y, float z) /* returns unsigned cellnoise */ static float cellNoiseU(float x, float y, float z) { - int xi = (int)(floor(x)); - int yi = (int)(floor(y)); - int zi = (int)(floor(z)); - unsigned int n = xi + yi*1301 + zi*314159; - n ^= (n<<13); - return ((float)(n*(n*n*15731 + 789221) + 1376312589) / 4294967296.0); + int xi = (int)(floor(x)); + int yi = (int)(floor(y)); + int zi = (int)(floor(z)); + unsigned int n = xi + yi*1301 + zi*314159; + n ^= (n<<13); + return ((float)(n*(n*n*15731 + 789221) + 1376312589) / 4294967296.0); } /* idem, signed */ float cellNoise(float x, float y, float z) { - return (2.0*cellNoiseU(x, y, z)-1.0); + return (2.0*cellNoiseU(x, y, z)-1.0); } /* returns a vector/point/color in ca, using point hasharray directly */ diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c index f7115b4d46f..1f4b0ffdd5c 100644 --- a/source/blender/blenlib/intern/path_util.c +++ b/source/blender/blenlib/intern/path_util.c @@ -324,8 +324,8 @@ void BLI_cleanup_path(const char *relabase, char *dir) /* Note, this should really be moved to the file selector, * since this function is used in many areas */ if(strcmp(dir, ".")==0) { /* happens for example in FILE_MAIN */ - get_default_root(dir); - return; + get_default_root(dir); + return; } while ( (start = strstr(dir, "\\..\\")) ) { @@ -353,9 +353,9 @@ void BLI_cleanup_path(const char *relabase, char *dir) } #else if(dir[0]=='.') { /* happens, for example in FILE_MAIN */ - dir[0]= '/'; - dir[1]= 0; - return; + dir[0]= '/'; + dir[1]= 0; + return; } /* support for odd paths: eg /../home/me --> /home/me @@ -525,7 +525,7 @@ int BLI_parent_dir(char *path) BLI_add_slash(tmp); strcat(tmp, parent_dir); BLI_cleanup_dir(NULL, tmp); - + if (!BLI_testextensie(tmp, parent_dir)) { BLI_strncpy(path, tmp, sizeof(tmp)); return 1; @@ -763,7 +763,7 @@ void BLI_splitdirstring(char *di, char *fi) } } -void BLI_getlastdir(const char* dir, char *last, int maxlen) +void BLI_getlastdir(const char* dir, char *last, const size_t maxlen) { const char *s = dir; const char *lslash = NULL; @@ -1144,6 +1144,8 @@ char *BLI_get_folder_version(const int id, const int ver, const int do_check) ok= get_path_system(path, NULL, NULL, NULL, ver); break; default: + path[0]= '\0'; /* incase do_check is false */ + ok= FALSE; BLI_assert(!"incorrect ID"); } @@ -1439,7 +1441,7 @@ void BLI_split_dirfile(const char *string, char *dir, char *file) } /* simple appending of filename to dir, does not check for valid path! */ -void BLI_join_dirfile(char *string, const int maxlen, const char *dir, const char *file) +void BLI_join_dirfile(char *string, const size_t maxlen, const char *dir, const char *file) { int sl_dir; @@ -1489,7 +1491,7 @@ char *BLI_path_basename(char *path) that a user gets his images in one place. It'll also provide consistent behaviour across exporters. */ -int BKE_rebase_path(char *abs, int abs_size, char *rel, int rel_size, const char *base_dir, const char *src_dir, const char *dest_dir) +int BKE_rebase_path(char *abs, size_t abs_len, char *rel, size_t rel_len, const char *base_dir, const char *src_dir, const char *dest_dir) { char path[FILE_MAX]; char dir[FILE_MAX]; @@ -1545,11 +1547,11 @@ int BKE_rebase_path(char *abs, int abs_size, char *rel, int rel_size, const char } if (abs) - BLI_strncpy(abs, dest_path, abs_size); + BLI_strncpy(abs, dest_path, abs_len); if (rel) { - strncat(rel, rel_dir, rel_size); - strncat(rel, base, rel_size); + strncat(rel, rel_dir, rel_len); + strncat(rel, base, rel_len); } /* return 2 if src=dest */ @@ -1665,7 +1667,7 @@ static int add_win32_extension(char *name) } /* filename must be FILE_MAX length minimum */ -void BLI_where_am_i(char *fullname, const int maxlen, const char *name) +void BLI_where_am_i(char *fullname, const size_t maxlen, const char *name) { char filename[FILE_MAXDIR+FILE_MAXFILE]; const char *path = NULL, *temp; @@ -1690,6 +1692,10 @@ void BLI_where_am_i(char *fullname, const int maxlen, const char *name) #ifdef _WIN32 if(GetModuleFileName(0, fullname, maxlen)) { GetShortPathName(fullname, fullname, maxlen); + if(!BLI_exists(fullname)) { + printf("path can't be found: \"%.*s\"\n", maxlen, fullname); + MessageBox(NULL, "path constains invalid characters or is too long (see console)", "Error", MB_OK); + } return; } #endif @@ -1754,7 +1760,7 @@ void BLI_where_am_i(char *fullname, const int maxlen, const char *name) } } -void BLI_where_is_temp(char *fullname, const int maxlen, int usertemp) +void BLI_where_is_temp(char *fullname, const size_t maxlen, int usertemp) { fullname[0] = '\0'; @@ -1800,26 +1806,6 @@ void BLI_where_is_temp(char *fullname, const int maxlen, int usertemp) } } -char *get_install_dir(void) { - char *tmpname = BLI_strdup(bprogname); - char *cut; - -#ifdef __APPLE__ - cut = strstr(tmpname, ".app"); - if (cut) cut[0] = 0; -#endif - - cut = BLI_last_slash(tmpname); - - if (cut) { - cut[0] = 0; - return tmpname; - } else { - MEM_freeN(tmpname); - return NULL; - } -} - #ifdef WITH_ICONV void BLI_string_to_utf8(char *original, char *utf_8, const char *code) diff --git a/source/blender/blenlib/intern/pbvh.c b/source/blender/blenlib/intern/pbvh.c index 025c5560764..5372adbf399 100644 --- a/source/blender/blenlib/intern/pbvh.c +++ b/source/blender/blenlib/intern/pbvh.c @@ -672,7 +672,7 @@ static PBVHNode *pbvh_iter_next(PBVHIter *iter) parents, this order is necessary for e.g. computing bounding boxes */ while(iter->stacksize) { - /* pop node */ + /* pop node */ iter->stacksize--; node= iter->stack[iter->stacksize].node; @@ -709,30 +709,30 @@ static PBVHNode *pbvh_iter_next(PBVHIter *iter) static PBVHNode *pbvh_iter_next_occluded(PBVHIter *iter) { - PBVHNode *node; - - while(iter->stacksize) { - /* pop node */ - iter->stacksize--; - node= iter->stack[iter->stacksize].node; - - /* on a mesh with no faces this can happen - * can remove this check if we know meshes have at least 1 face */ - if(node==NULL) return NULL; - - if(iter->scb && !iter->scb(node, iter->search_data)) continue; /* don't traverse, outside of search zone */ - - if(node->flag & PBVH_Leaf) { - /* immediately hit leaf node */ - return node; - } - else { - pbvh_stack_push(iter, iter->bvh->nodes+node->children_offset+1, 0); - pbvh_stack_push(iter, iter->bvh->nodes+node->children_offset, 0); - } - } - - return NULL; + PBVHNode *node; + + while(iter->stacksize) { + /* pop node */ + iter->stacksize--; + node= iter->stack[iter->stacksize].node; + + /* on a mesh with no faces this can happen + * can remove this check if we know meshes have at least 1 face */ + if(node==NULL) return NULL; + + if(iter->scb && !iter->scb(node, iter->search_data)) continue; /* don't traverse, outside of search zone */ + + if(node->flag & PBVH_Leaf) { + /* immediately hit leaf node */ + return node; + } + else { + pbvh_stack_push(iter, iter->bvh->nodes+node->children_offset+1, 0); + pbvh_stack_push(iter, iter->bvh->nodes+node->children_offset, 0); + } + } + + return NULL; } void BLI_pbvh_search_gather(PBVH *bvh, @@ -793,59 +793,59 @@ void BLI_pbvh_search_callback(PBVH *bvh, } typedef struct node_tree { - PBVHNode* data; + PBVHNode* data; - struct node_tree* left; - struct node_tree* right; + struct node_tree* left; + struct node_tree* right; } node_tree; static void node_tree_insert(node_tree* tree, node_tree* new_node) { - if (new_node->data->tmin < tree->data->tmin) { - if (tree->left) { - node_tree_insert(tree->left, new_node); - } - else { - tree->left = new_node; - } - } - else { - if (tree->right) { - node_tree_insert(tree->right, new_node); - } - else { - tree->right = new_node; - } - } + if (new_node->data->tmin < tree->data->tmin) { + if (tree->left) { + node_tree_insert(tree->left, new_node); + } + else { + tree->left = new_node; + } + } + else { + if (tree->right) { + node_tree_insert(tree->right, new_node); + } + else { + tree->right = new_node; + } + } } static void traverse_tree(node_tree* tree, BLI_pbvh_HitOccludedCallback hcb, void* hit_data, float* tmin) { - if (tree->left) traverse_tree(tree->left, hcb, hit_data, tmin); + if (tree->left) traverse_tree(tree->left, hcb, hit_data, tmin); - hcb(tree->data, hit_data, tmin); + hcb(tree->data, hit_data, tmin); - if (tree->right) traverse_tree(tree->right, hcb, hit_data, tmin); + if (tree->right) traverse_tree(tree->right, hcb, hit_data, tmin); } static void free_tree(node_tree* tree) { - if (tree->left) { - free_tree(tree->left); - tree->left = 0; - } + if (tree->left) { + free_tree(tree->left); + tree->left = 0; + } - if (tree->right) { - free_tree(tree->right); - tree->right = 0; - } + if (tree->right) { + free_tree(tree->right); + tree->right = 0; + } - free(tree); + free(tree); } float BLI_pbvh_node_get_tmin(PBVHNode* node) { - return node->tmin; + return node->tmin; } static void BLI_pbvh_search_callback_occluded(PBVH *bvh, @@ -1129,7 +1129,7 @@ void BLI_pbvh_get_grid_updates(PBVH *bvh, int clear, void ***gridfaces, int *tot GHash *map; void *face, **faces; unsigned i; - int tot; + int tot; map = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "pbvh_get_grid_updates gh"); @@ -1318,17 +1318,17 @@ static int ray_face_intersection(float ray_start[3], float ray_normal[3], float *t0, float *t1, float *t2, float *t3, float *fdist) { - float dist; - - if ((isect_ray_tri_epsilon_v3(ray_start, ray_normal, t0, t1, t2, &dist, NULL, 0.1f) && dist < *fdist) || - (t3 && isect_ray_tri_epsilon_v3(ray_start, ray_normal, t0, t2, t3, &dist, NULL, 0.1f) && dist < *fdist)) - { - *fdist = dist; - return 1; - } - else { - return 0; - } + float dist; + + if ((isect_ray_tri_epsilon_v3(ray_start, ray_normal, t0, t1, t2, &dist, NULL, 0.1f) && dist < *fdist) || + (t3 && isect_ray_tri_epsilon_v3(ray_start, ray_normal, t0, t2, t3, &dist, NULL, 0.1f) && dist < *fdist)) + { + *fdist = dist; + return 1; + } + else { + return 0; + } } int BLI_pbvh_node_raycast(PBVH *bvh, PBVHNode *node, float (*origco)[3], diff --git a/source/blender/blenlib/intern/string.c b/source/blender/blenlib/intern/string.c index d626ca4bf09..ee5bd17c901 100644 --- a/source/blender/blenlib/intern/string.c +++ b/source/blender/blenlib/intern/string.c @@ -381,64 +381,64 @@ static const char trailingBytesForUTF8[256] = { int BLI_utf8_invalid_byte(const char *str, int length) { - const unsigned char *p, *pend = (unsigned char*)str + length; - unsigned char c; - int ab; - - for (p = (unsigned char*)str; p < pend; p++) { - c = *p; - if (c < 128) - continue; - if ((c & 0xc0) != 0xc0) - goto utf8_error; - ab = trailingBytesForUTF8[c]; - if (length < ab) - goto utf8_error; - length -= ab; - - p++; - /* Check top bits in the second byte */ - if ((*p & 0xc0) != 0x80) - goto utf8_error; - - /* Check for overlong sequences for each different length */ - switch (ab) { - /* Check for xx00 000x */ - case 1: - if ((c & 0x3e) == 0) goto utf8_error; - continue; /* We know there aren't any more bytes to check */ - - /* Check for 1110 0000, xx0x xxxx */ - case 2: - if (c == 0xe0 && (*p & 0x20) == 0) goto utf8_error; - break; - - /* Check for 1111 0000, xx00 xxxx */ - case 3: - if (c == 0xf0 && (*p & 0x30) == 0) goto utf8_error; - break; - - /* Check for 1111 1000, xx00 0xxx */ - case 4: - if (c == 0xf8 && (*p & 0x38) == 0) goto utf8_error; - break; - - /* Check for leading 0xfe or 0xff, - and then for 1111 1100, xx00 00xx */ - case 5: - if (c == 0xfe || c == 0xff || - (c == 0xfc && (*p & 0x3c) == 0)) goto utf8_error; - break; - } - - /* Check for valid bytes after the 2nd, if any; all must start 10 */ - while (--ab > 0) { - if ((*(p+1) & 0xc0) != 0x80) goto utf8_error; + const unsigned char *p, *pend = (unsigned char*)str + length; + unsigned char c; + int ab; + + for (p = (unsigned char*)str; p < pend; p++) { + c = *p; + if (c < 128) + continue; + if ((c & 0xc0) != 0xc0) + goto utf8_error; + ab = trailingBytesForUTF8[c]; + if (length < ab) + goto utf8_error; + length -= ab; + + p++; + /* Check top bits in the second byte */ + if ((*p & 0xc0) != 0x80) + goto utf8_error; + + /* Check for overlong sequences for each different length */ + switch (ab) { + /* Check for xx00 000x */ + case 1: + if ((c & 0x3e) == 0) goto utf8_error; + continue; /* We know there aren't any more bytes to check */ + + /* Check for 1110 0000, xx0x xxxx */ + case 2: + if (c == 0xe0 && (*p & 0x20) == 0) goto utf8_error; + break; + + /* Check for 1111 0000, xx00 xxxx */ + case 3: + if (c == 0xf0 && (*p & 0x30) == 0) goto utf8_error; + break; + + /* Check for 1111 1000, xx00 0xxx */ + case 4: + if (c == 0xf8 && (*p & 0x38) == 0) goto utf8_error; + break; + + /* Check for leading 0xfe or 0xff, + and then for 1111 1100, xx00 00xx */ + case 5: + if (c == 0xfe || c == 0xff || + (c == 0xfc && (*p & 0x3c) == 0)) goto utf8_error; + break; + } + + /* Check for valid bytes after the 2nd, if any; all must start 10 */ + while (--ab > 0) { + if ((*(p+1) & 0xc0) != 0x80) goto utf8_error; p++; /* do this after so we get usable offset - campbell */ - } - } + } + } - return -1; + return -1; utf8_error: diff --git a/source/blender/blenlib/intern/winstuff.c b/source/blender/blenlib/intern/winstuff.c index 90754e7d2bb..66080ed2a85 100644 --- a/source/blender/blenlib/intern/winstuff.c +++ b/source/blender/blenlib/intern/winstuff.c @@ -66,14 +66,6 @@ int BLI_getInstallationDir( char * str ) { return 1; } -int IsConsoleEmpty(void) -{ - CONSOLE_SCREEN_BUFFER_INFO csbi = {{0}}; - HANDLE hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE); - - return GetConsoleScreenBufferInfo(hStdOutput, &csbi) && csbi.dwCursorPosition.X == 0 && csbi.dwCursorPosition.Y == 0; -} - void RegisterBlendExtension_Fail(HKEY root) { printf("failed\n"); @@ -307,21 +299,21 @@ int check_file_chars(char *filename) #include <string.h> char* dirname(char *path) { - char *p; - if( path == NULL || *path == '\0' ) - return "."; - p = path + strlen(path) - 1; - while( *p == '/' ) { - if( p == path ) - return path; - *p-- = '\0'; - } - while( p >= path && *p != '/' ) - p--; - return - p < path ? "." : - p == path ? "/" : - (*p = '\0', path); + char *p; + if( path == NULL || *path == '\0' ) + return "."; + p = path + strlen(path) - 1; + while( *p == '/' ) { + if( p == path ) + return path; + *p-- = '\0'; + } + while( p >= path && *p != '/' ) + p--; + return + p < path ? "." : + p == path ? "/" : + (*p = '\0', path); } /* End of copied part */ |