Cogs.Core
TexAtlasExtension.cpp
1#include "Context.h"
2#include "ExtensionRegistry.h"
3#include "Resources/ResourceStore.h"
4#include "ResourceManifest.h"
5#include "Serialization/EntityReader.h"
6
7#include "Resources/MaterialManager.h"
8
9#include "TexAtlasComponent.h"
10#include "TexAtlasSystem.h"
11
12
13namespace Cogs::Core {
14
16 {
18 ExtensionRegistry::add(this, COGS_CORE_VERSION_STRING);
19 }
20
21 bool initializeStatic() override
22 {
23 TexAtlasComponent::registerType();
24 return true;
25 }
26
27 bool initialize(Context* context) override
28 {
29 const std::string resourceArchive = "Cogs.Core.Extensions.TexAtlas.zip";
30
31#ifdef __EMSCRIPTEN__
32 bool resourceArchiveAdded = false;
33 auto manifest = getResourceManifest(context);
34 for (auto& item : manifest) {
35 if (item.find(resourceArchive) != std::string::npos) {
36 context->resourceStore->addResourceArchive(item);
37 resourceArchiveAdded = true;
38 break;
39 }
40 }
41 if (!resourceArchiveAdded) {
42 context->resourceStore->addResourceArchive(resourceArchive);
43 }
44#else
45 context->resourceStore->addSearchPath("../Extensions/TexAtlas/Data/");
46 context->resourceStore->addResourceArchive(resourceArchive);
47#endif
48
49 // Load the extension materials so they can be inherited from.
50 context->materialManager->loadMaterial("Materials/TexAtlas.material");
51
52
53 readEntityDefinition(R"(
54{ "name": "TexAtlas",
55 "components" : [
56 "TexAtlasComponent",
57 "TransformComponent",
58 "SceneComponent",
59 ]
60})", context->store);
61
62 ExtensionRegistry::registerExtensionSystem<TexAtlasSystem>(context, SystemPriority::PostView, 8);
63 return true;
64 }
65
66
67 const char* getExtensionKey() const override { return "TexAtlas"; }
68 } texAtlasExtensionInstance;
69
70}
71
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...
@ PostView
Run after view data has been updated. Anything after this is appropriate for geometry depending on e....
Definition: Engine.h:66
bool initializeStatic() override
Initialize extension statically.
bool initialize(Context *context) override
Initialize extension for the given context.
const char * getExtensionKey() const override
Get the extensions unique key, used to check for extension presence and retrieve extension specific d...