From 246ac25d0ab0b6fc5afdc48048e31d5d085f9d9b Mon Sep 17 00:00:00 2001 From: samcake Date: Wed, 14 Feb 2018 17:36:46 -0800 Subject: [PATCH] Introducing a way to abort a task from one of its job, using it to skip highlight tasks if nothing to highlight --- .../render-utils/src/HighlightEffect.cpp | 4 +++ libraries/task/src/task/Task.cpp | 35 +++++++++++++++++++ libraries/task/src/task/Task.h | 20 ++++++++--- 3 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 libraries/task/src/task/Task.cpp diff --git a/libraries/render-utils/src/HighlightEffect.cpp b/libraries/render-utils/src/HighlightEffect.cpp index 9501a74d52..de13188733 100644 --- a/libraries/render-utils/src/HighlightEffect.cpp +++ b/libraries/render-utils/src/HighlightEffect.cpp @@ -453,6 +453,10 @@ void SelectionToHighlight::run(const render::RenderContextPointer& renderContext } } } + + if (numLayers == 0) { + renderContext->abortTask(); + } } void ExtractSelectionName::run(const render::RenderContextPointer& renderContext, const Inputs& inputs, Outputs& outputs) { diff --git a/libraries/task/src/task/Task.cpp b/libraries/task/src/task/Task.cpp new file mode 100644 index 0000000000..bb65f15b7c --- /dev/null +++ b/libraries/task/src/task/Task.cpp @@ -0,0 +1,35 @@ +// +// Task.cpp +// task/src/task +// +// Created by Sam Gateau on 2/14/2018. +// Copyright 2018 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// +#include "Task.h" + +using namespace task; + +JobContext::JobContext(const QLoggingCategory& category) : + profileCategory(category) { + assert(&category); +} + +JobContext::~JobContext() { +} + +void JobContext::resetTaskFlow() { + _doAbortTask = false; +} + +void JobContext::abortTask() { + _doAbortTask = true; +} + +bool JobContext::doAbortTask() const { + return _doAbortTask; +} + + diff --git a/libraries/task/src/task/Task.h b/libraries/task/src/task/Task.h index b75f6d7321..1f1fb79ee1 100644 --- a/libraries/task/src/task/Task.h +++ b/libraries/task/src/task/Task.h @@ -29,13 +29,21 @@ class JobNoIO {}; class JobContext { public: - JobContext(const QLoggingCategory& category) : profileCategory(category) { - assert(&category); - } - virtual ~JobContext() {} + JobContext(const QLoggingCategory& category); + virtual ~JobContext(); std::shared_ptr jobConfig { nullptr }; const QLoggingCategory& profileCategory; + + // control flow commands + void resetTaskFlow(); + void abortTask(); + + // Check command flow + bool doAbortTask() const; + +protected: + bool _doAbortTask{ false }; }; using JobContextPointer = std::shared_ptr; @@ -308,6 +316,10 @@ public: if (config->alwaysEnabled || config->enabled) { for (auto job : TaskConcept::_jobs) { job.run(jobContext); + if (jobContext->doAbortTask()) { + jobContext->resetTaskFlow(); + return; + } } } }