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> <br>std::weak_ptr< T > | addEntity(std::shared_ptr< T > entity)<br>Adds entity to the scene. |
void | addSelectionCallback(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 void | draw(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 void | draw(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 void | init()<br>Initialises the scene. |
virtual void | loadSettings(ViewportSettings & stg, bool scene, bool global) |
void | processInput(double dt, glm::vec2 mousePos, glm::ivec2 windowSize)<br>Update input logic. |
void | processSelection(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> <br>void | removeEntity(std::weak_ptr< T > entity)<br>Remove entity from the scene. |
virtual void | saveSettings(ViewportSettings & stg, bool scene, bool global) |
void | triggerSelectionCallbacks(Entity * entity) |
virtual void | update(double dt)<br>Update entity logic. |
Protected Functions
Name | |
---|---|
void | renderSortedTransparentEntities(glm::mat4 view, glm::mat4 projection, const std::vector< Entity * > & entities) const |
void | sortExplicitlyOrderedTransparentEntities(std::vector< Entity * > & entities) |
void | sortUnorderedTransparentEntities(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 | |
---|---|
class | Viewport |
Detailed Description
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
explicit Scene(
Viewport * viewport
)
explicit Scene(
Viewport * viewport
)
function ~Scene
virtual ~Scene() =default
virtual ~Scene() =default
function addEntity
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:
- T Any derived type of Entity
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
inline void addSelectionCallback(
std::function< void(Entity *)> callback
)
inline void addSelectionCallback(
std::function< void(Entity *)> callback
)
function createRenderTarget
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
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
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
inline const std::vector< std::shared_ptr< Entity > > & getEntities() const
inline const std::vector< std::shared_ptr< Entity > > & getEntities() const
function init
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
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
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
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
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:
- T Any derived type of Entity
The entity is passed as a weak pointer previously acquired by addEntity()
function saveSettings
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
void triggerSelectionCallbacks(
Entity * entity
)
void triggerSelectionCallbacks(
Entity * entity
)
function update
virtual void update(
double dt
)
virtual void update(
double dt
)
Update entity logic.
Reimplemented by: Vp::MainScene::update
Protected Functions Documentation
function renderSortedTransparentEntities
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
void sortExplicitlyOrderedTransparentEntities(
std::vector< Entity * > & entities
)
void sortExplicitlyOrderedTransparentEntities(
std::vector< Entity * > & entities
)
function sortUnorderedTransparentEntities
void sortUnorderedTransparentEntities(
glm::mat4 view,
std::vector< Entity * > & entities
)
void sortUnorderedTransparentEntities(
glm::mat4 view,
std::vector< Entity * > & entities
)
Public Attributes Documentation
variable m_camera
std::shared_ptr< AbstractCamera > m_camera;
std::shared_ptr< AbstractCamera > m_camera;
variable m_lighting
std::shared_ptr< Lighting > m_lighting;
std::shared_ptr< Lighting > m_lighting;
variable m_selectStencil
std::shared_ptr< SelectStencil > m_selectStencil;
std::shared_ptr< SelectStencil > m_selectStencil;
variable m_viewport
Viewport * m_viewport;
Viewport * m_viewport;
Protected Attributes Documentation
variable m_entities
std::vector< std::shared_ptr< Entity > > m_entities;
std::vector< std::shared_ptr< Entity > > m_entities;
variable m_explicitTransparencyOrderEntitiesFirst
std::vector< Entity * > m_explicitTransparencyOrderEntitiesFirst;
std::vector< Entity * > m_explicitTransparencyOrderEntitiesFirst;
variable m_explicitTransparencyOrderEntitiesLast
std::vector< Entity * > m_explicitTransparencyOrderEntitiesLast;
std::vector< Entity * > m_explicitTransparencyOrderEntitiesLast;
variable m_highlightedEntities
std::vector< Entity * > m_highlightedEntities;
std::vector< Entity * > m_highlightedEntities;
variable m_selectedEntity
Entity * m_selectedEntity = nullptr;
Entity * m_selectedEntity = nullptr;
variable m_selectionCallbacks
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
std::vector< Entity * > m_unorderedTransparentEntities;
std::vector< Entity * > m_unorderedTransparentEntities;
Friends
friend Viewport
friend class Viewport(
Viewport
);
friend class Viewport(
Viewport
);
Updated on 2024-11-06 at 20:16:53 +0000