DNA: support renaming structs that use the old renaming hack
This commit is contained in:
@@ -384,34 +384,8 @@ static bool init_structDNA(
|
||||
|
||||
cp = (char *)data;
|
||||
for (int nr = 0; nr < sdna->nr_types; nr++) {
|
||||
sdna->types[nr] = cp;
|
||||
|
||||
/* ------------------------------------------------------------- */
|
||||
/* WARNING!
|
||||
*
|
||||
* The renaming here isn't complete, references to the old struct names
|
||||
* are still included in DNA, now fixing these struct names properly
|
||||
* breaks forward compatibility. Leave these as-is, but don't add to them!
|
||||
* See D4342#98780 */
|
||||
|
||||
/* this is a patch, to change struct names without a conflict with SDNA */
|
||||
/* be careful to use it, in this case for a system-struct (opengl/X) */
|
||||
|
||||
/* struct Screen was already used by X,
|
||||
* 'bScreen' replaces the old IrisGL 'Screen' struct */
|
||||
if (strcmp("bScreen", cp) == 0) {
|
||||
sdna->types[nr] = cp + 1;
|
||||
}
|
||||
/* Groups renamed to collections in 2.8 */
|
||||
else if (strcmp("Collection", cp) == 0) {
|
||||
sdna->types[nr] = "Group";
|
||||
}
|
||||
else if (strcmp("CollectionObject", cp) == 0) {
|
||||
sdna->types[nr] = "GroupObject";
|
||||
}
|
||||
/* END WARNING */
|
||||
/* ------------------------------------------------------------- */
|
||||
|
||||
/* WARNING! See: DNA_struct_rename_legacy_hack_static_from_alias docs. */
|
||||
sdna->types[nr] = DNA_struct_rename_legacy_hack_static_from_alias(cp);
|
||||
while (*cp) cp++;
|
||||
cp++;
|
||||
}
|
||||
@@ -1530,6 +1504,9 @@ static const char *dna_sdna_alias_alias_from_static_elem_full(
|
||||
|
||||
void DNA_sdna_alias_data_ensure(SDNA *sdna)
|
||||
{
|
||||
/* We may want this to be optional later. */
|
||||
const bool use_legacy_hack = true;
|
||||
|
||||
if (sdna->mem_arena == NULL) {
|
||||
sdna->mem_arena = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, __func__);
|
||||
}
|
||||
@@ -1546,9 +1523,14 @@ void DNA_sdna_alias_data_ensure(SDNA *sdna)
|
||||
if (sdna->alias.types == NULL) {
|
||||
sdna->alias.types = MEM_mallocN(sizeof(*sdna->alias.types) * sdna->nr_types, __func__);
|
||||
for (int type_nr = 0; type_nr < sdna->nr_types; type_nr++) {
|
||||
const char *str = sdna->types[type_nr];
|
||||
const char *struct_name_static = sdna->types[type_nr];
|
||||
|
||||
if (use_legacy_hack) {
|
||||
struct_name_static = DNA_struct_rename_legacy_hack_alias_from_static(struct_name_static);
|
||||
}
|
||||
|
||||
sdna->alias.types[type_nr] = BLI_ghash_lookup_default(
|
||||
struct_map_alias_from_static, str, (void *)str);
|
||||
struct_map_alias_from_static, struct_name_static, (void *)struct_name_static);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1558,6 +1540,11 @@ void DNA_sdna_alias_data_ensure(SDNA *sdna)
|
||||
for (int struct_nr = 0; struct_nr < sdna->nr_structs; struct_nr++) {
|
||||
const short *sp = sdna->structs[struct_nr];
|
||||
const char *struct_name_static = sdna->types[sp[0]];
|
||||
|
||||
if (use_legacy_hack) {
|
||||
struct_name_static = DNA_struct_rename_legacy_hack_alias_from_static(struct_name_static);
|
||||
}
|
||||
|
||||
const int dna_struct_names_len = sp[1];
|
||||
sp += 2;
|
||||
for (int a = 0; a < dna_struct_names_len; a++, sp += 2) {
|
||||
|
||||
@@ -281,3 +281,52 @@ void DNA_alias_maps(
|
||||
#undef DNA_MAKESDNA
|
||||
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name Struct Name Legacy Hack
|
||||
* \{ */
|
||||
|
||||
/**
|
||||
* DNA Compatibility Hack
|
||||
* ======================
|
||||
*
|
||||
* Only keep this for compatibility: **NEVER ADD NEW STRINGS HERE**.
|
||||
*
|
||||
* The renaming here isn't complete, references to the old struct names
|
||||
* are still included in DNA, now fixing these struct names properly
|
||||
* breaks forward compatibility. Leave these as-is, but don't add to them!
|
||||
* See D4342#98780
|
||||
*/
|
||||
const char *DNA_struct_rename_legacy_hack_static_from_alias(const char *name)
|
||||
{
|
||||
/* 'bScreen' replaces the old IrisGL 'Screen' struct */
|
||||
if (STREQ("bScreen", name)) {
|
||||
return "Screen";
|
||||
}
|
||||
/* Groups renamed to collections in 2.8 */
|
||||
if (STREQ("Collection", name)) {
|
||||
return "Group";
|
||||
}
|
||||
if (STREQ("CollectionObject", name)) {
|
||||
return "GroupObject";
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
const char *DNA_struct_rename_legacy_hack_alias_from_static(const char *name)
|
||||
{
|
||||
/* 'bScreen' replaces the old IrisGL 'Screen' struct */
|
||||
if (STREQ("Screen", name)) {
|
||||
return "bScreen";
|
||||
}
|
||||
/* Groups renamed to collections in 2.8 */
|
||||
if (STREQ("Group", name)) {
|
||||
return "Collection";
|
||||
}
|
||||
if (STREQ("GroupObject", name)) {
|
||||
return "CollectionObject";
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
@@ -50,4 +50,7 @@ void DNA_alias_maps(
|
||||
enum eDNA_RenameDir version_dir,
|
||||
struct GHash **r_struct_map, struct GHash **r_elem_map);
|
||||
|
||||
const char *DNA_struct_rename_legacy_hack_alias_from_static(const char *name);
|
||||
const char *DNA_struct_rename_legacy_hack_static_from_alias(const char *name);
|
||||
|
||||
#endif /* __DNA_UTILS_H__ */
|
||||
|
||||
@@ -303,8 +303,6 @@ void RNA_def_collections(BlenderRNA *brna)
|
||||
PropertyRNA *prop;
|
||||
|
||||
srna = RNA_def_struct(brna, "Collection", "ID");
|
||||
/* XXX: CAN WE RENAME TO Collection? */
|
||||
RNA_def_struct_sdna(srna, "Group"); /* it is actually Collection but for 2.8 the dna is patched! */
|
||||
RNA_def_struct_ui_text(srna, "Collection", "Collection of Object data-blocks");
|
||||
RNA_def_struct_ui_icon(srna, ICON_GROUP);
|
||||
/* this is done on save/load in readfile.c, removed if no objects are in the collection and not in a scene */
|
||||
|
||||
@@ -172,6 +172,20 @@ static void rna_brna_structs_remove_and_free(BlenderRNA *brna, StructRNA *srna)
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
static int DNA_struct_find_nr_wrapper(const struct SDNA *sdna, const char *struct_name)
|
||||
{
|
||||
struct_name = DNA_struct_rename_legacy_hack_static_from_alias(struct_name);
|
||||
#ifdef RNA_RUNTIME
|
||||
/* We may support this at some point but for now we don't. */
|
||||
BLI_assert(0);
|
||||
#else
|
||||
struct_name = BLI_ghash_lookup_default(
|
||||
g_version_data.struct_map_static_from_alias, struct_name, (void *)struct_name);
|
||||
#endif
|
||||
return DNA_struct_find_nr(sdna, struct_name);
|
||||
}
|
||||
|
||||
StructDefRNA *rna_find_struct_def(StructRNA *srna)
|
||||
{
|
||||
StructDefRNA *dsrna;
|
||||
@@ -368,18 +382,7 @@ static int rna_find_sdna_member(SDNA *sdna, const char *structname, const char *
|
||||
CLOG_ERROR(&LOG, "only during preprocessing.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifndef RNA_RUNTIME
|
||||
{
|
||||
const char *structname_maybe_static = BLI_ghash_lookup_default(
|
||||
g_version_data.struct_map_static_from_alias, structname, (void *)structname);
|
||||
structnr = DNA_struct_find_nr(sdna, structname_maybe_static);
|
||||
}
|
||||
#else
|
||||
/* Quiet warning only, this is only for the proprocessor. */
|
||||
BLI_assert(0);
|
||||
structnr = -1;
|
||||
#endif
|
||||
structnr = DNA_struct_find_nr_wrapper(sdna, structname);
|
||||
|
||||
if (structnr == -1)
|
||||
return 0;
|
||||
@@ -926,7 +929,7 @@ void RNA_def_struct_sdna(StructRNA *srna, const char *structname)
|
||||
/* there are far too many structs which initialize without valid DNA struct names,
|
||||
* this can't be checked without adding an option to disable (tested this and it means changes all over - Campbell) */
|
||||
#if 0
|
||||
if (DNA_struct_find_nr(DefRNA.sdna, structname) == -1) {
|
||||
if (DNA_struct_find_nr_wrapper(DefRNA.sdna, structname) == -1) {
|
||||
if (!DefRNA.silent) {
|
||||
CLOG_ERROR(&LOG, "%s not found.", structname);
|
||||
DefRNA.error = 1;
|
||||
@@ -954,7 +957,7 @@ void RNA_def_struct_sdna_from(StructRNA *srna, const char *structname, const cha
|
||||
return;
|
||||
}
|
||||
|
||||
if (DNA_struct_find_nr(DefRNA.sdna, structname) == -1) {
|
||||
if (DNA_struct_find_nr_wrapper(DefRNA.sdna, structname) == -1) {
|
||||
if (!DefRNA.silent) {
|
||||
CLOG_ERROR(&LOG, "%s not found.", structname);
|
||||
DefRNA.error = 1;
|
||||
|
||||
Reference in New Issue
Block a user