Skip to content

Commit

Permalink
CXX: Use std::this_thread::sleep_for for vkrender.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamievlin committed Dec 31, 2023
1 parent 56c9353 commit 244de92
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
1 change: 0 additions & 1 deletion include/vkrender.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include <sstream>
#include <stdlib.h>
#include <string>
#include <sys/time.h>
#include <unordered_map>
#include <vector>
#include <array>
Expand Down
12 changes: 6 additions & 6 deletions src/vkrender.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
#include "drawimage.h"
#include "EXRFiles.h"

#include <chrono>
#include <thread>

#define SHADER_DIRECTORY "base/shaders/"
#define VALIDATION_LAYER "VK_LAYER_KHRONOS_validation"
#define MESA_OVERLAY_LAYER "VK_LAYER_MESA_overlay"
Expand Down Expand Up @@ -513,8 +516,10 @@ void AsyVkRender::vkrender(const string& prefix, const picture* pic, const strin
double* background, size_t nlightsin, triple* lights,
double* diffuse, double* specular, bool view, int oldpid/*=0*/)
{
#if !defined(_WIN32)
// By default use discrete GPU.
setenv("DRI_PRIME","1",0);
#endif

glfwInit();

Expand Down Expand Up @@ -3792,12 +3797,7 @@ void AsyVkRender::nextFrame()
double seconds=frameTimer.seconds(true);
delay -= seconds;
if(delay > 0) {
timespec req;
timespec rem;
req.tv_sec=(unsigned int) delay;
req.tv_nsec=(unsigned int) (1.0e9*(delay-req.tv_sec));
while(nanosleep(&req,&rem) < 0 && errno == EINTR)
req=rem;
std::this_thread::sleep_for(std::chrono::duration<double>(delay));
}
if(Step) Animate=false;
}
Expand Down

0 comments on commit 244de92

Please sign in to comment.