Commit Graph

53 Commits

Author SHA1 Message Date
Bastien Montagne
f6a9f082e9 Core: Add data-level support for new 'system IDprops' storage for Blender 4.5 forward compatibility with 5.0 blendfiles
This mainly adds DNA level IDProp storage for system properties, their
handling in data management code, and the forward-versioning code
copying back content from system properties into 'all-in-one' single
IDProperties storage, for data types that will support both in Blender
5.0.

There is no user-facing changes expected here.

Part of #123232.

Pull Request: https://projects.blender.org/blender/blender/pulls/139257
2025-06-06 11:49:54 +02:00
Campbell Barton
c90e8bae0b Cleanup: spelling in comments & replace some use of single quotes
Previously spell checker ignored text in single quotes however this
meant incorrect spelling was ignored in text where it shouldn't have
been.

In cases single quotes were used for literal strings
(such as variables, code & compiler flags),
replace these with back-ticks.

In cases they were used for UI labels,
replace these with double quotes.

In cases they were used to reference symbols,
replace them with doxygens symbol link syntax (leading hash).

Apply some spelling corrections & tweaks (for check_spelling_* targets).
2025-04-26 11:17:13 +00:00
Campbell Barton
720b00ae50 Cleanup: use doxygen comments in BKE, consistent comment blocks
Also remove doxygen comment use for comments in the functions body.
2025-04-22 06:13:33 +00:00
Jacques Lucke
374604f188 Refactor: Core: simplify accessing ListBases in Main
This replaces the `set_listbasepointers` function with `BKE_main_lists_get`
which returns an array of `ListBase *`. This simplifies the caller a bit. In
some cases, it can be simplifed further by changing the order in which we iterate
over the listbase. For historical reasons, we iterate from the back to front in
most cases but sometimes the order does not matter. I did keep the iteration order
in this patch though, to avoid regressions.

Pull Request: https://projects.blender.org/blender/blender/pulls/134242
2025-02-11 17:46:07 +01:00
Hans Goudey
7d6e098ca1 Cleanup: Remove unused includes in blenkernel
Pull Request: https://projects.blender.org/blender/blender/pulls/133688
2025-01-28 15:27:34 +01:00
Bastien Montagne
90995f6c46 Fix #126310: Recursive ID CleanUp operation wrongly deleting some used IDs.
Broken detection of isolated archipelagos of IDs lead to falsly detecting
some data as unused in some specific cases (when the entry point of the
archipelago was only used within that archipelago, but some other ID in
the archipelago had actual valid users outside of it).
2025-01-27 14:19:25 +01:00
Campbell Barton
dfef060ea4 Cleanup: spelling in comments (make check_spelling_*)
Also use doxy-code blocks for inlined TEX to avoid
them being interpreted as English.
2025-01-02 15:11:17 +11:00
Bastien Montagne
eb8632e71f Fix #132029: Purge can delete actualy used linked Objects.
Work-around the issue until we actually have correct refcounting usage
handling of Objects: For now, consider all linked objects used by
another used ID as used, even if their usercount is null.

NOTE: This _may_ have side-effects on liboverride (especially the resync
process), by leaving more 'unused' data behind. Since these are linked
though, and presumably not instanced in the Scene, this is probably an
acceptable compromise.

Pull Request: https://projects.blender.org/blender/blender/pulls/132076
2024-12-20 11:42:06 +01:00
Sybren A. Stüvel
efd2e762f7 Refactor: Core, give the IDWALK_CB_… enum an explicit name
Give the `IDWALK_CB_…` enum an explicit name:
`LibraryForeachIDCallbackFlag`. This way the flags are type-safe, and
it's known where values come from. This is much preferred (at least by
me) to just having `int flags`.

Uses of `0` have been replaced with `IDWALK_CB_NOP` as that has the same
value and is of the right type.

One invalid use of `IDWALK_NOP` was detected by this change, and is
replaced by `IDWALK_CB_NOP`.

This change might be incomplete; I gave the enum a name, fixed the
compiler errors, and then also updated assignments like `int cb_flag =
cb_data->cb_flag`. I might have missed some assignments to `int` though.

No functional changes.

