#include <nap/core.h>
Classes | |
class | Services |
Public Types | |
using | ServicesHandle = std::unique_ptr< Services > |
Public Member Functions | |
Core () | |
Core (std::unique_ptr< CoreExtension > coreExtension) | |
virtual | ~Core () |
bool | initializeEngine (utility::ErrorState &error) |
bool | initializeEngine (const std::string &projectInfofile, ProjectInfo::EContext context, utility::ErrorState &error) |
Core::ServicesHandle | initializeServices (utility::ErrorState &errorState) |
bool | isInitialized () const |
bool | initializePython (utility::ErrorState &error) |
void | start () |
double | update (std::function< void(double)> &updateFunction) |
ResourceManager * | getResourceManager () |
const ModuleManager & | getModuleManager () const |
uint32 | getTicks () const |
double | getElapsedTime () const |
SteadyTimeStamp | getStartTime () const |
float | getFramerate () const |
Service * | getService (const rtti::TypeInfo &type) |
const Service * | getService (const rtti::TypeInfo &type) const |
Service * | getService (const std::string &type) |
template<typename T > | |
T * | getService () |
template<typename T > | |
const T * | getService () const |
template<typename T > | |
const T & | getExtension () const |
template<typename T > | |
bool | hasExtension () const |
bool | findProjectFilePath (const std::string &filename, std::string &foundFilePath) const |
const nap::ProjectInfo * | getProjectInfo () const |
bool | loadPathMapping (nap::ProjectInfo &projectInfo, nap::utility::ErrorState &err) |
bool | writeConfigFile (const std::string &path, utility::ErrorState &errorState, bool linkToProjectInfo=true) |
std::vector< const ServiceConfiguration * > | getServiceConfigs () const |
void | setupPlatformSpecificEnvironment () |
Core manages the object graph, modules and services Core is required in every NAP application and should be the first object that is created and initialized. There should only be only 1 instance of Core in your application
After creation, initialize the core engine by invoking initializeEngine(). This will load all the available modules and their dependencies including services. When all modules are loaded all available services are initialized. Initialization occurs based on the Service dependency tree. So when Service B points to A, Service A is initialized before B. After initialization all module specific resources and their contexts are available for object creation using the ResourceManager.
Every instance of Core is initialized against a nap::ProjectInfo resource, which is declared inside a project.json
file. The nap::ProjectInfo file contains information such as the project name, version and which modules are required for the project to run. It also contains a link to a data file, which contains the actual application content and an optional link to a service configuration file, which contains service configuration information.
The linked path mapping file provides core with additional information on how to resolve paths to all required modules. Using this information both the editor and application are able to load the requested modules and initialize all required services.
It is therefore required that core is able to load a valid project.json file, that contains a 'nap::ProjectInfo' resource. example of a project.json file:
Call update inside your app loop to update all available services. When exiting the application invoke shutdown. This will close all operating services in the reverse order of their dependency tree
using ServicesHandle = std::unique_ptr<Services> |
Core | ( | ) |
Default Constructor
Core | ( | std::unique_ptr< CoreExtension > | coreExtension | ) |
|
virtual |
Destructor
bool findProjectFilePath | ( | const std::string & | filename, |
std::string & | foundFilePath | ||
) | const |
Searches for a file next to the binary, and in case of non-packaged builds, searches through the project folders to find the file.
filename | File to search for. |
foundFilePath | The full file path of where the file was found. |
double getElapsedTime | ( | ) | const |
const T & getExtension |
Returns the extension associated with this instance of core as T. Note that an extension is given explicitly to core on construction. When using the default constructor core has no interface associated with it!
Returns the core extension as an extension of type T
float getFramerate | ( | ) | const |
const ModuleManager& getModuleManager | ( | ) | const |
const nap::ProjectInfo* getProjectInfo | ( | ) | const |
Returns loaded project information, only available after initialization, nullptr otherwise.
ResourceManager* getResourceManager | ( | ) |
The resource manager holds all the entities and components currently loaded by Core.
T * getService |
Searches for a service of type T, returns a nullptr if not found.
Searches for a service of type T in the services and returns it, returns nullptr if none found
const T * getService |
Searches for a service of type T, returns a nullptr if not found.
Searches for a service of type T in the services and returns it, returns nullptr if none found
Service* getService | ( | const rtti::TypeInfo & | type | ) |
Find a service of a given type.
type | the type of service to get |
const Service* getService | ( | const rtti::TypeInfo & | type | ) | const |
Find a service of a given type.
type | the type of service to get |
Service* getService | ( | const std::string & | type | ) |
Searches for a service based on given type name, names need to match exactly.
type | the type of the service as a string |
std::vector<const ServiceConfiguration*> getServiceConfigs | ( | ) | const |
Returns all available and used service configurations.
SteadyTimeStamp getStartTime | ( | ) | const |
uint32 getTicks | ( | ) | const |
bool hasExtension |
Returns if core has an extension of type T
bool initializeEngine | ( | const std::string & | projectInfofile, |
ProjectInfo::EContext | context, | ||
utility::ErrorState & | error | ||
) |
Loads all modules in to the core environment and creates all the associated services.
Every instance of Core is initialized against a nap::ProjectInfo resource, which is declared inside a project.json
file. The nap::ProjectInfo file contains information such as the project name, version and which modules are required for the project to run. It also contains an optional link to a service configuration file, which holds service configuration information.
The linked path mapping file provides core with additional information on how to resolve paths to all required modules. Using this information both the editor and application are able to load the requested modules and initialize all required services.
It is therefore required that core is able to find and load the provided project.json file that contains a 'nap::ProjectInfo' resource.
projectInfofile | absolute path to the project file on disk. |
context | whether initializing for application or editor |
error | contains the error code when initialization fails |
bool initializeEngine | ( | utility::ErrorState & | error | ) |
Loads all modules in to the core environment and creates all the associated services.
Every instance of Core is initialized against a nap::ProjectInfo resource, which is declared inside a project.json
file. The nap::ProjectInfo file contains information such as the project name, version and which modules are required for the project to run. It also contains an optional link to a service configuration file, which holds service configuration information.
The linked path mapping file provides core with additional information on how to resolve paths to all required modules. Using this information both the editor and application are able to load the requested modules and initialize all required services.
It is therefore required that core is able to find and load a valid project.json file that contains a 'nap::ProjectInfo' resource.
error | contains the error code when initialization fails |
bool initializePython | ( | utility::ErrorState & | error | ) |
Initialize python interpreter so we can have components running python scripts
Core::ServicesHandle initializeServices | ( | utility::ErrorState & | errorState | ) |
Attempts to initialize all registered services. Call this after initializeEngine(). Initialization occurs based on service dependencies, this means that if service B depends on Service A, Service A is initialized before service B etc. This call returns a handle that, when destroyed, shuts down all services in the right order.
errorState | contains the error message when initialization fails |
bool isInitialized | ( | ) | const |
Returns if core is initialized.
bool loadPathMapping | ( | nap::ProjectInfo & | projectInfo, |
nap::utility::ErrorState & | err | ||
) |
Load path mapping file and replace any template vars with their respective values
projectInfo | The current project info |
err | Contains the error if the path mapping operation failed |
void setupPlatformSpecificEnvironment | ( | ) |
Used on macOS to apply an environment variable for Vulkan.
void start | ( | ) |
Starts core, call this after initializing the engine, just before starting the application loop.
double update | ( | std::function< void(double)> & | updateFunction | ) |
Updates all services. This happens in 3 distinct steps. First the resource file is reloaded. After that all services are updated, the last step is the the update of the entities and their respective components managed by the resource manager
updateFunction | application callback that is invoked after updating all the services but before render. Input parameter is deltaTime |
bool writeConfigFile | ( | const std::string & | path, |
utility::ErrorState & | errorState, | ||
bool | linkToProjectInfo = true |
||
) |
Writes a 'config.json' file, that contains all currently loaded service configurations
path | The path to the config file relative to the path of the project info json file |
errorState | Contains the error if the operation fails |
linkToProjectInfo | If set to true the new written file will be linked in the current project info, and the project info will be saved to the project.json file. |