Files
fs2open.github.com/code/executor/GameStateExecutionContext.h
asarium 016c07dc3a Add feature to execute Lua coroutines at specific points
This adds a mechanism for running generic operations at specific points
of the frame execution. This can be used by any part of the code an not
just Lua since it simply executes std::functions. It also adds an
"execution context" concept that specifies in which situation an
operation should be executed.

This is then used by the Lua Coroutines code for resuming coroutines at
specific points instead of always when the awaited promise resolves.
2020-06-06 21:29:48 +02:00

32 lines
1.0 KiB
C++

#pragma once
#include "IExecutionContext.h"
#include "gamesequence/gamesequence.h"
#include "utils/event.h"
namespace executor {
/**
* @brief An execution context that captures the game state
*
* This will only execute if the game state is the same as at the time when captureContext() was called. If a game state
* is pushed onto the stack then this context will only suspend. Should the game state change completely then this
* context will be invalid. Will also become invalid if the same game state is active but with a different instance id.
*/
class GameStateExecutionContext : public IExecutionContext, public std::enable_shared_from_this<GameStateExecutionContext> {
public:
GameStateExecutionContext(GS_STATE contextState, int stateInstance);
~GameStateExecutionContext() override;
State determineContextState() const override;
static std::shared_ptr<IExecutionContext> captureContext();
private:
GS_STATE m_contextState = GS_STATE_INVALID;
int m_stateInstanceId = -1;
};
} // namespace executor