ID: Document the steps to properly add a new ID data-block type #15
No reviewers
Labels
No Label
No Milestone
No Assignees
8 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender-developer-docs#15
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "pr/new-id-datablock"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Extend the existing documentation of how to add a new
IDTypeInfo
, so thatit includes all the places in which the new ID datatype has to be added
before Blender truely can work with it.
This is based on what I had to do for the new
Animation
data-blockintroduced in blender/blender#114098.
@ -188,0 +197,4 @@
- `which_libbase()`
- `set_listbasepointers()`
6. `readfile.c`: in `dataname()`
7. `BLT_translation.h`: add a `#define BLT_I18NCONTEXT_ID...` line
BLT_translation.h
: add#define BLT_I18NCONTEXT_ID...
andBLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_..., "id_..."), \
linesI didn't try to render this locally, but rendering this on gitea leads to some inconsistent indentation. Looks like previous lines in this file used 4 spaces for indentation and this is unsing only 2.
@ -188,0 +190,4 @@
- Add a new `case` to `BKE_idtype_idcode_from_index()`
Additionally, there are some other areas in the source code where a reference to
the new type might be added:
might be added
->might be needed
?@ -188,0 +196,4 @@
5. `blenkernel/intern/main.cc`:
- `which_libbase()`
- `set_listbasepointers()`
6. `readfile.c`: in `dataname()`
This is
readfile.cc
now.Thanks for the feedback!
I tried indenting with 4 spaces earlier, but then the nested lists didn't work properly. mkdocs seems to be quite sensitive to the exact amount of whitespace, unfortunately.
I'm wondering if we really want to go into that much detail, this is prone to getting outdated in no time. Then again, it might actually avoid some bugs. (I mean, I hope small documentation edits when changing code will become the norm, but at this point it's not common practice yet.)
Let's get some opinions. @brecht @Sergey what do you think?
Those areas do not change that often, and it is a topic which people keeps running into, and which is easy to make a mistake in. So I think it is ok to have such instruction.
We should also be able to leverage compiler warning much better. For example, ensure we do not silence any unhandled case in a switch statements in the areas where it is important. And by moving more things into the IDType info. For example, it would be great if we can more DEG building logic of various IDs away from the core DEG logic. But that's for the future work, not as part of this PR.
I'd put this on its own page, and maybe at the beginning add some text like.
Shouldn't list of new ID elements be added in bmain structure?
TL;DR:
While getting better documentation about new ID type creation is indeed great, I'm not a big fan of such detailed instructions. The relevant code may not change that often, but imho it changes often enough that keeping this doc up to date with all the specifics will become a challenge. I'd rather have some more generic instructions.
Issues I see in this PR
I find giving a 'complete' recipe to be 'dangerous', in the sense that devs may stop thinking by themselves and just apply it blindly. Especially if there is no structure/explanation about the 'why' of each of these steps.
Further more, it's very hard to ensure that said recipe is actually complete. I do not see a reference to adding a new list of IDs in the Main struct in proposed patch e.g.
Some instructions in the proposed PR also do not belong here imho. E.g. under the RNA category, a lot is actually valid for any RNA editing, and should therefore be documented in the RNA section of the doc. Same goes for the handling of DNA 'default' headers.
Proposal
Like @brecht, I would put forward the fact that the best way to find which code needs to be edited when adding a new ID type is by looking for usages/references to other existing similar ID types (both the
IDType_ID_...
declared inBKE_idtype.hh
, and theID_...
inDNA_ID_enums.h
).As @Sergey noted, a remark about using
IDType
switches (withoutdefault
clause) and the fact that they will raise errors at compile time if one of the enum value is not handled is another nice 'generic' way to find missing handling cases.And I would personally much rather see a list of 'areas of code' that do (or may) need some work, than specific references to files and functions. Maybe organized by 'new ID type creation' tasks, in some form of logical progression (from the most low-level, basic things to do in absolutely all cases, to less critical areas, and things that may be ignored in some cases):
BKE_idtype_idcode_to_idfilter
etc.).ID_Type
itself (DNA_ID_enums.h
);FILTER_ID_
, and add it toFILTER_ID_ALL
(DNA_ID.h
).eID_Index
value (DNA_ID.h
).Main
struct.which_libbase
etc.).BKE_library_id_can_use_filter_id
)deg_builder_relations
anddeg_builder_nodes
.RNA_MAIN_LISTBASE_FUNCS_DEF
to enable the access to the Main's newListBase
by the new RNA collection.RNA_MAIN_ID_TAG_FUNCS_DEF
to enable the tagging of the IDs of the new type.RNA_def_main_
function inrna_main_api
, which defines the basic handling of the new RNA collection (like adding or removing an ID). And the related static functions (note that some functions are generated by macros and do not need to be defined explicitly, e.g. the tagging one throughRNA_MAIN_ID_TAG_FUNCS_DEF
).MainCollectionDef
inRNA_def_main
. It will wrap the matching new ListBase added to the Main struct, with the help of the functions and macro calls above.UI_icons.hh
), updateUI_icon_from_idcode
space_outliner
:TREESTORE_ID_TYPE
.TreeElementID
or some subclass.TreeElementID::create_from_id
at least needs to be updated.TreeElementID
may be defined, in a new set of files (like e.g.tree_element_id_object.hh
/.cc
, etc.).opengl_render.cc
(gather_frames_to_render_for_id
), orinterface_templates.cc
(template_id_browse_tip
).BLT_I18NCONTEXT_ID_
translation context in BLT_translation.dataname()
) (sic)Note that this is still a very rough layout idea, would need to be fleshed out, cleaned up...
PS: blender/blender!117958 should 'fix' the
readfile
case by removing any need to edit it when adding a new ID type.The large number of "oh I had to add something there too" that I had to go through was frustrating and time-consuming. These instructions were born from that frustration. I found the current documentation, of just three steps to add a new
IDTypeInfo
, to be misleading, as once that's done, that ID type is not actually usable in Blender.I think the better approach here is not to avoid this level of detail in documentation, but rather write our software so that there is less entanglement. Having to hunt through basically all of Blender to add yet another "this is the icon for this type" or something similar.
Big note: I'm not blaming anyone, I'm just voicing frustration about the current state of things. Having an
IDTypeInfo
struct was a good idea, and IMO we should look at expanding this system, rather than adding yet moreswitch(GS(id->name))
orELEM(GS(id->name), ID_...)
. Or have some way where "lists of ID-type-dependent things" can be checked against the knownIDTypeInfo
structs, so that at least at runtime (in debug builds) a warning can be emitted that that list is incomplete.I agree that there should be more structure & explanation.
And this is why the code should be better structured & commented in the first place. And why this documentation is essential to have. While writing the code, it's hard to know where to add what, as it's so all over the place. The fact that I didn't catch all places, but things still seem to work, is proof of that. Without this documentation, and a sense of "yeah now I'm done", developers will also at some point stop thinking for themselves, and just look for yet-another-thing-to-add when what they did so far doesn't work.
That's fine by me, that's what we have links for.
I'm fine adding this as some extra documentation, as it's simply good advice. I don't think it can replace a concrete list of places/areas to adjust, though.
💯 but also there are many other places where things need to be added to lists that don't get caught by this.
👍
I'll see how clean I can get ;-)
Removing from own review queue ;)
Checkout
From your project repository, check out a new branch and test the changes.