EngineΒΆ

Inherited: ObjectSystem

DescriptionΒΆ

The Engine class is one of the central parts of the Thunder Engine. This class is created first and removed last in your game. It is responsible for many basic functions, such as game cycle, management of game modules, loading and unloading of game resources, work with game settings.

Public MethodsΒΆ

Engine ()

~Engine ()

Static MethodsΒΆ

void

addModule (Module * module)

TString

applicationName ()

TString

applicationVersion ()

Actor *

composeActor (const TString & component, const TString & name, Object * parent = nullptr)

System *

getSystem (const TString & name)

bool

init ()

Engine &

instance ()

bool

isGameMode ()

bool

isResourceExist (const TString & path)

Resource *

loadResource (const TString & path)

Resource *

loadResourceAsync (const TString & path)

bool

loadTranslator (const TString & name)

TString

locationAppConfig ()

TString

organizationName ()

PlatformAdaptor *

platformAdaptor ()

TString

reference (Object * object)

void

reloadResource (const TString & path)

RenderSystem *

renderSystem ()

ResourceSystem *

resourceSystem ()

void

setApplicationName (const TString & name)

void

setApplicationVersion (const TString & version)

void

setGameMode (bool flag)

void

setOrganizationName (const TString & name)

bool

setPlatformAdaptor (PlatformAdaptor * platform)

void

setValue (const TString & key, const Variant & value)

bool

start ()

void

syncValues ()

TString

translate (const TString & text)

void

unloadResource (const TString & path)

void

unloadResource (Resource * resource)

void

update (World * world)

Variant

value (const TString & key, const Variant & defaultValue = Variant())

World *

world ()

Methods DescriptionΒΆ

Engine::Engine ()

Constructs Engine.


Engine::~Engine ()

Destructs Engine, related objects, registered object factories and platform adaptor.


void Engine::addModule (Module * module)

Adds a game module to pool. This module will be used during update() method execution.

Example:

if(engine->init()) {
    Engine::addModule(new RenderGL(engine));

    engine->start();
}

TString Engine::applicationName ()

Returns the name of this application. This name is used to create the path to the settings and logs for this application.

See also setApplicationName().


TString Engine::applicationVersion ()

Returns the version of this application.

See also setApplicationVersion().


Actor * Engine::composeActor (TString & component, TString & name, Object * parent = nullptr)

Creates an Actor with name and attached component. Created Actor will be added to the hierarchy of parent. This method helps to create all dependencies for the component.

Warning: This method should be used only in Editor mode.


System * Engine::getSystem (TString & name)

Returns a sub system with specific name.


bool Engine::init ()

Initializes all engine systems. Returns true if successful; otherwise returns false.


Engine & Engine::instance ()

Returns Engine object instance.


bool Engine::isGameMode ()

Returns true if game started; otherwise returns false.


bool Engine::isResourceExist (TString & path)

Returns true if resource with path exists; otherwise returns false.


Resource * Engine::loadResource (TString & path)

Returns an instance for loading resource by the provided path.

Note: In case of resource was loaded previously this function will return the same instance.

See also unloadResource().


Resource * Engine::loadResourceAsync (TString & path)

Returns an instance for loading resource by the provided path. The resource will be loaded asynchronously. This means you should check the state of resource before use it.

Note: In case of resource was loaded previously this function will return the same instance.

See also unloadResource().


bool Engine::loadTranslator (TString & name)

Loads translation table with provided file name. This method generates the LanguageChange event for the Engine instance. An Engine instance will propagate the event to all top-level widgets, where reimplementation of event() can re-translate user-visible Strings. Returns true on success; otherwise returns false.


TString Engine::locationAppConfig ()

Returns path to application config directory.


TString Engine::organizationName ()

Returns the name of the organization that wrote this application. This name is used to create the path to the settings and logs for this application.

See also setOrganizationName().


PlatformAdaptor * Engine::platformAdaptor ()

Return the current platform adaptor.

See also setPlatformAdaptor().


TString Engine::reference (Object * object)

Returns resource path for the provided resource object.


void Engine::reloadResource (TString & path)

Reloads the resource located along the path.

See also loadResource().


RenderSystem * Engine::renderSystem ()

Returns the render system which can be used in external modules.


ResourceSystem * Engine::resourceSystem ()

Returns the resource management system which can be used in external modules.


void Engine::setApplicationName (TString & name)

Sets the name of this application.

See also applicationName().


void Engine::setApplicationVersion (TString & version)

Sets the version of this application.

See also applicationVersion().


void Engine::setGameMode (bool flag)

Set game flag to true if game started; otherwise set false.

See also isGameMode().


void Engine::setOrganizationName (TString & name)

Sets the name of the organization that wrote this application.

See also organizationName().


bool Engine::setPlatformAdaptor (PlatformAdaptor * platform)

Replaces a current platform adaptor with new one; Returns true if replacement been succeeded; otherwise returns false.

Note: The previous platform adaptor will not be deleted.

See also platformAdaptor().


void Engine::setValue (TString & key, Variant & value)

Sets the value of setting key to value. If the key already exists, the previous value will be overwritten.

See also value().


bool Engine::start ()

Starts the main game cycle. Also this method loads the first level of your game. Returns true if successful; otherwise returns false.


void Engine::syncValues ()

Applies all unsaved settings.


TString Engine::translate (TString & text)

Returns the translation of text.


void Engine::unloadResource (TString & path)

Forcely unloads the resource located along the path from memory.

Warning: After this call, the reference on the resource may become an invalid at any time and must not be used anymore.

See also loadResource().


void Engine::unloadResource (Resource * resource)

Forcely unloads the resource from memory.

Warning: After this call, the reference on the resource may become an invalid at any time and must not be used anymore.

See also loadResource().


void Engine::update (World * world)

This method launches all your game modules responsible for processing all the game logic. It calls on each iteration of the game cycle for the particular world.

Note: Usually, this method calls internally and must not be called manually.


Variant Engine::value (TString & key, Variant & defaultValue = Variant())

Returns the value for setting key. If the setting doesn’t exist, returns defaultValue.

See also setValue().


World * Engine::world ()

Returns game World.

Note: The game can have only one scene graph. World is a root object, all map loads on this World.