Pictel 2d 0.1
Game Engine Documentation
Public Member Functions | List of all members
engine::EngineStateI Class Referenceabstract

Engine state holder. More...

Public Member Functions

virtual Size GetViewportSize ()=0
 
virtual void SetViewportSize (Size, float)=0
 
virtual void SetOnScreenSizeChangeHandler (std::function< void(Size, float)>)=0
 

Detailed Description

Engine state holder.

Holds various information on the state of the engine. This should be used to setup an observer for the screen size change so that the game has a chance to react and, maybe, change the viewport size.

The default implementation should register for screen size change event via EngineStateI::SetOnScreenSizeChangeHandler and provide the wanted viewport size via EngineStateI::SetViewportSize.

The code below takes the screen size provided in the handler and calcualtes and scale for the game leaving the viewport size unchanged.

auto engineState = engine::Globals::engineState()
engineState->SetOnScreenSizeChangeHandler([&](engine::Size size, float density) {
// have the wanted size ready somewhere
engine::Vector2 wantedSize = { 320, 200 };
// calcualte the scale provided we don't want to change the viewport size
float scale = MIN((float)size.width / wantedSize.x, (float)size.height / wantedSize.y);
// update the viewport size with the modified scale; this is a pixel-art
// game so it should scale by using nearest-neighbour
engineState->SetViewportSize({(int)wantedSize.x, (int)wantedSize.y}, scale);
});
virtual void SetOnScreenSizeChangeHandler(std::function< void(Size, float)>)=0
Definition: vector2.hpp:51

Member Function Documentation

◆ GetViewportSize()

virtual Size engine::EngineStateI::GetViewportSize ( )
pure virtual

Returns the viewport width and height. This is the desired viewport size and controls the size of the framebuffer texture. Is reflects what was set during initialization and what was modified throughout the course of the engine lifcycle.

◆ SetOnScreenSizeChangeHandler()

virtual void engine::EngineStateI::SetOnScreenSizeChangeHandler ( std::function< void(Size, float)>  )
pure virtual

Registers a screen size change. Once the screen size is changed this function will be callsed and the script will have an option to modify the desired viewport. That in turn might recreate the framebuffer texture size.

See also
EngineStateI::SetViewportSize

The lambda will receive the parameters:

  • size
  • screen density

◆ SetViewportSize()

virtual void engine::EngineStateI::SetViewportSize ( Size  ,
float   
)
pure virtual

Set the viewport & scale. This changes the target framebuffer texture size on the frame.