Pull Request: https://projects.blender.org/blender/blender/pulls/131865
2024-12-13 17:32:24 +01:00
Sybren A. Stüvel
8dd1eb4e8f Refactor: Core, give the IDWALK_… enum an explicit name
Give the `IDWALK_…` enum an explicit name: `LibraryForeachIDFlag`. This way
the flags are type-safe, and it's known where values come from. This is
much preferred (at least by me) to just having `int flags`.

Uses of `0` have been replaced with `IDWALK_NOP` as that has the same value
and is of the right type.

One invalid use of `IDWALK_CB_NOP` was detected by this change, and is
replaced by `IDWALK_NOP`.

This change might be incomplete; I gave the enum a name, and then fixed
the compiler errors.

No functional changes.

Pull Request: https://projects.blender.org/blender/blender/pulls/131865
2024-12-13 17:32:24 +01:00
Sybren A. Stüvel
7d5143e94c Revert "Refactor: Core, give the IDWALK_… enums an explicit name"
This reverts commit 3ef748789d. It was
landed too hastily, my apologies.

Pull Request: https://projects.blender.org/blender/blender/pulls/131813
2024-12-12 20:03:27 +01:00
Sybren A. Stüvel
3ef748789d Refactor: Core, give the IDWALK_… enums an explicit name
Two commits that basically do the same thing for two `enum`s: give
them a name.

- the `IDWALK_…` enum → `LibraryForeachIDFlag`.
- the `IDWALK_CB_…` enum → `LibraryForeachIDCallbackFlag`.

This way the flags are type-safe, and it's known where values come
from. This is much preferred (at least by me) to just having `int
flags`.

Uses of `0` have been replaced with `IDWALK_NOP` and `IDWALK_CB_NOP`,
as those have the same value and are of the right type.

One invalid use of `IDWALK_NOP` was detected by this change, and is
replaced by `IDWALK_CB_NOP`. And another one in the opposite
direction.

This change might be incomplete; I gave the enum a name, fixed the
compiler errors, and then also updated assignments like `int cb_flag =
cb_data->cb_flag`. I might have missed some assignments to `int`
though.

No functional changes.

----------

I intend to land this PR as its two separate commits. I just put them in the same PR so the buildbot can handle them in one go, and we don't have a stack of highly relatled PRs.

In the future this could also apply to the `IDWALK_RET_…` enum. This one I left out, though, because a proper cleanup there would also have to include their ambiguity on whether they are bitflags (like the enums in this PR) or not. Their values and the code in `BKE_lib_query_foreachid_process()` implies they are bitflags, but in practice they are never or'ed together and just used as discrete values.

Pull Request: https://projects.blender.org/blender/blender/pulls/131803
2024-12-12 17:28:28 +01:00
Jacques Lucke
1d39bb4c80 Core: remove leftover IDOverrideLibrary
This is a leftover from an earlier version of overrides, but is effectively dead
code currently. It was used when there were proportional diffing capabilities.
However, Bastien mentioned that this would be implemented differently nowadays
anyway if it becomes necessary again.

This simplifies the write ID loop quite significantly.

Pull Request: https://projects.blender.org/blender/blender/pulls/130928
2024-11-26 16:09:59 +01:00
Campbell Barton
b302f37952 Cleanup: remove/comment unused struct members & variables 2024-09-22 18:25:40 +10:00
Iliya Katueshenock
1b67be14c6 Cleanup: BKE: Nodes: Functions renaming
Use snake style naming for all the kernel nodes functions.
Omit kernel prefix in the names since of the using namespace.
Use full forms of the terms
('iter' -> 'iterator', 'ntree' -> 'node_tree', 'rem' -> 'remove', ...).

Pull Request: https://projects.blender.org/blender/blender/pulls/126416
2024-08-19 20:27:37 +02:00
Jacques Lucke
5861b078f7 Core: rename ID.flag and ID.tag values
Previously, values for `ID.flag` and `ID.tag` used the prefixes `LIB_` and
`LIB_TAG` respectively. This was somewhat confusing because it's not really
related to libraries in general. This patch changes the prefix to `ID_FLAG_` and
`ID_TAG_`. This makes it more obvious what they correspond to, simplifying code.

Pull Request: https://projects.blender.org/blender/blender/pulls/125811
2024-08-07 12:12:17 +02:00
Sybren A. Stüvel
d342f64fa4 Core: add BKE_lib_query_foreachid_process_main_get() function
Add a function to get the `Main *bmain` pointer from a
LibraryForeachIDData struct. Since the struct is opaque to the
`..._foreach_id` functions, a separate function like this is necessary
to get that pointer.

Not used yet, but will be in a followup commit.

Pull Request: https://projects.blender.org/blender/blender/pulls/123187
2024-06-28 14:41:26 +02:00
Bastien Montagne
a50ab48709 Core: Cleanup: foreach_id: document acceptable return values from callbacks.
Essentially, callbacks in non-readonly are never expected to early-abort
the ID usages iteration. Add comments and an assert to ensure this.
2024-06-26 19:11:10 +02:00
Hans Goudey
e14d153edf Cleanup: Formatting 2024-06-24 08:42:07 -04:00
Bastien Montagne
a94798d31c Fix (unreported) assert in recursive 'foreach id' iterating code.
owner ID pointer needs to be reset after initial usage, for the
recursively processed 'children' IDs.
2024-06-24 13:33:21 +02:00
Bastien Montagne
6426de4489 Core: IDManagement: Refactor how 'never unused' IDs are defined.
A few ID types are considered as 'never unused' in Blender (UI related
ones, the Libraries and the Scenes). Local IDs of this type are always
considered as used, even if no other ID links to them.

This was previously fairly weekly defined and implemented (mainly in the
writefile code and the 'tag unused' libquery functions).

This commit formalize this characteristic of ID types by adding a new
`IDTYPE_FLAGS_NEVER_UNUSED` flag, and using this in the few places in
the code that handle unused IDs.
2024-05-24 17:43:22 +02:00
Iliya Katueshenock
75d17b1db5 Cleanup: Move BKE_node to namespace
Move all header file into namespace.
Unnecessary namespaces was removed from implementations file.
Part of forward declarations in header was moved in the top part
of file just to do not have a lot of separate namespaces.

Pull Request: https://projects.blender.org/blender/blender/pulls/121637
2024-05-13 16:07:12 +02:00
Bastien Montagne
36c3504994 BKE lib_query: Improve handling of owner ID info for embedded ID.
In previous code, the owner ID info would not be available when
processing an embedded ID in two cases, and was incorrectly set to the
processed (embedded) ID instead:
1. When directly calling `BKE_library_foreach_ID_link` on an embedded ID.
2. When using recursive processing (`IDWALK_RECURSE`).

This commit mostly fixes both cases, by using `BKE_id_owner_get` to find
the owner ID when it is unknown.

There are some caveats here though: in a few specific cases (mainly ID
copying, and depsgraph ID copying), `BKE_library_foreach_ID_link` can be
called on embedded IDs which owner ID is not yet valid. In such case, a
new flag can be used to keep using the previous behavior
(`IDWALK_IGNORE_MISSING_OWNER_ID`).

Fixing the issue with copy code being unaware of the owner ID when
copying an embedded one should also be fixed, but this will be addressed
separately.

Note that as 'side efect', this commit also fixes a matching issue in
the `lib_remap` code, where the `IDRemap.id-owner` pointer would also
wrongly be set to the remapped embedded ID instead of its actual owner.

This change is not expected to have any effect in current codebase.
2024-05-02 17:17:03 +02:00
Bastien Montagne
f933dae207 BKE_lib_query: Add a partial ID usage iterator system.
The idea is to allow iterating over e.g. all ID usages of a node from a
whole nodetree, using the same generic handling as existing 'whole ID'
`foreach_id` code.

This is necessary in some cases wher a sub-data needs to processed
independently from any 'owner ID', e.g. in some copy/paste handling.

