Scene

namespace marengine
class Scene
#include “Core/ecs/Scene.h”

Scene has information about all important entities, has abilities to create and destroy entities Scene contains main class that rule them all - SceneRegistry. You can consider Scene as the game itself. If you want to create a new game, just create some entities, attach components to them and push them to rendering engine.

Public Functions

Scene() = delete

Default Constructor deleted, because we want to create registry explicitly.

Scene(std::string name)

Default Constructor, with which we assign sceneName and create scene registry.

void close()

Method is responsible for whole cleanup. It destroys all entities and registry itself.

const Entity &createEntity()

Method creates Entity at m_entities, assigns to it some basic components and returns it.

Return

created entity pushed to scene

void destroyEntity(const Entity &entity)

Method checks if given entity exists in m_entities, if so entity is being destroyed and popped from m_entities.

Parameters
  • entity: that will be deleted from current scene

const FEntityArray &getEntities() const

Method returns all entities.

Return

m_entities const reference to array of entities

void setName(std::string newSceneName)

Sets new scene name.

Parameters
  • new: name for current scene

const std::string &getName() const

Returns current scene name.

Return

current name scene

void setBackground(maths::vec3 newSceneBackgroundColor)

Sets scene background color value.

Parameters
  • new: vec3 background color for current scene

maths::vec3 getBackground() const

Returns scene background color value. Non-const method, because we want to modify it during editor mode / game mode.

Return

current background color

entt::registry *getRegistry()

Returns pointer to scene registry. Non-const, because it will be used by entities. Please, use this carefully.

Return

pointer to registry of the scene

template<typename TComponent>
auto getView()

Returns view at all entities that contains TComponent. View can be iterated with lambda [](entt::entity entt_entity, TComponent& component) {};.

Return

view for given TComponent

template<typename TComponent>
TComponent &getComponent(entt::entity entt_entity)

Returns component from entt::entity. Used only in lambda methods at view.

Return

reference to instance of entt_entity’s TComponent

Parameters
  • entt_entity: entity’s unique index

bool isValid(entt::entity enttEntity) const

Method checks, if entt::entity is valid one and returns result.

Return

returns true if entt::entity is valid (it exists and is fine).

Public Static Functions

Scene createEmptyScene(std::string sceneName)

Creates empty scene with cameraEntity and lightEntity. Two created entities by default:

  • cameraEntity (main camera assigned)

  • lightEntity (pointLight assigned) Scene is created on the heap using ‘new’, make sure to delete it when the job is done!

    Return

    created scene with “new” operator

    Parameters
    • sceneName: name of the new created scene

Private Members

std::string m_name = {"Empty Scene"}
FEntityArray m_entities
maths::vec3 m_backgroundColor = {0.22f, 0.69f, 0.87f}
entt::registry m_sceneRegistry