载入中...
搜索中...
未找到
GraphicsLifetime.cpp
浏览该文件的文档.
1#include <cstdio>
2#include <unordered_map>
4#include "graphics/Graphics.h"
5namespace eve::graphics {
6namespace {
7struct Lifetime {
9 bool retired = false;
10};
11bool registryAlive = false;
12struct Registry {
13 std::unordered_map<const Graphics*, std::shared_ptr<Lifetime>> tokens;
14 Registry() { registryAlive = true; }
15 ~Registry() { registryAlive = false; }
16};
17auto& lifetimes() {
18 static Registry registry;
19 return registry.tokens;
20}
21auto lifetime(const Graphics* graphics) {
22 auto& value = lifetimes()[graphics];
23 if (!value) value = std::make_shared<Lifetime>();
24 return value;
25}
26} // namespace
27std::weak_ptr<const void> Graphics::resourceLifetime() const {
28 auto value = lifetime(this);
29 return value->retired ? std::weak_ptr<const void>{} : value;
30}
32 auto value = lifetime(this);
33 if (value->retired)
35 Diagnostic::error(DiagnosticCode::Conflict, "Graphics resources are retiring"));
36 return Result<eve::Subscription>::success(value->retiring.subscribe(std::move(callback)));
37}
39 if (!registryAlive) return;
40 auto it = lifetimes().find(this);
41 if (it == lifetimes().end() || it->second->retired) return;
42 auto value = it->second;
43 value->retired = true;
44 const auto failures = value->retiring.notifyChecked([]() noexcept {});
45 if (failures) std::fprintf(stderr, "Graphics resource retirement: %zu callback failures\n", failures);
46 lifetimes().erase(this);
47}
48} // namespace eve::graphics
double value
bool retired
std::unordered_map< const Graphics *, std::shared_ptr< Lifetime > > tokens
eve::Observer retiring
std::weak_ptr< const void > lifetime
ViewPreparation callback
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={}, DiagnosticDetails details={}, std::string source={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.h:125
Thread-affine callback registry with mutation-safe dispatch.
Move-only operation result carrying either a value or Status.
Definition Result.h:155
static Result success(T value)
Construct a successful result owning value.
Definition Result.h:164
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:175
std::weak_ptr< const void > resourceLifetime() const
Observe this provider's resource lifetime without extending it.
void retireResourceLifetime() const
Retire resource lifetime.
Result< eve::Subscription > onResourcesRetiring(std::function< void()> callback) const
Register cleanup before this provider destroys its GPU device/resources.
卡牌游戏 UI 工具模块:工厂 + 脚本绑定入口。 功能参考 ycarowr/UiCard:扇形手牌布局、抽牌/洗牌、悬浮放大、拖拽到落牌区、 敌方手牌(背面/偷看)、费用不足置灰,以及可实时调节的布局...
Definition Animation.h:25