NAP
Classes | Public Types | Public Member Functions | List of all members
Core Class Referencefinal

#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)
 
ResourceManagergetResourceManager ()
 
const ModuleManagergetModuleManager () const
 
uint32 getTicks () const
 
double getElapsedTime () const
 
SteadyTimeStamp getStartTime () const
 
float getFramerate () const
 
ServicegetService (const rtti::TypeInfo &type)
 
const ServicegetService (const rtti::TypeInfo &type) const
 
ServicegetService (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::ProjectInfogetProjectInfo () const
 
bool writeConfigFile (const std::string &path, utility::ErrorState &errorState, bool linkToProjectInfo=true)
 
std::vector< const ServiceConfiguration * > getServiceConfigs () const
 
void setupPlatformSpecificEnvironment ()
 

Description

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 an app.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 app.json file, that contains a 'nap::ProjectInfo' resource. example of an app.json file:

{
"Type": "nap::ProjectInfo",
"mID": "ProjectInfo",
"Title": "MyProject",
"Version": "1.0.0",
"RequiredModules":
[
"napapp",
"napimgui"
],
"Data": "data/myapp.json",
"ServiceConfig": "",
"PathMapping": "cache/path_mapping.json"
}

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

Member Typedef Documentation

◆ ServicesHandle

using ServicesHandle = std::unique_ptr<Services>

Constructor & Destructor Documentation

◆ Core() [1/2]

Core ( )

Default Constructor

◆ Core() [2/2]

Core ( std::unique_ptr< CoreExtension coreExtension)

Extension constructor. Used to add additional information to Core. This is the case on specific platforms, where additional information is required to correctly initialize Core.

Parameters
coreExtensionthe extension to associated with this instance of core, owned by core after construction.

◆ ~Core()

virtual ~Core ( )
virtual

Destructor

Member Function Documentation

◆ findProjectFilePath()

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.

Parameters
filenameFile to search for.
foundFilePathThe full file path of where the file was found.
Returns
true if the file was found, otherwise false.

◆ getElapsedTime()

double getElapsedTime ( ) const
Returns
number of elapsed seconds after invoking start

◆ getExtension()

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
extension associated with core as type T

Returns the core extension as an extension of type T

◆ getFramerate()

float getFramerate ( ) const
Returns
number of frames per second

◆ getModuleManager()

const ModuleManager& getModuleManager ( ) const
Returns
the ModuleManager for this core

◆ getProjectInfo()

const nap::ProjectInfo* getProjectInfo ( ) const

Returns loaded project information, only available after initialization, nullptr otherwise.

Returns
The loaded project information, available after initialization, nullptr otherwise

◆ getResourceManager()

ResourceManager* getResourceManager ( )

The resource manager holds all the entities and components currently loaded by Core.

Returns
the resource manager.

◆ getService() [1/5]

T * getService

Searches for a service of type T, returns a nullptr if not found.

RenderService* renderer = getCore().getService<nap::RenderService>();
...
Returns
a service of type T, returns nullptr if that service can't be found

Searches for a service of type T in the services and returns it, returns nullptr if none found

◆ getService() [2/5]

const T * getService

Searches for a service of type T, returns a nullptr if not found.

const RenderService* renderer = getCore().getService<nap::RenderService>();
...
Returns
a service of type T, returns nullptr if that service can't be found

Searches for a service of type T in the services and returns it, returns nullptr if none found

◆ getService() [3/5]

Service* getService ( const rtti::TypeInfo type)

Find a service of a given type.

Parameters
typethe type of service to get
Returns
found service, nullptr if not found.

◆ getService() [4/5]

const Service* getService ( const rtti::TypeInfo type) const

Find a service of a given type.

Parameters
typethe type of service to get
Returns
found service, nullptr if not found.

◆ getService() [5/5]

Service* getService ( const std::string &  type)

Searches for a service based on given type name, names need to match exactly.

Returns
an already registered service based on its type name, nullptr if not found
Parameters
typethe type of the service as a string

◆ getServiceConfigs()

std::vector<const ServiceConfiguration*> getServiceConfigs ( ) const

Returns all available and used service configurations.

Returns
all available service configurations.

◆ getStartTime()

SteadyTimeStamp getStartTime ( ) const
Returns
core start time

◆ getTicks()

uint32 getTicks ( ) const
Returns
number of elapsed time in milliseconds after invoking start

◆ hasExtension()

bool hasExtension
Returns
if core has an extension of type T

Returns if core has an extension of type T

◆ initializeEngine() [1/2]

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 an app.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 app.json file that contains a 'nap::ProjectInfo' resource.

Parameters
projectInfofileabsolute path to the project file on disk.
contextwhether initializing for application or editor
errorcontains the error code when initialization fails
Returns
if initialization succeeded

◆ initializeEngine() [2/2]

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 an app.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 app.json file that contains a 'nap::ProjectInfo' resource.

Parameters
errorcontains the error code when initialization fails
Returns
if initialization succeeded

◆ initializePython()

bool initializePython ( utility::ErrorState error)

Initialize python interpreter so we can have components running python scripts

◆ initializeServices()

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.

Parameters
errorStatecontains the error message when initialization fails
Returns
handle that manages services on success, nullptr if initialization fails

◆ isInitialized()

bool isInitialized ( ) const

Returns if core is initialized.

Returns
true if the engine initialized successfully, false otherwise.

◆ setupPlatformSpecificEnvironment()

void setupPlatformSpecificEnvironment ( )

Used on macOS to apply an environment variable for Vulkan.

◆ start()

void start ( )

Starts core, call this after initializing the engine, just before starting the application loop.

◆ update()

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

Parameters
updateFunctionapplication callback that is invoked after updating all the services but before render. Input parameter is deltaTime
Returns
deltaTime between update calls in seconds

◆ writeConfigFile()

bool writeConfigFile ( const std::string &  path,
utility::ErrorState errorState,
bool  linkToProjectInfo = true 
)

Writes a 'config.json' file, that contains all currently loaded service configurations

Parameters
pathThe path to the config file relative to the path of the project info json file
errorStateContains the error if the operation fails
linkToProjectInfoIf 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.
Returns
True on success
nap::RenderService
Definition: renderservice.h:275