Commit Graph

39 Commits

Author SHA1 Message Date
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
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 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
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 628c026140 Cleanup: Make asset catalog service functions const 2024-02-19 20:47:22 +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
Bastien Montagne deab8c085a Cleanup: Move `BKE_callbacks.h` and `BKE_cachefile.h` to CPP headers. 2024-02-09 19:29:34 +01: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
Bastien Montagne d8d44a62f7 Cleanup: Move `BKE_appdir.h` to full Cpp header `BKE_appdir.hh`. 2024-01-21 19:42:13 +01:00
Brecht Van Lommel 364beee159 Tests: add option to build one binary per GTest file
Bundling many tests in a single binary reduces build time and disk space
usage, but is less convenient for running individual tests command line
as filter flags need to be used.

This adds WITH_TESTS_SINGLE_BINARY to generate one executable file per
source file. Note that enabling this option requires a significant amount
of disk space.

Due to refactoring, the resulting ctest names are a bit different than
before. The number of tests is also a bit different depending if this
option is used, as one uses gtests discovery and the other is organized
purely by filename, which isn't always 1:1.

Co-authored-by: Sergey Sharybin <sergey@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/114604
2024-01-03 18:35:50 +01: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 15db0cb446 Cleanup: use style for doxygen comment blocks 2023-11-30 14:15:11 +11:00
Hans Goudey 3d57bc4397 Cleanup: Move several blenkernel headers to C++
Mostly focus on areas where we're already using C++ features,
where combining C and C++ APIs is getting in the way.

Pull Request: https://projects.blender.org/blender/blender/pulls/114972
2023-11-16 11:41:55 +01:00
Julian Eisel f622b4ce96 Fix #113201: Assets in same folder as current file ignored in All library
Note: Initially committed as 7705e49bcd, but got reverted with
1f0520034a. Note includes fixes for unit tests.

If an asset library was pointing to the same path as the current file is saved
in, the assets from this library wouldn't be loaded. This is because the asset
library service assumed the absolute library root path is a way to uniquely
identify an asset library.

Instead, identify the asset library using both the root path and the library
type.
2023-10-18 16:10:42 +02:00
Hans Goudey fa34992def Cleanup: Remove unnecessary includes from C++ data structure headers
The hash tables and vector blenlib headers were pulling many more
headers than they actually need, including the C base math header,
our C string API header, and the StringRef header. All of this
potentially slows down compilation and polutes autocomplete
with unrelated information.

Also remove the `ListBase` constructor for `Vector`. It wasn't used
much, and making it easy to use `ListBase` isn't worth it for the
same reasons mentioned above.

It turns out a lot of files depended on indirect includes of
`BLI_string.h` and `BLI_listbase.h`, so those are fixed here.

Pull Request: https://projects.blender.org/blender/blender/pulls/111801
2023-09-01 21:37:11 +02:00
Julian Eisel 567e3b9b19 Assets: Always use guarded allocator for weak references
Although I don't like the idea of using owning raw pointers in new APIs
like this (violates fundamental C++ good practises), this type is mostly
meant for writing to files via DNA. So we have to use Blender's memory
management via the guarded allocator here.

Considered making this an alternative function, but then we'd have to
duplicate logif or duplicate memory or so. Not worth it to me.
2023-08-29 13:49:58 +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
Hans Goudey 1b4b90f5f7 Cleanup: Remove unnecessary C API for asset representation
Now that almost all code is in C++, this is unnecessary and
just confuses things with multiple entry points to the same code.

Pull Request: https://projects.blender.org/blender/blender/pulls/109661
2023-07-04 14:46:19 +02:00
Julian Eisel 631e5d5d4f Asset system: Store ID type in asset representation
No user visible changes expected.

This brings us another step closer to replacing the temporary asset
handle design with the proper asset representation design. I held off
with this a bit because we eventually want to support non-ID assets, but
for now it is fine to consider all assets to be IDs. In future the asset
system can make the necessary distinctions still.

Now only the preview is handled via asset handle still.
2023-06-08 20:55:10 +02:00
Campbell Barton 87ff8ee09a Cleanup: disambiguate the term 'path'
Use filepath or dirpath, unless the contents might be either,
in that case note that the contents could be both.
Use `rna_path*` in some cases too.
2023-06-05 10:57:34 +10:00
Sergey Sharybin c1bc70b711 Cleanup: Add a copyright notice to files and use SPDX format
A lot of files were missing copyright field in the header and
the Blender Foundation contributed to them in a sense of bug
fixing and general maintenance.

This change makes it explicit that those files are at least
partially copyrighted by the Blender Foundation.

Note that this does not make it so the Blender Foundation is
the only holder of the copyright in those files, and developers
who do not have a signed contract with the foundation still
hold the copyright as well.

