init
This commit is contained in:
31
main.cpp
Normal file
31
main.cpp
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
#include "timercpp.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
struct winsize w;
|
||||||
|
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
|
||||||
|
|
||||||
|
vector< vector<char> > 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<char> > screen)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
50
timercpp.h
Normal file
50
timercpp.h
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
// https: //github.com/99x/timercpp/blob/master/timercpp.h
|
||||||
|
#include <iostream>
|
||||||
|
#include <thread>
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user