mirror of
https://github.com/scp-fs2open/fs2open.github.com.git
synced 2026-11-08 17:48:46 -10:00
This allows a script to create its own execution context so that it can control when a coroutine is valid to play based on custom data. Also adds a function which causes a coroutine to end in an error.
35 lines
1.0 KiB
C++
35 lines
1.0 KiB
C++
#include "CombinedExecutionContext.h"
|
|
|
|
namespace executor {
|
|
CombinedExecutionContext::CombinedExecutionContext(SCP_vector<std::shared_ptr<IExecutionContext>> contexts)
|
|
: m_contexts(std::move(contexts))
|
|
{
|
|
}
|
|
IExecutionContext::State CombinedExecutionContext::determineContextState() const
|
|
{
|
|
bool suspended_context = false;
|
|
bool invalid_context = false;
|
|
for (const auto& context : m_contexts) {
|
|
const auto state = context->determineContextState();
|
|
|
|
if (state == IExecutionContext::State::Suspended) {
|
|
suspended_context = true;
|
|
} else if (state == IExecutionContext::State::Invalid) {
|
|
invalid_context = true;
|
|
}
|
|
}
|
|
|
|
// If there is an invalid context then the combined state is invalid
|
|
// If there is not but there is a suspended one, then the state is suspended
|
|
if (invalid_context) {
|
|
return IExecutionContext::State::Invalid;
|
|
} else if (suspended_context) {
|
|
return IExecutionContext::State::Suspended;
|
|
} else {
|
|
return IExecutionContext::State::Valid;
|
|
}
|
|
}
|
|
CombinedExecutionContext::~CombinedExecutionContext() = default;
|
|
|
|
} // namespace executor
|