commit 6048e17caa8a7402e6963ee6adccc42b9445022c Author: Zomo Date: Mon Mar 29 22:21:34 2021 -0500 init diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..deb82c0 --- /dev/null +++ b/main.cpp @@ -0,0 +1,31 @@ +#include +#include +#include +#include +#include +#include "timercpp.h" + +using namespace std; + +int main(int argc, char **argv) +{ + struct winsize w; + ioctl(STDOUT_FILENO, TIOCGWINSZ, &w); + + vector< vector > screen; + + Timer t = Timer(); + + float framerate = 60.0; + float frameduration = 1000.0/framerate; + + t.setInterval([&]() { + eachFrame(w.ws_row, w.ws_col, screen); + }, (int) frameduration); + return 0; +} + +void eachFrame(short width, short height, vector< vector > screen) +{ + +} \ No newline at end of file diff --git a/main.o b/main.o new file mode 100755 index 0000000..0f97164 Binary files /dev/null and b/main.o differ diff --git a/timercpp.h b/timercpp.h new file mode 100644 index 0000000..9878c06 --- /dev/null +++ b/timercpp.h @@ -0,0 +1,50 @@ +// https: //github.com/99x/timercpp/blob/master/timercpp.h +#include +#include +#include + +class Timer +{ + bool clear = false; + + public: + void setTimeout(auto function, int delay); + void setInterval(auto function, int interval); + void stop(); +}; + +void Timer::setTimeout(auto function, int delay) +{ + this->clear = false; + std::thread t([=]() { + if (this->clear) + return; + std::this_thread::sleep_for(std::chrono::milliseconds(delay)); + if (this->clear) + return; + function(); + }); + t.detach(); +} + +void Timer::setInterval(auto function, int interval) +{ + this->clear = false; + std::thread t([=]() { + while (true) + { + if (this->clear) + return; + std::this_thread::sleep_for(std::chrono::milliseconds(interval)); + if (this->clear) + return; + function(); + } + }); + t.detach(); +} + +void Timer::stop() +{ + this->clear = true; +} \ No newline at end of file