Commit Graph

41 Commits

Author SHA1 Message Date
Bastien Montagne
48e26c3afe MEM_guardedalloc: Refactor to add more type-safety.
The main goal of these changes are to improve static (i.e. build-time)
checks on whether a given data can be allocated and freed with `malloc`
and `free` (C-style), or requires proper C++-style construction and
destruction (`new` and `delete`).

* Add new `MEM_malloc_arrayN_aligned` API.
* Make `MEM_freeN` a template function in C++, which does static assert on
  type triviality.
* Add `MEM_SAFE_DELETE`, similar to `MEM_SAFE_FREE` but calling
  `MEM_delete`.

The changes to `MEM_freeN` was painful and useful, as it allowed to fix a bunch
of invalid calls in existing codebase already.

It also highlighted a fair amount of places where it is called to free incomplete
type pointers, which is likely a sign of badly designed code (there should
rather be an API to destroy and free these data then, if the data type is not fully
publicly exposed). For now, these are 'worked around' by explicitly casting the
freed pointers to `void *` in these cases - which also makes them easy to search for.
Some of these will be addressed separately (see blender/blender!134765).

Finally, MSVC seems to consider structs defining new/delete operators (e.g. by
using the `MEM_CXX_CLASS_ALLOC_FUNCS` macro) as non-trivial. This does not
seem to follow the definition of type triviality, so for now static type checking in
`MEM_freeN` has been disabled for Windows. We'll likely have to do the same
with type-safe `MEM_[cm]allocN` API being worked on in blender/blender!134771

Based on ideas from Brecht in blender/blender!134452

Pull Request: https://projects.blender.org/blender/blender/pulls/134463
2025-02-20 10:37:10 +01:00
Brecht Van Lommel
6458458c07 Merge branch 'blender-v4.4-release' 2025-02-18 19:46:42 +01:00
Brecht Van Lommel
c650977534 Grease Pencil: Make brush asset pinned materials local
Keeping these as linked datablocks to the brush does not match the idea
that assets should generally be appended, and leads to some confusing
situations with linked materials on objects. Now use either a local
material with matching weak library reference or make a local copy if
it does not exist yet.

This also add weak library references to the materials in the 2D Animation
template, so they will be reused.

A problem is that weak library references include a full path to assets
blend files, including the Blender version for the essentials assets files.
This means weak library references do not work across platforms and
Blender versions.

Another known limitation is that if the (linked) Brush Asset material is
edited, and there is already a local copy of it, this local copy will
remain unchanged and will be used by future strokes as well.

Ref #131186

Pull Request: https://projects.blender.org/blender/blender/pulls/134226
2025-02-18 19:46:07 +01:00
Brecht Van Lommel
c7a33a62a2 Cleanup: Directly include DNA_userdef_types.h and BLI_listbase.h
Instead of relying on them being included indirectly.

Pull Request: https://projects.blender.org/blender/blender/pulls/134406
2025-02-12 23:01:08 +01: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
Bastien Montagne
87a4c0d3a8 Refactor: Make Library.runtime an allocated pointer.
Move `Library.runtime` to be a pointer, move the related
`LibraryRuntime` struct to `BKE_library.hh`. Similar to e.g.
Mesh.runtime, that pointer is expected to always be valid, and is
allocated at readtime or when creating a new Library ID.

Related smaller changes:
* Write code now uses standard ID writing codepath for Library IDs too.
  * Runtime pointer is reset to nullptr before writing.
* Looking up a library by its absolute path is now handled through a
  dedicated utils, `search_filepath_abs`, instead of using
  `BLI_findstring`.

Pull Request: https://projects.blender.org/blender/blender/pulls/134188
2025-02-07 17:47:16 +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
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
Campbell Barton
4ec0cce30a WM: improve thumbnail scaling performance (debug builds)
Saving files could take ~3-4 seconds on debug builds because of new
imbuf scaling logic.

Even though debug performance usually isn't much of a consideration,
it gets in the way of development.

Since thumbnails don't require the same accuracy as the sequencer or
compositor, use a faster scaling method that uses a box-filter clamped
to integer bounds & integer math.

