.. _api_Engine: Engine ====== Inherited: None .. _api_Engine_description: 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. .. _api_Engine_public: Public Methods -------------- +--+-------------------------------------------------------------------+ | | :ref:`Engine` (File * file, const char * path) | +--+-------------------------------------------------------------------+ | | :ref:`~Engine` () | +--+-------------------------------------------------------------------+ .. _api_Engine_static: Static Methods -------------- +----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`addModule` (Module * module) | +----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+ | std::string | :ref:`applicationName` () | +----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Actor` * | :ref:`composeActor` (const std::string & component, const std::string & name, Object * parent = nullptr) | +----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+ | :ref:`File` * | :ref:`file` () | +----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+ | bool | :ref:`init` () | +----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+ | bool | :ref:`isGameMode` () | +----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+ | bool | :ref:`isResourceExist` (const std::string & path) | +----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Object` * | :ref:`loadResource` (const std::string & path) | +----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Scene` * | :ref:`loadScene` (const std::string & path, bool additive) | +----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+ | bool | :ref:`loadTranslator` (const std::string & name) | +----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+ | std::string | :ref:`locationAppConfig` () | +----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+ | std::string | :ref:`locationAppDir` () | +----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+ | std::string | :ref:`organizationName` () | +----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+ | std::string | :ref:`reference` (Object * object) | +----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+ | bool | :ref:`reloadBundle` () | +----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`reloadResource` (const std::string & path) | +----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+ | :ref:`RenderSystem` * | :ref:`renderSystem` () | +----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+ | :ref:`ResourceSystem` * | :ref:`resourceSystem` () | +----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`setGameMode` (bool flag) | +----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`setPlatformAdaptor` (PlatformAdaptor * platform) | +----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`setResource` (Object * object, const std::string & uuid) | +----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`setValue` (const std::string & key, const Variant & value) | +----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+ | bool | :ref:`start` () | +----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`syncValues` () | +----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+ | std::string | :ref:`translate` (const std::string & source) | +----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`unloadAllScenes` () | +----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`unloadResource` (Resource * resource) | +----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`unloadResource` (const std::string & path) | +----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`unloadScene` (Scene * scene) | +----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`update` () | +----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Variant` | :ref:`value` (const std::string & key, const Variant & defaultValue = Variant()) | +----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+ | :ref:`World` * | :ref:`world` () | +----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+ .. _api_Engine_methods: Methods Description ------------------- .. _api_Engine_Engine: **Engine::Engine** (:ref:`File` * *file*, char * *path*) Constructs Engine. Using *file* and *path* parameters creates necessary platform adapters, register basic component types and resource types. ---- .. _api_Engine_~Engine: **Engine::~Engine** () Destructs Engine, related objects, registered object factories and platform adaptor. ---- .. _api_Engine_addModule: void **Engine::addModule** (:ref:`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(); } ---- .. _api_Engine_applicationName: std::string **Engine::applicationName** () Returns application name. ---- .. _api_Engine_composeActor: :ref:`Actor` * **Engine::composeActor** (std::string & *component*, std::string & *name*, :ref:`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. ---- .. _api_Engine_file: :ref:`File` * **Engine::file** () Returns file system module. ---- .. _api_Engine_init: bool **Engine::init** () Initializes all engine systems. Returns true if successful; otherwise returns false. ---- .. _api_Engine_isGameMode: bool **Engine::isGameMode** () Returns true if game started; otherwise returns false. ---- .. _api_Engine_isResourceExist: bool **Engine::isResourceExist** (std::string & *path*) Returns true if resource with *path* exists; otherwise returns false. ---- .. _api_Engine_loadResource: :ref:`Object` * **Engine::loadResource** (std::string & *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(). ---- .. _api_Engine_loadScene: :ref:`Scene` * **Engine::loadScene** (std::string & *path*, bool *additive*) Loads the scene stored in the .map files by the it's *path* to the Engine. **Note:** The previous scenes will be not unloaded in the case of an *additive* flag is true. ---- .. _api_Engine_loadTranslator: bool **Engine::loadTranslator** (std::string & *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 std::strings. Returns true on success; otherwise returns false. ---- .. _api_Engine_locationAppConfig: std::string **Engine::locationAppConfig** () Returns path to application config directory. ---- .. _api_Engine_locationAppDir: std::string **Engine::locationAppDir** () Returns path to application binary directory. ---- .. _api_Engine_organizationName: std::string **Engine::organizationName** () Returns organization name. ---- .. _api_Engine_reference: std::string **Engine::reference** (:ref:`Object` * *object*) Returns resource path for the provided resource *object*. **See also** setResource(). ---- .. _api_Engine_reloadBundle: bool **Engine::reloadBundle** () This method reads the index file for the resource bundle. The index file helps to find required game resources. Returns true in case of success; otherwise returns false. ---- .. _api_Engine_reloadResource: void **Engine::reloadResource** (std::string & *path*) Reloads the resource located along the *path*. **See also** loadResource(). ---- .. _api_Engine_renderSystem: :ref:`RenderSystem` * **Engine::renderSystem** () Returns the render system which can be used in external modules. ---- .. _api_Engine_resourceSystem: :ref:`ResourceSystem` * **Engine::resourceSystem** () Returns the resource management system which can be used in external modules. ---- .. _api_Engine_setGameMode: void **Engine::setGameMode** (bool *flag*) Set game *flag* to true if game started; otherwise set false. **See also** isGameMode(). ---- .. _api_Engine_setPlatformAdaptor: void **Engine::setPlatformAdaptor** (:ref:`PlatformAdaptor` * *platform*) Replaces a current *platform* adaptor with new one; **Note:** The previous one will not be deleted. ---- .. _api_Engine_setResource: void **Engine::setResource** (:ref:`Object` * *object*, std::string & *uuid*) Register resource *object* by *uuid* path. **See also** setResource(). ---- .. _api_Engine_setValue: void **Engine::setValue** (std::string & *key*, :ref:`Variant` & *value*) Sets the *value* of setting *key* to *value*. If the *key* already exists, the previous *value* will be overwritten. **See also** *value*(). ---- .. _api_Engine_start: 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. ---- .. _api_Engine_syncValues: void **Engine::syncValues** () Applies all unsaved settings. ---- .. _api_Engine_translate: std::string **Engine::translate** (std::string & *source*) Returns the translation text for the *source* std::string. ---- .. _api_Engine_unloadAllScenes: void **Engine::unloadAllScenes** () Unloads all scenes from the World. ---- .. _api_Engine_unloadResource: void **Engine::unloadResource** (:ref:`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(). ---- .. _api_Engine_unloadResource: void **Engine::unloadResource** (std::string & *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(). ---- .. _api_Engine_unloadScene: void **Engine::unloadScene** (:ref:`Scene` * *scene*) Unloads the *scene* from the World. ---- .. _api_Engine_update: void **Engine::update** () This method launches all your game modules responsible for processing all the game logic. It calls on each iteration of the game cycle. **Note:** Usually, this method calls internally and must not be called manually. ---- .. _api_Engine_value: :ref:`Variant` **Engine::value** (std::string & *key*, :ref:`Variant` & *defaultValue* = Variant()) Returns the value for setting *key*. If the setting doesn't exist, returns *defaultValue*. **See also** setValue(). ---- .. _api_Engine_world: :ref:`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.