Skip to content

Vp::Scene

A scene representing a "game world" that contains entities and is viewed by a camera. More...

#include "Viewport/scene/Scene.h"

Inherited by Vp::MainScene, Vp::PreviewScene

Public Functions

Name
Scene(Viewport * viewport)
virtual~Scene() =default
template <typename T ,typename std::enable_if< std::is_base_of< Entity, T >::value, bool >::type =true&gt; <br>std::weak_ptr< T >addEntity(std::shared_ptr< T > entity)<br>Adds entity to the scene.
voidaddSelectionCallback(std::function< void(Entity *)> callback)
virtual Ptr< SceneRenderTarget >createRenderTarget(const RenderOptions & options)<br>Create and populates a SceneRenderTarget object with expected framebuffer objects for the scenes render pass.
virtual voiddraw(int width, int height, glm::mat4 view, glm::mat4 projection, SceneRenderTarget & renderTarget, const DisplayOptions & displayOptions)<br>Draw the scene using the provided view and projection matrices.
virtual voiddraw(int width, int height, SceneRenderTarget & renderTarget, const DisplayOptions & displayOptions)<br>Draw the scene using the scene's camera.
const std::vector< std::shared_ptr< Entity > > &getEntities() const
virtual voidinit()<br>Initialises the scene.
virtual voidloadSettings(ViewportSettings & stg, bool scene, bool global)
voidprocessInput(double dt, glm::vec2 mousePos, glm::ivec2 windowSize)<br>Update input logic.
voidprocessSelection(SceneRenderTarget & renderTarget, glm::vec2 mousePos, glm::ivec2 windowSize)<br>Update selection logic.
template <typename T ,typename std::enable_if< std::is_base_of< Entity, T >::value, bool >::type =true&gt; <br>voidremoveEntity(std::weak_ptr< T > entity)<br>Remove entity from the scene.
virtual voidsaveSettings(ViewportSettings & stg, bool scene, bool global)
voidtriggerSelectionCallbacks(Entity * entity)
virtual voidupdate(double dt)<br>Update entity logic.

Protected Functions

Name
voidrenderSortedTransparentEntities(glm::mat4 view, glm::mat4 projection, const std::vector< Entity * > & entities) const
voidsortExplicitlyOrderedTransparentEntities(std::vector< Entity * > & entities)
voidsortUnorderedTransparentEntities(glm::mat4 view, std::vector< Entity * > & entities)

Public Attributes

Name
std::shared_ptr< AbstractCamera >m_camera
std::shared_ptr< Lighting >m_lighting
std::shared_ptr< SelectStencil >m_selectStencil
Viewport *m_viewport

Protected Attributes

Name
std::vector< std::shared_ptr< Entity > >m_entities
std::vector< Entity * >m_explicitTransparencyOrderEntitiesFirst
std::vector< Entity * >m_explicitTransparencyOrderEntitiesLast
std::vector< Entity * >m_highlightedEntities
Entity *m_selectedEntity
std::vector< std::function< void(Entity *)> >m_selectionCallbacks <br>Callbacks that get triggered on entity selection.
std::vector< Entity * >m_unorderedTransparentEntities

Friends

Name
classViewport

Detailed Description

cpp
class Vp::Scene;
class Vp::Scene;

A scene representing a "game world" that contains entities and is viewed by a camera.

Handles drawing and logic updates.

Public Functions Documentation

function Scene

cpp
explicit Scene(
    Viewport * viewport
)
explicit Scene(
    Viewport * viewport
)

function ~Scene

cpp
virtual ~Scene() =default
virtual ~Scene() =default

function addEntity

cpp
template <typename T ,
typename std::enable_if< std::is_base_of< Entity, T >::value, bool >::type  =true>
inline std::weak_ptr< T > addEntity(
    std::shared_ptr< T > entity
)
template <typename T ,
typename std::enable_if< std::is_base_of< Entity, T >::value, bool >::type  =true>
inline std::weak_ptr< T > addEntity(
    std::shared_ptr< T > entity
)

