-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainExample.cpp
More file actions
37 lines (31 loc) · 1.16 KB
/
mainExample.cpp
File metadata and controls
37 lines (31 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <iostream>
#include <memory>
#include <chrono>
#include <thread>
#include "Utility/task.hpp"
#include "Utility/taskActions.hpp"
#include <conio.h> //nonstandard
using namespace MV;
int main() {
std::cout << "Start\n";
Task root("Root");
char c = ' ';
//Set up some tasks to show a few different ways to do so with a mix of ActionBase derived classes and custom behaviours.
root.then("PrintCount", [](Task& t, double) {std::cout << t.elapsed() << "\n"; return t.elapsed() > 2.0f;}).recent()
->localInterval(0.2f);
root.then(std::make_shared<BlockForSeconds>(2.0)).recent()
->onFinish.connect("Finish", [](Task&) {std::cout << "\n2 Second Invisible Wait Done... Press x to Quit\n"; });
root.then(std::make_shared<BlockUntil>([&]() {return c == 'x'; })).recent()
->onFinish.connect("Finish", [](Task&) {std::cout << "Goodbye!\n"; });
//Execute the demo!
auto start = std::chrono::high_resolution_clock::now();
double timestep = 0.0f;
while (!root.update(timestep)) {
if (_kbhit()) { //nonstandard
c = _getch();
}
auto end = std::chrono::high_resolution_clock::now();
timestep = std::chrono::duration<double>(end - start).count();
start = end;
}
}