Commit: e217839fd3488e09b83a99372707d6f9a31c7d10 Author: Bastien Montagne Date: Mon Feb 6 20:42:00 2017 +0100 Branches: master https://developer.blender.org/rBe217839fd3488e09b83a99372707d6f9a31c7d10
Cleanup writefile code a bit. Modernize some of it a bit, saves quite some lines of blabla (using shile instead of for loops... tsssts...). =================================================================== M source/blender/blenloader/intern/writefile.c =================================================================== diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index 7b8b95f000..abdc5fcf67 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -799,22 +799,18 @@ static void write_fcurves(WriteData *wd, ListBase *fcurves) static void write_actions(WriteData *wd, ListBase *idbase) { - bAction *act; - bActionGroup *grp; - TimeMarker *marker; - - for (act = idbase->first; act; act = act->id.next) { + for (bAction *act = idbase->first; act; act = act->id.next) { if (act->id.us > 0 || wd->current) { writestruct(wd, ID_AC, bAction, 1, act); write_iddata(wd, &act->id); write_fcurves(wd, &act->curves); - for (grp = act->groups.first; grp; grp = grp->next) { + for (bActionGroup *grp = act->groups.first; grp; grp = grp->next) { writestruct(wd, DATA, bActionGroup, 1, grp); } - for (marker = act->markers.first; marker; marker = marker->next) { + for (TimeMarker *marker = act->markers.first; marker; marker = marker->next) { writestruct(wd, DATA, TimeMarker, 1, marker); } } @@ -1280,13 +1276,7 @@ static void write_pointcaches(WriteData *wd, ListBase *ptcaches) } static void write_particlesettings(WriteData *wd, ListBase *idbase) { - ParticleSettings *part; - ParticleDupliWeight *dw; - GroupObject *go; - int a; - - part = idbase->first; - while (part) { + for (ParticleSettings *part = idbase->first; part; part = part->id.next) { if (part->id.us > 0 || wd->current) { /* write LibData */ writestruct(wd, ID_PA, ParticleSettings, 1, part); @@ -1306,24 +1296,23 @@ static void write_particlesettings(WriteData *wd, ListBase *idbase) write_curvemapping(wd, part->roughcurve); } - dw = part->dupliweights.first; - for (; dw; dw = dw->next) { + for (ParticleDupliWeight *dw = part->dupliweights.first; dw; dw = dw->next) { /* update indices, but only if dw->ob is set (can be NULL after loading e.g.) */ if (dw->ob != NULL) { dw->index = 0; if (part->dup_group) { /* can be NULL if lining fails or set to None */ - for (go = part->dup_group->gobject.first; go && go->ob != dw->ob; go = go->next, dw->index++); + for (GroupObject *go = part->dup_group->gobject.first; + go && go->ob != dw->ob; + go = go->next, dw->index++); } } writestruct(wd, DATA, ParticleDupliWeight, 1, dw); } if (part->boids && part->phystype == PART_PHYS_BOIDS) { - BoidState *state = part->boids->states.first; - writestruct(wd, DATA, BoidSettings, 1, part->boids); - for (; state; state = state->next) { + for (BoidState *state = part->boids->states.first; state; state = state->next) { write_boid_state(wd, state); } } @@ -1331,13 +1320,12 @@ static void write_particlesettings(WriteData *wd, ListBase *idbase) writestruct(wd, DATA, SPHFluidSettings, 1, part->fluid); } - for (a = 0; a < MAX_MTEX; a++) { + for (int a = 0; a < MAX_MTEX; a++) { if (part->mtex[a]) { writestruct(wd, DATA, MTex, 1, part->mtex[a]); } } } - part = part->id.next; } } static void write_particlesystems(WriteData *wd, ListBase *particles) @@ -1835,10 +1823,7 @@ static void write_modifiers(WriteData *wd, ListBase *modbase) static void write_objects(WriteData *wd, ListBase *idbase) { - Object *ob; - - ob = idbase->first; - while (ob) { + for (Object *ob = idbase->first; ob; ob = ob->id.next) { if (ob->id.us > 0 || wd->current) { /* write LibData */ writestruct(wd, ID_OB, Object, 1, ob); @@ -1897,8 +1882,6 @@ static void write_objects(WriteData *wd, ListBase *idbase) } write_previews(wd, ob->preview); - - ob = ob->id.next; } mywrite_flush(wd); @@ -1907,26 +1890,19 @@ static void write_objects(WriteData *wd, ListBase *idbase) static void write_vfonts(WriteData *wd, ListBase *idbase) { - VFont *vf; - PackedFile *pf; - - vf = idbase->first; - while (vf) { + for (VFont *vf = idbase->first; vf; vf = vf->id.next) { if (vf->id.us > 0 || wd->current) { /* write LibData */ writestruct(wd, ID_VF, VFont, 1, vf); write_iddata(wd, &vf->id); /* direct data */ - if (vf->packedfile) { - pf = vf->packedfile; + PackedFile *pf = vf->packedfile; writestruct(wd, DATA, PackedFile, 1, pf); writedata(wd, DATA, pf->size, pf->data); } } - - vf = vf->id.next; } mywrite_flush(wd); @@ -1935,11 +1911,7 @@ static void write_vfonts(WriteData *wd, ListBase *idbase) static void write_keys(WriteData *wd, ListBase *idbase) { - Key *key; - KeyBlock *kb; - - key = idbase->first; - while (key) { + for (Key *key = idbase->first; key; key = key->id.next) { if (key->id.us > 0 || wd->current) { /* write LibData */ writestruct(wd, ID_KE, Key, 1, key); @@ -1950,17 +1922,13 @@ static void write_keys(WriteData *wd, ListBase *idbase) } /* direct data */ - kb = key->block.first; - while (kb) { + for (KeyBlock *kb = key->block.first; kb; kb = kb->next) { writestruct(wd, DATA, KeyBlock, 1, kb); if (kb->data) { writedata(wd, DATA, kb->totelem * key->elemsize, kb->data); } - kb = kb->next; } } - - key = key->id.next; } mywrite_flush(wd); @@ -1968,10 +1936,7 @@ static void write_keys(WriteData *wd, ListBase *idbase) static void write_cameras(WriteData *wd, ListBase *idbase) { - Camera *cam; - - cam = idbase->first; - while (cam) { + for (Camera *cam = idbase->first; cam; cam = cam->id.next) { if (cam->id.us > 0 || wd->current) { /* write LibData */ writestruct(wd, ID_CA, Camera, 1, cam); @@ -1981,18 +1946,12 @@ static void write_cameras(WriteData *wd, ListBase *idbase) write_animdata(wd, cam->adt); } } - - cam = cam->id.next; } } static void write_mballs(WriteData *wd, ListBase *idbase) { - MetaBall *mb; - MetaElem *ml; - - mb = idbase->first; - while (mb) { + for (MetaBall *mb = idbase->first; mb; mb = mb->id.next) { if (mb->id.us > 0 || wd->current) { /* write LibData */ writestruct(wd, ID_MB, MetaBall, 1, mb); @@ -2004,23 +1963,16 @@ static void write_mballs(WriteData *wd, ListBase *idbase) write_animdata(wd, mb->adt); } - ml = mb->elems.first; - while (ml) { + for (MetaElem *ml = mb->elems.first; ml; ml = ml->next) { writestruct(wd, DATA, MetaElem, 1, ml); - ml = ml->next; } } - mb = mb->id.next; } } static void write_curves(WriteData *wd, ListBase *idbase) { - Curve *cu; - Nurb *nu; - - cu = idbase->first; - while (cu) { + for (Curve *cu = idbase->first; cu; cu = cu->id.next) { if (cu->id.us > 0 || wd->current) { /* write LibData */ writestruct(wd, ID_CU, Curve, 1, cu); @@ -2039,13 +1991,10 @@ static void write_curves(WriteData *wd, ListBase *idbase) } else { /* is also the order of reading */ - nu = cu->nurb.first; - while (nu) { + for (Nurb *nu = cu->nurb.first; nu; nu = nu->next) { writestruct(wd, DATA, Nurb, 1, nu); - nu = nu->next; } - nu = cu->nurb.first; - while (nu) { + for (Nurb *nu = cu->nurb.first; nu; nu = nu->next) { if (nu->type == CU_BEZIER) { writestruct(wd, DATA, BezTriple, nu->pntsu, nu->bezt); } @@ -2058,11 +2007,9 @@ static void write_curves(WriteData *wd, ListBase *idbase) writedata(wd, DATA, KNOTSV(nu) * sizeof(float), nu->knotsv); } } - nu = nu->next; } } } - cu = cu->id.next; } mywrite_flush(wd); @@ -2184,15 +2131,13 @@ static void write_customdata( static void write_meshes(WriteData *wd, ListBase *idbase) { - Mesh *mesh; - bool save_for_old_blender = false; - #ifdef USE_BMESH_SAVE_AS_COMPAT - save_for_old_blender = wd->use_mesh_compat; /* option to save with older mesh format */ + const bool save_for_old_blender = wd->use_mesh_compat; /* option to save with older mesh format */ +#else + const bool save_for_old_blender = false; #endif - mesh = idbase->first; - while (mesh) { + for (Mesh *mesh = idbase->first; mesh; mesh = mesh->id.next) { CustomDataLayer *vlayers = NULL, vlayers_buff[CD_TEMP_CHUNK_SIZE]; CustomDataLayer *elayers = NULL, elayers_buff[CD_TEMP_CHUNK_SIZE]; CustomDataLayer *flayers = NULL, flayers_buff[CD_TEMP_CHUNK_SIZE]; @@ -2336,8 +2281,6 @@ static void write_meshes(WriteData *wd, ListBase *idbase) if (players && players != players_buff) { MEM_freeN(players); } - - mesh = mesh->id.next; } mywrite_flush(wd); @@ -2345,10 +2288,7 @@ static void write_meshes(WriteData *wd, ListBase *idbase) static void write_lattices(WriteData *wd, ListBase *idbase) { - Lattice *lt; - - lt = idbase->first; - while (lt) { + for (Lattice *lt = idbase->first; lt; lt = lt->id.next) { if (lt->id.us > 0 || wd->current) { /* write LibData */ writestruct(wd, ID_LT, Lattice, 1, lt); @@ -2363,9 +2303,7 @@ static void write_lattices(WriteData *wd, ListBase *idbase) writestruct(wd, DATA, BPoint, lt->pntsu * lt->pntsv * lt->pntsw, lt->def); write_dverts(wd, lt->pntsu * lt->pntsv * lt->pntsw, lt->dvert); - } - lt = lt->id.next; } mywrite_flush(wd); @@ -2373,14 +2311,10 @@ static void write_lattices(WriteData *wd, ListBase *idbase) static void write_images(WriteData *wd, ListBase *idbase) { - Image *ima; - PackedFile *pf; - ImageView *iv; - ImagePackedFile *imapf; - - ima = idbase->first; - while (ima) { + for (Image *ima = idbase->first; ima; ima = ima->id.next) { if (ima->id.us > 0 || wd->current) { + ImagePackedFile *imapf; + /* Some trickery to keep forward compatibility of packed images. */ BLI_assert(ima->packedfile == NULL); if (ima->packedfiles.first != NULL) { @@ -2395,7 +2329,7 @@ static void write_images(WriteData *wd, ListBase *idbase) for (imapf = ima->packedfiles.first; imapf; imapf = imapf->next) { writestruct(wd, DATA, ImagePackedFile, 1, imapf); if (imapf->packedfile) { - pf = imapf->packedfile; + PackedFile *pf = imapf->packedfile; writestruct(wd, DATA, PackedFile, 1, pf); writedata(wd, DATA, pf->size, pf->data); } @@ -2403,14 +2337,13 @@ static void write_images(WriteData *wd, ListBase *idbase) write_previews(wd, ima->preview); - for (iv = ima @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs