xyginext  0.2.0
Second generation of xygine game creation framework
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Friends | List of all members
xy::App Class Referenceabstract

Abstract base class for new games or applications. More...

#include <App.hpp>

Classes

struct  VideoSettings
 VideoSettings struct. More...
 

Public Member Functions

 App (sf::ContextSettings contextSettings=sf::ContextSettings())
 Constructor. More...
 
 App (const App &)=delete
 
 App (App &&)=delete
 
Appoperator= (const App &)=delete
 
Appoperator= (App &&)=delete
 
void run ()
 Starts the application. More...
 
void pause ()
 Pauses the app's logic update function.
 
void resume ()
 Resumes the app's update function, if it is paused.
 
const VideoSettingsgetVideoSettings () const
 Returns a reference to a struct containing the current Video settings.
 
void applyVideoSettings (const VideoSettings &)
 Applies a given set of video settings. More...
 
MessageBusgetMessageBus ()
 Returns a reference to the message bus. More...
 
void setWindowTitle (const std::string &)
 Sets the window title. Prefer this when setting the window title over setting it directly as it will ensure the title is maintained when switching video modes.
 
void setWindowIcon (const std::string &)
 Sets the window icon. This should be a path to a 16x16px image on most platforms, although on macOS this icon should be larger as it appears in the dock. Prefer this to setting the icon directly on the window object, as it will make sure to maintain the icon when video modes are modified.
 
void setApplicationName (const std::string &name)
 Sets the application name. This is used when reading/writing config files such as window settings to the current user directory. A directory with this name is created to store the configurations files, and so should be unique to the application to prevent cross pollution of settings between xygine apps. This is set to "xygine_application" by default.
 
const std::string & getApplicationName () const
 Returns the current application name string.
 

Static Public Member Functions

static void quit ()
 Quits the application.
 
static void setClearColour (sf::Color)
 Sets the clear colour for the render window. Defaults to sf::Color::Black.
 
static sf::Color getClearColour ()
 Gets the current clear colour of the app render window.
 
static sf::RenderWindow * getRenderWindow ()
 Returns a reference to the current render window.
 
static void printStat (const std::string &, const std::string &)
 Prints the name/value pair to the stats window.
 
static AppgetActiveInstance ()
 Returns a reference to the active App instance.
 
static void setMouseCursorVisible (bool)
 Sets whether or not the mouse cursor should be visible. Prefer this rather than setting on the render window directly to prevent ImGUI settings overriding the window setting.
 
static bool isMouseCursorVisible ()
 Returns whether or not the mouse cursor is set to be visible.
 

Protected Member Functions

virtual void handleEvent (const sf::Event &)=0
 Function for despatching all window events. More...
 
virtual void handleMessage (const Message &)=0
 Function for despatching messages received by the message bus. More...
 
virtual void registerStates ()=0
 Registers a custom state with a state stack. More...
 
virtual void updateApp (float dt)=0
 Updates derived applications with the elapsed frame time during the game loop. More...
 
virtual void draw ()=0
 Draws to the render window. All drawing operations should be started from here. clear() and display() are called automatically by xygine and need to be manually used in derived applications.
 
virtual bool initialise ()
 Called when the application is first run. More...
 
virtual void finalise ()
 Called when the application shuts down. More...
 

Friends

class GuiClient
 
class Console
 

Detailed Description

Abstract base class for new games or applications.

When creating a new game or application this class provides management for basic proeprties such as video settings and event handling. All events and system messages are despatched from here so that they are available across the entire application.

Constructor & Destructor Documentation

◆ App()

xy::App::App ( sf::ContextSettings  contextSettings = sf::ContextSettings())

Constructor.

Parameters
sf::ContextSettings.Default context settings are supplied when inherting the App class, but provide the option to request a specific context if needed.

Member Function Documentation

◆ applyVideoSettings()

void xy::App::applyVideoSettings ( const VideoSettings )

Applies a given set of video settings.

This is the preferred method for resizing the window, as SFML does not raise Resized events when calling Window::setSize(). This function ensures a message is posted to the message bus in such cases, so that active scenes and states can correctly re-calculate the render view.

◆ finalise()

virtual void xy::App::finalise ( )
protectedvirtual

Called when the application shuts down.

Optionally overridable this allows derived classes to tidy up any data when the program exits, such as clearing the state stack.

◆ getMessageBus()

MessageBus& xy::App::getMessageBus ( )

Returns a reference to the message bus.

See also
MessageBus

◆ handleEvent()

virtual void xy::App::handleEvent ( const sf::Event &  )
protectedpure virtual

Function for despatching all window events.

This should be implemented in the derived game or application to allow passing down any received SFML events throughout the program. Usually this would be passing the event to a state stack

◆ handleMessage()

virtual void xy::App::handleMessage ( const Message )
protectedpure virtual

Function for despatching messages received by the message bus.

This should be implemented by any derived game or application to allow custom or system messages to be handled by xygine objects

◆ initialise()

virtual bool xy::App::initialise ( )
protectedvirtual

Called when the application is first run.

Optionally overridable this should be used when performing operations which may throw exceptions such as loading configuration data, which should not be performed in the constructor of a derived application. If initialisation is successful then this should return true, else return false. Returning false will prevent the application running and cause it to attempt to perform a clean shutdown with finalise();

◆ registerStates()

virtual void xy::App::registerStates ( )
protectedpure virtual

Registers a custom state with a state stack.

This should be implements by derived games or applications so that custom states can be registered with the xygine state stack instance.

See also
State

◆ run()

void xy::App::run ( )

Starts the application.

This should be called once from within main() This will start the application and enter the game loop

◆ updateApp()

virtual void xy::App::updateApp ( float  dt)
protectedpure virtual

Updates derived applications with the elapsed frame time during the game loop.

Logic updates should be performed here by any game objects such as the state stack. The frame time is fixed at 1/60 second