← Back

ofxTaskRunner

github.com/ffunatsu/ofxTaskRunner · @ffunatsu
OF 0.11 Utilities

Task runner for openFrameworks (kinda like UniTask or bevy_flurx)

0 0 Last commit 1y ago Created 1y ago

README

ofxTaskRunner



A task runner addon for openFrameworks that allows you to create time-based sequences of actions. (kinda like UniTask or bevy_flurx)

Features



Note: this is not multi-threaded ( vs ofxAsync )



This addon is not using other threads. All actions are done on the main thread (so it's single threaded).

If you need real multi-thread, please consider to use std::thread or ofxAsync instead.

Dependencies



Installation



1. Download or clone this repository into your openFrameworks/addons folder 2. Include the addon in your project using the Project Generator or by adding it to your build configuration

Usage



Basic Example



// In ofApp.h

pragma once

include "ofMain.h"

include "ofxTaskRunner.h"

class ofApp : public ofBaseApp{ public: void setup(); void update(); void draw(); // ... other methods ofxTaskRunner<ofApp> taskRunner; ofColor backgroundColor; };


// In ofApp.cpp
void ofApp::setup(){
    // Initialize the task runner with a reference to the app
    taskRunner.setup(*this);
    
    // Create a task queue that changes background color over time
    taskRunner.createTaskQueue()
        .wait_sec(1.0)
        .then([](ofApp& self){
            self.backgroundColor = ofColor(255, 0, 0); // Red
        })
        .wait_sec(1.0)
        .then([](ofApp& self){
            self.backgroundColor = ofColor(0, 255, 0); // Green
        })
        .wait_sec(1.0)
        .then([](ofApp& self){
            self.backgroundColor = ofColor(0, 0, 255); // Blue
        });
}

void ofApp::update(){
    taskRunner.update(); // Update the task runner
}

void ofApp::draw(){
    ofBackground(backgroundColor);
    taskRunner.draw(); // Optional: draw any task-related visuals (described in then_on_draw() functions)
}


Synchronized Tasks Example



You can create multiple tasks that run in sync with each other (for example: multiple screen app, which has same synced multiple tasks):

for(int i = 0; i < NUM_TASKS; i++) {
    int taskId = i + 1;

    // Register task ID first (needed for synchronization)
    taskRunner.registerTaskId(taskId);
}

// Create multiple synchronized tasks
for(int i = 0; i < NUM_TASKS; i++) {
    int taskId = i + 1;
    
    taskRunner.createTaskQueue(taskId, "sync_task") // Group tasks by task name
        .wait_sync_sec(1.0) // synchroned wait among group
        .then([](ofApp& self){
            // First action
        })
        .wait_sync_sec(1.0) // synchroned wait among group
        .then([](ofApp& self){
            // Second action
        });
}


API Reference



ofxTaskRunner<AppType>



TaskQueue<AppType>



Examples



The addon includes several examples:

1. example - A simple example showing background color changes over time 2. example_sync - Demonstrates synchronized tasks with multiple animations

License



MIT License

Get this addon

HTTPS
SSH