diff options
author | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2013-03-18 04:48:59 +0400 |
---|---|---|
committer | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2013-03-18 04:48:59 +0400 |
commit | c1ceab1281ccf061f03f8000bf190a082a5385d8 (patch) | |
tree | 01b9a9cfca80432d316bdad6c18c74eb025e9eb0 /source/blender/blenkernel/intern | |
parent | 0d9c98c4bbfbc8c70c4772086dd09a51d01921ef (diff) | |
parent | 66a35e089a64d27bfc09c2225a530069eca05875 (diff) |
Merged changes in the trunk up to revision 55357.
Resolved conflicts:
release/datafiles/startup.blend
source/blender/editors/space_nla/nla_buttons.c
Also updated source/blender/blenkernel/intern/linestyle.c as a follow-up of
recent changes for the use of bool.
Diffstat (limited to 'source/blender/blenkernel/intern')
56 files changed, 1174 insertions, 682 deletions
diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index ffd86ea9ce0..f09de138428 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -1025,12 +1025,18 @@ enum { CALC_WP_AUTO_NORMALIZE = (1 << 4) }; -static void weightpaint_color(unsigned char r_col[4], ColorBand *coba, const float input) +typedef struct DMWeightColorInfo { + const ColorBand *coba; + const char *alert_color; +} DMWeightColorInfo; + + +static void weightpaint_color(unsigned char r_col[4], DMWeightColorInfo *dm_wcinfo, const float input) { float colf[4]; - if (coba) { - do_colorband(coba, input, colf); + if (dm_wcinfo && dm_wcinfo->coba) { + do_colorband(dm_wcinfo->coba, input, colf); } else { weight_to_rgb(colf, input); @@ -1047,17 +1053,19 @@ static void weightpaint_color(unsigned char r_col[4], ColorBand *coba, const flo static void calc_weightpaint_vert_color( unsigned char r_col[4], - MDeformVert *dv, ColorBand *coba, + MDeformVert *dv, + DMWeightColorInfo *dm_wcinfo, const int defbase_tot, const int defbase_act, const char *defbase_sel, const int defbase_sel_tot, const int draw_flag) { float input = 0.0f; - bool make_black = false; + bool show_alert_color = false; if ((defbase_sel_tot > 1) && (draw_flag & CALC_WP_MULTIPAINT)) { - int was_a_nonzero = FALSE; + /* Multi-Paint feature */ + bool was_a_nonzero = false; unsigned int i; MDeformWeight *dw = dv->dw; @@ -1068,15 +1076,15 @@ static void calc_weightpaint_vert_color( if (defbase_sel[dw->def_nr]) { if (dw->weight) { input += dw->weight; - was_a_nonzero = TRUE; + was_a_nonzero = true; } } } } /* make it black if the selected groups have no weight on a vertex */ - if (was_a_nonzero == FALSE) { - make_black = true; + if (was_a_nonzero == false) { + show_alert_color = true; } else if ((draw_flag & CALC_WP_AUTO_NORMALIZE) == FALSE) { input /= defbase_sel_tot; /* get the average */ @@ -1088,33 +1096,32 @@ static void calc_weightpaint_vert_color( if (draw_flag & CALC_WP_GROUP_USER_ACTIVE) { if (input == 0.0f) { - make_black = true; + show_alert_color = true; } } else if (draw_flag & CALC_WP_GROUP_USER_ALL) { if (input == 0.0f) { - make_black = defvert_is_weight_zero(dv, defbase_tot); + show_alert_color = defvert_is_weight_zero(dv, defbase_tot); } } } - if (make_black) { /* TODO, theme color */ - r_col[3] = 255; - r_col[2] = 0; - r_col[1] = 0; - r_col[0] = 0; + if (show_alert_color == false) { + CLAMP(input, 0.0f, 1.0f); + weightpaint_color(r_col, dm_wcinfo, input); } else { - CLAMP(input, 0.0f, 1.0f); - weightpaint_color(r_col, coba, input); + copy_v3_v3_char((char *)r_col, dm_wcinfo->alert_color); + r_col[3] = 255; } } -static ColorBand *stored_cb = NULL; +static DMWeightColorInfo G_dm_wcinfo; -void vDM_ColorBand_store(ColorBand *coba) +void vDM_ColorBand_store(const ColorBand *coba, const char alert_color[4]) { - stored_cb = coba; + G_dm_wcinfo.coba = coba; + G_dm_wcinfo.alert_color = alert_color; } /* return an array of vertex weight colors, caller must free. @@ -1122,7 +1129,7 @@ void vDM_ColorBand_store(ColorBand *coba) * note that we could save some memory and allocate RGB only but then we'd need to * re-arrange the colors when copying to the face since MCol has odd ordering, * so leave this as is - campbell */ -static unsigned char *calc_weightpaint_vert_array(Object *ob, DerivedMesh *dm, int const draw_flag, ColorBand *coba) +static unsigned char *calc_weightpaint_vert_array(Object *ob, DerivedMesh *dm, int const draw_flag, DMWeightColorInfo *dm_wcinfo) { MDeformVert *dv = DM_get_vert_data_layer(dm, CD_MDEFORMVERT); int numVerts = dm->getNumVerts(dm); @@ -1144,7 +1151,7 @@ static unsigned char *calc_weightpaint_vert_array(Object *ob, DerivedMesh *dm, i } for (i = numVerts; i != 0; i--, wc += 4, dv++) { - calc_weightpaint_vert_color(wc, dv, coba, defbase_tot, defbase_act, defbase_sel, defbase_sel_tot, draw_flag); + calc_weightpaint_vert_color(wc, dv, dm_wcinfo, defbase_tot, defbase_act, defbase_sel, defbase_sel_tot, draw_flag); } if (defbase_sel) { @@ -1157,7 +1164,7 @@ static unsigned char *calc_weightpaint_vert_array(Object *ob, DerivedMesh *dm, i col_i = 0; } else { - weightpaint_color((unsigned char *)&col_i, coba, 0.0f); + weightpaint_color((unsigned char *)&col_i, dm_wcinfo, 0.0f); } fill_vn_i((int *)wtcol_v, numVerts, col_i); } @@ -1185,7 +1192,6 @@ static unsigned char *calc_colors_from_weights_array(const int num, float *weigh void DM_update_weight_mcol(Object *ob, DerivedMesh *dm, int const draw_flag, float *weights, int num, const int *indices) { - ColorBand *coba = stored_cb; /* warning, not a local var */ unsigned char *wtcol_v; unsigned char(*wtcol_l)[4] = CustomData_get_layer(dm->getLoopDataLayout(dm), CD_PREVIEW_MLOOPCOL); @@ -1213,10 +1219,10 @@ void DM_update_weight_mcol(Object *ob, DerivedMesh *dm, int const draw_flag, if (indices) MEM_freeN(w); } - - /* No weights given, take them from active vgroup(s). */ - else - wtcol_v = calc_weightpaint_vert_array(ob, dm, draw_flag, coba); + else { + /* No weights given, take them from active vgroup(s). */ + wtcol_v = calc_weightpaint_vert_array(ob, dm, draw_flag, &G_dm_wcinfo); + } /* now add to loops, so the data can be passed through the modifier stack */ /* If no CD_PREVIEW_MLOOPCOL existed yet, we have to add a new one! */ diff --git a/source/blender/blenkernel/intern/anim.c b/source/blender/blenkernel/intern/anim.c index 4eb26e81ae2..ddb4cc4391a 100644 --- a/source/blender/blenkernel/intern/anim.c +++ b/source/blender/blenkernel/intern/anim.c @@ -1154,10 +1154,6 @@ static void face_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, floa if (ob->type != OB_MBALL) ob->flag |= OB_DONE; /* doesnt render */ for (a = 0, mp = mpoly; a < totface; a++, mp++) { - int mv1; - int mv2; - int mv3; - /* int mv4; */ /* UNUSED */ float *v1; float *v2; float *v3; @@ -1171,9 +1167,9 @@ static void face_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, floa } else { BKE_mesh_calc_poly_normal(mp, mloop + mp->loopstart, mvert, f_no); - v1 = mvert[(mv1 = loopstart[0].v)].co; - v2 = mvert[(mv2 = loopstart[1].v)].co; - v3 = mvert[(mv3 = loopstart[2].v)].co; + v1 = mvert[loopstart[0].v].co; + v2 = mvert[loopstart[1].v].co; + v3 = mvert[loopstart[2].v].co; } /* translation */ diff --git a/source/blender/blenkernel/intern/anim_sys.c b/source/blender/blenkernel/intern/anim_sys.c index bd13c406fa5..738d4c5b089 100644 --- a/source/blender/blenkernel/intern/anim_sys.c +++ b/source/blender/blenkernel/intern/anim_sys.c @@ -245,7 +245,7 @@ void BKE_free_animdata(ID *id) /* Freeing -------------------------------------------- */ /* Make a copy of the given AnimData - to be used when copying datablocks */ -AnimData *BKE_copy_animdata(AnimData *adt, const short do_action) +AnimData *BKE_copy_animdata(AnimData *adt, const bool do_action) { AnimData *dadt; @@ -277,7 +277,7 @@ AnimData *BKE_copy_animdata(AnimData *adt, const short do_action) return dadt; } -int BKE_copy_animdata_id(ID *id_to, ID *id_from, const short do_action) +int BKE_copy_animdata_id(ID *id_to, ID *id_from, const bool do_action) { AnimData *adt; diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c index 480814a28c3..ffe6a312ef8 100644 --- a/source/blender/blenkernel/intern/armature.c +++ b/source/blender/blenkernel/intern/armature.c @@ -1596,7 +1596,7 @@ static void pose_proxy_synchronize(Object *ob, Object *from, int layer_protected } else if (pchan->bone->layer & layer_protected) { ListBase proxylocal_constraints = {NULL, NULL}; - bPoseChannel pchanw = {NULL}; + bPoseChannel pchanw; /* copy posechannel to temp, but restore important pointers */ pchanw = *pchanp; diff --git a/source/blender/blenkernel/intern/blender.c b/source/blender/blenkernel/intern/blender.c index be316197078..82b3b4f5618 100644 --- a/source/blender/blenkernel/intern/blender.c +++ b/source/blender/blenkernel/intern/blender.c @@ -899,7 +899,9 @@ static void copybuffer_doit(void *UNUSED(handle), Main *UNUSED(bmain), void *vid { if (vid) { ID *id = vid; - id->flag |= LIB_NEED_EXPAND | LIB_DOIT; + /* only tag for need-expand if not done, prevents eternal loops */ + if ((id->flag & LIB_DOIT) == 0) + id->flag |= LIB_NEED_EXPAND | LIB_DOIT; } } @@ -993,7 +995,7 @@ int BKE_copybuffer_paste(bContext *C, char *libname, ReportList *reports) /* append, rather than linking */ lib = BLI_findstring(&bmain->library, libname, offsetof(Library, filepath)); - BKE_library_make_local(bmain, lib, 1); + BKE_library_make_local(bmain, lib, true); /* important we unset, otherwise these object wont * link into other scenes from this blend file */ diff --git a/source/blender/blenkernel/intern/bmfont.c b/source/blender/blenkernel/intern/bmfont.c index fc83b24da5b..78da4f5b1c2 100644 --- a/source/blender/blenkernel/intern/bmfont.c +++ b/source/blender/blenkernel/intern/bmfont.c @@ -56,7 +56,7 @@ #include "BKE_bmfont.h" #include "BKE_bmfont_types.h" -void printfGlyph(bmGlyph * glyph) +void printfGlyph(bmGlyph *glyph) { printf("unicode: %d '%c'\n", glyph->unicode, glyph->unicode); printf(" locx: %4d locy: %4d\n", glyph->locx, glyph->locy); @@ -68,7 +68,7 @@ void printfGlyph(bmGlyph * glyph) #define MAX2(x, y) ((x) > (y) ? (x) : (y)) #define MAX3(x, y, z) (MAX2(MAX2((x), (y)), (z))) -void calcAlpha(ImBuf * ibuf) +void calcAlpha(ImBuf *ibuf) { int i; char * rect; @@ -82,7 +82,7 @@ void calcAlpha(ImBuf * ibuf) } } -void readBitmapFontVersion0(ImBuf * ibuf, unsigned char * rect, int step) +void readBitmapFontVersion0(ImBuf *ibuf, unsigned char *rect, int step) { int glyphcount, bytes, i, index, linelength, ysize; unsigned char * buffer; @@ -198,7 +198,7 @@ void detectBitmapFont(ImBuf *ibuf) readBitmapFontVersion0(ibuf, rect, 4); } else { - printf("detectBitmapFont :Unsupported version %d\n", version); + printf("detectBitmapFont :Unsupported version %d\n", (int)version); } /* on succes ibuf->userdata points to the bitmapfont */ diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c index ba69fa4336e..6adcdbd2c3e 100644 --- a/source/blender/blenkernel/intern/brush.c +++ b/source/blender/blenkernel/intern/brush.c @@ -53,6 +53,7 @@ #include "IMB_imbuf_types.h" #include "RE_render_ext.h" /* externtex */ +#include "RE_shader_ext.h" static void brush_defaults(Brush *brush) { @@ -471,62 +472,133 @@ int BKE_brush_clone_image_delete(Brush *brush) return 0; } -/* Brush Sampling for 3d brushes. Currently used for texture painting only, but should be generalized */ -void BKE_brush_sample_tex(const Scene *scene, Brush *brush, const float sampleco[3], float rgba[4], const int thread, struct ImagePool *pool) +/* Generic texture sampler for 3D painting systems. point has to be either in + * region space mouse coordinates, or 3d world coordinates for 3D mapping */ +float BKE_brush_sample_tex_3D(const Scene *scene, Brush *br, + const float point[3], + float rgba[4], const int thread, + struct ImagePool *pool) { - MTex *mtex = &brush->mtex; + UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings; + MTex *mtex = &br->mtex; + float intensity = 1.0; + bool hasrgb = false; - if (mtex && mtex->tex) { - float tin, tr, tg, tb, ta; - int hasrgb; - const int radius = BKE_brush_size_get(scene, brush); + if (!mtex->tex) { + intensity = 1; + } + else if (mtex->brush_map_mode == MTEX_MAP_MODE_3D) { + /* Get strength by feeding the vertex + * location directly into a texture */ + hasrgb = externtex(mtex, point, &intensity, + rgba, rgba + 1, rgba + 2, rgba + 3, thread, pool); + } + else { + float rotation = -mtex->rot; + float point_2d[2] = {point[0], point[1]}; + float x = 0.0f, y = 0.0f; /* Quite warnings */ + float radius = 1.0f; /* Quite warnings */ + float co[3]; - if (brush->mtex.brush_map_mode == MTEX_MAP_MODE_3D) { - hasrgb = externtex(mtex, sampleco, &tin, &tr, &tg, &tb, &ta, thread, pool); - } - else { - float co[3]; + if (mtex->brush_map_mode == MTEX_MAP_MODE_VIEW) { + /* keep coordinates relative to mouse */ + + rotation += ups->brush_rotation; - co[0] = sampleco[0] / radius; - co[1] = sampleco[1] / radius; - co[2] = 0.0f; + point_2d[0] -= ups->tex_mouse[0]; + point_2d[1] -= ups->tex_mouse[1]; - hasrgb = externtex(mtex, co, &tin, &tr, &tg, &tb, &ta, thread, pool); + /* use pressure adjusted size for fixed mode */ + radius = ups->pixel_radius; + + x = point_2d[0]; + y = point_2d[1]; } + else if (mtex->brush_map_mode == MTEX_MAP_MODE_TILED) { + /* leave the coordinates relative to the screen */ - if (hasrgb) { - rgba[0] = tr; - rgba[1] = tg; - rgba[2] = tb; - rgba[3] = ta; + /* use unadjusted size for tiled mode */ + radius = BKE_brush_size_get(scene, br); + + x = point_2d[0]; + y = point_2d[1]; } - else { - rgba[0] = tin; - rgba[1] = tin; - rgba[2] = tin; - rgba[3] = 1.0f; + + x /= radius; + y /= radius; + + /* it is probably worth optimizing for those cases where + * the texture is not rotated by skipping the calls to + * atan2, sqrtf, sin, and cos. */ + if (rotation > 0.001f || rotation < -0.001f) { + const float angle = atan2f(y, x) + rotation; + const float flen = sqrtf(x * x + y * y); + + x = flen * cosf(angle); + y = flen * sinf(angle); } + + x *= br->mtex.size[0]; + y *= br->mtex.size[1]; + + co[0] = x + br->mtex.ofs[0]; + co[1] = y + br->mtex.ofs[1]; + co[2] = 0.0f; + + hasrgb = externtex(mtex, co, &intensity, + rgba, rgba + 1, rgba + 2, rgba + 3, thread, pool); } - else { - rgba[0] = rgba[1] = rgba[2] = rgba[3] = 1.0f; + + intensity += br->texture_sample_bias; + + if (!hasrgb) { + rgba[0] = intensity; + rgba[1] = intensity; + rgba[2] = intensity; + rgba[3] = 1.0f; } + + return intensity; } + /* Brush Sampling for 2D brushes. when we unify the brush systems this will be necessarily a separate function */ -void BKE_brush_sample_tex_2D(const Scene *scene, Brush *brush, const float xy[2], float rgba[4], const int thread) +float BKE_brush_sample_tex_2D(const Scene *scene, Brush *brush, const float xy[2], float rgba[4], struct ImagePool *pool) { + UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings; MTex *mtex = &brush->mtex; if (mtex && mtex->tex) { float co[3], tin, tr, tg, tb, ta; + float x = xy[0], y = xy[1]; int hasrgb; - const int radius = BKE_brush_size_get(scene, brush); + int radius = BKE_brush_size_get(scene, brush); + float rotation = -mtex->rot; + + if (mtex->brush_map_mode == MTEX_MAP_MODE_VIEW) { + rotation += ups->brush_rotation; + radius = ups->pixel_radius; + } + + x /= radius; + y /= radius; + + if (rotation > 0.001f || rotation < -0.001f) { + const float angle = atan2f(y, x) + rotation; + const float flen = sqrtf(x * x + y * y); - co[0] = xy[0] / radius; - co[1] = xy[1] / radius; + x = flen * cosf(angle); + y = flen * sinf(angle); + } + + x *= brush->mtex.size[0]; + y *= brush->mtex.size[1]; + + co[0] = x + brush->mtex.ofs[0]; + co[1] = y + brush->mtex.ofs[1]; co[2] = 0.0f; - hasrgb = externtex(mtex, co, &tin, &tr, &tg, &tb, &ta, thread, NULL); + hasrgb = externtex(mtex, co, &tin, &tr, &tg, &tb, &ta, 0, pool); if (hasrgb) { rgba[0] = tr; @@ -540,9 +612,11 @@ void BKE_brush_sample_tex_2D(const Scene *scene, Brush *brush, const float xy[2] rgba[2] = tin; rgba[3] = 1.0f; } + return tin; } else { rgba[0] = rgba[1] = rgba[2] = rgba[3] = 1.0f; + return 1.0; } } @@ -790,7 +864,8 @@ void BKE_brush_scale_size(int *r_brush_size, void BKE_brush_jitter_pos(const Scene *scene, Brush *brush, const float pos[2], float jitterpos[2]) { - int use_jitter = brush->jitter != 0; + int use_jitter = (brush->flag & BRUSH_ABSOLUTE_JITTER) ? + (brush->jitter_absolute != 0) : (brush->jitter != 0); /* jitter-ed brush gives weird and unpredictable result for this * kinds of stroke, so manually disable jitter usage (sergey) */ @@ -798,17 +873,26 @@ void BKE_brush_jitter_pos(const Scene *scene, Brush *brush, const float pos[2], if (use_jitter) { float rand_pos[2]; - const int radius = BKE_brush_size_get(scene, brush); - const int diameter = 2 * radius; + float spread; + int diameter; - /* find random position within a circle of diameter 1 */ do { rand_pos[0] = BLI_frand() - 0.5f; rand_pos[1] = BLI_frand() - 0.5f; } while (len_v2(rand_pos) > 0.5f); - jitterpos[0] = pos[0] + 2 * rand_pos[0] * diameter * brush->jitter; - jitterpos[1] = pos[1] + 2 * rand_pos[1] * diameter * brush->jitter; + + if (brush->flag & BRUSH_ABSOLUTE_JITTER) { + diameter = 2 * brush->jitter_absolute; + spread = 1.0; + } + else { + diameter = 2 * BKE_brush_size_get(scene, brush); + spread = brush->jitter; + } + /* find random position within a circle of diameter 1 */ + jitterpos[0] = pos[0] + 2 * rand_pos[0] * diameter * spread; + jitterpos[1] = pos[1] + 2 * rand_pos[1] * diameter * spread; } else { copy_v2_v2(jitterpos, pos); @@ -841,6 +925,49 @@ float BKE_brush_curve_strength(Brush *br, float p, const float len) return curvemapping_evaluateF(br->curve, 0, p); } +/* TODO: should probably be unified with BrushPainter stuff? */ +unsigned int *BKE_brush_gen_texture_cache(Brush *br, int half_side) +{ + unsigned int *texcache = NULL; + MTex *mtex = &br->mtex; + TexResult texres = {0}; + int hasrgb, ix, iy; + int side = half_side * 2; + + if (mtex->tex) { + float x, y, step = 2.0 / side, co[3]; + + texcache = MEM_callocN(sizeof(int) * side * side, "Brush texture cache"); + + /*do normalized cannonical view coords for texture*/ + for (y = -1.0, iy = 0; iy < side; iy++, y += step) { + for (x = -1.0, ix = 0; ix < side; ix++, x += step) { + co[0] = x; + co[1] = y; + co[2] = 0.0f; + + /* This is copied from displace modifier code */ + hasrgb = multitex_ext(mtex->tex, co, NULL, NULL, 0, &texres, NULL); + + /* if the texture gave an RGB value, we assume it didn't give a valid + * intensity, so calculate one (formula from do_material_tex). + * if the texture didn't give an RGB value, copy the intensity across + */ + if (hasrgb & TEX_RGB) + texres.tin = rgb_to_grayscale(&texres.tr); + + ((char *)texcache)[(iy * side + ix) * 4] = + ((char *)texcache)[(iy * side + ix) * 4 + 1] = + ((char *)texcache)[(iy * side + ix) * 4 + 2] = + ((char *)texcache)[(iy * side + ix) * 4 + 3] = (char)(texres.tin * 255.0f); + } + } + } + + return texcache; +} + + /**** Radial Control ****/ struct ImBuf *BKE_brush_gen_radial_control_imbuf(Brush *br) { diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c index c1293542963..a7311d5efc7 100644 --- a/source/blender/blenkernel/intern/cloth.c +++ b/source/blender/blenkernel/intern/cloth.c @@ -783,14 +783,12 @@ static void cloth_apply_vgroup ( ClothModifierData *clmd, DerivedMesh *dm ) /* goalfac= 1.0f; */ /* UNUSED */ - /* // Kicking goal factor to simplify things...who uses that anyway? // ABS ( clmd->sim_parms->maxgoal - clmd->sim_parms->mingoal ); - */ verts->goal = powf(verts->goal, 4.0f); if ( verts->goal >= SOFTGOALSNAP ) - verts->flags |= CLOTH_VERT_FLAG_PINNED; + verts->flags |= CLOTH_VERT_FLAG_PINNED; } if (clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_SCALING ) { diff --git a/source/blender/blenkernel/intern/collision.c b/source/blender/blenkernel/intern/collision.c index 061657c8f2d..ed72a0fb37b 100644 --- a/source/blender/blenkernel/intern/collision.c +++ b/source/blender/blenkernel/intern/collision.c @@ -116,7 +116,7 @@ BVHTree *bvhtree_build_from_mvert ( MFace *mfaces, unsigned int numfaces, MVert return tree; } -void bvhtree_update_from_mvert(BVHTree * bvhtree, MFace *faces, int numfaces, MVert *x, MVert *xnew, int UNUSED(numverts), int moving ) +void bvhtree_update_from_mvert(BVHTree *bvhtree, MFace *faces, int numfaces, MVert *x, MVert *xnew, int UNUSED(numverts), int moving ) { int i; MFace *mfaces = faces; @@ -654,7 +654,7 @@ static void cloth_bvh_objcollisions_nearcheck ( ClothModifierData * clmd, Collis { int i; - *collisions = (CollPair *) MEM_mallocN(sizeof(CollPair) * numresult * 64, "collision array" ); //*4 since cloth_collision_static can return more than 1 collision + *collisions = (CollPair *) MEM_mallocN(sizeof(CollPair) * numresult * 64, "collision array" ); // * 4 since cloth_collision_static can return more than 1 collision *collisions_index = *collisions; for ( i = 0; i < numresult; i++ ) { @@ -706,7 +706,7 @@ static int cloth_bvh_objcollisions_resolve ( ClothModifierData * clmd, Collision } // cloth - object collisions -int cloth_bvh_objcollision(Object *ob, ClothModifierData * clmd, float step, float dt ) +int cloth_bvh_objcollision(Object *ob, ClothModifierData *clmd, float step, float dt ) { Cloth *cloth= clmd->clothObject; BVHTree *cloth_bvh= cloth->bvhtree; diff --git a/source/blender/blenkernel/intern/colortools.c b/source/blender/blenkernel/intern/colortools.c index d08c16eac9e..5176f93f4f3 100644 --- a/source/blender/blenkernel/intern/colortools.c +++ b/source/blender/blenkernel/intern/colortools.c @@ -199,7 +199,9 @@ int curvemap_remove_point(CurveMap *cuma, CurveMapPoint *point) cmp[b] = cuma->curve[a]; b++; } - else removed++; + else { + removed++; + } } MEM_freeN(cuma->curve); @@ -221,7 +223,9 @@ void curvemap_remove(CurveMap *cuma, const short flag) cmp[b] = cuma->curve[a]; b++; } - else removed++; + else { + removed++; + } } cmp[b] = cuma->curve[a]; diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c index 48ad3f51389..3430c2ea7a1 100644 --- a/source/blender/blenkernel/intern/constraint.c +++ b/source/blender/blenkernel/intern/constraint.c @@ -817,7 +817,7 @@ static void childof_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *tar static bConstraintTypeInfo CTI_CHILDOF = { CONSTRAINT_TYPE_CHILDOF, /* type */ sizeof(bChildOfConstraint), /* size */ - "ChildOf", /* name */ + "Child Of", /* name */ "bChildOfConstraint", /* struct name */ NULL, /* free data */ childof_id_looper, /* id looper */ @@ -992,7 +992,7 @@ static void trackto_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *tar static bConstraintTypeInfo CTI_TRACKTO = { CONSTRAINT_TYPE_TRACKTO, /* type */ sizeof(bTrackToConstraint), /* size */ - "TrackTo", /* name */ + "Track To", /* name */ "bTrackToConstraint", /* struct name */ NULL, /* free data */ trackto_id_looper, /* id looper */ diff --git a/source/blender/blenkernel/intern/context.c b/source/blender/blenkernel/intern/context.c index a9e3d52f223..d899990a66a 100644 --- a/source/blender/blenkernel/intern/context.c +++ b/source/blender/blenkernel/intern/context.c @@ -27,7 +27,6 @@ * \ingroup bke */ - #include <string.h> #include <stdlib.h> #include <stddef.h> @@ -41,8 +40,6 @@ #include "DNA_windowmanager_types.h" #include "DNA_object_types.h" -#include "RNA_access.h" - #include "BLI_listbase.h" #include "BLI_string.h" #include "BLI_threads.h" @@ -54,8 +51,10 @@ #include "BKE_main.h" #include "BKE_screen.h" +#include "RNA_access.h" + #ifdef WITH_PYTHON -#include "BPY_extern.h" +# include "BPY_extern.h" #endif /* struct */ diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c index 2da75ec64be..5d2c85e5825 100644 --- a/source/blender/blenkernel/intern/curve.c +++ b/source/blender/blenkernel/intern/curve.c @@ -793,7 +793,9 @@ static void makeknots(Nurb *nu, short uv) calcknots(nu->knotsv, nu->pntsv, nu->orderv, nu->flagv); } } - else nu->knotsv = NULL; + else { + nu->knotsv = NULL; + } } } } @@ -3317,76 +3319,76 @@ void BKE_curve_keyVertexTilts_apply(Curve *UNUSED(cu), ListBase *lb, float *key) } } -int BKE_nurb_check_valid_u(struct Nurb *nu) +bool BKE_nurb_check_valid_u(struct Nurb *nu) { if (nu == NULL) - return 0; + return false; if (nu->pntsu <= 1) - return 0; + return false; if (nu->type != CU_NURBS) - return 1; /* not a nurb, lets assume its valid */ + return true; /* not a nurb, lets assume its valid */ - if (nu->pntsu < nu->orderu) return 0; + if (nu->pntsu < nu->orderu) return false; if (((nu->flag & CU_NURB_CYCLIC) == 0) && (nu->flagu & CU_NURB_BEZIER)) { /* Bezier U Endpoints */ if (nu->orderu == 4) { if (nu->pntsu < 5) - return 0; /* bezier with 4 orderu needs 5 points */ + return false; /* bezier with 4 orderu needs 5 points */ } else { if (nu->orderu != 3) - return 0; /* order must be 3 or 4 */ + return false; /* order must be 3 or 4 */ } } - return 1; + return true; } -int BKE_nurb_check_valid_v(struct Nurb *nu) +bool BKE_nurb_check_valid_v(struct Nurb *nu) { if (nu == NULL) - return 0; + return false; if (nu->pntsv <= 1) - return 0; + return false; if (nu->type != CU_NURBS) - return 1; /* not a nurb, lets assume its valid */ + return true; /* not a nurb, lets assume its valid */ if (nu->pntsv < nu->orderv) - return 0; + return false; if (((nu->flag & CU_NURB_CYCLIC) == 0) && (nu->flagv & CU_NURB_BEZIER)) { /* Bezier V Endpoints */ if (nu->orderv == 4) { if (nu->pntsv < 5) - return 0; /* bezier with 4 orderu needs 5 points */ + return false; /* bezier with 4 orderu needs 5 points */ } else { if (nu->orderv != 3) - return 0; /* order must be 3 or 4 */ + return false; /* order must be 3 or 4 */ } } - return 1; + return true; } -int BKE_nurb_order_clamp_u(struct Nurb *nu) +bool BKE_nurb_order_clamp_u(struct Nurb *nu) { - int change = 0; + bool change = false; if (nu->pntsu < nu->orderu) { nu->orderu = nu->pntsu; - change = 1; + change = true; } if (((nu->flagu & CU_NURB_CYCLIC) == 0) && (nu->flagu & CU_NURB_BEZIER)) { CLAMP(nu->orderu, 3, 4); - change = 1; + change = true; } return change; } -int BKE_nurb_order_clamp_v(struct Nurb *nu) +bool BKE_nurb_order_clamp_v(struct Nurb *nu) { - int change = 0; + bool change = false; if (nu->pntsv < nu->orderv) { nu->orderv = nu->pntsv; - change = 1; + change = true; } if (((nu->flagv & CU_NURB_CYCLIC) == 0) && (nu->flagv & CU_NURB_BEZIER)) { CLAMP(nu->orderv, 3, 4); - change = 1; + change = true; } return change; } @@ -3403,7 +3405,7 @@ ListBase *BKE_curve_nurbs_get(Curve *cu) /* basic vertex data functions */ -int BKE_curve_minmax(Curve *cu, float min[3], float max[3]) +bool BKE_curve_minmax(Curve *cu, float min[3], float max[3]) { ListBase *nurb_lb = BKE_curve_nurbs_get(cu); Nurb *nu; @@ -3414,7 +3416,7 @@ int BKE_curve_minmax(Curve *cu, float min[3], float max[3]) return (nurb_lb->first != NULL); } -int BKE_curve_center_median(Curve *cu, float cent[3]) +bool BKE_curve_center_median(Curve *cu, float cent[3]) { ListBase *nurb_lb = BKE_curve_nurbs_get(cu); Nurb *nu; @@ -3452,16 +3454,16 @@ int BKE_curve_center_median(Curve *cu, float cent[3]) return (total != 0); } -int BKE_curve_center_bounds(Curve *cu, float cent[3]) +bool BKE_curve_center_bounds(Curve *cu, float cent[3]) { float min[3], max[3]; INIT_MINMAX(min, max); if (BKE_curve_minmax(cu, min, max)) { mid_v3_v3v3(cent, min, max); - return 1; + return true; } - return 0; + return false; } void BKE_curve_translate(Curve *cu, float offset[3], int do_keys) diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c index 48d7ae1de86..e91fd0cc929 100644 --- a/source/blender/blenkernel/intern/customdata.c +++ b/source/blender/blenkernel/intern/customdata.c @@ -195,7 +195,7 @@ static void layerCopy_bmesh_elem_py_ptr(const void *UNUSED(source), void *dest, } #ifndef WITH_PYTHON -void bpy_bm_generic_invalidate(void *UNUSED(self)) +void bpy_bm_generic_invalidate(struct BPy_BMGeneric *UNUSED(self)) { /* dummy */ } @@ -203,8 +203,6 @@ void bpy_bm_generic_invalidate(void *UNUSED(self)) static void layerFree_bmesh_elem_py_ptr(void *data, int count, int size) { - extern void bpy_bm_generic_invalidate(void *self); - int i; for (i = 0; i < count; ++i) { @@ -1174,7 +1172,7 @@ const CustomDataMask CD_MASK_MESH = CD_MASK_MSTICKY | CD_MASK_MDEFORMVERT | CD_MASK_MTFACE | CD_MASK_MCOL | CD_MASK_PROP_FLT | CD_MASK_PROP_INT | CD_MASK_PROP_STR | CD_MASK_MDISPS | CD_MASK_MLOOPUV | CD_MASK_MLOOPCOL | CD_MASK_MPOLY | CD_MASK_MLOOP | - CD_MASK_MTEXPOLY | CD_MASK_NORMAL | CD_MASK_RECAST | CD_MASK_PAINT_MASK | + CD_MASK_MTEXPOLY | CD_MASK_RECAST | CD_MASK_PAINT_MASK | CD_MASK_GRID_PAINT_MASK | CD_MASK_MVERT_SKIN | CD_MASK_FREESTYLE_EDGE | CD_MASK_FREESTYLE_FACE; const CustomDataMask CD_MASK_EDITMESH = CD_MASK_MSTICKY | CD_MASK_MDEFORMVERT | CD_MASK_MTFACE | CD_MASK_MLOOPUV | @@ -2866,7 +2864,7 @@ static int CustomData_is_property_layer(int type) return 0; } -static int cd_layer_find_dupe(CustomData *data, const char *name, int type, int index) +static bool cd_layer_find_dupe(CustomData *data, const char *name, int type, int index) { int i; /* see if there is a duplicate */ @@ -2876,21 +2874,21 @@ static int cd_layer_find_dupe(CustomData *data, const char *name, int type, int if (CustomData_is_property_layer(type)) { if (CustomData_is_property_layer(layer->type) && strcmp(layer->name, name) == 0) { - return 1; + return true; } } else { if (i != index && layer->type == type && strcmp(layer->name, name) == 0) { - return 1; + return true; } } } } - return 0; + return false; } -static int customdata_unique_check(void *arg, const char *name) +static bool customdata_unique_check(void *arg, const char *name) { struct {CustomData *data; int type; int index; } *data_arg = arg; return cd_layer_find_dupe(data_arg->data, name, data_arg->type, data_arg->index); diff --git a/source/blender/blenkernel/intern/customdata_file.c b/source/blender/blenkernel/intern/customdata_file.c index 78449879f72..c72eea50e40 100644 --- a/source/blender/blenkernel/intern/customdata_file.c +++ b/source/blender/blenkernel/intern/customdata_file.c @@ -29,9 +29,9 @@ #include "MEM_guardedalloc.h" +#include "BLI_utildefines.h" #include "BLI_fileops.h" #include "BLI_string.h" -#include "BLI_utildefines.h" #include "BLI_endian_switch.h" #include "BKE_customdata_file.h" @@ -404,7 +404,7 @@ void cdf_write_close(CDataFile *cdf) void cdf_remove(const char *filename) { - BLI_delete(filename, 0, 0); + BLI_delete(filename, false, false); } /********************************** Layers ***********************************/ diff --git a/source/blender/blenkernel/intern/deform.c b/source/blender/blenkernel/intern/deform.c index 439180e8d76..2ba71ecd9b5 100644 --- a/source/blender/blenkernel/intern/deform.c +++ b/source/blender/blenkernel/intern/deform.c @@ -432,22 +432,22 @@ int defgroup_flip_index(Object *ob, int index, int use_default) return (flip_index == -1 && use_default) ? index : flip_index; } -static int defgroup_find_name_dupe(const char *name, bDeformGroup *dg, Object *ob) +static bool defgroup_find_name_dupe(const char *name, bDeformGroup *dg, Object *ob) { bDeformGroup *curdef; for (curdef = ob->defbase.first; curdef; curdef = curdef->next) { if (dg != curdef) { if (!strcmp(curdef->name, name)) { - return 1; + return true; } } } - return 0; + return false; } -static int defgroup_unique_check(void *arg, const char *name) +static bool defgroup_unique_check(void *arg, const char *name) { struct {Object *ob; void *dg; } *data = arg; return defgroup_find_name_dupe(name, data->dg, data->ob); diff --git a/source/blender/blenkernel/intern/depsgraph.c b/source/blender/blenkernel/intern/depsgraph.c index b919b9ffd8f..3a531cf32ae 100644 --- a/source/blender/blenkernel/intern/depsgraph.c +++ b/source/blender/blenkernel/intern/depsgraph.c @@ -1555,7 +1555,9 @@ static unsigned int flush_layer_node(Scene *sce, DagNode *node, int curtime) if (itA->node->lasttime != curtime) { itA->lay = flush_layer_node(sce, itA->node, curtime); /* lay is only set once for each relation */ } - else itA->lay = itA->node->lay; + else { + itA->lay = itA->node->lay; + } node->lay |= itA->lay; } diff --git a/source/blender/blenkernel/intern/dynamicpaint.c b/source/blender/blenkernel/intern/dynamicpaint.c index 685d66195c7..4b05f1c1050 100644 --- a/source/blender/blenkernel/intern/dynamicpaint.c +++ b/source/blender/blenkernel/intern/dynamicpaint.c @@ -340,7 +340,7 @@ int dynamicPaint_outputLayerExists(struct DynamicPaintSurface *surface, Object * return 0; } -static int surface_duplicateOutputExists(void *arg, const char *name) +static bool surface_duplicateOutputExists(void *arg, const char *name) { DynamicPaintSurface *t_surface = (DynamicPaintSurface *)arg; DynamicPaintSurface *surface = t_surface->canvas->surfaces.first; @@ -349,11 +349,11 @@ static int surface_duplicateOutputExists(void *arg, const char *name) if (surface != t_surface && surface->type == t_surface->type && surface->format == t_surface->format) { - if (surface->output_name[0] != '\0' && !BLI_path_cmp(name, surface->output_name)) return 1; - if (surface->output_name2[0] != '\0' && !BLI_path_cmp(name, surface->output_name2)) return 1; + if (surface->output_name[0] != '\0' && !BLI_path_cmp(name, surface->output_name)) return true; + if (surface->output_name2[0] != '\0' && !BLI_path_cmp(name, surface->output_name2)) return true; } } - return 0; + return false; } static void surface_setUniqueOutputName(DynamicPaintSurface *surface, char *basename, int output) @@ -367,15 +367,15 @@ static void surface_setUniqueOutputName(DynamicPaintSurface *surface, char *base } -static int surface_duplicateNameExists(void *arg, const char *name) +static bool surface_duplicateNameExists(void *arg, const char *name) { DynamicPaintSurface *t_surface = (DynamicPaintSurface *)arg; DynamicPaintSurface *surface = t_surface->canvas->surfaces.first; for (; surface; surface = surface->next) { - if (surface != t_surface && !strcmp(name, surface->name)) return 1; + if (surface != t_surface && !strcmp(name, surface->name)) return true; } - return 0; + return false; } void dynamicPaintSurface_setUniqueName(DynamicPaintSurface *surface, const char *basename) @@ -473,7 +473,9 @@ static float mixColors(float a_color[3], float a_weight, float b_color[3], float } weight_ratio = b_weight / (a_weight + b_weight); } - else return a_weight * (1.0f - ratio); + else { + return a_weight * (1.0f - ratio); + } /* calculate final interpolation factor */ if (ratio <= 0.5f) { @@ -2606,7 +2608,9 @@ int dynamicPaint_createUVSurface(DynamicPaintSurface *surface) if (!f_data->uv_p || !f_data->barycentricWeights) error = 1; } - else error = 1; + else { + error = 1; + } sData->total_points = active_points; @@ -2859,7 +2863,9 @@ static void dynamicPaint_doMaterialTex(BrushMaterials *bMats, float color[3], fl mat = bMats->ob_mats[mat_nr]; if (mat == NULL) return; /* No material assigned */ } - else return; + else { + return; + } } RE_sample_material_color(mat, color, alpha, volume_co, surface_co, faceIndex, isQuad, orcoDm, brushOb); @@ -3924,7 +3930,9 @@ static int dynamicPaint_paintSinglePoint(DynamicPaintSurface *surface, float *po strength = 1.0f - distance / brush_radius; CLAMP(strength, 0.0f, 1.0f); } - else strength = 1.0f; + else { + strength = 1.0f; + } if (strength >= 0.001f) { float paintColor[3] = {0.0f}; diff --git a/source/blender/blenkernel/intern/font.c b/source/blender/blenkernel/intern/font.c index 3e1e55132d8..b3edeb67928 100644 --- a/source/blender/blenkernel/intern/font.c +++ b/source/blender/blenkernel/intern/font.c @@ -101,9 +101,9 @@ void BKE_vfont_free(struct VFont *vf) static void *builtin_font_data = NULL; static int builtin_font_size = 0; -int BKE_vfont_is_builtin(struct VFont *vfont) +bool BKE_vfont_is_builtin(struct VFont *vfont) { - return (strcmp(vfont->name, FO_BUILTIN_NAME) == 0); + return STREQ(vfont->name, FO_BUILTIN_NAME); } void BKE_vfont_builtin_register(void *mem, int size) @@ -188,18 +188,14 @@ VFont *BKE_vfont_load(Main *bmain, const char *name) PackedFile *temp_pf = NULL; int is_builtin; - if (strcmp(name, FO_BUILTIN_NAME) == 0) { + if (STREQ(name, FO_BUILTIN_NAME)) { BLI_strncpy(filename, name, sizeof(filename)); pf = get_builtin_packedfile(); is_builtin = TRUE; } else { - char dir[FILE_MAXDIR]; - - BLI_strncpy(dir, name, sizeof(dir)); - BLI_splitdirstring(dir, filename); - + BLI_split_file_part(name, filename, sizeof(filename)); pf = newPackedFile(NULL, name, bmain->name); temp_pf = newPackedFile(NULL, name, bmain->name); @@ -947,10 +943,13 @@ makebreak: ct = chartransdata; for (i = 0; i < slen; i++) { if (ct->linenr == lnr) { - if (ct->charnr == cnr) break; - if ( (ct + 1)->charnr == 0) break; + if ((ct->charnr == cnr) || ((ct + 1)->charnr == 0)) { + break; + } + } + else if (ct->linenr > lnr) { + break; } - else if (ct->linenr > lnr) break; cu->pos++; ct++; } diff --git a/source/blender/blenkernel/intern/idcode.c b/source/blender/blenkernel/intern/idcode.c index 8fab0f2d4df..11d3e69120d 100644 --- a/source/blender/blenkernel/intern/idcode.c +++ b/source/blender/blenkernel/intern/idcode.c @@ -30,12 +30,13 @@ * \ingroup bke */ - #include <stdlib.h> #include <string.h> #include "DNA_ID.h" +#include "BLI_utildefines.h" + #include "BKE_idcode.h" typedef struct { @@ -91,9 +92,11 @@ static IDType *idtype_from_name(const char *str) { int i = nidtypes; - while (i--) - if (strcmp(str, idtypes[i].name) == 0) + while (i--) { + if (STREQ(str, idtypes[i].name)) { return &idtypes[i]; + } + } return NULL; } @@ -108,15 +111,15 @@ static IDType *idtype_from_code(int code) return NULL; } -int BKE_idcode_is_valid(int code) +bool BKE_idcode_is_valid(int code) { - return idtype_from_code(code) ? 1 : 0; + return idtype_from_code(code) ? true : false; } -int BKE_idcode_is_linkable(int code) +bool BKE_idcode_is_linkable(int code) { IDType *idt = idtype_from_code(code); - return idt ? (idt->flags & IDTYPE_FLAGS_ISLINKABLE) : 0; + return idt ? ((idt->flags & IDTYPE_FLAGS_ISLINKABLE) != 0) : false; } const char *BKE_idcode_to_name(int code) diff --git a/source/blender/blenkernel/intern/idprop.c b/source/blender/blenkernel/intern/idprop.c index 19ef1e3971d..8dc284e0a3e 100644 --- a/source/blender/blenkernel/intern/idprop.c +++ b/source/blender/blenkernel/intern/idprop.c @@ -451,7 +451,7 @@ void IDP_ReplaceGroupInGroup(IDProperty *dest, IDProperty *src) IDProperty *loop, *prop; for (prop = src->data.group.first; prop; prop = prop->next) { for (loop = dest->data.group.first; loop; loop = loop->next) { - if (strcmp(loop->name, prop->name) == 0) { + if (STREQ(loop->name, prop->name)) { IDProperty *copy = IDP_CopyProperty(prop); BLI_insertlinkafter(&dest->data.group, loop, copy); diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c index 3655afdf088..c27f5e62520 100644 --- a/source/blender/blenkernel/intern/image.c +++ b/source/blender/blenkernel/intern/image.c @@ -1042,7 +1042,7 @@ char BKE_ftype_to_imtype(const int ftype) } -int BKE_imtype_is_movie(const char imtype) +bool BKE_imtype_is_movie(const char imtype) { switch (imtype) { case R_IMF_IMTYPE_AVIRAW: @@ -1053,9 +1053,9 @@ int BKE_imtype_is_movie(const char imtype) case R_IMF_IMTYPE_THEORA: case R_IMF_IMTYPE_XVID: case R_IMF_IMTYPE_FRAMESERVER: - return 1; + return true; } - return 0; + return false; } int BKE_imtype_supports_zbuf(const char imtype) @@ -1567,7 +1567,9 @@ static void stampdata(Scene *scene, Object *camera, StampData *stamp_data, int d if (camera && camera->type == OB_CAMERA) { BLI_snprintf(text, sizeof(text), "%.2f", ((Camera *)camera->data)->lens); } - else BLI_strncpy(text, "<none>", sizeof(text)); + else { + BLI_strncpy(text, "<none>", sizeof(text)); + } BLI_snprintf(stamp_data->cameralens, sizeof(stamp_data->cameralens), do_prefix ? "Lens %s" : "%s", text); } @@ -1944,7 +1946,7 @@ int BKE_imbuf_write(ImBuf *ibuf, const char *name, ImageFormatData *imf) else if (imtype == R_IMF_IMTYPE_DPX) { ibuf->ftype = DPX; if (imf->cineon_flag & R_IMF_CINEON_FLAG_LOG) { - ibuf->ftype |= CINEON_LOG; + ibuf->ftype |= CINEON_LOG; } if (imf->depth == R_IMF_CHAN_DEPTH_16) { ibuf->ftype |= CINEON_16BIT; diff --git a/source/blender/blenkernel/intern/image_gen.c b/source/blender/blenkernel/intern/image_gen.c index 468a88775c6..415f0a87431 100644 --- a/source/blender/blenkernel/intern/image_gen.c +++ b/source/blender/blenkernel/intern/image_gen.c @@ -24,13 +24,14 @@ * \ingroup bke */ - #include <math.h> #include <stdlib.h> -#include "BKE_image.h" #include "BLI_math_color.h" #include "BLI_math_base.h" + +#include "BKE_image.h" + #include "BLF_api.h" void BKE_image_buf_fill_color(unsigned char *rect, float *rect_float, int width, int height, const float color[4]) diff --git a/source/blender/blenkernel/intern/implicit.c b/source/blender/blenkernel/intern/implicit.c index 90cd7bc2df5..b9064fe8ba3 100644 --- a/source/blender/blenkernel/intern/implicit.c +++ b/source/blender/blenkernel/intern/implicit.c @@ -1716,7 +1716,7 @@ static void simulate_implicit_euler(lfVector *Vnew, lfVector *UNUSED(lX), lfVect * (edge distance constraints) in a lagrangian solver. then add forces to help * guide the implicit solver to that state. this function is called after * collisions*/ -static int UNUSED_FUNCTION(cloth_calc_helper_forces)(Object *UNUSED(ob), ClothModifierData * clmd, float (*initial_cos)[3], float UNUSED(step), float dt) +static int UNUSED_FUNCTION(cloth_calc_helper_forces)(Object *UNUSED(ob), ClothModifierData *clmd, float (*initial_cos)[3], float UNUSED(step), float dt) { Cloth *cloth= clmd->clothObject; float (*cos)[3] = MEM_callocN(sizeof(float)*3*cloth->numverts, "cos cloth_calc_helper_forces"); diff --git a/source/blender/blenkernel/intern/key.c b/source/blender/blenkernel/intern/key.c index f3dc391738e..d123de224e9 100644 --- a/source/blender/blenkernel/intern/key.c +++ b/source/blender/blenkernel/intern/key.c @@ -405,9 +405,13 @@ static int setkeys(float fac, ListBase *lb, KeyBlock *k[], float t[4], int cycl) k1 = firstkey; ofs += dpos; } - else if (t[2] == t[3]) break; + else if (t[2] == t[3]) { + break; + } + } + else { + k1 = k1->next; } - else k1 = k1->next; t[0] = t[1]; k[0] = k[1]; @@ -595,7 +599,9 @@ static void cp_key(const int start, int end, const int tot, char *poin, Key *key k1 += a * key->elemsize; } } - else k1 += start * key->elemsize; + else { + k1 += start * key->elemsize; + } } if (mode == KEY_MODE_BEZTRIPLE) { @@ -828,7 +834,9 @@ static void do_key(const int start, int end, const int tot, char *poin, Key *key if (k[0]->totelem) { k1d = k[0]->totelem / (float)tot; } - else flagdo -= 1; + else { + flagdo -= 1; + } } if (tot != k[1]->totelem) { k2tot = 0.0; @@ -836,7 +844,9 @@ static void do_key(const int start, int end, const int tot, char *poin, Key *key if (k[0]->totelem) { k2d = k[1]->totelem / (float)tot; } - else flagdo -= 2; + else { + flagdo -= 2; + } } if (tot != k[2]->totelem) { k3tot = 0.0; @@ -844,7 +854,9 @@ static void do_key(const int start, int end, const int tot, char *poin, Key *key if (k[0]->totelem) { k3d = k[2]->totelem / (float)tot; } - else flagdo -= 4; + else { + flagdo -= 4; + } } if (tot != k[3]->totelem) { k4tot = 0.0; @@ -852,7 +864,9 @@ static void do_key(const int start, int end, const int tot, char *poin, Key *key if (k[0]->totelem) { k4d = k[3]->totelem / (float)tot; } - else flagdo -= 8; + else { + flagdo -= 8; + } } /* this exception needed for slurphing */ @@ -869,7 +883,9 @@ static void do_key(const int start, int end, const int tot, char *poin, Key *key k1 += a * key->elemsize; } } - else k1 += start * key->elemsize; + else { + k1 += start * key->elemsize; + } } if (flagdo & 2) { if (flagflo & 2) { @@ -880,7 +896,9 @@ static void do_key(const int start, int end, const int tot, char *poin, Key *key k2 += a * key->elemsize; } } - else k2 += start * key->elemsize; + else { + k2 += start * key->elemsize; + } } if (flagdo & 4) { if (flagflo & 4) { @@ -891,7 +909,9 @@ static void do_key(const int start, int end, const int tot, char *poin, Key *key k3 += a * key->elemsize; } } - else k3 += start * key->elemsize; + else { + k3 += start * key->elemsize; + } } if (flagdo & 8) { if (flagflo & 8) { @@ -902,7 +922,9 @@ static void do_key(const int start, int end, const int tot, char *poin, Key *key k4 += a * key->elemsize; } } - else k4 += start * key->elemsize; + else { + k4 += start * key->elemsize; + } } } @@ -968,7 +990,9 @@ static void do_key(const int start, int end, const int tot, char *poin, Key *key k2 += elemsize; } } - else k2 += elemsize; + else { + k2 += elemsize; + } } if (flagdo & 4) { if (flagflo & 4) { @@ -978,7 +1002,9 @@ static void do_key(const int start, int end, const int tot, char *poin, Key *key k3 += elemsize; } } - else k3 += elemsize; + else { + k3 += elemsize; + } } if (flagdo & 8) { if (flagflo & 8) { @@ -988,7 +1014,9 @@ static void do_key(const int start, int end, const int tot, char *poin, Key *key k4 += elemsize; } } - else k4 += elemsize; + else { + k4 += elemsize; + } } if (mode == KEY_MODE_BEZTRIPLE) a += 2; diff --git a/source/blender/blenkernel/intern/lattice.c b/source/blender/blenkernel/intern/lattice.c index c3e7a963c04..c881209b109 100644 --- a/source/blender/blenkernel/intern/lattice.c +++ b/source/blender/blenkernel/intern/lattice.c @@ -404,9 +404,11 @@ void calc_latt_deform(Object *ob, float co[3], float weight) if (w != 0.0f) { if (ww > 0) { if (ww < lt->pntsw) idx_w = ww * lt->pntsu * lt->pntsv; - else idx_w = (lt->pntsw - 1) * lt->pntsu * lt->pntsv; + else idx_w = (lt->pntsw - 1) * lt->pntsu * lt->pntsv; + } + else { + idx_w = 0; } - else idx_w = 0; for (vv = vi - 1; vv <= vi + 2; vv++) { v = w * tv[vv - vi + 1]; @@ -414,9 +416,11 @@ void calc_latt_deform(Object *ob, float co[3], float weight) if (v != 0.0f) { if (vv > 0) { if (vv < lt->pntsv) idx_v = idx_w + vv * lt->pntsu; - else idx_v = idx_w + (lt->pntsv - 1) * lt->pntsu; + else idx_v = idx_w + (lt->pntsv - 1) * lt->pntsu; + } + else { + idx_v = idx_w; } - else idx_v = idx_w; for (uu = ui - 1; uu <= ui + 2; uu++) { u = weight * v * tu[uu - ui + 1]; @@ -424,9 +428,11 @@ void calc_latt_deform(Object *ob, float co[3], float weight) if (u != 0.0f) { if (uu > 0) { if (uu < lt->pntsu) idx_u = idx_v + uu; - else idx_u = idx_v + (lt->pntsu - 1); + else idx_u = idx_v + (lt->pntsu - 1); + } + else { + idx_u = idx_v; } - else idx_u = idx_v; madd_v3_v3fl(co, <->latticedata[idx_u * 3], u); @@ -492,7 +498,9 @@ static int where_on_path_deform(Object *ob, float ctime, float vec[4], float dir if (cycl == 0) { ctime1 = CLAMPIS(ctime, 0.0f, 1.0f); } - else ctime1 = ctime; + else { + ctime1 = ctime; + } /* vec needs 4 items */ if (where_on_path(ob, ctime1, vec, dir, quat, radius, NULL)) { diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c index b4c1d681ddc..67fc5bd5dca 100644 --- a/source/blender/blenkernel/intern/library.c +++ b/source/blender/blenkernel/intern/library.c @@ -174,6 +174,7 @@ void id_us_plus(ID *id) } } +/* decrements the user count for *id. */ void id_us_min(ID *id) { if (id) { @@ -189,106 +190,112 @@ void id_us_min(ID *id) } } -int id_make_local(ID *id, int test) +/* calls the appropriate make_local method for the block, unless test. Returns true + * if the block can be made local. */ +bool id_make_local(ID *id, bool test) { if (id->flag & LIB_INDIRECT) - return 0; + return false; switch (GS(id->name)) { case ID_SCE: - return 0; /* not implemented */ + return false; /* not implemented */ case ID_LI: - return 0; /* can't be linked */ + return false; /* can't be linked */ case ID_OB: if (!test) BKE_object_make_local((Object *)id); - return 1; + return true; case ID_ME: if (!test) { BKE_mesh_make_local((Mesh *)id); BKE_key_make_local(((Mesh *)id)->key); } - return 1; + return true; case ID_CU: if (!test) { BKE_curve_make_local((Curve *)id); BKE_key_make_local(((Curve *)id)->key); } - return 1; + return true; case ID_MB: if (!test) BKE_mball_make_local((MetaBall *)id); - return 1; + return true; case ID_MA: if (!test) BKE_material_make_local((Material *)id); - return 1; + return true; case ID_TE: if (!test) BKE_texture_make_local((Tex *)id); - return 1; + return true; case ID_IM: if (!test) BKE_image_make_local((Image *)id); - return 1; + return true; case ID_LT: if (!test) { BKE_lattice_make_local((Lattice *)id); BKE_key_make_local(((Lattice *)id)->key); } - return 1; + return true; case ID_LA: if (!test) BKE_lamp_make_local((Lamp *)id); - return 1; + return true; case ID_CA: if (!test) BKE_camera_make_local((Camera *)id); - return 1; + return true; case ID_SPK: if (!test) BKE_speaker_make_local((Speaker *)id); - return 1; + return true; case ID_IP: - return 0; /* deprecated */ + return false; /* deprecated */ case ID_KE: if (!test) BKE_key_make_local((Key *)id); - return 1; + return true; case ID_WO: if (!test) BKE_world_make_local((World *)id); - return 1; + return true; case ID_SCR: - return 0; /* can't be linked */ + return false; /* can't be linked */ case ID_VF: - return 0; /* not implemented */ + return false; /* not implemented */ case ID_TXT: - return 0; /* not implemented */ + return false; /* not implemented */ case ID_SCRIPT: - return 0; /* deprecated */ + return false; /* deprecated */ case ID_SO: - return 0; /* not implemented */ + return false; /* not implemented */ case ID_GR: - return 0; /* not implemented */ + return false; /* not implemented */ case ID_AR: if (!test) BKE_armature_make_local((bArmature *)id); - return 1; + return true; case ID_AC: if (!test) BKE_action_make_local((bAction *)id); - return 1; + return true; case ID_NT: - return 0; /* not implemented */ + return false; /* not implemented */ case ID_BR: if (!test) BKE_brush_make_local((Brush *)id); - return 1; + return true; case ID_PA: if (!test) BKE_particlesettings_make_local((ParticleSettings *)id); - return 1; + return true; case ID_WM: - return 0; /* can't be linked */ + return false; /* can't be linked */ case ID_GD: - return 0; /* not implemented */ + return false; /* not implemented */ #ifdef WITH_FREESTYLE case ID_LS: return 0; /* not implemented */ #endif } - return 0; + return false; } -int id_copy(ID *id, ID **newid, int test) +/** + * Invokes the appropriate copy method for the block and returns the result in + * newid, unless test. Returns true iff the block can be copied. + */ +bool id_copy(ID *id, ID **newid, bool test) { if (!test) *newid = NULL; @@ -297,86 +304,86 @@ int id_copy(ID *id, ID **newid, int test) * - id.us of the new ID is set to 1 */ switch (GS(id->name)) { case ID_SCE: - return 0; /* can't be copied from here */ + return false; /* can't be copied from here */ case ID_LI: - return 0; /* can't be copied from here */ + return false; /* can't be copied from here */ case ID_OB: if (!test) *newid = (ID *)BKE_object_copy((Object *)id); - return 1; + return true; case ID_ME: if (!test) *newid = (ID *)BKE_mesh_copy((Mesh *)id); - return 1; + return true; case ID_CU: if (!test) *newid = (ID *)BKE_curve_copy((Curve *)id); - return 1; + return true; case ID_MB: if (!test) *newid = (ID *)BKE_mball_copy((MetaBall *)id); - return 1; + return true; case ID_MA: if (!test) *newid = (ID *)BKE_material_copy((Material *)id); - return 1; + return true; case ID_TE: if (!test) *newid = (ID *)BKE_texture_copy((Tex *)id); - return 1; + return true; case ID_IM: if (!test) *newid = (ID *)BKE_image_copy(G.main, (Image *)id); - return 1; + return true; case ID_LT: if (!test) *newid = (ID *)BKE_lattice_copy((Lattice *)id); - return 1; + return true; case ID_LA: if (!test) *newid = (ID *)BKE_lamp_copy((Lamp *)id); - return 1; + return true; case ID_SPK: if (!test) *newid = (ID *)BKE_speaker_copy((Speaker *)id); - return 1; + return true; case ID_CA: if (!test) *newid = (ID *)BKE_camera_copy((Camera *)id); - return 1; + return true; case ID_IP: - return 0; /* deprecated */ + return false; /* deprecated */ case ID_KE: if (!test) *newid = (ID *)BKE_key_copy((Key *)id); - return 1; + return true; case ID_WO: if (!test) *newid = (ID *)BKE_world_copy((World *)id); - return 1; + return true; case ID_SCR: - return 0; /* can't be copied from here */ + return false; /* can't be copied from here */ case ID_VF: - return 0; /* not implemented */ + return false; /* not implemented */ case ID_TXT: if (!test) *newid = (ID *)BKE_text_copy((Text *)id); - return 1; + return true; case ID_SCRIPT: - return 0; /* deprecated */ + return false; /* deprecated */ case ID_SO: - return 0; /* not implemented */ + return false; /* not implemented */ case ID_GR: if (!test) *newid = (ID *)BKE_group_copy((Group *)id); - return 1; + return true; case ID_AR: if (!test) *newid = (ID *)BKE_armature_copy((bArmature *)id); - return 1; + return true; case ID_AC: if (!test) *newid = (ID *)BKE_action_copy((bAction *)id); - return 1; + return true; case ID_NT: if (!test) *newid = (ID *)ntreeCopyTree((bNodeTree *)id); - return 1; + return true; case ID_BR: if (!test) *newid = (ID *)BKE_brush_copy((Brush *)id); - return 1; + return true; case ID_PA: if (!test) *newid = (ID *)BKE_particlesettings_copy((ParticleSettings *)id); - return 1; + return true; case ID_WM: - return 0; /* can't be copied from here */ + return false; /* can't be copied from here */ case ID_GD: - return 0; /* not implemented */ + return false; /* not implemented */ case ID_MSK: if (!test) *newid = (ID *)BKE_mask_copy((Mask *)id); - return 1; + return true; #ifdef WITH_FREESTYLE case ID_LS: if(!test) *newid= (ID*)FRS_copy_linestyle((FreestyleLineStyle*)id); @@ -384,42 +391,42 @@ int id_copy(ID *id, ID **newid, int test) #endif } - return 0; + return false; } -int id_unlink(ID *id, int test) +bool id_unlink(ID *id, int test) { Main *mainlib = G.main; ListBase *lb; switch (GS(id->name)) { case ID_TXT: - if (test) return 1; + if (test) return true; BKE_text_unlink(mainlib, (Text *)id); break; case ID_GR: - if (test) return 1; + if (test) return true; BKE_group_unlink((Group *)id); break; case ID_OB: - if (test) return 1; + if (test) return true; BKE_object_unlink((Object *)id); break; } if (id->us == 0) { - if (test) return 1; + if (test) return true; lb = which_libbase(mainlib, GS(id->name)); BKE_libblock_free(lb, id); - return 1; + return true; } - return 0; + return false; } -int id_single_user(bContext *C, ID *id, PointerRNA *ptr, PropertyRNA *prop) +bool id_single_user(bContext *C, ID *id, PointerRNA *ptr, PropertyRNA *prop) { ID *newid = NULL; PointerRNA idptr; @@ -427,7 +434,7 @@ int id_single_user(bContext *C, ID *id, PointerRNA *ptr, PropertyRNA *prop) if (id) { /* if property isn't editable, we're going to have an extra block hanging around until we save */ if (RNA_property_editable(ptr, prop)) { - if (id_copy(id, &newid, 0) && newid) { + if (id_copy(id, &newid, false) && newid) { /* copy animation actions too */ BKE_copy_animdata_id_action(id); /* us is 1 by convention, but RNA_property_pointer_set @@ -439,12 +446,12 @@ int id_single_user(bContext *C, ID *id, PointerRNA *ptr, PropertyRNA *prop) RNA_property_pointer_set(ptr, prop, idptr); RNA_property_update(C, ptr, prop); - return 1; + return true; } } } - return 0; + return false; } ListBase *which_libbase(Main *mainlib, short type) @@ -552,7 +559,13 @@ void recalc_all_library_objects(Main *main) ob->recalc |= OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME; } -/* note: MAX_LIBARRAY define should match this code */ +/** + * puts into array *lb pointers to all the ListBase structs in main, + * and returns the number of them as the function result. This is useful for + * generic traversal of all the blocks in a Main (by traversing all the + * lists in turn), without worrying about block types. + * + * \note MAX_LIBARRAY define should match this code */ int set_listbasepointers(Main *main, ListBase **lb) { int a = 0; @@ -619,6 +632,10 @@ int set_listbasepointers(Main *main, ListBase **lb) * * **************************** */ +/** + * Allocates and returns memory of the right size for the specified block type, + * initialized to zero. + */ static ID *alloc_libblock_notest(short type) { ID *id = NULL; @@ -726,7 +743,12 @@ static ID *alloc_libblock_notest(short type) return id; } -/* used everywhere in blenkernel and text.c */ +/** + * Allocates and returns a block of the specified type, with the specified name + * (adjusted as necessary to ensure uniqueness), and appended to the specified list. + * The user count is set to 1, all other content (apart from name and links) being + * initialized to zero. + */ void *BKE_libblock_alloc(ListBase *lb, short type, const char *name) { ID *id = NULL; @@ -738,25 +760,25 @@ void *BKE_libblock_alloc(ListBase *lb, short type, const char *name) id->icon_id = 0; *( (short *)id->name) = type; new_id(lb, id, name); - /* alphabetic insterion: is in new_id */ + /* alphabetic insertion: is in new_id */ } return id; } /* by spec, animdata is first item after ID */ /* and, trust that BKE_animdata_from_id() will only find AnimData for valid ID-types */ -static void id_copy_animdata(ID *id, const short do_action) +static void id_copy_animdata(ID *id, const bool do_action) { AnimData *adt = BKE_animdata_from_id(id); if (adt) { IdAdtTemplate *iat = (IdAdtTemplate *)id; - iat->adt = BKE_copy_animdata(iat->adt, do_action); /* could be set to FALSE, need to investigate */ + iat->adt = BKE_copy_animdata(iat->adt, do_action); /* could be set to false, need to investigate */ } } /* material nodes use this since they are not treated as libdata */ -void BKE_libblock_copy_data(ID *id, const ID *id_from, const short do_action) +void BKE_libblock_copy_data(ID *id, const ID *id_from, const bool do_action) { if (id_from->properties) id->properties = IDP_CopyProperty(id_from->properties); @@ -788,7 +810,7 @@ void *BKE_libblock_copy_ex(Main *bmain, ID *id) id->newid = idn; idn->flag |= LIB_NEW; - BKE_libblock_copy_data(idn, id, FALSE); + BKE_libblock_copy_data(idn, id, false); return idn; } @@ -1207,7 +1229,7 @@ void id_sort_by_name(ListBase *lb, ID *id) } -/* +/** * Check to see if there is an ID with the same name as 'name'. * Returns the ID if so, if not, returns NULL */ @@ -1229,9 +1251,9 @@ static ID *is_dupid(ListBase *lb, ID *id, const char *name) return idtest; } -/* +/** * Check to see if an ID name is already used, and find a new one if so. - * Return 1 if created a new name (returned in name). + * Return true if created a new name (returned in name). * * Normally the ID that's being check is already in the ListBase, so ID *id * points at the new entry. The Python Library module needs to know what @@ -1239,11 +1261,13 @@ static ID *is_dupid(ListBase *lb, ID *id, const char *name) * id is NULL */ -static int check_for_dupid(ListBase *lb, ID *id, char *name) +static bool check_for_dupid(ListBase *lb, ID *id, char *name) { ID *idtest; int nr = 0, nrtest, a, left_len; - char in_use[64]; /* use as a boolean array, unrelated to name length */ +#define MAX_IN_USE 64 + bool in_use[MAX_IN_USE]; + /* to speed up finding unused numbers within [1 .. MAX_IN_USE - 1] */ char left[MAX_ID_NAME + 8], leftest[MAX_ID_NAME + 8]; @@ -1251,23 +1275,23 @@ static int check_for_dupid(ListBase *lb, ID *id, char *name) /* if ( strlen(name) > MAX_ID_NAME-3 ) name[MAX_ID_NAME-3] = 0; */ /* removed since this is only ever called from one place - campbell */ - while (1) { + while (true) { /* phase 1: id already exists? */ idtest = is_dupid(lb, id, name); /* if there is no double, done */ - if (idtest == NULL) return 0; + if (idtest == NULL) return false; /* we have a dup; need to make a new name */ - /* quick check so we can reuse one of first 64 ids if vacant */ - memset(in_use, 0, sizeof(in_use)); + /* quick check so we can reuse one of first MAX_IN_USE - 1 ids if vacant */ + memset(in_use, false, sizeof(in_use)); /* get name portion, number portion ("name.number") */ left_len = BLI_split_name_num(left, &nr, name, '.'); /* if new name will be too long, truncate it */ - if (nr > 999 && left_len > (MAX_ID_NAME - 8)) { + if (nr > 999 && left_len > (MAX_ID_NAME - 8)) { /* assumption: won't go beyond 9999 */ left[MAX_ID_NAME - 8] = 0; left_len = MAX_ID_NAME - 8; } @@ -1284,35 +1308,50 @@ static int check_for_dupid(ListBase *lb, ID *id, char *name) (BLI_split_name_num(leftest, &nrtest, idtest->name + 2, '.') == left_len) ) { - if (nrtest < sizeof(in_use)) - in_use[nrtest] = 1; /* mark as used */ + /* will get here at least once, otherwise is_dupid call above would have returned NULL */ + if (nrtest < MAX_IN_USE) + in_use[nrtest] = true; /* mark as used */ if (nr <= nrtest) nr = nrtest + 1; /* track largest unused */ } } + /* At this point, nr will be at least 1. */ + BLI_assert(nr >= 1); /* decide which value of nr to use */ - for (a = 0; a < sizeof(in_use); a++) { - if (a >= nr) break; /* stop when we've check up to biggest */ - if (in_use[a] == 0) { /* found an unused value */ + for (a = 0; a < MAX_IN_USE; a++) { + if (a >= nr) break; /* stop when we've checked up to biggest */ /* redundant check */ + if (!in_use[a]) { /* found an unused value */ nr = a; + /* can only be zero if all potential duplicate names had + * nonzero numeric suffixes, which means name itself has + * nonzero numeric suffix (else no name conflict and wouldn't + * have got here), which means name[left_len] is not a null */ break; } } + /* At this point, nr is either the lowest unused number within [0 .. MAX_IN_USE - 1], + * or 1 greater than the largest used number if all those low ones are taken. + * We can't be bothered to look for the lowest unused number beyond (MAX_IN_USE - 1). */ /* If the original name has no numeric suffix, * rather than just chopping and adding numbers, * shave off the end chars until we have a unique name. * Check the null terminators match as well so we don't get Cube.000 -> Cube.00 */ if (nr == 0 && name[left_len] == '\0') { - int len = left_len - 1; + int len; + /* FIXME: this code will never be executed, because either nr will be + * at least 1, or name will not end at left_len! */ + BLI_assert(0); + + len = left_len - 1; idtest = is_dupid(lb, id, name); while (idtest && len > 1) { name[len--] = '\0'; idtest = is_dupid(lb, id, name); } - if (idtest == NULL) return 1; + if (idtest == NULL) return true; /* otherwise just continue and use a number suffix */ } @@ -1326,24 +1365,26 @@ static int check_for_dupid(ListBase *lb, ID *id, char *name) /* this format specifier is from hell... */ BLI_snprintf(name, sizeof(id->name) - 2, "%s.%.3d", left, nr); - return 1; + return true; } + +#undef MAX_IN_USE } /* * Only for local blocks: external en indirect blocks already have a * unique ID. * - * return 1: created a new name + * return true: created a new name */ -int new_id(ListBase *lb, ID *id, const char *tname) +bool new_id(ListBase *lb, ID *id, const char *tname) { - int result; + bool result; char name[MAX_ID_NAME - 2]; /* if library, don't rename */ - if (id->lib) return 0; + if (id->lib) return false; /* if no libdata given, look up based on ID */ if (lb == NULL) lb = which_libbase(G.main, GS(id->name)); @@ -1415,10 +1456,9 @@ void clear_id_newpoins(void) } } -#define LIBTAG(a) if (a && a->id.lib) { a->id.flag &= ~LIB_INDIRECT; a->id.flag |= LIB_EXTERN; } (void)0 - static void lib_indirect_test_id(ID *id, Library *lib) { +#define LIBTAG(a) if (a && a->id.lib) { a->id.flag &= ~LIB_INDIRECT; a->id.flag |= LIB_EXTERN; } (void)0 if (id->lib) { /* datablocks that were indirectly related are now direct links @@ -1458,6 +1498,8 @@ static void lib_indirect_test_id(ID *id, Library *lib) me = ob->data; LIBTAG(me); } + +#undef LIBTAG } void tag_main_lb(ListBase *lb, const short tag) @@ -1495,9 +1537,9 @@ void tag_main(struct Main *mainvar, const short tag) /* if lib!=NULL, only all from lib local * bmain is almost certainly G.main */ -void BKE_library_make_local(Main *bmain, Library *lib, int untagged_only) +void BKE_library_make_local(Main *bmain, Library *lib, bool untagged_only) { - ListBase *lbarray[MAX_LIBARRAY], tempbase = {NULL, NULL}; + ListBase *lbarray[MAX_LIBARRAY]; ID *id, *idn; int a; @@ -1515,7 +1557,7 @@ void BKE_library_make_local(Main *bmain, Library *lib, int untagged_only) * (very nasty to discover all your links are lost after appending) * */ if (id->flag & (LIB_EXTERN | LIB_INDIRECT | LIB_NEW) && - (untagged_only == 0 || !(id->flag & LIB_PRE_EXISTING))) + ((untagged_only == false) || !(id->flag & LIB_PRE_EXISTING))) { if (lib == NULL || id->lib == lib) { if (id->lib) { @@ -1532,16 +1574,8 @@ void BKE_library_make_local(Main *bmain, Library *lib, int untagged_only) } id = idn; } - - /* patch2: make it aphabetically */ - while ( (id = tempbase.first) ) { - BLI_remlink(&tempbase, id); - BLI_addtail(lbarray[a], id); - new_id(lbarray[a], id, NULL); - } } - /* patch 3: make sure library data isn't indirect falsely... */ a = set_listbasepointers(bmain, lbarray); while (a--) { for (id = lbarray[a]->first; id; id = id->next) @@ -1557,39 +1591,20 @@ void test_idbutton(char *name) ID *idtest; - lb = which_libbase(G.main, GS(name - 2) ); + lb = which_libbase(G.main, GS(name) ); if (lb == NULL) return; /* search for id */ - idtest = BLI_findstring(lb, name, offsetof(ID, name) + 2); + idtest = BLI_findstring(lb, name + 2, offsetof(ID, name) + 2); - if (idtest && (new_id(lb, idtest, name) == 0)) { + if (idtest && !new_id(lb, idtest, name + 2)) { id_sort_by_name(lb, idtest); } } -void text_idbutton(struct ID *id, char *text) -{ - if (id) { - if (GS(id->name) == ID_SCE) - strcpy(text, "SCE: "); - else if (GS(id->name) == ID_SCR) - strcpy(text, "SCR: "); - else if (GS(id->name) == ID_MA && ((Material *)id)->use_nodes) - strcpy(text, "NT: "); - else { - text[0] = id->name[0]; - text[1] = id->name[1]; - text[2] = ':'; - text[3] = ' '; - text[4] = 0; - } - } - else { - text[0] = '\0'; - } -} - +/** + * Sets the name of a block to name, suitably adjusted for uniqueness. + */ void rename_id(ID *id, const char *name) { ListBase *lb; @@ -1600,7 +1615,11 @@ void rename_id(ID *id, const char *name) new_id(lb, id, name); } -void name_uiprefix_id(char *name, ID *id) +/** + * Returns in name the name of the block, with a 3-character prefix prepended + * indicating whether it comes from a library, has a fake user, or no users. + */ +void name_uiprefix_id(char *name, const ID *id) { name[0] = id->lib ? 'L' : ' '; name[1] = id->flag & LIB_FAKEUSER ? 'F' : (id->us == 0) ? '0' : ' '; diff --git a/source/blender/blenkernel/intern/linestyle.c b/source/blender/blenkernel/intern/linestyle.c index aa9200adef4..ca3a910f403 100644 --- a/source/blender/blenkernel/intern/linestyle.c +++ b/source/blender/blenkernel/intern/linestyle.c @@ -39,6 +39,10 @@ #include "DNA_material_types.h" /* for ramp blend */ #include "DNA_texture_types.h" +#include "BLI_blenlib.h" +#include "BLI_math.h" +#include "BLI_utildefines.h" + #include "BKE_global.h" #include "BKE_library.h" #include "BKE_linestyle.h" @@ -47,9 +51,6 @@ #include "BKE_colortools.h" #include "BKE_animsys.h" -#include "BLI_blenlib.h" -#include "BLI_math.h" - static const char *modifier_name[LS_MODIFIER_NUM] = { NULL, "Along Stroke", diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c index 50e00161db3..6f6686150ae 100644 --- a/source/blender/blenkernel/intern/material.c +++ b/source/blender/blenkernel/intern/material.c @@ -1797,7 +1797,9 @@ static short convert_tfacenomaterial(Main *main, Mesh *me, MTFace *tf, int flag) ma->game.flag = -flag; id_us_min((ID *)ma); } - else printf("Error: Unable to create Material \"%s\" for Mesh \"%s\".", idname + 2, me->id.name + 2); + else { + printf("Error: Unable to create Material \"%s\" for Mesh \"%s\".", idname + 2, me->id.name + 2); + } } /* set as converted, no need to go bad to this face */ diff --git a/source/blender/blenkernel/intern/mball.c b/source/blender/blenkernel/intern/mball.c index 5cc3145213c..72284130869 100644 --- a/source/blender/blenkernel/intern/mball.c +++ b/source/blender/blenkernel/intern/mball.c @@ -439,18 +439,15 @@ float *BKE_mball_make_orco(Object *ob, ListBase *dispbase) * It test last character of Object ID name. If last character * is digit it return 0, else it return 1. */ -int BKE_mball_is_basis(Object *ob) +bool BKE_mball_is_basis(Object *ob) { - int len; - /* just a quick test */ - len = strlen(ob->id.name); - if (isdigit(ob->id.name[len - 1]) ) return 0; - return 1; + const int len = strlen(ob->id.name); + return (!isdigit(ob->id.name[len - 1])); } /* return nonzero if ob1 is a basis mball for ob */ -int BKE_mball_is_basis_for(Object *ob1, Object *ob2) +bool BKE_mball_is_basis_for(Object *ob1, Object *ob2) { int basis1nr, basis2nr; char basis1name[MAX_ID_NAME], basis2name[MAX_ID_NAME]; @@ -458,8 +455,12 @@ int BKE_mball_is_basis_for(Object *ob1, Object *ob2) BLI_split_name_num(basis1name, &basis1nr, ob1->id.name + 2, '.'); BLI_split_name_num(basis2name, &basis2nr, ob2->id.name + 2, '.'); - if (!strcmp(basis1name, basis2name)) return BKE_mball_is_basis(ob1); - else return 0; + if (!strcmp(basis1name, basis2name)) { + return BKE_mball_is_basis(ob1); + } + else { + return false; + } } /* \brief copy some properties from object to other metaball object with same base name @@ -1500,7 +1501,7 @@ static void add_cube(PROCESS *mbproc, int i, int j, int k, int count) static void find_first_points(PROCESS *mbproc, MetaBall *mb, int a) { MetaElem *ml; - float f = 0.0f; + float f; ml = G_mb.mainb[a]; f = 1.0f - (mb->thresh / ml->s); @@ -2293,7 +2294,9 @@ void BKE_mball_polygonize(Scene *scene, Object *ob, ListBase *dispbase) } /* width is size per polygonize cube */ - if (G.is_rendering) width = mb->rendersize; + if (G.is_rendering) { + width = mb->rendersize; + } else { width = mb->wiresize; if (G.moving && mb->flag == MB_UPDATE_HALFRES) width *= 2; diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c index f6f60d03cf7..b4833cdb53b 100644 --- a/source/blender/blenkernel/intern/mesh.c +++ b/source/blender/blenkernel/intern/mesh.c @@ -1198,7 +1198,7 @@ void BKE_mesh_from_metaball(ListBase *lb, Mesh *me) BKE_mesh_calc_normals(me->mvert, me->totvert, me->mloop, me->mpoly, me->totloop, me->totpoly, NULL); - BKE_mesh_calc_edges(me, TRUE); + BKE_mesh_calc_edges(me, true, false); } } @@ -1523,7 +1523,7 @@ void BKE_mesh_from_nurbs_displist(Object *ob, ListBase *dispbase, int use_orco_u BKE_mesh_calc_normals(me->mvert, me->totvert, me->mloop, me->mpoly, me->totloop, me->totpoly, NULL); - BKE_mesh_calc_edges(me, TRUE); + BKE_mesh_calc_edges(me, true, false); } else { me = BKE_mesh_add(G.main, "Mesh"); @@ -1586,65 +1586,46 @@ static void appendPolyLineVert(ListBase *lb, unsigned int index) BLI_addtail(lb, vl); } -void BKE_mesh_from_curve(Scene *scene, Object *ob) +void BKE_mesh_to_curve_nurblist(DerivedMesh *dm, ListBase *nurblist, const int edge_users_test) { - /* make new mesh data from the original copy */ - DerivedMesh *dm = mesh_get_derived_final(scene, ob, CD_MASK_MESH); - - MVert *mverts = dm->getVertArray(dm); + MVert *mvert = dm->getVertArray(dm); MEdge *med, *medge = dm->getEdgeArray(dm); - MFace *mf, *mface = dm->getTessFaceArray(dm); + MPoly *mp, *mpoly = dm->getPolyArray(dm); + MLoop *mloop = dm->getLoopArray(dm); - int totedge = dm->getNumEdges(dm); - int totface = dm->getNumTessFaces(dm); + int dm_totedge = dm->getNumEdges(dm); + int dm_totpoly = dm->getNumPolys(dm); int totedges = 0; - int i, needsFree = 0; + int i; /* only to detect edge polylines */ - EdgeHash *eh = BLI_edgehash_new(); - EdgeHash *eh_edge = BLI_edgehash_new(); - + int *edge_users; ListBase edges = {NULL, NULL}; - /* create edges from all faces (so as to find edges not in any faces) */ - mf = mface; - for (i = 0; i < totface; i++, mf++) { - if (!BLI_edgehash_haskey(eh, mf->v1, mf->v2)) - BLI_edgehash_insert(eh, mf->v1, mf->v2, NULL); - if (!BLI_edgehash_haskey(eh, mf->v2, mf->v3)) - BLI_edgehash_insert(eh, mf->v2, mf->v3, NULL); - - if (mf->v4) { - if (!BLI_edgehash_haskey(eh, mf->v3, mf->v4)) - BLI_edgehash_insert(eh, mf->v3, mf->v4, NULL); - if (!BLI_edgehash_haskey(eh, mf->v4, mf->v1)) - BLI_edgehash_insert(eh, mf->v4, mf->v1, NULL); - } - else { - if (!BLI_edgehash_haskey(eh, mf->v3, mf->v1)) - BLI_edgehash_insert(eh, mf->v3, mf->v1, NULL); + /* get boundary edges */ + edge_users = MEM_callocN(sizeof(int) * dm_totedge, __func__); + for (i = 0, mp = mpoly; i < dm_totpoly; i++, mp++) { + MLoop *ml = &mloop[mp->loopstart]; + int j; + for (j = 0; j < mp->totloop; j++, ml++) { + edge_users[ml->e]++; } } + /* create edges from all faces (so as to find edges not in any faces) */ med = medge; - for (i = 0; i < totedge; i++, med++) { - if (!BLI_edgehash_haskey(eh, med->v1, med->v2)) { + for (i = 0; i < dm_totedge; i++, med++) { + if (edge_users[i] == edge_users_test) { EdgeLink *edl = MEM_callocN(sizeof(EdgeLink), "EdgeLink"); - - BLI_edgehash_insert(eh_edge, med->v1, med->v2, NULL); edl->edge = med; BLI_addtail(&edges, edl); totedges++; } } - BLI_edgehash_free(eh_edge, NULL); - BLI_edgehash_free(eh, NULL); + MEM_freeN(edge_users); if (edges.first) { - Curve *cu = BKE_curve_add(G.main, ob->id.name + 2, OB_CURVE); - cu->flag |= CU_3D; - while (edges.first) { /* each iteration find a polyline and add this as a nurbs poly spline */ @@ -1724,24 +1705,41 @@ void BKE_mesh_from_curve(Scene *scene, Object *ob) /* add points */ vl = polyline.first; for (i = 0, bp = nu->bp; i < totpoly; i++, bp++, vl = (VertLink *)vl->next) { - copy_v3_v3(bp->vec, mverts[vl->index].co); + copy_v3_v3(bp->vec, mvert[vl->index].co); bp->f1 = SELECT; bp->radius = bp->weight = 1.0; } BLI_freelistN(&polyline); /* add nurb to curve */ - BLI_addtail(&cu->nurb, nu); + BLI_addtail(nurblist, nu); } /* --- done with nurbs --- */ } + } +} + +void BKE_mesh_to_curve(Scene *scene, Object *ob) +{ + /* make new mesh data from the original copy */ + DerivedMesh *dm = mesh_get_derived_final(scene, ob, CD_MASK_MESH); + ListBase nurblist = {NULL, NULL}; + bool needsFree = false; + + BKE_mesh_to_curve_nurblist(dm, &nurblist, 0); + + if (nurblist.first) { + Curve *cu = BKE_curve_add(G.main, ob->id.name + 2, OB_CURVE); + cu->flag |= CU_3D; + + cu->nurb = nurblist; ((Mesh *)ob->data)->id.us--; ob->data = cu; ob->type = OB_CURVE; /* curve objects can't contain DM in usual cases, we could free memory */ - needsFree = 1; + needsFree = true; } dm->needsFree = needsFree; diff --git a/source/blender/blenkernel/intern/mesh_validate.c b/source/blender/blenkernel/intern/mesh_validate.c index 74d3645ea66..9d16d38220a 100644 --- a/source/blender/blenkernel/intern/mesh_validate.c +++ b/source/blender/blenkernel/intern/mesh_validate.c @@ -774,7 +774,7 @@ int BKE_mesh_validate_arrays(Mesh *mesh, } if (do_edge_recalc) { - BKE_mesh_calc_edges(mesh, TRUE); + BKE_mesh_calc_edges(mesh, true, false); } } @@ -914,7 +914,7 @@ int BKE_mesh_validate_dm(DerivedMesh *dm) * \param mesh The mesh to add edges into * \param update When true create new edges co-exist */ -void BKE_mesh_calc_edges(Mesh *mesh, int update) +void BKE_mesh_calc_edges(Mesh *mesh, bool update, const bool select) { CustomData edata; EdgeHashIterator *ehi; @@ -923,9 +923,11 @@ void BKE_mesh_calc_edges(Mesh *mesh, int update) EdgeHash *eh = BLI_edgehash_new(); int i, totedge, totpoly = mesh->totpoly; int med_index; + /* select for newly created meshes which are selected [#25595] */ + const short ed_flag = (ME_EDGEDRAW | ME_EDGERENDER) | (select ? SELECT : 0); if (mesh->totedge == 0) - update = FALSE; + update = false; if (update) { /* assume existing edges are valid @@ -963,7 +965,7 @@ void BKE_mesh_calc_edges(Mesh *mesh, int update) } else { BLI_edgehashIterator_getKey(ehi, &med->v1, &med->v2); - med->flag = ME_EDGEDRAW | ME_EDGERENDER | SELECT; /* select for newly created meshes which are selected [#25595] */ + med->flag = ed_flag; } /* store the new edge index in the hash value */ diff --git a/source/blender/blenkernel/intern/movieclip.c b/source/blender/blenkernel/intern/movieclip.c index 5519edca7ff..e79754ca203 100644 --- a/source/blender/blenkernel/intern/movieclip.c +++ b/source/blender/blenkernel/intern/movieclip.c @@ -1230,7 +1230,7 @@ void BKE_movieclip_update_scopes(MovieClip *clip, MovieClipUser *user, MovieClip scopes->ok = TRUE; } -static void movieclip_build_proxy_ibuf(MovieClip *clip, ImBuf *ibuf, int cfra, int proxy_render_size, int undistorted) +static void movieclip_build_proxy_ibuf(MovieClip *clip, ImBuf *ibuf, int cfra, int proxy_render_size, int undistorted, bool threaded) { char name[FILE_MAX]; int quality, rectx, recty; @@ -1244,7 +1244,10 @@ static void movieclip_build_proxy_ibuf(MovieClip *clip, ImBuf *ibuf, int cfra, i scaleibuf = IMB_dupImBuf(ibuf); - IMB_scaleImBuf(scaleibuf, (short)rectx, (short)recty); + if (threaded) + IMB_scaleImBuf_threaded(scaleibuf, (short)rectx, (short)recty); + else + IMB_scaleImBuf(scaleibuf, (short)rectx, (short)recty); quality = clip->proxy.quality; scaleibuf->ftype = JPG | quality; @@ -1253,6 +1256,10 @@ static void movieclip_build_proxy_ibuf(MovieClip *clip, ImBuf *ibuf, int cfra, i if (scaleibuf->planes == 32) scaleibuf->planes = 24; + /* TODO: currently the most weak part of multithreaded proxies, + * could be solved in a way that thread only prepares memory + * buffer and write to disk happens separately + */ BLI_lock_thread(LOCK_MOVIECLIP); BLI_make_existing_file(name); @@ -1264,12 +1271,18 @@ static void movieclip_build_proxy_ibuf(MovieClip *clip, ImBuf *ibuf, int cfra, i IMB_freeImBuf(scaleibuf); } +/* note: currently used by proxy job for movies, threading happens within single frame + * (meaning scaling shall be threaded) + */ void BKE_movieclip_build_proxy_frame(MovieClip *clip, int clip_flag, struct MovieDistortion *distortion, int cfra, int *build_sizes, int build_count, int undistorted) { ImBuf *ibuf; MovieClipUser user; + if (!build_count) + return; + user.framenr = cfra; user.render_flag = 0; user.render_size = MCLIP_PROXY_RENDER_SIZE_FULL; @@ -1284,7 +1297,7 @@ void BKE_movieclip_build_proxy_frame(MovieClip *clip, int clip_flag, struct Movi tmpibuf = get_undistorted_ibuf(clip, distortion, ibuf); for (i = 0; i < build_count; i++) - movieclip_build_proxy_ibuf(clip, tmpibuf, cfra, build_sizes[i], undistorted); + movieclip_build_proxy_ibuf(clip, tmpibuf, cfra, build_sizes[i], undistorted, true); IMB_freeImBuf(ibuf); @@ -1293,6 +1306,30 @@ void BKE_movieclip_build_proxy_frame(MovieClip *clip, int clip_flag, struct Movi } } +/* note: currently used by proxy job for sequences, threading happens within sequence + * (different threads handles different frames, no threading within frame is needed) + */ +void BKE_movieclip_build_proxy_frame_for_ibuf(MovieClip *clip, ImBuf *ibuf, struct MovieDistortion *distortion, + int cfra, int *build_sizes, int build_count, int undistorted) +{ + if (!build_count) + return; + + if (ibuf) { + ImBuf *tmpibuf = ibuf; + int i; + + if (undistorted) + tmpibuf = get_undistorted_ibuf(clip, distortion, ibuf); + + for (i = 0; i < build_count; i++) + movieclip_build_proxy_ibuf(clip, tmpibuf, cfra, build_sizes[i], undistorted, false); + + if (tmpibuf != ibuf) + IMB_freeImBuf(tmpibuf); + } +} + void BKE_movieclip_free(MovieClip *clip) { BKE_sequencer_clear_movieclip_in_clipboard(clip); @@ -1381,3 +1418,14 @@ float BKE_movieclip_remap_clip_to_scene_frame(MovieClip *clip, float framenr) { return framenr + (float) clip->start_frame - 1.0f; } + +void BKE_movieclip_filename_for_frame(MovieClip *clip, int framenr, char *name) +{ + if (clip->source != MCLIP_SRC_MOVIE) { + get_sequence_fname(clip, framenr, name); + } + else { + BLI_strncpy(name, clip->name, FILE_MAX); + BLI_path_abs(name, ID_BLEND_PATH(G.main, &clip->id)); + } +} diff --git a/source/blender/blenkernel/intern/navmesh_conversion.c b/source/blender/blenkernel/intern/navmesh_conversion.c index 3bf5f863557..1d662ae3116 100644 --- a/source/blender/blenkernel/intern/navmesh_conversion.c +++ b/source/blender/blenkernel/intern/navmesh_conversion.c @@ -436,7 +436,7 @@ int buildNavMeshDataByDerivedMesh(DerivedMesh *dm, int *vertsPerPoly, unsigned short **polys, int **dtrisToPolysMap, int **dtrisToTrisMap, int **trisToFacesMap) { - int res = 1; + int res; int ntris = 0, *recastData = NULL; unsigned short *tris = NULL; diff --git a/source/blender/blenkernel/intern/nla.c b/source/blender/blenkernel/intern/nla.c index 143f2186020..ccae1f606fc 100644 --- a/source/blender/blenkernel/intern/nla.c +++ b/source/blender/blenkernel/intern/nla.c @@ -1262,7 +1262,7 @@ void BKE_nlastrip_validate_fcurves(NlaStrip *strip) /* Sanity Validation ------------------------------------ */ -static int nla_editbone_name_check(void *arg, const char *name) +static bool nla_editbone_name_check(void *arg, const char *name) { return BLI_ghash_haskey((GHash *)arg, (void *)name); } @@ -1660,7 +1660,7 @@ void BKE_nla_tweakmode_exit(AnimData *adt) /* Baking Tools ------------------------------------------- */ -static void UNUSED_FUNCTION(BKE_nla_bake) (Scene * scene, ID *UNUSED(id), AnimData * adt, int UNUSED(flag)) +static void UNUSED_FUNCTION(BKE_nla_bake) (Scene *scene, ID *UNUSED(id), AnimData *adt, int UNUSED(flag)) { /* verify that data is valid diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c index 3dbaab008f8..974a564b9da 100644 --- a/source/blender/blenkernel/intern/node.c +++ b/source/blender/blenkernel/intern/node.c @@ -571,6 +571,12 @@ void nodeInternalRelink(bNodeTree *ntree, bNode *node) link->fromnode = fromlink->fromnode; link->fromsock = fromlink->fromsock; + /* if the up- or downstream link is invalid, + * the replacement link will be invalid too. + */ + if (!(fromlink->flag & NODE_LINK_VALID)) + link->flag &= ~NODE_LINK_VALID; + ntree->update |= NTREE_UPDATE_LINKS; } else @@ -710,7 +716,7 @@ static bNodeTree *ntreeCopyTree_internal(bNodeTree *ntree, const short do_id_use } else { newtree = MEM_dupallocN(ntree); - BKE_libblock_copy_data(&newtree->id, &ntree->id, TRUE); /* copy animdata and ID props */ + BKE_libblock_copy_data(&newtree->id, &ntree->id, true); /* copy animdata and ID props */ } id_us_plus((ID *)newtree->gpd); diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index 5cea2c9fe0e..0c6e0f72523 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -189,7 +189,7 @@ void BKE_object_free_modifiers(Object *ob) BKE_object_free_softbody(ob); } -int BKE_object_support_modifier_type_check(Object *ob, int modifier_type) +bool BKE_object_support_modifier_type_check(Object *ob, int modifier_type) { ModifierTypeInfo *mti; @@ -198,10 +198,10 @@ int BKE_object_support_modifier_type_check(Object *ob, int modifier_type) if (!((mti->flags & eModifierTypeFlag_AcceptsCVs) || (ob->type == OB_MESH && (mti->flags & eModifierTypeFlag_AcceptsMesh)))) { - return FALSE; + return false; } - return TRUE; + return true; } void BKE_object_link_modifiers(struct Object *ob_dst, struct Object *ob_src) @@ -291,6 +291,9 @@ void sculptsession_bm_to_me(struct Object *ob, int reorder) BM_mesh_bm_to_me(ss->bm, ob->data, FALSE); } } + + /* ensure the objects DerivedMesh mesh doesn't hold onto arrays now realloc'd in the mesh [#34473] */ + DAG_id_tag_update(&ob->id, OB_RECALC_DATA); } } @@ -784,61 +787,61 @@ void BKE_object_unlink(Object *ob) } /* actual check for internal data, not context or flags */ -int BKE_object_is_in_editmode(Object *ob) +bool BKE_object_is_in_editmode(Object *ob) { if (ob->data == NULL) - return 0; + return false; if (ob->type == OB_MESH) { Mesh *me = ob->data; if (me->edit_btmesh) - return 1; + return true; } else if (ob->type == OB_ARMATURE) { bArmature *arm = ob->data; if (arm->edbo) - return 1; + return true; } else if (ob->type == OB_FONT) { Curve *cu = ob->data; if (cu->editfont) - return 1; + return true; } else if (ob->type == OB_MBALL) { MetaBall *mb = ob->data; if (mb->editelems) - return 1; + return true; } else if (ob->type == OB_LATTICE) { Lattice *lt = ob->data; if (lt->editlatt) - return 1; + return true; } else if (ob->type == OB_SURF || ob->type == OB_CURVE) { Curve *cu = ob->data; if (cu->editnurb) - return 1; + return true; } - return 0; + return false; } -int BKE_object_exists_check(Object *obtest) +bool BKE_object_exists_check(Object *obtest) { Object *ob; - if (obtest == NULL) return 0; + if (obtest == NULL) return false; ob = G.main->object.first; while (ob) { - if (ob == obtest) return 1; + if (ob == obtest) return true; ob = ob->id.next; } - return 0; + return false; } /* *************************************************** */ @@ -1405,24 +1408,24 @@ void BKE_object_make_local(Object *ob) /* * Returns true if the Object is a from an external blend file (libdata) */ -int BKE_object_is_libdata(Object *ob) +bool BKE_object_is_libdata(Object *ob) { - if (!ob) return 0; - if (ob->proxy) return 0; - if (ob->id.lib) return 1; - return 0; + if (!ob) return false; + if (ob->proxy) return false; + if (ob->id.lib) return true; + return false; } /* Returns true if the Object data is a from an external blend file (libdata) */ -int BKE_object_obdata_is_libdata(Object *ob) +bool BKE_object_obdata_is_libdata(Object *ob) { - if (!ob) return 0; - if (ob->proxy && (ob->data == NULL || ((ID *)ob->data)->lib == NULL)) return 0; - if (ob->id.lib) return 1; - if (ob->data == NULL) return 0; - if (((ID *)ob->data)->lib) return 1; + if (!ob) return false; + if (ob->proxy && (ob->data == NULL || ((ID *)ob->data)->lib == NULL)) return false; + if (ob->id.lib) return true; + if (ob->data == NULL) return false; + if (((ID *)ob->data)->lib) return true; - return 0; + return false; } /* *************** PROXY **************** */ @@ -2634,11 +2637,11 @@ void BKE_object_tfm_restore(Object *ob, void *obtfm_pt) copy_m4_m4(ob->imat, obtfm->imat); } -int BKE_object_parent_loop_check(const Object *par, const Object *ob) +bool BKE_object_parent_loop_check(const Object *par, const Object *ob) { /* test if 'ob' is a parent somewhere in par's parents */ - if (par == NULL) return 0; - if (ob == par) return 1; + if (par == NULL) return false; + if (ob == par) return true; return BKE_object_parent_loop_check(par->parent, ob); } @@ -3137,6 +3140,16 @@ KeyBlock *BKE_object_insert_shape_key(Scene *scene, Object *ob, const char *name } +bool BKE_object_is_child_recursive(Object *ob_parent, Object *ob_child) +{ + for (ob_child = ob_child->parent; ob_child; ob_child = ob_child->parent) { + if (ob_child == ob_parent) { + return true; + } + } + return false; +} + /* most important if this is modified it should _always_ return True, in certain * cases false positives are hard to avoid (shape keys for example) */ int BKE_object_is_modified(Scene *scene, Object *ob) @@ -3192,7 +3205,7 @@ int BKE_object_is_deform_modified(Scene *scene, Object *ob) } /* See if an object is using an animated modifier */ -int BKE_object_is_animated(Scene *scene, Object *ob) +bool BKE_object_is_animated(Scene *scene, Object *ob) { ModifierData *md; @@ -3201,9 +3214,9 @@ int BKE_object_is_animated(Scene *scene, Object *ob) (modifier_isEnabled(scene, md, eModifierMode_Realtime) || modifier_isEnabled(scene, md, eModifierMode_Render))) { - return 1; + return true; } - return 0; + return false; } static void copy_object__forwardModifierLinks(void *UNUSED(userData), Object *UNUSED(ob), ID **idpoin) @@ -3286,18 +3299,6 @@ static Object *obrel_armature_find(Object *ob) return ob_arm; } -static int obrel_is_recursive_child(Object *ob, Object *child) -{ - Object *par; - for (par = child->parent; par; par = par->parent) { - if (par == ob) { - return TRUE; - } - } - return FALSE; -} - - static int obrel_list_test(Object *ob) { return ob && !(ob->id.flag & LIB_DOIT); @@ -3370,7 +3371,7 @@ LinkNode *BKE_object_relational_superset(struct Scene *scene, eObjectSet objectS Object *child = local_base->object; if (obrel_list_test(child)) { - if ((includeFilter & OB_REL_CHILDREN_RECURSIVE && obrel_is_recursive_child(ob, child)) || + if ((includeFilter & OB_REL_CHILDREN_RECURSIVE && BKE_object_is_child_recursive(ob, child)) || (includeFilter & OB_REL_CHILDREN && child->parent && child->parent == ob)) { obrel_list_add(&links, child); diff --git a/source/blender/blenkernel/intern/packedFile.c b/source/blender/blenkernel/intern/packedFile.c index 288e4ccde5d..5a02d929b76 100644 --- a/source/blender/blenkernel/intern/packedFile.c +++ b/source/blender/blenkernel/intern/packedFile.c @@ -348,7 +348,7 @@ int writePackedFile(ReportList *reports, const char *filename, PackedFile *pf, i } } else { - if (BLI_delete(tempname, 0, 0) != 0) { + if (BLI_delete(tempname, false, false) != 0) { BKE_reportf(reports, RPT_ERROR, "Error deleting '%s' (ignored)", tempname); } } @@ -488,11 +488,8 @@ int unpackVFont(ReportList *reports, VFont *vfont, int how) int ret_value = RET_ERROR; if (vfont != NULL) { - BLI_strncpy(localname, vfont->name, sizeof(localname)); - BLI_splitdirstring(localname, fi); - + BLI_split_file_part(vfont->name, fi, sizeof(fi)); BLI_snprintf(localname, sizeof(localname), "//fonts/%s", fi); - newname = unpackFile(reports, vfont->name, localname, vfont->packedfile, how); if (newname != NULL) { ret_value = RET_OK; @@ -513,10 +510,8 @@ int unpackSound(Main *bmain, ReportList *reports, bSound *sound, int how) int ret_value = RET_ERROR; if (sound != NULL) { - BLI_strncpy(localname, sound->name, sizeof(localname)); - BLI_splitdirstring(localname, fi); + BLI_split_file_part(sound->name, fi, sizeof(fi)); BLI_snprintf(localname, sizeof(localname), "//sounds/%s", fi); - newname = unpackFile(reports, sound->name, localname, sound->packedfile, how); if (newname != NULL) { BLI_strncpy(sound->name, newname, sizeof(sound->name)); @@ -541,10 +536,8 @@ int unpackImage(ReportList *reports, Image *ima, int how) int ret_value = RET_ERROR; if (ima != NULL && ima->name[0]) { - BLI_strncpy(localname, ima->name, sizeof(localname)); - BLI_splitdirstring(localname, fi); + BLI_split_file_part(ima->name, fi, sizeof(fi)); BLI_snprintf(localname, sizeof(localname), "//textures/%s", fi); - newname = unpackFile(reports, ima->name, localname, ima->packedfile, how); if (newname != NULL) { ret_value = RET_OK; @@ -591,7 +584,7 @@ void packLibraries(Main *bmain, ReportList *reports) /* test for relativenss */ for (lib = bmain->library.first; lib; lib = lib->id.next) - if (0 == BLI_path_is_rel(lib->name)) + if (!BLI_path_is_rel(lib->name)) break; if (lib) { @@ -624,7 +617,7 @@ void unpackAll(Main *bmain, ReportList *reports, int how) } /* ID should be not NULL, return 1 if there's a packed file */ -int BKE_pack_check(ID *id) +bool BKE_pack_check(ID *id) { if (GS(id->name) == ID_IM) { Image *ima = (Image *)id; @@ -642,7 +635,7 @@ int BKE_pack_check(ID *id) Library *li = (Library *)id; return li->packedfile != NULL; } - return 0; + return false; } /* ID should be not NULL */ diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c index d34d5eaa250..cc647a90c8f 100644 --- a/source/blender/blenkernel/intern/paint.c +++ b/source/blender/blenkernel/intern/paint.c @@ -40,6 +40,7 @@ #include "BLI_bitmap.h" #include "BLI_utildefines.h" +#include "BLI_math_vector.h" #include "BKE_brush.h" #include "BKE_context.h" @@ -137,6 +138,55 @@ Paint *paint_get_active_from_context(const bContext *C) return NULL; } +PaintMode paintmode_get_active_from_context(const bContext *C) +{ + Scene *sce = CTX_data_scene(C); + SpaceImage *sima; + + if (sce) { + ToolSettings *ts = sce->toolsettings; + Object *obact = NULL; + + if (sce->basact && sce->basact->object) + obact = sce->basact->object; + + if ((sima = CTX_wm_space_image(C)) != NULL) { + if (obact && obact->mode == OB_MODE_EDIT) { + if (sima->mode == SI_MODE_PAINT) + return PAINT_TEXTURE_2D; + else if (ts->use_uv_sculpt) + return PAINT_SCULPT_UV; + } + else { + return PAINT_TEXTURE_2D; + } + } + else if (obact) { + switch (obact->mode) { + case OB_MODE_SCULPT: + return PAINT_SCULPT; + case OB_MODE_VERTEX_PAINT: + return PAINT_VERTEX; + case OB_MODE_WEIGHT_PAINT: + return PAINT_WEIGHT; + case OB_MODE_TEXTURE_PAINT: + return PAINT_TEXTURE_PROJECTIVE; + case OB_MODE_EDIT: + if (ts->use_uv_sculpt) + return PAINT_SCULPT_UV; + else + return PAINT_TEXTURE_2D; + } + } + else { + /* default to image paint */ + return PAINT_TEXTURE_2D; + } + } + + return PAINT_INVALID; +} + Brush *paint_brush(Paint *p) { return p ? p->brush : NULL; @@ -251,3 +301,22 @@ float paint_grid_paint_mask(const GridPaintMask *gpm, unsigned level, return gpm->data[(y * factor) * gridsize + (x * factor)]; } + +/* threshhold to move before updating the brush rotation */ +#define RAKE_THRESHHOLD 20 + +void paint_calculate_rake_rotation(UnifiedPaintSettings *ups, const float mouse_pos[2]) +{ + const float u = 0.5f; + const float r = RAKE_THRESHHOLD; + + float dpos[2]; + sub_v2_v2v2(dpos, ups->last_rake, mouse_pos); + + if (len_squared_v2(dpos) >= r * r) { + ups->brush_rotation = atan2(dpos[0], dpos[1]); + + interp_v2_v2v2(ups->last_rake, ups->last_rake, + mouse_pos, u); + } +} diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c index 477ae27394f..5efeeaeedaa 100644 --- a/source/blender/blenkernel/intern/pbvh.c +++ b/source/blender/blenkernel/intern/pbvh.c @@ -294,7 +294,7 @@ static void build_mesh_leaf_node(PBVH *bvh, PBVHNode *node) /* Build the vertex list, unique verts first */ for (iter = BLI_ghashIterator_new(map), i = 0; - BLI_ghashIterator_isDone(iter) == FALSE; + BLI_ghashIterator_notDone(iter); BLI_ghashIterator_step(iter), ++i) { void *value = BLI_ghashIterator_getValue(iter); @@ -1217,7 +1217,7 @@ void BKE_pbvh_get_grid_updates(PBVH *bvh, int clear, void ***gridfaces, int *tot faces = MEM_callocN(sizeof(void *) * tot, "PBVH Grid Faces"); for (hiter = BLI_ghashIterator_new(map), i = 0; - !BLI_ghashIterator_isDone(hiter); + BLI_ghashIterator_notDone(hiter); BLI_ghashIterator_step(hiter), ++i) { faces[i] = BLI_ghashIterator_getKey(hiter); diff --git a/source/blender/blenkernel/intern/pbvh_bmesh.c b/source/blender/blenkernel/intern/pbvh_bmesh.c index 386a8b27870..0ca73b92071 100644 --- a/source/blender/blenkernel/intern/pbvh_bmesh.c +++ b/source/blender/blenkernel/intern/pbvh_bmesh.c @@ -20,6 +20,7 @@ #include "MEM_guardedalloc.h" +#include "BLI_utildefines.h" #include "BLI_buffer.h" #include "BLI_ghash.h" #include "BLI_heap.h" @@ -82,8 +83,8 @@ static void pbvh_bmesh_node_finalize(PBVH *bvh, int node_index) } BLI_assert(n->vb.bmin[0] <= n->vb.bmax[0] && - n->vb.bmin[1] <= n->vb.bmax[1] && - n->vb.bmin[2] <= n->vb.bmax[2]); + n->vb.bmin[1] <= n->vb.bmax[1] && + n->vb.bmin[2] <= n->vb.bmax[2]); n->orig_vb = n->vb; @@ -274,8 +275,8 @@ static PBVHNode *pbvh_bmesh_node_lookup(PBVH *bvh, GHash *map, void *key) } static BMVert *pbvh_bmesh_vert_create(PBVH *bvh, int node_index, - const float co[3], - const BMVert *example) + const float co[3], + const BMVert *example) { BMVert *v = BM_vert_create(bvh->bm, co, example, 0); void *val = SET_INT_IN_POINTER(node_index); @@ -354,7 +355,7 @@ static PBVHNode *pbvh_bmesh_vert_other_node_find(PBVH *bvh, BMVert *v) } static void pbvh_bmesh_vert_ownership_transfer(PBVH *bvh, PBVHNode *new_owner, - BMVert *v) + BMVert *v) { PBVHNode *current_owner; @@ -367,7 +368,7 @@ static void pbvh_bmesh_vert_ownership_transfer(PBVH *bvh, PBVHNode *new_owner, /* Set new ownership */ BLI_ghash_insert(bvh->bm_vert_to_node, v, - SET_INT_IN_POINTER(new_owner - bvh->nodes)); + SET_INT_IN_POINTER(new_owner - bvh->nodes)); BLI_ghash_insert(new_owner->bm_unique_verts, v, NULL); BLI_ghash_remove(new_owner->bm_other_verts, v, NULL, NULL); BLI_assert(!BLI_ghash_haskey(new_owner->bm_other_verts, v)); @@ -489,35 +490,50 @@ static int edge_queue_tri_in_sphere(const EdgeQueue *q, BMFace *f) return ((len_squared_v3v3(q->center, c) <= q->radius_squared)); } +/* Return true if the vertex mask is less than 0.5, false otherwise */ +static int check_mask_half(BMesh *bm, BMVert *v) +{ + const float *mask; + + mask = CustomData_bmesh_get(&bm->vdata, v->head.data, CD_PAINT_MASK); + return ((*mask) < 0.5f); +} + static void edge_queue_insert(EdgeQueue *q, BLI_mempool *pool, BMEdge *e, - float priority) + float priority, BMesh *bm) { BMVert **pair; - pair = BLI_mempool_alloc(pool); - pair[0] = e->v1; - pair[1] = e->v2; - BLI_heap_insert(q->heap, priority, pair); + /* Don't let topology update affect masked vertices. Unlike with + * displacements, can't do 50% topology update, so instead set + * (arbitrary) cutoff: if both vertices' masks are less than 50%, + * topology update can happen. */ + if (check_mask_half(bm, e->v1) && check_mask_half(bm, e->v2)) { + pair = BLI_mempool_alloc(pool); + pair[0] = e->v1; + pair[1] = e->v2; + BLI_heap_insert(q->heap, priority, pair); + } } static void long_edge_queue_edge_add(EdgeQueue *q, BLI_mempool *pool, - BMEdge *e) + BMEdge *e, BMesh *bm) { const float len_sq = BM_edge_calc_length_squared(e); if (len_sq > q->limit_len_squared) - edge_queue_insert(q, pool, e, 1.0f / len_sq); + edge_queue_insert(q, pool, e, 1.0f / len_sq, bm); } static void short_edge_queue_edge_add(EdgeQueue *q, BLI_mempool *pool, - BMEdge *e) + BMEdge *e, BMesh *bm) { const float len_sq = BM_edge_calc_length_squared(e); if (len_sq < q->limit_len_squared) - edge_queue_insert(q, pool, e, len_sq); + edge_queue_insert(q, pool, e, len_sq, bm); } static void long_edge_queue_face_add(EdgeQueue *q, BLI_mempool *pool, - BMFace *f) + BMFace *f, BMesh *bm) { if (edge_queue_tri_in_sphere(q, f)) { BMLoop *l_iter; @@ -526,13 +542,13 @@ static void long_edge_queue_face_add(EdgeQueue *q, BLI_mempool *pool, /* Check each edge of the face */ l_iter = l_first = BM_FACE_FIRST_LOOP(f); do { - long_edge_queue_edge_add(q, pool, l_iter->e); + long_edge_queue_edge_add(q, pool, l_iter->e, bm); } while ((l_iter = l_iter->next) != l_first); } } static void short_edge_queue_face_add(EdgeQueue *q, BLI_mempool *pool, - BMFace *f) + BMFace *f, BMesh *bm) { if (edge_queue_tri_in_sphere(q, f)) { BMLoop *l_iter; @@ -541,7 +557,7 @@ static void short_edge_queue_face_add(EdgeQueue *q, BLI_mempool *pool, /* Check each edge of the face */ l_iter = l_first = BM_FACE_FIRST_LOOP(f); do { - short_edge_queue_edge_add(q, pool, l_iter->e); + short_edge_queue_edge_add(q, pool, l_iter->e, bm); } while ((l_iter = l_iter->next) != l_first); } } @@ -556,8 +572,8 @@ static void short_edge_queue_face_add(EdgeQueue *q, BLI_mempool *pool, * The highest priority (lowest number) is given to the longest edge. */ static void long_edge_queue_create(EdgeQueue *q, BLI_mempool *pool, - PBVH *bvh, const float center[3], - float radius) + PBVH *bvh, const float center[3], + float radius) { int n; @@ -579,7 +595,7 @@ static void long_edge_queue_create(EdgeQueue *q, BLI_mempool *pool, GHASH_ITER (gh_iter, node->bm_faces) { BMFace *f = BLI_ghashIterator_getKey(&gh_iter); - long_edge_queue_face_add(q, pool, f); + long_edge_queue_face_add(q, pool, f, bvh->bm); } } } @@ -595,8 +611,8 @@ static void long_edge_queue_create(EdgeQueue *q, BLI_mempool *pool, * The highest priority (lowest number) is given to the shortest edge. */ static void short_edge_queue_create(EdgeQueue *q, BLI_mempool *pool, - PBVH *bvh, const float center[3], - float radius) + PBVH *bvh, const float center[3], + float radius) { int n; @@ -618,7 +634,7 @@ static void short_edge_queue_create(EdgeQueue *q, BLI_mempool *pool, GHASH_ITER (gh_iter, node->bm_faces) { BMFace *f = BLI_ghashIterator_getKey(&gh_iter); - short_edge_queue_face_add(q, pool, f); + short_edge_queue_face_add(q, pool, f, bvh->bm); } } } @@ -673,9 +689,9 @@ static void pbvh_bmesh_split_edge(PBVH *bvh, EdgeQueue *q, BLI_mempool *pool, /* Create two new faces */ f_new = pbvh_bmesh_face_create(bvh, ni, v1, v_new, opp, f_adj); - long_edge_queue_face_add(q, pool, f_new); + long_edge_queue_face_add(q, pool, f_new, bvh->bm); f_new = pbvh_bmesh_face_create(bvh, ni, v_new, v2, opp, f_adj); - long_edge_queue_face_add(q, pool, f_new); + long_edge_queue_face_add(q, pool, f_new, bvh->bm); /* Delete original */ pbvh_bmesh_face_remove(bvh, f_adj); @@ -693,7 +709,7 @@ static void pbvh_bmesh_split_edge(PBVH *bvh, EdgeQueue *q, BLI_mempool *pool, BMEdge *e2; BM_ITER_ELEM (e2, &bm_iter, opp, BM_EDGES_OF_VERT) { - long_edge_queue_edge_add(q, pool, e2); + long_edge_queue_edge_add(q, pool, e2, bvh->bm); } } } @@ -929,8 +945,8 @@ static int pbvh_bmesh_collapse_short_edges(PBVH *bvh, EdgeQueue *q, /************************* Called from pbvh.c *************************/ int pbvh_bmesh_node_raycast(PBVHNode *node, const float ray_start[3], - const float ray_normal[3], float *dist, - int use_original) + const float ray_normal[3], float *dist, + int use_original) { GHashIterator gh_iter; int hit = 0; @@ -940,10 +956,10 @@ int pbvh_bmesh_node_raycast(PBVHNode *node, const float ray_start[3], for (i = 0; i < node->bm_tot_ortri; i++) { const int *t = node->bm_ortri[i]; hit |= ray_face_intersection(ray_start, ray_normal, - node->bm_orco[t[0]], - node->bm_orco[t[1]], - node->bm_orco[t[2]], - NULL, dist); + node->bm_orco[t[0]], + node->bm_orco[t[1]], + node->bm_orco[t[2]], + NULL, dist); } } else { @@ -988,7 +1004,7 @@ void pbvh_bmesh_normals_update(PBVHNode **nodes, int totnode) /* Build a PBVH from a BMesh */ void BKE_pbvh_build_bmesh(PBVH *bvh, BMesh *bm, int smooth_shading, - BMLog *log) + BMLog *log) { BMIter iter; BMFace *f; @@ -1098,7 +1114,7 @@ void BKE_pbvh_bmesh_node_save_orig(PBVHNode *node) return; totvert = (BLI_ghash_size(node->bm_unique_verts) + - BLI_ghash_size(node->bm_other_verts)); + BLI_ghash_size(node->bm_other_verts)); tottri = BLI_ghash_size(node->bm_faces); @@ -1214,31 +1230,31 @@ void bmesh_print(BMesh *bm) BMLoop *l; fprintf(stderr, "\nbm=%p, totvert=%d, totedge=%d, " - "totloop=%d, totface=%d\n", - bm, bm->totvert, bm->totedge, - bm->totloop, bm->totface); + "totloop=%d, totface=%d\n", + bm, bm->totvert, bm->totedge, + bm->totloop, bm->totface); fprintf(stderr, "vertices:\n"); BM_ITER_MESH(v, &iter, bm, BM_VERTS_OF_MESH) { fprintf(stderr, " %d co=(%.3f %.3f %.3f) oflag=%x\n", - BM_elem_index_get(v), v->co[0], v->co[1], v->co[2], - v->oflags[bm->stackdepth - 1].f); + BM_elem_index_get(v), v->co[0], v->co[1], v->co[2], + v->oflags[bm->stackdepth - 1].f); } fprintf(stderr, "edges:\n"); BM_ITER_MESH(e, &iter, bm, BM_EDGES_OF_MESH) { fprintf(stderr, " %d v1=%d, v2=%d, oflag=%x\n", - BM_elem_index_get(e), - BM_elem_index_get(e->v1), - BM_elem_index_get(e->v2), - e->oflags[bm->stackdepth - 1].f); + BM_elem_index_get(e), + BM_elem_index_get(e->v1), + BM_elem_index_get(e->v2), + e->oflags[bm->stackdepth - 1].f); } fprintf(stderr, "faces:\n"); BM_ITER_MESH(f, &iter, bm, BM_FACES_OF_MESH) { fprintf(stderr, " %d len=%d, oflag=%x\n", - BM_elem_index_get(f), f->len, - f->oflags[bm->stackdepth - 1].f); + BM_elem_index_get(f), f->len, + f->oflags[bm->stackdepth - 1].f); fprintf(stderr, " v: "); BM_ITER_ELEM(v, &siter, f, BM_VERTS_OF_FACE) { @@ -1255,9 +1271,9 @@ void bmesh_print(BMesh *bm) fprintf(stderr, " l: "); BM_ITER_ELEM(l, &siter, f, BM_LOOPS_OF_FACE) { fprintf(stderr, "%d(v=%d, e=%d) ", - BM_elem_index_get(l), - BM_elem_index_get(l->v), - BM_elem_index_get(l->e)); + BM_elem_index_get(l), + BM_elem_index_get(l->v), + BM_elem_index_get(l->e)); } fprintf(stderr, "\n"); } @@ -1272,15 +1288,15 @@ void pbvh_bmesh_print(PBVH *bvh) fprintf(stderr, "bm_face_to_node:\n"); GHASH_ITER (gh_iter, bvh->bm_face_to_node) { fprintf(stderr, " %d -> %d\n", - BM_elem_index_get((BMFace*)BLI_ghashIterator_getKey(&gh_iter)), - GET_INT_FROM_POINTER(BLI_ghashIterator_getValue(&gh_iter))); + BM_elem_index_get((BMFace*)BLI_ghashIterator_getKey(&gh_iter)), + GET_INT_FROM_POINTER(BLI_ghashIterator_getValue(&gh_iter))); } fprintf(stderr, "bm_vert_to_node:\n"); GHASH_ITER (gh_iter, bvh->bm_vert_to_node) { fprintf(stderr, " %d -> %d\n", - BM_elem_index_get((BMVert*)BLI_ghashIterator_getKey(&gh_iter)), - GET_INT_FROM_POINTER(BLI_ghashIterator_getValue(&gh_iter))); + BM_elem_index_get((BMVert*)BLI_ghashIterator_getKey(&gh_iter)), + GET_INT_FROM_POINTER(BLI_ghashIterator_getValue(&gh_iter))); } for (n = 0; n < bvh->totnode; n++) { @@ -1291,15 +1307,15 @@ void pbvh_bmesh_print(PBVH *bvh) fprintf(stderr, "node %d\n faces:\n", n); GHASH_ITER (gh_iter, node->bm_faces) fprintf(stderr, " %d\n", - BM_elem_index_get((BMFace*)BLI_ghashIterator_getKey(&gh_iter))); + BM_elem_index_get((BMFace*)BLI_ghashIterator_getKey(&gh_iter))); fprintf(stderr, " unique verts:\n"); GHASH_ITER (gh_iter, node->bm_unique_verts) fprintf(stderr, " %d\n", - BM_elem_index_get((BMVert*)BLI_ghashIterator_getKey(&gh_iter))); + BM_elem_index_get((BMVert*)BLI_ghashIterator_getKey(&gh_iter))); fprintf(stderr, " other verts:\n"); GHASH_ITER (gh_iter, node->bm_other_verts) fprintf(stderr, " %d\n", - BM_elem_index_get((BMVert*)BLI_ghashIterator_getKey(&gh_iter))); + BM_elem_index_get((BMVert*)BLI_ghashIterator_getKey(&gh_iter))); } } @@ -1341,7 +1357,7 @@ void pbvh_bmesh_verify(PBVH *bvh) /* Check that the vertex is in the node */ BLI_assert(BLI_ghash_haskey(n->bm_unique_verts, v) ^ - BLI_ghash_haskey(n->bm_other_verts, v)); + BLI_ghash_haskey(n->bm_other_verts, v)); /* Check that the vertex has a node owner */ nv = pbvh_bmesh_node_lookup(bvh, bvh->bm_vert_to_node, v); diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c index c8947730ea8..c900d08e4e9 100644 --- a/source/blender/blenkernel/intern/pointcache.c +++ b/source/blender/blenkernel/intern/pointcache.c @@ -840,7 +840,10 @@ static int ptcache_dynamicpaint_read(PTCacheFile *pf, void *dp_v) /* version header */ ptcache_file_read(pf, version, 1, sizeof(char) * 4); - if (strncmp(version, DPAINT_CACHE_VERSION, 4)) {printf("Dynamic Paint: Invalid cache version: %s!\n", version); return 0;} + if (strncmp(version, DPAINT_CACHE_VERSION, 4)) { + printf("Dynamic Paint: Invalid cache version: %s!\n", version); + return 0; + } if (surface->format != MOD_DPAINT_SURFACE_F_IMAGESEQ && surface->data) { unsigned int data_len; @@ -1516,7 +1519,7 @@ static int ptcache_file_compressed_write(PTCacheFile *pf, unsigned char *in, uns if (mode == 2) { r = LzmaCompress(out, &out_len, in, in_len, //assume sizeof(char)==1.... - props, &sizeOfIt, 5, 1 << 24, 3, 0, 2, 32, 2); + props, &sizeOfIt, 5, 1 << 24, 3, 0, 2, 32, 2); if (!(r == SZ_OK) || (out_len >= in_len)) compressed = 0; @@ -2432,7 +2435,7 @@ void BKE_ptcache_id_clear(PTCacheID *pid, int mode, unsigned int cfra) if (mode == PTCACHE_CLEAR_ALL) { pid->cache->last_exact = MIN2(pid->cache->startframe, 0); BLI_join_dirfile(path_full, sizeof(path_full), path, de->d_name); - BLI_delete(path_full, 0, 0); + BLI_delete(path_full, false, false); } else { /* read the number of the file */ @@ -2448,7 +2451,7 @@ void BKE_ptcache_id_clear(PTCacheID *pid, int mode, unsigned int cfra) { BLI_join_dirfile(path_full, sizeof(path_full), path, de->d_name); - BLI_delete(path_full, 0, 0); + BLI_delete(path_full, false, false); if (pid->cache->cached_frames && frame >=sta && frame <= end) pid->cache->cached_frames[frame-sta] = 0; } @@ -2502,7 +2505,7 @@ void BKE_ptcache_id_clear(PTCacheID *pid, int mode, unsigned int cfra) if (pid->cache->flag & PTCACHE_DISK_CACHE) { if (BKE_ptcache_id_exist(pid, cfra)) { ptcache_filename(pid, filename, cfra, 1, 1); /* no path */ - BLI_delete(filename, 0, 0); + BLI_delete(filename, false, false); } } else { @@ -2820,7 +2823,7 @@ void BKE_ptcache_remove(void) } else if (strstr(de->d_name, PTCACHE_EXT)) { /* do we have the right extension?*/ BLI_join_dirfile(path_full, sizeof(path_full), path, de->d_name); - BLI_delete(path_full, 0, 0); + BLI_delete(path_full, false, false); } else { rmdir = 0; /* unknown file, don't remove the dir */ @@ -2834,7 +2837,7 @@ void BKE_ptcache_remove(void) } if (rmdir) { - BLI_delete(path, 1, 0); + BLI_delete(path, true, false); } } @@ -3039,7 +3042,7 @@ static void *ptcache_bake_thread(void *ptr) } /* if bake is not given run simulations to current frame */ -void BKE_ptcache_bake(PTCacheBaker* baker) +void BKE_ptcache_bake(PTCacheBaker *baker) { Main *bmain = baker->main; Scene *scene = baker->scene; @@ -3511,7 +3514,7 @@ void BKE_ptcache_update_info(PTCacheID *pid) else if (totframes && cache->totpoint) BLI_snprintf(cache->info, sizeof(cache->info), IFACE_("%i points found!"), cache->totpoint); else - BLI_snprintf(cache->info, sizeof(cache->info), IFACE_("No valid data to read!")); + BLI_strncpy(cache->info, IFACE_("No valid data to read!"), sizeof(cache->info)); return; } diff --git a/source/blender/blenkernel/intern/property.c b/source/blender/blenkernel/intern/property.c index c4658712ecb..ec23a7db8a1 100644 --- a/source/blender/blenkernel/intern/property.c +++ b/source/blender/blenkernel/intern/property.c @@ -74,8 +74,10 @@ bProperty *BKE_bproperty_copy(bProperty *prop) if (prop->poin && prop->poin != &prop->data) { propn->poin = MEM_dupallocN(prop->poin); } - else propn->poin = &propn->data; - + else { + propn->poin = &propn->data; + } + return propn; } diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c index d144ac927a6..bccc6f9a93b 100644 --- a/source/blender/blenkernel/intern/rigidbody.c +++ b/source/blender/blenkernel/intern/rigidbody.c @@ -637,12 +637,12 @@ void BKE_rigidbody_validate_sim_constraint(RigidBodyWorld *rbw, Object *ob, shor RB_constraint_set_limits_6dof(rbc->physics_constraint, RB_LIMIT_ANG_Z, 0.0f, -1.0f); break; case RBC_TYPE_MOTOR: - rbc->physics_constraint = RB_constraint_new_motor(loc, rot, rb1, rb2); + rbc->physics_constraint = RB_constraint_new_motor(loc, rot, rb1, rb2); - RB_constraint_set_enable_motor(rbc->physics_constraint, rbc->flag & RBC_FLAG_USE_MOTOR_LIN, rbc->flag & RBC_FLAG_USE_MOTOR_ANG); + RB_constraint_set_enable_motor(rbc->physics_constraint, rbc->flag & RBC_FLAG_USE_MOTOR_LIN, rbc->flag & RBC_FLAG_USE_MOTOR_ANG); RB_constraint_set_max_impulse_motor(rbc->physics_constraint, rbc->motor_lin_max_impulse, rbc->motor_ang_max_impulse); RB_constraint_set_target_velocity_motor(rbc->physics_constraint, rbc->motor_lin_target_velocity, rbc->motor_ang_target_velocity); - break; + break; } } else { /* can't create constraint without both rigid bodies */ @@ -1338,6 +1338,7 @@ void BKE_rigidbody_remove_constraint(Scene *scene, Object *ob) {} void BKE_rigidbody_sync_transforms(RigidBodyWorld *rbw, Object *ob, float ctime) {} void BKE_rigidbody_aftertrans_update(Object *ob, float loc[3], float rot[3], float quat[4], float rotAxis[3], float rotAngle) {} void BKE_rigidbody_cache_reset(RigidBodyWorld *rbw) {} +void BKE_rigidbody_rebuild_world(Scene *scene, float ctime) {} void BKE_rigidbody_do_simulation(Scene *scene, float ctime) {} #ifdef __GNUC__ diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c index 19eea279f79..a942e694f2e 100644 --- a/source/blender/blenkernel/intern/scene.c +++ b/source/blender/blenkernel/intern/scene.c @@ -461,7 +461,7 @@ Scene *BKE_scene_add(Main *bmain, const char *name) sce->r.postsat = 1.0; sce->r.bake_mode = 1; /* prevent to include render stuff here */ - sce->r.bake_filter = 2; + sce->r.bake_filter = 16; sce->r.bake_osa = 5; sce->r.bake_flag = R_BAKE_CLEAR; sce->r.bake_normal_space = R_BAKE_SPACE_TANGENT; @@ -786,7 +786,9 @@ int BKE_scene_base_iter_next(Scene **scene, int val, Base **base, Object **ob) else { if (*base && fase != F_DUPLI) { *base = (*base)->next; - if (*base) *ob = (*base)->object; + if (*base) { + *ob = (*base)->object; + } else { if (fase == F_SCENE) { /* (*scene) is finished, now do the set */ @@ -803,7 +805,9 @@ int BKE_scene_base_iter_next(Scene **scene, int val, Base **base, Object **ob) } } - if (*base == NULL) fase = F_START; + if (*base == NULL) { + fase = F_START; + } else { if (fase != F_DUPLI) { if ( (*base)->object->transflag & OB_DUPLI) { diff --git a/source/blender/blenkernel/intern/seqcache.c b/source/blender/blenkernel/intern/seqcache.c index e3f0226c863..978c1a7c9b0 100644 --- a/source/blender/blenkernel/intern/seqcache.c +++ b/source/blender/blenkernel/intern/seqcache.c @@ -26,7 +26,6 @@ * \ingroup bke */ - #include <stddef.h> #include "BLO_sys_types.h" /* for intptr_t */ @@ -34,7 +33,6 @@ #include "MEM_guardedalloc.h" #include "DNA_sequence_types.h" -#include "BKE_sequencer.h" #include "IMB_moviecache.h" #include "IMB_imbuf.h" @@ -42,6 +40,8 @@ #include "BLI_listbase.h" +#include "BKE_sequencer.h" + typedef struct SeqCacheKey { struct Sequence *seq; SeqRenderData context; diff --git a/source/blender/blenkernel/intern/seqeffects.c b/source/blender/blenkernel/intern/seqeffects.c index c0e85352217..a1dc19e1ff7 100644 --- a/source/blender/blenkernel/intern/seqeffects.c +++ b/source/blender/blenkernel/intern/seqeffects.c @@ -182,8 +182,8 @@ static void do_alphaover_effect_byte(float facf0, float facf1, int x, int y, un fac = fac2; mfac = 1.0f - fac2 * rt1[3]; - if (fac <= 0.0f) *( (unsigned int *) rt) = *( (unsigned int *) cp2); - else if (mfac <= 0.0f) *( (unsigned int *) rt) = *( (unsigned int *) cp1); + if (fac <= 0.0f) *((unsigned int *) rt) = *((unsigned int *) cp2); + else if (mfac <= 0.0f) *((unsigned int *) rt) = *((unsigned int *) cp1); else { tempc[0] = fac * rt1[0] + mfac * rt2[0]; tempc[1] = fac * rt1[1] + mfac * rt2[1]; @@ -206,8 +206,8 @@ static void do_alphaover_effect_byte(float facf0, float facf1, int x, int y, un fac = fac4; mfac = 1.0f - (fac4 * rt1[3]); - if (fac <= 0.0f) *( (unsigned int *) rt) = *( (unsigned int *) cp2); - else if (mfac <= 0.0f) *( (unsigned int *) rt) = *( (unsigned int *) cp1); + if (fac <= 0.0f) *((unsigned int *) rt) = *((unsigned int *) cp2); + else if (mfac <= 0.0f) *((unsigned int *) rt) = *((unsigned int *) cp1); else { tempc[0] = fac * rt1[0] + mfac * rt2[0]; tempc[1] = fac * rt1[1] + mfac * rt2[1]; @@ -328,13 +328,13 @@ static void do_alphaunder_effect_byte(float facf0, float facf1, int x, int y, un /* this complex optimization is because the * 'skybuf' can be crossed in */ - if (rt2[3] == 0 && fac2 == 256) *( (unsigned int *) rt) = *( (unsigned int *) rt1); - else if (rt2[3] == 255) *( (unsigned int *) rt) = *( (unsigned int *) rt2); + if (rt2[3] == 0 && fac2 == 256) *((unsigned int *) rt) = *((unsigned int *) rt1); + else if (rt2[3] == 255) *((unsigned int *) rt) = *((unsigned int *) rt2); else { mfac = rt2[3]; fac = (fac2 * (256 - mfac)) >> 8; - if (fac == 0) *( (unsigned int *) rt) = *( (unsigned int *) rt2); + if (fac == 0) *((unsigned int *) rt) = *((unsigned int *) rt2); else { rt[0] = (fac * rt1[0] + mfac * rt2[0]) >> 8; rt[1] = (fac * rt1[1] + mfac * rt2[1]) >> 8; @@ -351,13 +351,13 @@ static void do_alphaunder_effect_byte(float facf0, float facf1, int x, int y, un x = xo; while (x--) { - if (rt2[3] == 0 && fac4 == 256) *( (unsigned int *) rt) = *( (unsigned int *) rt1); - else if (rt2[3] == 255) *( (unsigned int *) rt) = *( (unsigned int *) rt2); + if (rt2[3] == 0 && fac4 == 256) *((unsigned int *) rt) = *((unsigned int *) rt1); + else if (rt2[3] == 255) *((unsigned int *) rt) = *((unsigned int *) rt2); else { mfac = rt2[3]; fac = (fac4 * (256 - mfac)) >> 8; - if (fac == 0) *( (unsigned int *)rt) = *( (unsigned int *)rt2); + if (fac == 0) *((unsigned int *)rt) = *((unsigned int *)rt2); else { rt[0] = (fac * rt1[0] + mfac * rt2[0]) >> 8; rt[1] = (fac * rt1[1] + mfac * rt2[1]) >> 8; @@ -682,7 +682,7 @@ static void gamtabs(float gamma) } /* inverse gamtab1 : in byte, out short */ for (a = 1; a <= 256; a++) { - if (gamma == 2.0f) igamtab1[a - 1] = a * a - 1; + if (gamma == 2.0f) igamtab1[a - 1] = a * a - 1; else if (gamma == 1.0f) igamtab1[a - 1] = 256 * a - 1; else { val = a / 256.0f; diff --git a/source/blender/blenkernel/intern/sequencer.c b/source/blender/blenkernel/intern/sequencer.c index 613c02c173b..9b276912087 100644 --- a/source/blender/blenkernel/intern/sequencer.c +++ b/source/blender/blenkernel/intern/sequencer.c @@ -245,7 +245,7 @@ static void seq_free_sequence_recurse(Scene *scene, Sequence *seq) } -Editing *BKE_sequencer_editing_get(Scene *scene, int alloc) +Editing *BKE_sequencer_editing_get(Scene *scene, bool alloc) { if (alloc) { BKE_sequencer_editing_ensure(scene); @@ -856,7 +856,7 @@ static void seqbase_unique_name(ListBase *seqbasep, SeqUniqueInfo *sui) { Sequence *seq; for (seq = seqbasep->first; seq; seq = seq->next) { - if (sui->seq != seq && strcmp(sui->name_dest, seq->name + 2) == 0) { + if ((sui->seq != seq) && STREQ(sui->name_dest, seq->name + 2)) { /* SEQ_NAME_MAXSTR - 2 for prefix, -1 for \0, -4 for the number */ BLI_snprintf(sui->name_dest, sizeof(sui->name_dest), "%.59s.%03d", sui->name_src, sui->count++); sui->match = 1; /* be sure to re-scan */ @@ -3062,30 +3062,30 @@ static void free_anim_seq(Sequence *seq) } /* check whether sequence cur depends on seq */ -int BKE_sequence_check_depend(Sequence *seq, Sequence *cur) +bool BKE_sequence_check_depend(Sequence *seq, Sequence *cur) { if (cur->seq1 == seq || cur->seq2 == seq || cur->seq3 == seq) - return TRUE; + return true; /* sequences are not intersecting in time, assume no dependency exists between them */ if (cur->enddisp < seq->startdisp || cur->startdisp > seq->enddisp) - return FALSE; + return false; /* checking sequence is below reference one, not dependent on it */ if (cur->machine < seq->machine) - return FALSE; + return false; /* sequence is not blending with lower machines, no dependency here occurs * check for non-effects only since effect could use lower machines as input */ if ((cur->type & SEQ_TYPE_EFFECT) == 0 && - ((cur->blend_mode == SEQ_BLEND_REPLACE) || - (cur->blend_mode == SEQ_TYPE_CROSS && cur->blend_opacity == 100.0f))) + ((cur->blend_mode == SEQ_BLEND_REPLACE) || + (cur->blend_mode == SEQ_TYPE_CROSS && cur->blend_opacity == 100.0f))) { - return FALSE; + return false; } - return TRUE; + return true; } static void sequence_do_invalidate_dependent(Sequence *seq, ListBase *seqbase) @@ -3291,7 +3291,7 @@ void BKE_sequence_tx_set_final_right(Sequence *seq, int val) /* used so we can do a quick check for single image seq * since they work a bit differently to normal image seq's (during transform) */ -int BKE_sequence_single_check(Sequence *seq) +bool BKE_sequence_single_check(Sequence *seq) { return ((seq->len == 1) && (seq->type == SEQ_TYPE_IMAGE || @@ -3300,21 +3300,21 @@ int BKE_sequence_single_check(Sequence *seq) } /* check if the selected seq's reference unselected seq's */ -int BKE_sequence_base_isolated_sel_check(ListBase *seqbase) +bool BKE_sequence_base_isolated_sel_check(ListBase *seqbase) { Sequence *seq; /* is there more than 1 select */ - int ok = FALSE; + bool ok = false; for (seq = seqbase->first; seq; seq = seq->next) { if (seq->flag & SELECT) { - ok = TRUE; + ok = true; break; } } - if (ok == FALSE) - return FALSE; + if (ok == false) + return false; /* test relationships */ for (seq = seqbase->first; seq; seq = seq->next) { @@ -3322,24 +3322,24 @@ int BKE_sequence_base_isolated_sel_check(ListBase *seqbase) continue; if (seq->flag & SELECT) { - if ( (seq->seq1 && (seq->seq1->flag & SELECT) == 0) || - (seq->seq2 && (seq->seq2->flag & SELECT) == 0) || - (seq->seq3 && (seq->seq3->flag & SELECT) == 0) ) + if ((seq->seq1 && (seq->seq1->flag & SELECT) == 0) || + (seq->seq2 && (seq->seq2->flag & SELECT) == 0) || + (seq->seq3 && (seq->seq3->flag & SELECT) == 0) ) { - return FALSE; + return false; } } else { - if ( (seq->seq1 && (seq->seq1->flag & SELECT)) || - (seq->seq2 && (seq->seq2->flag & SELECT)) || - (seq->seq3 && (seq->seq3->flag & SELECT)) ) + if ((seq->seq1 && (seq->seq1->flag & SELECT)) || + (seq->seq2 && (seq->seq2->flag & SELECT)) || + (seq->seq3 && (seq->seq3->flag & SELECT)) ) { - return FALSE; + return false; } } } - return TRUE; + return true; } /* use to impose limits when dragging/extending - so impossible situations don't happen @@ -3405,29 +3405,29 @@ void BKE_sequence_single_fix(Sequence *seq) } } -int BKE_sequence_tx_test(Sequence *seq) +bool BKE_sequence_tx_test(Sequence *seq) { return (seq->type < SEQ_TYPE_EFFECT) || (BKE_sequence_effect_get_num_inputs(seq->type) == 0); } -static int seq_overlap(Sequence *seq1, Sequence *seq2) +static bool seq_overlap(Sequence *seq1, Sequence *seq2) { return (seq1 != seq2 && seq1->machine == seq2->machine && ((seq1->enddisp <= seq2->startdisp) || (seq1->startdisp >= seq2->enddisp)) == 0); } -int BKE_sequence_test_overlap(ListBase *seqbasep, Sequence *test) +bool BKE_sequence_test_overlap(ListBase *seqbasep, Sequence *test) { Sequence *seq; seq = seqbasep->first; while (seq) { if (seq_overlap(test, seq)) - return 1; + return true; seq = seq->next; } - return 0; + return false; } @@ -3487,7 +3487,7 @@ Sequence *BKE_sequencer_foreground_frame_get(Scene *scene, int frame) } /* return 0 if there werent enough space */ -int BKE_sequence_base_shuffle(ListBase *seqbasep, Sequence *test, Scene *evil_scene) +bool BKE_sequence_base_shuffle(ListBase *seqbasep, Sequence *test, Scene *evil_scene) { int orig_machine = test->machine; test->machine++; @@ -3518,10 +3518,10 @@ int BKE_sequence_base_shuffle(ListBase *seqbasep, Sequence *test, Scene *evil_sc BKE_sequence_translate(evil_scene, test, new_frame - test->start); BKE_sequence_calc(evil_scene, test); - return 0; + return false; } else { - return 1; + return true; } } @@ -3572,7 +3572,7 @@ static int shuffle_seq_time_offset(Scene *scene, ListBase *seqbasep, char dir) return tot_ofs; } -int BKE_sequence_base_shuffle_time(ListBase *seqbasep, Scene *evil_scene) +bool BKE_sequence_base_shuffle_time(ListBase *seqbasep, Scene *evil_scene) { /* note: seq->tmp is used to tag strips to move */ @@ -3591,7 +3591,7 @@ int BKE_sequence_base_shuffle_time(ListBase *seqbasep, Scene *evil_scene) } } - return offset ? 0 : 1; + return offset ? false : true; } void BKE_sequencer_update_sound_bounds_all(Scene *scene) @@ -3861,7 +3861,7 @@ Sequence *BKE_sequence_get_by_name(ListBase *seqbase, const char *name, int recu Sequence *rseq = NULL; for (iseq = seqbase->first; iseq; iseq = iseq->next) { - if (strcmp(name, iseq->name + 2) == 0) + if (STREQ(name, iseq->name + 2)) return iseq; else if (recursive && (iseq->seqbase.first) && (rseq = BKE_sequence_get_by_name(&iseq->seqbase, name, 1))) { return rseq; @@ -4072,7 +4072,7 @@ Sequence *BKE_sequencer_add_sound_strip(bContext *C, ListBase *seqbasep, SeqLoad if (sound == NULL || sound->playback_handle == NULL) { #if 0 - if (op) + if (op) BKE_report(op->reports, RPT_ERROR, "Unsupported audio format"); #endif @@ -4324,7 +4324,7 @@ void BKE_sequence_base_dupli_recursive(Scene *scene, Scene *scene_to, ListBase * /* called on draw, needs to be fast, * we could cache and use a flag if we want to make checks for file paths resolving for eg. */ -int BKE_sequence_is_valid_check(Sequence *seq) +bool BKE_sequence_is_valid_check(Sequence *seq) { switch (seq->type) { case SEQ_TYPE_MASK: @@ -4337,6 +4337,6 @@ int BKE_sequence_is_valid_check(Sequence *seq) return (seq->sound != NULL); } - return TRUE; + return true; } diff --git a/source/blender/blenkernel/intern/smoke.c b/source/blender/blenkernel/intern/smoke.c index 248cd689258..435e81556ab 100644 --- a/source/blender/blenkernel/intern/smoke.c +++ b/source/blender/blenkernel/intern/smoke.c @@ -1776,6 +1776,8 @@ static void update_flowsfluids(Scene *scene, Object *ob, SmokeDomainSettings *sd dy = gy - sds->res_min[1]; dz = gz - sds->res_min[2]; d_index = smoke_get_index(dx, sds->res[0], dy, sds->res[1], dz); + /* make sure emission cell is inside the new domain boundary */ + if (dx < 0 || dy < 0 || dz < 0 || dx >= sds->res[0] || dy >= sds->res[1] || dz >= sds->res[2]) continue; if (sfs->type == MOD_SMOKE_FLOW_TYPE_OUTFLOW) { // outflow apply_outflow_fields(d_index, density, heat, fuel, react, color_r, color_g, color_b); @@ -2284,7 +2286,9 @@ struct DerivedMesh *smokeModifier_do(SmokeModifierData *smd, Scene *scene, Objec { return createDomainGeometry(smd->domain, ob); } - else return CDDM_copy(dm); + else { + return CDDM_copy(dm); + } } static float calc_voxel_transp(float *result, float *input, int res[3], int *pixel, float *tRay, float correct) diff --git a/source/blender/blenkernel/intern/softbody.c b/source/blender/blenkernel/intern/softbody.c index e2c6df5e528..8e5e0da20f9 100644 --- a/source/blender/blenkernel/intern/softbody.c +++ b/source/blender/blenkernel/intern/softbody.c @@ -200,18 +200,18 @@ static float sb_time_scale(Object *ob) SoftBody *sb= ob->soft; /* is supposed to be there */ if (sb) { return(sb->physics_speed); - /*hrms .. this could be IPO as well :) - estimated range [0.001 sluggish slug - 100.0 very fast (i hope ODE solver can handle that)] - 1 approx = a unit 1 pendulum at g = 9.8 [earth conditions] has period 65 frames - theory would give a 50 frames period .. so there must be something inaccurate .. looking for that (BM) + /* hrms .. this could be IPO as well :) + * estimated range [0.001 sluggish slug - 100.0 very fast (i hope ODE solver can handle that)] + * 1 approx = a unit 1 pendulum at g = 9.8 [earth conditions] has period 65 frames + * theory would give a 50 frames period .. so there must be something inaccurate .. looking for that (BM) */ } return (1.0f); /* - this would be frames/sec independent timing assuming 25 fps is default - but does not work very well with NLA - return (25.0f/scene->r.frs_sec) - */ + * this would be frames/sec independent timing assuming 25 fps is default + * but does not work very well with NLA + * return (25.0f/scene->r.frs_sec) + */ } /*--- frame based timing ---*/ @@ -1034,7 +1034,7 @@ static int sb_detect_aabb_collisionCached(float UNUSED(force[3]), unsigned int U hash = vertexowner->soft->scratch->colliderhash; ihash = BLI_ghashIterator_new(hash); - while (!BLI_ghashIterator_isDone(ihash) ) { + while (BLI_ghashIterator_notDone(ihash) ) { ccd_Mesh *ccdm = BLI_ghashIterator_getValue (ihash); ob = BLI_ghashIterator_getKey (ihash); @@ -1113,7 +1113,7 @@ static int sb_detect_face_pointCached(float face_v1[3], float face_v2[3], float hash = vertexowner->soft->scratch->colliderhash; ihash = BLI_ghashIterator_new(hash); - while (!BLI_ghashIterator_isDone(ihash) ) { + while (BLI_ghashIterator_notDone(ihash) ) { ccd_Mesh *ccdm = BLI_ghashIterator_getValue (ihash); ob = BLI_ghashIterator_getKey (ihash); @@ -1205,7 +1205,7 @@ static int sb_detect_face_collisionCached(float face_v1[3], float face_v2[3], fl hash = vertexowner->soft->scratch->colliderhash; ihash = BLI_ghashIterator_new(hash); - while (!BLI_ghashIterator_isDone(ihash) ) { + while (BLI_ghashIterator_notDone(ihash) ) { ccd_Mesh *ccdm = BLI_ghashIterator_getValue (ihash); ob = BLI_ghashIterator_getKey (ihash); @@ -1305,7 +1305,7 @@ static int sb_detect_face_collisionCached(float face_v1[3], float face_v2[3], fl normalize_v3(d_nvect); if ( /* isect_line_tri_v3(nv1, nv3, face_v1, face_v2, face_v3, &t, NULL) || - we did that edge already */ + * we did that edge already */ isect_line_tri_v3(nv3, nv4, face_v1, face_v2, face_v3, &t, NULL) || isect_line_tri_v3(nv4, nv1, face_v1, face_v2, face_v3, &t, NULL) ) { Vec3PlusStVec(force, -0.5f, d_nvect); @@ -1433,7 +1433,7 @@ static int sb_detect_edge_collisionCached(float edge_v1[3], float edge_v2[3], fl hash = vertexowner->soft->scratch->colliderhash; ihash = BLI_ghashIterator_new(hash); - while (!BLI_ghashIterator_isDone(ihash) ) { + while (BLI_ghashIterator_notDone(ihash) ) { ccd_Mesh *ccdm = BLI_ghashIterator_getValue (ihash); ob = BLI_ghashIterator_getKey (ihash); @@ -1763,7 +1763,7 @@ static int sb_detect_vertex_collisionCached(float opco[3], float facenormal[3], outerforceaccu[0]=outerforceaccu[1]=outerforceaccu[2]=0.0f; innerforceaccu[0]=innerforceaccu[1]=innerforceaccu[2]=0.0f; /* go */ - while (!BLI_ghashIterator_isDone(ihash) ) { + while (BLI_ghashIterator_notDone(ihash) ) { ccd_Mesh *ccdm = BLI_ghashIterator_getValue (ihash); ob = BLI_ghashIterator_getKey (ihash); diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c index 3c90da60103..3d633dc964a 100644 --- a/source/blender/blenkernel/intern/subsurf_ccg.c +++ b/source/blender/blenkernel/intern/subsurf_ccg.c @@ -3103,7 +3103,6 @@ static CCGDerivedMesh *getCCGDerivedMesh(CCGSubSurf *ss, int numTex, numCol; int hasPCol, hasOrigSpace; int gridInternalEdges; - float *w = NULL; WeightTable wtable = {0}; /* MCol *mcol; */ /* UNUSED */ MEdge *medge = NULL; @@ -3307,7 +3306,7 @@ static CCGDerivedMesh *getCCGDerivedMesh(CCGSubSurf *ss, int numFinalEdges = numVerts * (gridSideEdges + gridInternalEdges); int origIndex = GET_INT_FROM_POINTER(ccgSubSurf_getFaceFaceHandle(f)); int g2_wid = gridCuts + 2; - float *w2; + float *w, *w2; int s, x, y; w = get_ss_weights(&wtable, gridCuts, numVerts); @@ -3320,8 +3319,6 @@ static CCGDerivedMesh *getCCGDerivedMesh(CCGSubSurf *ss, faceFlags->mat_nr = mpoly ? mpoly[origIndex].mat_nr : 0; faceFlags++; - origIndex = base_polyOrigIndex ? base_polyOrigIndex[origIndex] : origIndex; - /* set the face base vert */ *((int *)ccgSubSurf_getFaceUserData(ss, f)) = vertNum; @@ -3429,7 +3426,7 @@ static CCGDerivedMesh *getCCGDerivedMesh(CCGSubSurf *ss, faceOrigIndex++; } if (polyOrigIndex) { - *polyOrigIndex = origIndex; + *polyOrigIndex = base_polyOrigIndex ? base_polyOrigIndex[origIndex] : origIndex; polyOrigIndex++; } diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c index 184984352ba..3936c533a41 100644 --- a/source/blender/blenkernel/intern/text.c +++ b/source/blender/blenkernel/intern/text.c @@ -791,6 +791,29 @@ int txt_utf8_index_to_offset(const char *str, int index) return offset; } +int txt_utf8_offset_to_column(const char *str, int offset) +{ + int column = 0, pos = 0; + while (pos < offset) { + column += BLI_str_utf8_char_width_safe(str + pos); + pos += BLI_str_utf8_size_safe(str + pos); + } + return column; +} + +int txt_utf8_column_to_offset(const char *str, int column) +{ + int offset = 0, pos = 0, col; + while (pos < column) { + col = BLI_str_utf8_char_width_safe(str + offset); + if (pos + col > column) + break; + offset += BLI_str_utf8_size_safe(str + offset); + pos += col; + } + return offset; +} + /* returns the real number of characters in string */ /* not the same as BLI_strlen_utf8, which returns length for wide characters */ static int txt_utf8_len(const char *src) @@ -804,6 +827,17 @@ static int txt_utf8_len(const char *src) return len; } +static int txt_utf8_width(const char *src) +{ + int col = 0; + + for (; *src; src += BLI_str_utf8_size(src)) { + col += BLI_str_utf8_char_width(src); + } + + return col; +} + void txt_move_up(Text *text, short sel) { TextLine **linep; @@ -815,10 +849,10 @@ void txt_move_up(Text *text, short sel) if (!*linep) return; if ((*linep)->prev) { - int index = txt_utf8_offset_to_index((*linep)->line, *charp); + int column = txt_utf8_offset_to_column((*linep)->line, *charp); *linep = (*linep)->prev; - if (index > txt_utf8_len((*linep)->line)) *charp = (*linep)->len; - else *charp = txt_utf8_index_to_offset((*linep)->line, index); + if (column > txt_utf8_width((*linep)->line)) *charp = (*linep)->len; + else *charp = txt_utf8_column_to_offset((*linep)->line, column); } else { @@ -839,10 +873,10 @@ void txt_move_down(Text *text, short sel) if (!*linep) return; if ((*linep)->next) { - int index = txt_utf8_offset_to_index((*linep)->line, *charp); + int column = txt_utf8_offset_to_column((*linep)->line, *charp); *linep = (*linep)->next; - if (index > txt_utf8_len((*linep)->line)) *charp = (*linep)->len; - else *charp = txt_utf8_index_to_offset((*linep)->line, index); + if (column > txt_utf8_width((*linep)->line)) *charp = (*linep)->len; + else *charp = txt_utf8_column_to_offset((*linep)->line, column); } else { txt_move_eol(text, sel); @@ -930,7 +964,9 @@ void txt_move_right(Text *text, short sel) tabsize++; (*charp) = i; } - else (*charp) += BLI_str_utf8_size((*linep)->line + *charp); + else { + (*charp) += BLI_str_utf8_size((*linep)->line + *charp); + } } if (!sel) txt_pop_sel(text); @@ -2825,7 +2861,7 @@ void txt_move_lines(struct Text *text, const int direction) } } -int setcurr_tab_spaces(Text *text, int space) +int txt_setcurr_tab_spaces(Text *text, int space) { int i = 0; int test = 0; diff --git a/source/blender/blenkernel/intern/texture.c b/source/blender/blenkernel/intern/texture.c index 55a0f3752a1..bdf2ce622de 100644 --- a/source/blender/blenkernel/intern/texture.c +++ b/source/blender/blenkernel/intern/texture.c @@ -256,7 +256,9 @@ int do_colorband(const ColorBand *coba, float in, float out[4]) left.pos = 0.0f; cbd2 = &left; } - else cbd2 = cbd1 - 1; + else { + cbd2 = cbd1 - 1; + } if (in >= cbd1->pos && coba->ipotype < 2) { out[0] = cbd1->r; @@ -440,7 +442,7 @@ void default_tex(Tex *tex) tex->type = TEX_CLOUDS; tex->stype = 0; tex->flag = TEX_CHECKER_ODD; - tex->imaflag = TEX_INTERPOL | TEX_MIPMAP; + tex->imaflag = TEX_INTERPOL | TEX_MIPMAP | TEX_USEALPHA; tex->extend = TEX_REPEAT; tex->cropxmin = tex->cropymin = 0.0; tex->cropxmax = tex->cropymax = 1.0; @@ -911,15 +913,18 @@ void autotexname(Tex *tex) else if (tex->type == TEX_IMAGE) { ima = tex->ima; if (ima) { - BLI_strncpy(di, ima->name, sizeof(di)); - BLI_splitdirstring(di, fi); + BLI_split_file_part(ima->name, fi, sizeof(fi)); strcpy(di, "I."); strcat(di, fi); new_id(&bmain->tex, (ID *)tex, di); } - else new_id(&bmain->tex, (ID *)tex, texstr[tex->type]); + else { + new_id(&bmain->tex, (ID *)tex, texstr[tex->type]); + } + } + else { + new_id(&bmain->tex, (ID *)tex, texstr[tex->type]); } - else new_id(&bmain->tex, (ID *)tex, texstr[tex->type]); } } #endif diff --git a/source/blender/blenkernel/intern/tracking.c b/source/blender/blenkernel/intern/tracking.c index f63a1f2cec0..df10d1374bb 100644 --- a/source/blender/blenkernel/intern/tracking.c +++ b/source/blender/blenkernel/intern/tracking.c @@ -261,7 +261,9 @@ void BKE_tracking_get_projection_matrix(MovieTracking *tracking, MovieTrackingOb invert_m4_m4(imat, camera->mat); mult_m4_m4m4(mat, winmat, imat); } - else copy_m4_m4(mat, winmat); + else { + copy_m4_m4(mat, winmat); + } } /* **** space transformation functions **** */ @@ -1189,6 +1191,7 @@ MovieTrackingObject *BKE_tracking_object_add(MovieTracking *tracking, const char object->keyframe2 = 30; BKE_tracking_object_unique_name(tracking, object); + BKE_tracking_dopesheet_tag_update(tracking); return object; } @@ -1223,6 +1226,9 @@ int BKE_tracking_object_delete(MovieTracking *tracking, MovieTrackingObject *obj tracking->objectnr = index - 1; else tracking->objectnr = 0; + + BKE_tracking_dopesheet_tag_update(tracking); + return TRUE; } @@ -1446,7 +1452,7 @@ static void cameraIntrinscisOptionsFromTracking(libmv_cameraIntrinsicsOptions *c camera_intrinsics_options->k3 = camera->k3; camera_intrinsics_options->image_width = calibration_width; - camera_intrinsics_options->image_height = (double) calibration_height * aspy; + camera_intrinsics_options->image_height = (double) (calibration_height * aspy); } #endif @@ -1456,6 +1462,10 @@ MovieDistortion *BKE_tracking_distortion_new(void) distortion = MEM_callocN(sizeof(MovieDistortion), "BKE_tracking_distortion_create"); +#ifdef WITH_LIBMV + distortion->intrinsics = libmv_CameraIntrinsicsNewEmpty(); +#endif + return distortion; } @@ -1468,12 +1478,7 @@ void BKE_tracking_distortion_update(MovieDistortion *distortion, MovieTracking * cameraIntrinscisOptionsFromTracking(&camera_intrinsics_options, tracking, calibration_width, calibration_height); - if (!distortion->intrinsics) { - distortion->intrinsics = libmv_CameraIntrinsicsNew(&camera_intrinsics_options); - } - else { - libmv_CameraIntrinsicsUpdate(distortion->intrinsics, &camera_intrinsics_options); - } + libmv_CameraIntrinsicsUpdate(distortion->intrinsics, &camera_intrinsics_options); #else (void) distortion; (void) tracking; @@ -1482,6 +1487,16 @@ void BKE_tracking_distortion_update(MovieDistortion *distortion, MovieTracking * #endif } +void BKE_tracking_distortion_set_threads(MovieDistortion *distortion, int threads) +{ +#ifdef WITH_LIBMV + libmv_CameraIntrinsicsSetThreads(distortion->intrinsics, threads); +#else + (void) distortion; + (void) threads; +#endif +} + MovieDistortion *BKE_tracking_distortion_copy(MovieDistortion *distortion) { MovieDistortion *new_distortion; @@ -1594,8 +1609,8 @@ void BKE_tracking_undistort_v2(MovieTracking *tracking, const float co[2], float libmv_InvertIntrinsics(&camera_intrinsics_options, x, y, &x, &y); - r_co[0] = x * camera->focal + camera->principal[0]; - r_co[1] = y * camera->focal + camera->principal[1] * aspy; + r_co[0] = (float)x * camera->focal + camera->principal[0]; + r_co[1] = (float)y * camera->focal + camera->principal[1] * aspy; #else (void) camera; (void) co; @@ -1699,7 +1714,7 @@ static void disable_imbuf_channels(ImBuf *ibuf, MovieTrackingTrack *track, int g ImBuf *BKE_tracking_sample_pattern(int frame_width, int frame_height, ImBuf *search_ibuf, MovieTrackingTrack *track, MovieTrackingMarker *marker, - int use_mask, int num_samples_x, int num_samples_y, + int from_anchor, int use_mask, int num_samples_x, int num_samples_y, float pos[2]) { #ifdef WITH_LIBMV @@ -1719,6 +1734,28 @@ ImBuf *BKE_tracking_sample_pattern(int frame_width, int frame_height, ImBuf *sea get_marker_coords_for_tracking(frame_width, frame_height, marker, src_pixel_x, src_pixel_y); + /* from_anchor means search buffer was obtained for an anchored position, + * which means applying track offset rounded to pixel space (we could not + * store search buffer with sub-pixel precision) + * + * in this case we need to alter coordinates a bit, to compensate rounded + * fractional part of offset + */ + if (from_anchor) { + int a; + + for (a = 0; a < 5; a++) { + src_pixel_x[a] += (double) ((track->offset[0] * frame_width) - ((int) (track->offset[0] * frame_width))); + src_pixel_y[a] += (double) ((track->offset[1] * frame_height) - ((int) (track->offset[1] * frame_height))); + + /* when offset is negative, rounding happens in opposite direction */ + if (track->offset[0] < 0.0f) + src_pixel_x[a] += 1.0; + if (track->offset[1] < 0.0f) + src_pixel_y[a] += 1.0; + } + } + if (use_mask) { mask = BKE_tracking_track_get_mask(frame_width, frame_height, track, marker); } @@ -1751,6 +1788,7 @@ ImBuf *BKE_tracking_sample_pattern(int frame_width, int frame_height, ImBuf *sea (void) frame_height; (void) search_ibuf; (void) marker; + (void) from_anchor; (void) track; (void) use_mask; @@ -1779,7 +1817,7 @@ ImBuf *BKE_tracking_get_pattern_imbuf(ImBuf *ibuf, MovieTrackingTrack *track, Mo if (search_ibuf) { pattern_ibuf = BKE_tracking_sample_pattern(ibuf->x, ibuf->y, search_ibuf, track, marker, - FALSE, num_samples_x, num_samples_y, NULL); + anchored, FALSE, num_samples_x, num_samples_y, NULL); IMB_freeImBuf(search_ibuf); } @@ -2726,7 +2764,7 @@ static void reconstruct_retrieve_libmv_intrinscis(MovieReconstructContext *conte tracking->camera.focal = focal_length; tracking->camera.principal[0] = principal_x; - tracking->camera.principal[1] = principal_y / aspy; + tracking->camera.principal[1] = principal_y / (double)aspy; tracking->camera.k1 = k1; tracking->camera.k2 = k2; diff --git a/source/blender/blenkernel/intern/unit.c b/source/blender/blenkernel/intern/unit.c index dd6ed42bd92..066b6eff5c5 100644 --- a/source/blender/blenkernel/intern/unit.c +++ b/source/blender/blenkernel/intern/unit.c @@ -104,7 +104,7 @@ typedef struct bUnitCollection { /* Dummy */ static struct bUnitDef buDummyDef[] = { {"", NULL, "", NULL, NULL, 1.0, 0.0}, {NULL, NULL, NULL, NULL, NULL, 0.0, 0.0}}; -static struct bUnitCollection buDummyCollecton = {buDummyDef, 0, 0, sizeof(buDummyDef)}; +static struct bUnitCollection buDummyCollection = {buDummyDef, 0, 0, sizeof(buDummyDef)}; /* Lengths */ static struct bUnitDef buMetricLenDef[] = { @@ -125,7 +125,7 @@ static struct bUnitDef buMetricLenDef[] = { #endif {NULL, NULL, NULL, NULL, NULL, 0.0, 0.0} }; -static struct bUnitCollection buMetricLenCollecton = {buMetricLenDef, 3, 0, sizeof(buMetricLenDef) / sizeof(bUnitDef)}; +static struct bUnitCollection buMetricLenCollection = {buMetricLenDef, 3, 0, sizeof(buMetricLenDef) / sizeof(bUnitDef)}; static struct bUnitDef buImperialLenDef[] = { {"mile", "miles", "mi", "m", "Miles", UN_SC_MI, 0.0, B_UNIT_DEF_NONE}, @@ -137,7 +137,7 @@ static struct bUnitDef buImperialLenDef[] = { {"thou", "thou", "thou", "mil", "Thou", UN_SC_MIL, 0.0, B_UNIT_DEF_NONE}, /* plural for thou has no 's' */ {NULL, NULL, NULL, NULL, NULL, 0.0, 0.0} }; -static struct bUnitCollection buImperialLenCollecton = {buImperialLenDef, 4, 0, sizeof(buImperialLenDef) / sizeof(bUnitDef)}; +static struct bUnitCollection buImperialLenCollection = {buImperialLenDef, 4, 0, sizeof(buImperialLenDef) / sizeof(bUnitDef)}; /* Areas */ static struct bUnitDef buMetricAreaDef[] = { @@ -151,7 +151,7 @@ static struct bUnitDef buMetricAreaDef[] = { {"square micrometer", "square micrometers", "µm²", "um2", "Square Micrometers", UN_SC_UM * UN_SC_UM, 0.0, B_UNIT_DEF_NONE}, {NULL, NULL, NULL, NULL, NULL, 0.0, 0.0} }; -static struct bUnitCollection buMetricAreaCollecton = {buMetricAreaDef, 3, 0, sizeof(buMetricAreaDef) / sizeof(bUnitDef)}; +static struct bUnitCollection buMetricAreaCollection = {buMetricAreaDef, 3, 0, sizeof(buMetricAreaDef) / sizeof(bUnitDef)}; static struct bUnitDef buImperialAreaDef[] = { {"square mile", "square miles", "sq mi", "sq m", "Square Miles", UN_SC_MI * UN_SC_MI, 0.0, B_UNIT_DEF_NONE}, @@ -163,7 +163,7 @@ static struct bUnitDef buImperialAreaDef[] = { {"square thou", "square thous", "sq mil", NULL, "Square Thous", UN_SC_MIL * UN_SC_MIL, 0.0, B_UNIT_DEF_NONE}, {NULL, NULL, NULL, NULL, NULL, 0.0, 0.0} }; -static struct bUnitCollection buImperialAreaCollecton = {buImperialAreaDef, 4, 0, sizeof(buImperialAreaDef) / sizeof(bUnitDef)}; +static struct bUnitCollection buImperialAreaCollection = {buImperialAreaDef, 4, 0, sizeof(buImperialAreaDef) / sizeof(bUnitDef)}; /* Volumes */ static struct bUnitDef buMetricVolDef[] = { @@ -177,7 +177,7 @@ static struct bUnitDef buMetricVolDef[] = { {"cubic micrometer", "cubic micrometers", "µm³", "um3", "Cubic Micrometers", UN_SC_UM * UN_SC_UM * UN_SC_UM, 0.0, B_UNIT_DEF_NONE}, {NULL, NULL, NULL, NULL, NULL, 0.0, 0.0} }; -static struct bUnitCollection buMetricVolCollecton = {buMetricVolDef, 3, 0, sizeof(buMetricVolDef) / sizeof(bUnitDef)}; +static struct bUnitCollection buMetricVolCollection = {buMetricVolDef, 3, 0, sizeof(buMetricVolDef) / sizeof(bUnitDef)}; static struct bUnitDef buImperialVolDef[] = { {"cubic mile", "cubic miles", "cu mi", "cu m", "Cubic Miles", UN_SC_MI * UN_SC_MI * UN_SC_MI, 0.0, B_UNIT_DEF_NONE}, @@ -189,7 +189,7 @@ static struct bUnitDef buImperialVolDef[] = { {"cubic thou", "cubic thous", "cu mil", NULL, "Cubic Thous", UN_SC_MIL * UN_SC_MIL * UN_SC_MIL, 0.0, B_UNIT_DEF_NONE}, {NULL, NULL, NULL, NULL, NULL, 0.0, 0.0} }; -static struct bUnitCollection buImperialVolCollecton = {buImperialVolDef, 4, 0, sizeof(buImperialVolDef) / sizeof(bUnitDef)}; +static struct bUnitCollection buImperialVolCollection = {buImperialVolDef, 4, 0, sizeof(buImperialVolDef) / sizeof(bUnitDef)}; /* Mass */ static struct bUnitDef buMetricMassDef[] = { @@ -201,7 +201,7 @@ static struct bUnitDef buMetricMassDef[] = { {"gram", "grams", "g", NULL, "Grams", UN_SC_G, 0.0, B_UNIT_DEF_NONE}, {NULL, NULL, NULL, NULL, NULL, 0.0, 0.0} }; -static struct bUnitCollection buMetricMassCollecton = {buMetricMassDef, 2, 0, sizeof(buMetricMassDef) / sizeof(bUnitDef)}; +static struct bUnitCollection buMetricMassCollection = {buMetricMassDef, 2, 0, sizeof(buMetricMassDef) / sizeof(bUnitDef)}; static struct bUnitDef buImperialMassDef[] = { {"ton", "tonnes", "ton", "t", "Tonnes", UN_SC_ITON, 0.0, B_UNIT_DEF_NONE}, @@ -211,7 +211,7 @@ static struct bUnitDef buImperialMassDef[] = { {"ounce", "ounces", "oz", NULL, "Ounces", UN_SC_OZ, 0.0, B_UNIT_DEF_NONE}, {NULL, NULL, NULL, NULL, NULL, 0.0, 0.0} }; -static struct bUnitCollection buImperialMassCollecton = {buImperialMassDef, 3, 0, sizeof(buImperialMassDef) / sizeof(bUnitDef)}; +static struct bUnitCollection buImperialMassCollection = {buImperialMassDef, 3, 0, sizeof(buImperialMassDef) / sizeof(bUnitDef)}; /* Even if user scales the system to a point where km^3 is used, velocity and * acceleration aren't scaled: that's why we have so few units for them */ @@ -222,27 +222,27 @@ static struct bUnitDef buMetricVelDef[] = { {"kilometer per hour", "kilometers per hour", "km/h", NULL, "Kilometers per hour", UN_SC_KM / 3600.0f, 0.0, B_UNIT_DEF_SUPPRESS}, {NULL, NULL, NULL, NULL, NULL, 0.0, 0.0} }; -static struct bUnitCollection buMetricVelCollecton = {buMetricVelDef, 0, 0, sizeof(buMetricVelDef) / sizeof(bUnitDef)}; +static struct bUnitCollection buMetricVelCollection = {buMetricVelDef, 0, 0, sizeof(buMetricVelDef) / sizeof(bUnitDef)}; static struct bUnitDef buImperialVelDef[] = { {"foot per second", "feet per second", "ft/s", "fps", "Feet per second", UN_SC_FT, 0.0, B_UNIT_DEF_NONE}, /* base unit */ {"mile per hour", "miles per hour", "mph", NULL, "Miles per hour", UN_SC_MI / 3600.0f, 0.0, B_UNIT_DEF_SUPPRESS}, {NULL, NULL, NULL, NULL, NULL, 0.0, 0.0} }; -static struct bUnitCollection buImperialVelCollecton = {buImperialVelDef, 0, 0, sizeof(buImperialVelDef) / sizeof(bUnitDef)}; +static struct bUnitCollection buImperialVelCollection = {buImperialVelDef, 0, 0, sizeof(buImperialVelDef) / sizeof(bUnitDef)}; /* Acceleration */ static struct bUnitDef buMetricAclDef[] = { {"meter per second squared", "meters per second squared", "m/s²", "m/s2", "Meters per second squared", UN_SC_M, 0.0, B_UNIT_DEF_NONE}, /* base unit */ {NULL, NULL, NULL, NULL, NULL, 0.0, 0.0} }; -static struct bUnitCollection buMetricAclCollecton = {buMetricAclDef, 0, 0, sizeof(buMetricAclDef) / sizeof(bUnitDef)}; +static struct bUnitCollection buMetricAclCollection = {buMetricAclDef, 0, 0, sizeof(buMetricAclDef) / sizeof(bUnitDef)}; static struct bUnitDef buImperialAclDef[] = { {"foot per second squared", "feet per second squared", "ft/s²", "ft/s2", "Feet per second squared", UN_SC_FT, 0.0, B_UNIT_DEF_NONE}, /* base unit */ {NULL, NULL, NULL, NULL, NULL, 0.0, 0.0} }; -static struct bUnitCollection buImperialAclCollecton = {buImperialAclDef, 0, 0, sizeof(buImperialAclDef) / sizeof(bUnitDef)}; +static struct bUnitCollection buImperialAclCollection = {buImperialAclDef, 0, 0, sizeof(buImperialAclDef) / sizeof(bUnitDef)}; /* Time */ static struct bUnitDef buNaturalTimeDef[] = { @@ -255,7 +255,7 @@ static struct bUnitDef buNaturalTimeDef[] = { {"microsecond", "microseconds", "µs", "us", "Microseconds", 0.000001, 0.0, B_UNIT_DEF_NONE}, {NULL, NULL, NULL, NULL, NULL, 0.0, 0.0} }; -static struct bUnitCollection buNaturalTimeCollecton = {buNaturalTimeDef, 3, 0, sizeof(buNaturalTimeDef) / sizeof(bUnitDef)}; +static struct bUnitCollection buNaturalTimeCollection = {buNaturalTimeDef, 3, 0, sizeof(buNaturalTimeDef) / sizeof(bUnitDef)}; static struct bUnitDef buNaturalRotDef[] = { @@ -266,12 +266,24 @@ static struct bUnitDef buNaturalRotDef[] = { }; static struct bUnitCollection buNaturalRotCollection = {buNaturalRotDef, 0, 0, sizeof(buNaturalRotDef) / sizeof(bUnitDef)}; -#define UNIT_SYSTEM_TOT (((sizeof(bUnitSystems) / 9) / sizeof(void *)) - 1) -static struct bUnitCollection *bUnitSystems[][9] = { - {NULL, NULL, NULL, NULL, NULL, &buNaturalRotCollection, &buNaturalTimeCollecton, NULL, NULL}, - {NULL, &buMetricLenCollecton, &buMetricAreaCollecton, &buMetricVolCollecton, &buMetricMassCollecton, &buNaturalRotCollection, &buNaturalTimeCollecton, &buMetricVelCollecton, &buMetricAclCollecton}, /* metric */ - {NULL, &buImperialLenCollecton, &buImperialAreaCollecton, &buImperialVolCollecton, &buImperialMassCollecton, &buNaturalRotCollection, &buNaturalTimeCollecton, &buImperialVelCollecton, &buImperialAclCollecton}, /* imperial */ - {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL} +/* Camera Lengths */ +static struct bUnitDef buCameraLenDef[] = { + {"meter", "meters", "m", NULL, "Meters", UN_SC_KM, 0.0, B_UNIT_DEF_NONE}, /* base unit */ + {"decimeter", "decimeters", "dm", NULL, "10 Centimeters", UN_SC_HM, 0.0, B_UNIT_DEF_SUPPRESS}, + {"centimeter", "centimeters", "cm", NULL, "Centimeters", UN_SC_DAM, 0.0, B_UNIT_DEF_SUPPRESS}, + {"millimeter", "millimeters", "mm", NULL, "Millimeters", UN_SC_M, 0.0, B_UNIT_DEF_NONE}, + {"micrometer", "micrometers", "µm", "um", "Micrometers", UN_SC_MM, 0.0, B_UNIT_DEF_SUPPRESS}, // micron too? + {NULL, NULL, NULL, NULL, NULL, 0.0, 0.0} +}; +static struct bUnitCollection buCameraLenCollection = {buCameraLenDef, 3, 0, sizeof(buCameraLenDef) / sizeof(bUnitDef)}; + + +#define UNIT_SYSTEM_TOT (((sizeof(bUnitSystems) / B_UNIT_TYPE_TOT) / sizeof(void *)) - 1) +static struct bUnitCollection *bUnitSystems[][B_UNIT_TYPE_TOT] = { + {NULL, NULL, NULL, NULL, NULL, &buNaturalRotCollection, &buNaturalTimeCollection, NULL, NULL, NULL}, + {NULL, &buMetricLenCollection, &buMetricAreaCollection, &buMetricVolCollection, &buMetricMassCollection, &buNaturalRotCollection, &buNaturalTimeCollection, &buMetricVelCollection, &buMetricAclCollection, &buCameraLenCollection}, /* metric */ + {NULL, &buImperialLenCollection, &buImperialAreaCollection, &buImperialVolCollection, &buImperialMassCollection, &buNaturalRotCollection, &buNaturalTimeCollection, &buImperialVelCollection, &buImperialAclCollection, &buCameraLenCollection}, /* imperial */ + {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL} }; @@ -395,10 +407,10 @@ void bUnit_AsString(char *str, int len_max, double value, int prec, int system, bUnitCollection *usys = unit_get_system(system, type); if (usys == NULL || usys->units[0].name == NULL) - usys = &buDummyCollecton; + usys = &buDummyCollection; /* split output makes sense only for length, mass and time */ - if (split && (type == B_UNIT_LENGTH || type == B_UNIT_MASS || type == B_UNIT_TIME)) { + if (split && (type == B_UNIT_LENGTH || type == B_UNIT_MASS || type == B_UNIT_TIME || type == B_UNIT_CAMERA)) { bUnitDef *unit_a, *unit_b; double value_a, value_b; @@ -706,7 +718,7 @@ void bUnit_ToUnitAltName(char *str, int len_max, const char *orig_str, int syste /* print the alt_name */ if (unit->name_alt) - len_name = BLI_snprintf(str, len_max, "%s", unit->name_alt); + len_name = BLI_strncpy_rlen(str, unit->name_alt, len_max); else len_name = 0; diff --git a/source/blender/blenkernel/intern/writeffmpeg.c b/source/blender/blenkernel/intern/writeffmpeg.c index 7e51025883d..a88a9e4954b 100644 --- a/source/blender/blenkernel/intern/writeffmpeg.c +++ b/source/blender/blenkernel/intern/writeffmpeg.c @@ -111,8 +111,9 @@ static void delete_picture(AVFrame *f) } } -static int use_float_audio_buffer(int codec_id) +static int request_float_audio_buffer(int codec_id) { + /* If any of these codecs, we prefer the float sample format (if supported) */ return codec_id == CODEC_ID_AAC || codec_id == CODEC_ID_AC3 || codec_id == CODEC_ID_VORBIS; } @@ -551,6 +552,12 @@ static AVStream *alloc_video_stream(RenderData *rd, int codec_id, AVFormatContex } } + if (codec_id == CODEC_ID_PNG) { + if (rd->im_format.planes == R_IMF_PLANES_RGBA) { + c->pix_fmt = PIX_FMT_ARGB; + } + } + if ((of->oformat->flags & AVFMT_GLOBALHEADER) // || !strcmp(of->oformat->name, "mp4") // || !strcmp(of->oformat->name, "mov") @@ -623,16 +630,55 @@ static AVStream *alloc_audio_stream(RenderData *rd, int codec_id, AVFormatContex c->bit_rate = ffmpeg_audio_bitrate * 1000; c->sample_fmt = AV_SAMPLE_FMT_S16; c->channels = rd->ffcodecdata.audio_channels; - if (use_float_audio_buffer(codec_id)) { + + if (request_float_audio_buffer(codec_id)) { + /* mainly for AAC codec which is experimental */ c->strict_std_compliance = FF_COMPLIANCE_EXPERIMENTAL; c->sample_fmt = AV_SAMPLE_FMT_FLT; } + codec = avcodec_find_encoder(c->codec_id); if (!codec) { //XXX error("Couldn't find a valid audio codec"); return NULL; } + if (codec->sample_fmts) { + /* check if the prefered sample format for this codec is supported. + * this is because, depending on the version of libav, and with the whole ffmpeg/libav fork situation, + * you have various implementations around. float samples in particular are not always supported. + */ + const enum AVSampleFormat *p = codec->sample_fmts; + for (; *p!=-1; p++) { + if (*p == st->codec->sample_fmt) + break; + } + if (*p == -1) { + /* sample format incompatible with codec. Defaulting to a format known to work */ + st->codec->sample_fmt = codec->sample_fmts[0]; + } + } + + if (c->sample_fmt == AV_SAMPLE_FMT_FLTP) { + BLI_strncpy(error, "Requested audio codec requires planar float sample format, which is not supported yet", error_size); + return NULL; + } + + if (codec->supported_samplerates) { + const int *p = codec->supported_samplerates; + int best = 0; + int best_dist = INT_MAX; + for (; *p; p++) { + int dist = abs(st->codec->sample_rate - *p); + if (dist < best_dist) { + best_dist = dist; + best = *p; + } + } + /* best is the closest supported sample rate (same as selected if best_dist == 0) */ + st->codec->sample_rate = best; + } + set_ffmpeg_properties(rd, c, "audio"); if (avcodec_open2(c, codec, NULL) < 0) { @@ -658,7 +704,7 @@ static AVStream *alloc_audio_stream(RenderData *rd, int codec_id, AVFormatContex audio_output_buffer = (uint8_t *) av_malloc(audio_outbuf_size); - if (use_float_audio_buffer(codec_id)) { + if (c->sample_fmt == AV_SAMPLE_FMT_FLT) { audio_input_buffer = (uint8_t *) av_malloc(audio_input_samples * c->channels * sizeof(float)); } else { @@ -740,7 +786,7 @@ static int start_ffmpeg_impl(struct RenderData *rd, int rectx, int recty, Report fmt->audio_codec = ffmpeg_audio_codec; - BLI_snprintf(of->filename, sizeof(of->filename), "%s", name); + BLI_strncpy(of->filename, name, sizeof(of->filename)); /* set the codec to the user's selection */ switch (ffmpeg_type) { case FFMPEG_AVI: @@ -837,7 +883,8 @@ static int start_ffmpeg_impl(struct RenderData *rd, int rectx, int recty, Report } if (avformat_write_header(of, NULL) < 0) { BKE_report(reports, RPT_ERROR, "Could not initialize streams, probably unsupported codec combination"); - av_dict_free(&opts); + av_dict_free(&opts); + avio_close(of->pb); return 0; } @@ -963,7 +1010,7 @@ int BKE_ffmpeg_start(struct Scene *scene, RenderData *rd, int rectx, int recty, AVCodecContext *c = audio_stream->codec; AUD_DeviceSpecs specs; specs.channels = c->channels; - if (use_float_audio_buffer(c->codec_id)) { + if (c->sample_fmt == AV_SAMPLE_FMT_FLT) { specs.format = AUD_FORMAT_FLOAT32; } else { @@ -980,7 +1027,6 @@ int BKE_ffmpeg_start(struct Scene *scene, RenderData *rd, int rectx, int recty, return success; } -void BKE_ffmpeg_end(void); static void end_ffmpeg_impl(int is_autosplit); #ifdef WITH_AUDASPACE @@ -1493,6 +1539,9 @@ int BKE_ffmpeg_alpha_channel_is_supported(RenderData *rd) if (codec == CODEC_ID_QTRLE) return TRUE; + if (codec == CODEC_ID_PNG) + return TRUE; + #ifdef FFMPEG_FFV1_ALPHA_SUPPORTED if (codec == CODEC_ID_FFV1) return TRUE; |