implement global tick routine in windows
This commit is contained in:
20
src/main.cpp
20
src/main.cpp
@@ -483,6 +483,7 @@ int main(int argc, char** argv)
|
|||||||
std::thread renderer([&] {
|
std::thread renderer([&] {
|
||||||
BT_SetTerminate();
|
BT_SetTerminate();
|
||||||
const float target_fps = 10;
|
const float target_fps = 10;
|
||||||
|
const float target_tick_rate = 60;
|
||||||
unsigned long t0 = GetTickCount();
|
unsigned long t0 = GetTickCount();
|
||||||
unsigned long t1;
|
unsigned long t1;
|
||||||
int frames = 0;
|
int frames = 0;
|
||||||
@@ -514,16 +515,21 @@ int main(int argc, char** argv)
|
|||||||
working_list = std::move(tasklist);
|
working_list = std::move(tasklist);
|
||||||
}
|
}
|
||||||
|
|
||||||
async_lock();
|
if (!working_list.empty())
|
||||||
while (!working_list.empty())
|
|
||||||
{
|
{
|
||||||
|
async_lock();
|
||||||
|
while (!working_list.empty())
|
||||||
|
{
|
||||||
|
|
||||||
working_list.front()();
|
working_list.front()();
|
||||||
working_list.pop_front();
|
working_list.pop_front();
|
||||||
|
}
|
||||||
|
async_unlock();
|
||||||
}
|
}
|
||||||
async_unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
App::I.tick(dt);
|
||||||
|
|
||||||
std::unique_lock<std::mutex> lock(render_mutex);
|
std::unique_lock<std::mutex> lock(render_mutex);
|
||||||
if (render_timer > 1.0f / target_fps)
|
if (render_timer > 1.0f / target_fps)
|
||||||
{
|
{
|
||||||
@@ -541,10 +547,10 @@ int main(int argc, char** argv)
|
|||||||
async_unlock();
|
async_unlock();
|
||||||
frame_timer = 0;
|
frame_timer = 0;
|
||||||
//LOG("swap main");
|
//LOG("swap main");
|
||||||
|
frames++;
|
||||||
}
|
}
|
||||||
frames++;
|
|
||||||
|
|
||||||
const int framerate = (1.f / target_fps) * 1000;
|
const int framerate = (1.f / target_tick_rate) * 1000;
|
||||||
const int diff = framerate - (t1 - t0);
|
const int diff = framerate - (t1 - t0);
|
||||||
render_cv.wait_for(lock, std::chrono::milliseconds(diff));
|
render_cv.wait_for(lock, std::chrono::milliseconds(diff));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user