Changeset View
Changeset View
Standalone View
Standalone View
source/blender/makesdna/intern/dna_defaults.c
| Show All 13 Lines | |||||
| * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
| * | * | ||||
| * DNA default value access. | * DNA default value access. | ||||
| */ | */ | ||||
| /** \file | /** \file | ||||
| * \ingroup DNA | * \ingroup DNA | ||||
| * | * | ||||
| * DNA Defaults | |||||
| * ============ | |||||
| * | |||||
| * This API provides direct access to DNA default structs | * This API provides direct access to DNA default structs | ||||
| * to avoid duplicating values for initialization, versioning and RNA. | * to avoid duplicating values for initialization, versioning and RNA. | ||||
| * This allows DNA default definitions to be defined in a single header along side the types. | * This allows DNA default definitions to be defined in a single header along side the types. | ||||
| * So each `DNA_{name}_types.h` can have an optional `DNA_{name}_defaults.h` file along side it. | * So each `DNA_{name}_types.h` can have an optional `DNA_{name}_defaults.h` file along side it. | ||||
| * | * | ||||
| * Defining the defaults is optional since it doesn't make sense for some structs to have defaults. | * Defining the defaults is optional since it doesn't make sense for some structs to have defaults. | ||||
| * | * | ||||
| * Adding Defaults | |||||
| * --------------- | |||||
| * | |||||
| * Adding/removing defaults for existing structs can be done by hand. | |||||
| * When adding new defaults for larger structs you may want to write-out the in-memory data. | |||||
| * | |||||
| * To create these defaults there is a GDB script which can be handy to get started: | * To create these defaults there is a GDB script which can be handy to get started: | ||||
| * `./source/tools/utils/gdb_struct_repr_c99.py` | * `./source/tools/utils/gdb_struct_repr_c99.py` | ||||
| * | * | ||||
| * Magic numbers should be replaced with flags before committing. | * Magic numbers should be replaced with flags before committing. | ||||
| * | * | ||||
| * Public API | |||||
| * ---------- | |||||
| * | |||||
| * The main functions to access these are: | * The main functions to access these are: | ||||
| * - #DNA_struct_default_get | * - #DNA_struct_default_get | ||||
| * - #DNA_struct_default_alloc | * - #DNA_struct_default_alloc | ||||
| * | * | ||||
| * These access the struct table #DNA_default_table using the struct number. | * These access the struct table #DNA_default_table using the struct number. | ||||
| * | * | ||||
| * \note Struct members only define their members (pointers are left as NULL set). | * \note Struct members only define their members (pointers are left as NULL set). | ||||
| * | |||||
| * Typical Usage | |||||
| * ------------- | |||||
| * | |||||
| * While there is no restriction for using these defaults, | |||||
| * it's worth noting where these functions are typically used: | |||||
| * | |||||
| * - When creating/allocating new data. | |||||
| * - RNA property defaults, used for "Set Default Value" in the buttons right-click context menu. | |||||
| * | |||||
| * These defaults are not used: | |||||
| * | |||||
| * - When loading old files that don't contain newly added struct members (these will be zeroed) | |||||
| * to set their values use `versioning_{BLENDER_VERSION}.c` source files. | |||||
| * - For startup file data, to update these defaults use | |||||
| * #BLO_update_defaults_startup_blend & #BLO_version_defaults_userpref_blend. | |||||
| */ | */ | ||||
| #include <limits.h> | #include <limits.h> | ||||
| #include <stdio.h> | #include <stdio.h> | ||||
| #include <stdlib.h> | #include <stdlib.h> | ||||
| #include <string.h> | #include <string.h> | ||||
| #include "MEM_guardedalloc.h" | #include "MEM_guardedalloc.h" | ||||
| ▲ Show 20 Lines • Show All 257 Lines • Show Last 20 Lines | |||||