Browse Source

Add SetPrimaryEvent and UnsetPrimaryEvent to Module.

tags/v2.0.0
Andrew Belt 3 years ago
parent
commit
0c9598ba8f
2 changed files with 19 additions and 0 deletions
  1. +6
    -0
      include/engine/Module.hpp
  2. +13
    -0
      src/engine/Engine.cpp

+ 6
- 0
include/engine/Module.hpp View File

@@ -387,6 +387,12 @@ struct Module {
*/ */
virtual void onSave(const SaveEvent& e) {} virtual void onSave(const SaveEvent& e) {}


struct SetPrimaryEvent {};
virtual void onSetPrimary(const SetPrimaryEvent& e) {}

struct UnsetPrimaryEvent {};
virtual void onUnsetPrimary(const UnsetPrimaryEvent& e) {}

/** DEPRECATED. Override `onAdd(e)` instead. */ /** DEPRECATED. Override `onAdd(e)` instead. */
virtual void onAdd() {} virtual void onAdd() {}
/** DEPRECATED. Override `onRemove(e)` instead. */ /** DEPRECATED. Override `onRemove(e)` instead. */


+ 13
- 0
src/engine/Engine.cpp View File

@@ -577,7 +577,20 @@ void Engine::stepBlock(int frames) {


void Engine::setPrimaryModule(Module* module) { void Engine::setPrimaryModule(Module* module) {
WriteLock lock(internal->mutex); WriteLock lock(internal->mutex);

if (internal->primaryModule) {
// Trigger UnsetPrimaryEvent
Module::UnsetPrimaryEvent e;
internal->primaryModule->onUnsetPrimary(e);
}

internal->primaryModule = module; internal->primaryModule = module;

if (internal->primaryModule) {
// Trigger SetPrimaryEvent
Module::SetPrimaryEvent e;
internal->primaryModule->onSetPrimary(e);
}
} }






Loading…
Cancel
Save