From 072fb7b2ec3e1f6ba6433ba4c9cea1f93528acf1 Mon Sep 17 00:00:00 2001 From: Leonid Pospelov Date: Fri, 3 Nov 2023 19:52:04 +0600 Subject: [PATCH] internal: fix Windows build (#1728) --- .../skyrim_platform/EventHandler.h | 136 ++++++++++++------ .../platform_se/skyrim_platform/EventUtils.h | 2 +- 2 files changed, 93 insertions(+), 45 deletions(-) diff --git a/skyrim-platform/src/platform_se/skyrim_platform/EventHandler.h b/skyrim-platform/src/platform_se/skyrim_platform/EventHandler.h index 4c431507bb..2e769222dd 100644 --- a/skyrim-platform/src/platform_se/skyrim_platform/EventHandler.h +++ b/skyrim-platform/src/platform_se/skyrim_platform/EventHandler.h @@ -452,64 +452,83 @@ class EventHandler final activeSinks.reserve(20); // script events - AppendSink(std::vector({ "activate" })); - AppendSink( + AppendSinkScriptEvent(std::vector({ "activate" })); + AppendSinkScriptEvent( std::vector({ "effectStart", "effectFinish" })); - AppendSink( + AppendSinkScriptEvent( std::vector({ "locationChanged" })); - AppendSink( + AppendSinkScriptEvent( std::vector({ "cellAttach", "cellDetach" })); - AppendSink( + AppendSinkScriptEvent( std::vector({ "cellFullyLoaded" })); - AppendSink(std::vector({ "combatState" })); - AppendSink( + AppendSinkScriptEvent(std::vector({ "combatState" })); + AppendSinkScriptEvent( std::vector({ "containerChanged" })); - AppendSink(std::vector({ "deathEnd", "deathStart" })); - AppendSink( + AppendSinkScriptEvent( + std::vector({ "deathEnd", "deathStart" })); + AppendSinkScriptEvent( std::vector({ "destructionStageChanged" })); - AppendSink(std::vector({ "enterBleedout" })); - AppendSink(std::vector({ "equip", "unequip" })); - AppendSink(std::vector({ "fastTravelEnd" })); - AppendSink( + AppendSinkScriptEvent( + std::vector({ "enterBleedout" })); + AppendSinkScriptEvent( + std::vector({ "equip", "unequip" })); + AppendSinkScriptEvent( + std::vector({ "fastTravelEnd" })); + AppendSinkScriptEvent( std::vector({ "furnitureExit", "furnitureEnter" })); - AppendSink(std::vector({ "grabRelease" })); - AppendSink(std::vector({ "hit" })); - AppendSink(std::vector({ "scriptInit" })); - AppendSink(std::vector({ "loadGame" })); - AppendSink(std::vector({ "lockChanged" })); - AppendSink( + AppendSinkScriptEvent( + std::vector({ "grabRelease" })); + AppendSinkScriptEvent(std::vector({ "hit" })); + AppendSinkScriptEvent( + std::vector({ "scriptInit" })); + AppendSinkScriptEvent(std::vector({ "loadGame" })); + AppendSinkScriptEvent( + std::vector({ "lockChanged" })); + AppendSinkScriptEvent( std::vector({ "magicEffectApply" })); - AppendSink(std::vector({ "wardHit" })); - AppendSink( + AppendSinkScriptEvent( + std::vector({ "wardHit" })); + AppendSinkScriptEvent( std::vector({ "moveAttachDetach" })); - AppendSink(std::vector({ "objectLoaded" })); - AppendSink( + AppendSinkScriptEvent( + std::vector({ "objectLoaded" })); + AppendSinkScriptEvent( std::vector({ "translationFailed", "translationAlmostCompleted", "translationCompleted" })); - AppendSink(std::vector({ "open", "close" })); - AppendSink( + AppendSinkScriptEvent( + std::vector({ "open", "close" })); + AppendSinkScriptEvent( std::vector({ "packageStart", "packageChange", "packageEnd" })); - AppendSink(std::vector({ "perkEntryRun" })); - AppendSink(std::vector({ "playerBowShot" })); - AppendSink(std::vector({ "questInit" })); - AppendSink(std::vector({ "questStage" })); - AppendSink( + AppendSinkScriptEvent( + std::vector({ "perkEntryRun" })); + AppendSinkScriptEvent( + std::vector({ "playerBowShot" })); + AppendSinkScriptEvent(std::vector({ "questInit" })); + AppendSinkScriptEvent( + std::vector({ "questStage" })); + AppendSinkScriptEvent( std::vector({ "questStart", "questStop" })); - AppendSink(std::vector({ "reset" })); - AppendSink(std::vector({ "sceneAction" })); - AppendSink(std::vector({ "sell" })); - AppendSink(std::vector({ "sleepStart" })); - AppendSink(std::vector({ "sleepStop" })); - AppendSink(std::vector({ "spellCast" })); - AppendSink( + AppendSinkScriptEvent(std::vector({ "reset" })); + AppendSinkScriptEvent( + std::vector({ "sceneAction" })); + AppendSinkScriptEvent(std::vector({ "sell" })); + AppendSinkScriptEvent( + std::vector({ "sleepStart" })); + AppendSinkScriptEvent(std::vector({ "sleepStop" })); + AppendSinkScriptEvent(std::vector({ "spellCast" })); + AppendSinkScriptEvent( std::vector({ "switchRaceComplete" })); - AppendSink(std::vector({ "trackedStats" })); - AppendSink(std::vector({ "triggerEnter" })); - AppendSink(std::vector({ "trigger" })); - AppendSink(std::vector({ "triggerLeave" })); - AppendSink(std::vector({ "uniqueIdChange" })); - AppendSink(std::vector({ "waitStart" })); - AppendSink(std::vector({ "waitStop" })); + AppendSinkScriptEvent( + std::vector({ "trackedStats" })); + AppendSinkScriptEvent( + std::vector({ "triggerEnter" })); + AppendSinkScriptEvent(std::vector({ "trigger" })); + AppendSinkScriptEvent( + std::vector({ "triggerLeave" })); + AppendSinkScriptEvent( + std::vector({ "uniqueIdChange" })); + AppendSinkScriptEvent(std::vector({ "waitStart" })); + AppendSinkScriptEvent(std::vector({ "waitStop" })); // skse events // at the moment of writing, no way was found to standardize event source @@ -655,6 +674,35 @@ class EventHandler final AppendSink(std::vector({ "spellsLearned" })); } + template + void AppendSinkScriptEvent(std::vector eventNames) + { + // should consider checking if sink exists + // but since we store sink pointers + // the only option it to loop through all sinks + // and check for event names, TODO? + + auto sink = new Sink( + eventNames, + // Activate + [](const ::Sink* sink) { + const auto handler = EventHandler::GetSingleton(); + handler->ActivateSink(sink, GetEventSourceScriptEvent()); + }, + // Deactivate + [](const ::Sink* sink) { + const auto handler = EventHandler::GetSingleton(); + handler->DeactivateSink(sink, GetEventSourceScriptEvent()); + }, + // IsActive + [](const ::Sink* sink) -> bool { + const auto handler = EventHandler::GetSingleton(); + return handler->IsActiveSink(sink); + }); + + sinks.emplace(sink); + } + /** * @brief Create new sink instance and add it to sink set. * Registration via script event source. diff --git a/skyrim-platform/src/platform_se/skyrim_platform/EventUtils.h b/skyrim-platform/src/platform_se/skyrim_platform/EventUtils.h index db10cf288c..7bee972353 100644 --- a/skyrim-platform/src/platform_se/skyrim_platform/EventUtils.h +++ b/skyrim-platform/src/platform_se/skyrim_platform/EventUtils.h @@ -1,7 +1,7 @@ #pragma once template -inline RE::BSTEventSource* GetEventSource() +inline RE::BSTEventSource* GetEventSourceScriptEvent() { return RE::ScriptEventSourceHolder::GetSingleton()->GetEventSource(); }