Adds entity to the scene.

Parameters:

  • entity A shared pointer to the entity to add. This pointer should be destroyed afterwards.

Template Parameters:

Return: A weak pointer to the added entity of said type.

Entity is added via a shared pointer which is copied and stored. The original pointer should be discarded after this call and the weak reference can be further used.

function addSelectionCallback

cpp
inline void addSelectionCallback(
    std::function< void(Entity *)> callback
)
inline void addSelectionCallback(
    std::function< void(Entity *)> callback
)

function createRenderTarget

cpp
virtual Ptr< SceneRenderTarget > createRenderTarget(
    const RenderOptions & options
)
virtual Ptr< SceneRenderTarget > createRenderTarget(
    const RenderOptions & options
)

Create and populates a SceneRenderTarget object with expected framebuffer objects for the scenes render pass.

Parameters:

  • options Relevant render options to take into account during render target creation

Return: Owning pointer to the created render target object

Individual framebuffers are only identified by their index in the render target framebuffer array. It is expected that these indexes are kept track of somewhere else, or just expected to be a certain way.

function draw

cpp
virtual void draw(
    int width,
    int height,
    glm::mat4 view,
    glm::mat4 projection,
    SceneRenderTarget & renderTarget,
    const DisplayOptions & displayOptions
)
virtual void draw(
    int width,
    int height,
    glm::mat4 view,
    glm::mat4 projection,
    SceneRenderTarget & renderTarget,
    const DisplayOptions & displayOptions
)

Draw the scene using the provided view and projection matrices.

Reimplemented by: Vp::MainScene::draw

function draw

cpp
virtual void draw(
    int width,
    int height,
    SceneRenderTarget & renderTarget,
    const DisplayOptions & displayOptions
)
virtual void draw(
    int width,
    int height,
    SceneRenderTarget & renderTarget,
    const DisplayOptions & displayOptions
)

Draw the scene using the scene's camera.

Parameters:

  • width Width of the

Reimplemented by: Vp::MainScene::draw

function getEntities

cpp
inline const std::vector< std::shared_ptr< Entity > > & getEntities() const
inline const std::vector< std::shared_ptr< Entity > > & getEntities() const

function init

cpp
inline virtual void init()
inline virtual void init()

Initialises the scene.

Reimplemented by: Vp::MainScene::init, Vp::PreviewScene::init

Should be called before any draw operations.

function loadSettings

cpp
inline virtual void loadSettings(
    ViewportSettings & stg,
    bool scene,
    bool global
)
inline virtual void loadSettings(
    ViewportSettings & stg,
    bool scene,
    bool global
)

Reimplemented by: Vp::MainScene::loadSettings

function processInput

cpp
void processInput(
    double dt,
    glm::vec2 mousePos,
    glm::ivec2 windowSize
)
void processInput(
    double dt,
    glm::vec2 mousePos,
    glm::ivec2 windowSize
)

Update input logic.

Parameters:

  • dt Time since last frame
  • mousePos Current mouse position relative to the window
  • windowSize Current window size

function processSelection

cpp
void processSelection(
    SceneRenderTarget & renderTarget,
    glm::vec2 mousePos,
    glm::ivec2 windowSize
)
void processSelection(
    SceneRenderTarget & renderTarget,
    glm::vec2 mousePos,
    glm::ivec2 windowSize
)

Update selection logic.

Parameters:

  • diwne
  • renderTarget Scene's render target
  • mousePos Current mouse position relative to the window
  • windowSize Current window size

function removeEntity

cpp
template <typename T ,
typename std::enable_if< std::is_base_of< Entity, T >::value, bool >::type  =true>
inline void removeEntity(
    std::weak_ptr< T > entity
)
template <typename T ,
typename std::enable_if< std::is_base_of< Entity, T >::value, bool >::type  =true>
inline void removeEntity(
    std::weak_ptr< T > entity
)