Another aspect of this change is using SPDX format for the
header. We already used it for the license specification,
and now we state it for the copyright as well, following the
FAQ:

    https://reuse.software/faq/
2023-05-31 16:19:06 +02:00
Campbell Barton 3958ae7241 Cleanup: use STRNCPY, SNPRINTF macros 2023-05-09 14:08:19 +10:00
Campbell Barton 6859bb6e67 Cleanup: format (with BraceWrapping::AfterControlStatement "MultiLine") 2023-05-02 09:37:49 +10:00
Julian Eisel d90795bc3c Asset System: New "weak" asset reference for storing in .blend files
No user visible changes expected.

For brush assets, we need a way to store a reference to a brush in .blend files, so that the last active brush can be restored from the file. See #101908. It seems like a generally useful thing to have.

Adds a new DNA struct to store a "weak" asset reference, that is, a reference that can break under a number of circumstances, but should work reliably enough under normal usage. There's no way to reliably reference an asset currently, so this works on a "best effort" basis. It can break when assets are moved inside the asset library, asset libraries are unregistered from the Preferences, or a file is opened on a different machine with different Preferences, for example. It can also break currently if an asset library is renamed.
It contains:
- Information to identify the asset library the asset can be found in.
- A relative "identifier" (currently a relative path) for the asset within the asset library.

There's further code to resolve a weak reference to file paths and Blender library paths.

Part of #101908.

Co-authored-by: Bastien Montagne <bastien@blender.org>

Pull Request: https://projects.blender.org/blender/blender/pulls/105603
2023-03-30 12:25:42 +02:00
Sergey Sharybin a12a8a71bb Remove "All Rights Reserved" from Blender Foundation copyright code
The goal is to solve confusion of the "All rights reserved" for licensing
code under an open-source license.

The phrase "All rights reserved" comes from a historical convention that
required this phrase for the copyright protection to apply. This convention
is no longer relevant.

However, even though the phrase has no meaning in establishing the copyright
it has not lost meaning in terms of licensing.

This change makes it so code under the Blender Foundation copyright does
not use "all rights reserved". This is also how the GPL license itself
states how to apply it to the source code:

    <one line to give the program's name and a brief idea of what it does.>
    Copyright (C) <year>  <name of author>

    This program is free software ...

This change does not change copyright notice in cases when the copyright
is dual (BF and an author), or just an author of the code. It also does
mot change copyright which is inherited from NaN Holding BV as it needs
some further investigation about what is the proper way to handle it.
2023-03-30 10:51:59 +02:00
Campbell Barton 1ddbe7cadd Cleanup: move doc-strings into headers, remove duplicates
In some cases move implementation details into the function body.
2023-03-29 14:37:34 +11:00
Julian Eisel a243a9dc79 Cleanup: Remove unused headers in asset files 2022-12-14 15:43:05 +01:00
Julian Eisel 85d92afbd4 Cleanup: Move asset catalog tree tests to own file
The catalog tree is a unit on its own, and should be tested separately.
This makes the testing files smaller and more focused, which can help
maintaining them.
2022-12-12 17:07:55 +01:00
Julian Eisel dbd3822329 Cleanup: Extract asset test class into own header
This manages setting up asset library directories for testing, which is
useful for testing multiple asset library related compontents. So move
it to a common header. No reason to squeeze everything into one file
then.
2022-12-12 16:59:26 +01:00
Julian Eisel 7c0cecfd00 Asset system: Move catalog tree code to own files
The catalog code is already quite complex, I rather keep the tree stuff
separate in a more focused unit.
2022-11-18 12:45:56 +01:00
Julian Eisel ea2dda306c Asset system: New asset system code module (with files from BKE)
Adds a new `source/blender/asset_system` directory and moves asset
related files from BKE to it. More asset related code can follow
(e.g. asset indexing, ED_assetlist stuff) but needs further work to
untangle it. I also kept `BKE_asset.h` and `asset.cc` as is, since they
deal with asset DNA data mostly, thus make sense in BKE.

Motivation:
- Makes the asset system design more present (term wasn't even used in
  code before).
- An `asset_system` directory is quite descriptive (trivial to identify
  core asset system features) and makes it easy to find asset code.
- Asset system is mostly runtime data, with little relation to other
  `Main`/BKE/DNA types.
- There's a lot of stuff in BKE already. It shouldn't be just a dump for
  all stuff that seems core enough.
- Being its own directly helps us be more mindful about encapsulating
  the module well, and avoiding dependencies on other modules.
- We can be more free with splitting files here than in BKE.
- In future there might be an asset system BPY module, which would then
  map quite nicely to the `asset_system` directory.

Checked with some other core devs, consensus seems that this makes
sense.
2022-11-14 12:46:34 +01:00