In practice the difference between the resulting thumbnails isn't
noticeable in my tests.

For debug build with ASAN this gives a ~25x speedup,
for release builds it gives a ~1.4x speedup which is to be
expected with a more approximate scaling method.
2024-09-16 19:51:32 +10:00
Jacques Lucke
436f4570c2 Cleanup: move weak reference map to C++
This replaces a `GHash` with `Map<LibWeakRefKey, ID *>` which simplifies the code.

Pull Request: https://projects.blender.org/blender/blender/pulls/124519
2024-07-11 18:43:35 +02:00
Julian Eisel
c5180e0988 Assets: Special .asset.blend files, for storing externally editable assets
Introduces a new kind of blend file that store assets that can savely be edited
from the Blender UI, without having to open the blend-file storing the asset
itself (asset "pushing" workflow).

Only brush assets will use this for now.

Technical Documentation:
https://developer.blender.org/docs/features/asset_system/asset_editing/

User Documentation:
https://docs.blender.org/manual/en/latest/files/asset_libraries/introduction.html#asset-system-files-asset-blend-extention

The API to manage assets by generating these files is added in the following
commit.

Main authors: Bastien Montagne, Brecht Van Lommel, Julian Eisel

Pull Request for the latest design iteration:
https://projects.blender.org/blender/blender/pulls/124246

Part of the brush assets project, see:
- https://projects.blender.org/blender/blender/issues/116337
- https://projects.blender.org/blender/blender/pulls/106303
2024-07-08 17:50:24 +02:00
Sybren A. Stüvel
c0364efec0 Refactor: rename 'Action Binding' to 'Action Slot'
Rename 'Binding' to 'Slot'. The old term was causing all kind of
confusion, and 'slot' was considered to be a better term for the
intended functionality.

This commit breaks existing blend files that were using the new layered
Action for their animation. The animation data will be lost due to the
rename, as there is no versioning code or DNA renaming logic. At this
time the new system is still marked as experimental, so shouldn't be
used for anything serious anyway.

Pull Request: https://projects.blender.org/blender/blender/pulls/124170
2024-07-05 17:52:55 +02:00
Bastien Montagne
f1c2a93623 Refactor: Core: BKE_main: init/clear code.
This commit allows to initialize and clear a Main struct which
allocation is handled separately.

There is no behavioral change expected from this commit.

