Commit Graph

141 Commits

Author SHA1 Message Date
Campbell Barton
b03332a055 Cleanup: use BLI_assert_msg instead of checking string literals 2024-04-03 14:27:54 +11:00
Hans Goudey
f8e8e3ac8c Cleanup: Use utility mixins for AssetRepresentation 2024-03-28 13:43:20 -04:00
Hans Goudey
2d9f19c962 Cleanup: Use std::move for asset identifier construction
Pass strings by value and move their result. This gives the caller
the potential to move existing strings into the class. Moving the
std::shared_ptr should just avoid reference counting here.
2024-03-27 22:31:44 -04:00
Campbell Barton
a2fa743364 Cleanup: pass std::string by reference instead of value 2024-03-28 13:01:39 +11:00
Hans Goudey
6072a641ee Cleanup: A few small tweaks in asset library code
- Fix a typo
- Remove unnecessary namespace specification
- Use "this" to access class methods
2024-03-14 08:49:21 -04:00
Hans Goudey
d8252cdff7 Cleanup: Use "this->" to call class methods 2024-03-07 16:23:35 -05: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
Hans Goudey
d727738157 Cleanup: Comment formatting
Use consistent formatting for multi-line comments.
2024-03-07 09:30:22 -05:00
Julian Eisel
4733b11a8c Cleanup: Make asset catalog ID immutable
There's no need for the catalog ID to change ever with the current
catalog system design. If that changes, a new catalog can probably be
created instead. Avoiding modifications also helps avoiding data races.

Also means the currently unused default constructor becomes unavailable.
2024-03-05 12:26:48 +01:00
Campbell Barton
76867ad4c2 Cleanup: redundant "void" in function declarations for C++ 2024-03-05 11:25:35 +11:00
Campbell Barton
1b514659ca Cleanup: minor changes to temp directory API
- Pass null instead of an empty string to BKE_tempdir_init
  because the string isn't meant to be used.
- Never pass null to BLI_temp_directory_path_copy_if_valid
  (the caller must check).
- Additional comments for which checks are performed & why
  from discussion about #95411.
2024-03-04 11:42:02 +11:00
Hans Goudey
b9fb51eaed Cleanup: Make format 2024-02-29 14:27:47 -05:00
Julian Eisel
0876f58171 Assets: Increase thread safety when rebuilding "All" library
Note that this still isn't entirely thread safe since the catalogs of
the asset libraries may still be edited in various ways while building
the all asset library. But at least this avoids a data race when
assigning the catalog service once done building it.
2024-02-29 17:49:04 +01:00
Julian Eisel
9178ff244f Cleanup: remove 'this' keyword where guidelines don't ask for it
4cc1c65272 made this a protected member, so following the C++ style
guidelines, this doesn't have to use `this` for accessing.
2024-02-29 17:43:16 +01:00
Julian Eisel
5bc9434893 Refactor: Make asset catalog class members constant
Some of these members are not expected to change throughout the lifetime
of the class instances, so make them constant and only set them via the
constructor. Making them immutable this way helps making clear which
data needs extra attention for thread safety.
2024-02-29 17:33:18 +01:00
Julian Eisel
e6642cd99c Refactor: Remove asset catalog helper classes from public header
These shouldn't need to be accessed from outside the asset system
itself, so they should not be exposed with its API. Move them to an own
asset system private headers. This is a further step towards making
asset system classes more encapuslated, so behavior and data flow can be
controlled better (which helps addressing threat safety issues).
Personally I've found it quite confusing to work on higher level issues
of the asset catalog system, because I got lost in the multiple classes.
Hopefully separating them more clearly helps with that too.
2024-02-29 17:12:08 +01:00
Julian Eisel
4cc1c65272 Refactor: Make asset catalog service non-public, access through API
Making the member private (or at least protected) makes threat safety
more tangible, and we don't need to expose locking in the API. Generally
we need to make data more encapsulated, so we can make edits more
controlled and threat safe.

