Infinity Engine v0.6.20
C++ API Documentation
Loading...
Searching...
No Matches
Plugin.hpp
1// INFINITY_API_PUBLIC
2
3#pragma once
4
5#include <Infinity/api.h>
6#include <Infinity/Plugin/API.h>
7#include <Infinity/Procedural/ProceduralComponent.hpp>
8#include <Infinity/Procedural/Registry.hpp>
9#include <Infinity/Util/unordered_dense.h>
10
11#include <string>
12#include <memory>
13
15{
31 {
32 public:
36 virtual ~ComponentLibrary() = default;
37
66 virtual void registerComponents() = 0;
67
74 ankerl::unordered_dense::map<Infinity::Procedural::ComponentID, std::pair<CreateComponentFunction*, DeleteComponentFunction*>> registrants;
75
76 protected:
84 template<typename T>
85 void registerComponent(const std::string& group, const std::string& name)
86 {
87 registerComponent<T>(Infinity::Procedural::ComponentID(group, name));
88 }
89
100 template<typename T>
102 {
103 static_assert(std::is_base_of<Infinity::Procedural::ProceduralComponent, T>::value,
104 "Registered component type must inherit from Infinity::Procedural::ProceduralComponent");
105
106 registrants.emplace(id, std::make_pair<CreateComponentFunction*, DeleteComponentFunction*>(
108 return new T(desc);
109 },
111 delete component;
112 }
113 ));
114 }
115 };
116}
117
147#define INFINITY_PLUGIN(FactoryClass) \
148 namespace { \
149 std::unique_ptr<FactoryClass> g_factory; \
150 } \
151 extern "C" { \
152 INFINITY_API_PLUGIN int plugin_get_api_version() { return INFINITY_PLUGIN_API_VERSION; } \
153 INFINITY_API_PLUGIN PluginHandle* plugin_create() { \
154 g_factory = std::make_unique<FactoryClass>(); \
155 g_factory->registerComponents(); \
156 return reinterpret_cast<PluginHandle*>(dynamic_cast<Infinity::Plugin::ComponentLibrary*>(g_factory.get())); \
157 } \
158 INFINITY_API_PLUGIN void plugin_destroy(PluginHandle* handle) { \
159 g_factory.reset(); \
160 } \
161 }
Base class for plugin component libraries that provide custom ProceduralComponents.
Definition Plugin.hpp:31
virtual void registerComponents()=0
Register all components provided by this plugin.
void registerComponent(const std::string &group, const std::string &name)
Registers a component type with the specified group and name.
Definition Plugin.hpp:85
void registerComponent(const Infinity::Procedural::ComponentID &id)
Registers a component type with the specified ComponentID.
Definition Plugin.hpp:101
ankerl::unordered_dense::map< Infinity::Procedural::ComponentID, std::pair< CreateComponentFunction *, DeleteComponentFunction * > > registrants
Registry mapping ComponentIDs to their creation and deletion functions.
Definition Plugin.hpp:74
virtual ~ComponentLibrary()=default
Virtual destructor.
Description and configuration data for a ProceduralComponent instance.
Definition ProceduralComponentDescription.hpp:48
Base class for procedural generation components.
Definition ProceduralComponent.hpp:73
Definition Plugin.hpp:15
Unique identifier for a procedural component.
Definition ComponentID.hpp:35