From 2253b63c979fbfbbb6f06c93ede85d9b9b6caddf Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 16 Dec 2011 09:25:07 +0000 Subject: static functions for getting power of 2 values were being copied about too much, add to the BLI_math api. - is_power_of_2_i - power_of_2_min_i - power_of_2_max_i --- source/blender/blenlib/intern/math_base_inline.c | 26 ++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'source/blender/blenlib/intern') diff --git a/source/blender/blenlib/intern/math_base_inline.c b/source/blender/blenlib/intern/math_base_inline.c index 0b2411af009..7e04e0ae566 100644 --- a/source/blender/blenlib/intern/math_base_inline.c +++ b/source/blender/blenlib/intern/math_base_inline.c @@ -115,6 +115,31 @@ MINLINE float power_of_2(float val) return (float)pow(2.0, ceil(log((double)val) / M_LN2)); } +MINLINE int is_power_of_2_i(int n) +{ + return (n & (n - 1)) == 0; +} + +MINLINE int power_of_2_max_i(int n) +{ + if (is_power_of_2_i(n)) + return n; + + while(!is_power_of_2_i(n)) + n = n & (n - 1); + + return n * 2; +} + +MINLINE int power_of_2_min_i(int n) +{ + while (!is_power_of_2_i(n)) + n = n & (n - 1); + + return n; +} + + MINLINE float minf(float a, float b) { return (a < b)? a: b; @@ -130,5 +155,6 @@ MINLINE float signf(float f) return (f < 0.f)? -1.f: 1.f; } + #endif /* BLI_MATH_BASE_INLINE_H */ -- cgit v1.2.3 From 3311164b24da61f2967f96d0ee27508a7e2e0267 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Fri, 16 Dec 2011 19:53:12 +0000 Subject: Math lib: matrix multiplication order fix for two functions that were inconsistent with similar functions & math notation: mul_m4_m4m4(R, B, A) => mult_m4_m4m4(R, A, B) mul_m3_m3m4(R, B, A) => mult_m3_m3m4(R, A, B) For branch maintainers, it should be relatively simple to fix things manually, it's also possible run this script after merging to do automatic replacement: http://www.pasteall.org/27459/python --- source/blender/blenlib/intern/math_matrix.c | 18 +++++++++--------- source/blender/blenlib/intern/math_rotation.c | 6 +++--- 2 files changed, 12 insertions(+), 12 deletions(-) (limited to 'source/blender/blenlib/intern') diff --git a/source/blender/blenlib/intern/math_matrix.c b/source/blender/blenlib/intern/math_matrix.c index 37cb49fc17b..ee9cbaf1f81 100644 --- a/source/blender/blenlib/intern/math_matrix.c +++ b/source/blender/blenlib/intern/math_matrix.c @@ -142,7 +142,7 @@ void swap_m4m4(float m1[][4], float m2[][4]) /******************************** Arithmetic *********************************/ -void mul_m4_m4m4(float m1[][4], float m2_[][4], float m3_[][4]) +void mult_m4_m4m4(float m1[][4], float m3_[][4], float m2_[][4]) { float m2[4][4], m3[4][4]; @@ -209,7 +209,7 @@ void mul_m4_m4m3(float (*m1)[4], float (*m3)[4], float (*m2)[3]) } /* m1 = m2 * m3, ignore the elements on the 4th row/column of m3*/ -void mul_m3_m3m4(float m1[][3], float m2[][3], float m3[][4]) +void mult_m3_m3m4(float m1[][3], float m3[][4], float m2[][3]) { /* m1[i][j] = m2[i][k] * m3[k][j] */ m1[0][0] = m2[0][0] * m3[0][0] + m2[0][1] * m3[1][0] +m2[0][2] * m3[2][0]; @@ -280,19 +280,19 @@ void mul_serie_m4(float answ[][4], float m1[][4], if(m1==NULL || m2==NULL) return; - mul_m4_m4m4(answ, m2, m1); + mult_m4_m4m4(answ, m1, m2); if(m3) { - mul_m4_m4m4(temp, m3, answ); + mult_m4_m4m4(temp, answ, m3); if(m4) { - mul_m4_m4m4(answ, m4, temp); + mult_m4_m4m4(answ, temp, m4); if(m5) { - mul_m4_m4m4(temp, m5, answ); + mult_m4_m4m4(temp, answ, m5); if(m6) { - mul_m4_m4m4(answ, m6, temp); + mult_m4_m4m4(answ, temp, m6); if(m7) { - mul_m4_m4m4(temp, m7, answ); + mult_m4_m4m4(temp, answ, m7); if(m8) { - mul_m4_m4m4(answ, m8, temp); + mult_m4_m4m4(answ, temp, m8); } else copy_m4_m4(answ, temp); } diff --git a/source/blender/blenlib/intern/math_rotation.c b/source/blender/blenlib/intern/math_rotation.c index e4664798f5d..5596b6f9f22 100644 --- a/source/blender/blenlib/intern/math_rotation.c +++ b/source/blender/blenlib/intern/math_rotation.c @@ -1433,7 +1433,7 @@ void mat4_to_dquat(DualQuat *dq,float basemat[][4], float mat[][4]) /* split scaling and rotation, there is probably a faster way to do this, it's done like this now to correctly get negative scaling */ - mul_m4_m4m4(baseRS, basemat, mat); + mult_m4_m4m4(baseRS, mat, basemat); mat4_to_size(scale,baseRS); copy_v3_v3(dscale, scale); @@ -1452,10 +1452,10 @@ void mat4_to_dquat(DualQuat *dq,float basemat[][4], float mat[][4]) copy_v3_v3(baseR[3], baseRS[3]); invert_m4_m4(baseinv, basemat); - mul_m4_m4m4(R, baseinv, baseR); + mult_m4_m4m4(R, baseR, baseinv); invert_m4_m4(baseRinv, baseR); - mul_m4_m4m4(S, baseRS, baseRinv); + mult_m4_m4m4(S, baseRinv, baseRS); /* set scaling part */ mul_serie_m4(dq->scale, basemat, S, baseinv, NULL, NULL, NULL, NULL, NULL); -- cgit v1.2.3 From 4d6c34462c1473afb6a0896f97bc5cd2393d0171 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Fri, 16 Dec 2011 23:56:18 +0000 Subject: Fix #29640: make duplicates release keep hierarchy and parent properties not working for multiple objects. ID.newid only worked for one object, now it uses a hash instead. --- source/blender/blenlib/intern/BLI_ghash.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'source/blender/blenlib/intern') diff --git a/source/blender/blenlib/intern/BLI_ghash.c b/source/blender/blenlib/intern/BLI_ghash.c index c1894088300..13f33f01420 100644 --- a/source/blender/blenlib/intern/BLI_ghash.c +++ b/source/blender/blenlib/intern/BLI_ghash.c @@ -285,3 +285,31 @@ unsigned int BLI_ghashutil_strhash(const void *ptr) { int BLI_ghashutil_strcmp(const void *a, const void *b) { return strcmp(a, b); } + +GHashPair *BLI_ghashutil_pairalloc(const void *first, int second) { + GHashPair *pair = MEM_mallocN(sizeof(GHashPair), "GHashPair"); + pair->first = first; + pair->second = second; + return pair; +} + +unsigned int BLI_ghashutil_pairhash(const void *ptr) { + const GHashPair *pair = ptr; + unsigned int hash = BLI_ghashutil_ptrhash(pair->first); + return hash ^ BLI_ghashutil_inthash(SET_INT_IN_POINTER(pair->second)); +} + +int BLI_ghashutil_paircmp(const void *a, const void *b) { + const GHashPair *A = a; + const GHashPair *B = b; + + int cmp = BLI_ghashutil_ptrcmp(A->first, B->first); + if(cmp == 0) + return BLI_ghashutil_intcmp(SET_INT_IN_POINTER(A->second), SET_INT_IN_POINTER(B->second)); + return cmp; +} + +void BLI_ghashutil_pairfree(const void *ptr) { + MEM_freeN((void*)ptr); +} + -- cgit v1.2.3 From ad96dacbc5a7cc61ccf74405927847f243a955b5 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 17 Dec 2011 00:52:36 +0000 Subject: style edit only - move parenthesis onto second line of function definition (in keeping with most of blenders code) also split some long lines in own code. --- source/blender/blenlib/intern/BLI_dynstr.c | 9 ++-- source/blender/blenlib/intern/BLI_ghash.c | 69 ++++++++++++++++++---------- source/blender/blenlib/intern/BLI_linklist.c | 24 ++++++---- source/blender/blenlib/intern/BLI_memarena.c | 18 +++++--- source/blender/blenlib/intern/edgehash.c | 45 ++++++++++++------ source/blender/blenlib/intern/rand.c | 39 ++++++++++------ source/blender/blenlib/intern/winstuff.c | 18 +++++--- 7 files changed, 148 insertions(+), 74 deletions(-) (limited to 'source/blender/blenlib/intern') diff --git a/source/blender/blenlib/intern/BLI_dynstr.c b/source/blender/blenlib/intern/BLI_dynstr.c index 5cdadce7c01..349bc3492e7 100644 --- a/source/blender/blenlib/intern/BLI_dynstr.c +++ b/source/blender/blenlib/intern/BLI_dynstr.c @@ -94,7 +94,8 @@ void BLI_dynstr_append(DynStr *ds, const char *cstr) ds->curlen+= cstrlen; } -void BLI_dynstr_nappend(DynStr *ds, const char *cstr, int len) { +void BLI_dynstr_nappend(DynStr *ds, const char *cstr, int len) +{ DynStrElem *dse= malloc(sizeof(*dse)); int cstrlen= BLI_strnlen(cstr, len); @@ -225,7 +226,8 @@ int BLI_dynstr_get_len(DynStr *ds) return ds->curlen; } -char *BLI_dynstr_get_cstring(DynStr *ds) { +char *BLI_dynstr_get_cstring(DynStr *ds) +{ char *s, *rets= MEM_mallocN(ds->curlen+1, "dynstr_cstring"); DynStrElem *dse; @@ -241,7 +243,8 @@ char *BLI_dynstr_get_cstring(DynStr *ds) { return rets; } -void BLI_dynstr_free(DynStr *ds) { +void BLI_dynstr_free(DynStr *ds) +{ DynStrElem *dse; for (dse= ds->elems; dse; ) { diff --git a/source/blender/blenlib/intern/BLI_ghash.c b/source/blender/blenlib/intern/BLI_ghash.c index 13f33f01420..9f388b68c38 100644 --- a/source/blender/blenlib/intern/BLI_ghash.c +++ b/source/blender/blenlib/intern/BLI_ghash.c @@ -56,7 +56,8 @@ static unsigned int hashsizes[]= { /***/ -GHash *BLI_ghash_new(GHashHashFP hashfp, GHashCmpFP cmpfp, const char *info) { +GHash *BLI_ghash_new(GHashHashFP hashfp, GHashCmpFP cmpfp, const char *info) +{ GHash *gh= MEM_mallocN(sizeof(*gh), info); gh->hashfp= hashfp; gh->cmpfp= cmpfp; @@ -72,11 +73,13 @@ GHash *BLI_ghash_new(GHashHashFP hashfp, GHashCmpFP cmpfp, const char *info) { return gh; } -int BLI_ghash_size(GHash *gh) { +int BLI_ghash_size(GHash *gh) +{ return gh->nentries; } -void BLI_ghash_insert(GHash *gh, void *key, void *val) { +void BLI_ghash_insert(GHash *gh, void *key, void *val) +{ unsigned int hash= gh->hashfp(key)%gh->nbuckets; Entry *e= (Entry*) BLI_mempool_alloc(gh->entrypool); @@ -109,7 +112,8 @@ void BLI_ghash_insert(GHash *gh, void *key, void *val) { } } -void *BLI_ghash_lookup(GHash *gh, const void *key) { +void *BLI_ghash_lookup(GHash *gh, const void *key) +{ if(gh) { unsigned int hash= gh->hashfp(key)%gh->nbuckets; Entry *e; @@ -151,7 +155,8 @@ int BLI_ghash_remove (GHash *gh, void *key, GHashKeyFreeFP keyfreefp, GHashValFr return 0; } -int BLI_ghash_haskey(GHash *gh, void *key) { +int BLI_ghash_haskey(GHash *gh, void *key) +{ unsigned int hash= gh->hashfp(key)%gh->nbuckets; Entry *e; @@ -162,7 +167,8 @@ int BLI_ghash_haskey(GHash *gh, void *key) { return 0; } -void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp) { +void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp) +{ int i; if (keyfreefp || valfreefp) { @@ -190,7 +196,8 @@ void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreef /***/ -GHashIterator *BLI_ghashIterator_new(GHash *gh) { +GHashIterator *BLI_ghashIterator_new(GHash *gh) +{ GHashIterator *ghi= MEM_mallocN(sizeof(*ghi), "ghash iterator"); ghi->gh= gh; ghi->curEntry= NULL; @@ -203,7 +210,8 @@ GHashIterator *BLI_ghashIterator_new(GHash *gh) { } return ghi; } -void BLI_ghashIterator_init(GHashIterator *ghi, GHash *gh) { +void BLI_ghashIterator_init(GHashIterator *ghi, GHash *gh) +{ ghi->gh= gh; ghi->curEntry= NULL; ghi->curBucket= -1; @@ -214,18 +222,22 @@ void BLI_ghashIterator_init(GHashIterator *ghi, GHash *gh) { ghi->curEntry= ghi->gh->buckets[ghi->curBucket]; } } -void BLI_ghashIterator_free(GHashIterator *ghi) { +void BLI_ghashIterator_free(GHashIterator *ghi) +{ MEM_freeN(ghi); } -void *BLI_ghashIterator_getKey(GHashIterator *ghi) { +void *BLI_ghashIterator_getKey(GHashIterator *ghi) +{ return ghi->curEntry?ghi->curEntry->key:NULL; } -void *BLI_ghashIterator_getValue(GHashIterator *ghi) { +void *BLI_ghashIterator_getValue(GHashIterator *ghi) +{ return ghi->curEntry?ghi->curEntry->val:NULL; } -void BLI_ghashIterator_step(GHashIterator *ghi) { +void BLI_ghashIterator_step(GHashIterator *ghi) +{ if (ghi->curEntry) { ghi->curEntry= ghi->curEntry->next; while (!ghi->curEntry) { @@ -236,23 +248,27 @@ void BLI_ghashIterator_step(GHashIterator *ghi) { } } } -int BLI_ghashIterator_isDone(GHashIterator *ghi) { +int BLI_ghashIterator_isDone(GHashIterator *ghi) +{ return !ghi->curEntry; } /***/ -unsigned int BLI_ghashutil_ptrhash(const void *key) { +unsigned int BLI_ghashutil_ptrhash(const void *key) +{ return (unsigned int)(intptr_t)key; } -int BLI_ghashutil_ptrcmp(const void *a, const void *b) { +int BLI_ghashutil_ptrcmp(const void *a, const void *b) +{ if (a==b) return 0; else return (afirst = first; pair->second = second; return pair; } -unsigned int BLI_ghashutil_pairhash(const void *ptr) { +unsigned int BLI_ghashutil_pairhash(const void *ptr) +{ const GHashPair *pair = ptr; unsigned int hash = BLI_ghashutil_ptrhash(pair->first); return hash ^ BLI_ghashutil_inthash(SET_INT_IN_POINTER(pair->second)); } -int BLI_ghashutil_paircmp(const void *a, const void *b) { +int BLI_ghashutil_paircmp(const void *a, const void *b) +{ const GHashPair *A = a; const GHashPair *B = b; @@ -309,7 +331,8 @@ int BLI_ghashutil_paircmp(const void *a, const void *b) { return cmp; } -void BLI_ghashutil_pairfree(const void *ptr) { +void BLI_ghashutil_pairfree(void *ptr) +{ MEM_freeN((void*)ptr); } diff --git a/source/blender/blenlib/intern/BLI_linklist.c b/source/blender/blenlib/intern/BLI_linklist.c index a9b8cbb6467..6300817ec03 100644 --- a/source/blender/blenlib/intern/BLI_linklist.c +++ b/source/blender/blenlib/intern/BLI_linklist.c @@ -35,7 +35,8 @@ #include "BLI_linklist.h" #include "BLI_memarena.h" -int BLI_linklist_length(LinkNode *list) { +int BLI_linklist_length(LinkNode *list) +{ if (0) { return list?(1+BLI_linklist_length(list->next)):0; } else { @@ -70,7 +71,8 @@ LinkNode *BLI_linklist_find(LinkNode *list, int index) return NULL; } -void BLI_linklist_reverse(LinkNode **listp) { +void BLI_linklist_reverse(LinkNode **listp) +{ LinkNode *rhead= NULL, *cur= *listp; while (cur) { @@ -85,7 +87,8 @@ void BLI_linklist_reverse(LinkNode **listp) { *listp= rhead; } -void BLI_linklist_prepend(LinkNode **listp, void *ptr) { +void BLI_linklist_prepend(LinkNode **listp, void *ptr) +{ LinkNode *nlink= MEM_mallocN(sizeof(*nlink), "nlink"); nlink->link= ptr; @@ -93,7 +96,8 @@ void BLI_linklist_prepend(LinkNode **listp, void *ptr) { *listp= nlink; } -void BLI_linklist_append(LinkNode **listp, void *ptr) { +void BLI_linklist_append(LinkNode **listp, void *ptr) +{ LinkNode *nlink= MEM_mallocN(sizeof(*nlink), "nlink"); LinkNode *node = *listp; @@ -110,7 +114,8 @@ void BLI_linklist_append(LinkNode **listp, void *ptr) { } } -void BLI_linklist_prepend_arena(LinkNode **listp, void *ptr, MemArena *ma) { +void BLI_linklist_prepend_arena(LinkNode **listp, void *ptr, MemArena *ma) +{ LinkNode *nlink= BLI_memarena_alloc(ma, sizeof(*nlink)); nlink->link= ptr; @@ -118,7 +123,8 @@ void BLI_linklist_prepend_arena(LinkNode **listp, void *ptr, MemArena *ma) { *listp= nlink; } -void BLI_linklist_insert_after(LinkNode **listp, void *ptr) { +void BLI_linklist_insert_after(LinkNode **listp, void *ptr) +{ LinkNode *nlink= MEM_mallocN(sizeof(*nlink), "nlink"); LinkNode *node = *listp; @@ -134,7 +140,8 @@ void BLI_linklist_insert_after(LinkNode **listp, void *ptr) { } } -void BLI_linklist_free(LinkNode *list, LinkNodeFreeFP freefunc) { +void BLI_linklist_free(LinkNode *list, LinkNodeFreeFP freefunc) +{ while (list) { LinkNode *next= list->next; @@ -146,7 +153,8 @@ void BLI_linklist_free(LinkNode *list, LinkNodeFreeFP freefunc) { } } -void BLI_linklist_apply(LinkNode *list, LinkNodeApplyFP applyfunc, void *userdata) { +void BLI_linklist_apply(LinkNode *list, LinkNodeApplyFP applyfunc, void *userdata) +{ for (; list; list= list->next) applyfunc(list->link, userdata); } diff --git a/source/blender/blenlib/intern/BLI_memarena.c b/source/blender/blenlib/intern/BLI_memarena.c index 308fc6a61e6..4debe1a4b04 100644 --- a/source/blender/blenlib/intern/BLI_memarena.c +++ b/source/blender/blenlib/intern/BLI_memarena.c @@ -48,7 +48,8 @@ struct MemArena { LinkNode *bufs; }; -MemArena *BLI_memarena_new(int bufsize, const char *name) { +MemArena *BLI_memarena_new(int bufsize, const char *name) +{ MemArena *ma= MEM_callocN(sizeof(*ma), "memarena"); ma->bufsize= bufsize; ma->align = 8; @@ -57,20 +58,24 @@ MemArena *BLI_memarena_new(int bufsize, const char *name) { return ma; } -void BLI_memarena_use_calloc(MemArena *ma) { +void BLI_memarena_use_calloc(MemArena *ma) +{ ma->use_calloc= 1; } -void BLI_memarena_use_malloc(MemArena *ma) { +void BLI_memarena_use_malloc(MemArena *ma) +{ ma->use_calloc= 0; } -void BLI_memarena_use_align(struct MemArena *ma, int align) { +void BLI_memarena_use_align(struct MemArena *ma, int align) +{ /* align should be a power of two */ ma->align = align; } -void BLI_memarena_free(MemArena *ma) { +void BLI_memarena_free(MemArena *ma) +{ BLI_linklist_free(ma->bufs, (void(*)(void*)) MEM_freeN); MEM_freeN(ma); } @@ -78,7 +83,8 @@ void BLI_memarena_free(MemArena *ma) { /* amt must be power of two */ #define PADUP(num, amt) ((num+(amt-1))&~(amt-1)) -void *BLI_memarena_alloc(MemArena *ma, int size) { +void *BLI_memarena_alloc(MemArena *ma, int size) +{ void *ptr; /* ensure proper alignment by rounding diff --git a/source/blender/blenlib/intern/edgehash.c b/source/blender/blenlib/intern/edgehash.c index 0eda3e78824..7ae68101154 100644 --- a/source/blender/blenlib/intern/edgehash.c +++ b/source/blender/blenlib/intern/edgehash.c @@ -64,7 +64,8 @@ struct EdgeHash { /***/ -EdgeHash *BLI_edgehash_new(void) { +EdgeHash *BLI_edgehash_new(void) +{ EdgeHash *eh= MEM_mallocN(sizeof(*eh), "EdgeHash"); eh->cursize= 0; eh->nentries= 0; @@ -76,7 +77,8 @@ EdgeHash *BLI_edgehash_new(void) { return eh; } -void BLI_edgehash_insert(EdgeHash *eh, int v0, int v1, void *val) { +void BLI_edgehash_insert(EdgeHash *eh, int v0, int v1, void *val) +{ unsigned int hash; Entry *e= malloc(sizeof(*e)); @@ -117,7 +119,8 @@ void BLI_edgehash_insert(EdgeHash *eh, int v0, int v1, void *val) { } } -void** BLI_edgehash_lookup_p(EdgeHash *eh, int v0, int v1) { +void** BLI_edgehash_lookup_p(EdgeHash *eh, int v0, int v1) +{ unsigned int hash; Entry *e; @@ -134,21 +137,25 @@ void** BLI_edgehash_lookup_p(EdgeHash *eh, int v0, int v1) { return NULL; } -void* BLI_edgehash_lookup(EdgeHash *eh, int v0, int v1) { +void* BLI_edgehash_lookup(EdgeHash *eh, int v0, int v1) +{ void **value_p = BLI_edgehash_lookup_p(eh,v0,v1); return value_p?*value_p:NULL; } -int BLI_edgehash_haskey(EdgeHash *eh, int v0, int v1) { +int BLI_edgehash_haskey(EdgeHash *eh, int v0, int v1) +{ return BLI_edgehash_lookup_p(eh, v0, v1)!=NULL; } -int BLI_edgehash_size(EdgeHash *eh) { +int BLI_edgehash_size(EdgeHash *eh) +{ return eh->nentries; } -void BLI_edgehash_clear(EdgeHash *eh, EdgeHashFreeFP valfreefp) { +void BLI_edgehash_clear(EdgeHash *eh, EdgeHashFreeFP valfreefp) +{ int i; for (i=0; inbuckets; i++) { @@ -168,7 +175,8 @@ void BLI_edgehash_clear(EdgeHash *eh, EdgeHashFreeFP valfreefp) { eh->nentries= 0; } -void BLI_edgehash_free(EdgeHash *eh, EdgeHashFreeFP valfreefp) { +void BLI_edgehash_free(EdgeHash *eh, EdgeHashFreeFP valfreefp) +{ BLI_edgehash_clear(eh, valfreefp); free(eh->buckets); @@ -184,7 +192,8 @@ struct EdgeHashIterator { Entry *curEntry; }; -EdgeHashIterator *BLI_edgehashIterator_new(EdgeHash *eh) { +EdgeHashIterator *BLI_edgehashIterator_new(EdgeHash *eh) +{ EdgeHashIterator *ehi= malloc(sizeof(*ehi)); ehi->eh= eh; ehi->curEntry= NULL; @@ -197,26 +206,31 @@ EdgeHashIterator *BLI_edgehashIterator_new(EdgeHash *eh) { } return ehi; } -void BLI_edgehashIterator_free(EdgeHashIterator *ehi) { +void BLI_edgehashIterator_free(EdgeHashIterator *ehi) +{ free(ehi); } -void BLI_edgehashIterator_getKey(EdgeHashIterator *ehi, int *v0_r, int *v1_r) { +void BLI_edgehashIterator_getKey(EdgeHashIterator *ehi, int *v0_r, int *v1_r) +{ if (ehi->curEntry) { *v0_r = ehi->curEntry->v0; *v1_r = ehi->curEntry->v1; } } -void *BLI_edgehashIterator_getValue(EdgeHashIterator *ehi) { +void *BLI_edgehashIterator_getValue(EdgeHashIterator *ehi) +{ return ehi->curEntry?ehi->curEntry->val:NULL; } -void BLI_edgehashIterator_setValue(EdgeHashIterator *ehi, void *val) { +void BLI_edgehashIterator_setValue(EdgeHashIterator *ehi, void *val) +{ if(ehi->curEntry) ehi->curEntry->val= val; } -void BLI_edgehashIterator_step(EdgeHashIterator *ehi) { +void BLI_edgehashIterator_step(EdgeHashIterator *ehi) +{ if (ehi->curEntry) { ehi->curEntry= ehi->curEntry->next; while (!ehi->curEntry) { @@ -227,7 +241,8 @@ void BLI_edgehashIterator_step(EdgeHashIterator *ehi) { } } } -int BLI_edgehashIterator_isDone(EdgeHashIterator *ehi) { +int BLI_edgehashIterator_isDone(EdgeHashIterator *ehi) +{ return !ehi->curEntry; } diff --git a/source/blender/blenlib/intern/rand.c b/source/blender/blenlib/intern/rand.c index b1b7ebed18e..28dc5a696d5 100644 --- a/source/blender/blenlib/intern/rand.c +++ b/source/blender/blenlib/intern/rand.c @@ -78,11 +78,13 @@ void rng_free(RNG* rng) MEM_freeN(rng); } -void rng_seed(RNG *rng, unsigned int seed) { +void rng_seed(RNG *rng, unsigned int seed) +{ rng->X= (((r_uint64) seed)<<16) | LOWSEED; } -void rng_srandom(RNG *rng, unsigned int seed) { +void rng_srandom(RNG *rng, unsigned int seed) +{ rng_seed(rng, seed + hash[seed & 255]); seed= rng_getInt(rng); rng_seed(rng, seed + hash[seed & 255]); @@ -90,16 +92,19 @@ void rng_srandom(RNG *rng, unsigned int seed) { rng_seed(rng, seed + hash[seed & 255]); } -int rng_getInt(RNG *rng) { +int rng_getInt(RNG *rng) +{ rng->X= (MULTIPLIER*rng->X + ADDEND)&MASK; return (int) (rng->X>>17); } -double rng_getDouble(RNG *rng) { +double rng_getDouble(RNG *rng) +{ return (double) rng_getInt(rng)/0x80000000; } -float rng_getFloat(RNG *rng) { +float rng_getFloat(RNG *rng) +{ return (float) rng_getInt(rng)/0x80000000; } @@ -135,28 +140,34 @@ void rng_skip(RNG *rng, int n) static RNG theBLI_rng = {0}; /* note, this one creates periodical patterns */ -void BLI_srand(unsigned int seed) { +void BLI_srand(unsigned int seed) +{ rng_seed(&theBLI_rng, seed); } /* using hash table to create better seed */ -void BLI_srandom(unsigned int seed) { +void BLI_srandom(unsigned int seed) +{ rng_srandom(&theBLI_rng, seed); } -int BLI_rand(void) { +int BLI_rand(void) +{ return rng_getInt(&theBLI_rng); } -double BLI_drand(void) { +double BLI_drand(void) +{ return rng_getDouble(&theBLI_rng); } -float BLI_frand(void) { +float BLI_frand(void) +{ return rng_getFloat(&theBLI_rng); } -void BLI_fillrand(void *addr, int len) { +void BLI_fillrand(void *addr, int len) +{ RNG rng; unsigned char *p= addr; @@ -188,11 +199,13 @@ void BLI_thread_srandom(int thread, unsigned int seed) rng_seed(&rng_tab[thread], seed + hash[seed & 255]); } -int BLI_thread_rand(int thread) { +int BLI_thread_rand(int thread) +{ return rng_getInt(&rng_tab[thread]); } -float BLI_thread_frand(int thread) { +float BLI_thread_frand(int thread) +{ return rng_getFloat(&rng_tab[thread]); } diff --git a/source/blender/blenlib/intern/winstuff.c b/source/blender/blenlib/intern/winstuff.c index 1b5bb607386..b2002b63a22 100644 --- a/source/blender/blenlib/intern/winstuff.c +++ b/source/blender/blenlib/intern/winstuff.c @@ -49,7 +49,8 @@ /* FILE_MAX */ -int BLI_getInstallationDir( char * str ) { +int BLI_getInstallationDir( char * str ) +{ char dir[FILE_MAXDIR]; int a; @@ -73,7 +74,8 @@ void RegisterBlendExtension_Fail(HKEY root) TerminateProcess(GetCurrentProcess(),1); } -void RegisterBlendExtension(void) { +void RegisterBlendExtension(void) +{ LONG lresult; HKEY hkey = 0; HKEY root = 0; @@ -167,7 +169,8 @@ void RegisterBlendExtension(void) { TerminateProcess(GetCurrentProcess(),0); } -DIR *opendir (const char *path) { +DIR *opendir (const char *path) +{ if (GetFileAttributes(path) & FILE_ATTRIBUTE_DIRECTORY) { DIR *newd= MEM_mallocN(sizeof(DIR), "opendir"); @@ -185,7 +188,8 @@ DIR *opendir (const char *path) { } } -struct dirent *readdir(DIR *dp) { +struct dirent *readdir(DIR *dp) +{ if (dp->direntry.d_name) { MEM_freeN(dp->direntry.d_name); dp->direntry.d_name= NULL; @@ -208,7 +212,8 @@ struct dirent *readdir(DIR *dp) { } } -int closedir (DIR *dp) { +int closedir (DIR *dp) +{ if (dp->direntry.d_name) MEM_freeN(dp->direntry.d_name); if (dp->handle!=INVALID_HANDLE_VALUE) FindClose(dp->handle); @@ -217,7 +222,8 @@ int closedir (DIR *dp) { return 0; } -void get_default_root(char* root) { +void get_default_root(char* root) +{ char str[MAX_PATH+1]; /* the default drive to resolve a directory without a specified drive -- cgit v1.2.3 From 414370b8d42324878485e569fc332b814131887f Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 18 Dec 2011 07:27:11 +0000 Subject: Support for arbitrary sized vectors - (was limited by 2-4 previously) patch http://codereview.appspot.com/5482043 from Andrew Hale * Text from the submission * This patch adds the ability to use arbitrary sized vectors from mathutils. Currently vectors are only of size 2, 3 or 4 since they are generally restricted to geometric applications. However, we can use arbitrary sized vectors for efficient calculations and data manipulation. --- source/blender/blenlib/intern/math_vector.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'source/blender/blenlib/intern') diff --git a/source/blender/blenlib/intern/math_vector.c b/source/blender/blenlib/intern/math_vector.c index a9ea90ef555..590a48e8085 100644 --- a/source/blender/blenlib/intern/math_vector.c +++ b/source/blender/blenlib/intern/math_vector.c @@ -416,6 +416,15 @@ void range_vn_i(int *array_tar, const int size, const int start) while(i--) { *(array_pt--) = j--; } } +void range_vn_fl(float *array_tar, const int size, const float start, const float step) +{ + float *array_pt= array_tar + (size-1); + int i= size; + while(i--) { + *(array_pt--) = start + step * (float)(i); + } +} + void negate_vn(float *array_tar, const int size) { float *array_pt= array_tar + (size-1); -- cgit v1.2.3 From b49463c439820c5039caf63421bdc8f3a58554b2 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 18 Dec 2011 12:54:50 +0000 Subject: cleanup of weight paint color setting code, no functional changes --- source/blender/blenlib/intern/bpath.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'source/blender/blenlib/intern') diff --git a/source/blender/blenlib/intern/bpath.c b/source/blender/blenlib/intern/bpath.c index 140e1752648..861efcfe6c5 100644 --- a/source/blender/blenlib/intern/bpath.c +++ b/source/blender/blenlib/intern/bpath.c @@ -199,7 +199,11 @@ void makeFilesAbsolute(Main *bmain, const char *basedir, ReportList *reports) - filesize: filesize for the file */ #define MAX_RECUR 16 -static int findFileRecursive(char *filename_new, const char *dirname, const char *filename, int *filesize, int *recur_depth) +static int findFileRecursive(char *filename_new, + const char *dirname, + const char *filename, + int *filesize, + int *recur_depth) { /* file searching stuff */ DIR *dir; @@ -314,7 +318,11 @@ static int rewrite_path_fixed(char *path, BPathVisitor visit_cb, const char *abs } } -static int rewrite_path_fixed_dirfile(char path_dir[FILE_MAXDIR], char path_file[FILE_MAXFILE], BPathVisitor visit_cb, const char *absbase, void *userdata) +static int rewrite_path_fixed_dirfile(char path_dir[FILE_MAXDIR], + char path_file[FILE_MAXFILE], + BPathVisitor visit_cb, + const char *absbase, + void *userdata) { char path_src[FILE_MAX]; char path_dst[FILE_MAX]; @@ -496,7 +504,8 @@ void bpath_traverse_id(Main *bmain, ID *id, BPathVisitor visit_cb, const int fla SEQ_BEGIN(scene->ed, seq) { if (SEQ_HAS_PATH(seq)) { if (ELEM(seq->type, SEQ_MOVIE, SEQ_SOUND)) { - rewrite_path_fixed_dirfile(seq->strip->dir, seq->strip->stripdata->name, visit_cb, absbase, bpath_user_data); + rewrite_path_fixed_dirfile(seq->strip->dir, seq->strip->stripdata->name, + visit_cb, absbase, bpath_user_data); } else if (seq->type == SEQ_IMAGE) { /* might want an option not to loop over all strips */ @@ -510,7 +519,8 @@ void bpath_traverse_id(Main *bmain, ID *id, BPathVisitor visit_cb, const int fla } for(i= 0; i < len; i++, se++) { - rewrite_path_fixed_dirfile(seq->strip->dir, se->name, visit_cb, absbase, bpath_user_data); + rewrite_path_fixed_dirfile(seq->strip->dir, se->name, + visit_cb, absbase, bpath_user_data); } } else { -- cgit v1.2.3