Cogs.Core
VectorFieldExtension.cpp
1#include "VectorFieldComponent.h"
2#include "VectorFieldSystem.h"
3
4#include "Context.h"
5#include "EntityDefinition.h"
6#include "EntityStore.h"
7#include "ExtensionRegistry.h"
8#include "ResourceManifest.h"
9#include "Resources/ResourceStore.h"
10
11namespace Cogs::Core::VectorField
12{
14 {
15 VectorFieldExtension() { ExtensionRegistry::add(this, COGS_CORE_VERSION_STRING); }
16
17 bool initializeStatic() override {
18 VectorFieldComponent::registerType();
19 return true;
20 }
21
22 bool initialize(Context *context) override {
23 const std::string resourceArchive = "Cogs.Core.Extensions.VectorField.zip";
24#ifdef EMSCRIPTEN
25 bool resourceArchiveAdded = false;
26 auto manifest = getResourceManifest(context);
27 for (auto& item : manifest) {
28 if (item.find(resourceArchive) != std::string::npos) {
29 context->resourceStore->addResourceArchive(item);
30 resourceArchiveAdded = true;
31 break;
32 }
33 }
34 if (!resourceArchiveAdded) {
35 context->resourceStore->addResourceArchive(resourceArchive);
36 }
37#else
38 context->resourceStore->addResourceArchive(resourceArchive);
39 context->resourceStore->addSearchPath("../Extensions/VectorField/Data/");
40#endif
41 EntityDefinition definition = {};
42 definition.name = "VectorField";
43 definition.components = std::vector<std::string>{ "TransformComponent", "SceneComponent", "VectorFieldComponent" };
44 context->store->addEntityDefinition(definition);
45
46 ExtensionRegistry::registerExtensionSystem<VectorFieldSystem>(context, SystemPriority::PreGeometry, 4);
47 return true;
48 }
49
50 const char * getExtensionKey() const override { return "VectorField"; }
51 } vectorFieldExtensionInstance;
52}// namespace ...
A Context instance contains all the services, systems and runtime components needed to use Cogs.
Definition: Context.h:83
class EntityStore * store
Entity store.
Definition: Context.h:231
std::unique_ptr< class ResourceStore > resourceStore
ResourceStore service instance.
Definition: Context.h:210
void addEntityDefinition(const EntityDefinition &definition)
Add the given entity definition to the store.
Definition: EntityStore.cpp:59
static void add(Extension *extension, StringView version)
Adds the given extension to the registry, ensuring the initialization methods are called at appropria...
Defines how to construct entities of a certain type by a list of components to instantiate and defaul...
std::vector< std::string > components
Names of the component types to instantiate when creating an entity from this definition.
Defines an extension to Cogs.Core and provides methods to override in order to initialize extension c...
@ PreGeometry
Run before geometry updates are performed.
Definition: Engine.h:68
const char * getExtensionKey() const override
Get the extensions unique key, used to check for extension presence and retrieve extension specific d...
bool initializeStatic() override
Initialize extension statically.
bool initialize(Context *context) override
Initialize extension for the given context.