This is a pre-requirement for proper fix of nodes copy/paste (see
e.g. #120103).

Pull Request: https://projects.blender.org/blender/blender/pulls/121018
2024-04-28 17:35:02 +02:00
Bastien Montagne
679a05a02c Core: lib_query: Replace raw function pointer by FunctionRef for callback.
Besides using modern code, this also allows to use 'capturing' lambdas
as callbacks here.
2024-04-25 12:38:23 +02:00
Hans Goudey
e0567eadbd Cleanup: Use FunctionRef for IDProperty iteration callback
Avoid the need for a seaprate user_data argument.
2024-03-26 15:39:39 -04:00
Hans Goudey
efee753e8f Cleanup: Move BKE_idprop.h to C++ 2024-03-26 13:07:04 -04:00
Hans Goudey
c8efea42e1 Cleanup: Remove unnecessary braces for container default constructors
These containers (Set, Vector, Map, Span), etc. have default constructors,
making the braces unnecessary for default initialization. Better to depend
on that consistently rather than having braces in some places and not others.
2024-03-07 09:30:23 -05:00
Bastien Montagne
de5451b112 Cleanup: Move BKE_anim_data header to be fully C++. 2024-02-28 11:51:03 +01:00
Bastien Montagne
d5e2d96a8b Fix mistake in todays own LibQuery work (3fdae6e56d).
Forgot to also initialize new filtering callback in internal struct.
Did not cause any issue in practic, since this new feature is not yet used.
2024-02-21 17:25:39 +01:00
Bastien Montagne
3fdae6e56d Core: LibQuery: Add a 'filter' callback to BKE_lib_query_unused_ids Api.
This will allow for more control over which ID should actually be marked
as unused/to be deleted.

Also some general minor cleanups and refactor, most notably:
* Add a constructor to internal `UnusedIDsData` struct, which can
  directly use the public `LibQueryUnusedIDsData` parameters struct.
* Add default values to trivial data in `LibQueryUnusedIDsData`.

No expected behavioral changes in this commit.
2024-02-21 15:01:20 +01:00
Iliya Katueshenock
9e12a675b5 Cleanup: Merge BKE_node.h into BKE_node.hh
Trivial change, just move all the code from `BKE_node.h` to `BKE_node.hh` header top.
No mixing code from different headers or namespace changes. Part of #117773

Pull Request: https://projects.blender.org/blender/blender/pulls/118407
2024-02-19 15:26:10 +01:00
Bastien Montagne
df0efda0d6 Refactor: IDTypeInfo: Add info about 'potentially used IDTypes'.
This data was 'hidden' away in a util in
`lib_query.cc`, which made it hard to discover and keep up-to-date.

However, as shown by e.g. #108407, critical low-level features in ID
management code, such as remapping, now rely on this information being
valid.

Also simplify `BKE_library_id_can_use_filter_id` and
`BKE_library_id_can_use_idtype` to make them more generic, relying on
IDTypeInfo to retrieve IDtype-specific info.

No behavioral changes expected here.
2024-02-15 19:45:10 +01:00
Bastien Montagne
f674e486e1 Merge branch 'blender-v4.1-release' 2024-02-15 18:26:31 +01:00
Bastien Montagne
401a2397db Fix mistake in fix for #108407 (crash on deleting shapekeys).
Own d38824bc02 mistakenly added the 'FILTER_ID_KE' to the list IDTypes
usable by Lights (`ID_LA`) instead of Lattices (`ID_LT`)...

Note that this did not cause any additional issue, but only missed part
of the expected fix.
2024-02-15 18:25:50 +01:00
Bastien Montagne
d2fbfe0ec0 Merge branch 'blender-v4.1-release' 2024-02-13 12:57:50 +01:00
Bastien Montagne
d38824bc02 Fix #108407: Crash on deleting shape key from Blender File view.
`BKE_library_id_can_use_filter_id` was missing the ShapeKey type for
geometry IDs (meshes, legacy curves, and lattices), leading to the
remapping code to fail to do its job when deleting the ShapeKey only.
2024-02-13 12:34:09 +01:00
Bastien Montagne
09a2688684 Refactor BKE_lib_query_unused_ids API.
Add a new `BKE_lib_query_unused_ids_amounts` to query expected amounts
of deleted IDs. This function does not tag IDs in main anymore.

Factorize most parameters (and output data) into a new struct
`LibQueryUnusedIDsData`.

Part of PR https://projects.blender.org/blender/blender/pulls/117304.
2024-02-09 17:01:31 +01:00
Bastien Montagne
af5731ce03 Cleanup: Move BKE_idtype.h to Cpp header BKE_idtype.hh 2024-01-20 19:17:36 +01:00
Hans Goudey
21407901f8 Cleanup: Various clang tidy changes 2024-01-19 12:08:48 -05:00
Bastien Montagne
03c1cc4310 Cleanup: Move BKE_lib_query header to Cpp era. 2024-01-18 12:21:19 +01:00
Hans Goudey
3e76a1a6c2 Cleanup: Move BKE_lib_id.h to C++ 2024-01-15 12:44:14 -05:00
Brecht Van Lommel
d377ef2543 Clang Format: bump to version 17
Along with the 4.1 libraries upgrade, we are bumping the clang-format
version from 8-12 to 17. This affects quite a few files.

If not already the case, you may consider pointing your IDE to the
clang-format binary bundled with the Blender precompiled libraries.
2024-01-03 13:38:14 +01:00
Bastien Montagne
3acb64e7ac BKE_main: move header to be a fully CPP one.
Pull Request: https://projects.blender.org/blender/blender/pulls/115681
2023-12-01 20:38:54 +01:00
Campbell Barton
3b5031f1cb Cleanup: use 'r_' prefix for output arguments, order last
Also clarify some naming.
2023-11-30 10:42:18 +11:00
Campbell Barton
b7f3e0d84e Cleanup: spelling & punctuation in comments
Also remove some unhelpful/redundant comments.
2023-09-14 13:25:24 +10:00
Bastien Montagne
c79642fa98 Core: foreach_id: Do not mutually exclude 'no origpointer access' and 'readonly' flags anymore.
There are actually cases where you do not want to access the original
ID pointers, even though the callback will not modify them. One example
is the incoming generic 'expand' readfile callback, which will replace the
dedicated one for all ID types.

Related to #105134: Removal of readfile's lib_link & expand code.
2023-08-23 16:44:56 +02:00
Bastien Montagne
7a0a406ff8 Core: foreach_id: add optional support for deprecated ID pointers.
This commit adds a new option flag to the lib_query foreach_id code,
which will make deprecated ID pointers to be processed as well.

NOTE: Currently there is no report to the callbakcs about the fact that
it is processing a deprecated ID. This can be easily added later if it
becomes necessary.

Part of implementing #105134: Removal of readfile's lib_link & expand code.
2023-08-22 17:47:57 +02:00
Campbell Barton
e955c94ed3 License Headers: Set copyright to "Blender Authors", add AUTHORS
Listing the "Blender Foundation" as copyright holder implied the Blender
Foundation holds copyright to files which may include work from many
developers.

While keeping copyright on headers makes sense for isolated libraries,
Blender's own code may be refactored or moved between files in a way
that makes the per file copyright holders less meaningful.

Copyright references to the "Blender Foundation" have been replaced with
"Blender Authors", with the exception of `./extern/` since these this
contains libraries which are more isolated, any changed to license
headers there can be handled on a case-by-case basis.

Some directories in `./intern/` have also been excluded:

- `./intern/cycles/` it's own `AUTHORS` file is planned.
- `./intern/opensubdiv/`.

An "AUTHORS" file has been added, using the chromium projects authors
file as a template.

Design task: #110784

Ref !110783.
2023-08-16 00:20:26 +10:00
Bastien Montagne
6a86dd5f34 LibOverride: Add ID pointer to operations over ID pointers.
In RNA collections storing ID references, the name of the collection
item may not always be unique, when several IDs from different libraries
are present.

While rare, this situation can become deadly to liboverride, by causing
random but exponential liboverride hierarchies corruptions.

This has already been alleviated by using preferably both name and index
in items lookup (a05419f18b) and by reducing the risk of name collision
in general between liboverrides and their linked reference (b9becc47de).

This commit goes further, by ensuring that references to items of RNA
collections of IDs stored in liboverride operations become completely
unambiguous. This is achieved by storing an extra pointer to the item's
ID itself, when relevant.

Lookup then requires a complete match `name + ID` to be successful,
which is guaranteed to match at most a single item in the whole RNA
collection (since RNA collection of IDs do not allow duplicates, and
the ID pointer is always unique).

Note that this ID pointer is implemented as an `std::optional` one
(either directly in C++ code, or using an new liboverride operation `flag`
in DNA). This allows to smoothly transition from existing data to the
added ID pointer info (when needed), without needing any dedicated
versioning. This solution also preserves forward compatibility as much
as possible.

It may also provide marginal performances improvements in some cases, as
looking up for ID items in RNA collections will first check for the
ID pointer, which should be faster than a string comparision.

Implements #110421.

Pull Request: https://projects.blender.org/blender/blender/pulls/110773
2023-08-10 12:41:20 +02:00