Cogs.Core
HighlightRegionExtension.cpp
1#include "Context.h"
2#include "ExtensionRegistry.h"
3#include "ResourceManifest.h"
4#include "Resources/ResourceStore.h"
5#include "Serialization/EntityReader.h"
6
7#include "Renderer/Tasks/RenderTaskFactory.h"
8
9#include "HighlightRegionComponent.h"
10#include "HighlightRegionSystem.h"
11#include "HighlightRegionRenderTask.h"
12
13namespace Cogs::Core {
14
16 {
18 ExtensionRegistry::add(this, COGS_CORE_VERSION_STRING);
19 }
20
21 bool initializeStatic() override;
22 bool initialize(Context* context) override;
23 void cleanup(Context* context) override;
24
25 const char* getExtensionKey() const override { return "HighlightRegion"; }
26 } highlightRegion;
27
28}
29
30namespace {
31 using namespace Cogs::Core;
32
33 RenderTask* createGuiRenderTask(RenderTaskContext*, const RenderTaskDefinition &, const PipelineOptions &)
34 {
35 return new HighlightRegionRenderTask();
36 }
37
38 void destroyGuiRenderTask(RenderTask** task, RenderTaskContext *)
39 {
40 if (HighlightRegionRenderTask* myTask = dynamic_cast<HighlightRegionRenderTask*>(*task); myTask) {
41 delete myTask;
42 *task = nullptr;
43 }
44 }
45
46}
47
48
50{
51 HighlightRegionComponent::registerType();
52 return true;
53}
54
56{
57 const std::string resourceArchive = "Cogs.Core.Extensions.HighlightRegion.zip";
58#ifdef EMSCRIPTEN
59 bool resourceArchiveAdded = false;
60 std::vector<std::string> manifest = getResourceManifest(context);
61 for (auto& item : manifest) {
62 if (item.find(resourceArchive) != std::string::npos) {
63 context->resourceStore->addResourceArchive(item);
64 resourceArchiveAdded = true;
65 break;
66 }
67 }
68 if (!resourceArchiveAdded) {
69 context->resourceStore->addResourceArchive(resourceArchive);
70 }
71#else
72 context->resourceStore->addSearchPath("../Extensions/HighlightRegion/Data/");
73 context->resourceStore->addResourceArchive(resourceArchive);
74#endif
75
76 readEntityDefinition(R"(
77{ "name": "HighlightRegion",
78 "components" : [
79 "HighlightRegionComponent",
80 "TransformComponent",
81 "SceneComponent",
82 ]
83})", context->store);
84
85 addTaskType("HighlightRegionRender", createGuiRenderTask, destroyGuiRenderTask);
86
87 ExtensionRegistry::registerExtensionSystem<HighlightRegionSystem>(context, SystemPriority::PreRendering, 8);
88 return true;
89}
90
92{
93}
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
static void add(Extension *extension, StringView version)
Adds the given extension to the registry, ensuring the initialization methods are called at appropria...
Contains the Engine, Renderer, resource managers and other systems needed to run Cogs....
Defines an extension to Cogs.Core and provides methods to override in order to initialize extension c...
void cleanup(Context *context) override
Cleanup context bound extension content.
bool initialize(Context *context) override
Initialize extension for the given context.
bool initializeStatic() override
Initialize extension statically.
const char * getExtensionKey() const override
Get the extensions unique key, used to check for extension presence and retrieve extension specific d...
@ PreRendering
Run before rendering is performed.
Definition: Engine.h:74