Page MenuHome

Refactor ID types code/handling to use an `ID_type` structure, with callbacks for common generic ID management (creation, copy, delete, etc.).
Closed, ResolvedPublicDESIGN


General Idea

We want to have some sort of ID_type structure, similar to what we have for e.g. modifiers or constraints.

This structure would mainly contain:

  • ID info data, like name, UI name, plural name, etc.
    • note: this is mostly handled in BKE_idcode currently.
  • Callbacks for common ID operations (create, copy, delete, make local, etc.)
    • note: those are mostly scattered in each ID type BKE's code currently, and called from BKE_lib API through switch/case pattern.


See D6966 and rBc328049535a4 for the initial implementation, including 'demo' for the ID_OB object type.

To add a new IDTypeInfo you need to:

  1. Define the IDTypeInfo in the relevant BKE's implementation file (e.g. mesh.c for ID_ME, etc.).
    1. Please put the static callbacks and then the IDTypeInfo struct definition at the start of those files.
      1. If you need extra helpers, put only their forward declaration there, and implement them below the IDTypeInfo definition. This allows for a consistent clear separation between common info and specific APIs for each ID type implementation file.
    2. The callbacks should basically be moving around code from existing BKE_XXX_copy_data(), BKE_XXX_init() etc. functions. Those existing functions become therefore wrappers around the static callbacks as well (and shall be removed in later cleanup steps).
    3. The IDTypeInfo should be named from its idcode (e.g. IDType_ID_OB for object).
  2. Add the extern declaration of the new IDType in BKE_idtype.h.
  3. Register the new IDType in id_type_init() of idtype.c.

Tasks for Cleanup Friday

Now we have to create those for all remaining ID types. Please put your name in the list below for IDTypes you want to handle (I already reserved the oddballs ones I suspect to be the trickiest ;) ).

Event Timeline

Bastien Montagne (mont29) changed the task status from Needs Triage to Confirmed.Feb 10 2020, 5:41 PM
Bastien Montagne (mont29) created this task.
Bastien Montagne (mont29) changed the subtype of this task from "Report" to "Design".
Bastien Montagne (mont29) closed this task as Resolved.Mar 9 2020, 6:10 PM
Bastien Montagne (mont29) claimed this task.
Bastien Montagne (mont29) updated the task description. (Show Details)

I guess we need a follow-up task for:

  • Removing switches which only have BLI_assert(0)
  • Make BKE_id_swap and BKE_libblock_get_alloc_info generic
  • Folding idcode.c into idtype.c
  • Moving code from lib_query.c to the various ID types

Yes indeed (already removed the relevant switch/case btw, just have to commit this).

Will handle creating new tasks in comming days.