载入中...
搜索中...
未找到
ViewPreparation.cpp
浏览该文件的文档.
2#include <algorithm>
3#include <exception>
4#include <vector>
5#include "common/Assert.h"
6namespace eve::graphics {
7namespace {
8struct Entry {
9 uint64_t token;
11};
12std::vector<Entry> entries;
13uint64_t nextToken = 1;
14bool dispatching = false;
15Diagnostic rejected(const char* message) {
16 return Diagnostic::error(DiagnosticCode::InvalidArgument, message, "graphics.view-preparation");
17}
18} // namespace
20 if (!callback || dispatching || nextToken == 0)
21 return Result<uint64_t>::failure(rejected("Invalid or reentrant view preparation registration"));
22 try {
23 const auto token = nextToken;
24 entries.push_back({token, std::move(callback)});
25 ++nextToken;
27 } catch (const std::exception& error) {
28 return Result<uint64_t>::failure(rejected(error.what()));
29 }
30}
31void removeViewPreparation(uint64_t token) noexcept {
32 EV_ASSERT(!dispatching, "View preparers must detach outside dispatch");
33 if (dispatching) return;
34 std::erase_if(entries, [token](const Entry& entry) { return entry.token == token; });
35}
36Result<void> detail::prepareViewResources(Graphics& graphics, const glm::mat4& vp, const glm::vec3& eye) {
37 if (dispatching) return Result<void>::failure(rejected("View preparation cannot recursively dispatch"));
38 struct Guard {
39 Guard() { dispatching = true; }
40 ~Guard() { dispatching = false; }
41 } guard;
42 try {
43 for (const auto& entry : entries) {
44 auto prepared = entry.callback(graphics, vp, eye);
45 if (!prepared) return Result<void>::failure(prepared.status());
46 }
47 return Result<void>::success();
48 } catch (const std::exception& error) {
49 return Result<void>::failure(rejected(error.what()));
50 }
51}
52} // namespace eve::graphics
EVEngine assertion entry point, backed by zeroerr.
#define EV_ASSERT(cond,...)
Assert an internal engine invariant (state that must always hold).
Definition Assert.h:37
std::unordered_map< std::string, QuestRuntime > entries
std::string message
std::string error
Definition Package.cpp:60
glm::vec3 eye
uint64_t token
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
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
eve::Diagnostic Diagnostic
Result< T > rejected(RuleId rule, std::string message, eve::DiagnosticCode code=eve::DiagnosticCode::PreconditionViolation)
Construct a Rejected result for invalid editing input or preconditions.
EVENGINE_API_BACKENDS Result< void > prepareViewResources(Graphics &graphics, const glm::mat4 &viewProjection, const glm::vec3 &eye)
Dispatch preparers before opening the destination; no callbacks means success. @thread Graphics threa...
卡牌游戏 UI 工具模块:工厂 + 脚本绑定入口。 功能参考 ycarowr/UiCard:扇形手牌布局、抽牌/洗牌、悬浮放大、拖拽到落牌区、 敌方手牌(背面/偷看)、费用不足置灰,以及可实时调节的布局...
Definition Animation.h:25
std::function< Result< void >(Graphics &, const glm::mat4 &, const glm::vec3 &)> ViewPreparation
Prepare view-dependent resources before any forward target is opened. @thread Graphics thread only....
void removeViewPreparation(uint64_t token) noexcept
Remove a registration; missing/zero tokens are harmless. @thread Graphics thread outside dispatch....
Result< uint64_t > addViewPreparation(ViewPreparation callback)
Register a preparer for main and offscreen views; empty callbacks fail. @ownership Registry owns the ...