Page MenuHome

DNA Defaults
AcceptedPublic

Authored by Campbell Barton (campbellbarton) on Mar 12 2019, 11:20 AM.

Details

Summary

This patch adds initial support for DNA defaults,

  • Each DNA struct can optionally have a default struct assigned.
  • If this struct is assigned, it's used for defaults when old files are loaded which either.
    • Don't define the entire struct.
    • Define the struct but don't include a newly added struct member.

      So there is no need to loop over initializing values manually version patching.

This avoids duplicating defaults 2x times (3x once RNA support is added).

This review is mainly to get feedback before spending more time on this and preparing it for inclusion.


Note, this was fun-weekend project, not a priority for 2.8x, nevertheless it could be useful long term.

Diff Detail

Repository
rB Blender
Branch
TEMP-DNA-DEFAULTS-5 (branched from master)
Build Status
Buildable 4848
Build 4848: arc lint + arc unit

Event Timeline

Campbell Barton (campbellbarton) edited the summary of this revision. (Show Details)
Campbell Barton (campbellbarton) edited the summary of this revision. (Show Details)
Campbell Barton (campbellbarton) edited the summary of this revision. (Show Details)

The duplication of defaults would indeed be great to solve, and should simplify versioning nicely.

Maybe it makes sense to have files like DNA_scene_defaults.h next to DNA_scene_types.h?

Also not sure e.g. View3DShading defaults should be defined as nested struct in scene. Seems more clear if we define all struct defaults separately following DNA header organization, even if it's a bit more verbose.

@Brecht Van Lommel (brecht), do you mean to define the structs as macros?

eg:

#define DNA_DEFAULT_View3DCursor { \
    .rotation_mode = ROT_MODE_XYZ, \
    .rotation_quaternion = {1, 0, 0, 0}, \
    .rotation_axis = {0, 1, 0}, \
}

#define DNA_DEFAULT_RenderData { \
    .mode = R_OSA, \
    /* snip */ \
}

#define DNA_DEFAULT_Scene { \
    .cursor = DNA_DEFAULT_View3DCursor, \
    .r = DNA_DEFAULT_RenderData, \
    /* snip */ \
}

Think it can work nicely, it has the advantage that a struct like View3DShading thats used in multiple places can have a single define.

Note that we wouldn't want defines from from DNA_*_defaults.h being instantiated many times - ideally only once for ID types.

Ah, I thought .shading = DNA_Default_View3DShading, would work. Apparently in C++ but not C.

The macro seems like a good trick for structs that are embedded multiple times.

  • Use macros for defaults
  • Merge branch 'master' into TEMP-DNA-DEFAULTS-2

It looks good to me, but would like to see some comments explaining how to use this system.

source/blender/makesdna/intern/dna_defaults.c
45 ↗(On Diff #17964)

Please add a comment in this file explaining how these default data structures work, what to add here and what to add in the table below.

This revision is now accepted and ready to land.Sep 9 2019, 12:00 PM

Merged part of this patch, dna_genfile.c is now the only modified file.