NAP
Core Class Reference

#include <nap/core.h>

Public Member Functions

 Core ()
 
 Core (std::unique_ptr< CoreExtension > coreExtension)
 
virtual ~Core ()
 
bool initializeEngine (utility::ErrorState &error, const std::string &forcedDataPath={}, bool runningInNonProjectContext=false)
 
bool initializeServices (utility::ErrorState &errorState)
 
void shutdownServices ()
 
bool initializePython (utility::ErrorState &error)
 
void start ()
 
double update (std::function< void(double)> &updateFunction)
 
ResourceManagergetResourceManager ()
 
const ModuleManagergetModuleManager () const
 
uint32 getTicks () const
 
double getElapsedTime () const
 
HighResTimeStamp getStartTime () const
 
float getFramerate () const
 
ServicegetService (const rtti::TypeInfo &type)
 
ServicegetService (const std::string &type)
 
template<typename T >
T * getService ()
 
template<typename T >
const T & getExtension () const
 
template<typename T >
bool hasExtension () const
 
bool findProjectFilePath (const std::string &filename, std::string &foundFilePath) const
 

Detailed 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.

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

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 ( ) const

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

◆ getResourceManager()

ResourceManager* getResourceManager ( )

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

Returns
the resource manager

◆ getService() [1/3]

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() [2/3]

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

◆ getService() [3/3]

T * getService ( )

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

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

◆ getStartTime()

HighResTimeStamp getStartTime ( ) const
Returns
start time point

◆ getTicks()

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

◆ hasExtension()

bool hasExtension ( ) const
Returns
if core has an extension of type T

Returns if core has an extension of type T

◆ initializeEngine()

bool initializeEngine ( utility::ErrorState error,
const std::string &  forcedDataPath = {},
bool  runningInNonProjectContext = false 
)

Loads all modules in to the core environment and creates all the associated services

Parameters
errorcontains the error code when initialization fails
forcedDataPathoptionally overwrite the project data detection, using specified path instead
runningInNonProjectContextindicates if the engine is being run for a non-project use, eg. running Napkin
Returns
if initialization succeeded

◆ initializePython()

bool initializePython ( utility::ErrorState error)

Initialize python interpreter so we can have components running python scripts

◆ initializeServices()

bool initializeServices ( utility::ErrorState errorState)

Initializes all registered services Initialization occurs based on service dependencies, this means that if service B depends on Service A, Service A is initialized before service B etc.

Parameters
errorStatecontains the error message when initialization fails
Returns
if initialization failed or succeeded

◆ shutdownServices()

void shutdownServices ( )

Shuts down all registered services in the right order Only call this when initializeServices has been called

◆ start()

void start ( )

Starts core, call this after initializing the engine, just before starting the application loop. This call will start the core timer

◆ 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