diff options
author | Martin Poirier <theeth@yahoo.com> | 2008-10-03 00:39:57 +0400 |
---|---|---|
committer | Martin Poirier <theeth@yahoo.com> | 2008-10-03 00:39:57 +0400 |
commit | c35a2d6ea9dc5226911bd90848e96a59233bdaf8 (patch) | |
tree | be895ae3982a72a5b1cfd4ff9b1766037c07a6d0 /source/blender/blenlib | |
parent | 39e66e4d6f48b7a54a510ec5504fd500cc07174f (diff) | |
parent | 06c43148a19ad7e8cddf9ba51549b51bdb1f6f0c (diff) |
merge trunk 16118 -> 116886
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_arithb.h | 9 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_blenlib.h | 7 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_editVert.h | 8 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_kdopbvh.h | 3 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_rand.h | 1 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_winstuff.h | 8 | ||||
-rw-r--r-- | source/blender/blenlib/SConscript | 2 | ||||
-rw-r--r-- | source/blender/blenlib/intern/BLI_ghash.c | 8 | ||||
-rw-r--r-- | source/blender/blenlib/intern/BLI_kdopbvh.c | 260 | ||||
-rw-r--r-- | source/blender/blenlib/intern/arithb.c | 136 | ||||
-rw-r--r-- | source/blender/blenlib/intern/bpath.c | 6 | ||||
-rw-r--r-- | source/blender/blenlib/intern/dynlib.c | 6 | ||||
-rw-r--r-- | source/blender/blenlib/intern/edgehash.c | 14 | ||||
-rw-r--r-- | source/blender/blenlib/intern/fileops.c | 6 | ||||
-rw-r--r-- | source/blender/blenlib/intern/freetypefont.c | 2 | ||||
-rw-r--r-- | source/blender/blenlib/intern/psfont.c | 16 | ||||
-rw-r--r-- | source/blender/blenlib/intern/rand.c | 18 | ||||
-rw-r--r-- | source/blender/blenlib/intern/util.c | 93 |
18 files changed, 500 insertions, 103 deletions
diff --git a/source/blender/blenlib/BLI_arithb.h b/source/blender/blenlib/BLI_arithb.h index a0fde98843d..e4b983d9ba3 100644 --- a/source/blender/blenlib/BLI_arithb.h +++ b/source/blender/blenlib/BLI_arithb.h @@ -91,6 +91,7 @@ float saasin(float fac); float sasqrt(float fac); int FloatCompare(float *v1, float *v2, float limit); +int FloatCompare4(float *v1, float *v2, float limit); float FloatLerpf(float target, float origin, float fac); float CalcNormFloat(float *v1, float *v2, float *v3, float *n); @@ -164,6 +165,7 @@ void Mat3Inv(float m1[][3], float m2[][3]); void Mat3CpyMat4(float m1[][3],float m2[][4]); void Mat4CpyMat3(float m1[][4], float m2[][3]); +void Mat3BlendMat3(float out[][3], float dst[][3], float src[][3], float srcweight); void Mat4BlendMat4(float out[][4], float dst[][4], float src[][4], float srcweight); float Det2x2(float a,float b,float c, float d); @@ -261,6 +263,7 @@ void Vec2Mulf(float *v1, float f); void Vec2Addf(float *v, float *v1, float *v2); void Vec2Subf(float *v, float *v1, float *v2); void Vec2Copyf(float *v1, float *v2); +void Vec2Lerpf(float *target, float *a, float *b, float t); void AxisAngleToQuat(float *q, float *axis, float angle); void RotationBetweenVectorsToQuat(float *q, float v1[3], float v2[3]); @@ -321,6 +324,10 @@ void i_window( float mat[][4] ); +#define BLI_CS_SMPTE 0 +#define BLI_CS_REC709 1 +#define BLI_CS_CIE 2 + void hsv_to_rgb(float h, float s, float v, float *r, float *g, float *b); void hex_to_rgb(char *hexcol, float *r, float *g, float *b); void rgb_to_yuv(float r, float g, float b, float *ly, float *lu, float *lv); @@ -328,7 +335,7 @@ void yuv_to_rgb(float y, float u, float v, float *lr, float *lg, float *lb); void ycc_to_rgb(float y, float cb, float cr, float *lr, float *lg, float *lb); void rgb_to_ycc(float r, float g, float b, float *ly, float *lcb, float *lcr); void rgb_to_hsv(float r, float g, float b, float *lh, float *ls, float *lv); -void xyz_to_rgb(float x, float y, float z, float *r, float *g, float *b); +void xyz_to_rgb(float x, float y, float z, float *r, float *g, float *b, int colorspace); int constrain_rgb(float *r, float *g, float *b); void gamma_correct_rgb(float *r, float *g, float *b); unsigned int hsv_to_cpack(float h, float s, float v); diff --git a/source/blender/blenlib/BLI_blenlib.h b/source/blender/blenlib/BLI_blenlib.h index e24ccad12fb..4bbda9709d7 100644 --- a/source/blender/blenlib/BLI_blenlib.h +++ b/source/blender/blenlib/BLI_blenlib.h @@ -73,7 +73,6 @@ extern ListBase fillvertbase; * @attention Defined in scanfill.c */ extern ListBase filledgebase; -extern int totblock; extern char btempdir[]; /* creator.c temp dir used instead of U.tempdir, set with BLI_where_is_temp( btempdir, 1 ); */ @@ -138,6 +137,9 @@ void BLI_dlist_reinit(struct DynamicList *dlist); void BLI_cleanup_file(const char *relabase, char *dir); void BLI_cleanup_dir(const char *relabase, char *dir); /* same as above but adds a trailing slash */ +/* go back one directory */ +int BLI_parent_dir(char *path); + /** * Blender's path code replacement function. * Bases @a path strings leading with "//" by the @@ -152,6 +154,7 @@ void BLI_cleanup_dir(const char *relabase, char *dir); /* same as above but adds */ int BLI_convertstringcode(char *path, const char *basepath); int BLI_convertstringframe(char *path, int frame); +int BLI_convertstringcwd(char *path); void BLI_makestringcode(const char *relfile, char *file); @@ -224,7 +227,7 @@ int BLI_strcaseeq(char *a, char *b); /* in util.c */ #ifdef WITH_ICONV -void BLI_string_to_utf8(char *original, char *utf_8, char *code); +void BLI_string_to_utf8(char *original, char *utf_8, const char *code); #endif /** diff --git a/source/blender/blenlib/BLI_editVert.h b/source/blender/blenlib/BLI_editVert.h index d42663e17c7..447f6a2a485 100644 --- a/source/blender/blenlib/BLI_editVert.h +++ b/source/blender/blenlib/BLI_editVert.h @@ -38,6 +38,8 @@ #include "DNA_customdata_types.h" #include "DNA_mesh_types.h" +#include "BLO_sys_types.h" // for intptr_t support + struct DerivedMesh; struct RetopoPaintData; @@ -53,7 +55,7 @@ typedef struct EditVert struct EditEdge *e; struct EditFace *f; void *p; - long l; + intptr_t l; float fp; } tmp; float no[3]; /*vertex normal */ @@ -95,7 +97,7 @@ typedef struct EditEdge struct EditEdge *e; struct EditFace *f; void *p; - long l; + intptr_t l; float fp; } tmp; short f1, f2; /* short, f1 is (ab)used in subdiv */ @@ -122,7 +124,7 @@ typedef struct EditFace struct EditEdge *e; struct EditFace *f; void *p; - long l; + intptr_t l; float fp; } tmp; float n[3], cent[3]; diff --git a/source/blender/blenlib/BLI_kdopbvh.h b/source/blender/blenlib/BLI_kdopbvh.h index 6d9a17efebf..e3591a84e98 100644 --- a/source/blender/blenlib/BLI_kdopbvh.h +++ b/source/blender/blenlib/BLI_kdopbvh.h @@ -54,6 +54,7 @@ typedef struct BVHTreeRay { float origin[3]; /* ray origin */ float direction[3]; /* ray direction */ + float radius; /* radius around ray */ } BVHTreeRay; typedef struct BVHTreeRayHit @@ -90,7 +91,7 @@ float BLI_bvhtree_getepsilon(BVHTree *tree); /* find nearest node to the given coordinates (if nearest is given it will only search nodes where square distance is smaller than nearest->dist) */ int BLI_bvhtree_find_nearest(BVHTree *tree, const float *co, BVHTreeNearest *nearest, BVHTree_NearestPointCallback callback, void *userdata); -int BLI_bvhtree_ray_cast(BVHTree *tree, const float *co, const float *dir, BVHTreeRayHit *hit, BVHTree_RayCastCallback callback, void *userdata); +int BLI_bvhtree_ray_cast(BVHTree *tree, const float *co, const float *dir, float radius, BVHTreeRayHit *hit, BVHTree_RayCastCallback callback, void *userdata); #endif // BLI_KDOPBVH_H diff --git a/source/blender/blenlib/BLI_rand.h b/source/blender/blenlib/BLI_rand.h index 0e534783c17..266aa347aff 100644 --- a/source/blender/blenlib/BLI_rand.h +++ b/source/blender/blenlib/BLI_rand.h @@ -44,6 +44,7 @@ struct RNG* rng_new (unsigned int seed); void rng_free (struct RNG* rng); void rng_seed (struct RNG* rng, unsigned int seed); +void rng_srandom(struct RNG *rng, unsigned int seed); int rng_getInt (struct RNG* rng); double rng_getDouble (struct RNG* rng); float rng_getFloat (struct RNG* rng); diff --git a/source/blender/blenlib/BLI_winstuff.h b/source/blender/blenlib/BLI_winstuff.h index 11150075bac..3bb63506c95 100644 --- a/source/blender/blenlib/BLI_winstuff.h +++ b/source/blender/blenlib/BLI_winstuff.h @@ -61,6 +61,10 @@ // These definitions are also in arithb for simplicity +#ifdef __cplusplus +extern "C" { +#endif + #ifndef M_PI #define M_PI 3.14159265358979323846 #endif @@ -116,5 +120,9 @@ int closedir (DIR *dp); void get_default_root(char *root); int check_file_chars(char *filename); +#ifdef __cplusplus +} +#endif + #endif /* __WINSTUFF_H__ */ diff --git a/source/blender/blenlib/SConscript b/source/blender/blenlib/SConscript index 649d3cb5659..65cebf02f62 100644 --- a/source/blender/blenlib/SConscript +++ b/source/blender/blenlib/SConscript @@ -24,4 +24,4 @@ if env['OURPLATFORM'] == 'linux2': if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw'): incs += ' ' + env['BF_PTHREADS_INC'] -env.BlenderLib ( 'bf_blenlib', sources, Split(incs), Split(defs), libtype=['core','player'], priority = [85,195], compileflags =cflags ) +env.BlenderLib ( 'bf_blenlib', sources, Split(incs), Split(defs), libtype=['core', 'intern', 'player'], priority = [85,150,195], compileflags =cflags ) diff --git a/source/blender/blenlib/intern/BLI_ghash.c b/source/blender/blenlib/intern/BLI_ghash.c index bae6ad428ea..1967b8a88e2 100644 --- a/source/blender/blenlib/intern/BLI_ghash.c +++ b/source/blender/blenlib/intern/BLI_ghash.c @@ -34,6 +34,8 @@ #include "MEM_guardedalloc.h" #include "BLI_ghash.h" +#include "BLO_sys_types.h" // for intptr_t support + #ifdef HAVE_CONFIG_H #include <config.h> #endif @@ -261,11 +263,7 @@ int BLI_ghashutil_ptrcmp(void *a, void *b) { } unsigned int BLI_ghashutil_inthash(void *ptr) { -#if defined(_WIN64) - unsigned __int64 key = (unsigned __int64)ptr; -#else - unsigned long key = (unsigned long)ptr; -#endif + uintptr_t key = (uintptr_t)ptr; key += ~(key << 16); key ^= (key >> 5); diff --git a/source/blender/blenlib/intern/BLI_kdopbvh.c b/source/blender/blenlib/intern/BLI_kdopbvh.c index 9671551a7f1..30472beb3e6 100644 --- a/source/blender/blenlib/intern/BLI_kdopbvh.c +++ b/source/blender/blenlib/intern/BLI_kdopbvh.c @@ -46,10 +46,12 @@ #define MAX_TREETYPE 32 +#define DEFAULT_FIND_NEAREST_HEAP_SIZE 1024 typedef struct BVHNode { struct BVHNode **children; + struct BVHNode *parent; // some user defined traversed need that float *bv; // Bounding volume of all nodes, max 13 axis int index; // face, edge, vertex index char totnode; // how many nodes are used, used for speedup @@ -81,7 +83,7 @@ typedef struct BVHOverlapData typedef struct BVHNearestData { BVHTree *tree; - float *co; + const float *co; BVHTree_NearestPointCallback callback; void *userdata; float proj[13]; //coordinates projection over axis @@ -119,6 +121,72 @@ static float KDOP_AXES[13][3] = {0, 1.0, -1.0} }; +/* + * Generic push and pop heap + */ +#define PUSH_HEAP_BODY(HEAP_TYPE,PRIORITY,heap,heap_size) \ +{ \ + HEAP_TYPE element = heap[heap_size-1]; \ + int child = heap_size-1; \ + while(child != 0) \ + { \ + int parent = (child-1) / 2; \ + if(PRIORITY(element, heap[parent])) \ + { \ + heap[child] = heap[parent]; \ + child = parent; \ + } \ + else break; \ + } \ + heap[child] = element; \ +} + +#define POP_HEAP_BODY(HEAP_TYPE, PRIORITY,heap,heap_size) \ +{ \ + HEAP_TYPE element = heap[heap_size-1]; \ + int parent = 0; \ + while(parent < (heap_size-1)/2 ) \ + { \ + int child2 = (parent+1)*2; \ + if(PRIORITY(heap[child2-1], heap[child2])) \ + --child2; \ + \ + if(PRIORITY(element, heap[child2])) \ + break; \ + \ + heap[parent] = heap[child2]; \ + parent = child2; \ + } \ + heap[parent] = element; \ +} + +int ADJUST_MEMORY(void *local_memblock, void **memblock, int new_size, int *max_size, int size_per_item) +{ + int new_max_size = *max_size * 2; + void *new_memblock = NULL; + + if(new_size <= *max_size) + return TRUE; + + if(*memblock == local_memblock) + { + new_memblock = malloc( size_per_item * new_max_size ); + memcpy( new_memblock, *memblock, size_per_item * *max_size ); + } + else + new_memblock = realloc(*memblock, size_per_item * new_max_size ); + + if(new_memblock) + { + *memblock = new_memblock; + *max_size = new_max_size; + return TRUE; + } + else + return FALSE; +} + + ////////////////////////////////////////////////////////////////////////////////////////////////////// // Introsort // with permission deriven from the following Java code: @@ -414,7 +482,7 @@ static void bvhtree_print_tree(BVHTree *tree, BVHNode *node, int depth) { int i; for(i=0; i<depth; i++) printf(" "); - printf(" - %d (%d): ", node->index, node - tree->nodearray); + printf(" - %d (%ld): ", node->index, node - tree->nodearray); for(i=2*tree->start_axis; i<2*tree->stop_axis; i++) printf("%.3f ", node->bv[i]); printf("\n"); @@ -429,10 +497,10 @@ static void bvhtree_info(BVHTree *tree) printf("BVHTree info\n"); printf("tree_type = %d, axis = %d, epsilon = %f\n", tree->tree_type, tree->axis, tree->epsilon); printf("nodes = %d, branches = %d, leafs = %d\n", tree->totbranch + tree->totleaf, tree->totbranch, tree->totleaf); - printf("Memory per node = %dbytes\n", sizeof(BVHNode) + sizeof(BVHNode*)*tree->tree_type + sizeof(float)*tree->axis); + printf("Memory per node = %ldbytes\n", sizeof(BVHNode) + sizeof(BVHNode*)*tree->tree_type + sizeof(float)*tree->axis); printf("BV memory = %dbytes\n", MEM_allocN_len(tree->nodebv)); - printf("Total memory = %dbytes\n", sizeof(BVHTree) + printf("Total memory = %ldbytes\n", sizeof(BVHTree) + MEM_allocN_len(tree->nodes) + MEM_allocN_len(tree->nodearray) + MEM_allocN_len(tree->nodechild) @@ -633,6 +701,23 @@ static void non_recursive_bvh_div_nodes(BVHTree *tree, BVHNode *branches_array, BVHBuildHelper data; int depth; + + // set parent from root node to NULL + BVHNode *tmp = branches_array+0; + tmp->parent = NULL; + + //Most of bvhtree code relies on 1-leaf trees having at least one branch + //We handle that special case here + if(num_leafs == 1) + { + BVHNode *root = branches_array+0; + refit_kdop_hull(tree, root, 0, num_leafs); + root->main_axis = get_largest_axis(root->bv) / 2; + root->totnode = 1; + root->children[0] = leafs_array[0]; + root->children[0]->parent = root; + return; + } branches_array--; //Implicit trees use 1-based indexs @@ -693,9 +778,15 @@ static void non_recursive_bvh_div_nodes(BVHTree *tree, BVHNode *branches_array, int child_leafs_end = implicit_leafs_index(&data, depth+1, child_level_index+1); if(child_leafs_end - child_leafs_begin > 1) + { parent->children[k] = branches_array + child_index; + parent->children[k]->parent = parent; + } else if(child_leafs_end - child_leafs_begin == 1) + { parent->children[k] = leafs_array[ child_leafs_begin ]; + parent->children[k]->parent = parent; + } else break; @@ -722,6 +813,11 @@ BVHTree *BLI_bvhtree_new(int maxsize, float epsilon, char tree_type, char axis) return NULL; tree = (BVHTree *)MEM_callocN(sizeof(BVHTree), "BVHTree"); + + //tree epsilon must be >= FLT_EPSILON + //so that tangent rays can still hit a bounding volume.. + //this bug would show up when casting a ray aligned with a kdop-axis and with an edge of 2 faces + epsilon = MAX2(FLT_EPSILON, epsilon); if(tree) { @@ -1012,7 +1108,7 @@ BVHTreeOverlap *BLI_bvhtree_overlap(BVHTree *tree1, BVHTree *tree2, int *result) BVHOverlapData **data; // check for compatibility of both trees (can't compare 14-DOP with 18-DOP) - if((tree1->axis != tree2->axis) && ((tree1->axis == 14) || tree2->axis == 14)) + if((tree1->axis != tree2->axis) && (tree1->axis == 14 || tree2->axis == 14) && (tree1->axis == 18 || tree2->axis == 18)) return 0; // fast check root nodes for collision before doing big splitting + traversal @@ -1114,15 +1210,18 @@ static float calc_nearest_point(BVHNearestData *data, BVHNode *node, float *near } -// TODO: use a priority queue to reduce the number of nodes looked on -static void dfs_find_nearest(BVHNearestData *data, BVHNode *node) +typedef struct NodeDistance { - int i; - float nearest[3], sdist; + BVHNode *node; + float dist; - sdist = calc_nearest_point(data, node, nearest); - if(sdist >= data->nearest.dist) return; +} NodeDistance; + +#define NodeDistance_priority(a,b) ( (a).dist < (b).dist ) +// TODO: use a priority queue to reduce the number of nodes looked on +static void dfs_find_nearest_dfs(BVHNearestData *data, BVHNode *node) +{ if(node->totnode == 0) { if(data->callback) @@ -1130,17 +1229,129 @@ static void dfs_find_nearest(BVHNearestData *data, BVHNode *node) else { data->nearest.index = node->index; - VECCOPY(data->nearest.co, nearest); - data->nearest.dist = sdist; + data->nearest.dist = calc_nearest_point(data, node, data->nearest.co); } } else { - for(i=0; i != node->totnode; i++) - dfs_find_nearest(data, node->children[i]); + //Better heuristic to pick the closest node to dive on + int i; + float nearest[3]; + + if(data->proj[ node->main_axis ] <= node->children[0]->bv[node->main_axis*2+1]) + { + + for(i=0; i != node->totnode; i++) + { + if( calc_nearest_point(data, node->children[i], nearest) >= data->nearest.dist) continue; + dfs_find_nearest_dfs(data, node->children[i]); + } + } + else + { + for(i=node->totnode-1; i >= 0 ; i--) + { + if( calc_nearest_point(data, node->children[i], nearest) >= data->nearest.dist) continue; + dfs_find_nearest_dfs(data, node->children[i]); + } + } + } +} + +static void dfs_find_nearest_begin(BVHNearestData *data, BVHNode *node) +{ + float nearest[3], sdist; + sdist = calc_nearest_point(data, node, nearest); + if(sdist >= data->nearest.dist) return; + dfs_find_nearest_dfs(data, node); +} + + +static void NodeDistance_push_heap(NodeDistance *heap, int heap_size) +PUSH_HEAP_BODY(NodeDistance, NodeDistance_priority, heap, heap_size) + +static void NodeDistance_pop_heap(NodeDistance *heap, int heap_size) +POP_HEAP_BODY(NodeDistance, NodeDistance_priority, heap, heap_size) + +//NN function that uses an heap.. this functions leads to an optimal number of min-distance +//but for normal tri-faces and BV 6-dop.. a simple dfs with local heuristics (as implemented +//in source/blender/blenkernel/intern/shrinkwrap.c) works faster. +// +//It may make sense to use this function if the callback queries are very slow.. or if its impossible +//to get a nice heuristic +// +//this function uses "malloc/free" instead of the MEM_* because it intends to be openmp safe +static void bfs_find_nearest(BVHNearestData *data, BVHNode *node) +{ + int i; + NodeDistance default_heap[DEFAULT_FIND_NEAREST_HEAP_SIZE]; + NodeDistance *heap=default_heap, current; + int heap_size = 0, max_heap_size = sizeof(default_heap)/sizeof(default_heap[0]); + float nearest[3]; + + int callbacks = 0, push_heaps = 0; + + if(node->totnode == 0) + { + dfs_find_nearest_dfs(data, node); + return; } + + current.node = node; + current.dist = calc_nearest_point(data, node, nearest); + + while(current.dist < data->nearest.dist) + { +// printf("%f : %f\n", current.dist, data->nearest.dist); + for(i=0; i< current.node->totnode; i++) + { + BVHNode *child = current.node->children[i]; + if(child->totnode == 0) + { + callbacks++; + dfs_find_nearest_dfs(data, child); + } + else + { + //adjust heap size + if(heap_size >= max_heap_size + && ADJUST_MEMORY(default_heap, (void**)&heap, heap_size+1, &max_heap_size, sizeof(heap[0])) == FALSE) + { + printf("WARNING: bvh_find_nearest got out of memory\n"); + + if(heap != default_heap) + free(heap); + + return; + } + + heap[heap_size].node = current.node->children[i]; + heap[heap_size].dist = calc_nearest_point(data, current.node->children[i], nearest); + + if(heap[heap_size].dist >= data->nearest.dist) continue; + heap_size++; + + NodeDistance_push_heap(heap, heap_size); + // PUSH_HEAP_BODY(NodeDistance, NodeDistance_priority, heap, heap_size); + push_heaps++; + } + } + + if(heap_size == 0) break; + + current = heap[0]; + NodeDistance_pop_heap(heap, heap_size); +// POP_HEAP_BODY(NodeDistance, NodeDistance_priority, heap, heap_size); + heap_size--; + } + +// printf("hsize=%d, callbacks=%d, pushs=%d\n", heap_size, callbacks, push_heaps); + + if(heap != default_heap) + free(heap); } + int BLI_bvhtree_find_nearest(BVHTree *tree, const float *co, BVHTreeNearest *nearest, BVHTree_NearestPointCallback callback, void *userdata) { int i; @@ -1172,7 +1383,7 @@ int BLI_bvhtree_find_nearest(BVHTree *tree, const float *co, BVHTreeNearest *nea //dfs search if(root) - dfs_find_nearest(&data, root); + dfs_find_nearest_begin(&data, root); //copy back results if(nearest) @@ -1203,16 +1414,16 @@ static float ray_nearest_hit(BVHRayCastData *data, BVHNode *node) if(data->ray_dot_axis[i] == 0.0f) { //axis aligned ray - if(data->ray.origin[i] < bv[0] - || data->ray.origin[i] > bv[1]) + if(data->ray.origin[i] < bv[0] - data->ray.radius + || data->ray.origin[i] > bv[1] + data->ray.radius) return FLT_MAX; } else { - float ll = (bv[0] - data->ray.origin[i]) / data->ray_dot_axis[i]; - float lu = (bv[1] - data->ray.origin[i]) / data->ray_dot_axis[i]; + float ll = (bv[0] - data->ray.radius - data->ray.origin[i]) / data->ray_dot_axis[i]; + float lu = (bv[1] + data->ray.radius - data->ray.origin[i]) / data->ray_dot_axis[i]; - if(data->ray_dot_axis[i] > 0) + if(data->ray_dot_axis[i] > 0.0f) { if(ll > low) low = ll; if(lu < upper) upper = lu; @@ -1252,7 +1463,7 @@ static void dfs_raycast(BVHRayCastData *data, BVHNode *node) else { //pick loop direction to dive into the tree (based on ray direction and split axis) - if(data->ray_dot_axis[ node->main_axis ] > 0) + if(data->ray_dot_axis[ node->main_axis ] > 0.0f) { for(i=0; i != node->totnode; i++) { @@ -1269,7 +1480,7 @@ static void dfs_raycast(BVHRayCastData *data, BVHNode *node) } } -int BLI_bvhtree_ray_cast(BVHTree *tree, const float *co, const float *dir, BVHTreeRayHit *hit, BVHTree_RayCastCallback callback, void *userdata) +int BLI_bvhtree_ray_cast(BVHTree *tree, const float *co, const float *dir, float radius, BVHTreeRayHit *hit, BVHTree_RayCastCallback callback, void *userdata) { int i; BVHRayCastData data; @@ -1282,6 +1493,7 @@ int BLI_bvhtree_ray_cast(BVHTree *tree, const float *co, const float *dir, BVHTr VECCOPY(data.ray.origin, co); VECCOPY(data.ray.direction, dir); + data.ray.radius = radius; Normalize(data.ray.direction); @@ -1289,7 +1501,7 @@ int BLI_bvhtree_ray_cast(BVHTree *tree, const float *co, const float *dir, BVHTr { data.ray_dot_axis[i] = INPR( data.ray.direction, KDOP_AXES[i]); - if(fabs(data.ray_dot_axis[i]) < 1e-7) + if(fabs(data.ray_dot_axis[i]) < FLT_EPSILON) data.ray_dot_axis[i] = 0.0; } diff --git a/source/blender/blenlib/intern/arithb.c b/source/blender/blenlib/intern/arithb.c index 3083078abac..149d3cf1f8f 100644 --- a/source/blender/blenlib/intern/arithb.c +++ b/source/blender/blenlib/intern/arithb.c @@ -759,6 +759,28 @@ void Mat4MulSerie(float answ[][4], float m1[][4], } } +void Mat3BlendMat3(float out[][3], float dst[][3], float src[][3], float srcweight) +{ + float squat[4], dquat[4], fquat[4]; + float ssize[3], dsize[3], fsize[4]; + float rmat[3][3], smat[3][3]; + + Mat3ToQuat(dst, dquat); + Mat3ToSize(dst, dsize); + + Mat3ToQuat(src, squat); + Mat3ToSize(src, ssize); + + /* do blending */ + QuatInterpol(fquat, dquat, squat, srcweight); + VecLerpf(fsize, dsize, ssize, srcweight); + + /* compose new matrix */ + QuatToMat3(fquat, rmat); + SizeToMat3(fsize, smat); + Mat3MulMat3(out, rmat, smat); +} + void Mat4BlendMat4(float out[][4], float dst[][4], float src[][4], float srcweight) { float squat[4], dquat[4], fquat[4]; @@ -1004,6 +1026,19 @@ int FloatCompare( float *v1, float *v2, float limit) return 0; } +int FloatCompare4( float *v1, float *v2, float limit) +{ + + if( fabs(v1[0]-v2[0])<limit ) { + if( fabs(v1[1]-v2[1])<limit ) { + if( fabs(v1[2]-v2[2])<limit ) { + if( fabs(v1[3]-v2[3])<limit ) return 1; + } + } + } + return 0; +} + float FloatLerpf( float target, float origin, float fac) { return (fac*target) + (1.0f-fac)*origin; @@ -2125,6 +2160,14 @@ void VecLerpf(float *target, float *a, float *b, float t) target[2]= s*a[2] + t*b[2]; } +void Vec2Lerpf(float *target, float *a, float *b, float t) +{ + float s = 1.0f-t; + + target[0]= s*a[0] + t*b[0]; + target[1]= s*a[1] + t*b[1]; +} + void VecMidf(float *v, float *v1, float *v2) { v[0]= 0.5f*(v1[0]+ v2[0]); @@ -2477,7 +2520,7 @@ short IsectLL2Df(float *v1, float *v2, float *v3, float *v4) 1: intersection */ -short IsectLLPt2Df(float x0,float y0,float x1,float y1, +static short IsectLLPt2Df(float x0,float y0,float x1,float y1, float x2,float y2,float x3,float y3, float *xi,float *yi) { @@ -2527,29 +2570,47 @@ short IsectLLPt2Df(float x0,float y0,float x1,float y1, } // end Intersect_Lines #define SIDE_OF_LINE(pa,pb,pp) ((pa[0]-pp[0])*(pb[1]-pp[1]))-((pb[0]-pp[0])*(pa[1]-pp[1])) -#define ISECT_EPSILON 1e-6 - /* point in tri */ int IsectPT2Df(float pt[2], float v1[2], float v2[2], float v3[2]) { - if ((SIDE_OF_LINE(v1,v2,pt)>=-ISECT_EPSILON) && - (SIDE_OF_LINE(v2,v3,pt)>=-ISECT_EPSILON) && - (SIDE_OF_LINE(v3,v1,pt)>=-ISECT_EPSILON)) - return 1; - else { - return 0; + if (SIDE_OF_LINE(v1,v2,pt)>=0.0) { + if (SIDE_OF_LINE(v2,v3,pt)>=0.0) { + if (SIDE_OF_LINE(v3,v1,pt)>=0.0) { + return 1; + } + } + } else { + if (! (SIDE_OF_LINE(v2,v3,pt)>=0.0) ) { + if (! (SIDE_OF_LINE(v3,v1,pt)>=0.0)) { + return -1; + } + } } + + return 0; } /* point in quad - only convex quads */ int IsectPQ2Df(float pt[2], float v1[2], float v2[2], float v3[2], float v4[2]) { - if ((SIDE_OF_LINE(v1,v2,pt)>=-ISECT_EPSILON) && - (SIDE_OF_LINE(v2,v3,pt)>=-ISECT_EPSILON) && - (SIDE_OF_LINE(v3,v4,pt)>=-ISECT_EPSILON) && - (SIDE_OF_LINE(v4,v1,pt)>=-ISECT_EPSILON)) - return 1; - else - return 0; + if (SIDE_OF_LINE(v1,v2,pt)>=0.0) { + if (SIDE_OF_LINE(v2,v3,pt)>=0.0) { + if (SIDE_OF_LINE(v3,v4,pt)>=0.0) { + if (SIDE_OF_LINE(v4,v1,pt)>=0.0) { + return 1; + } + } + } + } else { + if (! (SIDE_OF_LINE(v2,v3,pt)>=0.0) ) { + if (! (SIDE_OF_LINE(v3,v4,pt)>=0.0)) { + if (! (SIDE_OF_LINE(v4,v1,pt)>=0.0)) { + return -1; + } + } + } + } + + return 0; } @@ -3427,13 +3488,27 @@ void rgb_to_hsv(float r, float g, float b, float *lh, float *ls, float *lv) *lv = v; } -/*http://brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html - * SMPTE-C XYZ to RGB matrix*/ -void xyz_to_rgb(float xc, float yc, float zc, float *r, float *g, float *b) -{ - *r = (3.50570 * xc) + (-1.73964 * yc) + (-0.544011 * zc); - *g = (-1.06906 * xc) + (1.97781 * yc) + (0.0351720 * zc); - *b = (0.0563117 * xc) + (-0.196994 * yc) + (1.05005 * zc); +/*http://brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html */ + +void xyz_to_rgb(float xc, float yc, float zc, float *r, float *g, float *b, int colorspace) +{ + switch (colorspace) { + case BLI_CS_SMPTE: + *r = (3.50570 * xc) + (-1.73964 * yc) + (-0.544011 * zc); + *g = (-1.06906 * xc) + (1.97781 * yc) + (0.0351720 * zc); + *b = (0.0563117 * xc) + (-0.196994 * yc) + (1.05005 * zc); + break; + case BLI_CS_REC709: + *r = (3.240476 * xc) + (-1.537150 * yc) + (-0.498535 * zc); + *g = (-0.969256 * xc) + (1.875992 * yc) + (0.041556 * zc); + *b = (0.055648 * xc) + (-0.204043 * yc) + (1.057311 * zc); + break; + case BLI_CS_CIE: + *r = (2.28783848734076f * xc) + (-0.833367677835217f * yc) + (-0.454470795871421f * zc); + *g = (-0.511651380743862f * xc) + (1.42275837632178f * yc) + (0.0888930017552939f * zc); + *b = (0.00572040983140966f * xc) + (-0.0159068485104036f * yc) + (1.0101864083734f * zc); + break; + } } /*If the requested RGB shade contains a negative weight for @@ -3468,7 +3543,7 @@ int constrain_rgb(float *r, float *g, float *b) Parameter Values for the HDTV Standard for the Studio and for International Programme Exchange'', formerly CCIR Rec. 709.*/ -void gamma_correct(float *c) +static void gamma_correct(float *c) { /* Rec. 709 gamma correction. */ float cc = 0.018; @@ -3574,6 +3649,8 @@ void spheremap(float x, float y, float z, float *u, float *v) /* ------------------------------------------------------------------------- */ +/* proposed api by ton and zr, not used yet */ +#if 0 /* ***************** m1 = m2 ***************** */ void cpy_m3_m3(float m1[][3], float m2[][3]) { @@ -3597,7 +3674,6 @@ void ident_m4(float m[][4]) m[3][0]= m[3][1]= m[3][2]= 0.0; } - /* ***************** m1 = m2 (pre) * m3 (post) ***************** */ void mul_m3_m3m3(float m1[][3], float m2[][3], float m3[][3]) { @@ -3735,6 +3811,8 @@ void mul_v3_v3m4(float *v1, float *v2, float mat[][4]) } +#endif + /* moved from effect.c test if the line starting at p1 ending at p2 intersects the triangle v0..v2 return non zero if it does @@ -4182,7 +4260,7 @@ float lambda_cp_line_ex(float p[3], float l1[3], float l2[3], float cp[3]) } /* little sister we only need to know lambda */ -float lambda_cp_line(float p[3], float l1[3], float l2[3]) +static float lambda_cp_line(float p[3], float l1[3], float l2[3]) { float h[3],u[3]; VecSubf(u, l2, l1); @@ -4341,7 +4419,7 @@ void VecfCubicInterpol(float *x1, float *v1, float *x2, float *v2, float t, floa v[2]= 3*a[2]*t2 + 2*b[2]*t + v1[2]; } -int point_in_slice(float p[3], float v1[3], float l1[3], float l2[3]) +static int point_in_slice(float p[3], float v1[3], float l1[3], float l2[3]) { /* what is a slice ? @@ -4368,7 +4446,7 @@ but see a 'spat' which is a deformed cube with paired parallel planes needs only /*adult sister defining the slice planes by the origin and the normal NOTE |normal| may not be 1 but defining the thickness of the slice*/ -int point_in_slice_as(float p[3],float origin[3],float normal[3]) +static int point_in_slice_as(float p[3],float origin[3],float normal[3]) { float h,rp[3]; VecSubf(rp,p,origin); @@ -4378,7 +4456,7 @@ int point_in_slice_as(float p[3],float origin[3],float normal[3]) } /*mama (knowing the squared lenght of the normal)*/ -int point_in_slice_m(float p[3],float origin[3],float normal[3],float lns) +static int point_in_slice_m(float p[3],float origin[3],float normal[3],float lns) { float h,rp[3]; VecSubf(rp,p,origin); diff --git a/source/blender/blenlib/intern/bpath.c b/source/blender/blenlib/intern/bpath.c index 898ad6ddd67..e23c2658399 100644 --- a/source/blender/blenlib/intern/bpath.c +++ b/source/blender/blenlib/intern/bpath.c @@ -254,7 +254,7 @@ static struct Sequence *seq_stepdata__internal(struct BPathIterator *bpi, int st return NULL; } -void seq_getpath(struct BPathIterator *bpi, char *path) { +static void seq_getpath(struct BPathIterator *bpi, char *path) { Sequence *seq = (Sequence *)bpi->data; @@ -275,7 +275,7 @@ void seq_getpath(struct BPathIterator *bpi, char *path) { } } -void seq_setpath(struct BPathIterator *bpi, char *path) { +static void seq_setpath(struct BPathIterator *bpi, char *path) { Sequence *seq = (Sequence *)bpi->data; if (seq==NULL) return; @@ -456,7 +456,6 @@ void checkMissingFiles( char *txtname ) { /* be sure there is low chance of the path being too short */ char filepath_expanded[FILE_MAXDIR*2]; - int files_missing = 0; BLI_bpathIterator_init(&bpi); while (!BLI_bpathIterator_isDone(&bpi)) { @@ -470,7 +469,6 @@ void checkMissingFiles( char *txtname ) { } } bpathToText(btxt, &bpi); - files_missing = 1; } BLI_bpathIterator_step(&bpi); } diff --git a/source/blender/blenlib/intern/dynlib.c b/source/blender/blenlib/intern/dynlib.c index c4692995f20..e7fa3332f43 100644 --- a/source/blender/blenlib/intern/dynlib.c +++ b/source/blender/blenlib/intern/dynlib.c @@ -77,12 +77,12 @@ char *PIL_dynlib_get_error_as_string(PILdynlib* lib) { int err; /* if lib is NULL reset the last error code */ + err= GetLastError(); if (!lib) { SetLastError(ERROR_SUCCESS); - return NULL; + err = ERROR_SUCCESS; } - err= GetLastError(); if (err) { static char buf[1024]; @@ -96,7 +96,7 @@ char *PIL_dynlib_get_error_as_string(PILdynlib* lib) { return buf; } - return NULL; + return "unrecognized error"; } void PIL_dynlib_close(PILdynlib *lib) { diff --git a/source/blender/blenlib/intern/edgehash.c b/source/blender/blenlib/intern/edgehash.c index 3e1c8afb7a8..603c85655d7 100644 --- a/source/blender/blenlib/intern/edgehash.c +++ b/source/blender/blenlib/intern/edgehash.c @@ -77,8 +77,12 @@ void BLI_edgehash_insert(EdgeHash *eh, int v0, int v1, void *val) { unsigned int hash; Entry *e= malloc(sizeof(*e)); - if (v1<v0) v0 ^= v1 ^= v0 ^= v1; - hash = EDGEHASH(v0,v1)%eh->nbuckets; + if (v1<v0) { + v0 ^= v1; + v1 ^= v0; + v0 ^= v1; + } + hash = EDGEHASH(v0,v1)%eh->nbuckets; e->v0 = v0; e->v1 = v1; @@ -114,7 +118,11 @@ void** BLI_edgehash_lookup_p(EdgeHash *eh, int v0, int v1) { unsigned int hash; Entry *e; - if (v1<v0) v0 ^= v1 ^= v0 ^= v1; + if (v1<v0) { + v0 ^= v1; + v1 ^= v0; + v0 ^= v1; + } hash = EDGEHASH(v0,v1)%eh->nbuckets; for (e= eh->buckets[hash]; e; e= e->next) if (v0==e->v0 && v1==e->v1) diff --git a/source/blender/blenlib/intern/fileops.c b/source/blender/blenlib/intern/fileops.c index 96de5e99f4f..2acbbbe6712 100644 --- a/source/blender/blenlib/intern/fileops.c +++ b/source/blender/blenlib/intern/fileops.c @@ -62,6 +62,8 @@ #include "BKE_utildefines.h" #include <errno.h> +#include "BLO_sys_types.h" // for intptr_t support + /* implementations: */ char *first_slash(char *string) { char *ffslash, *fbslash; @@ -72,7 +74,7 @@ char *first_slash(char *string) { if (!ffslash) return fbslash; else if (!fbslash) return ffslash; - if ((long)ffslash < (long)fbslash) return ffslash; + if ((intptr_t)ffslash < (intptr_t)fbslash) return ffslash; else return fbslash; } @@ -85,7 +87,7 @@ char *BLI_last_slash(const char *string) { if (!lfslash) return lbslash; else if (!lbslash) return lfslash; - if ((long)lfslash < (long)lbslash) return lbslash; + if ((intptr_t)lfslash < (intptr_t)lbslash) return lbslash; else return lfslash; } diff --git a/source/blender/blenlib/intern/freetypefont.c b/source/blender/blenlib/intern/freetypefont.c index 74f152ac635..48a40db6a72 100644 --- a/source/blender/blenlib/intern/freetypefont.c +++ b/source/blender/blenlib/intern/freetypefont.c @@ -404,8 +404,6 @@ static VFontData *objfnt_to_ftvfontdata(PackedFile * pf) break; lcode = charcode; } - - err = FT_Select_Charmap( face, FT_ENCODING_UNICODE ); return vfd; } diff --git a/source/blender/blenlib/intern/psfont.c b/source/blender/blenlib/intern/psfont.c index 498c87cdef9..54d7f8ec1af 100644 --- a/source/blender/blenlib/intern/psfont.c +++ b/source/blender/blenlib/intern/psfont.c @@ -43,6 +43,8 @@ #include "DNA_packedFile_types.h" #include "DNA_curve_types.h" +#include "BLO_sys_types.h" // for intptr_t support + #ifdef HAVE_CONFIG_H #include <config.h> #endif @@ -54,7 +56,7 @@ typedef struct chardesc { short llx, lly; /* bounding box */ short urx, ury; short *data; /* char data */ - long datalen; + intptr_t datalen; } chardesc; typedef struct objfnt { @@ -975,7 +977,7 @@ static void applymat(float mat[][2], float *x, float *y) static void setcharlist(void) { - char *name, found; + char *name; /*found;*/ int i, j; for(i=0; i<NASCII; i++) ISOcharlist[i].prog = -1; @@ -983,11 +985,11 @@ static void setcharlist(void) for(j=0; j<my_nchars; j++) { name = my_charname[j]; if(name) { - found = 0; + /*found = 0;*/ for(i=0; i<NASCII; i++) { if(ISOcharlist[i].name && (strcmp(name,ISOcharlist[i].name) == 0)){ ISOcharlist[i].prog = j; - found = 1; + /*found = 1;*/ } } /*if (found == 0) printf("no match found for: %s\n", name);*/ @@ -1256,10 +1258,10 @@ static void subr0(void) int x1, y1; int x2, y2; int x3, y3; - int xpos, ypos, noise; + int noise; - ypos = pop(); - xpos = pop(); + pop(); /* xpos, unused */ + pop(); /* ypos, unused */ noise = pop(); if(coordpos!=7) { fprintf(stderr,"subr0: bad poop\n"); diff --git a/source/blender/blenlib/intern/rand.c b/source/blender/blenlib/intern/rand.c index ccc478203fe..c484a307393 100644 --- a/source/blender/blenlib/intern/rand.c +++ b/source/blender/blenlib/intern/rand.c @@ -81,6 +81,16 @@ void rng_seed(RNG *rng, unsigned int seed) { rng->X= (((r_uint64) seed)<<16) | LOWSEED; } +void rng_srandom(RNG *rng, unsigned int seed) { + extern unsigned char hash[]; // noise.c + + rng_seed(rng, seed + hash[seed & 255]); + seed= rng_getInt(rng); + rng_seed(rng, seed + hash[seed & 255]); + seed= rng_getInt(rng); + rng_seed(rng, seed + hash[seed & 255]); +} + int rng_getInt(RNG *rng) { rng->X= (MULTIPLIER*rng->X + ADDEND)&MASK; return (int) (rng->X>>17); @@ -132,13 +142,7 @@ void BLI_srand(unsigned int seed) { /* using hash table to create better seed */ void BLI_srandom(unsigned int seed) { - extern unsigned char hash[]; // noise.c - - rng_seed(&theBLI_rng, seed + hash[seed & 255]); - seed= rng_getInt(&theBLI_rng); - rng_seed(&theBLI_rng, seed + hash[seed & 255]); - seed= rng_getInt(&theBLI_rng); - rng_seed(&theBLI_rng, seed + hash[seed & 255]); + rng_srandom(&theBLI_rng, seed); } int BLI_rand(void) { diff --git a/source/blender/blenlib/intern/util.c b/source/blender/blenlib/intern/util.c index 48ebf770e1b..442a629b12d 100644 --- a/source/blender/blenlib/intern/util.c +++ b/source/blender/blenlib/intern/util.c @@ -1058,6 +1058,26 @@ void BLI_makestringcode(const char *relfile, char *file) } } +int BLI_parent_dir(char *path) +{ +#ifdef WIN32 + static char *parent_dir="..\\"; +#else + static char *parent_dir="../"; +#endif + char tmp[FILE_MAXDIR+FILE_MAXFILE+4]; + BLI_strncpy(tmp, path, sizeof(tmp)); + 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; + } else { + return 0; + } +} int BLI_convertstringframe(char *path, int frame) { @@ -1129,15 +1149,13 @@ int BLI_convertstringframe(char *path, int frame) int BLI_convertstringcode(char *path, const char *basepath) { - int wasrelative; + int wasrelative = (strncmp(path, "//", 2)==0); char tmp[FILE_MAX]; char base[FILE_MAX]; +#ifdef WIN32 char vol[3] = {'\0', '\0', '\0'}; BLI_strncpy(vol, path, 3); - wasrelative= (vol[0]=='/' && vol[1]=='/'); - -#ifdef WIN32 /* we are checking here if we have an absolute path that is not in the current blend file as a lib main - we are basically checking for the case that a UNIX root '/' is passed. @@ -1156,6 +1174,20 @@ int BLI_convertstringcode(char *path, const char *basepath) } #else BLI_strncpy(tmp, path, FILE_MAX); + + /* Check for loading a windows path on a posix system + * in this case, there is no use in trying C:/ since it + * will never exist on a unix os. + * + * Add a / prefix and lowercase the driveletter, remove the : + * C:\foo.JPG -> /c/foo.JPG */ + + if (tmp[1] == ':' && isalpha(tmp[0]) && (tmp[2]=='\\' || tmp[2]=='/') ) { + tmp[1] = tolower(tmp[0]); /* replace ':' with driveletter */ + tmp[0] = '/'; + /* '\' the slash will be converted later */ + } + #endif BLI_strncpy(base, basepath, FILE_MAX); @@ -1211,6 +1243,49 @@ int BLI_convertstringcode(char *path, const char *basepath) return wasrelative; } + +/* + * Should only be done with command line paths. + * this is NOT somthing blenders internal paths support like the // prefix + */ +int BLI_convertstringcwd(char *path) +{ + int wasrelative = 1; + int filelen = strlen(path); + +#ifdef WIN32 + if (filelen >= 3 && path[1] == ':' && (path[2] == '\\' || path[2] == '/')) + wasrelative = 0; +#else + if (filelen >= 2 && path[0] == '/') + wasrelative = 0; +#endif + + if (wasrelative==1) { + char cwd[FILE_MAXDIR + FILE_MAXFILE]; + BLI_getwdN(cwd); /* incase the full path to the blend isnt used */ + + if (cwd[0] == '\0') { + printf( "Could not get the current working directory - $PWD for an unknown reason."); + } else { + /* uses the blend path relative to cwd important for loading relative linked files. + * + * cwd should contain c:\ etc on win32 so the relbase can be NULL + * relbase being NULL also prevents // being misunderstood as relative to the current + * blend file which isnt a feature we want to use in this case since were dealing + * with a path from the command line, rather then from inside Blender */ + + char origpath[FILE_MAXDIR + FILE_MAXFILE]; + BLI_strncpy(origpath, path, FILE_MAXDIR + FILE_MAXFILE); + + BLI_make_file_string(NULL, path, cwd, origpath); + } + } + + return wasrelative; +} + + /* copy di to fi, filename only */ void BLI_splitdirstring(char *di, char *fi) { @@ -1912,7 +1987,7 @@ int BLI_strncasecmp(const char *s1, const char *s2, int n) { #include "iconv.h" #include "localcharset.h" -void BLI_string_to_utf8(char *original, char *utf_8, char *code) +void BLI_string_to_utf8(char *original, char *utf_8, const char *code) { size_t inbytesleft=strlen(original); size_t outbytesleft=512; @@ -1970,7 +2045,7 @@ void BLI_timestr(double _time, char *str) int BLI_int_from_pointer(void *poin) { - long lval= (long)poin; + intptr_t lval= (intptr_t)poin; return (int)(lval>>3); } @@ -1978,17 +2053,17 @@ int BLI_int_from_pointer(void *poin) void *BLI_pointer_from_int(int val) { static int firsttime= 1; - static long basevalue= 0; + static intptr_t basevalue= 0; if(firsttime) { void *poin= malloc(10000); - basevalue= (long)poin; + basevalue= (intptr_t)poin; basevalue &= ~PMASK; printf("base: %d pointer %p\n", basevalue, poin); /* debug */ firsttime= 0; free(poin); } - return (void *)(basevalue | (((long)val)<<3)); + return (void *)(basevalue | (((intptr_t)val)<<3)); } #else |