From 3d43a5faff7e0cdd6bb37bce4c72a3d026f82fb0 Mon Sep 17 00:00:00 2001 From: vypxl Date: Sun, 30 Jan 2022 18:16:57 +0100 Subject: [PATCH] Fix speed in web --- src/sort.cpp | 10 +++++++--- src/viz.cpp | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/sort.cpp b/src/sort.cpp index 11ba44c..c502ada 100644 --- a/src/sort.cpp +++ b/src/sort.cpp @@ -17,10 +17,14 @@ Sort::~Sort() { } #ifdef __EMSCRIPTEN__ void Sort::em_tick() { - if (!finished && !paused) - stats.elapsed = std::chrono::system_clock::now() - starttime; + auto tick_begin = std::chrono::system_clock::now(); - if (!paused) step(); + while (std::chrono::system_clock::now() - tick_begin < std::chrono::milliseconds(15)) { + if (!finished && !paused) + stats.elapsed = std::chrono::system_clock::now() - starttime; + + if (!paused) step(); + } } #endif diff --git a/src/viz.cpp b/src/viz.cpp index 3906247..8d00b5c 100644 --- a/src/viz.cpp +++ b/src/viz.cpp @@ -108,7 +108,7 @@ int Viz::init() { // Initialize VBOs glGenBuffers(1, &dataBuffer); glGenBuffers(1, &indexBuffer); - + // Initialize data, sort and style setDataSize(dataSizes[current_data_size]); changeStyle(Styles::Varietyloop);