123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- /*
- * Copyright (c) Contributors to the Open 3D Engine Project.
- * For complete copyright and license terms please see the LICENSE at the root of this distribution.
- *
- * SPDX-License-Identifier: Apache-2.0 OR MIT
- *
- */
- #pragma once
- #include <AzCore/Component/Entity.h>
- #include <AzCore/Component/EntityId.h>
- #include <AzCore/Debug/TraceMessageBus.h>
- #include <AzCore/RTTI/BehaviorContext.h>
- #include <AzFramework/Entity/EntityContextBus.h>
- #include <AzFramework/Entity/SliceEntityOwnershipServiceBus.h>
- #include <ScriptCanvas/Asset/RuntimeAsset.h>
- #include <ScriptCanvas/Asset/RuntimeAssetHandler.h>
- #include <ScriptCanvas/Core/Core.h>
- #include <ScriptCanvas/Core/Graph.h>
- #include <ScriptCanvas/Core/ScriptCanvasBus.h>
- #include <ScriptCanvas/Data/Data.h>
- #include <ScriptCanvas/Variable/VariableBus.h>
- #include <ScriptCanvas/Assets/ScriptCanvasFileHandling.h>
- namespace AZ
- {
- class ScriptAsset;
- }
- namespace ScriptCanvas
- {
- class RuntimeAsset;
- class RuntimeComponent;
- }
- namespace ScriptCanvasEditor
- {
- struct LoadTestGraphResult
- {
- AZStd::unique_ptr<AZ::Entity> m_entity;
- ScriptCanvas::RuntimeComponent* m_runtimeComponent = nullptr;
- bool m_nativeFunctionFound = false;
- SourceHandle m_editorAsset;
- AZ::Data::Asset<ScriptCanvas::RuntimeAsset> m_runtimeAsset;
- AZ::Data::Asset<AZ::ScriptAsset> m_scriptAsset;
- };
- // how long a unit test should be allowed to execute
- enum class eDuration
- {
- InitialActivation = 0, // kill the test as soon as control returns from the graph
- Seconds, // wait for the specified amount of seconds, regardless of ticks
- Ticks, // wait for the the specified amount of ticks, regardless of seconds
- };
- struct DurationSpec
- {
- eDuration m_spec = eDuration::InitialActivation;
- size_t m_ticks = 0;
- float m_seconds = 0.0f;
- float m_timeStep = (1.0f / 60.0f);
- static DurationSpec Seconds(float seconds);
- static DurationSpec Ticks(size_t ticks);
- };
- class TraceSuppressionRequests
- : public AZ::EBusTraits
- {
- public:
- static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single;
- virtual void SuppressPreAssert(bool suppress) = 0;
- virtual void SuppressAssert(bool suppress) = 0;
- virtual void SuppressException(bool suppress) = 0;
- virtual void SuppressPreError(bool suppress) = 0;
- virtual void SuppressError(bool suppress) = 0;
- virtual void SuppressPreWarning(bool suppress) = 0;
- virtual void SuppressWarning(bool suppress) = 0;
- virtual void SuppressPrintf(bool suppress) = 0;
- virtual void SuppressAllOutput(bool suppress) = 0;
- };
- using TraceSuppressionBus = AZ::EBus<TraceSuppressionRequests>;
- class TraceMessageComponent
- : public AZ::Component
- , protected AZ::Debug::TraceMessageBus::Handler
- , protected TraceSuppressionBus::Handler
- {
- public:
- AZ_COMPONENT(TraceMessageComponent, "{E12144CE-809D-4056-9735-4384D7DBCCDC}");
- TraceMessageComponent() = default;
- ~TraceMessageComponent() override = default;
- void Activate() override
- {
- AZ::Debug::TraceMessageBus::Handler::BusConnect();
- TraceSuppressionBus::Handler::BusConnect();
- }
- void Deactivate() override
- {
- AZ::Debug::TraceMessageBus::Handler::BusDisconnect();
- TraceSuppressionBus::Handler::BusDisconnect();
- }
- private:
- /// \ref ComponentDescriptor::Reflect
- static void Reflect(AZ::ReflectContext* context)
- {
- if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
- {
- serializeContext->Class<TraceMessageComponent, AZ::Component>()
- ->Version(0)
- ;
- }
- }
- bool OnPreAssert(const char*, int, const char*, const char*) override { return suppressPreAssert; }
- bool OnAssert(const char*) override { return suppressAssert; }
- bool OnException(const char*) override { return suppressException; }
- bool OnPreError(const char*, const char*, int, const char*, const char*) override { return suppressPreError; }
- bool OnError(const char*, const char*) override { return suppressError; }
- bool OnPreWarning(const char*, const char*, int, const char*, const char*) override { return suppressPreWarning; }
- bool OnWarning(const char*, const char*) override { return suppressWarning; }
- bool OnPrintf(const char*, const char*) override { return suppressPrintf; }
- bool OnOutput(const char*, const char*) override { return suppressAllOutput; }
- void SuppressPreAssert(bool suppress) override { suppressPreAssert = suppress; }
- void SuppressAssert(bool suppress)override { suppressAssert = suppress; }
- void SuppressException(bool suppress) override { suppressException = suppress; }
- void SuppressPreError(bool suppress) override { suppressPreError = suppress; }
- void SuppressError(bool suppress) override { suppressPreError = suppress; }
- void SuppressPreWarning(bool suppress) override { suppressPreWarning = suppress; }
- void SuppressWarning(bool suppress) override { suppressWarning = suppress; }
- void SuppressPrintf(bool suppress) override { suppressPrintf = suppress; }
- void SuppressAllOutput(bool suppress) override { suppressAllOutput = suppress; }
- bool suppressPreAssert = false;
- bool suppressAssert = false;
- bool suppressException = false;
- bool suppressPreError = false;
- bool suppressError = false;
- bool suppressPreWarning = false;
- bool suppressWarning = false;
- bool suppressPrintf = false;
- bool suppressAllOutput = false;
- };
- struct ScopedOutputSuppression
- {
- ScopedOutputSuppression([[maybe_unused]] bool suppressState = true)
- {
- AZ::Debug::TraceMessageBus::BroadcastResult(m_oldSuppression, &AZ::Debug::TraceMessageEvents::OnOutput, "", "");
- TraceSuppressionBus::Broadcast(&TraceSuppressionRequests::SuppressAllOutput, suppressState);
- }
- ~ScopedOutputSuppression()
- {
- TraceSuppressionBus::Broadcast(&TraceSuppressionRequests::SuppressAllOutput, m_oldSuppression);
- }
- private:
- bool m_oldSuppression = false;
- };
- } // ScriptCanvasEditor
|