Created
June 17, 2024 22:13
-
-
Save CoffeeVampir3/a56bc1322e582b804051b1d81772ed7c to your computer and use it in GitHub Desktop.
Problem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include <coroutine> | |
#include <utility> | |
#include <functional> | |
struct NecroAiState; | |
struct NecroAiState | |
{ | |
struct promise_type; | |
using TaskHandle = std::coroutine_handle<promise_type>; | |
struct promise_type { | |
void unhandled_exception() noexcept {} | |
NecroAiState get_return_object() { return TaskHandle::from_promise(*this); } | |
std::suspend_always initial_suspend() noexcept { return {}; } | |
std::suspend_always final_suspend() noexcept { return {}; } | |
void return_void() const noexcept {} | |
}; | |
TaskHandle Handle; | |
NecroAiState(const TaskHandle H) : Handle{H} {} | |
//~NecroAiState | |
//This memory is owned and managed by the State Machine, it frees everything and manages these coroutine lifetimes. | |
explicit operator TaskHandle() const { return Handle; } | |
explicit operator bool() const { return Handle && !Handle.done(); } | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Fill out your copyright notice in the Description page of Project Settings. | |
#pragma once | |
#include <coroutine> | |
#include <utility> | |
#include <functional> | |
struct NecroAiStateMachine; | |
struct NecroAiTask { | |
struct promise_type; | |
using TaskHandle = std::coroutine_handle<promise_type>; | |
struct promise_type { | |
void unhandled_exception() noexcept {} | |
NecroAiTask get_return_object() { return TaskHandle::from_promise(*this); } | |
std::suspend_always initial_suspend() noexcept { return {}; } | |
std::suspend_always final_suspend() noexcept { return {}; } | |
void return_void() const noexcept {} | |
}; | |
TaskHandle Handle; | |
NecroAiTask(const TaskHandle H) : Handle{H} {} | |
//~NecroAiTask | |
//This memory is owned and managed by the State Machine, it frees everything and manages these coroutine lifetimes. | |
explicit operator TaskHandle() const { return Handle; } | |
explicit operator bool() const { return Handle && !Handle.done(); } | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment