Repository navigation
Expand file tree
/
Copy pathDekiParticlesPackage.cpp
More file actions
147 lines (127 loc) · 5.27 KB
/
Copy pathDekiParticlesPackage.cpp
File metadata and controls
147 lines (127 loc) · 5.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// Entry point of the deki-particles DLL. Exports the standard Deki plugin
// interface, so the editor can load it and register its one component (the
// emitter) and its particle-graph nodes: the Emitter entry and the built-in
// modifiers (Emission, Initial Velocity, Initial Rotation, Gravity, Drag, and
// Size, Color and Rotation over Lifetime).
//
// Other packages add modifiers the same way: declare a DEKI_NODE struct in a
// category starting "Particles/", register its ParticleModifierOps with
// REGISTER_PARTICLE_MODIFIER, and register the node type from their own
// package entry. deki-particles needs no change.
#include <deki/interop/Plugin.h>
#include "ParticleEmitterComponent.h"
#include "ParticleNodes.h"
#include "ParticleSystem.h"
#include "ParticlesInit.h"
#include <deki/reflection/ComponentRegistry.h>
#include <deki/reflection/ComponentFactory.h>
#include "deki-nodegraph/DekiNode.h" // DekiNodeGraph::NodeFactory + DekiNodeGraph::NodeTypeRegistry (editor)
extern void DekiParticlesRegisterComponents();
extern int DekiParticlesGetAutoComponentCount();
extern const Deki::ComponentMeta* DekiParticlesGetAutoComponentMeta(int index);
namespace DekiParticles
{
#ifdef DEKI_EDITOR
// The exports below are C symbols at global scope; the package's own
// registration helpers and statics live in its namespace.
using namespace DekiParticles;
// Defined in editor/ParticleGraphEditor.cpp; registers the graph domain again.
extern "C" void DekiParticlesRegisterEditorGraphDomain(void);
static bool s_ParticlesRegistered = false;
namespace
{
// Does what the generated REGISTER_RUNTIME_NODE/REGISTER_NODE static
// registrars do, but can run again. Those run once at DLL load, while the
// editor's plugin-only hot reload clears the shared node registries without
// unloading this package. DekiNodeGraph::NodeFactory overwrites by typeId and
// DekiNodeGraph::NodeTypeRegistry skips duplicates, so repeating is safe.
template <typename T>
void RegisterParticleNodeType()
{
DekiNodeGraph::SceneFormat::NodeFactory::Instance().Register(
Deki::HashString(T::StaticNodeName), []() -> void* { return new T(); },
[](void* p, Deki::SceneFormat::SceneMsgPackParser& parser, uint32_t mapSize) -> bool
{ return DeserializeMsgPack(*static_cast<T*>(p), parser, mapSize); },
[](void* p) { delete static_cast<T*>(p); });
DekiNodeGraph::NodeTypeRegistry::Instance().Register(&T::GetNodeMeta(), sizeof(DekiNodeGraph::DekiNodeMeta));
}
} // namespace
extern "C"
{
/// Registers this package's node graph types: modifier node factories,
/// editor metas and the Particles graph domain. Called at package load via
/// ::DekiPluginRegisterComponents, and again after any registry clear that
/// keeps this DLL loaded (plugin-only hot reload).
DEKI_PARTICLES_API void DekiParticlesRegisterGraphTypes(void)
{
RegisterParticleNodeType<ParticleEmitNode>();
RegisterParticleNodeType<ParticleEmissionNode>();
RegisterParticleNodeType<ParticleInitialVelocityNode>();
RegisterParticleNodeType<ParticleInitialRotationNode>();
RegisterParticleNodeType<ParticleGravityNode>();
RegisterParticleNodeType<ParticleDragNode>();
RegisterParticleNodeType<ParticleSizeOverLifetimeNode>();
RegisterParticleNodeType<ParticleColorOverLifetimeNode>();
RegisterParticleNodeType<ParticleRotationOverLifetimeNode>();
DekiParticlesRegisterEditorGraphDomain();
}
DEKI_PARTICLES_API int DekiParticlesEnsureRegistered(void)
{
if (s_ParticlesRegistered)
{
return ::DekiParticlesGetAutoComponentCount();
}
s_ParticlesRegistered = true;
::DekiParticlesRegisterComponents();
return ::DekiParticlesGetAutoComponentCount();
}
DEKI_PLUGIN_API const char* DekiPluginGetName(void)
{
return "Deki Particles Package";
}
DEKI_PLUGIN_API const char* DekiPluginGetVersion(void)
{
#ifdef DEKI_PACKAGE_VERSION
return DEKI_PACKAGE_VERSION;
#else
return "0.0.0-dev";
#endif
}
DEKI_PLUGIN_API int DekiPluginInit(void)
{
DekiParticlesInitSystem();
return 0;
}
DEKI_PLUGIN_API void DekiPluginShutdown(void)
{
s_ParticlesRegistered = false;
ParticleSystem::GetInstance().ClearAll();
}
DEKI_PLUGIN_API int DekiPluginGetComponentCount(void)
{
return ::DekiParticlesGetAutoComponentCount();
}
DEKI_PLUGIN_API const Deki::ComponentMeta* DekiPluginGetComponentMeta(int index)
{
return ::DekiParticlesGetAutoComponentMeta(index);
}
DEKI_PLUGIN_API void DekiPluginRegisterComponents(void)
{
DekiParticlesEnsureRegistered();
// Outside the s_ParticlesRegistered latch on purpose: every hot reload
// (full or plugin-only) clears the node registries, and this export is
// how they are filled again in the plugin-only case.
DekiParticlesRegisterGraphTypes();
}
DEKI_PLUGIN_API void DekiPluginOnPlayModeStop(void)
{
ParticleSystem::GetInstance().ClearAll();
}
// Package-specific API, named so linked DLLs do not clash.
DEKI_PARTICLES_API const char* DekiParticlesGetName(void)
{
return "Particles";
}
} // extern "C"
#endif // DEKI_EDITOR
} // namespace DekiParticles