cangine
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | List of all members
cangine::CangineApp Class Reference

Base application class that owns the window and main loop. More...

#include <cangine.hpp>

Collaboration diagram for cangine::CangineApp:
Collaboration graph
[legend]

Public Member Functions

 CangineApp (int windowWidth=800, int windowHeight=600, std::string windowTitle="cangine window", bool fullscreen=false, Color windowFillColor=Colors::BLACK, std::string defaultShaderName="default")
 Constructs the application and all its subsystems.
 
 ~CangineApp ()
 
virtual void onFirstFrame ()
 Override to run setup logic on the first frame.
 
virtual void onFrame (double dt)
 Override to run per-frame game logic.
 
template<typename T , typename... Args>
T * instantiateObject (Args &&... args)
 Instantiates a game object of a derived type.
 
void run ()
 Runs the main loop until the window is closed.
 

Public Attributes

Color windowFillColor
 Color the window is cleared to each frame.
 
Window * window
 The application window.
 
AudioManager * audioMan = nullptr
 Owned audio manager.
 

Private Member Functions

void initShader (std::string name)
 Loads and initializes the default shader.
 
void initRenderSystem ()
 Creates the render system.
 
void initObjectManager ()
 Creates the object manager.
 
void initAudioManager ()
 Creates the audio manager.
 

Private Attributes

bool isFirstFrame = true
 Whether the next frame is the first one.
 
Shader * shader
 Default shader used for rendering.
 
RenderSystem * _rs = nullptr
 Owned render system.
 
ObjectManager * _om = nullptr
 Owned object manager.
 

Detailed Description

Base application class that owns the window and main loop.

Subclass it and override onFirstFrame and onFrame to build a game. The constructor sets up the window, shader, render system, object manager and audio manager; run drives the frame loop until the window closes.

Constructor & Destructor Documentation

◆ CangineApp()

cangine::CangineApp::CangineApp ( int  windowWidth = 800,
int  windowHeight = 600,
std::string  windowTitle = "cangine window",
bool  fullscreen = false,
Color  windowFillColor = Colors::BLACK,
std::string  defaultShaderName = "default" 
)

Constructs the application and all its subsystems.

Parameters
windowWidthInitial window width in pixels.
windowHeightInitial window height in pixels.
windowTitleWindow title.
fullscreenWhether to open in fullscreen mode.
windowFillColorColor the window is cleared to each frame.
defaultShaderNameBase name of the default shader to load.

◆ ~CangineApp()

cangine::CangineApp::~CangineApp ( )

Member Function Documentation

◆ initAudioManager()

void cangine::CangineApp::initAudioManager ( )
private

Creates the audio manager.

◆ initObjectManager()

void cangine::CangineApp::initObjectManager ( )
private

Creates the object manager.

◆ initRenderSystem()

void cangine::CangineApp::initRenderSystem ( )
private

Creates the render system.

◆ initShader()

void cangine::CangineApp::initShader ( std::string  name)
private

Loads and initializes the default shader.

Parameters
nameBase name of the shader to load.

◆ instantiateObject()

template<typename T , typename... Args>
T * cangine::CangineApp::instantiateObject ( Args &&...  args)
inline

Instantiates a game object of a derived type.

Statically asserts that T derives from GameObject.

Template Parameters
TObject type to create (must derive from GameObject).
ArgsConstructor argument types.
Parameters
argsArguments forwarded to the object's constructor.
Returns
Pointer to the newly created object.

◆ onFirstFrame()

virtual void cangine::CangineApp::onFirstFrame ( )
inlinevirtual

Override to run setup logic on the first frame.

◆ onFrame()

virtual void cangine::CangineApp::onFrame ( double  dt)
inlinevirtual

Override to run per-frame game logic.

Parameters
dtSeconds elapsed since the previous frame.

◆ run()

void cangine::CangineApp::run ( )

Runs the main loop until the window is closed.

Member Data Documentation

◆ _om

ObjectManager* cangine::CangineApp::_om = nullptr
private

Owned object manager.

◆ _rs

RenderSystem* cangine::CangineApp::_rs = nullptr
private

Owned render system.

◆ audioMan

AudioManager* cangine::CangineApp::audioMan = nullptr

Owned audio manager.

◆ isFirstFrame

bool cangine::CangineApp::isFirstFrame = true
private

Whether the next frame is the first one.

◆ shader

Shader* cangine::CangineApp::shader
private

Default shader used for rendering.

◆ window

Window* cangine::CangineApp::window

The application window.

◆ windowFillColor

Color cangine::CangineApp::windowFillColor

Color the window is cleared to each frame.


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