载入中...
搜索中...
未找到
Capability.cpp
浏览该文件的文档.
1#include "common/BootWarmup.h"
2#include "common/Capability.h"
3
4#include <algorithm>
5#include <string>
6#include <unordered_map>
7#include <vector>
8
9namespace eve::cap::detail {
10
11namespace {
12
13struct Listener {
14 void* impl = nullptr;
15 int priority = 0;
16};
17
18struct Slot {
19 void* service = nullptr;
20 std::vector<Listener> listeners; // kept sorted by priority
21};
22
28std::unordered_map<std::string, Slot>& slots() {
29 static std::unordered_map<std::string, Slot> table;
30 return table;
31}
32
33} // namespace
34
35void provideRaw(const char* name, void* impl) {
36 if (!name) return;
37 slots()[name].service = impl;
38}
39
40void* queryRaw(const char* name) {
41 if (!name) return nullptr;
42 auto& table = slots();
43 auto it = table.find(name);
44 return it == table.end() ? nullptr : it->second.service;
45}
46
47void revokeRaw(const char* name, void* impl) {
48 if (!name) return;
49 auto& table = slots();
50 auto it = table.find(name);
51 // Only clear when `impl` is still the current provider, so a stale revoke
52 // from a torn-down module cannot unregister its replacement.
53 if (it != table.end() && it->second.service == impl) it->second.service = nullptr;
54}
55
56void addListenerRaw(const char* name, void* impl, int priority) {
57 if (!name || !impl) return;
58 auto& list = slots()[name].listeners;
59 for (const auto& l : list)
60 if (l.impl == impl) return; // idempotent
61 // stable_sort keeps registration order within one priority.
62 list.push_back({impl, priority});
63 std::stable_sort(list.begin(), list.end(),
64 [](const Listener& a, const Listener& b) { return a.priority < b.priority; });
65}
66
67void removeListenerRaw(const char* name, void* impl) {
68 if (!name) return;
69 auto& table = slots();
70 auto it = table.find(name);
71 if (it == table.end()) return;
72 auto& list = it->second.listeners;
73 list.erase(std::remove_if(list.begin(), list.end(),
74 [impl](const Listener& l) { return l.impl == impl; }),
75 list.end());
76}
77
78size_t listenerCountRaw(const char* name) {
79 if (!name) return 0;
80 auto& table = slots();
81 auto it = table.find(name);
82 return it == table.end() ? 0 : it->second.listeners.size();
83}
84
85void* listenerAtRaw(const char* name, size_t index) {
86 if (!name) return nullptr;
87 auto& table = slots();
88 auto it = table.find(name);
89 if (it == table.end() || index >= it->second.listeners.size()) return nullptr;
90 return it->second.listeners[index].impl;
91}
92
93void clearOwnedRaw(); // CapabilityOwned.cpp
94
96 slots().clear();
98}
99
100} // namespace eve::cap::detail
101
102namespace eve::boot {
103namespace {
104
105void (*gVulkanWarmup)() = nullptr;
106
107} // namespace
108
109void registerVulkanInstanceWarmup(void (*start)()) { gVulkanWarmup = start; }
110
112 if (gVulkanWarmup) gVulkanWarmup();
113}
114
115} // namespace eve::boot
Duration start
void * service
int priority
std::vector< Listener > listeners
void * impl
std::string name
MeleePoint3 b
Definition MeleeHit.cpp:41
MeleePoint3 a
Definition MeleeHit.cpp:40
LocalPageCacheEntry slots[ShadowConfig::kLocalSlots]
uint32_t index
EVENGINE_API_FOUNDATION void registerVulkanInstanceWarmup(void(*start)())
Register the graphics-backend function that starts VkInstance creation.
EVENGINE_API_FOUNDATION void startVulkanInstanceWarmup()
Kick off asynchronous VkInstance creation if a backend registered.
size_t listenerCountRaw(const char *name)
Listener count raw.
void addListenerRaw(const char *name, void *impl, int priority)
Adds listener raw.
void provideRaw(const char *name, void *impl)
Provides raw.
void removeListenerRaw(const char *name, void *impl)
Removes listener raw.
void * queryRaw(const char *name)
Queries raw.
void revokeRaw(const char *name, void *impl)
Revoke raw.
void clearAllRaw()
Clears all raw.
void * listenerAtRaw(const char *name, size_t index)
Listener at raw.
std::unordered_map< std::string, SkillDefinition > & table()
Definition Skill.cpp:65