This patch supports renaming structs and struct members in DNA.
Motivation
Over time Blender's internal struct names and their members get out of sync with whats used in the interface, some of the examples include SpaceOops (for the outliner), SpaceButs (properties editor).
In some cases its just a bit confusing, other times its misleading and makes the code hard to follow. It also means developers have to remember two names for the same thing.
Other examples:
Struct members: - Object.size -> scale - Object.dupli_ofs -> instance_offset - Camera.YF_dofdist -> dof_dist; Structs: - Lamp -> Light - SpaceOops -> SpaceOutliner - SpaceButs -> SpaceProperties
Implementation
This patch supports reading old SDNA with renamed fields, by patching them on load.
Unlike do_versions in readfile.c, version information is stored in an array, with the first two members being the version, subversion used to check if updates are needed.
/* Struct rename. */ DNA_sdna_patch_struct("StructNameOld", "StructNameNew"); /* Struct member rename. */ DNA_sdna_patch_struct_member("Struct", "member_old", "member_new");
Leading/trailing characters are accounted for, so you don't need to include pointer or array sizes, just the name, so PreviewImage's unsigned int *rect[2] can be renamed to unsigned int *image_data[2] with:
DNA_sdna_patch_struct_member("PreviewImage", "rect", "image_data")
It does, of course - mean loading these files in older Blender versions wont work (the values will be cleared, in some cases this will fail gracefully, in others not, so this will influence what we choose to rename).
Testing
Some things tested to work.
- Rename UserDef to bPreferences.
- Rename Object.size to Object.scale
- Rename PreviewImage.rect to PreviewImage.image_data (not a full check, just to see the renaming arrays and pointers properly converts the name).
- Updating old 2.8x files (already in this patch, try this old 2.8x file which runs the 2.8x view layer changes ).
Open Topics
Accessing Sub-Version from DNA
Getting the subversion from the Blend file isn't so simple because this is stored in FileGlobal currently this is read from the structure without decoding since it has been the first member since 2.43 (added a static assert to ensure it's always the case). This means we can't read the subversion from older files but I don't think we'll need this anyway.
When to Rename?
Suggest only major releases, if there are breakages in forward compatibility.
Support for opening 2.8x files in 2.7x is already limited, so while it shouldn't crash, loosing some settings is acceptable (Camera.YF_dofdist for eg).
Note that this isn't that extreme given that objects currently don't show up at all.
For future 2.8x releases we'll limit renaming since to cases that wont break forward compatibility since its useful to be able to test on older point releases.
We could be less struct with user preferences since users generally don't load new preferences in older versions of blender.