diff options
-rw-r--r-- | source/blender/blenloader/CMakeLists.txt | 7 | ||||
-rw-r--r-- | source/blender/blenloader/intern/writefile.c | 838 | ||||
-rw-r--r-- | source/blender/makesdna/intern/CMakeLists.txt | 16 | ||||
-rw-r--r-- | source/blender/makesdna/intern/makesdna.c | 53 |
4 files changed, 504 insertions, 410 deletions
diff --git a/source/blender/blenloader/CMakeLists.txt b/source/blender/blenloader/CMakeLists.txt index 8364df38208..479d3a15e6c 100644 --- a/source/blender/blenloader/CMakeLists.txt +++ b/source/blender/blenloader/CMakeLists.txt @@ -35,6 +35,10 @@ set(INC ../nodes ../render/extern/include ../../../intern/guardedalloc + + # for writefile.c: dna_type_offsets.h + ${CMAKE_BINARY_DIR}/source/blender/makesdna/intern + ) set(INC_SYS @@ -74,3 +78,6 @@ if(WITH_CODEC_FFMPEG) endif() blender_add_lib(bf_blenloader "${SRC}" "${INC}" "${INC_SYS}") + +# needed so writefile.c can use dna_type_offsets.h +add_dependencies(bf_blenloader bf_dna) diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index 5a7b2a7880c..9cf32e1fb73 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -184,6 +184,9 @@ #include "readfile.h" +/* for SDNA_TYPE_FROM_STRUCT() macro */ +#include "dna_type_offsets.h" + #include <errno.h> /* ********* my write, buffered writing with minimum size chunks ************ */ @@ -367,7 +370,7 @@ static void writedata_free(WriteData *wd) * \param len Length of new chunk of data * \warning Talks to other functions with global parameters */ - + #define MYWRITE_FLUSH NULL static void mywrite(WriteData *wd, const void *adr, int len) @@ -462,13 +465,15 @@ static int endwrite(WriteData *wd) /* ********** WRITE FILE ****************** */ -static void writestruct_at_address( - WriteData *wd, int filecode, const char *structname, int nr, +static void writestruct_at_address_nr( + WriteData *wd, int filecode, const int struct_nr, int nr, const void *adr, const void *data) { BHead bh; const short *sp; + BLI_assert(struct_nr > 0 && struct_nr < SDNA_TYPE_MAX); + if (adr == NULL || data == NULL || nr == 0) { return; } @@ -478,11 +483,7 @@ static void writestruct_at_address( bh.old = adr; bh.nr = nr; - bh.SDNAnr = DNA_struct_find_nr(wd->sdna, structname); - if (bh.SDNAnr == -1) { - printf("error: can't find SDNA code <%s>\n", structname); - return; - } + bh.SDNAnr = struct_nr; sp = wd->sdna->structs[bh.SDNAnr]; bh.len = nr * wd->sdna->typelens[sp[0]]; @@ -495,11 +496,35 @@ static void writestruct_at_address( mywrite(wd, data, bh.len); } -static void writestruct( +static void writestruct_at_address_id( + WriteData *wd, int filecode, const char *structname, int nr, + const void *adr, const void *data) +{ + if (adr == NULL || data == NULL || nr == 0) { + return; + } + + const int SDNAnr = DNA_struct_find_nr(wd->sdna, structname); + if (UNLIKELY(SDNAnr == -1)) { + printf("error: can't find SDNA code <%s>\n", structname); + return; + } + + writestruct_at_address_nr(wd, filecode, SDNAnr, nr, adr, data); +} + +static void writestruct_nr( + WriteData *wd, int filecode, const int struct_nr, int nr, + const void *adr) +{ + writestruct_at_address_nr(wd, filecode, struct_nr, nr, adr, adr); +} + +static void writestruct_id( WriteData *wd, int filecode, const char *structname, int nr, const void *adr) { - writestruct_at_address(wd, filecode, structname, nr, adr, adr); + writestruct_at_address_id(wd, filecode, structname, nr, adr, adr); } static void writedata(WriteData *wd, int filecode, int len, const void *adr) /* do not use for structs */ @@ -525,16 +550,45 @@ static void writedata(WriteData *wd, int filecode, int len, const void *adr) /* } /* use this to force writing of lists in same order as reading (using link_list) */ -static void writelist(WriteData *wd, int filecode, const char *structname, const ListBase *lb) +static void writelist_nr(WriteData *wd, int filecode, const int struct_nr, const ListBase *lb) { const Link *link = lb->first; while (link) { - writestruct(wd, filecode, structname, 1, link); + writestruct_nr(wd, filecode, struct_nr, 1, link); link = link->next; } } +#if 0 +static void writelist_id(WriteData *wd, int filecode, const char *structname, const ListBase *lb) +{ + const Link *link = lb->first; + if (link) { + + const int struct_nr = DNA_struct_find_nr(wd->sdna, structname); + if (struct_nr == -1) { + printf("error: can't find SDNA code <%s>\n", structname); + return; + } + + while (link) { + writestruct_nr(wd, filecode, struct_nr, 1, link); + link = link->next; + } + } +} +#endif + +#define writestruct_at_address(wd, filecode, struct_id, nr, adr, data) \ + writestruct_at_address_nr(wd, filecode, SDNA_TYPE_FROM_STRUCT(struct_id), nr, adr, data) + +#define writestruct(wd, filecode, struct_id, nr, adr) \ + writestruct_nr(wd, filecode, SDNA_TYPE_FROM_STRUCT(struct_id), nr, adr) + +#define writelist(wd, filecode, struct_id, lb) \ + writelist_nr(wd, filecode, SDNA_TYPE_FROM_STRUCT(struct_id), lb) + /* *************** writing some direct data structs used in more code parts **************** */ /*These functions are used by blender's .blend system for file saving/loading.*/ void IDP_WriteProperty_OnlyData(const IDProperty *prop, void *wd); @@ -564,7 +618,7 @@ static void IDP_WriteIDPArray(const IDProperty *prop, void *wd) const IDProperty *array = prop->data.pointer; int a; - writestruct(wd, DATA, "IDProperty", prop->len, array); + writestruct(wd, DATA, IDProperty, prop->len, array); for (a = 0; a < prop->len; a++) { IDP_WriteProperty_OnlyData(&array[a], wd); @@ -608,7 +662,7 @@ void IDP_WriteProperty_OnlyData(const IDProperty *prop, void *wd) void IDP_WriteProperty(const IDProperty *prop, void *wd) { - writestruct(wd, DATA, "IDProperty", 1, prop); + writestruct(wd, DATA, IDProperty, 1, prop); IDP_WriteProperty_OnlyData(prop, wd); } @@ -632,7 +686,7 @@ static void write_previews(WriteData *wd, const PreviewImage *prv_orig) prv.h[1] = 0; prv.rect[1] = NULL; } - writestruct_at_address(wd, DATA, "PreviewImage", 1, prv_orig, &prv); + writestruct_at_address(wd, DATA, PreviewImage, 1, prv_orig, &prv); if (prv.rect[0]) { writedata(wd, DATA, prv.w[0] * prv.h[0] * sizeof(unsigned int), prv.rect[0]); } @@ -647,7 +701,7 @@ static void write_fmodifiers(WriteData *wd, ListBase *fmodifiers) FModifier *fcm; /* Write all modifiers first (for faster reloading) */ - writelist(wd, DATA, "FModifier", fmodifiers); + writelist(wd, DATA, FModifier, fmodifiers); /* Modifiers */ for (fcm = fmodifiers->first; fcm; fcm = fcm->next) { @@ -656,7 +710,7 @@ static void write_fmodifiers(WriteData *wd, ListBase *fmodifiers) /* Write the specific data */ if (fmi && fcm->data) { /* firstly, just write the plain fmi->data struct */ - writestruct(wd, DATA, fmi->structName, 1, fcm->data); + writestruct_id(wd, DATA, fmi->structName, 1, fcm->data); /* do any modifier specific stuff */ switch (fcm->type) { @@ -677,7 +731,7 @@ static void write_fmodifiers(WriteData *wd, ListBase *fmodifiers) /* write envelope data */ if (data->data) { - writestruct(wd, DATA, "FCM_EnvelopeData", data->totvert, data->data); + writestruct(wd, DATA, FCM_EnvelopeData, data->totvert, data->data); } break; @@ -701,14 +755,14 @@ static void write_fcurves(WriteData *wd, ListBase *fcurves) { FCurve *fcu; - writelist(wd, DATA, "FCurve", fcurves); + writelist(wd, DATA, FCurve, fcurves); for (fcu = fcurves->first; fcu; fcu = fcu->next) { /* curve data */ if (fcu->bezt) { - writestruct(wd, DATA, "BezTriple", fcu->totvert, fcu->bezt); + writestruct(wd, DATA, BezTriple, fcu->totvert, fcu->bezt); } if (fcu->fpt) { - writestruct(wd, DATA, "FPoint", fcu->totvert, fcu->fpt); + writestruct(wd, DATA, FPoint, fcu->totvert, fcu->fpt); } if (fcu->rna_path) { @@ -720,10 +774,10 @@ static void write_fcurves(WriteData *wd, ListBase *fcurves) ChannelDriver *driver = fcu->driver; DriverVar *dvar; - writestruct(wd, DATA, "ChannelDriver", 1, driver); + writestruct(wd, DATA, ChannelDriver, 1, driver); /* variables */ - writelist(wd, DATA, "DriverVar", &driver->variables); + writelist(wd, DATA, DriverVar, &driver->variables); for (dvar = driver->variables.first; dvar; dvar = dvar->next) { DRIVER_TARGETS_USED_LOOPER(dvar) { @@ -748,17 +802,17 @@ static void write_actions(WriteData *wd, ListBase *idbase) for (act = idbase->first; act; act = act->id.next) { if (act->id.us > 0 || wd->current) { - writestruct(wd, ID_AC, "bAction", 1, act); + 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) { - writestruct(wd, DATA, "bActionGroup", 1, grp); + writestruct(wd, DATA, bActionGroup, 1, grp); } for (marker = act->markers.first; marker; marker = marker->next) { - writestruct(wd, DATA, "TimeMarker", 1, marker); + writestruct(wd, DATA, TimeMarker, 1, marker); } } } @@ -774,12 +828,12 @@ static void write_keyingsets(WriteData *wd, ListBase *list) for (ks = list->first; ks; ks = ks->next) { /* KeyingSet */ - writestruct(wd, DATA, "KeyingSet", 1, ks); + writestruct(wd, DATA, KeyingSet, 1, ks); /* Paths */ for (ksp = ks->paths.first; ksp; ksp = ksp->next) { /* Path */ - writestruct(wd, DATA, "KS_Path", 1, ksp); + writestruct(wd, DATA, KS_Path, 1, ksp); if (ksp->rna_path) { writedata(wd, DATA, strlen(ksp->rna_path) + 1, ksp->rna_path); @@ -792,7 +846,7 @@ static void write_nlastrips(WriteData *wd, ListBase *strips) { NlaStrip *strip; - writelist(wd, DATA, "NlaStrip", strips); + writelist(wd, DATA, NlaStrip, strips); for (strip = strips->first; strip; strip = strip->next) { /* write the strip's F-Curves and modifiers */ write_fcurves(wd, &strip->fcurves); @@ -810,7 +864,7 @@ static void write_nladata(WriteData *wd, ListBase *nlabase) /* write all the tracks */ for (nlt = nlabase->first; nlt; nlt = nlt->next) { /* write the track first */ - writestruct(wd, DATA, "NlaTrack", 1, nlt); + writestruct(wd, DATA, NlaTrack, 1, nlt); /* write the track's strips */ write_nlastrips(wd, &nlt->strips); @@ -822,7 +876,7 @@ static void write_animdata(WriteData *wd, AnimData *adt) AnimOverride *aor; /* firstly, just write the AnimData block */ - writestruct(wd, DATA, "AnimData", 1, adt); + writestruct(wd, DATA, AnimData, 1, adt); /* write drivers */ write_fcurves(wd, &adt->drivers); @@ -831,7 +885,7 @@ static void write_animdata(WriteData *wd, AnimData *adt) // FIXME: are these needed? for (aor = adt->overrides.first; aor; aor = aor->next) { /* overrides consist of base data + rna_path */ - writestruct(wd, DATA, "AnimOverride", 1, aor); + writestruct(wd, DATA, AnimOverride, 1, aor); writedata(wd, DATA, strlen(aor->rna_path) + 1, aor->rna_path); } @@ -844,13 +898,13 @@ static void write_animdata(WriteData *wd, AnimData *adt) static void write_curvemapping_curves(WriteData *wd, CurveMapping *cumap) { for (int a = 0; a < CM_TOT; a++) { - writestruct(wd, DATA, "CurveMapPoint", cumap->cm[a].totpoint, cumap->cm[a].curve); + writestruct(wd, DATA, CurveMapPoint, cumap->cm[a].totpoint, cumap->cm[a].curve); } } static void write_curvemapping(WriteData *wd, CurveMapping *cumap) { - writestruct(wd, DATA, "CurveMapping", 1, cumap); + writestruct(wd, DATA, CurveMapping, 1, cumap); write_curvemapping_curves(wd, cumap); } @@ -877,7 +931,7 @@ static void write_node_socket(WriteData *wd, bNodeTree *UNUSED(ntree), bNode *no #endif /* actual socket writing */ - writestruct(wd, DATA, "bNodeSocket", 1, sock); + writestruct(wd, DATA, bNodeSocket, 1, sock); if (sock->prop) { IDP_WriteProperty(sock->prop, wd); @@ -900,7 +954,7 @@ static void write_node_socket_interface(WriteData *wd, bNodeTree *UNUSED(ntree), #endif /* actual socket writing */ - writestruct(wd, DATA, "bNodeSocket", 1, sock); + writestruct(wd, DATA, bNodeSocket, 1, sock); if (sock->prop) { IDP_WriteProperty(sock->prop, wd); @@ -924,7 +978,7 @@ static void write_nodetree(WriteData *wd, bNodeTree *ntree) } for (node = ntree->nodes.first; node; node = node->next) { - writestruct(wd, DATA, "bNode", 1, node); + writestruct(wd, DATA, bNode, 1, node); if (node->prop) { IDP_WriteProperty(node->prop, wd); @@ -938,7 +992,7 @@ static void write_nodetree(WriteData *wd, bNodeTree *ntree) } for (link = node->internal_links.first; link; link = link->next) { - writestruct(wd, DATA, "bNodeLink", 1, link); + writestruct(wd, DATA, bNodeLink, 1, link); } if (node->storage) { @@ -955,7 +1009,7 @@ static void write_nodetree(WriteData *wd, bNodeTree *ntree) if (nss->bytecode) { writedata(wd, DATA, strlen(nss->bytecode) + 1, nss->bytecode); } - writestruct(wd, DATA, node->typeinfo->storagename, 1, node->storage); + writestruct_id(wd, DATA, node->typeinfo->storagename, 1, node->storage); } else if ((ntree->type == NTREE_COMPOSIT) && ELEM(node->type, CMP_NODE_TIME, CMP_NODE_CURVE_VEC, CMP_NODE_CURVE_RGB, CMP_NODE_HUECORRECT)) @@ -973,26 +1027,26 @@ static void write_nodetree(WriteData *wd, bNodeTree *ntree) /* pass */ } else { - writestruct(wd, DATA, node->typeinfo->storagename, 1, node->storage); + writestruct_id(wd, DATA, node->typeinfo->storagename, 1, node->storage); } } if (node->type == CMP_NODE_OUTPUT_FILE) { /* inputs have own storage data */ for (sock = node->inputs.first; sock; sock = sock->next) { - writestruct(wd, DATA, "NodeImageMultiFileSocket", 1, sock->storage); + writestruct(wd, DATA, NodeImageMultiFileSocket, 1, sock->storage); } } if (node->type == CMP_NODE_IMAGE) { /* write extra socket info */ for (sock = node->outputs.first; sock; sock = sock->next) { - writestruct(wd, DATA, "NodeImageLayer", 1, sock->storage); + writestruct(wd, DATA, NodeImageLayer, 1, sock->storage); } } } for (link = ntree->links.first; link; link = link->next) { - writestruct(wd, DATA, "bNodeLink", 1, link); + writestruct(wd, DATA, bNodeLink, 1, link); } for (sock = ntree->inputs.first; sock; sock = sock->next) { @@ -1074,7 +1128,7 @@ static void write_renderinfo(WriteData *wd, Main *mainvar) static void write_keymapitem(WriteData *wd, wmKeyMapItem *kmi) { - writestruct(wd, DATA, "wmKeyMapItem", 1, kmi); + writestruct(wd, DATA, wmKeyMapItem, 1, kmi); if (kmi->properties) { IDP_WriteProperty(kmi->properties, wd); } @@ -1090,17 +1144,17 @@ static void write_userdef(WriteData *wd) bPathCompare *path_cmp; uiStyle *style; - writestruct(wd, USER, "UserDef", 1, &U); + writestruct(wd, USER, UserDef, 1, &U); for (btheme = U.themes.first; btheme; btheme = btheme->next) { - writestruct(wd, DATA, "bTheme", 1, btheme); + writestruct(wd, DATA, bTheme, 1, btheme); } for (keymap = U.user_keymaps.first; keymap; keymap = keymap->next) { - writestruct(wd, DATA, "wmKeyMap", 1, keymap); + writestruct(wd, DATA, wmKeyMap, 1, keymap); for (kmdi = keymap->diff_items.first; kmdi; kmdi = kmdi->next) { - writestruct(wd, DATA, "wmKeyMapDiffItem", 1, kmdi); + writestruct(wd, DATA, wmKeyMapDiffItem, 1, kmdi); if (kmdi->remove_item) { write_keymapitem(wd, kmdi->remove_item); } @@ -1115,18 +1169,18 @@ static void write_userdef(WriteData *wd) } for (bext = U.addons.first; bext; bext = bext->next) { - writestruct(wd, DATA, "bAddon", 1, bext); + writestruct(wd, DATA, bAddon, 1, bext); if (bext->prop) { IDP_WriteProperty(bext->prop, wd); } } for (path_cmp = U.autoexec_paths.first; path_cmp; path_cmp = path_cmp->next) { - writestruct(wd, DATA, "bPathCompare", 1, path_cmp); + writestruct(wd, DATA, bPathCompare, 1, path_cmp); } for (style = U.uistyles.first; style; style = style->next) { - writestruct(wd, DATA, "uiStyle", 1, style); + writestruct(wd, DATA, uiStyle, 1, style); } } @@ -1134,35 +1188,35 @@ static void write_boid_state(WriteData *wd, BoidState *state) { BoidRule *rule = state->rules.first; - writestruct(wd, DATA, "BoidState", 1, state); + writestruct(wd, DATA, BoidState, 1, state); for (; rule; rule = rule->next) { switch (rule->type) { case eBoidRuleType_Goal: case eBoidRuleType_Avoid: - writestruct(wd, DATA, "BoidRuleGoalAvoid", 1, rule); + writestruct(wd, DATA, BoidRuleGoalAvoid, 1, rule); break; case eBoidRuleType_AvoidCollision: - writestruct(wd, DATA, "BoidRuleAvoidCollision", 1, rule); + writestruct(wd, DATA, BoidRuleAvoidCollision, 1, rule); break; case eBoidRuleType_FollowLeader: - writestruct(wd, DATA, "BoidRuleFollowLeader", 1, rule); + writestruct(wd, DATA, BoidRuleFollowLeader, 1, rule); break; case eBoidRuleType_AverageSpeed: - writestruct(wd, DATA, "BoidRuleAverageSpeed", 1, rule); + writestruct(wd, DATA, BoidRuleAverageSpeed, 1, rule); break; case eBoidRuleType_Fight: - writestruct(wd, DATA, "BoidRuleFight", 1, rule); + writestruct(wd, DATA, BoidRuleFight, 1, rule); break; default: - writestruct(wd, DATA, "BoidRule", 1, rule); + writestruct(wd, DATA, BoidRule, 1, rule); break; } } #if 0 BoidCondition *cond = state->conditions.first; for (; cond; cond = cond->next) { - writestruct(wd, DATA, "BoidCondition", 1, cond); + writestruct(wd, DATA, BoidCondition, 1, cond); } #endif } @@ -1188,7 +1242,7 @@ static void write_pointcaches(WriteData *wd, ListBase *ptcaches) int i; for (; cache; cache = cache->next) { - writestruct(wd, DATA, "PointCache", 1, cache); + writestruct(wd, DATA, PointCache, 1, cache); if ((cache->flag & PTCACHE_DISK_CACHE) == 0) { PTCacheMem *pm = cache->mem_cache.first; @@ -1196,7 +1250,7 @@ static void write_pointcaches(WriteData *wd, ListBase *ptcaches) for (; pm; pm = pm->next) { PTCacheExtra *extra = pm->extradata.first; - writestruct(wd, DATA, "PTCacheMem", 1, pm); + writestruct(wd, DATA, PTCacheMem, 1, pm); for (i = 0; i < BPHYS_TOT_DATA; i++) { if (pm->data[i] && pm->data_types & (1 << i)) { @@ -1204,7 +1258,7 @@ static void write_pointcaches(WriteData *wd, ListBase *ptcaches) writedata(wd, DATA, MEM_allocN_len(pm->data[i]), pm->data[i]); } else { - writestruct(wd, DATA, ptcache_data_struct[i], pm->totpoint, pm->data[i]); + writestruct_id(wd, DATA, ptcache_data_struct[i], pm->totpoint, pm->data[i]); } } } @@ -1213,8 +1267,8 @@ static void write_pointcaches(WriteData *wd, ListBase *ptcaches) if (ptcache_extra_struct[extra->type][0] == '\0') { continue; } - writestruct(wd, DATA, "PTCacheExtra", 1, extra); - writestruct(wd, DATA, ptcache_extra_struct[extra->type], extra->totdata, extra->data); + writestruct(wd, DATA, PTCacheExtra, 1, extra); + writestruct_id(wd, DATA, ptcache_extra_struct[extra->type], extra->totdata, extra->data); } } } @@ -1231,15 +1285,15 @@ static void write_particlesettings(WriteData *wd, ListBase *idbase) while (part) { if (part->id.us > 0 || wd->current) { /* write LibData */ - writestruct(wd, ID_PA, "ParticleSettings", 1, part); + writestruct(wd, ID_PA, ParticleSettings, 1, part); write_iddata(wd, &part->id); if (part->adt) { write_animdata(wd, part->adt); } - writestruct(wd, DATA, "PartDeflect", 1, part->pd); - writestruct(wd, DATA, "PartDeflect", 1, part->pd2); - writestruct(wd, DATA, "EffectorWeights", 1, part->effector_weights); + writestruct(wd, DATA, PartDeflect, 1, part->pd); + writestruct(wd, DATA, PartDeflect, 1, part->pd2); + writestruct(wd, DATA, EffectorWeights, 1, part->effector_weights); if (part->clumpcurve) { write_curvemapping(wd, part->clumpcurve); @@ -1259,25 +1313,25 @@ static void write_particlesettings(WriteData *wd, ListBase *idbase) dw->index++; } } - writestruct(wd, DATA, "ParticleDupliWeight", 1, dw); + 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); + writestruct(wd, DATA, BoidSettings, 1, part->boids); for (; state; state = state->next) { write_boid_state(wd, state); } } if (part->fluid && part->phystype == PART_PHYS_FLUID) { - writestruct(wd, DATA, "SPHFluidSettings", 1, part->fluid); + writestruct(wd, DATA, SPHFluidSettings, 1, part->fluid); } for (a = 0; a < MAX_MTEX; a++) { if (part->mtex[a]) { - writestruct(wd, DATA, "MTex", 1, part->mtex[a]); + writestruct(wd, DATA, MTex, 1, part->mtex[a]); } } } @@ -1291,45 +1345,45 @@ static void write_particlesystems(WriteData *wd, ListBase *particles) int a; for (; psys; psys = psys->next) { - writestruct(wd, DATA, "ParticleSystem", 1, psys); + writestruct(wd, DATA, ParticleSystem, 1, psys); if (psys->particles) { - writestruct(wd, DATA, "ParticleData", psys->totpart, psys->particles); + writestruct(wd, DATA, ParticleData, psys->totpart, psys->particles); if (psys->particles->hair) { ParticleData *pa = psys->particles; for (a = 0; a < psys->totpart; a++, pa++) { - writestruct(wd, DATA, "HairKey", pa->totkey, pa->hair); + writestruct(wd, DATA, HairKey, pa->totkey, pa->hair); } } if (psys->particles->boid && (psys->part->phystype == PART_PHYS_BOIDS)) { - writestruct(wd, DATA, "BoidParticle", psys->totpart, psys->particles->boid); + writestruct(wd, DATA, BoidParticle, psys->totpart, psys->particles->boid); } if (psys->part->fluid && (psys->part->phystype == PART_PHYS_FLUID) && (psys->part->fluid->flag & SPH_VISCOELASTIC_SPRINGS)) { - writestruct(wd, DATA, "ParticleSpring", psys->tot_fluidsprings, psys->fluid_springs); + writestruct(wd, DATA, ParticleSpring, psys->tot_fluidsprings, psys->fluid_springs); } } pt = psys->targets.first; for (; pt; pt = pt->next) { - writestruct(wd, DATA, "ParticleTarget", 1, pt); + writestruct(wd, DATA, ParticleTarget, 1, pt); } if (psys->child) { - writestruct(wd, DATA, "ChildParticle", psys->totchild, psys->child); + writestruct(wd, DATA, ChildParticle, psys->totchild, psys->child); } if (psys->clmd) { - writestruct(wd, DATA, "ClothModifierData", 1, psys->clmd); - writestruct(wd, DATA, "ClothSimSettings", 1, psys->clmd->sim_parms); - writestruct(wd, DATA, "ClothCollSettings", 1, psys->clmd->coll_parms); + writestruct(wd, DATA, ClothModifierData, 1, psys->clmd); + writestruct(wd, DATA, ClothSimSettings, 1, psys->clmd->sim_parms); + writestruct(wd, DATA, ClothCollSettings, 1, psys->clmd->coll_parms); } write_pointcaches(wd, &psys->ptcaches); @@ -1342,7 +1396,7 @@ static void write_properties(WriteData *wd, ListBase *lb) prop = lb->first; while (prop) { - writestruct(wd, DATA, "bProperty", 1, prop); + writestruct(wd, DATA, bProperty, 1, prop); if (prop->poin && prop->poin != &prop->data) { writedata(wd, DATA, MEM_allocN_len(prop->poin), prop->poin); @@ -1358,49 +1412,49 @@ static void write_sensors(WriteData *wd, ListBase *lb) sens = lb->first; while (sens) { - writestruct(wd, DATA, "bSensor", 1, sens); + writestruct(wd, DATA, bSensor, 1, sens); writedata(wd, DATA, sizeof(void *) * sens->totlinks, sens->links); switch (sens->type) { case SENS_NEAR: - writestruct(wd, DATA, "bNearSensor", 1, sens->data); + writestruct(wd, DATA, bNearSensor, 1, sens->data); break; case SENS_MOUSE: - writestruct(wd, DATA, "bMouseSensor", 1, sens->data); + writestruct(wd, DATA, bMouseSensor, 1, sens->data); break; case SENS_KEYBOARD: - writestruct(wd, DATA, "bKeyboardSensor", 1, sens->data); + writestruct(wd, DATA, bKeyboardSensor, 1, sens->data); break; case SENS_PROPERTY: - writestruct(wd, DATA, "bPropertySensor", 1, sens->data); + writestruct(wd, DATA, bPropertySensor, 1, sens->data); break; case SENS_ARMATURE: - writestruct(wd, DATA, "bArmatureSensor", 1, sens->data); + writestruct(wd, DATA, bArmatureSensor, 1, sens->data); break; case SENS_ACTUATOR: - writestruct(wd, DATA, "bActuatorSensor", 1, sens->data); + writestruct(wd, DATA, bActuatorSensor, 1, sens->data); break; case SENS_DELAY: - writestruct(wd, DATA, "bDelaySensor", 1, sens->data); + writestruct(wd, DATA, bDelaySensor, 1, sens->data); break; case SENS_COLLISION: - writestruct(wd, DATA, "bCollisionSensor", 1, sens->data); + writestruct(wd, DATA, bCollisionSensor, 1, sens->data); break; case SENS_RADAR: - writestruct(wd, DATA, "bRadarSensor", 1, sens->data); + writestruct(wd, DATA, bRadarSensor, 1, sens->data); break; case SENS_RANDOM: - writestruct(wd, DATA, "bRandomSensor", 1, sens->data); + writestruct(wd, DATA, bRandomSensor, 1, sens->data); break; case SENS_RAY: - writestruct(wd, DATA, "bRaySensor", 1, sens->data); + writestruct(wd, DATA, bRaySensor, 1, sens->data); break; case SENS_MESSAGE: - writestruct(wd, DATA, "bMessageSensor", 1, sens->data); + writestruct(wd, DATA, bMessageSensor, 1, sens->data); break; case SENS_JOYSTICK: - writestruct(wd, DATA, "bJoystickSensor", 1, sens->data); + writestruct(wd, DATA, bJoystickSensor, 1, sens->data); break; default: ; /* error: don't know how to write this file */ @@ -1416,16 +1470,16 @@ static void write_controllers(WriteData *wd, ListBase *lb) cont = lb->first; while (cont) { - writestruct(wd, DATA, "bController", 1, cont); + writestruct(wd, DATA, bController, 1, cont); writedata(wd, DATA, sizeof(void *) * cont->totlinks, cont->links); switch (cont->type) { case CONT_EXPRESSION: - writestruct(wd, DATA, "bExpressionCont", 1, cont->data); + writestruct(wd, DATA, bExpressionCont, 1, cont->data); break; case CONT_PYTHON: - writestruct(wd, DATA, "bPythonCont", 1, cont->data); + writestruct(wd, DATA, bPythonCont, 1, cont->data); break; default: ; /* error: don't know how to write this file */ @@ -1441,66 +1495,66 @@ static void write_actuators(WriteData *wd, ListBase *lb) act = lb->first; while (act) { - writestruct(wd, DATA, "bActuator", 1, act); + writestruct(wd, DATA, bActuator, 1, act); switch (act->type) { case ACT_ACTION: case ACT_SHAPEACTION: - writestruct(wd, DATA, "bActionActuator", 1, act->data); + writestruct(wd, DATA, bActionActuator, 1, act->data); break; case ACT_SOUND: - writestruct(wd, DATA, "bSoundActuator", 1, act->data); + writestruct(wd, DATA, bSoundActuator, 1, act->data); break; case ACT_OBJECT: - writestruct(wd, DATA, "bObjectActuator", 1, act->data); + writestruct(wd, DATA, bObjectActuator, 1, act->data); break; case ACT_PROPERTY: - writestruct(wd, DATA, "bPropertyActuator", 1, act->data); + writestruct(wd, DATA, bPropertyActuator, 1, act->data); break; case ACT_CAMERA: - writestruct(wd, DATA, "bCameraActuator", 1, act->data); + writestruct(wd, DATA, bCameraActuator, 1, act->data); break; case ACT_CONSTRAINT: - writestruct(wd, DATA, "bConstraintActuator", 1, act->data); + writestruct(wd, DATA, bConstraintActuator, 1, act->data); break; case ACT_EDIT_OBJECT: - writestruct(wd, DATA, "bEditObjectActuator", 1, act->data); + writestruct(wd, DATA, bEditObjectActuator, 1, act->data); break; case ACT_SCENE: - writestruct(wd, DATA, "bSceneActuator", 1, act->data); + writestruct(wd, DATA, bSceneActuator, 1, act->data); break; case ACT_GROUP: - writestruct(wd, DATA, "bGroupActuator", 1, act->data); + writestruct(wd, DATA, bGroupActuator, 1, act->data); break; case ACT_RANDOM: - writestruct(wd, DATA, "bRandomActuator", 1, act->data); + writestruct(wd, DATA, bRandomActuator, 1, act->data); break; case ACT_MESSAGE: - writestruct(wd, DATA, "bMessageActuator", 1, act->data); + writestruct(wd, DATA, bMessageActuator, 1, act->data); break; case ACT_GAME: - writestruct(wd, DATA, "bGameActuator", 1, act->data); + writestruct(wd, DATA, bGameActuator, 1, act->data); break; case ACT_VISIBILITY: - writestruct(wd, DATA, "bVisibilityActuator", 1, act->data); + writestruct(wd, DATA, bVisibilityActuator, 1, act->data); break; case ACT_2DFILTER: - writestruct(wd, DATA, "bTwoDFilterActuator", 1, act->data); + writestruct(wd, DATA, bTwoDFilterActuator, 1, act->data); break; case ACT_PARENT: - writestruct(wd, DATA, "bParentActuator", 1, act->data); + writestruct(wd, DATA, bParentActuator, 1, act->data); break; case ACT_STATE: - writestruct(wd, DATA, "bStateActuator", 1, act->data); + writestruct(wd, DATA, bStateActuator, 1, act->data); break; case ACT_ARMATURE: - writestruct(wd, DATA, "bArmatureActuator", 1, act->data); + writestruct(wd, DATA, bArmatureActuator, 1, act->data); break; case ACT_STEERING: - writestruct(wd, DATA, "bSteeringActuator", 1, act->data); + writestruct(wd, DATA, bSteeringActuator, 1, act->data); break; case ACT_MOUSE: - writestruct(wd, DATA, "bMouseActuator", 1, act->data); + writestruct(wd, DATA, bMouseActuator, 1, act->data); break; default: ; /* error: don't know how to write this file */ @@ -1518,10 +1572,10 @@ static void write_motionpath(WriteData *wd, bMotionPath *mpath) } /* firstly, just write the motionpath struct */ - writestruct(wd, DATA, "bMotionPath", 1, mpath); + writestruct(wd, DATA, bMotionPath, 1, mpath); /* now write the array of data */ - writestruct(wd, DATA, "bMotionPathVert", mpath->length, mpath->points); + writestruct(wd, DATA, bMotionPathVert, mpath->length, mpath->points); } static void write_constraints(WriteData *wd, ListBase *conlist) @@ -1534,7 +1588,7 @@ static void write_constraints(WriteData *wd, ListBase *conlist) /* Write the specific data */ if (cti && con->data) { /* firstly, just write the plain con->data struct */ - writestruct(wd, DATA, cti->structName, 1, con->data); + writestruct_id(wd, DATA, cti->structName, 1, con->data); /* do any constraint specific stuff */ switch (con->type) { @@ -1545,7 +1599,7 @@ static void write_constraints(WriteData *wd, ListBase *conlist) /* write targets */ for (ct = data->targets.first; ct; ct = ct->next) { - writestruct(wd, DATA, "bConstraintTarget", 1, ct); + writestruct(wd, DATA, bConstraintTarget, 1, ct); } /* Write ID Properties -- and copy this comment EXACTLY for easy finding @@ -1567,7 +1621,7 @@ static void write_constraints(WriteData *wd, ListBase *conlist) } /* Write the constraint */ - writestruct(wd, DATA, "bConstraint", 1, con); + writestruct(wd, DATA, bConstraint, 1, con); } } @@ -1600,31 +1654,31 @@ static void write_pose(WriteData *wd, bPose *pose) chan->selectflag = chan->bone->flag & BONE_SELECTED; } - writestruct(wd, DATA, "bPoseChannel", 1, chan); + writestruct(wd, DATA, bPoseChannel, 1, chan); } /* Write groups */ for (grp = pose->agroups.first; grp; grp = grp->next) { - writestruct(wd, DATA, "bActionGroup", 1, grp); + writestruct(wd, DATA, bActionGroup, 1, grp); } /* write IK param */ if (pose->ikparam) { const char *structname = BKE_pose_ikparam_get_name(pose); if (structname) { - writestruct(wd, DATA, structname, 1, pose->ikparam); + writestruct_id(wd, DATA, structname, 1, pose->ikparam); } } /* Write this pose */ - writestruct(wd, DATA, "bPose", 1, pose); + writestruct(wd, DATA, bPose, 1, pose); } static void write_defgroups(WriteData *wd, ListBase *defbase) { for (bDeformGroup *defgroup = defbase->first; defgroup; defgroup = defgroup->next) { - writestruct(wd, DATA, "bDeformGroup", 1, defgroup); + writestruct(wd, DATA, bDeformGroup, 1, defgroup); } } @@ -1642,7 +1696,7 @@ static void write_modifiers(WriteData *wd, ListBase *modbase) return; } - writestruct(wd, DATA, mti->structName, 1, md); + writestruct_id(wd, DATA, mti->structName, 1, md); if (md->type == eModifierType_Hook) { HookModifierData *hmd = (HookModifierData *)md; @@ -1656,9 +1710,9 @@ static void write_modifiers(WriteData *wd, ListBase *modbase) else if (md->type == eModifierType_Cloth) { ClothModifierData *clmd = (ClothModifierData *)md; - writestruct(wd, DATA, "ClothSimSettings", 1, clmd->sim_parms); - writestruct(wd, DATA, "ClothCollSettings", 1, clmd->coll_parms); - writestruct(wd, DATA, "EffectorWeights", 1, clmd->sim_parms->effector_weights); + writestruct(wd, DATA, ClothSimSettings, 1, clmd->sim_parms); + writestruct(wd, DATA, ClothCollSettings, 1, clmd->coll_parms); + writestruct(wd, DATA, EffectorWeights, 1, clmd->sim_parms->effector_weights); write_pointcaches(wd, &clmd->ptcaches); } else if (md->type == eModifierType_Smoke) { @@ -1676,50 +1730,50 @@ static void write_modifiers(WriteData *wd, ListBase *modbase) write_pointcaches(wd, &(smd->domain->ptcaches[1])); } - writestruct(wd, DATA, "SmokeDomainSettings", 1, smd->domain); + writestruct(wd, DATA, SmokeDomainSettings, 1, smd->domain); if (smd->domain) { /* cleanup the fake pointcache */ BKE_ptcache_free_list(&smd->domain->ptcaches[1]); smd->domain->point_cache[1] = NULL; - writestruct(wd, DATA, "EffectorWeights", 1, smd->domain->effector_weights); + writestruct(wd, DATA, EffectorWeights, 1, smd->domain->effector_weights); } } else if (smd->type & MOD_SMOKE_TYPE_FLOW) { - writestruct(wd, DATA, "SmokeFlowSettings", 1, smd->flow); + writestruct(wd, DATA, SmokeFlowSettings, 1, smd->flow); } else if (smd->type & MOD_SMOKE_TYPE_COLL) { - writestruct(wd, DATA, "SmokeCollSettings", 1, smd->coll); + writestruct(wd, DATA, SmokeCollSettings, 1, smd->coll); } } else if (md->type == eModifierType_Fluidsim) { FluidsimModifierData *fluidmd = (FluidsimModifierData *)md; - writestruct(wd, DATA, "FluidsimSettings", 1, fluidmd->fss); + writestruct(wd, DATA, FluidsimSettings, 1, fluidmd->fss); } else if (md->type == eModifierType_DynamicPaint) { DynamicPaintModifierData *pmd = (DynamicPaintModifierData *)md; if (pmd->canvas) { DynamicPaintSurface *surface; - writestruct(wd, DATA, "DynamicPaintCanvasSettings", 1, pmd->canvas); + writestruct(wd, DATA, DynamicPaintCanvasSettings, 1, pmd->canvas); /* write surfaces */ for (surface = pmd->canvas->surfaces.first; surface; surface = surface->next) { - writestruct(wd, DATA, "DynamicPaintSurface", 1, surface); + writestruct(wd, DATA, DynamicPaintSurface, 1, surface); } /* write caches and effector weights */ for (surface = pmd->canvas->surfaces.first; surface; surface = surface->next) { write_pointcaches(wd, &(surface->ptcaches)); - writestruct(wd, DATA, "EffectorWeights", 1, surface->effector_weights); + writestruct(wd, DATA, EffectorWeights, 1, surface->effector_weights); } } if (pmd->brush) { - writestruct(wd, DATA, "DynamicPaintBrushSettings", 1, pmd->brush); - writestruct(wd, DATA, "ColorBand", 1, pmd->brush->paint_ramp); - writestruct(wd, DATA, "ColorBand", 1, pmd->brush->vel_ramp); + writestruct(wd, DATA, DynamicPaintBrushSettings, 1, pmd->brush); + writestruct(wd, DATA, ColorBand, 1, pmd->brush->paint_ramp); + writestruct(wd, DATA, ColorBand, 1, pmd->brush->vel_ramp); } } else if (md->type == eModifierType_Collision) { @@ -1728,21 +1782,21 @@ static void write_modifiers(WriteData *wd, ListBase *modbase) CollisionModifierData *collmd = (CollisionModifierData *)md; // TODO: CollisionModifier should use pointcache // + have proper reset events before enabling this - writestruct(wd, DATA, "MVert", collmd->numverts, collmd->x); - writestruct(wd, DATA, "MVert", collmd->numverts, collmd->xnew); - writestruct(wd, DATA, "MFace", collmd->numfaces, collmd->mfaces); + writestruct(wd, DATA, MVert, collmd->numverts, collmd->x); + writestruct(wd, DATA, MVert, collmd->numverts, collmd->xnew); + writestruct(wd, DATA, MFace, collmd->numfaces, collmd->mfaces); #endif } else if (md->type == eModifierType_MeshDeform) { MeshDeformModifierData *mmd = (MeshDeformModifierData *)md; int size = mmd->dyngridsize; - writestruct(wd, DATA, "MDefInfluence", mmd->totinfluence, mmd->bindinfluences); + writestruct(wd, DATA, MDefInfluence, mmd->totinfluence, mmd->bindinfluences); writedata(wd, DATA, sizeof(int) * (mmd->totvert + 1), mmd->bindoffsets); writedata(wd, DATA, sizeof(float) * 3 * mmd->totcagevert, mmd->bindcagecos); - writestruct(wd, DATA, "MDefCell", size * size * size, mmd->dyngrid); - writestruct(wd, DATA, "MDefInfluence", mmd->totinfluence, mmd->dyninfluences); + writestruct(wd, DATA, MDefCell, size * size * size, mmd->dyngrid); + writestruct(wd, DATA, MDefInfluence, mmd->totinfluence, mmd->dyninfluences); writedata(wd, DATA, sizeof(int) * mmd->totvert, mmd->dynverts); } else if (md->type == eModifierType_Warp) { @@ -1781,7 +1835,7 @@ static void write_objects(WriteData *wd, ListBase *idbase) while (ob) { if (ob->id.us > 0 || wd->current) { /* write LibData */ - writestruct(wd, ID_OB, "Object", 1, ob); + writestruct(wd, ID_OB, Object, 1, ob); write_iddata(wd, &ob->id); if (ob->adt) { @@ -1809,31 +1863,31 @@ static void write_objects(WriteData *wd, ListBase *idbase) write_constraints(wd, &ob->constraints); write_motionpath(wd, ob->mpath); - writestruct(wd, DATA, "PartDeflect", 1, ob->pd); - writestruct(wd, DATA, "SoftBody", 1, ob->soft); + writestruct(wd, DATA, PartDeflect, 1, ob->pd); + writestruct(wd, DATA, SoftBody, 1, ob->soft); if (ob->soft) { write_pointcaches(wd, &ob->soft->ptcaches); - writestruct(wd, DATA, "EffectorWeights", 1, ob->soft->effector_weights); + writestruct(wd, DATA, EffectorWeights, 1, ob->soft->effector_weights); } - writestruct(wd, DATA, "BulletSoftBody", 1, ob->bsoft); + writestruct(wd, DATA, BulletSoftBody, 1, ob->bsoft); if (ob->rigidbody_object) { /* TODO: if any extra data is added to handle duplis, will need separate function then */ - writestruct(wd, DATA, "RigidBodyOb", 1, ob->rigidbody_object); + writestruct(wd, DATA, RigidBodyOb, 1, ob->rigidbody_object); } if (ob->rigidbody_constraint) { - writestruct(wd, DATA, "RigidBodyCon", 1, ob->rigidbody_constraint); + writestruct(wd, DATA, RigidBodyCon, 1, ob->rigidbody_constraint); } if (ob->type == OB_EMPTY && ob->empty_drawtype == OB_EMPTY_IMAGE) { - writestruct(wd, DATA, "ImageUser", 1, ob->iuser); + writestruct(wd, DATA, ImageUser, 1, ob->iuser); } write_particlesystems(wd, &ob->particlesystem); write_modifiers(wd, &ob->modifiers); - writelist(wd, DATA, "LinkData", &ob->pc_ids); - writelist(wd, DATA, "LodLevel", &ob->lodlevels); + writelist(wd, DATA, LinkData, &ob->pc_ids); + writelist(wd, DATA, LodLevel, &ob->lodlevels); } write_previews(wd, ob->preview); @@ -1855,14 +1909,14 @@ static void write_vfonts(WriteData *wd, ListBase *idbase) while (vf) { if (vf->id.us > 0 || wd->current) { /* write LibData */ - writestruct(wd, ID_VF, "VFont", 1, vf); + writestruct(wd, ID_VF, VFont, 1, vf); write_iddata(wd, &vf->id); /* direct data */ if (vf->packedfile) { pf = vf->packedfile; - writestruct(wd, DATA, "PackedFile", 1, pf); + writestruct(wd, DATA, PackedFile, 1, pf); writedata(wd, DATA, pf->size, pf->data); } } @@ -1881,7 +1935,7 @@ static void write_keys(WriteData *wd, ListBase *idbase) while (key) { if (key->id.us > 0 || wd->current) { /* write LibData */ - writestruct(wd, ID_KE, "Key", 1, key); + writestruct(wd, ID_KE, Key, 1, key); write_iddata(wd, &key->id); if (key->adt) { @@ -1891,7 +1945,7 @@ static void write_keys(WriteData *wd, ListBase *idbase) /* direct data */ kb = key->block.first; while (kb) { - writestruct(wd, DATA, "KeyBlock", 1, kb); + writestruct(wd, DATA, KeyBlock, 1, kb); if (kb->data) { writedata(wd, DATA, kb->totelem * key->elemsize, kb->data); } @@ -1913,7 +1967,7 @@ static void write_cameras(WriteData *wd, ListBase *idbase) while (cam) { if (cam->id.us > 0 || wd->current) { /* write LibData */ - writestruct(wd, ID_CA, "Camera", 1, cam); + writestruct(wd, ID_CA, Camera, 1, cam); write_iddata(wd, &cam->id); if (cam->adt) { @@ -1934,7 +1988,7 @@ static void write_mballs(WriteData *wd, ListBase *idbase) while (mb) { if (mb->id.us > 0 || wd->current) { /* write LibData */ - writestruct(wd, ID_MB, "MetaBall", 1, mb); + writestruct(wd, ID_MB, MetaBall, 1, mb); write_iddata(wd, &mb->id); /* direct data */ @@ -1945,7 +1999,7 @@ static void write_mballs(WriteData *wd, ListBase *idbase) ml = mb->elems.first; while (ml) { - writestruct(wd, DATA, "MetaElem", 1, ml); + writestruct(wd, DATA, MetaElem, 1, ml); ml = ml->next; } } @@ -1962,7 +2016,7 @@ static void write_curves(WriteData *wd, ListBase *idbase) while (cu) { if (cu->id.us > 0 || wd->current) { /* write LibData */ - writestruct(wd, ID_CU, "Curve", 1, cu); + writestruct(wd, ID_CU, Curve, 1, cu); write_iddata(wd, &cu->id); /* direct data */ @@ -1973,23 +2027,23 @@ static void write_curves(WriteData *wd, ListBase *idbase) if (cu->vfont) { writedata(wd, DATA, cu->len + 1, cu->str); - writestruct(wd, DATA, "CharInfo", cu->len_wchar + 1, cu->strinfo); - writestruct(wd, DATA, "TextBox", cu->totbox, cu->tb); + writestruct(wd, DATA, CharInfo, cu->len_wchar + 1, cu->strinfo); + writestruct(wd, DATA, TextBox, cu->totbox, cu->tb); } else { /* is also the order of reading */ nu = cu->nurb.first; while (nu) { - writestruct(wd, DATA, "Nurb", 1, nu); + writestruct(wd, DATA, Nurb, 1, nu); nu = nu->next; } nu = cu->nurb.first; while (nu) { if (nu->type == CU_BEZIER) { - writestruct(wd, DATA, "BezTriple", nu->pntsu, nu->bezt); + writestruct(wd, DATA, BezTriple, nu->pntsu, nu->bezt); } else { - writestruct(wd, DATA, "BPoint", nu->pntsu * nu->pntsv, nu->bp); + writestruct(wd, DATA, BPoint, nu->pntsu * nu->pntsv, nu->bp); if (nu->knotsu) { writedata(wd, DATA, KNOTSU(nu) * sizeof(float), nu->knotsu); } @@ -2013,12 +2067,12 @@ static void write_dverts(WriteData *wd, int count, MDeformVert *dvlist) if (dvlist) { /* Write the dvert list */ - writestruct(wd, DATA, "MDeformVert", count, dvlist); + writestruct(wd, DATA, MDeformVert, count, dvlist); /* Write deformation data for each dvert */ for (int i = 0; i < count; i++) { if (dvlist[i].dw) { - writestruct(wd, DATA, "MDeformWeight", dvlist[i].totweight, dvlist[i].dw); + writestruct(wd, DATA, MDeformWeight, dvlist[i].totweight, dvlist[i].dw); } } } @@ -2029,7 +2083,7 @@ static void write_mdisps(WriteData *wd, int count, MDisps *mdlist, int external) if (mdlist) { int i; - writestruct(wd, DATA, "MDisps", count, mdlist); + writestruct(wd, DATA, MDisps, count, mdlist); for (i = 0; i < count; ++i) { MDisps *md = &mdlist[i]; if (md->disps) { @@ -2050,7 +2104,7 @@ static void write_grid_paint_mask(WriteData *wd, int count, GridPaintMask *grid_ if (grid_paint_mask) { int i; - writestruct(wd, DATA, "GridPaintMask", count, grid_paint_mask); + writestruct(wd, DATA, GridPaintMask, count, grid_paint_mask); for (i = 0; i < count; ++i) { GridPaintMask *gpm = &grid_paint_mask[i]; if (gpm->data) { @@ -2074,7 +2128,7 @@ static void write_customdata( CustomData_external_write(data, id, CD_MASK_MESH, count, 0); } - writestruct_at_address(wd, DATA, "CustomDataLayer", data->totlayer, data->layers, layers); + writestruct_at_address(wd, DATA, CustomDataLayer, data->totlayer, data->layers, layers); for (i = 0; i < data->totlayer; i++) { CustomDataLayer *layer = &layers[i]; @@ -2108,7 +2162,7 @@ static void write_customdata( datasize = structnum * partial_count; } - writestruct(wd, DATA, structname, datasize, layer->data); + writestruct_id(wd, DATA, structname, datasize, layer->data); } else { printf("%s error: layer '%s':%d - can't be written to file\n", @@ -2118,7 +2172,7 @@ static void write_customdata( } if (data->external) { - writestruct(wd, DATA, "CustomDataExternal", 1, data->external); + writestruct(wd, DATA, CustomDataExternal, 1, data->external); } } @@ -2172,7 +2226,7 @@ static void write_meshes(WriteData *wd, ListBase *idbase) CustomData_file_write_prepare(&mesh->ldata, &llayers, llayers_buff, ARRAY_SIZE(llayers_buff)); CustomData_file_write_prepare(&mesh->pdata, &players, players_buff, ARRAY_SIZE(players_buff)); - writestruct_at_address(wd, ID_ME, "Mesh", 1, old_mesh, mesh); + writestruct_at_address(wd, ID_ME, Mesh, 1, old_mesh, mesh); write_iddata(wd, &mesh->id); /* direct data */ @@ -2232,7 +2286,7 @@ static void write_meshes(WriteData *wd, ListBase *idbase) CustomData_file_write_prepare(&mesh->pdata, &players, players_buff, ARRAY_SIZE(players_buff)); #endif - writestruct_at_address(wd, ID_ME, "Mesh", 1, old_mesh, mesh); + writestruct_at_address(wd, ID_ME, Mesh, 1, old_mesh, mesh); write_iddata(wd, &mesh->id); /* direct data */ @@ -2289,7 +2343,7 @@ static void write_lattices(WriteData *wd, ListBase *idbase) while (lt) { if (lt->id.us > 0 || wd->current) { /* write LibData */ - writestruct(wd, ID_LT, "Lattice", 1, lt); + writestruct(wd, ID_LT, Lattice, 1, lt); write_iddata(wd, <->id); /* write animdata */ @@ -2298,7 +2352,7 @@ static void write_lattices(WriteData *wd, ListBase *idbase) } /* direct data */ - writestruct(wd, DATA, "BPoint", lt->pntsu * lt->pntsv * lt->pntsw, lt->def); + writestruct(wd, DATA, BPoint, lt->pntsu * lt->pntsv * lt->pntsw, lt->def); write_dverts(wd, lt->pntsu * lt->pntsv * lt->pntsw, lt->dvert); @@ -2325,14 +2379,14 @@ static void write_images(WriteData *wd, ListBase *idbase) } /* write LibData */ - writestruct(wd, ID_IM, "Image", 1, ima); + writestruct(wd, ID_IM, Image, 1, ima); write_iddata(wd, &ima->id); for (imapf = ima->packedfiles.first; imapf; imapf = imapf->next) { - writestruct(wd, DATA, "ImagePackedFile", 1, imapf); + writestruct(wd, DATA, ImagePackedFile, 1, imapf); if (imapf->packedfile) { pf = imapf->packedfile; - writestruct(wd, DATA, "PackedFile", 1, pf); + writestruct(wd, DATA, PackedFile, 1, pf); writedata(wd, DATA, pf->size, pf->data); } } @@ -2340,9 +2394,9 @@ static void write_images(WriteData *wd, ListBase *idbase) write_previews(wd, ima->preview); for (iv = ima->views.first; iv; iv = iv->next) { - writestruct(wd, DATA, "ImageView", 1, iv); + writestruct(wd, DATA, ImageView, 1, iv); } - writestruct(wd, DATA, "Stereo3dFormat", 1, ima->stereo3d_format); + writestruct(wd, DATA, Stereo3dFormat, 1, ima->stereo3d_format); ima->packedfile = NULL; } @@ -2360,7 +2414,7 @@ static void write_textures(WriteData *wd, ListBase *idbase) while (tex) { if (tex->id.us > 0 || wd->current) { /* write LibData */ - writestruct(wd, ID_TE, "Tex", 1, tex); + writestruct(wd, ID_TE, Tex, 1, tex); write_iddata(wd, &tex->id); if (tex->adt) { @@ -2369,30 +2423,30 @@ static void write_textures(WriteData *wd, ListBase *idbase) /* direct data */ if (tex->coba) { - writestruct(wd, DATA, "ColorBand", 1, tex->coba); + writestruct(wd, DATA, ColorBand, 1, tex->coba); } if (tex->type == TEX_ENVMAP && tex->env) { - writestruct(wd, DATA, "EnvMap", 1, tex->env); + writestruct(wd, DATA, EnvMap, 1, tex->env); } if (tex->type == TEX_POINTDENSITY && tex->pd) { - writestruct(wd, DATA, "PointDensity", 1, tex->pd); + writestruct(wd, DATA, PointDensity, 1, tex->pd); if (tex->pd->coba) { - writestruct(wd, DATA, "ColorBand", 1, tex->pd->coba); + writestruct(wd, DATA, ColorBand, 1, tex->pd->coba); } if (tex->pd->falloff_curve) { write_curvemapping(wd, tex->pd->falloff_curve); } } if (tex->type == TEX_VOXELDATA) { - writestruct(wd, DATA, "VoxelData", 1, tex->vd); + writestruct(wd, DATA, VoxelData, 1, tex->vd); } if (tex->type == TEX_OCEAN && tex->ot) { - writestruct(wd, DATA, "OceanTex", 1, tex->ot); + writestruct(wd, DATA, OceanTex, 1, tex->ot); } /* nodetree is integral part of texture, no libdata */ if (tex->nodetree) { - writestruct(wd, DATA, "bNodeTree", 1, tex->nodetree); + writestruct(wd, DATA, bNodeTree, 1, tex->nodetree); write_nodetree(wd, tex->nodetree); } @@ -2414,7 +2468,7 @@ static void write_materials(WriteData *wd, ListBase *idbase) while (ma) { if (ma->id.us > 0 || wd->current) { /* write LibData */ - writestruct(wd, ID_MA, "Material", 1, ma); + writestruct(wd, ID_MA, Material, 1, ma); write_iddata(wd, &ma->id); if (ma->adt) { @@ -2423,20 +2477,20 @@ static void write_materials(WriteData *wd, ListBase *idbase) for (a = 0; a < MAX_MTEX; a++) { if (ma->mtex[a]) { - writestruct(wd, DATA, "MTex", 1, ma->mtex[a]); + writestruct(wd, DATA, MTex, 1, ma->mtex[a]); } } if (ma->ramp_col) { - writestruct(wd, DATA, "ColorBand", 1, ma->ramp_col); + writestruct(wd, DATA, ColorBand, 1, ma->ramp_col); } if (ma->ramp_spec) { - writestruct(wd, DATA, "ColorBand", 1, ma->ramp_spec); + writestruct(wd, DATA, ColorBand, 1, ma->ramp_spec); } /* nodetree is integral part of material, no libdata */ if (ma->nodetree) { - writestruct(wd, DATA, "bNodeTree", 1, ma->nodetree); + writestruct(wd, DATA, bNodeTree, 1, ma->nodetree); write_nodetree(wd, ma->nodetree); } @@ -2455,7 +2509,7 @@ static void write_worlds(WriteData *wd, ListBase *idbase) while (wrld) { if (wrld->id.us > 0 || wd->current) { /* write LibData */ - writestruct(wd, ID_WO, "World", 1, wrld); + writestruct(wd, ID_WO, World, 1, wrld); write_iddata(wd, &wrld->id); if (wrld->adt) { @@ -2464,13 +2518,13 @@ static void write_worlds(WriteData *wd, ListBase *idbase) for (a = 0; a < MAX_MTEX; a++) { if (wrld->mtex[a]) { - writestruct(wd, DATA, "MTex", 1, wrld->mtex[a]); + writestruct(wd, DATA, MTex, 1, wrld->mtex[a]); } } /* nodetree is integral part of world, no libdata */ if (wrld->nodetree) { - writestruct(wd, DATA, "bNodeTree", 1, wrld->nodetree); + writestruct(wd, DATA, bNodeTree, 1, wrld->nodetree); write_nodetree(wd, wrld->nodetree); } @@ -2489,7 +2543,7 @@ static void write_lamps(WriteData *wd, ListBase *idbase) while (la) { if (la->id.us > 0 || wd->current) { /* write LibData */ - writestruct(wd, ID_LA, "Lamp", 1, la); + writestruct(wd, ID_LA, Lamp, 1, la); write_iddata(wd, &la->id); if (la->adt) { @@ -2499,7 +2553,7 @@ static void write_lamps(WriteData *wd, ListBase *idbase) /* direct data */ for (a = 0; a < MAX_MTEX; a++) { if (la->mtex[a]) { - writestruct(wd, DATA, "MTex", 1, la->mtex[a]); + writestruct(wd, DATA, MTex, 1, la->mtex[a]); } } @@ -2509,7 +2563,7 @@ static void write_lamps(WriteData *wd, ListBase *idbase) /* nodetree is integral part of lamps, no libdata */ if (la->nodetree) { - writestruct(wd, DATA, "bNodeTree", 1, la->nodetree); + writestruct(wd, DATA, bNodeTree, 1, la->nodetree); write_nodetree(wd, la->nodetree); } @@ -2528,7 +2582,7 @@ static void write_sequence_modifiers(WriteData *wd, ListBase *modbase) const SequenceModifierTypeInfo *smti = BKE_sequence_modifier_type_info_get(smd->type); if (smti) { - writestruct(wd, DATA, smti->struct_name, 1, smd); + writestruct_id(wd, DATA, smti->struct_name, 1, smd); if (smd->type == seqModifierType_Curves) { CurvesModifierData *cmd = (CurvesModifierData *)smd; @@ -2542,7 +2596,7 @@ static void write_sequence_modifiers(WriteData *wd, ListBase *modbase) } } else { - writestruct(wd, DATA, "SequenceModifierData", 1, smd); + writestruct(wd, DATA, SequenceModifierData, 1, smd); } } } @@ -2580,7 +2634,7 @@ static void write_scenes(WriteData *wd, ListBase *scebase) sce = scebase->first; while (sce) { /* write LibData */ - writestruct(wd, ID_SCE, "Scene", 1, sce); + writestruct(wd, ID_SCE, Scene, 1, sce); write_iddata(wd, &sce->id); if (sce->adt) { @@ -2591,26 +2645,26 @@ static void write_scenes(WriteData *wd, ListBase *scebase) /* direct data */ base = sce->base.first; while (base) { - writestruct(wd, DATA, "Base", 1, base); + writestruct(wd, DATA, Base, 1, base); base = base->next; } tos = sce->toolsettings; - writestruct(wd, DATA, "ToolSettings", 1, tos); + writestruct(wd, DATA, ToolSettings, 1, tos); if (tos->vpaint) { - writestruct(wd, DATA, "VPaint", 1, tos->vpaint); + writestruct(wd, DATA, VPaint, 1, tos->vpaint); write_paint(wd, &tos->vpaint->paint); } if (tos->wpaint) { - writestruct(wd, DATA, "VPaint", 1, tos->wpaint); + writestruct(wd, DATA, VPaint, 1, tos->wpaint); write_paint(wd, &tos->wpaint->paint); } if (tos->sculpt) { - writestruct(wd, DATA, "Sculpt", 1, tos->sculpt); + writestruct(wd, DATA, Sculpt, 1, tos->sculpt); write_paint(wd, &tos->sculpt->paint); } if (tos->uvsculpt) { - writestruct(wd, DATA, "UvSculpt", 1, tos->uvsculpt); + writestruct(wd, DATA, UvSculpt, 1, tos->uvsculpt); write_paint(wd, &tos->uvsculpt->paint); } @@ -2618,7 +2672,7 @@ static void write_scenes(WriteData *wd, ListBase *scebase) ed = sce->ed; if (ed) { - writestruct(wd, DATA, "Editing", 1, ed); + writestruct(wd, DATA, Editing, 1, ed); /* reset write flags too */ @@ -2627,7 +2681,7 @@ static void write_scenes(WriteData *wd, ListBase *scebase) if (seq->strip) { seq->strip->done = false; } - writestruct(wd, DATA, "Sequence", 1, seq); + writestruct(wd, DATA, Sequence, 1, seq); } SEQ_END @@ -2639,49 +2693,49 @@ static void write_scenes(WriteData *wd, ListBase *scebase) if (seq->effectdata) { switch (seq->type) { case SEQ_TYPE_COLOR: - writestruct(wd, DATA, "SolidColorVars", 1, seq->effectdata); + writestruct(wd, DATA, SolidColorVars, 1, seq->effectdata); break; case SEQ_TYPE_SPEED: - writestruct(wd, DATA, "SpeedControlVars", 1, seq->effectdata); + writestruct(wd, DATA, SpeedControlVars, 1, seq->effectdata); break; case SEQ_TYPE_WIPE: - writestruct(wd, DATA, "WipeVars", 1, seq->effectdata); + writestruct(wd, DATA, WipeVars, 1, seq->effectdata); break; case SEQ_TYPE_GLOW: - writestruct(wd, DATA, "GlowVars", 1, seq->effectdata); + writestruct(wd, DATA, GlowVars, 1, seq->effectdata); break; case SEQ_TYPE_TRANSFORM: - writestruct(wd, DATA, "TransformVars", 1, seq->effectdata); + writestruct(wd, DATA, TransformVars, 1, seq->effectdata); break; case SEQ_TYPE_GAUSSIAN_BLUR: - writestruct(wd, DATA, "GaussianBlurVars", 1, seq->effectdata); + writestruct(wd, DATA, GaussianBlurVars, 1, seq->effectdata); break; case SEQ_TYPE_TEXT: - writestruct(wd, DATA, "TextVars", 1, seq->effectdata); + writestruct(wd, DATA, TextVars, 1, seq->effectdata); break; } } - writestruct(wd, DATA, "Stereo3dFormat", 1, seq->stereo3d_format); + writestruct(wd, DATA, Stereo3dFormat, 1, seq->stereo3d_format); strip = seq->strip; - writestruct(wd, DATA, "Strip", 1, strip); + writestruct(wd, DATA, Strip, 1, strip); if (seq->flag & SEQ_USE_CROP && strip->crop) { - writestruct(wd, DATA, "StripCrop", 1, strip->crop); + writestruct(wd, DATA, StripCrop, 1, strip->crop); } if (seq->flag & SEQ_USE_TRANSFORM && strip->transform) { - writestruct(wd, DATA, "StripTransform", 1, strip->transform); + writestruct(wd, DATA, StripTransform, 1, strip->transform); } if (seq->flag & SEQ_USE_PROXY && strip->proxy) { - writestruct(wd, DATA, "StripProxy", 1, strip->proxy); + writestruct(wd, DATA, StripProxy, 1, strip->proxy); } if (seq->type == SEQ_TYPE_IMAGE) { - writestruct(wd, DATA, "StripElem", + writestruct(wd, DATA, StripElem, MEM_allocN_len(strip->stripdata) / sizeof(struct StripElem), strip->stripdata); } else if (ELEM(seq->type, SEQ_TYPE_MOVIE, SEQ_TYPE_SOUND_RAM, SEQ_TYPE_SOUND_HD)) { - writestruct(wd, DATA, "StripElem", 1, strip->stripdata); + writestruct(wd, DATA, StripElem, 1, strip->stripdata); } strip->done = true; @@ -2697,12 +2751,12 @@ static void write_scenes(WriteData *wd, ListBase *scebase) /* new; meta stack too, even when its nasty restore code */ for (ms = ed->metastack.first; ms; ms = ms->next) { - writestruct(wd, DATA, "MetaStack", 1, ms); + writestruct(wd, DATA, MetaStack, 1, ms); } } if (sce->r.avicodecdata) { - writestruct(wd, DATA, "AviCodecData", 1, sce->r.avicodecdata); + writestruct(wd, DATA, AviCodecData, 1, sce->r.avicodecdata); if (sce->r.avicodecdata->lpFormat) { writedata(wd, DATA, sce->r.avicodecdata->cbFormat, sce->r.avicodecdata->lpFormat); } @@ -2712,7 +2766,7 @@ static void write_scenes(WriteData *wd, ListBase *scebase) } if (sce->r.qtcodecdata) { - writestruct(wd, DATA, "QuicktimeCodecData", 1, sce->r.qtcodecdata); + writestruct(wd, DATA, QuicktimeCodecData, 1, sce->r.qtcodecdata); if (sce->r.qtcodecdata->cdParms) { writedata(wd, DATA, sce->r.qtcodecdata->cdSize, sce->r.qtcodecdata->cdParms); } @@ -2723,31 +2777,31 @@ static void write_scenes(WriteData *wd, ListBase *scebase) /* writing dynamic list of TimeMarkers to the blend file */ for (marker = sce->markers.first; marker; marker = marker->next) { - writestruct(wd, DATA, "TimeMarker", 1, marker); + writestruct(wd, DATA, TimeMarker, 1, marker); } /* writing dynamic list of TransformOrientations to the blend file */ for (ts = sce->transform_spaces.first; ts; ts = ts->next) { - writestruct(wd, DATA, "TransformOrientation", 1, ts); + writestruct(wd, DATA, TransformOrientation, 1, ts); } for (srl = sce->r.layers.first; srl; srl = srl->next) { - writestruct(wd, DATA, "SceneRenderLayer", 1, srl); + writestruct(wd, DATA, SceneRenderLayer, 1, srl); for (fmc = srl->freestyleConfig.modules.first; fmc; fmc = fmc->next) { - writestruct(wd, DATA, "FreestyleModuleConfig", 1, fmc); + writestruct(wd, DATA, FreestyleModuleConfig, 1, fmc); } for (fls = srl->freestyleConfig.linesets.first; fls; fls = fls->next) { - writestruct(wd, DATA, "FreestyleLineSet", 1, fls); + writestruct(wd, DATA, FreestyleLineSet, 1, fls); } } /* writing MultiView to the blend file */ for (srv = sce->r.views.first; srv; srv = srv->next) { - writestruct(wd, DATA, "SceneRenderView", 1, srv); + writestruct(wd, DATA, SceneRenderView, 1, srv); } if (sce->nodetree) { - writestruct(wd, DATA, "bNodeTree", 1, sce->nodetree); + writestruct(wd, DATA, bNodeTree, 1, sce->nodetree); write_nodetree(wd, sce->nodetree); } @@ -2755,8 +2809,8 @@ static void write_scenes(WriteData *wd, ListBase *scebase) /* writing RigidBodyWorld data to the blend file */ if (sce->rigidbody_world) { - writestruct(wd, DATA, "RigidBodyWorld", 1, sce->rigidbody_world); - writestruct(wd, DATA, "EffectorWeights", 1, sce->rigidbody_world->effector_weights); + writestruct(wd, DATA, RigidBodyWorld, 1, sce->rigidbody_world); + writestruct(wd, DATA, EffectorWeights, 1, sce->rigidbody_world->effector_weights); write_pointcaches(wd, &(sce->rigidbody_world->ptcaches)); } @@ -2779,7 +2833,7 @@ static void write_gpencils(WriteData *wd, ListBase *lb) for (gpd = lb->first; gpd; gpd = gpd->id.next) { if (gpd->id.us > 0 || wd->current) { /* write gpd data block to file */ - writestruct(wd, ID_GD, "bGPdata", 1, gpd); + writestruct(wd, ID_GD, bGPdata, 1, gpd); write_iddata(wd, &gpd->id); if (gpd->adt) { @@ -2787,17 +2841,17 @@ static void write_gpencils(WriteData *wd, ListBase *lb) } /* write grease-pencil layers to file */ - writelist(wd, DATA, "bGPDlayer", &gpd->layers); + writelist(wd, DATA, bGPDlayer, &gpd->layers); for (gpl = gpd->layers.first; gpl; gpl = gpl->next) { /* write this layer's frames to file */ - writelist(wd, DATA, "bGPDframe", &gpl->frames); + writelist(wd, DATA, bGPDframe, &gpl->frames); for (gpf = gpl->frames.first; gpf; gpf = gpf->next) { /* write strokes */ - writelist(wd, DATA, "bGPDstroke", &gpf->strokes); + writelist(wd, DATA, bGPDstroke, &gpf->strokes); for (gps = gpf->strokes.first; gps; gps = gps->next) { - writestruct(wd, DATA, "bGPDspoint", gps->totpoints, gps->points); + writestruct(wd, DATA, bGPDspoint, gps->totpoints, gps->points); } } } @@ -2811,32 +2865,32 @@ static void write_windowmanagers(WriteData *wd, ListBase *lb) wmWindow *win; for (wm = lb->first; wm; wm = wm->id.next) { - writestruct(wd, ID_WM, "wmWindowManager", 1, wm); + writestruct(wd, ID_WM, wmWindowManager, 1, wm); write_iddata(wd, &wm->id); for (win = wm->windows.first; win; win = win->next) { - writestruct(wd, DATA, "wmWindow", 1, win); - writestruct(wd, DATA, "Stereo3dFormat", 1, win->stereo3d_format); + writestruct(wd, DATA, wmWindow, 1, win); + writestruct(wd, DATA, Stereo3dFormat, 1, win->stereo3d_format); } } } static void write_region(WriteData *wd, ARegion *ar, int spacetype) { - writestruct(wd, DATA, "ARegion", 1, ar); + writestruct(wd, DATA, ARegion, 1, ar); if (ar->regiondata) { switch (spacetype) { case SPACE_VIEW3D: if (ar->regiontype == RGN_TYPE_WINDOW) { RegionView3D *rv3d = ar->regiondata; - writestruct(wd, DATA, "RegionView3D", 1, rv3d); + writestruct(wd, DATA, RegionView3D, 1, rv3d); if (rv3d->localvd) { - writestruct(wd, DATA, "RegionView3D", 1, rv3d->localvd); + writestruct(wd, DATA, RegionView3D, 1, rv3d->localvd); } if (rv3d->clipbb) { - writestruct(wd, DATA, "BoundBox", 1, rv3d->clipbb); + writestruct(wd, DATA, BoundBox, 1, rv3d->clipbb); } } @@ -2851,7 +2905,7 @@ static void write_region(WriteData *wd, ARegion *ar, int spacetype) static void write_uilist(WriteData *wd, uiList *ui_list) { - writestruct(wd, DATA, "uiList", 1, ui_list); + writestruct(wd, DATA, uiList, 1, ui_list); if (ui_list->properties) { IDP_WriteProperty(ui_list->properties, wd); @@ -2876,10 +2930,10 @@ static void write_soops(WriteData *wd, SpaceOops *so, LinkNode **tmp_mem_list) /* temporarily replace mempool-treestore by flat-treestore */ so->treestore = (BLI_mempool *)ts_flat; - writestruct(wd, DATA, "SpaceOops", 1, so); + writestruct(wd, DATA, SpaceOops, 1, so); - writestruct(wd, DATA, "TreeStore", 1, ts_flat); - writestruct(wd, DATA, "TreeStoreElem", elems, data); + writestruct(wd, DATA, TreeStore, 1, ts_flat); + writestruct(wd, DATA, TreeStoreElem, elems, data); /* we do not free the pointers immediately, because if we have multiple * outliners in a screen we might get the same address on the next @@ -2890,14 +2944,14 @@ static void write_soops(WriteData *wd, SpaceOops *so, LinkNode **tmp_mem_list) } else { so->treestore = NULL; - writestruct(wd, DATA, "SpaceOops", 1, so); + writestruct(wd, DATA, SpaceOops, 1, so); } /* restore old treestore */ so->treestore = ts; } else { - writestruct(wd, DATA, "SpaceOops", 1, so); + writestruct(wd, DATA, SpaceOops, 1, so); } } @@ -2914,16 +2968,16 @@ static void write_screens(WriteData *wd, ListBase *scrbase) /* write LibData */ /* in 2.50+ files, the file identifier for screens is patched, forward compatibility */ - writestruct(wd, ID_SCRN, "Screen", 1, sc); + writestruct(wd, ID_SCRN, bScreen, 1, sc); write_iddata(wd, &sc->id); /* direct data */ for (sv = sc->vertbase.first; sv; sv = sv->next) { - writestruct(wd, DATA, "ScrVert", 1, sv); + writestruct(wd, DATA, ScrVert, 1, sv); } for (se = sc->edgebase.first; se; se = se->next) { - writestruct(wd, DATA, "ScrEdge", 1, se); + writestruct(wd, DATA, ScrEdge, 1, se); } for (sa = sc->areabase.first; sa; sa = sa->next) { @@ -2934,17 +2988,17 @@ static void write_screens(WriteData *wd, ListBase *scrbase) PanelCategoryStack *pc_act; ARegion *ar; - writestruct(wd, DATA, "ScrArea", 1, sa); + writestruct(wd, DATA, ScrArea, 1, sa); for (ar = sa->regionbase.first; ar; ar = ar->next) { write_region(wd, ar, sa->spacetype); for (pa = ar->panels.first; pa; pa = pa->next) { - writestruct(wd, DATA, "Panel", 1, pa); + writestruct(wd, DATA, Panel, 1, pa); } for (pc_act = ar->panels_category_active.first; pc_act; pc_act = pc_act->next) { - writestruct(wd, DATA, "PanelCategoryStack", 1, pc_act); + writestruct(wd, DATA, PanelCategoryStack, 1, pc_act); } for (ui_list = ar->ui_lists.first; ui_list; ui_list = ui_list->next) { @@ -2952,7 +3006,7 @@ static void write_screens(WriteData *wd, ListBase *scrbase) } for (ui_preview = ar->ui_previews.first; ui_preview; ui_preview = ui_preview->next) { - writestruct(wd, DATA, "uiPreview", 1, ui_preview); + writestruct(wd, DATA, uiPreview, 1, ui_preview); } } @@ -2965,19 +3019,19 @@ static void write_screens(WriteData *wd, ListBase *scrbase) if (sl->spacetype == SPACE_VIEW3D) { View3D *v3d = (View3D *)sl; BGpic *bgpic; - writestruct(wd, DATA, "View3D", 1, v3d); + writestruct(wd, DATA, View3D, 1, v3d); for (bgpic = v3d->bgpicbase.first; bgpic; bgpic = bgpic->next) { - writestruct(wd, DATA, "BGpic", 1, bgpic); + writestruct(wd, DATA, BGpic, 1, bgpic); } if (v3d->localvd) { - writestruct(wd, DATA, "View3D", 1, v3d->localvd); + writestruct(wd, DATA, View3D, 1, v3d->localvd); } if (v3d->fx_settings.ssao) { - writestruct(wd, DATA, "GPUSSAOSettings", 1, v3d->fx_settings.ssao); + writestruct(wd, DATA, GPUSSAOSettings, 1, v3d->fx_settings.ssao); } if (v3d->fx_settings.dof) { - writestruct(wd, DATA, "GPUDOFSettings", 1, v3d->fx_settings.dof); + writestruct(wd, DATA, GPUDOFSettings, 1, v3d->fx_settings.dof); } } else if (sl->spacetype == SPACE_IPO) { @@ -2987,68 +3041,68 @@ static void write_screens(WriteData *wd, ListBase *scrbase) /* temporarily disable ghost curves when saving */ sipo->ghostCurves.first = sipo->ghostCurves.last = NULL; - writestruct(wd, DATA, "SpaceIpo", 1, sl); + writestruct(wd, DATA, SpaceIpo, 1, sl); if (sipo->ads) { - writestruct(wd, DATA, "bDopeSheet", 1, sipo->ads); + writestruct(wd, DATA, bDopeSheet, 1, sipo->ads); } /* reenable ghost curves */ sipo->ghostCurves = tmpGhosts; } else if (sl->spacetype == SPACE_BUTS) { - writestruct(wd, DATA, "SpaceButs", 1, sl); + writestruct(wd, DATA, SpaceButs, 1, sl); } else if (sl->spacetype == SPACE_FILE) { SpaceFile *sfile = (SpaceFile *)sl; - writestruct(wd, DATA, "SpaceFile", 1, sl); + writestruct(wd, DATA, SpaceFile, 1, sl); if (sfile->params) { - writestruct(wd, DATA, "FileSelectParams", 1, sfile->params); + writestruct(wd, DATA, FileSelectParams, 1, sfile->params); } } else if (sl->spacetype == SPACE_SEQ) { - writestruct(wd, DATA, "SpaceSeq", 1, sl); + writestruct(wd, DATA, SpaceSeq, 1, sl); } else if (sl->spacetype == SPACE_OUTLINER) { SpaceOops *so = (SpaceOops *)sl; write_soops(wd, so, &tmp_mem_list); } else if (sl->spacetype == SPACE_IMAGE) { - writestruct(wd, DATA, "SpaceImage", 1, sl); + writestruct(wd, DATA, SpaceImage, 1, sl); } else if (sl->spacetype == SPACE_TEXT) { - writestruct(wd, DATA, "SpaceText", 1, sl); + writestruct(wd, DATA, SpaceText, 1, sl); } else if (sl->spacetype == SPACE_SCRIPT) { SpaceScript *scr = (SpaceScript *)sl; scr->but_refs = NULL; - writestruct(wd, DATA, "SpaceScript", 1, sl); + writestruct(wd, DATA, SpaceScript, 1, sl); } else if (sl->spacetype == SPACE_ACTION) { - writestruct(wd, DATA, "SpaceAction", 1, sl); + writestruct(wd, DATA, SpaceAction, 1, sl); } else if (sl->spacetype == SPACE_NLA) { SpaceNla *snla = (SpaceNla *)sl; - writestruct(wd, DATA, "SpaceNla", 1, snla); + writestruct(wd, DATA, SpaceNla, 1, snla); if (snla->ads) { - writestruct(wd, DATA, "bDopeSheet", 1, snla->ads); + writestruct(wd, DATA, bDopeSheet, 1, snla->ads); } } else if (sl->spacetype == SPACE_TIME) { - writestruct(wd, DATA, "SpaceTime", 1, sl); + writestruct(wd, DATA, SpaceTime, 1, sl); } else if (sl->spacetype == SPACE_NODE) { SpaceNode *snode = (SpaceNode *)sl; bNodeTreePath *path; - writestruct(wd, DATA, "SpaceNode", 1, snode); + writestruct(wd, DATA, SpaceNode, 1, snode); for (path = snode->treepath.first; path; path = path->next) { - writestruct(wd, DATA, "bNodeTreePath", 1, path); + writestruct(wd, DATA, bNodeTreePath, 1, path); } } else if (sl->spacetype == SPACE_LOGIC) { - writestruct(wd, DATA, "SpaceLogic", 1, sl); + writestruct(wd, DATA, SpaceLogic, 1, sl); } else if (sl->spacetype == SPACE_CONSOLE) { SpaceConsole *con = (SpaceConsole *)sl; @@ -3056,20 +3110,20 @@ static void write_screens(WriteData *wd, ListBase *scrbase) for (cl = con->history.first; cl; cl = cl->next) { /* 'len_alloc' is invalid on write, set from 'len' on read */ - writestruct(wd, DATA, "ConsoleLine", 1, cl); + writestruct(wd, DATA, ConsoleLine, 1, cl); writedata(wd, DATA, cl->len + 1, cl->line); } - writestruct(wd, DATA, "SpaceConsole", 1, sl); + writestruct(wd, DATA, SpaceConsole, 1, sl); } else if (sl->spacetype == SPACE_USERPREF) { - writestruct(wd, DATA, "SpaceUserPref", 1, sl); + writestruct(wd, DATA, SpaceUserPref, 1, sl); } else if (sl->spacetype == SPACE_CLIP) { - writestruct(wd, DATA, "SpaceClip", 1, sl); + writestruct(wd, DATA, SpaceClip, 1, sl); } else if (sl->spacetype == SPACE_INFO) { - writestruct(wd, DATA, "SpaceInfo", 1, sl); + writestruct(wd, DATA, SpaceInfo, 1, sl); } sl = sl->next; @@ -3091,7 +3145,7 @@ static void write_bone(WriteData *wd, Bone *bone) bone->size[0] = bone->size[1] = bone->size[2] = 1.0f; /* Write this bone */ - writestruct(wd, DATA, "Bone", 1, bone); + writestruct(wd, DATA, Bone, 1, bone); /* Write ID Properties -- and copy this comment EXACTLY for easy finding * of library blocks that implement this.*/ @@ -3113,7 +3167,7 @@ static void write_armatures(WriteData *wd, ListBase *idbase) arm = idbase->first; while (arm) { if (arm->id.us > 0 || wd->current) { - writestruct(wd, ID_AR, "bArmature", 1, arm); + writestruct(wd, ID_AR, bArmature, 1, arm); write_iddata(wd, &arm->id); if (arm->adt) { @@ -3146,7 +3200,7 @@ static void write_texts(WriteData *wd, ListBase *idbase) } /* write LibData */ - writestruct(wd, ID_TXT, "Text", 1, text); + writestruct(wd, ID_TXT, Text, 1, text); write_iddata(wd, &text->id); if (text->name) { @@ -3157,7 +3211,7 @@ static void write_texts(WriteData *wd, ListBase *idbase) /* now write the text data, in two steps for optimization in the readfunction */ tmp = text->lines.first; while (tmp) { - writestruct(wd, DATA, "TextLine", 1, tmp); + writestruct(wd, DATA, TextLine, 1, tmp); tmp = tmp->next; } @@ -3184,7 +3238,7 @@ static void write_speakers(WriteData *wd, ListBase *idbase) while (spk) { if (spk->id.us > 0 || wd->current) { /* write LibData */ - writestruct(wd, ID_SPK, "Speaker", 1, spk); + writestruct(wd, ID_SPK, Speaker, 1, spk); write_iddata(wd, &spk->id); if (spk->adt) { @@ -3205,12 +3259,12 @@ static void write_sounds(WriteData *wd, ListBase *idbase) while (sound) { if (sound->id.us > 0 || wd->current) { /* write LibData */ - writestruct(wd, ID_SO, "bSound", 1, sound); + writestruct(wd, ID_SO, bSound, 1, sound); write_iddata(wd, &sound->id); if (sound->packedfile) { pf = sound->packedfile; - writestruct(wd, DATA, "PackedFile", 1, pf); + writestruct(wd, DATA, PackedFile, 1, pf); writedata(wd, DATA, pf->size, pf->data); } } @@ -3229,14 +3283,14 @@ static void write_groups(WriteData *wd, ListBase *idbase) for (group = idbase->first; group; group = group->id.next) { if (group->id.us > 0 || wd->current) { /* write LibData */ - writestruct(wd, ID_GR, "Group", 1, group); + writestruct(wd, ID_GR, Group, 1, group); write_iddata(wd, &group->id); write_previews(wd, group->preview); go = group->gobject.first; while (go) { - writestruct(wd, DATA, "GroupObject", 1, go); + writestruct(wd, DATA, GroupObject, 1, go); go = go->next; } } @@ -3249,7 +3303,7 @@ static void write_nodetrees(WriteData *wd, ListBase *idbase) for (ntree = idbase->first; ntree; ntree = ntree->id.next) { if (ntree->id.us > 0 || wd->current) { - writestruct(wd, ID_NT, "bNodeTree", 1, ntree); + writestruct(wd, ID_NT, bNodeTree, 1, ntree); /* Note that trees directly used by other IDs (materials etc.) are not 'real' ID, they cannot * be linked, etc., so we write actual id data here only, for 'real' ID trees. */ write_iddata(wd, &ntree->id); @@ -3335,14 +3389,14 @@ static void write_brushes(WriteData *wd, ListBase *idbase) for (brush = idbase->first; brush; brush = brush->id.next) { if (brush->id.us > 0 || wd->current) { - writestruct(wd, ID_BR, "Brush", 1, brush); + writestruct(wd, ID_BR, Brush, 1, brush); write_iddata(wd, &brush->id); if (brush->curve) { write_curvemapping(wd, brush->curve); } if (brush->gradient) { - writestruct(wd, DATA, "ColorBand", 1, brush->gradient); + writestruct(wd, DATA, ColorBand, 1, brush->gradient); } } } @@ -3355,11 +3409,11 @@ static void write_palettes(WriteData *wd, ListBase *idbase) for (palette = idbase->first; palette; palette = palette->id.next) { if (palette->id.us > 0 || wd->current) { PaletteColor *color; - writestruct(wd, ID_PAL, "Palette", 1, palette); + writestruct(wd, ID_PAL, Palette, 1, palette); write_iddata(wd, &palette->id); for (color = palette->colors.first; color; color = color->next) { - writestruct(wd, DATA, "PaletteColor", 1, color); + writestruct(wd, DATA, PaletteColor, 1, color); } } } @@ -3371,10 +3425,10 @@ static void write_paintcurves(WriteData *wd, ListBase *idbase) for (pc = idbase->first; pc; pc = pc->id.next) { if (pc->id.us > 0 || wd->current) { - writestruct(wd, ID_PC, "PaintCurve", 1, pc); + writestruct(wd, ID_PC, PaintCurve, 1, pc); write_iddata(wd, &pc->id); - writestruct(wd, DATA, "PaintCurvePoint", pc->tot_points, pc->points); + writestruct(wd, DATA, PaintCurvePoint, pc->tot_points, pc->points); } } } @@ -3385,10 +3439,10 @@ static void write_movieTracks(WriteData *wd, ListBase *tracks) track = tracks->first; while (track) { - writestruct(wd, DATA, "MovieTrackingTrack", 1, track); + writestruct(wd, DATA, MovieTrackingTrack, 1, track); if (track->markers) { - writestruct(wd, DATA, "MovieTrackingMarker", track->markersnr, track->markers); + writestruct(wd, DATA, MovieTrackingMarker, track->markersnr, track->markers); } track = track->next; @@ -3403,17 +3457,17 @@ static void write_moviePlaneTracks(WriteData *wd, ListBase *plane_tracks_base) plane_track; plane_track = plane_track->next) { - writestruct(wd, DATA, "MovieTrackingPlaneTrack", 1, plane_track); + writestruct(wd, DATA, MovieTrackingPlaneTrack, 1, plane_track); writedata(wd, DATA, sizeof(MovieTrackingTrack *) * plane_track->point_tracksnr, plane_track->point_tracks); - writestruct(wd, DATA, "MovieTrackingPlaneMarker", plane_track->markersnr, plane_track->markers); + writestruct(wd, DATA, MovieTrackingPlaneMarker, plane_track->markersnr, plane_track->markers); } } static void write_movieReconstruction(WriteData *wd, MovieTrackingReconstruction *reconstruction) { if (reconstruction->camnr) { - writestruct(wd, DATA, "MovieReconstructedCamera", reconstruction->camnr, reconstruction->cameras); + writestruct(wd, DATA, MovieReconstructedCamera, reconstruction->camnr, reconstruction->cameras); } } @@ -3427,7 +3481,7 @@ static void write_movieclips(WriteData *wd, ListBase *idbase) MovieTracking *tracking = &clip->tracking; MovieTrackingObject *object; - writestruct(wd, ID_MC, "MovieClip", 1, clip); + writestruct(wd, ID_MC, MovieClip, 1, clip); write_iddata(wd, &clip->id); if (clip->adt) { @@ -3440,7 +3494,7 @@ static void write_movieclips(WriteData *wd, ListBase *idbase) object = tracking->objects.first; while (object) { - writestruct(wd, DATA, "MovieTrackingObject", 1, object); + writestruct(wd, DATA, MovieTrackingObject, 1, object); write_movieTracks(wd, &object->tracks); write_moviePlaneTracks(wd, &object->plane_tracks); @@ -3466,7 +3520,7 @@ static void write_masks(WriteData *wd, ListBase *idbase) if (mask->id.us > 0 || wd->current) { MaskLayer *masklay; - writestruct(wd, ID_MSK, "Mask", 1, mask); + writestruct(wd, ID_MSK, Mask, 1, mask); write_iddata(wd, &mask->id); if (mask->adt) { @@ -3477,7 +3531,7 @@ static void write_masks(WriteData *wd, ListBase *idbase) MaskSpline *spline; MaskLayerShape *masklay_shape; - writestruct(wd, DATA, "MaskLayer", 1, masklay); + writestruct(wd, DATA, MaskLayer, 1, masklay); for (spline = masklay->splines.first; spline; spline = spline->next) { int i; @@ -3485,8 +3539,8 @@ static void write_masks(WriteData *wd, ListBase *idbase) void *points_deform = spline->points_deform; spline->points_deform = NULL; - writestruct(wd, DATA, "MaskSpline", 1, spline); - writestruct(wd, DATA, "MaskSplinePoint", spline->tot_point, spline->points); + writestruct(wd, DATA, MaskSpline, 1, spline); + writestruct(wd, DATA, MaskSplinePoint, spline->tot_point, spline->points); spline->points_deform = points_deform; @@ -3494,7 +3548,7 @@ static void write_masks(WriteData *wd, ListBase *idbase) MaskSplinePoint *point = &spline->points[i]; if (point->tot_uw) { - writestruct(wd, DATA, "MaskSplinePointUW", point->tot_uw, point->uw); + writestruct(wd, DATA, MaskSplinePointUW, point->tot_uw, point->uw); } } } @@ -3503,7 +3557,7 @@ static void write_masks(WriteData *wd, ListBase *idbase) masklay_shape; masklay_shape = masklay_shape->next) { - writestruct(wd, DATA, "MaskLayerShape", 1, masklay_shape); + writestruct(wd, DATA, MaskLayerShape, 1, masklay_shape); writedata(wd, DATA, masklay_shape->tot_vert * sizeof(float) * MASK_OBJECT_SHAPE_ELEM_SIZE, masklay_shape->data); @@ -3521,64 +3575,64 @@ static void write_masks(WriteData *wd, ListBase *idbase) static void write_linestyle_color_modifiers(WriteData *wd, ListBase *modifiers) { LineStyleModifier *m; - const char *struct_name; for (m = modifiers->first; m; m = m->next) { + int struct_nr; switch (m->type) { case LS_MODIFIER_ALONG_STROKE: - struct_name = "LineStyleColorModifier_AlongStroke"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_AlongStroke); break; case LS_MODIFIER_DISTANCE_FROM_CAMERA: - struct_name = "LineStyleColorModifier_DistanceFromCamera"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_DistanceFromCamera); break; case LS_MODIFIER_DISTANCE_FROM_OBJECT: - struct_name = "LineStyleColorModifier_DistanceFromObject"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_DistanceFromObject); break; case LS_MODIFIER_MATERIAL: - struct_name = "LineStyleColorModifier_Material"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_Material); break; case LS_MODIFIER_TANGENT: - struct_name = "LineStyleColorModifier_Tangent"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_Tangent); break; case LS_MODIFIER_NOISE: - struct_name = "LineStyleColorModifier_Noise"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_Noise); break; case LS_MODIFIER_CREASE_ANGLE: - struct_name = "LineStyleColorModifier_CreaseAngle"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_CreaseAngle); break; case LS_MODIFIER_CURVATURE_3D: - struct_name = "LineStyleColorModifier_Curvature_3D"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_Curvature_3D); break; default: - struct_name = "LineStyleColorModifier"; /* this should not happen */ + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleModifier); /* this should not happen */ } - writestruct(wd, DATA, struct_name, 1, m); + writestruct_nr(wd, DATA, struct_nr, 1, m); } for (m = modifiers->first; m; m = m->next) { switch (m->type) { case LS_MODIFIER_ALONG_STROKE: - writestruct(wd, DATA, "ColorBand", 1, ((LineStyleColorModifier_AlongStroke *)m)->color_ramp); + writestruct(wd, DATA, ColorBand, 1, ((LineStyleColorModifier_AlongStroke *)m)->color_ramp); break; case LS_MODIFIER_DISTANCE_FROM_CAMERA: - writestruct(wd, DATA, "ColorBand", 1, ((LineStyleColorModifier_DistanceFromCamera *)m)->color_ramp); + writestruct(wd, DATA, ColorBand, 1, ((LineStyleColorModifier_DistanceFromCamera *)m)->color_ramp); break; case LS_MODIFIER_DISTANCE_FROM_OBJECT: - writestruct(wd, DATA, "ColorBand", 1, ((LineStyleColorModifier_DistanceFromObject *)m)->color_ramp); + writestruct(wd, DATA, ColorBand, 1, ((LineStyleColorModifier_DistanceFromObject *)m)->color_ramp); break; case LS_MODIFIER_MATERIAL: - writestruct(wd, DATA, "ColorBand", 1, ((LineStyleColorModifier_Material *)m)->color_ramp); + writestruct(wd, DATA, ColorBand, 1, ((LineStyleColorModifier_Material *)m)->color_ramp); break; case LS_MODIFIER_TANGENT: - writestruct(wd, DATA, "ColorBand", 1, ((LineStyleColorModifier_Tangent *)m)->color_ramp); + writestruct(wd, DATA, ColorBand, 1, ((LineStyleColorModifier_Tangent *)m)->color_ramp); break; case LS_MODIFIER_NOISE: - writestruct(wd, DATA, "ColorBand", 1, ((LineStyleColorModifier_Noise *)m)->color_ramp); + writestruct(wd, DATA, ColorBand, 1, ((LineStyleColorModifier_Noise *)m)->color_ramp); break; case LS_MODIFIER_CREASE_ANGLE: - writestruct(wd, DATA, "ColorBand", 1, ((LineStyleColorModifier_CreaseAngle *)m)->color_ramp); + writestruct(wd, DATA, ColorBand, 1, ((LineStyleColorModifier_CreaseAngle *)m)->color_ramp); break; case LS_MODIFIER_CURVATURE_3D: - writestruct(wd, DATA, "ColorBand", 1, ((LineStyleColorModifier_Curvature_3D *)m)->color_ramp); + writestruct(wd, DATA, ColorBand, 1, ((LineStyleColorModifier_Curvature_3D *)m)->color_ramp); break; } } @@ -3587,38 +3641,38 @@ static void write_linestyle_color_modifiers(WriteData *wd, ListBase *modifiers) static void write_linestyle_alpha_modifiers(WriteData *wd, ListBase *modifiers) { LineStyleModifier *m; - const char *struct_name; for (m = modifiers->first; m; m = m->next) { + int struct_nr; switch (m->type) { case LS_MODIFIER_ALONG_STROKE: - struct_name = "LineStyleAlphaModifier_AlongStroke"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_AlongStroke); break; case LS_MODIFIER_DISTANCE_FROM_CAMERA: - struct_name = "LineStyleAlphaModifier_DistanceFromCamera"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_DistanceFromCamera); break; case LS_MODIFIER_DISTANCE_FROM_OBJECT: - struct_name = "LineStyleAlphaModifier_DistanceFromObject"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_DistanceFromObject); break; case LS_MODIFIER_MATERIAL: - struct_name = "LineStyleAlphaModifier_Material"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_Material); break; case LS_MODIFIER_TANGENT: - struct_name = "LineStyleAlphaModifier_Tangent"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_Tangent); break; case LS_MODIFIER_NOISE: - struct_name = "LineStyleAlphaModifier_Noise"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_Noise); break; case LS_MODIFIER_CREASE_ANGLE: - struct_name = "LineStyleAlphaModifier_CreaseAngle"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_CreaseAngle); break; case LS_MODIFIER_CURVATURE_3D: - struct_name = "LineStyleAlphaModifier_Curvature_3D"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_Curvature_3D); break; default: - struct_name = "LineStyleAlphaModifier"; /* this should not happen */ + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleModifier); /* this should not happen */ } - writestruct(wd, DATA, struct_name, 1, m); + writestruct_nr(wd, DATA, struct_nr, 1, m); } for (m = modifiers->first; m; m = m->next) { switch (m->type) { @@ -3653,41 +3707,41 @@ static void write_linestyle_alpha_modifiers(WriteData *wd, ListBase *modifiers) static void write_linestyle_thickness_modifiers(WriteData *wd, ListBase *modifiers) { LineStyleModifier *m; - const char *struct_name; for (m = modifiers->first; m; m = m->next) { + int struct_nr; switch (m->type) { case LS_MODIFIER_ALONG_STROKE: - struct_name = "LineStyleThicknessModifier_AlongStroke"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_AlongStroke); break; case LS_MODIFIER_DISTANCE_FROM_CAMERA: - struct_name = "LineStyleThicknessModifier_DistanceFromCamera"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_DistanceFromCamera); break; case LS_MODIFIER_DISTANCE_FROM_OBJECT: - struct_name = "LineStyleThicknessModifier_DistanceFromObject"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_DistanceFromObject); break; case LS_MODIFIER_MATERIAL: - struct_name = "LineStyleThicknessModifier_Material"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_Material); break; case LS_MODIFIER_CALLIGRAPHY: - struct_name = "LineStyleThicknessModifier_Calligraphy"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_Calligraphy); break; case LS_MODIFIER_TANGENT: - struct_name = "LineStyleThicknessModifier_Tangent"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_Tangent); break; case LS_MODIFIER_NOISE: - struct_name = "LineStyleThicknessModifier_Noise"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_Noise); break; case LS_MODIFIER_CREASE_ANGLE: - struct_name = "LineStyleThicknessModifier_CreaseAngle"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_CreaseAngle); break; case LS_MODIFIER_CURVATURE_3D: - struct_name = "LineStyleThicknessModifier_Curvature_3D"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_Curvature_3D); break; default: - struct_name = "LineStyleThicknessModifier"; /* this should not happen */ + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleModifier); /* this should not happen */ } - writestruct(wd, DATA, struct_name, 1, m); + writestruct_nr(wd, DATA, struct_nr, 1, m); } for (m = modifiers->first; m; m = m->next) { switch (m->type) { @@ -3719,56 +3773,56 @@ static void write_linestyle_thickness_modifiers(WriteData *wd, ListBase *modifie static void write_linestyle_geometry_modifiers(WriteData *wd, ListBase *modifiers) { LineStyleModifier *m; - const char *struct_name; for (m = modifiers->first; m; m = m->next) { + int struct_nr; switch (m->type) { case LS_MODIFIER_SAMPLING: - struct_name = "LineStyleGeometryModifier_Sampling"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_Sampling); break; case LS_MODIFIER_BEZIER_CURVE: - struct_name = "LineStyleGeometryModifier_BezierCurve"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_BezierCurve); break; case LS_MODIFIER_SINUS_DISPLACEMENT: - struct_name = "LineStyleGeometryModifier_SinusDisplacement"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_SinusDisplacement); break; case LS_MODIFIER_SPATIAL_NOISE: - struct_name = "LineStyleGeometryModifier_SpatialNoise"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_SpatialNoise); break; case LS_MODIFIER_PERLIN_NOISE_1D: - struct_name = "LineStyleGeometryModifier_PerlinNoise1D"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_PerlinNoise1D); break; case LS_MODIFIER_PERLIN_NOISE_2D: - struct_name = "LineStyleGeometryModifier_PerlinNoise2D"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_PerlinNoise2D); break; case LS_MODIFIER_BACKBONE_STRETCHER: - struct_name = "LineStyleGeometryModifier_BackboneStretcher"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_BackboneStretcher); break; case LS_MODIFIER_TIP_REMOVER: - struct_name = "LineStyleGeometryModifier_TipRemover"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_TipRemover); break; case LS_MODIFIER_POLYGONIZATION: - struct_name = "LineStyleGeometryModifier_Polygonalization"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_Polygonalization); break; case LS_MODIFIER_GUIDING_LINES: - struct_name = "LineStyleGeometryModifier_GuidingLines"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_GuidingLines); break; case LS_MODIFIER_BLUEPRINT: - struct_name = "LineStyleGeometryModifier_Blueprint"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_Blueprint); break; case LS_MODIFIER_2D_OFFSET: - struct_name = "LineStyleGeometryModifier_2DOffset"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_2DOffset); break; case LS_MODIFIER_2D_TRANSFORM: - struct_name = "LineStyleGeometryModifier_2DTransform"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_2DTransform); break; case LS_MODIFIER_SIMPLIFICATION: - struct_name = "LineStyleGeometryModifier_Simplification"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_Simplification); break; default: - struct_name = "LineStyleGeometryModifier"; /* this should not happen */ + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleModifier); /* this should not happen */ } - writestruct(wd, DATA, struct_name, 1, m); + writestruct_nr(wd, DATA, struct_nr, 1, m); } } @@ -3779,7 +3833,7 @@ static void write_linestyles(WriteData *wd, ListBase *idbase) for (linestyle = idbase->first; linestyle; linestyle = linestyle->id.next) { if (linestyle->id.us > 0 || wd->current) { - writestruct(wd, ID_LS, "FreestyleLineStyle", 1, linestyle); + writestruct(wd, ID_LS, FreestyleLineStyle, 1, linestyle); write_iddata(wd, &linestyle->id); if (linestyle->adt) { @@ -3792,11 +3846,11 @@ static void write_linestyles(WriteData *wd, ListBase *idbase) write_linestyle_geometry_modifiers(wd, &linestyle->geometry_modifiers); for (a = 0; a < MAX_MTEX; a++) { if (linestyle->mtex[a]) { - writestruct(wd, DATA, "MTex", 1, linestyle->mtex[a]); + writestruct(wd, DATA, MTex, 1, linestyle->mtex[a]); } } if (linestyle->nodetree) { - writestruct(wd, DATA, "bNodeTree", 1, linestyle->nodetree); + writestruct(wd, DATA, bNodeTree, 1, linestyle->nodetree); write_nodetree(wd, linestyle->nodetree); } } @@ -3838,12 +3892,12 @@ static void write_libraries(WriteData *wd, Main *main) /* XXX needs rethink, just like save UI in undo files now - would be nice to append things only for the] * quit.blend and temp saves */ if (found_one) { - writestruct(wd, ID_LI, "Library", 1, main->curlib); + writestruct(wd, ID_LI, Library, 1, main->curlib); write_iddata(wd, &main->curlib->id); if (main->curlib->packedfile) { PackedFile *pf = main->curlib->packedfile; - writestruct(wd, DATA, "PackedFile", 1, pf); + writestruct(wd, DATA, PackedFile, 1, pf); writedata(wd, DATA, pf->size, pf->data); if (wd->current == NULL) { printf("write packed .blend: %s\n", main->curlib->name); @@ -3858,7 +3912,7 @@ static void write_libraries(WriteData *wd, Main *main) "but is flagged as directly linked", id->name, main->curlib->filepath); BLI_assert(0); } - writestruct(wd, ID_ID, "ID", 1, id); + writestruct(wd, ID_ID, ID, 1, id); } } } @@ -3910,7 +3964,7 @@ static void write_global(WriteData *wd, int fileflags, Main *mainvar) fg.build_commit_timestamp = 0; BLI_strncpy(fg.build_hash, "unknown", sizeof(fg.build_hash)); #endif - writestruct(wd, GLOB, "FileGlobal", 1, &fg); + writestruct(wd, GLOB, FileGlobal, 1, &fg); } /* preview image, first 2 values are width and height diff --git a/source/blender/makesdna/intern/CMakeLists.txt b/source/blender/makesdna/intern/CMakeLists.txt index b4ada7ffbf1..0bb6e866bf4 100644 --- a/source/blender/makesdna/intern/CMakeLists.txt +++ b/source/blender/makesdna/intern/CMakeLists.txt @@ -56,8 +56,14 @@ add_executable(makesdna ${SRC} ${SRC_DNA_INC}) # Output dna.c add_custom_command( - OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/dna.c - COMMAND "$<TARGET_FILE:makesdna>" ${CMAKE_CURRENT_BINARY_DIR}/dna.c ${CMAKE_SOURCE_DIR}/source/blender/makesdna/ + OUTPUT + ${CMAKE_CURRENT_BINARY_DIR}/dna.c + ${CMAKE_CURRENT_BINARY_DIR}/dna_type_offsets.h + COMMAND + "$<TARGET_FILE:makesdna>" + ${CMAKE_CURRENT_BINARY_DIR}/dna.c + ${CMAKE_CURRENT_BINARY_DIR}/dna_type_offsets.h + ${CMAKE_SOURCE_DIR}/source/blender/makesdna/ DEPENDS makesdna ) @@ -78,7 +84,11 @@ set(SRC ${SRC_DNA_INC} ) -set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/dna.c PROPERTIES GENERATED TRUE) +set_source_files_properties( + ${CMAKE_CURRENT_BINARY_DIR}/dna.c + ${CMAKE_CURRENT_BINARY_DIR}/dna_type_offsets.h + PROPERTIES GENERATED TRUE +) blender_add_lib(bf_dna "${SRC}" "${INC}" "${INC_SYS}") diff --git a/source/blender/makesdna/intern/makesdna.c b/source/blender/makesdna/intern/makesdna.c index fc94a8d9ff4..b78299316e1 100644 --- a/source/blender/makesdna/intern/makesdna.c +++ b/source/blender/makesdna/intern/makesdna.c @@ -968,7 +968,7 @@ void printStructLengths(void) } -static int make_structDNA(const char *baseDirectory, FILE *file) +static int make_structDNA(const char *baseDirectory, FILE *file, FILE *file_offsets) { int len, i; const short *sp; @@ -1159,6 +1159,19 @@ static int make_structDNA(const char *baseDirectory, FILE *file) /* end end padding test */ } + /* write a simple enum with all structs offsets, + * should only be accessed via SDNA_TYPE_FROM_STRUCT macro */ + { + fprintf(file_offsets, "#define SDNA_TYPE_FROM_STRUCT(id) _SDNA_TYPE_##id\n"); + fprintf(file_offsets, "enum {\n"); + for (i = 0; i < nr_structs; i++) { + const short *structpoin = structs[i]; + const int structtype = structpoin[0]; + fprintf(file_offsets, "\t_SDNA_TYPE_%s = %d,\n", types[structtype], i); + } + fprintf(file_offsets, "\tSDNA_TYPE_MAX = %d,\n", nr_structs); + fprintf(file_offsets, "};\n"); + } MEM_freeN(namedata); MEM_freeN(typedata); @@ -1190,43 +1203,53 @@ static void make_bad_file(const char *file, int line) int main(int argc, char **argv) { - FILE *file; int return_status = 0; - if (argc != 2 && argc != 3) { - printf("Usage: %s outfile.c [base directory]\n", argv[0]); + if (argc != 3 && argc != 4) { + printf("Usage: %s dna.c dna_struct_offsets.h [base directory]\n", argv[0]); return_status = 1; } else { - file = fopen(argv[1], "w"); - if (!file) { + FILE *file_dna = fopen(argv[1], "w"); + FILE *file_dna_offsets = fopen(argv[2], "w"); + if (!file_dna) { printf("Unable to open file: %s\n", argv[1]); return_status = 1; } + else if (!file_dna_offsets) { + printf("Unable to open file: %s\n", argv[2]); + return_status = 1; + } else { const char *baseDirectory; - if (argc == 3) { - baseDirectory = argv[2]; + if (argc == 4) { + baseDirectory = argv[3]; } else { baseDirectory = BASE_HEADER; } - fprintf(file, "const unsigned char DNAstr[] = {\n"); - if (make_structDNA(baseDirectory, file)) { + fprintf(file_dna, "const unsigned char DNAstr[] = {\n"); + if (make_structDNA(baseDirectory, file_dna, file_dna_offsets)) { /* error */ - fclose(file); + fclose(file_dna); + file_dna = NULL; make_bad_file(argv[1], __LINE__); return_status = 1; } else { - fprintf(file, "};\n"); - fprintf(file, "const int DNAlen = sizeof(DNAstr);\n"); - - fclose(file); + fprintf(file_dna, "};\n"); + fprintf(file_dna, "const int DNAlen = sizeof(DNAstr);\n"); } } + + if (file_dna) { + fclose(file_dna); + } + if (file_dna_offsets) { + fclose(file_dna_offsets); + } } |