Add a screen to download gltf models
This commit is contained in:
+17
-14
@@ -19,6 +19,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
#include <cassert>
|
||||
#include <condition_variable>
|
||||
#include <exception>
|
||||
#include <functional>
|
||||
@@ -177,7 +178,7 @@ struct async_token
|
||||
async_token & operator=(const async_token &) = default;
|
||||
async_token & operator=(async_token &&) = default;
|
||||
|
||||
void set_result(Result && r)
|
||||
void set_result(Result r)
|
||||
{
|
||||
assert(shared_state);
|
||||
std::unique_lock _{shared_state->lock};
|
||||
@@ -185,7 +186,7 @@ struct async_token
|
||||
shared_state->cv.notify_all();
|
||||
}
|
||||
|
||||
void set_exception(std::exception_ptr && e)
|
||||
void set_exception(std::exception_ptr e)
|
||||
{
|
||||
assert(shared_state);
|
||||
std::unique_lock _{shared_state->lock};
|
||||
@@ -194,7 +195,7 @@ struct async_token
|
||||
}
|
||||
|
||||
public:
|
||||
void set_progress(Progress && p)
|
||||
void set_progress(Progress p)
|
||||
{
|
||||
assert(shared_state);
|
||||
std::unique_lock _{shared_state->lock};
|
||||
@@ -215,17 +216,19 @@ future<Result, Progress> async(F && f, Args &&... args)
|
||||
|
||||
fut.shared_state = std::make_shared<typename future<Result, Progress>::state>();
|
||||
|
||||
fut.shared_state->thread = std::thread([f, args...](auto token) {
|
||||
try
|
||||
{
|
||||
token.set_result(std::invoke(f, token, args...));
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
token.set_exception(std::current_exception());
|
||||
}
|
||||
},
|
||||
async_token<Result, Progress>(fut.shared_state));
|
||||
fut.shared_state->thread = std::thread(
|
||||
[f](async_token<Result, Progress> token, Args &&... args) {
|
||||
try
|
||||
{
|
||||
token.set_result(std::invoke(f, token, std::forward<Args>(args)...));
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
token.set_exception(std::current_exception());
|
||||
}
|
||||
},
|
||||
async_token<Result, Progress>(fut.shared_state),
|
||||
std::forward<Args>(args)...);
|
||||
|
||||
return fut;
|
||||
}
|
||||
|
||||
+14
-4
@@ -28,14 +28,14 @@ namespace utils
|
||||
template <typename Key, typename Asset, typename Loader>
|
||||
class cache
|
||||
{
|
||||
Loader loader;
|
||||
Loader loader_;
|
||||
|
||||
thread_safe<std::unordered_map<Key, std::shared_ptr<Asset>>> entries;
|
||||
|
||||
public:
|
||||
template <typename... Args>
|
||||
cache(Args &&... args) :
|
||||
loader(std::forward<Args>(args)...)
|
||||
loader_(std::forward<Args>(args)...)
|
||||
{}
|
||||
|
||||
template <typename... Args>
|
||||
@@ -48,13 +48,13 @@ public:
|
||||
if (iter != _->end())
|
||||
return iter->second;
|
||||
|
||||
return _->emplace(key, loader(std::forward<Args>(args)...)).first->second;
|
||||
return _->emplace(key, loader_(std::forward<Args>(args)...)).first->second;
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
std::shared_ptr<Asset> load_uncached(Args &&... args)
|
||||
{
|
||||
return loader(std::forward<Args>(args)...);
|
||||
return loader_(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
void clear()
|
||||
@@ -68,5 +68,15 @@ public:
|
||||
auto _ = entries.lock();
|
||||
_->erase(key);
|
||||
}
|
||||
|
||||
Loader & loader()
|
||||
{
|
||||
return loader_;
|
||||
}
|
||||
|
||||
const Loader & loader() const
|
||||
{
|
||||
return loader_;
|
||||
}
|
||||
};
|
||||
} // namespace utils
|
||||
|
||||
Reference in New Issue
Block a user