Asset libraries also always have a catalog-service, so it can accessed
by reference, rather than pointer that would have to be null-checked.
2024-02-29 17:12:08 +01:00
Julian Eisel
9bf10d9a69 Cleanup: Use const for catalog service functions
These expose internal data for unit testing purposes. While it might be
better to avoid this entirely, at least make the returned data const, so
there's no unexpected modification from outside the catalog service
internals.
2024-02-26 20:15:14 +01:00
Julian Eisel
a9858c1565 Assets: Make asset catalog tree building (mostly) thread safe
Making this thread safe is quite trivial now. Note that for building the
tree we iterate the catalogs map, which may still be modified from
another thread in parallel. Making this thread safe is kept for a
separate commit.
2024-02-26 20:14:13 +01:00
Julian Eisel
0995adce20 Fix asset catalogs test failure
Unit tests were assuming that creating a catalog from a path would not
create catalogs for the parent path elements if missing. I'd argue this
should not be unit tested since it's internal behavior that isn't
visible to API users. But for now I'll keep the test working as is, also
to avoid indirect recursive calls of `create_missing_catalogs()`.
2024-02-26 15:12:38 +01:00
Julian Eisel
2bfaf94fa7 Refactor: Lazy create & update asset catalog trees
Rebuilding the tree immediately after changes could cause the tree to be
rebuilt multiple times. More importantly, it made it harder to reason
about thread safety, since we would touch the tree within a whole bunch
of API functions. Now tree building is simplified and managed in a
single place, so making the tree building thread safe can be made
trivially in a follow-up.

Note, this means the initial catalog tree building doesn't happen in a
background thread together with loading the asset library and catalogs
anymore. But we would already do all further rebuilds on the main thread
anyway, this shouldn't have any notable impact.
2024-02-26 10:35:15 +01:00
Julian Eisel
57dfc2a885 Cleanup: Make catalog tree const-correct
Basic motivation is that `AssetCatalogService::get_catalog_tree()`
should return a const tree, since this tree is internal state and
shouldn't be modified from outside. This exposed a whole bunch of const
incorrectnesses and just generally allows to make much more of the API
const (as it should be).

Also use references instead of pointers in testing functions, where null
is not an expected value.
2024-02-23 18:13:10 +01:00
Julian Eisel
53273e4460 Cleanup: Use const for asset catalog query 2024-02-23 18:13:10 +01:00
Julian Eisel
ee3291dc6d Fix double loading of asset catalogs when reloading "All" library
`refresh_catalogs()` for the "All" asset library effectively does the
same as iterating over all other asset libraries and calling
`get_asset_library()` on them. So doing both just performs the same work
twice.
2024-02-23 13:02:54 +01:00
Julian Eisel
49c7dfe904 Fix unintended reloading of asset catalog files from disk
Mistake in #118463.

Updating the catalogs of the "All" asset library would also reload
catalog data of the other asset libraries from disk. This wasn't
intended, this should be done with an explicit load request only (and on
a thread to not block the main thread).
2024-02-23 12:55:38 +01:00
Brecht Van Lommel
056becae8a Merge branch 'blender-v4.1-release' into main 2024-02-22 14:36:13 +01:00
Brecht Van Lommel
8dfb87d1af Fix: Update tests data path to new directory 2024-02-22 14:25:54 +01:00
Julian Eisel
56fa8c59af Fix possible infinite recursion in asset catalog tree building
PR #118382 exposed an issue where creating a catalog with non-existing
parents would trigger an endless recursion. When creating the missing
parents, the tree would be rebuilt, which would again try to create the
missing parents, for which the tree would be rebuild, etc. It just
happend to work fine for creating single catalogs with existing parents.

Rather than rebuilding the tree immediately, tag the asset library as
having "dirty" catalog data, and let code requiring the up-to-date
catalog tree (node tool menus) ensure the tree is updated if needed.

The asset library loading API should be made clearer and generally
better defined/designed, currently it's all a bit messy & confusing.

Pull Request: https://projects.blender.org/blender/blender/pulls/118463
2024-02-21 13:02:37 +01:00
Julian Eisel
debdde985f Fix #108703: assert when loading "All" asset library
Error caused by attempting to register multiple catalogs with the same
catalog ID. This would happen when multiple asset libraries would use
the same catalog definition file, and the "All" library would attempt to
merge them all into one library.

Ignore duplicate catalogs, like we already do when reading individual
asset catalog definition files. Log an error instead, or a info log if
the catalog path matches as well (in which case the conflict can be
ignored as it won't be user visible).
2024-02-20 16:48:42 +01:00
Julian Eisel
628c026140 Cleanup: Make asset catalog service functions const 2024-02-19 20:47:22 +01:00
Julian Eisel
342f470ccf Cleanup: Make asset library function more clear
Got confused by the naming here myself, this should help.
2024-02-19 20:47:22 +01:00
Julian Eisel
c473a165b8 Merge branch 'blender-v4.1-release' 2024-02-19 18:06:41 +01:00
Julian Eisel
edcdbf1cbd Fix race condition in "All" asset library building
Multiple threads may try to load the "All" asset library catalogs, so
avoid working on the same catalog service in parallel.

Found when testing #118463 on top of #118382, by creating a sculpt brush
asset while the asset shelf is open. The 3D View header would trigger
reloading of the "All" asset library catalogs to display node assets in
header pulldowns, while the asset shelf triggered a threaded reload of
the asset library.
2024-02-19 18:05:31 +01:00
Brecht Van Lommel
0f2064bc3b Revert changes from main commits that were merged into blender-v4.1-release
The last good commit was 4bf6a2e564.
2024-02-19 15:59:59 +01:00
Hans Goudey
8ab23f0a6e Assets: Return weak reference by value from asset representation
This is generally more flexible and less error prone. The struct
implements a proper descructorfor this anyway. That also makes the
separate free function unnecessary-- it's redundant with the destructor.
2024-02-16 12:02:08 -05:00
Hans Goudey
921ce2fae8 Cleanup: Consistent use of "this" keyword in asset code
Follow the style guide for using `this->` to access non-private variables.
2024-02-16 11:01:17 -05:00
Julian Eisel
6d387b3ba8 Cleanup: Use reference where null asset library is not possible
It should not be possible to end up with an asset representation that
does not have a valid pointer/reference to the asset library owning it,
it's injected via all constructors. So reflect that by using a reference
instead of a (possibly null) pointer.
2024-02-16 16:53:36 +01:00
Julian Eisel
38c2305457 Cleanup: Remove unused header in asset file 2024-02-16 16:51:53 +01:00
Julian Eisel
a5a3125fe1 Refactor: Remove unused move constructor for asset representation
This shouldn't be needed, and was incorrect anyway: It wasn't copying
the owner asset library pointer.
2024-02-16 16:38:14 +01:00
Hans Goudey
c07132b43b Cleanup: Make format 2024-02-14 17:43:03 -05:00
Hans Goudey
57586df687 Cleanup: Remove unnecessary asset system functions
These functions appear to be thin wrappers around the C++ classes
that previously weren't accessible in C code.
2024-02-14 17:23:01 -05:00
Hans Goudey
7098e53c61 Cleanup: Use "this" keyword to access class methods 2024-02-14 17:23:01 -05: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
deab8c085a Cleanup: Move BKE_callbacks.h and BKE_cachefile.h to CPP headers. 2024-02-09 19:29:34 +01:00
Bastien Montagne
b21ceece05 Cleanup: Move BKE_blender.h to CPP header.
Also fix comment in `build_files/cmake/macros.cmake`, CMake blender version
parsing depends in the (still C) `BKE_blender_version.h` header now.
2024-02-09 19:12:23 +01:00
Julian Eisel
3c2366d313 Assets: Add further dedicated derived classes for asset libraries
Continuation of bdfb1f6a04. Adds derived classes for the essentials and
preferences asset libraries, to allow specialized classes with a simple
and common interface. This should help untangling the asset library
service code.
2024-02-06 16:11:32 +01:00
Julian Eisel
bdfb1f6a04 Assets: Use inheritance for asset library class
Initial changes to make the asset library class polymorphic, plus using
that to cleanup some basic loading logic. I'm confident that this will
help us improve the asset library management code quite a bit, currently
it's quite confusing. Plus it will be extendable this way in future, so
new kinds of asset libraries (e.g. Blender project asset libraries or
arbitrary online asset libraries) can be added much easier.
2024-02-05 18:25:18 +01:00
Hans Goudey
fb0d6198c0 Cleanup: Move remaining asset editors code to C++ namespace 2024-01-26 18:43:13 -05:00
Hans Goudey
2043df4816 Cleanup: Remove unnecessary AssetLibrary C wrapper type 2024-01-26 18:15:41 -05:00
Hans Goudey
f08ce0a8ed Cleanup: Move AS_asset_library.h contents to C++ header 2024-01-26 18:15:41 -05:00