Kale
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
Kale::Application Class Reference

#include <Application.hpp>

Public Member Functions

 Application (const Application &other)=delete
 
 Application (Application &&other)=delete
 
void operator= (const Application &other)=delete
 
void operator= (Application &&other)=delete
 
WindowgetWindow () noexcept
 
std::shared_ptr< ScenegetPresentedScene () noexcept
 
const WindowgetWindow () const noexcept
 
std::shared_ptr< const ScenegetPresentedScene () const noexcept
 
void presentScene (const std::shared_ptr< Scene > &scene)
 
size_t getNumUpdateThreads () const noexcept
 
void runTaskOnMainThread (std::function< void()> task)
 
std::string getAssetFolderPath () const
 

Static Public Member Functions

static void addNodeSetupFunction (std::function< void()> func)
 
static void addNodeCleanupFunction (std::function< void()> func)
 

Public Attributes

const std::string applicationName
 

Protected Member Functions

virtual void onBegin ()
 
virtual void onEnd ()
 
void run () noexcept
 
 Application (const char *applicationName) noexcept
 
friend int::main ()
 

Protected Attributes

Window window
 

Private Member Functions

void update (size_t threadNum) noexcept
 
void synchronizeUpdate ()
 

Private Attributes

std::list< std::thread > updateThreads
 
std::queue< std::function< void()> > tasks
 
std::mutex threadSyncMutex
 
std::mutex taskManagerMutex
 
std::condition_variable threadSyncCondVar
 
std::condition_variable renderSyncCondVar
 
size_t numThreadsUpdated
 
bool updatingFinished
 
bool renderingFinished
 
float deltaTime
 
std::shared_ptr< ScenepresentedScene
 
std::shared_ptr< ScenesceneToPresent
 

Static Private Attributes

static std::vector< std::function< void()> > nodeSetupFuncs = { PathNode::setup }
 
static std::vector< std::function< void()> > nodeCleanupFuncs = { PathNode::cleanup }
 

Detailed Description

The main Application class

Definition at line 43 of file Application.hpp.

Constructor & Destructor Documentation

◆ Application() [1/3]

Application::Application ( const char * applicationName)
explicitprotectednoexcept

Creates a new application instance

Parameters
applicationNameThe name of your application

Definition at line 49 of file Application.cpp.

◆ Application() [2/3]

Kale::Application::Application ( const Application & other)
delete

◆ Application() [3/3]

Kale::Application::Application ( Application && other)
delete

Member Function Documentation

◆ addNodeCleanupFunction()

static void Kale::Application::addNodeCleanupFunction ( std::function< void()> func)
inlinestatic

Adds a node cleanup function to the list of methods to be called when cleaning up nodes Node cleanups are a one time process called prior to the application closing. It is done after application's onEnd

Parameters
funcThe function to be called

Definition at line 233 of file Application.hpp.

◆ addNodeSetupFunction()

static void Kale::Application::addNodeSetupFunction ( std::function< void()> func)
inlinestatic

Adds a node setup function to the list of methods to be called when setting up nodes Node setups are a one time process, called before any scene is loaded and after application's on begin

Parameters
funcThe function to be called

Definition at line 224 of file Application.hpp.

◆ getAssetFolderPath()

std::string Application::getAssetFolderPath ( ) const

Gets the path to the assets folder

Returns
The path to the assets folder

Definition at line 119 of file Application.cpp.

◆ getNumUpdateThreads()

size_t Application::getNumUpdateThreads ( ) const
noexcept

Gets the number of threads currently being used to update

Returns
The number of threads used for updating

Definition at line 93 of file Application.cpp.

◆ getPresentedScene() [1/2]

std::shared_ptr< const Scene > Application::getPresentedScene ( ) const
noexcept

Gets the currently presented scene

Returns
The currently presented scene pointer

Definition at line 85 of file Application.cpp.

◆ getPresentedScene() [2/2]

std::shared_ptr< Scene > Application::getPresentedScene ( )
noexcept

Gets the currently presented scene

Returns
The currently presented scene pointer

Definition at line 70 of file Application.cpp.

◆ getWindow() [1/2]

const Window & Application::getWindow ( ) const
noexcept

Gets the window

Returns
a pointer to the window

Gets the window

Definition at line 77 of file Application.cpp.

◆ getWindow() [2/2]

Window & Application::getWindow ( )
noexcept

Gets the window

Returns
a pointer to the window

