diff options
Diffstat (limited to 'source/blender/blenkernel')
41 files changed, 454 insertions, 461 deletions
diff --git a/source/blender/blenkernel/BKE_animsys.h b/source/blender/blenkernel/BKE_animsys.h index 80d2750fe82..e79822daa4d 100644 --- a/source/blender/blenkernel/BKE_animsys.h +++ b/source/blender/blenkernel/BKE_animsys.h @@ -37,8 +37,10 @@ struct Main; struct AnimData; struct KeyingSet; struct KS_Path; +struct bContext; struct PointerRNA; +struct PropertyRNA; struct ReportList; struct bAction; struct bActionGroup; @@ -127,6 +129,9 @@ void BKE_animdata_separate_by_basepath(struct ID *srcID, struct ID *dstID, struc /* Move F-Curves from src to destination if it's path is based on basepath */ void action_move_fcurves_by_basepath(struct bAction *srcAct, struct bAction *dstAct, const char basepath[]); +char *BKE_animdata_driver_path_hack(struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA *prop, + char *base_path); + /* ************************************* */ /* Batch AnimData API */ diff --git a/source/blender/blenkernel/BKE_blender.h b/source/blender/blenkernel/BKE_blender.h index 46a0c36a5f2..6c8f90c60ae 100644 --- a/source/blender/blenkernel/BKE_blender.h +++ b/source/blender/blenkernel/BKE_blender.h @@ -41,8 +41,8 @@ extern "C" { /* these lines are grep'd, watch out for our not-so-awesome regex * and keep comment above the defines. * Use STRINGIFY() rather than defining with quotes */ -#define BLENDER_VERSION 271 -#define BLENDER_SUBVERSION 6 +#define BLENDER_VERSION 272 +#define BLENDER_SUBVERSION 1 /* 262 was the last editmesh release but it has compatibility code for bmesh data */ #define BLENDER_MINVERSION 270 #define BLENDER_MINSUBVERSION 5 diff --git a/source/blender/blenkernel/BKE_customdata.h b/source/blender/blenkernel/BKE_customdata.h index 5a1e173f0b3..9a6524cc9ab 100644 --- a/source/blender/blenkernel/BKE_customdata.h +++ b/source/blender/blenkernel/BKE_customdata.h @@ -310,7 +310,7 @@ void CustomData_set_layer_flag(struct CustomData *data, int type, int flag); void CustomData_bmesh_set_default(struct CustomData *data, void **block); void CustomData_bmesh_free_block(struct CustomData *data, void **block); -void CustomData_bmesh_free_block_data(struct CustomData *data, void **block); +void CustomData_bmesh_free_block_data(struct CustomData *data, void *block); /* copy custom data to/from layers as in mesh/derivedmesh, to editmesh * blocks of data. the CustomData's must not be compatible */ diff --git a/source/blender/blenkernel/BKE_fcurve.h b/source/blender/blenkernel/BKE_fcurve.h index 0e86be9b97c..c377769b271 100644 --- a/source/blender/blenkernel/BKE_fcurve.h +++ b/source/blender/blenkernel/BKE_fcurve.h @@ -43,6 +43,7 @@ struct DriverVar; struct DriverTarget; struct FCM_EnvelopeData; +struct bContext; struct bAction; struct BezTriple; struct StructRNA; @@ -221,8 +222,12 @@ struct FCurve *id_data_find_fcurve(ID *id, void *data, struct StructRNA *type, c */ int list_find_data_fcurves(ListBase *dst, ListBase *src, const char *dataPrefix, const char *dataName); -/* find an f-curve based on an rna property */ -struct FCurve *rna_get_fcurve(struct PointerRNA *ptr, struct PropertyRNA *prop, int rnaindex, struct bAction **action, bool *r_driven); +/* find an f-curve based on an rna property. */ +struct FCurve *rna_get_fcurve(struct PointerRNA *ptr, struct PropertyRNA *prop, int rnaindex, + struct bAction **action, bool *r_driven); +/* Same as above, but takes a context data, temp hack needed for complex paths like texture ones. */ +struct FCurve *rna_get_fcurve_context_ui(struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA *prop, + int rnaindex, struct bAction **action, bool *r_driven); /* Binary search algorithm for finding where to 'insert' BezTriple with given frame number. * Returns the index to insert at (data already at that index will be offset if replace is 0) diff --git a/source/blender/blenkernel/BKE_library.h b/source/blender/blenkernel/BKE_library.h index 1d37f9e64e1..500c2813a75 100644 --- a/source/blender/blenkernel/BKE_library.h +++ b/source/blender/blenkernel/BKE_library.h @@ -71,8 +71,8 @@ void id_clear_lib_data(struct Main *bmain, struct ID *id); struct ListBase *which_libbase(struct Main *mainlib, short type); -#define MAX_LIBARRAY 43 -int set_listbasepointers(struct Main *main, struct ListBase **lb); +#define MAX_LIBARRAY 35 +int set_listbasepointers(struct Main *main, struct ListBase *lb[MAX_LIBARRAY]); void BKE_libblock_free(struct Main *bmain, void *idv); void BKE_libblock_free_ex(struct Main *bmain, void *idv, bool do_id_user); diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h index a81da8c18af..b080ca37e67 100644 --- a/source/blender/blenkernel/BKE_paint.h +++ b/source/blender/blenkernel/BKE_paint.h @@ -50,6 +50,7 @@ struct PaintCurve; struct Palette; struct PaletteColor; struct PBVH; +struct ReportList; struct Scene; struct Sculpt; struct StrokeCache; @@ -100,7 +101,6 @@ void BKE_paint_set_overlay_override(enum OverlayFlags flag); void BKE_palette_free(struct Palette *palette); struct Palette *BKE_palette_add(struct Main *bmain, const char *name); struct PaletteColor *BKE_palette_color_add(struct Palette *palette); -void BKE_palette_color_delete(struct Palette *palette); bool BKE_palette_is_empty(const struct Palette *palette); void BKE_palette_color_remove(struct Palette *palette, struct PaletteColor *color); void BKE_palette_cleanup(struct Palette *palette); @@ -122,6 +122,9 @@ struct Palette *BKE_paint_palette(struct Paint *paint); void BKE_paint_palette_set(struct Paint *p, struct Palette *palette); void BKE_paint_curve_set(struct Brush *br, struct PaintCurve *pc); +void BKE_paint_data_warning(struct ReportList *reports, bool uvs, bool mat, bool tex, bool stencil); +bool BKE_paint_proj_mesh_data_check(struct Scene *scene, struct Object *ob, bool *uvs, bool *mat, bool *tex, bool *stencil); + /* testing face select mode * Texture paint could be removed since selected faces are not used * however hiding faces is useful */ diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index 9ff9991f5a6..81c03d8081b 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -2602,8 +2602,6 @@ static void make_vertexcos__mapFunc(void *userData, int index, const float co[3] void mesh_get_mapped_verts_coords(DerivedMesh *dm, float (*r_cos)[3], const int totcos) { - float (*vertexcos)[3]; - if (dm->foreachMappedVert) { MappedUserData userData; memset(r_cos, 0, sizeof(*r_cos) * totcos); @@ -2615,7 +2613,7 @@ void mesh_get_mapped_verts_coords(DerivedMesh *dm, float (*r_cos)[3], const int else { int i; for (i = 0; i < totcos; i++) { - dm->getVertCo(dm, i, vertexcos[i]); + dm->getVertCo(dm, i, r_cos[i]); } } } diff --git a/source/blender/blenkernel/intern/anim_sys.c b/source/blender/blenkernel/intern/anim_sys.c index 5ee82bb5842..2fb832dc72d 100644 --- a/source/blender/blenkernel/intern/anim_sys.c +++ b/source/blender/blenkernel/intern/anim_sys.c @@ -51,18 +51,23 @@ #include "DNA_material_types.h" #include "DNA_object_types.h" #include "DNA_scene_types.h" +#include "DNA_screen_types.h" +#include "DNA_space_types.h" #include "DNA_texture_types.h" #include "DNA_world_types.h" #include "BKE_animsys.h" #include "BKE_action.h" +#include "BKE_context.h" #include "BKE_depsgraph.h" #include "BKE_fcurve.h" #include "BKE_nla.h" #include "BKE_global.h" #include "BKE_main.h" +#include "BKE_material.h" #include "BKE_library.h" #include "BKE_report.h" +#include "BKE_texture.h" #include "RNA_access.h" @@ -551,6 +556,74 @@ void BKE_animdata_separate_by_basepath(ID *srcID, ID *dstID, ListBase *basepaths } } +/** + * Temporary wrapper for driver operators for buttons to make it easier to create + * such drivers by rerouting all paths through the active object instead so that + * they will get picked up by the dependency system. + * + * \param C Context pointer - for getting active data + * \param[in,out] ptr RNA pointer for property's datablock. May be modified as result of path remapping. + * \param prop RNA definition of property to add for + * \return MEM_alloc'd string representing the path to the property from the given #PointerRNA + */ +char *BKE_animdata_driver_path_hack(bContext *C, PointerRNA *ptr, PropertyRNA *prop, char *base_path) +{ + ID *id = (ID *)ptr->id.data; + ScrArea *sa = CTX_wm_area(C); + + /* get standard path which may be extended */ + char *basepath = base_path ? base_path : RNA_path_from_ID_to_property(ptr, prop); + char *path = basepath; /* in case no remapping is needed */ + + /* Remapping will only be performed in the Properties Editor, as only this + * restricts the subspace of options to the 'active' data (a manageable state) + */ + /* TODO: watch out for pinned context? */ + if ((sa) && (sa->spacetype == SPACE_BUTS)) { + Object *ob = CTX_data_active_object(C); + + if (ob && id) { + /* only id-types which can be remapped to go through objects should be considered */ + switch (GS(id->name)) { + case ID_TE: /* textures */ + { + Material *ma = give_current_material(ob, ob->actcol); + Tex *tex = give_current_material_texture(ma); + + /* assumes: texture will only be shown if it is active material's active texture it's ok */ + if ((ID *)tex == id) { + char name_esc_ma[(sizeof(ma->id.name) - 2) * 2]; + char name_esc_tex[(sizeof(tex->id.name) - 2) * 2]; + + BLI_strescape(name_esc_ma, ma->id.name + 2, sizeof(name_esc_ma)); + BLI_strescape(name_esc_tex, tex->id.name + 2, sizeof(name_esc_tex)); + + /* create new path */ + // TODO: use RNA path functions to construct step by step instead? + // FIXME: maybe this isn't even needed anymore... + path = BLI_sprintfN("material_slots[\"%s\"].material.texture_slots[\"%s\"].texture.%s", + name_esc_ma, name_esc_tex, basepath); + + /* free old one */ + if (basepath != base_path) + MEM_freeN(basepath); + } + break; + } + } + + /* fix RNA pointer, as we've now changed the ID root by changing the paths */ + if (basepath != path) { + /* rebase provided pointer so that it starts from object... */ + RNA_pointer_create(&ob->id, ptr->type, ptr->data, ptr); + } + } + } + + /* the path should now have been corrected for use */ + return path; +} + /* Path Validation -------------------------------------------- */ /* Check if a given RNA Path is valid, by tracing it from the given ID, and seeing if we can resolve it */ diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c index 16b5574709e..bb05b5de8a6 100644 --- a/source/blender/blenkernel/intern/armature.c +++ b/source/blender/blenkernel/intern/armature.c @@ -505,7 +505,7 @@ void b_bone_spline_setup(bPoseChannel *pchan, int rest, Mat4 result_array[MAX_BB invert_m3_m3(imat3, mat3); mul_m3_m3m3(mat3, result, imat3); /* the matrix transforming vec_roll to desired roll */ - roll1 = (float)atan2(mat3[2][0], mat3[2][2]); + roll1 = atan2f(mat3[2][0], mat3[2][2]); } } else { @@ -543,7 +543,7 @@ void b_bone_spline_setup(bPoseChannel *pchan, int rest, Mat4 result_array[MAX_BB invert_m3_m3(imat3, mat3); mul_m3_m3m3(mat3, imat3, result); /* the matrix transforming vec_roll to desired roll */ - roll2 = (float)atan2(mat3[2][0], mat3[2][2]); + roll2 = atan2f(mat3[2][0], mat3[2][2]); /* and only now negate handle */ mul_v3_fl(h2, -hlength2); diff --git a/source/blender/blenkernel/intern/camera.c b/source/blender/blenkernel/intern/camera.c index 6ce3abe7a32..1402f62291f 100644 --- a/source/blender/blenkernel/intern/camera.c +++ b/source/blender/blenkernel/intern/camera.c @@ -232,7 +232,7 @@ void BKE_camera_params_from_object(CameraParams *params, Object *ob) /* lamp object */ Lamp *la = ob->data; float fac = cosf(la->spotsize * 0.5f); - float phi = acos(fac); + float phi = acosf(fac); params->lens = 16.0f * fac / sinf(phi); if (params->lens == 0.0f) diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c index 08052127fbf..bfc70c91181 100644 --- a/source/blender/blenkernel/intern/cdderivedmesh.c +++ b/source/blender/blenkernel/intern/cdderivedmesh.c @@ -552,7 +552,7 @@ static void cdDM_drawFacesSolid(DerivedMesh *dm, MVert *mvert = cddm->mvert; MFace *mface = cddm->mface; const float *nors = dm->getTessFaceDataArray(dm, CD_NORMAL); - short (*lnors)[4][3] = dm->getTessFaceDataArray(dm, CD_TESSLOOPNORMAL); + const short (*lnors)[4][3] = dm->getTessFaceDataArray(dm, CD_TESSLOOPNORMAL); int a, glmode = -1, shademodel = -1, matnr = -1, drawCurrentMat = 1; if (cddm->pbvh && cddm->pbvh_draw) { @@ -673,9 +673,9 @@ static void cdDM_drawFacesTex_common(DerivedMesh *dm, { CDDerivedMesh *cddm = (CDDerivedMesh *) dm; MVert *mv = cddm->mvert; - MFace *mf = DM_get_tessface_data_layer(dm, CD_MFACE); + const MFace *mf = DM_get_tessface_data_layer(dm, CD_MFACE); const float *nors = dm->getTessFaceDataArray(dm, CD_NORMAL); - short (*lnors)[4][3] = dm->getTessFaceDataArray(dm, CD_TESSLOOPNORMAL); + const short (*lnors)[4][3] = dm->getTessFaceDataArray(dm, CD_TESSLOOPNORMAL); MTFace *tf = DM_get_tessface_data_layer(dm, CD_MTFACE); MCol *mcol; int i, orig; @@ -940,7 +940,7 @@ static void cdDM_drawMappedFaces(DerivedMesh *dm, MFace *mf = cddm->mface; MCol *mcol; const float *nors = DM_get_tessface_data_layer(dm, CD_NORMAL); - short (*lnors)[4][3] = dm->getTessFaceDataArray(dm, CD_TESSLOOPNORMAL); + const short (*lnors)[4][3] = dm->getTessFaceDataArray(dm, CD_TESSLOOPNORMAL); int colType, useColors = flag & DM_DRAW_USE_COLORS; int i, orig; @@ -1157,8 +1157,8 @@ static void cdDM_drawMappedFacesTex(DerivedMesh *dm, cdDM_drawFacesTex_common(dm, NULL, setDrawOptions, compareDrawOptions, userData, flag); } -static void cddm_draw_attrib_vertex(DMVertexAttribs *attribs, MVert *mvert, int a, int index, int vert, - short (*lnor)[3], int smoothnormal) +static void cddm_draw_attrib_vertex(DMVertexAttribs *attribs, const MVert *mvert, int a, int index, int vert, + const short (*lnor)[3], const bool smoothnormal) { const float zero[4] = {0.0f, 0.0f, 0.0f, 0.0f}; int b; @@ -1234,11 +1234,11 @@ static void cdDM_drawMappedFacesGLSL(DerivedMesh *dm, CDDerivedMesh *cddm = (CDDerivedMesh *) dm; GPUVertexAttribs gattribs; DMVertexAttribs attribs; - MVert *mvert = cddm->mvert; - MFace *mface = cddm->mface; + const MVert *mvert = cddm->mvert; + const MFace *mface = cddm->mface; /* MTFace *tf = dm->getTessFaceDataArray(dm, CD_MTFACE); */ /* UNUSED */ - float (*nors)[3] = dm->getTessFaceDataArray(dm, CD_NORMAL); - short (*lnors)[4][3] = dm->getTessFaceDataArray(dm, CD_TESSLOOPNORMAL); + const float (*nors)[3] = dm->getTessFaceDataArray(dm, CD_NORMAL); + const short (*lnors)[4][3] = dm->getTessFaceDataArray(dm, CD_TESSLOOPNORMAL); int a, b, matnr, new_matnr; bool do_draw; int orig; @@ -1277,8 +1277,8 @@ static void cdDM_drawMappedFacesGLSL(DerivedMesh *dm, glBegin(GL_QUADS); for (a = 0; a < dm->numTessFaceData; a++, mface++) { - const int smoothnormal = lnors || (mface->flag & ME_SMOOTH); - short (*ln1)[3] = NULL, (*ln2)[3] = NULL, (*ln3)[3] = NULL, (*ln4)[3] = NULL; + const bool smoothnormal = lnors || (mface->flag & ME_SMOOTH); + const short (*ln1)[3] = NULL, (*ln2)[3] = NULL, (*ln3)[3] = NULL, (*ln4)[3] = NULL; new_matnr = mface->mat_nr + 1; if (new_matnr != matnr) { @@ -1323,13 +1323,11 @@ static void cdDM_drawMappedFacesGLSL(DerivedMesh *dm, glNormal3fv(nor); } } - - if (lnors) { - ln1 = &lnors[0][0]; - ln2 = &lnors[0][1]; - ln3 = &lnors[0][2]; - ln4 = &lnors[0][3]; - lnors++; + else if (lnors) { + ln1 = &lnors[a][0]; + ln2 = &lnors[a][1]; + ln3 = &lnors[a][2]; + ln4 = &lnors[a][3]; } cddm_draw_attrib_vertex(&attribs, mvert, a, mface->v1, 0, ln1, smoothnormal); @@ -1350,7 +1348,7 @@ static void cdDM_drawMappedFacesGLSL(DerivedMesh *dm, int start = 0, numfaces = 0 /* , prevdraw = 0 */ /* UNUSED */, curface = 0; int i; - MFace *mf = mface; + const MFace *mf = mface; GPUAttrib datatypes[GPU_MAX_ATTRIB]; /* TODO, messing up when switching materials many times - [#21056]*/ memset(&attribs, 0, sizeof(attribs)); @@ -1574,8 +1572,8 @@ static void cdDM_drawMappedFacesMat(DerivedMesh *dm, DMVertexAttribs attribs; MVert *mvert = cddm->mvert; MFace *mf = cddm->mface; - float (*nors)[3] = dm->getTessFaceDataArray(dm, CD_NORMAL); - short (*lnors)[4][3] = dm->getTessFaceDataArray(dm, CD_TESSLOOPNORMAL); + const float (*nors)[3] = dm->getTessFaceDataArray(dm, CD_NORMAL); + const short (*lnors)[4][3] = dm->getTessFaceDataArray(dm, CD_TESSLOOPNORMAL); int a, matnr, new_matnr; int orig; @@ -1610,8 +1608,8 @@ static void cdDM_drawMappedFacesMat(DerivedMesh *dm, glBegin(GL_QUADS); for (a = 0; a < dm->numTessFaceData; a++, mf++) { - const int smoothnormal = lnors || (mf->flag & ME_SMOOTH); - short (*ln1)[3] = NULL, (*ln2)[3] = NULL, (*ln3)[3] = NULL, (*ln4)[3] = NULL; + const bool smoothnormal = lnors || (mf->flag & ME_SMOOTH); + const short (*ln1)[3] = NULL, (*ln2)[3] = NULL, (*ln3)[3] = NULL, (*ln4)[3] = NULL; /* material */ new_matnr = mf->mat_nr + 1; @@ -1650,13 +1648,11 @@ static void cdDM_drawMappedFacesMat(DerivedMesh *dm, glNormal3fv(nor); } } - - if (lnors) { - ln1 = &lnors[0][0]; - ln2 = &lnors[0][1]; - ln3 = &lnors[0][2]; - ln4 = &lnors[0][3]; - lnors++; + else if (lnors) { + ln1 = &lnors[a][0]; + ln2 = &lnors[a][1]; + ln3 = &lnors[a][2]; + ln4 = &lnors[a][3]; } /* vertices */ @@ -2720,7 +2716,7 @@ static unsigned int poly_gset_hash_fn(const void *key) return pk->hash_sum; } -static int poly_gset_compare_fn(const void *k1, const void *k2) +static bool poly_gset_compare_fn(const void *k1, const void *k2) { const PolyKey *pk1 = k1; const PolyKey *pk2 = k2; @@ -3017,10 +3013,17 @@ DerivedMesh *CDDM_merge_verts(DerivedMesh *dm, const int *vtargetmap, const int if (UNLIKELY(c == 0)) { continue; } + else if (UNLIKELY(c < 3)) { + STACK_DISCARD(oldl, c); + STACK_DISCARD(mloop, c); + continue; + } + mp_new = STACK_PUSH_RET_PTR(mpoly); *mp_new = *mp; mp_new->totloop = c; + BLI_assert(mp_new->totloop >= 3); mp_new->loopstart = STACK_SIZE(mloop) - c; STACK_PUSH(oldp, i); @@ -3091,7 +3094,7 @@ DerivedMesh *CDDM_merge_verts(DerivedMesh *dm, const int *vtargetmap, const int MEM_freeN(oldv); MEM_freeN(olde); MEM_freeN(oldl); - MEM_freeN(oldp);; + MEM_freeN(oldp); BLI_edgehash_free(ehash, NULL); diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c index 885f186faf3..aacf02555d4 100644 --- a/source/blender/blenkernel/intern/cloth.c +++ b/source/blender/blenkernel/intern/cloth.c @@ -228,7 +228,7 @@ void bvhtree_update_from_cloth(ClothModifierData *clmd, int moving) ClothVertex *verts = cloth->verts; MFace *mfaces; float co[12], co_moving[12]; - int ret = 0; + bool ret = false; if (!bvhtree) return; diff --git a/source/blender/blenkernel/intern/collision.c b/source/blender/blenkernel/intern/collision.c index cedd9eae597..2f600935b1e 100644 --- a/source/blender/blenkernel/intern/collision.c +++ b/source/blender/blenkernel/intern/collision.c @@ -110,7 +110,7 @@ void bvhtree_update_from_mvert(BVHTree *bvhtree, MFace *faces, int numfaces, MVe int i; MFace *mfaces = faces; float co[12], co_moving[12]; - int ret = 0; + bool ret = false; if ( !bvhtree ) return; diff --git a/source/blender/blenkernel/intern/colortools.c b/source/blender/blenkernel/intern/colortools.c index c6d07a959d1..a63e06c7cb8 100644 --- a/source/blender/blenkernel/intern/colortools.c +++ b/source/blender/blenkernel/intern/colortools.c @@ -577,14 +577,14 @@ static void curvemap_make_table(CurveMap *cuma, const rctf *clipr) /* store first and last handle for extrapolation, unit length */ cuma->ext_in[0] = bezt[0].vec[0][0] - bezt[0].vec[1][0]; cuma->ext_in[1] = bezt[0].vec[0][1] - bezt[0].vec[1][1]; - range = sqrt(cuma->ext_in[0] * cuma->ext_in[0] + cuma->ext_in[1] * cuma->ext_in[1]); + range = sqrtf(cuma->ext_in[0] * cuma->ext_in[0] + cuma->ext_in[1] * cuma->ext_in[1]); cuma->ext_in[0] /= range; cuma->ext_in[1] /= range; a = cuma->totpoint - 1; cuma->ext_out[0] = bezt[a].vec[1][0] - bezt[a].vec[2][0]; cuma->ext_out[1] = bezt[a].vec[1][1] - bezt[a].vec[2][1]; - range = sqrt(cuma->ext_out[0] * cuma->ext_out[0] + cuma->ext_out[1] * cuma->ext_out[1]); + range = sqrtf(cuma->ext_out[0] * cuma->ext_out[0] + cuma->ext_out[1] * cuma->ext_out[1]); cuma->ext_out[0] /= range; cuma->ext_out[1] /= range; diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c index d80529ee780..ee7bad773fa 100644 --- a/source/blender/blenkernel/intern/constraint.c +++ b/source/blender/blenkernel/intern/constraint.c @@ -3592,7 +3592,7 @@ static void damptrack_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *t cross_v3_v3v3(raxis, obvec, tarvec); rangle = dot_v3v3(obvec, tarvec); - rangle = acos(max_ff(-1.0f, min_ff(1.0f, rangle))); + rangle = acosf(max_ff(-1.0f, min_ff(1.0f, rangle))); /* construct rotation matrix from the axis-angle rotation found above * - this call takes care to make sure that the axis provided is a unit vector first diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c index a06834f61b3..ca58035d638 100644 --- a/source/blender/blenkernel/intern/curve.c +++ b/source/blender/blenkernel/intern/curve.c @@ -2468,7 +2468,7 @@ static void make_bevel_list_2D(BevList *bl) /* first */ bevp = bl->bevpoints; - angle = atan2(bevp->dir[0], bevp->dir[1]) - M_PI / 2.0; + angle = atan2f(bevp->dir[0], bevp->dir[1]) - (float)(M_PI / 2.0f); bevp->sina = sinf(angle); bevp->cosa = cosf(angle); vec_to_quat(bevp->quat, bevp->dir, 5, 1); @@ -2476,7 +2476,7 @@ static void make_bevel_list_2D(BevList *bl) /* last */ bevp = bl->bevpoints; bevp += (bl->nr - 1); - angle = atan2(bevp->dir[0], bevp->dir[1]) - M_PI / 2.0; + angle = atan2f(bevp->dir[0], bevp->dir[1]) - (float)(M_PI / 2.0f); bevp->sina = sinf(angle); bevp->cosa = cosf(angle); vec_to_quat(bevp->quat, bevp->dir, 5, 1); @@ -2590,7 +2590,7 @@ void BKE_curve_bevelList_make(Object *ob, ListBase *nurbs, bool for_render) if (nu->type == CU_POLY) { len = nu->pntsu; bl = MEM_callocN(sizeof(BevList) + len * sizeof(BevPoint), "makeBevelList2"); - if (need_seglen) { + if (need_seglen && (nu->flagu & CU_NURB_CYCLIC) == 0) { bl->seglen = MEM_mallocN(segcount * sizeof(float), "makeBevelList2_seglen"); bl->segbevcount = MEM_mallocN(segcount * sizeof(int), "makeBevelList2_segbevcount"); } @@ -2613,7 +2613,7 @@ void BKE_curve_bevelList_make(Object *ob, ListBase *nurbs, bool for_render) bevp->weight = bp->weight; bevp->split_tag = true; bp++; - if (seglen != NULL) { + if (seglen != NULL && len != 0) { *seglen = len_v3v3(bevp->vec, bp->vec); bevp++; bevp->offset = *seglen; @@ -2629,11 +2629,6 @@ void BKE_curve_bevelList_make(Object *ob, ListBase *nurbs, bool for_render) if ((nu->flagu & CU_NURB_CYCLIC) == 0) { bevlist_firstlast_direction_calc_from_bpoint(nu, bl); - if (seglen != NULL) { - *seglen = len_v3v3(bevp->vec, nu->bp->vec); - bl->bevpoints->offset = *seglen; - *segbevcount = 1; - } } } else if (nu->type == CU_BEZIER) { @@ -2641,7 +2636,7 @@ void BKE_curve_bevelList_make(Object *ob, ListBase *nurbs, bool for_render) len = segcount * resolu + 1; bl = MEM_callocN(sizeof(BevList) + len * sizeof(BevPoint), "makeBevelBPoints"); - if (need_seglen) { + if (need_seglen && (nu->flagu & CU_NURB_CYCLIC) == 0) { bl->seglen = MEM_mallocN(segcount * sizeof(float), "makeBevelBPoints_seglen"); bl->segbevcount = MEM_mallocN(segcount * sizeof(int), "makeBevelBPoints_segbevcount"); } @@ -2777,7 +2772,7 @@ void BKE_curve_bevelList_make(Object *ob, ListBase *nurbs, bool for_render) len = (resolu * segcount); bl = MEM_callocN(sizeof(BevList) + len * sizeof(BevPoint), "makeBevelList3"); - if (need_seglen) { + if (need_seglen && (nu->flagu & CU_NURB_CYCLIC) == 0) { bl->seglen = MEM_mallocN(segcount * sizeof(float), "makeBevelList3_seglen"); bl->segbevcount = MEM_mallocN(segcount * sizeof(int), "makeBevelList3_segbevcount"); } diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c index ab3cf5851e9..63eb3b397b0 100644 --- a/source/blender/blenkernel/intern/customdata.c +++ b/source/blender/blenkernel/intern/customdata.c @@ -2554,12 +2554,12 @@ void CustomData_bmesh_free_block(CustomData *data, void **block) /** * Same as #CustomData_bmesh_free_block but zero the memory rather then freeing. */ -void CustomData_bmesh_free_block_data(CustomData *data, void **block) +void CustomData_bmesh_free_block_data(CustomData *data, void *block) { const LayerTypeInfo *typeInfo; int i; - if (*block == NULL) + if (block == NULL) return; for (i = 0; i < data->totlayer; ++i) { @@ -2568,13 +2568,13 @@ void CustomData_bmesh_free_block_data(CustomData *data, void **block) if (typeInfo->free) { int offset = data->layers[i].offset; - typeInfo->free((char *)*block + offset, 1, typeInfo->size); + typeInfo->free((char *)block + offset, 1, typeInfo->size); } } } if (data->totsize) - memset(*block, 0, data->totsize); + memset(block, 0, data->totsize); } static void CustomData_bmesh_alloc_block(CustomData *data, void **block) diff --git a/source/blender/blenkernel/intern/depsgraph.c b/source/blender/blenkernel/intern/depsgraph.c index 93bb4849718..44a0b93fc01 100644 --- a/source/blender/blenkernel/intern/depsgraph.c +++ b/source/blender/blenkernel/intern/depsgraph.c @@ -75,6 +75,7 @@ #include "BKE_mball.h" #include "BKE_modifier.h" #include "BKE_object.h" +#include "BKE_paint.h" #include "BKE_particle.h" #include "BKE_pointcache.h" #include "BKE_scene.h" @@ -2509,6 +2510,7 @@ static void dag_id_flush_update(Main *bmain, Scene *sce, ID *id) obt = sce->basact ? sce->basact->object : NULL; if (obt && obt->mode & OB_MODE_TEXTURE_PAINT) { BKE_texpaint_slots_refresh_object(sce, obt); + BKE_paint_proj_mesh_data_check(sce, obt, NULL, NULL, NULL, NULL); GPU_drawobject_free(obt->derivedFinal); } } diff --git a/source/blender/blenkernel/intern/effect.c b/source/blender/blenkernel/intern/effect.c index 24ee470eaa7..ced9da8d0b1 100644 --- a/source/blender/blenkernel/intern/effect.c +++ b/source/blender/blenkernel/intern/effect.c @@ -872,7 +872,7 @@ static void do_physical_effector(EffectorCache *eff, EffectorData *efd, Effected case PFIELD_HARMONIC: mul_v3_fl(force, -strength * efd->falloff); copy_v3_v3(temp, point->vel); - mul_v3_fl(temp, -damp * 2.0f * (float)sqrt(fabs(strength)) * point->vel_to_sec); + mul_v3_fl(temp, -damp * 2.0f * sqrtf(fabsf(strength)) * point->vel_to_sec); add_v3_v3(force, temp); break; case PFIELD_CHARGE: diff --git a/source/blender/blenkernel/intern/fcurve.c b/source/blender/blenkernel/intern/fcurve.c index 09c1dcf701d..e90a0891436 100644 --- a/source/blender/blenkernel/intern/fcurve.c +++ b/source/blender/blenkernel/intern/fcurve.c @@ -55,6 +55,7 @@ #include "BKE_action.h" #include "BKE_armature.h" #include "BKE_constraint.h" +#include "BKE_context.h" #include "BKE_curve.h" #include "BKE_global.h" #include "BKE_object.h" @@ -310,19 +311,35 @@ int list_find_data_fcurves(ListBase *dst, ListBase *src, const char *dataPrefix, FCurve *rna_get_fcurve(PointerRNA *ptr, PropertyRNA *prop, int rnaindex, bAction **action, bool *r_driven) { + return rna_get_fcurve_context_ui(NULL, ptr, prop, rnaindex, action, r_driven); +} + +FCurve *rna_get_fcurve_context_ui(bContext *C, PointerRNA *ptr, PropertyRNA *prop, int rnaindex, + bAction **action, bool *r_driven) +{ FCurve *fcu = NULL; + PointerRNA tptr = *ptr; *r_driven = false; /* there must be some RNA-pointer + property combon */ - if (prop && ptr->id.data && RNA_property_animateable(ptr, prop)) { - AnimData *adt = BKE_animdata_from_id(ptr->id.data); - char *path; + if (prop && tptr.id.data && RNA_property_animateable(&tptr, prop)) { + AnimData *adt = BKE_animdata_from_id(tptr.id.data); + int step = C ? 2 : 1; /* Always 1 in case we have no context (can't check in 'ancestors' of given RNA ptr). */ + char *path = NULL; - if (adt) { + if (!adt && C) { + path = BKE_animdata_driver_path_hack(C, &tptr, prop, NULL); + adt = BKE_animdata_from_id(tptr.id.data); + step--; + } + + while (adt && step--) { if ((adt->action && adt->action->curves.first) || (adt->drivers.first)) { /* XXX this function call can become a performance bottleneck */ - path = RNA_path_from_ID_to_property(ptr, prop); + if (step) { + path = RNA_path_from_ID_to_property(&tptr, prop); + } if (path) { /* animation takes priority over drivers */ @@ -337,13 +354,25 @@ FCurve *rna_get_fcurve(PointerRNA *ptr, PropertyRNA *prop, int rnaindex, bAction *r_driven = true; } - if (fcu && action) + if (fcu && action) { *action = adt->action; - - MEM_freeN(path); + break; + } + else if (step) { + char *tpath = BKE_animdata_driver_path_hack(C, &tptr, prop, path); + if (tpath && tpath != path) { + MEM_freeN(path); + path = tpath; + adt = BKE_animdata_from_id(tptr.id.data); + } + else { + adt = NULL; + } + } } } } + MEM_SAFE_FREE(path); } return fcu; diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c index 805c1250c5d..5c673eeef3f 100644 --- a/source/blender/blenkernel/intern/image.c +++ b/source/blender/blenkernel/intern/image.c @@ -62,6 +62,7 @@ #include "DNA_meshdata_types.h" #include "BLI_blenlib.h" +#include "BLI_math_vector.h" #include "BLI_threads.h" #include "BLI_timecode.h" /* for stamp timecode format */ #include "BLI_utildefines.h" @@ -120,12 +121,12 @@ static unsigned int imagecache_hashhash(const void *key_v) return key->index; } -static int imagecache_hashcmp(const void *a_v, const void *b_v) +static bool imagecache_hashcmp(const void *a_v, const void *b_v) { const ImageCacheKey *a = (ImageCacheKey *) a_v; const ImageCacheKey *b = (ImageCacheKey *) b_v; - return a->index - b->index; + return (a->index != b->index); } static void imagecache_keydata(void *userkey, int *framenr, int *proxy, int *render_flags) @@ -365,6 +366,7 @@ Image *BKE_image_copy(Main *bmain, Image *ima) nima->gen_x = ima->gen_x; nima->gen_y = ima->gen_y; nima->gen_type = ima->gen_type; + copy_v4_v4(nima->gen_color, ima->gen_color); nima->animspeed = ima->animspeed; @@ -769,6 +771,7 @@ Image *BKE_image_add_generated(Main *bmain, unsigned int width, unsigned int hei ima->gen_type = gen_type; ima->gen_flag |= (floatbuf ? IMA_GEN_FLOAT : 0); ima->gen_depth = depth; + copy_v4_v4(ima->gen_color, color); ibuf = add_ibuf_size(width, height, ima->name, depth, floatbuf, gen_type, color, &ima->colorspace_settings); image_assign_ibuf(ima, ibuf, IMA_NO_INDEX, 0); @@ -2996,7 +2999,6 @@ BLI_INLINE bool image_quick_test(Image *ima, ImageUser *iuser) static ImBuf *image_acquire_ibuf(Image *ima, ImageUser *iuser, void **lock_r) { ImBuf *ibuf = NULL; - float color[] = {0, 0, 0, 1}; int frame = 0, index = 0; if (lock_r) @@ -3041,7 +3043,7 @@ static ImBuf *image_acquire_ibuf(Image *ima, ImageUser *iuser, void **lock_r) if (ima->gen_y == 0) ima->gen_y = 1024; if (ima->gen_depth == 0) ima->gen_depth = 24; ibuf = add_ibuf_size(ima->gen_x, ima->gen_y, ima->name, ima->gen_depth, (ima->gen_flag & IMA_GEN_FLOAT) != 0, ima->gen_type, - color, &ima->colorspace_settings); + ima->gen_color, &ima->colorspace_settings); image_assign_ibuf(ima, ibuf, IMA_NO_INDEX, 0); ima->ok = IMA_OK_LOADED; } diff --git a/source/blender/blenkernel/intern/implicit.c b/source/blender/blenkernel/intern/implicit.c index 4d80256426d..4cf9d52989f 100644 --- a/source/blender/blenkernel/intern/implicit.c +++ b/source/blender/blenkernel/intern/implicit.c @@ -1236,7 +1236,7 @@ DO_INLINE void cloth_calc_spring_force(ClothModifierData *clmd, ClothSpring *s, sub_v3_v3v3(extent, X[s->kl], X[s->ij]); sub_v3_v3v3(vel, V[s->kl], V[s->ij]); dot = dot_v3v3(extent, extent); - length = sqrt(dot); + length = sqrtf(dot); s->flags &= ~CLOTH_SPRING_FLAG_NEEDED; diff --git a/source/blender/blenkernel/intern/lamp.c b/source/blender/blenkernel/intern/lamp.c index 749e915e5ca..4a413850ec0 100644 --- a/source/blender/blenkernel/intern/lamp.c +++ b/source/blender/blenkernel/intern/lamp.c @@ -135,8 +135,7 @@ Lamp *localize_lamp(Lamp *la) Lamp *lan; int a; - lan = BKE_libblock_copy(&la->id); - BLI_remlink(&G.main->lamp, lan); + lan = BKE_libblock_copy_nolib(&la->id, false); for (a = 0; a < MAX_MTEX; a++) { if (lan->mtex[a]) { diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c index 515287de336..b49eee3ea22 100644 --- a/source/blender/blenkernel/intern/library.c +++ b/source/blender/blenkernel/intern/library.c @@ -620,6 +620,8 @@ int set_listbasepointers(Main *main, ListBase **lb) lb[a] = NULL; + BLI_assert(a + 1 == MAX_LIBARRAY); + return a; } diff --git a/source/blender/blenkernel/intern/linestyle.c b/source/blender/blenkernel/intern/linestyle.c index 45695844101..5e17117a875 100644 --- a/source/blender/blenkernel/intern/linestyle.c +++ b/source/blender/blenkernel/intern/linestyle.c @@ -93,6 +93,7 @@ static void default_linestyle_settings(FreestyleLineStyle *linestyle) linestyle->min_length = 0.0f; linestyle->max_length = 10000.0f; linestyle->split_length = 100; + linestyle->chain_count = 10; linestyle->sort_key = LS_SORT_KEY_DISTANCE_FROM_CAMERA; linestyle->integration_type = LS_INTEGRATION_MEAN; linestyle->texstep = 1.0f; @@ -186,6 +187,7 @@ FreestyleLineStyle *BKE_linestyle_copy(FreestyleLineStyle *linestyle) new_linestyle->max_angle = linestyle->max_angle; new_linestyle->min_length = linestyle->min_length; new_linestyle->max_length = linestyle->max_length; + new_linestyle->chain_count = linestyle->chain_count; new_linestyle->split_dash1 = linestyle->split_dash1; new_linestyle->split_gap1 = linestyle->split_gap1; new_linestyle->split_dash2 = linestyle->split_dash2; diff --git a/source/blender/blenkernel/intern/mask.c b/source/blender/blenkernel/intern/mask.c index 1c40446c217..83ad2f1b2d2 100644 --- a/source/blender/blenkernel/intern/mask.c +++ b/source/blender/blenkernel/intern/mask.c @@ -1821,10 +1821,10 @@ void BKE_mask_layer_shape_unlink(MaskLayer *masklay, MaskLayerShape *masklay_sha BKE_mask_layer_shape_free(masklay_shape); } -static int mask_layer_shape_sort_cb(void *masklay_shape_a_ptr, void *masklay_shape_b_ptr) +static int mask_layer_shape_sort_cb(const void *masklay_shape_a_ptr, const void *masklay_shape_b_ptr) { - MaskLayerShape *masklay_shape_a = (MaskLayerShape *)masklay_shape_a_ptr; - MaskLayerShape *masklay_shape_b = (MaskLayerShape *)masklay_shape_b_ptr; + const MaskLayerShape *masklay_shape_a = masklay_shape_a_ptr; + const MaskLayerShape *masklay_shape_b = masklay_shape_b_ptr; if (masklay_shape_a->frame < masklay_shape_b->frame) return -1; else if (masklay_shape_a->frame > masklay_shape_b->frame) return 1; diff --git a/source/blender/blenkernel/intern/movieclip.c b/source/blender/blenkernel/intern/movieclip.c index 35bf453c328..e28adb7c0e0 100644 --- a/source/blender/blenkernel/intern/movieclip.c +++ b/source/blender/blenkernel/intern/movieclip.c @@ -406,27 +406,14 @@ static unsigned int moviecache_hashhash(const void *keyv) return rval; } -static int moviecache_hashcmp(const void *av, const void *bv) +static bool moviecache_hashcmp(const void *av, const void *bv) { const MovieClipImBufCacheKey *a = (MovieClipImBufCacheKey *)av; const MovieClipImBufCacheKey *b = (MovieClipImBufCacheKey *)bv; - if (a->framenr < b->framenr) - return -1; - else if (a->framenr > b->framenr) - return 1; - - if (a->proxy < b->proxy) - return -1; - else if (a->proxy > b->proxy) - return 1; - - if (a->render_flag < b->render_flag) - return -1; - else if (a->render_flag > b->render_flag) - return 1; - - return 0; + return ((a->framenr != b->framenr) || + (a->proxy != b->proxy) || + (a->render_flag != b->render_flag)); } static void *moviecache_getprioritydata(void *key_v) diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c index 0f86b551092..3a7bfb03e07 100644 --- a/source/blender/blenkernel/intern/node.c +++ b/source/blender/blenkernel/intern/node.c @@ -2682,16 +2682,12 @@ static unsigned int node_instance_hash_key(const void *key) return ((const bNodeInstanceKey *)key)->value; } -static int node_instance_hash_key_cmp(const void *a, const void *b) +static bool node_instance_hash_key_cmp(const void *a, const void *b) { unsigned int value_a = ((const bNodeInstanceKey *)a)->value; unsigned int value_b = ((const bNodeInstanceKey *)b)->value; - if (value_a == value_b) - return 0; - else if (value_a < value_b) - return -1; - else - return 1; + + return (value_a != value_b); } bNodeInstanceHash *BKE_node_instance_hash_new(const char *info) diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index b09016506e3..755ce91a8af 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -1067,10 +1067,10 @@ void BKE_object_lod_add(Object *ob) BLI_addtail(&ob->lodlevels, lod); } -static int lod_cmp(void *a, void *b) +static int lod_cmp(const void *a, const void *b) { - LodLevel *loda = (LodLevel *)a; - LodLevel *lodb = (LodLevel *)b; + const LodLevel *loda = a; + const LodLevel *lodb = b; if (loda->distance < lodb->distance) return -1; return loda->distance > lodb->distance; @@ -3242,9 +3242,9 @@ bool BKE_boundbox_ray_hit_check( return result; } -static int pc_cmp(void *a, void *b) +static int pc_cmp(const void *a, const void *b) { - LinkData *ad = a, *bd = b; + const LinkData *ad = a, *bd = b; if (GET_INT_FROM_POINTER(ad->data) > GET_INT_FROM_POINTER(bd->data)) return 1; else return 0; diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c index 4382d74f34e..d16575d80c8 100644 --- a/source/blender/blenkernel/intern/paint.c +++ b/source/blender/blenkernel/intern/paint.c @@ -315,8 +315,14 @@ void BKE_paint_curve_set(Brush *br, PaintCurve *pc) /* remove colour from palette. Must be certain color is inside the palette! */ void BKE_palette_color_remove(Palette *palette, PaletteColor *color) { - BLI_remlink(&palette->colors, color); - BLI_addhead(&palette->deleted, color); + if (color) { + int numcolors = BLI_countlist(&palette->colors); + if ((numcolors == palette->active_color + 1) && (numcolors != 1)) + palette->active_color--; + + BLI_remlink(&palette->colors, color); + BLI_addhead(&palette->deleted, color); + } } void BKE_palette_cleanup(Palette *palette) @@ -350,19 +356,6 @@ PaletteColor *BKE_palette_color_add(Palette *palette) return color; } -void BKE_palette_color_delete(struct Palette *palette) -{ - PaletteColor *color = BLI_findlink(&palette->colors, palette->active_color); - - if (color) { - if ((color == palette->colors.last) && (palette->colors.last != palette->colors.first)) - palette->active_color--; - - BLI_remlink(&palette->colors, color); - BLI_addhead(&palette->deleted, color); - } -} - bool BKE_palette_is_empty(const struct Palette *palette) { @@ -493,7 +486,7 @@ void paint_calculate_rake_rotation(UnifiedPaintSettings *ups, const float mouse_ sub_v2_v2v2(dpos, ups->last_rake, mouse_pos); if (len_squared_v2(dpos) >= r * r) { - ups->brush_rotation = atan2(dpos[0], dpos[1]); + ups->brush_rotation = atan2f(dpos[0], dpos[1]); interp_v2_v2v2(ups->last_rake, ups->last_rake, mouse_pos, u); diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c index 27d346f65b9..530573d6e38 100644 --- a/source/blender/blenkernel/intern/particle.c +++ b/source/blender/blenkernel/intern/particle.c @@ -656,7 +656,7 @@ static float psys_render_projected_area(ParticleSystem *psys, const float center } /* screen space radius */ - radius = sqrt(area / (float)M_PI); + radius = sqrtf(area / (float)M_PI); /* make smaller using fallof once over screen edge */ *viewport = 1.0f; @@ -917,8 +917,8 @@ int psys_render_simplify_distribution(ParticleThreadContext *ctx, int tot) elem->scalemax = (lambda + t < 1.0f) ? 1.0f / lambda : 1.0f / (1.0f - elem->t * elem->t / t); elem->scalemin = (lambda + t < 1.0f) ? 0.0f : elem->scalemax * (1.0f - elem->t / t); - elem->scalemin = sqrt(elem->scalemin); - elem->scalemax = sqrt(elem->scalemax); + elem->scalemin = sqrtf(elem->scalemin); + elem->scalemax = sqrtf(elem->scalemax); /* clamp scaling */ scaleclamp = (float)min_ii(elem->totchild, 10); @@ -939,8 +939,8 @@ int psys_render_simplify_distribution(ParticleThreadContext *ctx, int tot) } elem->lambda = lambda; - elem->scalemin = sqrt(elem->scalemin); - elem->scalemax = sqrt(elem->scalemax); + elem->scalemin = sqrtf(elem->scalemin); + elem->scalemax = sqrtf(elem->scalemax); elem->curchild = 0; } @@ -1950,10 +1950,10 @@ static void do_kink(ParticleKey *state, ParticleKey *par, float *par_rot, float t = time * freq * (float)M_PI; if (smooth_start) { - dt = fabs(t); + dt = fabsf(t); /* smooth the beginning of kink */ CLAMP(dt, 0.f, (float)M_PI); - dt = sin(dt / 2.f); + dt = sinf(dt / 2.f); } if (type != PART_KINK_RADIAL) { @@ -2014,12 +2014,12 @@ static void do_kink(ParticleKey *state, ParticleKey *par, float *par_rot, float madd_v3_v3fl(result, proj, flat); } - madd_v3_v3fl(result, par_vec, -amplitude * (float)sin(t)); + madd_v3_v3fl(result, par_vec, -amplitude * sinf(t)); break; } case PART_KINK_WAVE: { - madd_v3_v3fl(result, kink, amplitude * (float)sin(t)); + madd_v3_v3fl(result, kink, amplitude * sinf(t)); if (flat > 0.f) { float proj[3]; @@ -2054,22 +2054,22 @@ static void do_kink(ParticleKey *state, ParticleKey *par, float *par_rot, float if (inp_y > 0.5f) { copy_v3_v3(state_co, y_vec); - mul_v3_fl(y_vec, amplitude * (float)cos(t)); - mul_v3_fl(z_vec, amplitude / 2.f * (float)sin(2.f * t)); + mul_v3_fl(y_vec, amplitude * cosf(t)); + mul_v3_fl(z_vec, amplitude / 2.f * sinf(2.f * t)); } else if (inp_z > 0.0f) { - mul_v3_v3fl(state_co, z_vec, (float)sin((float)M_PI / 3.f)); + mul_v3_v3fl(state_co, z_vec, sinf((float)M_PI / 3.f)); madd_v3_v3fl(state_co, y_vec, -0.5f); - mul_v3_fl(y_vec, -amplitude * (float)cos(t + (float)M_PI / 3.f)); - mul_v3_fl(z_vec, amplitude / 2.f * (float)cos(2.f * t + (float)M_PI / 6.f)); + mul_v3_fl(y_vec, -amplitude * cosf(t + (float)M_PI / 3.f)); + mul_v3_fl(z_vec, amplitude / 2.f * cosf(2.f * t + (float)M_PI / 6.f)); } else { - mul_v3_v3fl(state_co, z_vec, -(float)sin((float)M_PI / 3.f)); + mul_v3_v3fl(state_co, z_vec, -sinf((float)M_PI / 3.f)); madd_v3_v3fl(state_co, y_vec, -0.5f); - mul_v3_fl(y_vec, amplitude * (float)-sin(t + (float)M_PI / 6.f)); - mul_v3_fl(z_vec, amplitude / 2.f * (float)-sin(2.f * t + (float)M_PI / 3.f)); + mul_v3_fl(y_vec, amplitude * -sinf(t + (float)M_PI / 6.f)); + mul_v3_fl(z_vec, amplitude / 2.f * -sinf(2.f * t + (float)M_PI / 3.f)); } mul_v3_fl(state_co, amplitude); @@ -2271,8 +2271,11 @@ static void do_rough(float *loc, float mat[4][4], float t, float fac, float size float rough[3]; float rco[3]; - if (thres != 0.0f) - if ((float)fabs((float)(-1.5f + loc[0] + loc[1] + loc[2])) < 1.5f * thres) return; + if (thres != 0.0f) { + if (fabsf((float)(-1.5f + loc[0] + loc[1] + loc[2])) < 1.5f * thres) { + return; + } + } copy_v3_v3(rco, loc); mul_v3_fl(rco, t); @@ -4567,8 +4570,8 @@ void psys_get_dupli_path_transform(ParticleSimulationData *sim, ParticleData *pa normalize_v3(nor); /* make sure that we get a proper side vector */ - if (fabs(dot_v3v3(nor, vec)) > 0.999999) { - if (fabs(dot_v3v3(nor, xvec)) > 0.999999) { + if (fabsf(dot_v3v3(nor, vec)) > 0.999999) { + if (fabsf(dot_v3v3(nor, xvec)) > 0.999999) { nor[0] = 0.0f; nor[1] = 1.0f; nor[2] = 0.0f; @@ -4676,12 +4679,12 @@ void psys_make_billboard(ParticleBillboardData *bb, float xvec[3], float yvec[3] copy_v3_v3(tvec, xvec); copy_v3_v3(tvec2, yvec); - mul_v3_fl(xvec, cos(bb->tilt * (float)M_PI)); - mul_v3_fl(tvec2, sin(bb->tilt * (float)M_PI)); + mul_v3_fl(xvec, cosf(bb->tilt * (float)M_PI)); + mul_v3_fl(tvec2, sinf(bb->tilt * (float)M_PI)); add_v3_v3(xvec, tvec2); - mul_v3_fl(yvec, cos(bb->tilt * (float)M_PI)); - mul_v3_fl(tvec, -sin(bb->tilt * (float)M_PI)); + mul_v3_fl(yvec, cosf(bb->tilt * (float)M_PI)); + mul_v3_fl(tvec, -sinf(bb->tilt * (float)M_PI)); add_v3_v3(yvec, tvec); mul_v3_fl(xvec, bb->size[0]); diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c index 09e20c02691..155299b69c3 100644 --- a/source/blender/blenkernel/intern/particle_system.c +++ b/source/blender/blenkernel/intern/particle_system.c @@ -701,7 +701,7 @@ static void init_mv_jit(float *jit, int num, int seed2, float amount) rad1= (float)(1.0f/sqrtf((float)num)); rad2= (float)(1.0f/((float)num)); - rad3= (float)sqrt((float)num)/((float)num); + rad3= (float)sqrtf((float)num)/((float)num); rng = BLI_rng_new(31415926 + num + seed2); x= 0; diff --git a/source/blender/blenkernel/intern/pbvh_bmesh.c b/source/blender/blenkernel/intern/pbvh_bmesh.c index 55653f41e75..1a0ddac03d7 100644 --- a/source/blender/blenkernel/intern/pbvh_bmesh.c +++ b/source/blender/blenkernel/intern/pbvh_bmesh.c @@ -823,15 +823,16 @@ static bool pbvh_bmesh_subdivide_long_edges(EdgeQueueContext *eq_ctx, PBVH *bvh, return any_subdivided; } -static void pbvh_bmesh_collapse_edge(PBVH *bvh, BMEdge *e, - BMVert *v1, BMVert *v2, - GSet *deleted_verts, - BLI_Buffer *edge_loops, - BLI_Buffer *deleted_faces, - EdgeQueueContext *eq_ctx) +static void pbvh_bmesh_collapse_edge( + PBVH *bvh, BMEdge *e, + BMVert *v1, BMVert *v2, + GSet *deleted_verts, + BLI_Buffer *deleted_faces, + EdgeQueueContext *eq_ctx) { BMIter bm_iter; BMFace *f; + BMLoop *l_adj; BMVert *v_del, *v_conn; int i; float mask_v1 = BM_ELEM_CD_GET_FLOAT(v1, eq_ctx->cd_vert_mask_offset); @@ -846,15 +847,11 @@ static void pbvh_bmesh_collapse_edge(PBVH *bvh, BMEdge *e, v_conn = v1; } - /* Get all faces adjacent to the edge */ - pbvh_bmesh_edge_loops(edge_loops, e); - /* Remove the merge vertex from the PBVH */ pbvh_bmesh_vert_remove(bvh, v_del, eq_ctx->cd_vert_node_offset, eq_ctx->cd_face_node_offset); /* Remove all faces adjacent to the edge */ - for (i = 0; i < edge_loops->count; i++) { - BMLoop *l_adj = BLI_buffer_at(edge_loops, BMLoop *, i); + while ((l_adj = e->l)) { BMFace *f_adj = l_adj->f; pbvh_bmesh_face_remove(bvh, f_adj, eq_ctx->cd_vert_node_offset, eq_ctx->cd_face_node_offset); @@ -973,10 +970,10 @@ static void pbvh_bmesh_collapse_edge(PBVH *bvh, BMEdge *e, BM_vert_kill(bvh->bm, v_del); } -static bool pbvh_bmesh_collapse_short_edges(EdgeQueueContext *eq_ctx, - PBVH *bvh, - BLI_Buffer *edge_loops, - BLI_Buffer *deleted_faces) +static bool pbvh_bmesh_collapse_short_edges( + EdgeQueueContext *eq_ctx, + PBVH *bvh, + BLI_Buffer *deleted_faces) { float min_len_squared = bvh->bm_min_edge_len * bvh->bm_min_edge_len; GSet *deleted_verts; @@ -1020,7 +1017,7 @@ static bool pbvh_bmesh_collapse_short_edges(EdgeQueueContext *eq_ctx, any_collapsed = true; pbvh_bmesh_collapse_edge(bvh, e, v1, v2, - deleted_verts, edge_loops, + deleted_verts, deleted_faces, eq_ctx); } @@ -1214,7 +1211,7 @@ bool BKE_pbvh_bmesh_update_topology(PBVH *bvh, PBVHTopologyUpdateMode mode, const float center[3], float radius) { /* 2 is enough for edge faces - manifold edge */ - BLI_buffer_declare_static(BMFace *, edge_loops, BLI_BUFFER_NOP, 2); + BLI_buffer_declare_static(BMLoop *, edge_loops, BLI_BUFFER_NOP, 2); BLI_buffer_declare_static(BMFace *, deleted_faces, BLI_BUFFER_NOP, 32); const int cd_vert_mask_offset = CustomData_get_offset(&bvh->bm->vdata, CD_PAINT_MASK); const int cd_vert_node_offset = bvh->cd_vert_node_offset; @@ -1230,7 +1227,7 @@ bool BKE_pbvh_bmesh_update_topology(PBVH *bvh, PBVHTopologyUpdateMode mode, short_edge_queue_create(&eq_ctx, bvh, center, radius); modified |= !BLI_heap_is_empty(q.heap); - pbvh_bmesh_collapse_short_edges(&eq_ctx, bvh, &edge_loops, + pbvh_bmesh_collapse_short_edges(&eq_ctx, bvh, &deleted_faces); BLI_heap_free(q.heap, NULL); BLI_mempool_destroy(queue_pool); diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c index 063a81e6efb..a6a7664ec61 100644 --- a/source/blender/blenkernel/intern/pointcache.c +++ b/source/blender/blenkernel/intern/pointcache.c @@ -85,11 +85,12 @@ #ifdef WITH_LZO #include "minilzo.h" -#else -/* used for non-lzo cases */ -#define LZO_OUT_LEN(size) ((size) + (size) / 16 + 64 + 3) +#define LZO_HEAP_ALLOC(var,size) \ + lzo_align_t __LZO_MMODEL var [ ((size) + (sizeof(lzo_align_t) - 1)) / sizeof(lzo_align_t) ] #endif +#define LZO_OUT_LEN(size) ((size) + (size) / 16 + 64 + 3) + #ifdef WITH_LZMA #include "LzmaLib.h" #endif diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c index eb98e381222..5bfd6e8a120 100644 --- a/source/blender/blenkernel/intern/scene.c +++ b/source/blender/blenkernel/intern/scene.c @@ -93,9 +93,6 @@ #include "bmesh.h" -//XXX #include "BIF_previewrender.h" -//XXX #include "BIF_editseq.h" - #ifdef WIN32 #else # include <sys/time.h> @@ -521,6 +518,9 @@ Scene *BKE_scene_add(Main *bmain, const char *name) sce->r.preview_start_resolution = 64; + sce->r.line_thickness_mode = R_LINE_THICKNESS_ABSOLUTE; + sce->r.unit_line_thickness = 1.0f; + sce->toolsettings = MEM_callocN(sizeof(struct ToolSettings), "Tool Settings Struct"); sce->toolsettings->doublimit = 0.001; sce->toolsettings->uvcalc_margin = 0.001f; @@ -1991,14 +1991,13 @@ double BKE_scene_unit_scale(const UnitSettings *unit, const int unit_type, doubl switch (unit_type) { case B_UNIT_LENGTH: return value * (double)unit->scale_length; - case B_UNIT_CAMERA: - return value * (double)unit->scale_length; case B_UNIT_AREA: return value * pow(unit->scale_length, 2); case B_UNIT_VOLUME: return value * pow(unit->scale_length, 3); case B_UNIT_MASS: return value * pow(unit->scale_length, 3); + case B_UNIT_CAMERA: /* *Do not* use scene's unit scale for camera focal lens! See T42026. */ default: return value; } diff --git a/source/blender/blenkernel/intern/seqcache.c b/source/blender/blenkernel/intern/seqcache.c index 97062f728c5..4268b33cb14 100644 --- a/source/blender/blenkernel/intern/seqcache.c +++ b/source/blender/blenkernel/intern/seqcache.c @@ -69,58 +69,15 @@ static struct SeqPreprocessCache *preprocess_cache = NULL; static void preprocessed_cache_destruct(void); -static int seq_cmp_render_data(const SeqRenderData *a, const SeqRenderData *b) +static bool seq_cmp_render_data(const SeqRenderData *a, const SeqRenderData *b) { - if (a->preview_render_size < b->preview_render_size) { - return -1; - } - if (a->preview_render_size > b->preview_render_size) { - return 1; - } - - if (a->rectx < b->rectx) { - return -1; - } - if (a->rectx > b->rectx) { - return 1; - } - - if (a->recty < b->recty) { - return -1; - } - if (a->recty > b->recty) { - return 1; - } - - if (a->bmain < b->bmain) { - return -1; - } - if (a->bmain > b->bmain) { - return 1; - } - - if (a->scene < b->scene) { - return -1; - } - if (a->scene > b->scene) { - return 1; - } - - if (a->motion_blur_shutter < b->motion_blur_shutter) { - return -1; - } - if (a->motion_blur_shutter > b->motion_blur_shutter) { - return 1; - } - - if (a->motion_blur_samples < b->motion_blur_samples) { - return -1; - } - if (a->motion_blur_samples > b->motion_blur_samples) { - return 1; - } - - return 0; + return ((a->preview_render_size != b->preview_render_size) || + (a->rectx != b->rectx) || + (a->recty != b->recty) || + (a->bmain != b->bmain) || + (a->scene != b->scene) || + (a->motion_blur_shutter != b->motion_blur_shutter) || + (a->motion_blur_samples != b->motion_blur_samples)); } static unsigned int seq_hash_render_data(const SeqRenderData *a) @@ -148,33 +105,15 @@ static unsigned int seqcache_hashhash(const void *key_) return rval; } -static int seqcache_hashcmp(const void *a_, const void *b_) +static bool seqcache_hashcmp(const void *a_, const void *b_) { const SeqCacheKey *a = (SeqCacheKey *) a_; const SeqCacheKey *b = (SeqCacheKey *) b_; - if (a->seq < b->seq) { - return -1; - } - if (a->seq > b->seq) { - return 1; - } - - if (a->cfra < b->cfra) { - return -1; - } - if (a->cfra > b->cfra) { - return 1; - } - - if (a->type < b->type) { - return -1; - } - if (a->type > b->type) { - return 1; - } - - return seq_cmp_render_data(&a->context, &b->context); + return ((a->seq != b->seq) || + (a->cfra != b->cfra) || + (a->type != b->type) || + seq_cmp_render_data(&a->context, &b->context)); } void BKE_sequencer_cache_destruct(void) diff --git a/source/blender/blenkernel/intern/seqeffects.c b/source/blender/blenkernel/intern/seqeffects.c index a8e578eae0d..11a6cb7acc3 100644 --- a/source/blender/blenkernel/intern/seqeffects.c +++ b/source/blender/blenkernel/intern/seqeffects.c @@ -1322,7 +1322,7 @@ static float check_zone(WipeZone *wipezone, int x, int y, Sequence *seq, float f if (angle == 0.0f) { b1 = posy; b2 = y; - hyp = fabs(y - posy); + hyp = fabsf(y - posy); } else { b1 = posy - (-angle) * posx; @@ -1745,8 +1745,8 @@ static void transform_image(int x, int y, ImBuf *ibuf1, ImBuf *out, float scale yo = y; /* Rotate */ - s = sin(rotate); - c = cos(rotate); + s = sinf(rotate); + c = cosf(rotate); for (yi = 0; yi < yo; yi++) { for (xi = 0; xi < xo; xi++) { diff --git a/source/blender/blenkernel/intern/softbody.c b/source/blender/blenkernel/intern/softbody.c index 9c411142566..13575560669 100644 --- a/source/blender/blenkernel/intern/softbody.c +++ b/source/blender/blenkernel/intern/softbody.c @@ -2160,7 +2160,7 @@ static void sb_spring_force(Object *ob, int bpi, BodySpring *bs, float iks, floa // dfdx_spring(ia, ia, op, dir, bs->len, distance, -mpos); /* depending on my vel */ // dfdv_goal(ia, ia, mvel); // well that ignores geometie - if (bp2->goal < SOFTGOALSNAP) { /* ommit this bp when it snaps */ + if (bp2->goal < SOFTGOALSNAP) { /* omit this bp when it snaps */ /* depending on other pos */ // dfdx_spring(ia, ic, op, dir, bs->len, distance, mpos); /* depending on other vel */ @@ -2257,7 +2257,7 @@ static int _softbody_calc_forces_slice_in_a_thread(Scene *scene, Object *ob, flo } /* naive ball self collision done */ - if (_final_goal(ob, bp) < SOFTGOALSNAP) { /* ommit this bp when it snaps */ + if (_final_goal(ob, bp) < SOFTGOALSNAP) { /* omit this bp when it snaps */ float auxvect[3]; float velgoal[3]; @@ -2652,7 +2652,7 @@ static void softbody_calc_forces(Scene *scene, Object *ob, float forcetime, floa } /* naive ball self collision done */ - if (_final_goal(ob, bp) < SOFTGOALSNAP) { /* ommit this bp when it snaps */ + if (_final_goal(ob, bp) < SOFTGOALSNAP) { /* omit this bp when it snaps */ float auxvect[3]; float velgoal[3]; diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c index 4cd85fb342e..8a272cd9d81 100644 --- a/source/blender/blenkernel/intern/text.c +++ b/source/blender/blenkernel/intern/text.c @@ -267,16 +267,79 @@ static void cleanup_textline(TextLine *tl) tl->len += txt_extended_ascii_as_utf8(&tl->line); } +/** + * used for load and reload (unlike txt_insert_buf) + * assumes all fields are empty + */ +static void text_from_buf(Text *text, const unsigned char *buffer, const int len) +{ + int i, llen; + + BLI_assert(BLI_listbase_is_empty(&text->lines)); + + text->nlines = 0; + llen = 0; + for (i = 0; i < len; i++) { + if (buffer[i] == '\n') { + TextLine *tmp; + + tmp = (TextLine *) MEM_mallocN(sizeof(TextLine), "textline"); + tmp->line = (char *) MEM_mallocN(llen + 1, "textline_string"); + tmp->format = NULL; + + if (llen) memcpy(tmp->line, &buffer[i - llen], llen); + tmp->line[llen] = 0; + tmp->len = llen; + + cleanup_textline(tmp); + + BLI_addtail(&text->lines, tmp); + text->nlines++; + + llen = 0; + continue; + } + llen++; + } + + /* create new line in cases: + * - rest of line (if last line in file hasn't got \n terminator). + * in this case content of such line would be used to fill text line buffer + * - file is empty. in this case new line is needed to start editing from. + * - last characted in buffer is \n. in this case new line is needed to + * deal with newline at end of file. (see [#28087]) (sergey) */ + if (llen != 0 || text->nlines == 0 || buffer[len - 1] == '\n') { + TextLine *tmp; + + tmp = (TextLine *) MEM_mallocN(sizeof(TextLine), "textline"); + tmp->line = (char *) MEM_mallocN(llen + 1, "textline_string"); + tmp->format = NULL; + + if (llen) memcpy(tmp->line, &buffer[i - llen], llen); + + tmp->line[llen] = 0; + tmp->len = llen; + + cleanup_textline(tmp); + + BLI_addtail(&text->lines, tmp); + text->nlines++; + } + + text->curl = text->sell = text->lines.first; + text->curc = text->selc = 0; +} + int BKE_text_reload(Text *text) { FILE *fp; - int i, llen, len; + int len; unsigned char *buffer; TextLine *tmp; char str[FILE_MAX]; - struct stat st; + BLI_stat_t st; - if (!text || !text->name) return 0; + if (!text->name) return 0; BLI_strncpy(str, text->name, FILE_MAX); BLI_path_abs(str, G.main->name); @@ -299,13 +362,12 @@ int BKE_text_reload(Text *text) /* clear undo buffer */ MEM_freeN(text->undo_buf); init_undo_text(text); - + fseek(fp, 0L, SEEK_END); len = ftell(fp); fseek(fp, 0L, SEEK_SET); - text->undo_pos = -1; - + buffer = MEM_mallocN(len, "text_buffer"); // under windows fread can return less then len bytes because // of CR stripping @@ -313,51 +375,11 @@ int BKE_text_reload(Text *text) fclose(fp); - stat(str, &st); + BLI_stat(str, &st); text->mtime = st.st_mtime; - - text->nlines = 0; - llen = 0; - for (i = 0; i < len; i++) { - if (buffer[i] == '\n') { - tmp = (TextLine *) MEM_mallocN(sizeof(TextLine), "textline"); - tmp->line = (char *) MEM_mallocN(llen + 1, "textline_string"); - tmp->format = NULL; - - if (llen) memcpy(tmp->line, &buffer[i - llen], llen); - tmp->line[llen] = 0; - tmp->len = llen; - - cleanup_textline(tmp); - BLI_addtail(&text->lines, tmp); - text->nlines++; - - llen = 0; - continue; - } - llen++; - } + text_from_buf(text, buffer, len); - if (llen != 0 || text->nlines == 0) { - tmp = (TextLine *) MEM_mallocN(sizeof(TextLine), "textline"); - tmp->line = (char *) MEM_mallocN(llen + 1, "textline_string"); - tmp->format = NULL; - - if (llen) memcpy(tmp->line, &buffer[i - llen], llen); - - tmp->line[llen] = 0; - tmp->len = llen; - - cleanup_textline(tmp); - - BLI_addtail(&text->lines, tmp); - text->nlines++; - } - - text->curl = text->sell = text->lines.first; - text->curc = text->selc = 0; - MEM_freeN(buffer); return 1; } @@ -365,12 +387,11 @@ int BKE_text_reload(Text *text) Text *BKE_text_load_ex(Main *bmain, const char *file, const char *relpath, const bool is_internal) { FILE *fp; - int i, llen, len; + int len; unsigned char *buffer; - TextLine *tmp; Text *ta; char str[FILE_MAX]; - struct stat st; + BLI_stat_t st; BLI_strncpy(str, file, FILE_MAX); if (relpath) /* can be NULL (bg mode) */ @@ -388,10 +409,6 @@ Text *BKE_text_load_ex(Main *bmain, const char *file, const char *relpath, const if ((U.flag & USER_TXT_TABSTOSPACES_DISABLE) == 0) ta->flags = TXT_TABSTOSPACES; - fseek(fp, 0L, SEEK_END); - len = ftell(fp); - fseek(fp, 0L, SEEK_SET); - if (is_internal == false) { ta->name = MEM_mallocN(strlen(file) + 1, "text_name"); strcpy(ta->name, file); @@ -400,7 +417,12 @@ Text *BKE_text_load_ex(Main *bmain, const char *file, const char *relpath, const ta->flags |= TXT_ISMEM | TXT_ISDIRTY; } + /* clear undo buffer */ init_undo_text(ta); + + fseek(fp, 0L, SEEK_END); + len = ftell(fp); + fseek(fp, 0L, SEEK_SET); buffer = MEM_mallocN(len, "text_buffer"); // under windows fread can return less then len bytes because @@ -409,56 +431,10 @@ Text *BKE_text_load_ex(Main *bmain, const char *file, const char *relpath, const fclose(fp); - stat(str, &st); + BLI_stat(str, &st); ta->mtime = st.st_mtime; - ta->nlines = 0; - llen = 0; - for (i = 0; i < len; i++) { - if (buffer[i] == '\n') { - tmp = (TextLine *) MEM_mallocN(sizeof(TextLine), "textline"); - tmp->line = (char *) MEM_mallocN(llen + 1, "textline_string"); - tmp->format = NULL; - - if (llen) memcpy(tmp->line, &buffer[i - llen], llen); - tmp->line[llen] = 0; - tmp->len = llen; - - cleanup_textline(tmp); - - BLI_addtail(&ta->lines, tmp); - ta->nlines++; - - llen = 0; - continue; - } - llen++; - } - - /* create new line in cases: - * - rest of line (if last line in file hasn't got \n terminator). - * in this case content of such line would be used to fill text line buffer - * - file is empty. in this case new line is needed to start editing from. - * - last characted in buffer is \n. in this case new line is needed to - * deal with newline at end of file. (see [#28087]) (sergey) */ - if (llen != 0 || ta->nlines == 0 || buffer[len - 1] == '\n') { - tmp = (TextLine *) MEM_mallocN(sizeof(TextLine), "textline"); - tmp->line = (char *) MEM_mallocN(llen + 1, "textline_string"); - tmp->format = NULL; - - if (llen) memcpy(tmp->line, &buffer[i - llen], llen); - - tmp->line[llen] = 0; - tmp->len = llen; - - cleanup_textline(tmp); - - BLI_addtail(&ta->lines, tmp); - ta->nlines++; - } - - ta->curl = ta->sell = ta->lines.first; - ta->curc = ta->selc = 0; + text_from_buf(ta, buffer, len); MEM_freeN(buffer); @@ -671,7 +647,7 @@ int BKE_text_file_modified_check(Text *text) int result; char file[FILE_MAX]; - if (!text || !text->name) + if (!text->name) return 0; BLI_strncpy(file, text->name, FILE_MAX); @@ -700,7 +676,7 @@ void BKE_text_file_modified_ignore(Text *text) int result; char file[FILE_MAX]; - if (!text || !text->name) return; + if (!text->name) return; BLI_strncpy(file, text->name, FILE_MAX); BLI_path_abs(file, G.main->name); @@ -766,9 +742,7 @@ static TextLine *txt_new_linen(const char *str, int n) void txt_clean_text(Text *text) { TextLine **top, **bot; - - if (!text) return; - + if (!text->lines.first) { if (text->lines.last) text->lines.first = text->lines.last; else text->lines.first = text->lines.last = txt_new_line(NULL); @@ -907,8 +881,7 @@ void txt_move_up(Text *text, const bool sel) { TextLine **linep; int *charp; - - if (!text) return; + if (sel) txt_curs_sel(text, &linep, &charp); else { txt_pop_first(text); txt_curs_cur(text, &linep, &charp); } if (!*linep) return; @@ -930,8 +903,7 @@ void txt_move_down(Text *text, const bool sel) { TextLine **linep; int *charp; - - if (!text) return; + if (sel) txt_curs_sel(text, &linep, &charp); else { txt_pop_last(text); txt_curs_cur(text, &linep, &charp); } if (!*linep) return; @@ -953,8 +925,7 @@ void txt_move_left(Text *text, const bool sel) TextLine **linep; int *charp; int tabsize = 0, i = 0; - - if (!text) return; + if (sel) txt_curs_sel(text, &linep, &charp); else { txt_pop_first(text); txt_curs_cur(text, &linep, &charp); } if (!*linep) return; @@ -998,8 +969,7 @@ void txt_move_right(Text *text, const bool sel) TextLine **linep; int *charp, i; bool do_tab = false; - - if (!text) return; + if (sel) txt_curs_sel(text, &linep, &charp); else { txt_pop_last(text); txt_curs_cur(text, &linep, &charp); } if (!*linep) return; @@ -1040,8 +1010,7 @@ void txt_jump_left(Text *text, const bool sel, const bool use_init_step) { TextLine **linep; int *charp; - - if (!text) return; + if (sel) txt_curs_sel(text, &linep, &charp); else { txt_pop_first(text); txt_curs_cur(text, &linep, &charp); } if (!*linep) return; @@ -1057,8 +1026,7 @@ void txt_jump_right(Text *text, const bool sel, const bool use_init_step) { TextLine **linep; int *charp; - - if (!text) return; + if (sel) txt_curs_sel(text, &linep, &charp); else { txt_pop_last(text); txt_curs_cur(text, &linep, &charp); } if (!*linep) return; @@ -1074,8 +1042,7 @@ void txt_move_bol(Text *text, const bool sel) { TextLine **linep; int *charp; - - if (!text) return; + if (sel) txt_curs_sel(text, &linep, &charp); else txt_curs_cur(text, &linep, &charp); if (!*linep) return; @@ -1089,8 +1056,7 @@ void txt_move_eol(Text *text, const bool sel) { TextLine **linep; int *charp; - - if (!text) return; + if (sel) txt_curs_sel(text, &linep, &charp); else txt_curs_cur(text, &linep, &charp); if (!*linep) return; @@ -1104,8 +1070,7 @@ void txt_move_bof(Text *text, const bool sel) { TextLine **linep; int *charp; - - if (!text) return; + if (sel) txt_curs_sel(text, &linep, &charp); else txt_curs_cur(text, &linep, &charp); if (!*linep) return; @@ -1120,8 +1085,7 @@ void txt_move_eof(Text *text, const bool sel) { TextLine **linep; int *charp; - - if (!text) return; + if (sel) txt_curs_sel(text, &linep, &charp); else txt_curs_cur(text, &linep, &charp); if (!*linep) return; @@ -1143,8 +1107,7 @@ void txt_move_to(Text *text, unsigned int line, unsigned int ch, const bool sel) TextLine **linep; int *charp; unsigned int i; - - if (!text) return; + if (sel) txt_curs_sel(text, &linep, &charp); else txt_curs_cur(text, &linep, &charp); if (!*linep) return; @@ -1181,7 +1144,6 @@ static void txt_curs_swap(Text *text) static void txt_pop_first(Text *text) { - if (txt_get_span(text->curl, text->sell) < 0 || (text->curl == text->sell && text->curc > text->selc)) { @@ -1210,7 +1172,6 @@ void txt_pop_sel(Text *text) void txt_order_cursors(Text *text, const bool reverse) { - if (!text) return; if (!text->curl) return; if (!text->sell) return; @@ -1240,8 +1201,7 @@ static void txt_delete_sel(Text *text) { TextLine *tmpl; char *buf; - - if (!text) return; + if (!text->curl) return; if (!text->sell) return; @@ -1277,8 +1237,6 @@ static void txt_delete_sel(Text *text) void txt_sel_all(Text *text) { - if (!text) return; - text->curl = text->lines.first; text->curc = 0; @@ -1301,7 +1259,6 @@ void txt_sel_clear(Text *text) void txt_sel_line(Text *text) { - if (!text) return; if (!text->curl) return; text->curc = 0; @@ -1319,8 +1276,7 @@ char *txt_to_buf(Text *text) TextLine *tmp, *linef, *linel; int charf, charl; char *buf; - - if (!text) return NULL; + if (!text->curl) return NULL; if (!text->sell) return NULL; if (!text->lines.first) return NULL; @@ -1382,7 +1338,7 @@ int txt_find_string(Text *text, const char *findstr, int wrap, int match_case) TextLine *tl, *startl; const char *s = NULL; - if (!text || !text->curl || !text->sell) return 0; + if (!text->curl || !text->sell) return 0; txt_order_cursors(text, false); @@ -1422,8 +1378,7 @@ char *txt_sel_to_buf(Text *text) int length = 0; TextLine *tmp, *linef, *linel; int charf, charl; - - if (!text) return NULL; + if (!text->curl) return NULL; if (!text->sell) return NULL; @@ -1504,7 +1459,6 @@ void txt_insert_buf(Text *text, const char *in_buffer) TextLine *add; char *buffer; - if (!text) return; if (!in_buffer) return; txt_delete_sel(text); @@ -2386,8 +2340,7 @@ void txt_split_curline(Text *text) { TextLine *ins; char *left, *right; - - if (!text) return; + if (!text->curl) return; txt_delete_sel(text); @@ -2429,7 +2382,6 @@ void txt_split_curline(Text *text) static void txt_delete_line(Text *text, TextLine *line) { - if (!text) return; if (!text->curl) return; BLI_remlink(&text->lines, line); @@ -2446,8 +2398,6 @@ static void txt_delete_line(Text *text, TextLine *line) static void txt_combine_lines(Text *text, TextLine *linea, TextLine *lineb) { char *tmp, *s; - - if (!text) return; if (!linea || !lineb) return; @@ -2471,7 +2421,7 @@ void txt_duplicate_line(Text *text) { TextLine *textline; - if (!text || !text->curl) return; + if (!text->curl) return; if (text->curl == text->sell) { textline = txt_new_line(text->curl->line); @@ -2487,8 +2437,7 @@ void txt_duplicate_line(Text *text) void txt_delete_char(Text *text) { unsigned int c = '\n'; - - if (!text) return; + if (!text->curl) return; if (txt_has_sel(text)) { /* deleting a selection */ @@ -2531,7 +2480,6 @@ void txt_backspace_char(Text *text) { unsigned int c = '\n'; - if (!text) return; if (!text->curl) return; if (txt_has_sel(text)) { /* deleting a selection */ @@ -2595,8 +2543,7 @@ static bool txt_add_char_intern(Text *text, unsigned int add, bool replace_tabs) { char *tmp, ch[BLI_UTF8_MAX]; size_t add_len; - - if (!text) return 0; + if (!text->curl) return 0; if (add == '\n') { @@ -2655,8 +2602,7 @@ bool txt_replace_char(Text *text, unsigned int add) unsigned int del; size_t del_size = 0, add_size; char ch[BLI_UTF8_MAX]; - - if (!text) return 0; + if (!text->curl) return 0; /* If text is selected or we're at the end of the line just use txt_add_char */ @@ -2710,7 +2656,7 @@ void txt_indent(Text *text) /* hardcoded: TXT_TABSIZE = 4 spaces: */ int spaceslen = TXT_TABSIZE; - if (ELEM(NULL, text, text->curl, text->sell)) { + if (ELEM(NULL, text->curl, text->sell)) { return; } @@ -2777,7 +2723,7 @@ void txt_unindent(Text *text) /* hardcoded: TXT_TABSIZE = 4 spaces: */ int spaceslen = TXT_TABSIZE; - if (ELEM(NULL, text, text->curl, text->sell)) { + if (ELEM(NULL, text->curl, text->sell)) { return; } @@ -2830,8 +2776,7 @@ void txt_comment(Text *text) int len, num; char *tmp; char add = '#'; - - if (!text) return; + if (!text->curl) return; if (!text->sell) return; // Need to change this need to check if only one line is selected to more than one @@ -2878,8 +2823,7 @@ void txt_uncomment(Text *text) { int num = 0; char remove = '#'; - - if (!text) return; + if (!text->curl) return; if (!text->sell) return; @@ -2925,7 +2869,7 @@ void txt_move_lines(struct Text *text, const int direction) BLI_assert(ELEM(direction, TXT_MOVE_LINE_UP, TXT_MOVE_LINE_DOWN)); - if (!text || !text->curl || !text->sell) return; + if (!text->curl || !text->sell) return; txt_order_cursors(text, false); @@ -2958,6 +2902,7 @@ int txt_setcurr_tab_spaces(Text *text, int space) const char *comm = "#"; const char indent = (text->flags & TXT_TABSTOSPACES) ? ' ' : '\t'; static const char *back_words[] = {"return", "break", "continue", "pass", "yield", NULL}; + if (!text->curl) return 0; while (text->curl->line[i] == indent) { diff --git a/source/blender/blenkernel/intern/tracking.c b/source/blender/blenkernel/intern/tracking.c index b77cd744a18..40d9dc0d7e0 100644 --- a/source/blender/blenkernel/intern/tracking.c +++ b/source/blender/blenkernel/intern/tracking.c @@ -371,6 +371,9 @@ void BKE_tracking_clipboard_paste_tracks(MovieTracking *tracking, MovieTrackingO while (track) { MovieTrackingTrack *new_track = BKE_tracking_track_duplicate(track); + if (track->prev == NULL) { + tracking->act_track = new_track; + } BLI_addtail(tracksbase, new_track); BKE_tracking_track_unique_name(tracksbase, new_track); @@ -1789,13 +1792,19 @@ ImBuf *BKE_tracking_distortion_exec(MovieDistortion *distortion, MovieTracking * if (ibuf->rect_float) { if (undistort) { libmv_cameraIntrinsicsUndistortFloat(distortion->intrinsics, - ibuf->rect_float, resibuf->rect_float, - ibuf->x, ibuf->y, overscan, ibuf->channels); + ibuf->rect_float, + ibuf->x, ibuf->y, + overscan, + ibuf->channels, + resibuf->rect_float); } else { libmv_cameraIntrinsicsDistortFloat(distortion->intrinsics, - ibuf->rect_float, resibuf->rect_float, - ibuf->x, ibuf->y, overscan, ibuf->channels); + ibuf->rect_float, + ibuf->x, ibuf->y, + overscan, + ibuf->channels, + resibuf->rect_float); } if (ibuf->rect) @@ -1804,13 +1813,19 @@ ImBuf *BKE_tracking_distortion_exec(MovieDistortion *distortion, MovieTracking * else { if (undistort) { libmv_cameraIntrinsicsUndistortByte(distortion->intrinsics, - (unsigned char *)ibuf->rect, (unsigned char *)resibuf->rect, - ibuf->x, ibuf->y, overscan, ibuf->channels); + (unsigned char *)ibuf->rect, + ibuf->x, ibuf->y, + overscan, + ibuf->channels, + (unsigned char *)resibuf->rect); } else { libmv_cameraIntrinsicsDistortByte(distortion->intrinsics, - (unsigned char *)ibuf->rect, (unsigned char *)resibuf->rect, - ibuf->x, ibuf->y, overscan, ibuf->channels); + (unsigned char *)ibuf->rect, + ibuf->x, ibuf->y, + overscan, + ibuf->channels, + (unsigned char *)resibuf->rect); } } @@ -2017,14 +2032,14 @@ ImBuf *BKE_tracking_sample_pattern(int frame_width, int frame_height, ImBuf *sea } if (search_ibuf->rect_float) { - libmv_samplePlanarPatch(search_ibuf->rect_float, - search_ibuf->x, search_ibuf->y, 4, - src_pixel_x, src_pixel_y, - num_samples_x, num_samples_y, - mask, - pattern_ibuf->rect_float, - &warped_position_x, - &warped_position_y); + libmv_samplePlanarPatchFloat(search_ibuf->rect_float, + search_ibuf->x, search_ibuf->y, 4, + src_pixel_x, src_pixel_y, + num_samples_x, num_samples_y, + mask, + pattern_ibuf->rect_float, + &warped_position_x, + &warped_position_y); } else { libmv_samplePlanarPatchByte((unsigned char *) search_ibuf->rect, @@ -2185,10 +2200,10 @@ void BKE_tracking_disable_channels(ImBuf *ibuf, bool disable_red, bool disable_g /* ** Channels sort comparators ** */ -static int channels_alpha_sort(void *a, void *b) +static int channels_alpha_sort(const void *a, const void *b) { - MovieTrackingDopesheetChannel *channel_a = a; - MovieTrackingDopesheetChannel *channel_b = b; + const MovieTrackingDopesheetChannel *channel_a = a; + const MovieTrackingDopesheetChannel *channel_b = b; if (BLI_strcasecmp(channel_a->track->name, channel_b->track->name) > 0) return 1; @@ -2196,10 +2211,10 @@ static int channels_alpha_sort(void *a, void *b) return 0; } -static int channels_total_track_sort(void *a, void *b) +static int channels_total_track_sort(const void *a, const void *b) { - MovieTrackingDopesheetChannel *channel_a = a; - MovieTrackingDopesheetChannel *channel_b = b; + const MovieTrackingDopesheetChannel *channel_a = a; + const MovieTrackingDopesheetChannel *channel_b = b; if (channel_a->total_frames > channel_b->total_frames) return 1; @@ -2207,10 +2222,10 @@ static int channels_total_track_sort(void *a, void *b) return 0; } -static int channels_longest_segment_sort(void *a, void *b) +static int channels_longest_segment_sort(const void *a, const void *b) { - MovieTrackingDopesheetChannel *channel_a = a; - MovieTrackingDopesheetChannel *channel_b = b; + const MovieTrackingDopesheetChannel *channel_a = a; + const MovieTrackingDopesheetChannel *channel_b = b; if (channel_a->max_segment > channel_b->max_segment) return 1; @@ -2218,10 +2233,10 @@ static int channels_longest_segment_sort(void *a, void *b) return 0; } -static int channels_average_error_sort(void *a, void *b) +static int channels_average_error_sort(const void *a, const void *b) { - MovieTrackingDopesheetChannel *channel_a = a; - MovieTrackingDopesheetChannel *channel_b = b; + const MovieTrackingDopesheetChannel *channel_a = a; + const MovieTrackingDopesheetChannel *channel_b = b; if (channel_a->track->error > channel_b->track->error) return 1; @@ -2229,7 +2244,7 @@ static int channels_average_error_sort(void *a, void *b) return 0; } -static int channels_alpha_inverse_sort(void *a, void *b) +static int channels_alpha_inverse_sort(const void *a, const void *b) { if (channels_alpha_sort(a, b)) return 0; @@ -2237,7 +2252,7 @@ static int channels_alpha_inverse_sort(void *a, void *b) return 1; } -static int channels_total_track_inverse_sort(void *a, void *b) +static int channels_total_track_inverse_sort(const void *a, const void *b) { if (channels_total_track_sort(a, b)) return 0; @@ -2245,7 +2260,7 @@ static int channels_total_track_inverse_sort(void *a, void *b) return 1; } -static int channels_longest_segment_inverse_sort(void *a, void *b) +static int channels_longest_segment_inverse_sort(const void *a, const void *b) { if (channels_longest_segment_sort(a, b)) return 0; @@ -2253,10 +2268,10 @@ static int channels_longest_segment_inverse_sort(void *a, void *b) return 1; } -static int channels_average_error_inverse_sort(void *a, void *b) +static int channels_average_error_inverse_sort(const void *a, const void *b) { - MovieTrackingDopesheetChannel *channel_a = a; - MovieTrackingDopesheetChannel *channel_b = b; + const MovieTrackingDopesheetChannel *channel_a = a; + const MovieTrackingDopesheetChannel *channel_b = b; if (channel_a->track->error < channel_b->track->error) return 1; diff --git a/source/blender/blenkernel/intern/treehash.c b/source/blender/blenkernel/intern/treehash.c index a65bd28da97..866502c4ae1 100644 --- a/source/blender/blenkernel/intern/treehash.c +++ b/source/blender/blenkernel/intern/treehash.c @@ -91,7 +91,7 @@ static unsigned int tse_hash(const void *ptr) return hash.u_int; } -static int tse_cmp(const void *a, const void *b) +static bool tse_cmp(const void *a, const void *b) { const TreeStoreElem *tse_a = a; const TreeStoreElem *tse_b = b; |