C++ flexible ComponentBatch, AsComponents, logging unification#3791
Merged
C++ flexible ComponentBatch, AsComponents, logging unification#3791
Conversation
…explicit archetype constructors
emilk
reviewed
Oct 11, 2023
Member
emilk
left a comment
There was a problem hiding this comment.
This looks very promising! I just had a quick look so far, will dive deeper later
| }; | ||
| rec.log("strip", rr::LineStrips3D(points)); | ||
| }); | ||
| rec.log("strip", rr::LineStrips3D(linestrip)); |
Member
There was a problem hiding this comment.
Am I reading this right: a single strip is passed to a constructor that can also take multiple strips?
Member
There was a problem hiding this comment.
Is this implemented with an overloaded constructor to ComponentBatch? There's so many layers to this 😓 implicit constructor calling in C++ is a bit 😬
Member
Author
There was a problem hiding this comment.
This one is relatively straight forward :)
/// Adapter for a single component, temporary or reference.
template <typename TComponent>
struct ComponentBatchAdapter<TComponent, TComponent> {
ComponentBatch<TComponent> operator()(const TComponent& one_and_only) {
return ComponentBatch<TComponent>::borrow(&one_and_only, 1);
}
ComponentBatch<TComponent> operator()(TComponent&& one_and_only) {
return ComponentBatch<TComponent>::take_ownership(std::move(one_and_only));
}
};
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
log_components) need to be optional non-owning (& mappable) #3050This PR introduces two new concepts to our logging/serialization pipeline that make it much more extensible and make us able to avoid allocations for (simple) user types.
On top, it simplifies our logging pipelines and - despite template juggling - should lead to better error messages!
The whole thing works with two new trait classes:
ComponentBatch<TComponent>std::vector<TComponent>in archetypesTInputfor whichComponentBatchAdapater<TComponent, TInput>existsTComponentno longer work (you have to construct your component before passing now).borrow(ptr, len)/take_ownership(std::vector&&)) but adapters typically decideAsComponents<T>logandtry_lognow 🎉ComponentBatch, vector/array/c-array of components and generated for all archetypes (-> serialization is no longer part of the archetype struct, but pushed to the trait impl)Unlike typically with traits, the default of both traits IS implemented, containing a static_assert (thanks @AnkeAnke for the idea!!) which gives a (somewhat readable) error message when there's not batch adapter or component:
AsComponents failure:
leads to:
ComponentBatchAdapter failure:
Future work:
MonoComponentBatchfor mono components - right now mono components (like transform, but also like MeshProperties which has all triangle indices 😞) are not adaptable and always full-copyto_data_cellarrow serialization methods to make them fit better into the system. SinceComponentBatchshould have strides etc. in the future, they will need to consumeComponentBatcheswhich in turn need the ability to iterate.Checklist