Foray Library
rapid prototyping framework for crossplatform development of vulkan hardware ray tracing applications
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
foray::base::RenderLoop Class Reference

Manages a single threaded, automatically balancing application lifetime. More...

#include <foray_renderloop.hpp>

Classes

struct  FrameTime
 
struct  FrameTimeAnalysis
 Analysis. More...
 
struct  RenderInfo
 

Public Types

using InitFunctionPointer = std::function< void()>
 Function pointer for application initialization.
 
using RenderFunctionPointer = std::function< void(RenderInfo &)>
 Function pointer for a single frame render action. Param#0 : Delta time in seconds.
 
using RenderReadyFunctionPointer = std::function< bool()>
 Function pointer for the RenderLoop to check if application is ready to render next frame. Return true if ready.
 
using DestroyFunctionPointer = std::function< void()>
 Function pointer for application finalization.
 
using PollEventsFunctionPointer = std::function< void()>
 Function pointer for system event polling and handling.
 
using OnStateChangedFunctionPointer = std::function< void(ELifetimeState, ELifetimeState)>
 Function pointer for a callback when the renderloops state changes. Param#0: Old state Param#1: Next state.
 

Public Member Functions

 RenderLoop ()=default
 
 RenderLoop (InitFunctionPointer initFunc, RenderFunctionPointer renderFunc, RenderReadyFunctionPointer renderReadyFunc, DestroyFunctionPointer destroyFunc, PollEventsFunctionPointer pollEventsFunc, OnStateChangedFunctionPointer onStateChangedFunc)
 Constructor.
 
int32_t Run ()
 Runs the application through its full lifetime, invoking all function pointers which have been set.
 
void RequestStop (int32_t runResult=0)
 Request the finalization of the application as soon as possible.
 
bool IsRunning () const
 Returns true, if the internal state is ELifetimeState::Running; false otherwise.
 
FrameTimeAnalysis AnalyseFrameTimes () const
 Analyse all stored frame times. Note: MaxFrameTimeAge member determines maximum possible frame time age.
 
void GetFrameTimes (std::vector< fp32_t > &outFrameTimes) const
 Get all stored frame times (in seconds) by pushing them on the vector.
 
RenderLoopSetInitFunc (InitFunctionPointer func)
 
RenderLoopSetRenderFunc (RenderFunctionPointer func)
 
RenderLoopSetRenderReadyFunc (RenderReadyFunctionPointer func)
 
RenderLoopSetDestroyFunc (DestroyFunctionPointer func)
 
RenderLoopSetPollEventsFunc (PollEventsFunctionPointer func)
 
RenderLoopSetOnStateChangedFunc (OnStateChangedFunctionPointer func)
 

Protected Member Functions

void AdvanceState ()
 

Protected Attributes

InitFunctionPointer mInitFunc = nullptr
 
RenderFunctionPointer mRenderFunc = nullptr
 
RenderReadyFunctionPointer mRenderReadyFunc = nullptr
 
DestroyFunctionPointer mDestroyFunc = nullptr
 
PollEventsFunctionPointer mPollEventsFunc = nullptr
 
OnStateChangedFunctionPointer mOnStateChangedFunc = nullptr
 
ELifetimeState mState = ELifetimeState::PreInit
 
int32_t mRunResult = 0
 
AppFrameTiming mFrameTiming
 
uint64_t mRenderedFrameCount = 0
 
std::list< FrameTimemFrameTimes
 
fp32_t mMaxFrameTimeAge = 1.f
 

Detailed Description

Manages a single threaded, automatically balancing application lifetime.

Member Typedef Documentation

◆ DestroyFunctionPointer

using foray::base::RenderLoop::DestroyFunctionPointer = std::function<void()>

Function pointer for application finalization.

◆ InitFunctionPointer

using foray::base::RenderLoop::InitFunctionPointer = std::function<void()>

Function pointer for application initialization.

◆ OnStateChangedFunctionPointer

Function pointer for a callback when the renderloops state changes. Param#0: Old state Param#1: Next state.

◆ PollEventsFunctionPointer

Function pointer for system event polling and handling.

◆ RenderFunctionPointer

Function pointer for a single frame render action. Param#0 : Delta time in seconds.

◆ RenderReadyFunctionPointer

Function pointer for the RenderLoop to check if application is ready to render next frame. Return true if ready.

Constructor & Destructor Documentation

◆ RenderLoop() [1/2]

