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

Closed
opened 2020-02-10 17:41:14 +01:00 by Bastien Montagne · 8 comments

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.

Process

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

To add a new IDTypeInfo you need to:

  • Define the IDTypeInfo in the relevant BKE's implementation file (e.g. mesh.c for ID_ME, etc.).
    • Please put the static callbacks and then the IDTypeInfo struct definition at the start of those files.
      • 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.
    • 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).
    • The IDTypeInfo should be named from its idcode (e.g. IDType_ID_OB for object).
  • Add the extern declaration of the new IDType in BKE_idtype.h.

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 ;)).

  • ID_SCE Scene ~~@mont29
  • ID_LI Library ~~@mont29
  • ID_OB Object ~~@mont29
  • ID_ME Mesh ~~@mont29
  • ID_CU Curve ~~@mont29
  • ID_MB MetaBall ~~@mont29
  • ID_MA Material ~~@mont29
  • ID_TE Texture ~~@mont29
  • ID_IM Image ~~@mont29
  • ID_LT Lattice ~~@mont29
  • ID_LA Light ~~@brecht
  • ID_CA Camera ~~@brecht
  • ID_IP Ipo (deprecated) ~~@mont29
  • ID_KE Shape key ~~@mont29
  • ID_WO World ~~@brecht
  • ID_SCR Screen ~~@mont29
  • ID_VF VFont~~@dfelinto
  • ID_TXT Text~~@dfelinto
  • ID_SPK Speaker ~~@mont29
  • ID_SO Sound ~~@mont29
  • ID_GR Group ~~@dfelinto
  • ID_AR Armature @dfelinto
  • ID_AC Action @dfelinto
  • ID_NT NodeTree ~~@mont29
  • ID_BR Brush ~~@mont29
  • ID_PA ParticleSettings ~~@mont29
  • ID_GD Grease Pencil ~~@mont29
  • ID_WM WindowManager ~~@mont29
  • ID_MC MovieClip ~~@mont29
  • ID_MSK Mask ~~@mont29
  • ID_LS FreestyleLineStyle ~~@mont29
  • ID_PAL Palette ~~@mont29
  • ID_PC PaintCurve ~~@mont29
  • ID_CF CacheFile ~~@mont29
  • ID_WS WorkSpace ~~@mont29
  • ID_LP LightProbe ~~@brecht
  • ID_HA Hair ~~@brecht
  • ID_PT PointCloud ~~@brecht
  • ID_VO Volume ~~@brecht
### 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.* ### Process See [D6966](https://archive.blender.org/developer/D6966) and c328049535 for the initial implementation, including 'demo' for the `ID_OB` object type. To add a new IDTypeInfo you need to: - Define the IDTypeInfo in the relevant BKE's implementation file (e.g. `mesh.c` for `ID_ME`, etc.). - Please put the static callbacks and then the IDTypeInfo struct definition at the start of those files. - 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. - 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). - The IDTypeInfo should be named from its idcode (e.g. `IDType_ID_OB` for object). - Add the `extern` declaration of the new IDType in `BKE_idtype.h`. # 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 ;)*). - [x] `ID_SCE` Scene ~~@mont29 - [x] `ID_LI` Library ~~@mont29 - [x] `ID_OB` Object ~~@mont29 - [x] `ID_ME` Mesh ~~@mont29 - [x] `ID_CU` Curve ~~@mont29 - [x] `ID_MB` MetaBall ~~@mont29 - [x] `ID_MA` Material ~~@mont29 - [x] `ID_TE` Texture ~~@mont29 - [x] `ID_IM` Image ~~@mont29 - [x] `ID_LT` Lattice ~~@mont29 - [x] `ID_LA` Light ~~@brecht - [x] `ID_CA` Camera ~~@brecht - [x] `ID_IP` Ipo (deprecated) ~~@mont29 - [x] `ID_KE` Shape key ~~@mont29 - [x] `ID_WO` World ~~@brecht - [x] `ID_SCR` Screen ~~@mont29 - [x] `ID_VF` VFont~~@dfelinto - [x] `ID_TXT` Text~~@dfelinto - [x] `ID_SPK` Speaker ~~@mont29 - [x] `ID_SO` Sound ~~@mont29 - [x] `ID_GR` Group ~~@dfelinto - [x] `ID_AR` Armature @dfelinto - [x] `ID_AC` Action @dfelinto - [x] `ID_NT` NodeTree ~~@mont29 - [x] `ID_BR` Brush ~~@mont29 - [x] `ID_PA` ParticleSettings ~~@mont29 - [x] `ID_GD` Grease Pencil ~~@mont29 - [x] `ID_WM` WindowManager ~~@mont29 - [x] `ID_MC` MovieClip ~~@mont29 - [x] `ID_MSK` Mask ~~@mont29 - [x] `ID_LS` FreestyleLineStyle ~~@mont29 - [x] `ID_PAL` Palette ~~@mont29 - [x] `ID_PC` PaintCurve ~~@mont29 - [x] `ID_CF` CacheFile ~~@mont29 - [x] `ID_WS` WorkSpace ~~@mont29 - [x] `ID_LP` LightProbe ~~@brecht - [x] `ID_HA` Hair ~~@brecht - [x] `ID_PT` PointCloud ~~@brecht - [x] `ID_VO` Volume ~~@brecht
Author
Owner

Changed status from 'Needs Triage' to: 'Confirmed'

Changed status from 'Needs Triage' to: 'Confirmed'
Author
Owner

Added subscriber: @mont29

Added subscriber: @mont29

Added subscriber: @brecht

Added subscriber: @brecht

Added subscriber: @dfelinto

Added subscriber: @dfelinto
Author
Owner

Changed status from 'Confirmed' to: 'Resolved'

Changed status from 'Confirmed' to: 'Resolved'
Bastien Montagne self-assigned this 2020-03-09 18:10:09 +01:00

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
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
Author
Owner

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

Will handle creating new tasks in comming days.

Yes indeed (already removed the relevant switch/case btw, just have to commit this). Will handle creating new tasks in comming days.
Author
Owner

See #74960 for follow-up tasks.

See #74960 for follow-up tasks.
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#73719
No description provided.