Remove entity from the scene.

Parameters:

  • entity

Template Parameters:

The entity is passed as a weak pointer previously acquired by addEntity()

function saveSettings

cpp
inline virtual void saveSettings(
    ViewportSettings & stg,
    bool scene,
    bool global
)
inline virtual void saveSettings(
    ViewportSettings & stg,
    bool scene,
    bool global
)

Reimplemented by: Vp::MainScene::saveSettings

function triggerSelectionCallbacks

cpp
void triggerSelectionCallbacks(
    Entity * entity
)
void triggerSelectionCallbacks(
    Entity * entity
)

function update

cpp
virtual void update(
    double dt
)
virtual void update(
    double dt
)

Update entity logic.

Reimplemented by: Vp::MainScene::update

Protected Functions Documentation

function renderSortedTransparentEntities

cpp
void renderSortedTransparentEntities(
    glm::mat4 view,
    glm::mat4 projection,
    const std::vector< Entity * > & entities
) const
void renderSortedTransparentEntities(
    glm::mat4 view,
    glm::mat4 projection,
    const std::vector< Entity * > & entities
) const

function sortExplicitlyOrderedTransparentEntities

cpp
void sortExplicitlyOrderedTransparentEntities(
    std::vector< Entity * > & entities
)
void sortExplicitlyOrderedTransparentEntities(
    std::vector< Entity * > & entities
)

function sortUnorderedTransparentEntities

cpp
void sortUnorderedTransparentEntities(
    glm::mat4 view,
    std::vector< Entity * > & entities
)
void sortUnorderedTransparentEntities(
    glm::mat4 view,
    std::vector< Entity * > & entities
)

Public Attributes Documentation

variable m_camera

cpp
std::shared_ptr< AbstractCamera > m_camera;
std::shared_ptr< AbstractCamera > m_camera;

variable m_lighting

cpp
std::shared_ptr< Lighting > m_lighting;
std::shared_ptr< Lighting > m_lighting;

variable m_selectStencil

cpp
std::shared_ptr< SelectStencil > m_selectStencil;
std::shared_ptr< SelectStencil > m_selectStencil;

variable m_viewport

cpp
Viewport * m_viewport;
Viewport * m_viewport;

Protected Attributes Documentation

variable m_entities

cpp
std::vector< std::shared_ptr< Entity > > m_entities;
std::vector< std::shared_ptr< Entity > > m_entities;

variable m_explicitTransparencyOrderEntitiesFirst

cpp
std::vector< Entity * > m_explicitTransparencyOrderEntitiesFirst;
std::vector< Entity * > m_explicitTransparencyOrderEntitiesFirst;

variable m_explicitTransparencyOrderEntitiesLast

cpp
std::vector< Entity * > m_explicitTransparencyOrderEntitiesLast;
std::vector< Entity * > m_explicitTransparencyOrderEntitiesLast;

variable m_highlightedEntities

cpp
std::vector< Entity * > m_highlightedEntities;
std::vector< Entity * > m_highlightedEntities;

variable m_selectedEntity

cpp
Entity * m_selectedEntity = nullptr;
Entity * m_selectedEntity = nullptr;

variable m_selectionCallbacks

cpp
std::vector< std::function< void(Entity *)> > m_selectionCallbacks;
std::vector< std::function< void(Entity *)> > m_selectionCallbacks;

Callbacks that get triggered on entity selection.

variable m_unorderedTransparentEntities

cpp
std::vector< Entity * > m_unorderedTransparentEntities;
std::vector< Entity * > m_unorderedTransparentEntities;

Friends

friend Viewport

cpp
friend class Viewport(
    Viewport 
);
friend class Viewport(
    Viewport 
);

Updated on 2024-03-16 at 19:15:01 +0000