3#include "Foundation/Logging/Logger.h"
7#include "EntityStore.h"
9#include "Services/Variables.h"
10#include "Services/TaskManager.h"
12#include "Systems/Core/TransformSystem.h"
13#include "Systems/Core/CameraSystem.h"
14#include "Systems/Core/FogSystem.h"
15#include "Systems/Core/EnvironmentSystem.h"
17#include "Serialization/AssetReader.h"
24Cogs::Core::Scene::Scene(Context * context) : context(context)
31 if (readDefaultScene && context->
variables->get(
"noDefaultScene")->isEmpty()) {
38 LOG_WARNING(logger,
"Default camera missing. Creating fallback camera.");
45 if (!cameraComponent) {
46 LOG_ERROR(logger,
"Default camera invalid. No CameraComponent. Adding fallback.");
48 cameraComponent = context->cameraSystem->createComponent();
49 camera->addComponent(cameraComponent);
53 LOG_ERROR(logger,
"Default camera invalid. No TransformComponent. Adding fallback.");
58 context->cameraSystem->setMainCamera(cameraComponent);
59 context->getDefaultView()->
setCamera(camera);
68 LOG_ERROR(logger,
"Entity 'Fog' expected to have FogComponent.");
72 context->fogSystem->setGlobalFog(fogComponent);
78 if (!environmentComponent) {
79 LOG_ERROR(logger,
"Entity 'Environment' expected to have EnvironmentComponent.");
83 context->environmentSystem->setGlobalEnvironment(environmentComponent);
88 sceneResources.clear();
90 context->taskManager->waitAll();
92 context->store->clear();
94 context->engine->clearResources();
96 context->engine->initializeResources();
101 sceneResources.emplace_back(resource);
ComponentHandle createComponent() override
class EntityStore * store
Entity store.
std::unique_ptr< class Variables > variables
Variables service instance.
EntityPtr getEntity(const StringView &name, bool logIfNotFound=true) const
Retrieve a reference to the shared entity pointer to the Entity with the given name.
EntityPtr createEntity(const StringView &name, const StringView &type, bool storeOwnership=true)
Create a new Entity.
Contains data to describe fog.
void clear()
Clear the scene contents, emptying the entity store of top level entities.
void setup(bool readDefaultScene)
Setup default scene components.
void addResource(ResourceHandleBase &resource)
Adds a resource to be handled with the lifetime of the scene.
void setCamera(const Cogs::Core::EntityPtr &renderCamera)
Sets or updates the camera of this ViewContext instance.
Log implementation class.
std::shared_ptr< ComponentModel::Entity > EntityPtr
Smart pointer for Entity access.
@ NoDefault
Don't load the default scene. Highly recommended as not setting this flag cause extra scene parse.
constexpr Log getLogger(const char(&name)[LEN]) noexcept
Handle to a Component instance.
ComponentType * resolveComponent() const
Resource handle base class handling reference counting of resources derived from ResourceBase.