载入中...
搜索中...
未找到
EcsDefaultTable.cpp
浏览该文件的文档.
1// The default ECS Table and each thread's current-world slot have one owner.
2//
3// `ecs::default_table()` used to be an inline function with a function-local
4// static (external/ECS.hpp). In a single-image build that is one Table, but the
5// shared link-group route (EVENGINE_MODULE_LINKAGE=SHARED) puts the engine in
6// several DLLs plus the host executable, and MSVC/ELF do not unify an inline
7// function's local static across images: the host and each group would address a
8// different Table, so an entity created through a domain module would be
9// invisible to `ecs::current()` in the caller (and vice versa).
10//
11// The canonical external/ECS.hpp header declares the compiled owner so
12// that in SHARED mode `ecs::default_table()` forwards to
13// `ecs::engine_default_table()`, and this translation unit -- compiled into the
14// foundation link unit, which every other group already depends on -- owns the
15// storage. The OBJECT/static route keeps the inline definition, so a release SDK
16// remains a single self-contained executable with no engine DLLs.
17// The canonical current-slot API routes ScopedTable's override through the same owner:
18// otherwise a factory in another link group still creates into the default
19// table instead of the caller's selected world. The override remains per-thread.
20//
21// The definition repeats EVE_ECS_DEFAULT_TABLE_API on purpose: MSVC rejects a
22// plain declaration followed by a dllexport definition (C2375, "redefinition;
23// different linkage"), so the header's declaration and this definition must carry
24// the same annotation.
25
26#include <ECS.hpp>
27
28#if defined(EVENGINE_MODULE_DLL)
29
30namespace ecs {
31
32EVE_ECS_DEFAULT_TABLE_API Table& engine_default_table() {
33 static Table table;
34 return table;
35}
36
37EVE_ECS_DEFAULT_TABLE_API Table*& engine_current_slot() {
38 thread_local Table* slot = nullptr;
39 return slot;
40}
41
42} // namespace ecs
43
44#endif
std::string slot
std::unordered_map< std::string, SkillDefinition > & table()
Definition Skill.cpp:73
enum EVENGINE_API_FOUNDATION Table
OT_TABLE (editable via Runtime table APIs / ReflectedPropertyModel).
Definition Runtime.h:121