This is a requirement for incoming rewrite of the PartialWrite code
(see #122061 and !122118).

Pull Request: https://projects.blender.org/blender/blender/pulls/122118
2024-07-01 15:26:58 +02:00
Sybren A. Stüvel
c4a7c4e2a1 Anim: add ID* cache of users to Action Bindings
Keep track of which IDs are animated by which Action Binding. This will
be necessary for display in the Action editor, where animation data that
is unrelated to the active object can be shown (when "show all bindings"
is on).

Note: animation evaluation will not be using this cache, at least not in
the near future. Potentially when we introduce animation-level
constraints this will change, but that's for the future.

The user cache isn't actually used in this commit. It will be used soon
in !122672.

Pull Request: https://projects.blender.org/blender/blender/pulls/123187

Pull Request: https://projects.blender.org/blender/blender/pulls/123187
2024-06-28 14:41:27 +02:00
Sybren A. Stüvel
d94a56bdad Anim: merge Animation data-block into bAction
The new/experimental, layered `Animation` data-block is merged with the
existing `bAction` data-block.

The `Animation` data-block is considerably newer than `bAction`, so the
supporting code that was written for it is also more modern. When moving
that code into `bAction`, I chose to keep the modernity where possible,
and thus some of the old code has been updated as well. Things like
preferring references over pointers.

The `Animation` data-block is now gone from DNA, the main database, etc.
As this was still an experimental feature, there is no versioning code
to convert any of that to Actions.

The DNA struct `bAction` now has a C++ wrapper `animrig::Action`, that
can be obtained via `some_action->wrap()`.

`animrig::Action` has functions `is_empty()`, `is_action_legacy()`, and
`is_action_layered()`. They **all** return `true` when the Action is
empty, as in that case none of the data that makes an action either
'legacy' or 'layered' is there.

The 'animation filtering' code (for showing things in the dope sheet,
graph editor, etc) that I wrote for `Animation` is intentionally kept
around. These types now target 'layered actions' and the
already-existing ones 'legacy actions'. A future PR may merge these two
together, but given how much work it was to add something new there, I'd
rather wait until the dust has settled on this commit.

There are plenty of variables (and some comments) named `anim` or
`animation` that now are of type `animrig::Action`. I haven't renamed
them all, to keep the noise level low in this commit (it's already big
enough). This can be done in a followup, non-functional PR.

Related task: #121355

Pull Request: https://projects.blender.org/blender/blender/pulls/121357
2024-05-13 15:58:04 +02:00
Jacques Lucke
936fb7488e Cleanup: move runtime data to Library.runtime
Having a better separation between runtime and non-runtime data makes
it easier to reason about the code.

Pull Request: https://projects.blender.org/blender/blender/pulls/120271
2024-04-08 13:08:36 +02:00
Sybren A. Stüvel
90ef46baa1 Anim: DNA for Animation data-block
Introduce new DNA for the `Animation` data-block and its sub-data.

This includes the blenkernel code for reading & writing to blend files,
and for memory management (freeing, duplicating). Minimal C++ wrappers
are included, with just the functionality needed for blenkernel to do
its job.

The Outliner code is extended so that it knows about the new data-type,
nothing more.

For more info, see issue #113594.

Pull Request: https://projects.blender.org/blender/blender/pulls/119077
2024-03-07 16:41:25 +01:00
Bastien Montagne
5baef63a20 BKE ID remap: Refactor: Remove C API around CPP IDRemapper.
The ID remapper code was already largely defined in a CPP struct
(IDRemapper). Make this an actual class, and remove the C API wrapper
around.

This makes the code cleaner, easier to follow, and easier to extend or
modify in the future.

Pull Request: https://projects.blender.org/blender/blender/pulls/118146
2024-02-13 15:36:38 +01:00
Bastien Montagne
29fe777445 Cleanup: Make BKE_report.h a full Cpp header. 2024-02-10 18:34:29 +01:00
Bastien Montagne
54618dbae3 Cleanup: Make BKE_global.h a Cpp header. 2024-02-10 18:25:14 +01:00
Bastien Montagne
a9b2cf8ce6 Cleanup: Move BKE_path.h to CPP header. 2024-02-09 19:23:03 +01:00
Jacques Lucke
311ca3e6af Core: rename Session UUID to Session UID
`UUID` generally stands for "universally unique identifier". The session identifier that
we use is neither universally unique, nor does it follow the standard. Therefor, the term
"session uuid" is confusing and should be replaced.

In #116888 we briefly talked about a better name and ended up with "session uid".
The reason for "uid" instead of "id" is that the latter is a very overloaded term in Blender
already.

This patch changes all uses of "uuid" to "uid" where it's used in the context of a
"session uid". It's not always trivial to see whether a specific mention of "uuid" refers
to an actual uuid or something else. Therefore, I might have missed some renames.
I can't think of an automated way to differentiate the case.

BMesh also uses the term "uuid" sometimes in a the wrong context (e.g. `UUIDFaceStepItem`)
but there it also does not mean "session uid", so it's *not* changed by this patch.

Pull Request: https://projects.blender.org/blender/blender/pulls/117350
2024-01-22 13:47:13 +01:00
Bastien Montagne
af5731ce03 Cleanup: Move BKE_idtype.h to Cpp header BKE_idtype.hh 2024-01-20 19:17:36 +01:00
Aras Pranckevicius
a705259b4b Cleanup: move imbuf .h files to .hh 2024-01-19 20:29:38 +01: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
Campbell Barton
617f7b76df Cleanup: comment block formatting 2024-01-08 11:31:43 +11: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
Damien Picard
6d70e9b05f UI: fix and improve a few messages
- "Frame Step" -> "Number of frames to skip forward while baking each
  frame": expand description which was just copying the prop name.
- "b-bone" -> "B-Bone": title case.
- "Volumes Lighting" -> "Volume Lighting": typo.
- "Volumes Shadows" -> "Volume Shadows": typo.
- "Insert Blank Keyframe (All Layer)" -> "(All Layers)": typo.
- "the an" -> "an", typo.
- "Inverse" -> "Invert": use verb instead of noun for an action.
- "Desination" -> "Destination": typo.
- "Hides all other F-Curves other than the ones being framed": remove
  extra "other".
- "Remove Bone from Bone collections" -> "Collection", singular because
  the operator is only applied to the active collection. Also title
  case on "Collection".
- "Change Stroke material with selected material" -> "Assign the
  active material slot to the selected strokes": rephrase by reusing
  the message from the non-Grease Pencil materials.
- "VisAction", "VisArea" -> "Visibility Action", "Visibility Area":
  expand abbreviation. This is not exposed in the UI right now but
  will show up in the API docs.
- "Stop Mode Right / Global Down" -> "Stop Move" (typo).
- "... for node input  %s": remove extra space.
- "Move along their normal" -> "Move shadows along their normal":
  rephrase unclear sentence.
- "Stat Vis" -> "Mesh Analysis": stands for "Statistical
  visualization"? Unclear and not shown anywhere. Reuse the label
  specified in the UI code instead.
- " Output data...": remove leading space.
- "Attribute domain for the selection and group id inputs": title case
  on "Selection" and "Group ID" as that is how they appear in the UI.
- "Ior" -> "IOR": uppercase acronym, for consistency.

Pull Request: https://projects.blender.org/blender/blender/pulls/115964
2023-12-11 00:23:03 +01:00
Campbell Barton
497600e49e Cleanup: spelling in comments, strings 2023-12-07 12:45:27 +11:00
Brecht Van Lommel
56cc47ee2e Cleanup: compiler warning 2023-12-04 20:37:11 +01:00
Bastien Montagne
5736f88e31 BKE main: Add 'merge' utils to merge one Main content into another.
This merge does not rename any ID. In case a conflict happens (an ID of
the same name and library already exists in destination Main), its
counterpart in source Main is not moved, and its usages by other
moved-from-source IDs are remapped accordingly.

Libraries are also properly de-duplicated, and remapped as necessary.

Source Main is always freed by this function, since it is either empty,
or contains left-over IDs very likely to have invalid relationships
after the merge.

NOTE: This commit also enables `main_test.cc` unittests, which was
comitted by mistake in fe3cb11ae4, sorry about that.

Pull Request: https://projects.blender.org/blender/blender/pulls/115671
2023-12-02 16:25:02 +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
Bastien Montagne
dad1eea511 Move BKE_main_idmap and BKE_main_namemap to be fully cpp headers.
NOTE: `BKE_main.h` is currently used by `writeffmpeg.c`, so not trivial
to make it a full CPP header file for now.

Pull Request: https://projects.blender.org/blender/blender/pulls/115485
2023-11-27 18:09:27 +01:00
Campbell Barton
ee6b39ae86 Cleanup: always run both FOREACH_MAIN_ID_BEGIN & END macros
Also correct the "END" macro being used in the wrong scope.
2023-09-14 11:46:32 +10:00
Campbell Barton
81ee130063 Cleanup: use C++ system headers
Apply clang-tidy modernize-deprecated-headers to source/
2023-07-22 11:27:25 +10:00
Campbell Barton
17563e9a91 Cleanup: use C++ function style casts, NULL -> nullptr 2023-07-18 14:18:07 +10:00
Jacques Lucke
129f78eee7 Blenkernel: move to C++
Also see #103343.

Couldn't move two files yet:
* `softbody.c`: The corresponding regression test fails. It seems like the
  conversion to C++ changes floating point accuracy, but it's not clear where that happens exactly.
* `writeffmpeg.c`: Is a bit more complex to convert because of the static array in `av_err2str`.

Pull Request: https://projects.blender.org/blender/blender/pulls/110182
2023-07-17 10:46:26 +02:00