foray::base::RenderLoop::RenderLoop ( )
inlinedefault

◆ RenderLoop() [2/2]

foray::base::RenderLoop::RenderLoop ( InitFunctionPointer  initFunc,
RenderFunctionPointer  renderFunc,
RenderReadyFunctionPointer  renderReadyFunc,
DestroyFunctionPointer  destroyFunc,
PollEventsFunctionPointer  pollEventsFunc,
OnStateChangedFunctionPointer  onStateChangedFunc 
)
inline

Constructor.

Parameters
initFuncFunction called once to initialize the application
renderFuncFunction called once per frame to render the application
renderReadyFuncFunction called 1...x times per frame to check if the application is ready for the next frame
destroyFuncFunction called once to destroy application resources
pollEventsFuncFunction called 1...x times per frame to poll and handle system events
onStateChangedFuncFunction called everytime the renderloop state changes

Member Function Documentation

◆ AdvanceState()

void foray::base::RenderLoop::AdvanceState ( )
protected

◆ AnalyseFrameTimes()

FrameTimeAnalysis foray::base::RenderLoop::AnalyseFrameTimes ( ) const

Analyse all stored frame times. Note: MaxFrameTimeAge member determines maximum possible frame time age.

◆ GetFrameTimes()

void foray::base::RenderLoop::GetFrameTimes ( std::vector< fp32_t > &  outFrameTimes) const

Get all stored frame times (in seconds) by pushing them on the vector.

◆ IsRunning()

bool foray::base::RenderLoop::IsRunning ( ) const

Returns true, if the internal state is ELifetimeState::Running; false otherwise.

◆ RequestStop()

void foray::base::RenderLoop::RequestStop ( int32_t  runResult = 0)

Request the finalization of the application as soon as possible.

Parameters
runResultThe result the encompassing Run() call should return

◆ Run()

int32_t foray::base::RenderLoop::Run ( )

Runs the application through its full lifetime, invoking all function pointers which have been set.

Returns
The runResult value from RequestStop, or -1 on catched exception

◆ SetDestroyFunc()

RenderLoop & foray::base::RenderLoop::SetDestroyFunc ( DestroyFunctionPointer  func)

◆ SetInitFunc()

RenderLoop & foray::base::RenderLoop::SetInitFunc ( InitFunctionPointer  func)

◆ SetOnStateChangedFunc()

RenderLoop & foray::base::RenderLoop::SetOnStateChangedFunc ( OnStateChangedFunctionPointer  func)

◆ SetPollEventsFunc()

RenderLoop & foray::base::RenderLoop::SetPollEventsFunc ( PollEventsFunctionPointer  func)

◆ SetRenderFunc()

RenderLoop & foray::base::RenderLoop::SetRenderFunc ( RenderFunctionPointer  func)

◆ SetRenderReadyFunc()

RenderLoop & foray::base::RenderLoop::SetRenderReadyFunc ( RenderReadyFunctionPointer  func)

Member Data Documentation

◆ mDestroyFunc

DestroyFunctionPointer foray::base::RenderLoop::mDestroyFunc = nullptr
protected

◆ mFrameTimes

std::list<FrameTime> foray::base::RenderLoop::mFrameTimes
protected

◆ mFrameTiming

AppFrameTiming foray::base::RenderLoop::mFrameTiming
protected

◆ mInitFunc

InitFunctionPointer foray::base::RenderLoop::mInitFunc = nullptr
protected

◆ mMaxFrameTimeAge

fp32_t foray::base::RenderLoop::mMaxFrameTimeAge = 1.f
protected

◆ mOnStateChangedFunc

OnStateChangedFunctionPointer foray::base::RenderLoop::mOnStateChangedFunc = nullptr
protected

◆ mPollEventsFunc

PollEventsFunctionPointer foray::base::RenderLoop::mPollEventsFunc = nullptr
protected

◆ mRenderedFrameCount

uint64_t foray::base::RenderLoop::mRenderedFrameCount = 0
protected

◆ mRenderFunc

RenderFunctionPointer foray::base::RenderLoop::mRenderFunc = nullptr
protected

◆ mRenderReadyFunc

RenderReadyFunctionPointer foray::base::RenderLoop::mRenderReadyFunc = nullptr
protected

◆ mRunResult

int32_t foray::base::RenderLoop::mRunResult = 0
protected

◆ mState

ELifetimeState foray::base::RenderLoop::mState = ELifetimeState::PreInit
protected

The documentation for this class was generated from the following file: