Jopnal Engine  alpha 0.4
Simple Component Based 2D/3D Game Engine
Public Types | Public Member Functions | Static Public Member Functions | List of all members
jop::Engine Class Referencefinal

#include <Engine.hpp>

Public Types

enum  State { State::Running, State::RenderOnly, State::Frozen }
 Engine state. More...
 

Public Member Functions

 Engine (const std::string &projectName, int argc, char *argv[])
 Constructor. More...
 
 ~Engine ()
 Destructor. More...
 
void loadDefaultConfiguration ()
 Load the default subsystem configuration. More...
 

Static Public Member Functions

static int runMainLoop ()
 Run the main loop. More...
 
static void advanceFrame ()
 Advance a single frame. More...
 
template<typename T , bool Threaded = false, bool WaitSignal = false, typename... Args>
static void createScene (Args &&...args)
 Create a new scene. More...
 
static bool hasCurrentScene ()
 Check if there's a current scene. More...
 
static ScenegetCurrentScene ()
 Get the current scene. More...
 
static bool signalNewScene ()
 Signal a new scene (loaded in a threaded manner) to set itself current. More...
 
static bool newSceneReady ()
 Check if a scene has been loaded and is ready to be set current. More...
 
template<typename T , typename... Args>
static T & createSubsystem (Args &&...args)
 Create a subsystem. More...
 
template<typename T >
static T * getSubsystem ()
 Get a subsystem using type info. More...
 
template<typename T >
static T * getSubsystem (const uint32 ID)
 Get a subsystem using subsystem ID and type info. More...
 
template<typename T >
static bool removeSubsystem (const uint32 ID)
 Remove a subsystem. More...
 
static bool exiting ()
 Check if the engine is signaled to exit. More...
 
static void exit ()
 Exit the main loop. More...
 
static void setState (const State state)
 Set the engine state. More...
 
static State getState ()
 Get the engine state. More...
 
static RenderTargetgetMainRenderTarget ()
 Get the main render target. More...
 
static WindowgetMainWindow ()
 Get the main window. More...
 
static bool hasMainWindow ()
 Check if there's a main window. More...
 
static Message::Result sendMessage (const Message &message)
 Send a message to the whole engine. More...
 
static ScenegetSharedScene ()
 Get the shared scene. More...
 
static bool hasSharedScene ()
 Check if a shared scene exists. More...
 
template<typename T , typename... Args>
static T & setSharedScene (Args &&...args)
 Set the shared scene. More...
 
static double getTotalTime ()
 Get the total time since Engine construction. More...
 
static float getDeltaTimeUnscaled ()
 Get the current actual/unscaled delta time. More...
 

Detailed Description

Definition at line 52 of file Engine.hpp.

Member Enumeration Documentation

enum jop::Engine::State
strong

Engine state.

No matter the state, sub systems will always be running normally.

Enumerator
Running 

Run normally.

RenderOnly 

Only render, don't update.

Frozen 

No rendering or updating.

Definition at line 65 of file Engine.hpp.

Constructor & Destructor Documentation

jop::Engine::Engine ( const std::string &  projectName,
int  argc,
char *  argv[] 
)

Constructor.

This will initialize the engine and all associated systems. Project name must not be empty, as it will be used to create the necessary config directories.

The engine object must stay alive until exit is called and the main loop is returned from.

Parameters
projectNameThe project name
argcNumber of arguments passed from main()
argvThe argument array passed from main()
jop::Engine::~Engine ( )

Destructor.

This will deinitialize the engine, so that the program can exit.

Warning
You should only create the engine object once during the program's life time. Some of the sub systems are not designed to be initialized more than once.

Member Function Documentation

static void jop::Engine::advanceFrame ( )
static

Advance a single frame.

When state is Running, this function has no effect.

template<typename T , bool Threaded = false, bool WaitSignal = false, typename... Args>
static void jop::Engine::createScene ( Args &&...  args)
static

Create a new scene.

This function will construct the scene and then set it as active. The previously active scene will be discarded and deleted.

If Threaded is true, the scene will be loaded in a separate thread, while the old one is left running. If WaitSignal is false, the new scene will be set current as soon as it's loaded. If WaitSignal is true, you'll need to call signalNewScene to set it active.

Warning
When creating a scene in a thread, exit() must not be called before the scene has finished loading.
Parameters
argsThe arguments to be used in the scene's construction
See also
signalNewScene()
newSceneReady()
template<typename T , typename... Args>
static T& jop::Engine::createSubsystem ( Args &&...  args)
static

Create a subsystem.

Parameters
argsThe arguments to be used in the subsystem's construction
Returns
Reference to the newly created subsystem
static void jop::Engine::exit ( )
static

Exit the main loop.

This function will have no effect if no jop::Engine exists at the time of the call. The main loop returns only after the current frame has been processed.

static bool jop::Engine::exiting ( )
static

Check if the engine is signaled to exit.

This will also be true when the engine hasn't been loaded yet.

Returns
True if engine was signaled to exit
static Scene& jop::Engine::getCurrentScene ( )
static

Get the current scene.

This function asserts that the scene has been loaded first with createScene().

Returns
Reference to the scene
See also
hasCurrentScene()
static float jop::Engine::getDeltaTimeUnscaled ( )
static

Get the current actual/unscaled delta time.

Use this if you need the real delta time value, which is unaffected by the scene's delta scale.

Returns
The unscaled delta time
static RenderTarget& jop::Engine::getMainRenderTarget ( )
static

Get the main render target.

This can be either MainRenderTarget or Window.

Returns
Reference to the main render target
static Window& jop::Engine::getMainWindow ( )
static

Get the main window.

This function asserts that the window has been created first. This will be done automatically by loadDefaultConfiguration().

Returns
Reference to the window
See also
hasMainWindow()
static Scene& jop::Engine::getSharedScene ( )
static

Get the shared scene.

The shared scene exists for the purpose of being able to have objects that are shared between scenes. This makes it possible to have general-purpose functionality without having to take care of it in every scene separately.

Returns
Reference to the shared scene
See also
hasSharedScene()
static State jop::Engine::getState ( )
static

Get the engine state.

Returns
Engine state
template<typename T >
static T* jop::Engine::getSubsystem ( )
static

Get a subsystem using type info.

Returns
Pointer to the subsystem. nullptr if not found
template<typename T >
static T* jop::Engine::getSubsystem ( const uint32  ID)
static

Get a subsystem using subsystem ID and type info.

Parameters
IDThe identifier to search with
Returns
Pointer to the subsystem. nullptr if not found
static double jop::Engine::getTotalTime ( )
static

Get the total time since Engine construction.

Returns
Total time in seconds
static bool jop::Engine::hasCurrentScene ( )
static

Check if there's a current scene.

Returns
True if there's a current scene
static bool jop::Engine::hasMainWindow ( )
static

Check if there's a main window.

Returns
True if there's a main window
static bool jop::Engine::hasSharedScene ( )
static

Check if a shared scene exists.

Returns
True if the shared scene exists
void jop::Engine::loadDefaultConfiguration ( )

Load the default subsystem configuration.

static bool jop::Engine::newSceneReady ( )
static

Check if a scene has been loaded and is ready to be set current.

If a scene wasn't previously loaded with a thread, this function will always return false.

Returns
True if a scene is ready and waiting to be set current
template<typename T >
static bool jop::Engine::removeSubsystem ( const uint32  ID)
static

Remove a subsystem.

Parameters
IDIdentifier of the subsystem to be removed
Returns
True if the subsystem was found and removed
static int jop::Engine::runMainLoop ( )
static

Run the main loop.

The main loop will run until exit() is called.

Returns
An integer return value. To be used as the main() return value
static Message::Result jop::Engine::sendMessage ( const Message message)
static

Send a message to the whole engine.

The message will be forwarded everywhere. This function is identical to jop::broadcast().

Parameters
messageThe message
Returns
Message result
template<typename T , typename... Args>
static T& jop::Engine::setSharedScene ( Args &&...  args)
static

Set the shared scene.

This will immediately replace the previous shared scene with a new one of the given type. Threaded loading is not supported at this time.

Parameters
argsArguments to use in the scene's construction
Returns
Reference to the new scene
static void jop::Engine::setState ( const State  state)
static

Set the engine state.

Parameters
stateThe new state to set
static bool jop::Engine::signalNewScene ( )
static

Signal a new scene (loaded in a threaded manner) to set itself current.

If a scene wasn't previously loaded with a thread, this function has no effect.

Returns
True if a new scene was ready to activate, false otherwise
See also
newSceneReady

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