diff options
author | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2011-05-09 05:38:29 +0400 |
---|---|---|
committer | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2011-05-09 05:38:29 +0400 |
commit | 31471f644cb9d9c3b88da1977705724649482a82 (patch) | |
tree | 46b5c62b475108e1b1a501a21e53846531ead116 /source/blender/blenlib | |
parent | b1db37dd056d1b2a16e82f1374163de566c2fe10 (diff) | |
parent | f8f4f73cc5e6dfdc2a4f8864a3e1edc2639e6fb2 (diff) |
Merged changes in the trunk up to revision 36551.
Conflicts resolved:
source/creator/SConscript
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_dynlib.h (renamed from source/blender/blenlib/PIL_dynlib.h) | 30 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_listbase.h | 9 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_math_geom.h | 5 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_path_util.h | 11 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_winstuff.h | 1 | ||||
-rw-r--r-- | source/blender/blenlib/CMakeLists.txt | 2 | ||||
-rw-r--r-- | source/blender/blenlib/intern/dynlib.c | 103 | ||||
-rw-r--r-- | source/blender/blenlib/intern/listbase.c | 49 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_geom.c | 33 | ||||
-rw-r--r-- | source/blender/blenlib/intern/path_util.c | 40 | ||||
-rw-r--r-- | source/blender/blenlib/intern/winstuff.c | 8 |
11 files changed, 159 insertions, 132 deletions
diff --git a/source/blender/blenlib/PIL_dynlib.h b/source/blender/blenlib/BLI_dynlib.h index 5569954c116..f269bedd639 100644 --- a/source/blender/blenlib/PIL_dynlib.h +++ b/source/blender/blenlib/BLI_dynlib.h @@ -27,31 +27,19 @@ * ***** END GPL LICENSE BLOCK ***** */ -/** \file blender/blenlib/PIL_dynlib.h +/** \file blender/blenlib/BLI_dynlib.h * \ingroup bli */ -#ifndef __PIL_DYNLIB_H__ -#define __PIL_DYNLIB_H__ +#ifndef __BLI_DYNLIB_H__ +#define __BLI_DYNLIB_H__ -typedef struct PILdynlib PILdynlib; +typedef struct DynamicLibrary DynamicLibrary; - PILdynlib* -PIL_dynlib_open( - char *name); +DynamicLibrary *BLI_dynlib_open(char *name); +void *BLI_dynlib_find_symbol(DynamicLibrary* lib, const char *symname); +char *BLI_dynlib_get_error_as_string(DynamicLibrary* lib); +void BLI_dynlib_close(DynamicLibrary* lib); - void* -PIL_dynlib_find_symbol( - PILdynlib* lib, - const char *symname); - - char* -PIL_dynlib_get_error_as_string( - PILdynlib* lib); - - void -PIL_dynlib_close( - PILdynlib* lib); - -#endif /* __PIL_DYNLIB_H__ */ +#endif /* __BLI_DYNLIB_H__ */ diff --git a/source/blender/blenlib/BLI_listbase.h b/source/blender/blenlib/BLI_listbase.h index 73af9a3738c..90556ea4b05 100644 --- a/source/blender/blenlib/BLI_listbase.h +++ b/source/blender/blenlib/BLI_listbase.h @@ -45,9 +45,16 @@ extern "C" { void BLI_insertlink(struct ListBase *listbase, void *vprevlink, void *vnewlink); void *BLI_findlink(const struct ListBase *listbase, int number); int BLI_findindex(const struct ListBase *listbase, void *vlink); +int BLI_findstringindex(const struct ListBase *listbase, const char *id, const int offset); + +/* find forwards */ void *BLI_findstring(const struct ListBase *listbase, const char *id, const int offset); void *BLI_findstring_ptr(const struct ListBase *listbase, const char *id, const int offset); -int BLI_findstringindex(const struct ListBase *listbase, const char *id, const int offset); + +/* find backwards */ +void *BLI_rfindstring(const struct ListBase *listbase, const char *id, const int offset); +void *BLI_rfindstring_ptr(const struct ListBase *listbase, const char *id, const int offset); + void BLI_freelistN(struct ListBase *listbase); void BLI_addtail(struct ListBase *listbase, void *vlink); void BLI_remlink(struct ListBase *listbase, void *vlink); diff --git a/source/blender/blenlib/BLI_math_geom.h b/source/blender/blenlib/BLI_math_geom.h index 8937612b41b..756d1501536 100644 --- a/source/blender/blenlib/BLI_math_geom.h +++ b/source/blender/blenlib/BLI_math_geom.h @@ -91,6 +91,11 @@ int isect_line_line_v3(const float v1[3], const float v2[3], int isect_line_line_strict_v3(const float v1[3], const float v2[3], const float v3[3], const float v4[3], float vi[3], float *lambda); +/*if clip is nonzero, will only return true if lambda is >= 0.0 + (i.e. intersection point is along positive d)*/ +int isect_ray_plane_v3(float p1[3], float d[3], float v0[3], + float v1[3], float v2[3], float *lambda, int clip); + /* line/ray triangle */ int isect_line_tri_v3(const float p1[3], const float p2[3], const float v0[3], const float v1[3], const float v2[3], float *lambda, float uv[2]); diff --git a/source/blender/blenlib/BLI_path_util.h b/source/blender/blenlib/BLI_path_util.h index 3e86079dcad..dd4ae781832 100644 --- a/source/blender/blenlib/BLI_path_util.h +++ b/source/blender/blenlib/BLI_path_util.h @@ -109,15 +109,15 @@ void BLI_make_file_string(const char *relabase, char *string, const char *dir, void BLI_make_exist(char *dir); void BLI_make_existing_file(const char *name); void BLI_split_dirfile(const char *string, char *dir, char *file); -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); char *BLI_path_basename(char *path); -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 *BLI_last_slash(const char *string); int BLI_add_slash(char *string); void BLI_del_slash(char *string); char *BLI_first_slash(char *string); -void BLI_getlastdir(const char* dir, char *last, int maxlen); +void BLI_getlastdir(const char* dir, char *last, const size_t maxlen); int BLI_testextensie(const char *str, const char *ext); int BLI_testextensie_array(const char *str, const char **ext_array); int BLI_testextensie_glob(const char *str, const char *ext_fnmatch); @@ -195,9 +195,8 @@ void BLI_char_switch(char *string, char from, char to); * @param fullname The full path and full name of the executable * @param name The name of the executable (usually argv[0]) to be checked */ -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 *get_install_dir(void); /** * Gets the temp directory when blender first runs. * If the default path is not found, use try $TEMP @@ -206,7 +205,7 @@ char *get_install_dir(void); * * @param fullname The full path to the temp directory */ -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); #ifdef WITH_ICONV diff --git a/source/blender/blenlib/BLI_winstuff.h b/source/blender/blenlib/BLI_winstuff.h index 176e7319bf7..d0eb3c7d67d 100644 --- a/source/blender/blenlib/BLI_winstuff.h +++ b/source/blender/blenlib/BLI_winstuff.h @@ -127,7 +127,6 @@ typedef struct _DIR { struct dirent direntry; } DIR; -int IsConsoleEmpty(void); void RegisterBlendExtension(void); DIR *opendir (const char *path); struct dirent *readdir(DIR *dp); diff --git a/source/blender/blenlib/CMakeLists.txt b/source/blender/blenlib/CMakeLists.txt index d78fbdf393e..7ade7a06ab5 100644 --- a/source/blender/blenlib/CMakeLists.txt +++ b/source/blender/blenlib/CMakeLists.txt @@ -89,6 +89,7 @@ set(SRC BLI_bpath.h BLI_cpu.h BLI_dlrbTree.h + BLI_dynlib.h BLI_dynstr.h BLI_edgehash.h BLI_editVert.h @@ -128,7 +129,6 @@ set(SRC BLI_vfontdata.h BLI_voxel.h BLI_winstuff.h - PIL_dynlib.h PIL_time.h intern/BLI_callbacks.h intern/dynamiclist.h 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/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_geom.c b/source/blender/blenlib/intern/math_geom.c index 4af56c66dde..be7f2d95d04 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,36 @@ 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; + /* float u, v; */ /*UNUSED*/ + + 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); */ /*UNUSED*/ + + cross_v3_v3v3(q, s, e1); + + /* v = f * dot_v3v3(d, q); */ /*UNUSED*/ + + *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 +1790,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/path_util.c b/source/blender/blenlib/intern/path_util.c index 1a47a93ab51..1f4b0ffdd5c 100644 --- a/source/blender/blenlib/intern/path_util.c +++ b/source/blender/blenlib/intern/path_util.c @@ -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; @@ -1441,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; @@ -1491,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]; @@ -1547,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 */ @@ -1667,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; @@ -1692,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 @@ -1756,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'; @@ -1802,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/winstuff.c b/source/blender/blenlib/intern/winstuff.c index 596ab2b0470..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"); |