-
-
Notifications
You must be signed in to change notification settings - Fork 893
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for failure in basic_snapshot_loader and entt::snapshot #1092
Comments
I wrote a rough pass at an implementation of an alternate method for get<> for snapshot_loader to show what I was thinking. It's based off the existing get<> template in the snapshot_loader class. Obviously it's not sufficient, but I thought it would provide something to help demonstrate what I was thinking: template<typename Type, typename Archive>
std::errc my_get(Archive& archive, const id_type id = type_hash<Type>::value()) const {
if (const auto* storage = reg->template storage<Type>(id); storage) {
if (std::errc const ec = archive(static_cast<typename traits_type::entity_type>(storage->size())); ec != std::errc{})
{
return ec;
}
if constexpr (std::is_same_v<Type, entity_type>) {
if (std::errc const ec = archive(static_cast<typename traits_type::entity_type>(storage->in_use())); ec != std::errc{})
{
return ec;
}
for (auto first = storage->data(), last = first + storage->size(); first != last; ++first) {
if (std::errc const ec = archive(*first); ec != std::errc{})
{
return ec;
}
}
}
else {
std::errc ec{};
auto const fold = [&ec, &archive](auto&&... args) {
if (ec != std::errc{})
return;
ec = (archive(std::forward<decltype(args)>(args)), ...);
};
for (auto elem : storage->reach()) {
std::apply(fold, elem);
}
return ec;
}
return std::errc{};
}
else {
return archive(typename traits_type::entity_type{});
}
} |
The main problem with |
Thank you so much for the reply!
Maybe I'm not seeing it clearly, but because entt/src/entt/entity/snapshot.hpp Line 126 in f2c4174
entt/src/entt/entity/snapshot.hpp Line 130 in f2c4174
entt/src/entt/entity/snapshot.hpp Line 133 in f2c4174
entt/src/entt/entity/snapshot.hpp Line 137 in f2c4174
What I'm looking for is when any of the calls to the archive returns "an error", I can stop immediately (print information about the error).
I didn't mean to
I guess I need to wait to see if I'm missing something obvious. I waited a couple days to respond because I wasn't sure if I was thinking enough about your response, but I don't see it. |
Bear with me, I'm just trying to brainstorm with you to see if it would work. 🙂 void
load_archive(auto& dest, auto& archive) noexcept {
std::errc error{};
auto error_aware_archive = [&error, &archive](auto &&... args) {
if(error == std::errc{}) { error = archive(std::forward<decltype(args)>(args)...);
};
if(dest.template get<entt::entity>(error_aware_archive ); error != std::errc) {
// do something to handle the error on the get<entt::entity> call
}
if(dest.template get<Coord2D>(error_aware_archive ); error != std::errc) {
// do something to handle the error on the get<Coord2D> call
}
// and so on
} This way you have the error available but we don't have to bind EnTT to |
At very least, using |
This is a really interesting idea for solving my issue, thank you for spending some time on it. Tell me if I'm off here, but since the std::vector<std::errc>
load_archive(auto& dest, auto& archive) noexcept
{
std::vector<std::errc> errors;
auto const error_aware_archive = [&errors, &archive](auto &&... args)
{
std::errc const ec = archive(std::forward<decltype(args)>(args)...);
if (std::errc{} != ec)
{
errors.push_back(ec);
}
};
if (dest.template get<entt::entity>(error_aware_archive); !std::empty(errors)) {
return errors;
}
// .... repeat for each component
}
This could totally work, and thank you again for spending time on this with me, it's just I don't think it's as good a solution as getting a return value from
|
Yeah I think a solution that allows the user to specify whatever return value they want instead of binding it to |
Hi @bjadamson sorry for the loooong gap but I went on vacation and decided to take a full break from everything this time. 🙂
Moreover, we have a couple of extra benefits imho:
Do you see any weak points here? Would it work in your case too? I think so but a double check is welcome. 🙂 |
Happy new year!
This sounds great, but it's unclear (unless an in/out parameter is used) to me how this can be done. I'm very curious what you have in mind. The extra benefits sound wonderful. Please let me know if I can do anything to assist.
I believe so. |
How is your Actually, we can even do better than this. We can support both Does it make sense? I think it would also work like a charm in your case. |
Ping @bjadamson 🙂 |
Sorry! I didn't notice you updated the thread.
Their all defined mostly using this macro: #define DEFINE_SERIALIZE_FN(...) \
static constexpr auto serialize(auto& archive, auto& self) noexcept -> zpp::bits::errc \
{ \
return archive(__VA_ARGS__); \
} I agree I believe it would work as well, as errc (typedef for std::errc). The one thing that comes to mind is that for https://groups.google.com/a/isocpp.org/g/std-discussion/c/b3gMahfDxSw?pli=1 |
Hello,
I wanted to ask you if you thought it was feasible to report errors in basic_snapshot_loader and snapshot classes, or if I am missing something obvious. I use zppbits (https://github.com/eyalz800/zpp_bits) to serialize my actual entities and components, and the function for serialization/deserialization returns a std::errc indicating success/failure. To use the snapshot and snapshot loader classes, I implemented the operator() overload, and return the std::errc that zppbits gives back to me, but it seems in my calling code (load_archive) doesn't have a chance to inspect the errors.
ie:
entt/src/entt/entity/snapshot.hpp
Line 122 in f2c4174
entt/src/entt/entity/snapshot.hpp
Line 87 in f2c4174
entt/src/entt/entity/snapshot.hpp
Line 193 in f2c4174
Am I missing something obvious, is there a way to get a return value from my operator() overload?
If it helps here's my code:
The text was updated successfully, but these errors were encountered: