From 6048e17caa8a7402e6963ee6adccc42b9445022c Mon Sep 17 00:00:00 2001 From: Zomo Date: Mon, 29 Mar 2021 22:21:34 -0500 Subject: [PATCH] init --- main.cpp | 31 +++++++++++++++++++++++++++++++ main.o | Bin 0 -> 12604 bytes timercpp.h | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+) create mode 100644 main.cpp create mode 100755 main.o create mode 100644 timercpp.h 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 0000000000000000000000000000000000000000..0f9716432a6d26d1317edc5905ac55209d8c6080 GIT binary patch literal 12604 zcmeHN&1+LZ5Z}~VL#rlL5XBFk*7#NFhZgiuq16T>mZ(h&BG@G#uT3CdBrn60 zP$=j@{Tn=Z^QH#{_2kuq2M;P$6g-NE@i+VSHF>Y<$y;a0yq%eyoj3E_EG&K`?V^9GJmj)%{WyIs`! zpxY+2j#PxhmuOjj$+A_-sy+$xME#pmg_sJk;@M&xuI)#;|AXC++J!u#_Xi96thauvThFPtq`o>HdbR$RXmgEzmRVdv-6NqTd<#!6dioX^oy(bM6PQ_k7y^VA8Q zXi#m6J*P!w-z7vCj zf7S5@>*<_(X*~=En9g5srCjRGW)i)r*=!0r(N-|!5j9hLCl4PRxYKp>TD2oOaR@d8 zOz#(gcF_tZS>@1nu;l>cAkAsohx%2$p7TTRMQZ9D>ObMTfe^k%F32a@-QCmQgQPME zmFLkWe_zUnvfTc$*|KHkdXDQQDuX?EQa(kzjPT#Db;6g45nu!u0Y-okU<4QeM&SP; zFcGPJh|GQIdlCLgL2FmOM{1RCPwA@oByIVJBJ&fAkHq2;=z+(T#mM}zNpcInhY@#1 zGJb|Jri|}k+z6@vRW1Cs_A)Z}yzk<(dgvZ5cJ88 zUazOuk@OZ)Hj_8YMkv)Tl7(y~m$zm6F1wBVLCvGOm*U7y(9r5nu!u0Y-okU<4QeMt~7m5eQWAt$;pu+}7iYD4L681Q-EE zfDvE>7y(9r5nu!u0Y-okU<6he0-arAj7r`xL`}7-8D1vPACBhrb0x7L%9xRvLek2T z;)ha1H@YiegjVn;U6ZM{5Csq)k{I@K)$ R1AW_s4~oAOw@d^D{RZh~@Z +#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