The engine owns all the systems and resource managers, and is responsible for executing different stages of updates in the correct order.
More...
|
| Engine (Context *context) |
| Constructs a new engine instance, living in the given Context.
|
|
| Engine (const Engine &other)=delete |
| Disable copying engine instances.
|
|
| ~Engine () |
| Destructs the engine instance.
|
|
Engine & | operator= (const Engine &other)=delete |
| Disable copy assignment of engine instances.
|
|
void | update () |
| Update the engine, advancing the system state a single frame.
|
|
void | invokeCallback (void(*callback)(void *), void *data) |
| Generic callback invoke wrapper for callbacks with just a data-wrapper, proxied from emscripten worker threads.
|
|
void | invokeComponentNotifyCallback (const ComponentModel::Component &component, int notification, const void *data, size_t dataSize) |
| Invoke the componentNotifyCallback if it exists, proxied from emscripten worker threads.
|
|
void | invokeResourceLoadCallback (int resourceType, ResourceId id, int code) |
| Invoke the resourceLoadCallback if it exists, proxied from emscripten worker threads.
|
|
bool | needsUpdate () const |
| Gets if the engine is in need of an update.
|
|
void | triggerUpdate () |
| Triggers an engine update.
|
|
void | setDirty () |
| Triggers an engine update and updates last dirty frame to the current frame.
|
|
uint32_t | getLastDirtyFrame () |
| Get the current frame at the last time setDirty was called.
|
|
void | setNeedsUpdateCallback (NeedsUpdateCallback *callback, void *data) |
| Invoked when update state goes from clean to dirty.
|
|
void | updateSystems () |
| Performs updates of all the systems.
|
|
void | registerSystem (ComponentSystemBase *system, int priority, bool registerInStore=true) |
| Register the given component system in the engine with the given priority.
|
|
template<typename SystemType > |
SystemType * | registerSystem (int priority, SystemType **storage, uint32_t capacity, bool registerInStore=true) |
| Utility function for instantiating a system of the given template type and assigning ownership to the engine.
|
|
void | addResourceManager (std::unique_ptr< IResourceManager > &&resourceManager) |
| Add the given resource manager to the engine.
|
|
IValueTypeManager * | getResourceManagerByValueType (int valueType) |
|
void | initializeResources () |
| Initializes all resource managers and default resources.
|
|
void | clearResources () |
| Clears all resource managers pending reinitialization of resources.
|
|
void | runTaskInMainThread (std::function< void()> &&task) |
|
void | preRender () |
|
void | render () |
|
void | postRender () |
|
void | swapResources () |
|
bool | workParallel () const |
| True if it is worthwhile to parallelize work.
|
|
bool | isReady () const |
|
void | checkAndUpdateResources () |
|
void | setEditor (class IEditor *editor) |
|
class IEditor * | getEditor () const |
|
The engine owns all the systems and resource managers, and is responsible for executing different stages of updates in the correct order.
When all systems and resource managers are done updating, rendering will be initiated by notifying the renderer.
The entity store, keeping all top level entities in the running instance, is also owned by the engine.
Definition at line 87 of file Engine.h.
Cogs::Core::Engine::Engine |
( |
Context * |
context | ) |
|
Constructs a new engine instance, living in the given Context.
The engine will perform full initialization of all core systems and resource managers, leaving the system ready to start running updates without rendering.
Initialization is performed as follows:
- The entity store is created and initialized
- The renderer is created
- All entity definitions and templates are initialized
- Resource managers are created
- Resource managers are initialized
- Core systems are created
Note: Systems are not initialized until after initializeRendering() is called.
- Parameters
-
context | Context instance the engine instance exists in. |
Definition at line 83 of file Engine.cpp.
void Cogs::Core::Engine::registerSystem |
( |
ComponentSystemBase * |
system, |
|
|
int |
priority, |
|
|
bool |
registerInStore = true |
|
) |
| |
Register the given component system in the engine with the given priority.
The engine assumes ownership over lifetime of the component system, and will perform cleanup and destruction of the system when the engine instance is destructed.
- Parameters
-
system | Unique pointer to a component system based on ComponentSystemBase. Ownership of the pointer will be assumed by the engine. |
priority | An integer stating a priority value for when the system should be run in different update phases. Increasing priority values will move the component system later in the execution queue. |
registerInStore | If the system should be registered in the entity store as candidate to create components of the systems type. |
- See also
- SystemPriority.
Definition at line 543 of file Engine.cpp.
References Cogs::Core::EntityStore::addSystem(), and Cogs::Core::Context::store.
void Cogs::Core::Engine::triggerUpdate |
( |
| ) |
|
|
inline |
Triggers an engine update.
If the engine is in the middle of a current update, an additional update will be performed following completion. Call this to trigger just a new engine run, e.g. where rendering is spread over multiple frames. When state has changed, setDirty should be called to trigger a full rendering.
Definition at line 191 of file Engine.h.
void Cogs::Core::Engine::update |
( |
| ) |
|
Update the engine, advancing the system state a single frame.
During the update all systems will have their different phases of updates executed in the order given by the different systems priorities.
All resource managers are updated, processing queued resources, resources ready for loading, and deleted or orphaned resources.
Finally, the renderer is invoked, producing a single frame of output.
Definition at line 358 of file Engine.cpp.
References Cogs::Core::IRenderer::beginFrame(), Cogs::Core::IRenderer::endFrame(), Cogs::Core::Context::qualityService, Cogs::Core::Context::renderer, Cogs::Core::Context::resourceUsageLogger, and Cogs::Core::Context::variables.
void Cogs::Core::Engine::updateSystems |
( |
| ) |
|
Performs updates of all the systems.
Updates are executed according to the order given by the component systems priorities.
The different phases of update are executed for all systems before moving to the next phase;
- Run preUpdate on all systems
- Run update on all systems
- Run postUpdate on all systems
This method is executed automatically by calling update() for a given frame, so it is not needed to invoke this manually. However, it can be used to ensure state is updated before out-of rendering queries such as bounding box queries, requiring that all geometry has been updated before valid results can be had.
Definition at line 442 of file Engine.cpp.