Skip to content

Instantly share code, notes, and snippets.

@CoffeeVampir3
Created June 17, 2024 22:13
Show Gist options
  • Save CoffeeVampir3/a56bc1322e582b804051b1d81772ed7c to your computer and use it in GitHub Desktop.
Save CoffeeVampir3/a56bc1322e582b804051b1d81772ed7c to your computer and use it in GitHub Desktop.
Problem
#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(); }
};
// 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