configurable python renderer update rate

This commit is contained in:
tmj-fstate
2018-04-28 16:45:19 +02:00
parent 22df82c8c0
commit b9be22eb25
4 changed files with 34 additions and 30 deletions

View File

@@ -1,6 +1,7 @@
#include "stdafx.h"
#include "PyInt.h"
#include "globals.h"
#include "parser.h"
#include "renderer.h"
#include "Model3d.h"
@@ -456,6 +457,7 @@ void TPythonScreens::init(cParser &parser, TModel3d *model, std::string const &n
WriteLog( "Python Screen: null renderer for " + pyClassName + " - Ignoring screen" );
return; // nie mozna utworzyc obiektu Pythonowego
}
m_updaterate = Global.PythonScreenUpdateRate;
TPythonScreenRenderer *renderer = new TPythonScreenRenderer(textureId, pyRenderer);
_screens.push_back(renderer);
WriteLog( "Created python screen " + pyClassName + " on submodel " + subModelName + " (" + std::to_string(textureId) + ")" );
@@ -485,10 +487,6 @@ void TPythonScreens::setLookupPath(std::string const &path)
TPythonScreens::TPythonScreens()
{
TPythonInterpreter::getInstance()->loadClassFile("", "abstractscreenrenderer");
_terminationFlag = false;
_renderReadyFlag = false;
_cleanupReadyFlag = false;
_thread = NULL;
}
TPythonScreens::~TPythonScreens()
@@ -512,6 +510,7 @@ void TPythonScreens::run()
{
while (1)
{
m_updatestopwatch.start();
if (_terminationFlag)
{
return;
@@ -535,12 +534,17 @@ void TPythonScreens::run()
return;
}
_renderReadyFlag = true;
m_updatestopwatch.stop();
while (!_cleanupReadyFlag && !_terminationFlag)
{
auto const sleeptime {
std::max(
100,
m_updaterate - static_cast<int>( m_updatestopwatch.average() ) ) };
#ifdef _WIN32
Sleep(100);
Sleep( sleeptime );
#elif __linux__
usleep(100*1000);
usleep( sleeptime * 1000 );
#endif
}
if (_terminationFlag)
@@ -553,7 +557,7 @@ void TPythonScreens::run()
void TPythonScreens::finish()
{
_thread = NULL;
// nothing to do here, proper clean up takes place afterwards
}
void ScreenRendererThread(TPythonScreens* renderer)