Gets the window

Definition at line 62 of file Application.cpp.

◆ int::main()

Kale::Application::int::main ( )
protected

◆ onBegin()

virtual void Kale::Application::onBegin ( )
inlineprotectedvirtual

Called when the application begins, just before the window is run.

Definition at line 137 of file Application.hpp.

◆ onEnd()

virtual void Kale::Application::onEnd ( )
inlineprotectedvirtual

Called just before the application is ended

Definition at line 142 of file Application.hpp.

◆ operator=() [1/2]

void Kale::Application::operator= ( Application && other)
delete

◆ operator=() [2/2]

void Kale::Application::operator= ( const Application & other)
delete

◆ presentScene()

void Application::presentScene ( const std::shared_ptr< Scene > & scene)

Presents a given scene

Parameters
sceneThe scene to present

Definition at line 101 of file Application.cpp.

◆ run()

void Application::run ( )
protectednoexcept

Runs the application

Definition at line 168 of file Application.cpp.

◆ runTaskOnMainThread()

void Application::runTaskOnMainThread ( std::function< void()> task)

Runs a given task on the main thread prior to rendering on any given frame, Can be called on any thread

Note
Do not use reference based lambdas if anything referenced is at risk of being destroyed.
Parameters
taskA method which carries out any necessary task

Definition at line 110 of file Application.cpp.

◆ synchronizeUpdate()

void Application::synchronizeUpdate ( )
private

Synchronizes udpates

Definition at line 126 of file Application.cpp.

◆ update()

void Application::update ( size_t threadNum)
privatenoexcept

Handles updating the application in a separate thread

Parameters
threadNumthe index of this thread, ranged 0 - numUpdateThreads

Definition at line 144 of file Application.cpp.

Member Data Documentation

◆ applicationName

const std::string Kale::Application::applicationName

The name of the application the engine is being used for

Definition at line 162 of file Application.hpp.

◆ deltaTime

float Kale::Application::deltaTime
private

The time taken to update and render each frame, set at the end of every render

Definition at line 104 of file Application.hpp.

◆ nodeCleanupFuncs

std::vector< std::function< void()> > Application::nodeCleanupFuncs = { PathNode::cleanup }
staticprivate

A vector of cleanup functions required for individual nodes

Definition at line 54 of file Application.hpp.

◆ nodeSetupFuncs

std::vector< std::function< void()> > Application::nodeSetupFuncs = { PathNode::setup }
staticprivate

A vector of setup functions required for individual nodes

Definition at line 49 of file Application.hpp.

◆ numThreadsUpdated

size_t Kale::Application::numThreadsUpdated
private

Used for thread synchronization

Definition at line 89 of file Application.hpp.

◆ presentedScene

std::shared_ptr<Scene> Kale::Application::presentedScene
private

A pointer to the current scene to render

Definition at line 109 of file Application.hpp.

◆ renderingFinished

bool Kale::Application::renderingFinished
private

Used for thread synchronization

Definition at line 99 of file Application.hpp.

◆ renderSyncCondVar

std::condition_variable Kale::Application::renderSyncCondVar
private

Used for thread synchronization

Definition at line 84 of file Application.hpp.

◆ sceneToPresent

std::shared_ptr<Scene> Kale::Application::sceneToPresent
private

A pointer to the scene to be presented

Definition at line 114 of file Application.hpp.

◆ taskManagerMutex

std::mutex Kale::Application::taskManagerMutex
private

Used for synchronizing access to tasks across threads

Definition at line 74 of file Application.hpp.

◆ tasks

std::queue<std::function<void()> > Kale::Application::tasks
private

Stores all tasks required to be run

Definition at line 64 of file Application.hpp.

◆ threadSyncCondVar

std::condition_variable Kale::Application::threadSyncCondVar
private

Used for thread synchronization

Definition at line 79 of file Application.hpp.

◆ threadSyncMutex

std::mutex Kale::Application::threadSyncMutex
private

Used for thread synchronization

Definition at line 69 of file Application.hpp.

◆ updateThreads

std::list<std::thread> Kale::Application::updateThreads
private

A list of the update threads

Definition at line 59 of file Application.hpp.

◆ updatingFinished

bool Kale::Application::updatingFinished
private

Used for thread synchronization

Definition at line 94 of file Application.hpp.

◆ window

Window Kale::Application::window
protected

The main window used for rendering for this application instance

Definition at line 132 of file Application.hpp.


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