Coder Social home page Coder Social logo

corobehaviour's Introduction

CoroBehaviour

This is the coroutine class using C++ and boost coroutine2.
Usage of CoroBehaviour is very similar with MonoBehavior Unity.
You may try to introduce this to the project of Unreal Engine.

Requirements

Boost Coroutine2

CoroBehaviour vs. MonoBehaviour

MonoBehaviour in Unity:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ExampleClass : MonoBehaviour
{
    void Start()
    {
        StartCoroutine(coroutineA());
    }

    IEnumerator coroutineA()
    {
        // wait for 1 second
        Debug.Log("coroutineA created");
        yield return new WaitForSeconds(1.0f);
        yield return StartCoroutine(coroutineB());
        Debug.Log("coroutineA running again");
    }

    IEnumerator coroutineB()
    {
        Debug.Log("coroutineB created");
        yield return new WaitForSeconds(2.5f);
        Debug.Log("coroutineB enables coroutineA to run");
    }
}

CoroBehaviour in C++:

#include "CoroBehaviour.h"
#include <iostream>

class ExampleClass : public CoroBehaviour
{
    void Start()
    {
        StartCoroutine(coroutineA());
    }

    CoroEnumerator coroutineA()
    {
        return [=](CoroPush& YieldReturn)
        {
            // wait for 1 second
            std::cout << "coroutineA created";
            YieldReturn(new WaitForSeconds(1.0f));
            YieldReturn(StartCoroutine(coroutineB()));
            std::cout << "coroutineA running again";
        };
    }

    CoroEnumerator coroutineB()
    {
        return [=](CoroPush& YieldReturn)
        {
            std::cout << "coroutineB created";
            YieldReturn(new WaitForSeconds(2.5f));
            std::cout << "coroutineB enables coroutineA to run";
        };
    }
}

Disclaimer

I didn't consider about performace, stability and security.
Please use this at your own risk.

And I have no plan to make this move forward.
Please do it yourself if you need more features.

Contact

[email protected]

corobehaviour's People

Contributors

exawon avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.