mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-03-22 15:05:03 +01:00
configurable python renderer update rate
This commit is contained in:
19
Globals.cpp
19
Globals.cpp
@@ -564,6 +564,17 @@ global_settings::ConfigParse(cParser &Parser) {
|
||||
Parser.getTokens(1, false);
|
||||
Parser >> asLang;
|
||||
}
|
||||
else if( token == "pyscreenrendererpriority" )
|
||||
{
|
||||
// old variable, repurposed as update rate of python screen renderer
|
||||
Parser.getTokens();
|
||||
Parser >> token;
|
||||
auto const priority { ToLower( token ) };
|
||||
PythonScreenUpdateRate = (
|
||||
priority == "lower" ? 500 :
|
||||
priority == "lowest" ? 1000 :
|
||||
200 );
|
||||
}
|
||||
else if( token == "uitextcolor" ) {
|
||||
// color of the ui text. NOTE: will be obsolete once the real ui is in place
|
||||
Parser.getTokens( 3, false );
|
||||
@@ -571,11 +582,9 @@ global_settings::ConfigParse(cParser &Parser) {
|
||||
>> UITextColor.r
|
||||
>> UITextColor.g
|
||||
>> UITextColor.b;
|
||||
UITextColor.r = clamp( UITextColor.r, 0.0f, 255.0f );
|
||||
UITextColor.g = clamp( UITextColor.g, 0.0f, 255.0f );
|
||||
UITextColor.b = clamp( UITextColor.b, 0.0f, 255.0f );
|
||||
UITextColor = UITextColor / 255.0f;
|
||||
UITextColor.a = 1.0f;
|
||||
glm::clamp( UITextColor, 0.f, 255.f );
|
||||
UITextColor = UITextColor / 255.f;
|
||||
UITextColor.a = 1.f;
|
||||
}
|
||||
else if( token == "input.gamepad" ) {
|
||||
// czy grupować eventy o tych samych nazwach
|
||||
|
||||
@@ -88,6 +88,7 @@ struct global_settings {
|
||||
bool bJoinEvents{ false }; // czy grupować eventy o tych samych nazwach
|
||||
int iHiddenEvents{ 1 }; // czy łączyć eventy z torami poprzez nazwę toru
|
||||
// ui
|
||||
int PythonScreenUpdateRate { 200 }; // delay between python-based screen updates, in milliseconds
|
||||
int iTextMode{ 0 }; // tryb pracy wyświetlacza tekstowego
|
||||
int iScreenMode[ 12 ] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; // numer ekranu wyświetlacza tekstowego
|
||||
glm::vec4 UITextColor { glm::vec4( 225.f / 255.f, 225.f / 255.f, 225.f / 255.f, 1.f ) }; // base color of UI text
|
||||
|
||||
18
PyInt.cpp
18
PyInt.cpp
@@ -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)
|
||||
|
||||
26
PyInt.h
26
PyInt.h
@@ -17,6 +17,7 @@
|
||||
#include "Python.h"
|
||||
#endif
|
||||
#include "Classes.h"
|
||||
#include "timer.h"
|
||||
|
||||
#define PyGetFloat(param) PyFloat_FromDouble(param >= 0 ? param : -param)
|
||||
#define PyGetFloatS(param) PyFloat_FromDouble(param)
|
||||
@@ -25,34 +26,21 @@
|
||||
#define PyGetBool(param) param ? Py_True : Py_False
|
||||
#define PyGetString(param) PyString_FromString(param)
|
||||
|
||||
struct ltstr
|
||||
{
|
||||
bool operator()(const char *s1, const char *s2) const
|
||||
{
|
||||
return strcmp(s1, s2) < 0;
|
||||
}
|
||||
};
|
||||
|
||||
class TPythonInterpreter
|
||||
{
|
||||
protected:
|
||||
TPythonInterpreter();
|
||||
~TPythonInterpreter() {}
|
||||
static TPythonInterpreter *_instance;
|
||||
// std::set<const char *, ltstr> _classes;
|
||||
std::set<std::string> _classes;
|
||||
PyObject *_main;
|
||||
PyObject *_stdErr;
|
||||
// FILE *_getFile(const char *lookupPath, const char *className);
|
||||
FILE *_getFile( std::string const &lookupPath, std::string const &className );
|
||||
|
||||
public:
|
||||
static TPythonInterpreter *getInstance();
|
||||
static void killInstance();
|
||||
/* bool loadClassFile(const char *lookupPath, const char *className);
|
||||
PyObject *newClass(const char *className);
|
||||
PyObject *newClass(const char *className, PyObject *argsTuple);
|
||||
*/ bool loadClassFile( std::string const &lookupPath, std::string const &className );
|
||||
bool loadClassFile( std::string const &lookupPath, std::string const &className );
|
||||
PyObject *newClass( std::string const &className );
|
||||
PyObject *newClass( std::string const &className, PyObject *argsTuple );
|
||||
void handleError();
|
||||
@@ -78,16 +66,18 @@ class TPythonScreenRenderer
|
||||
class TPythonScreens
|
||||
{
|
||||
protected:
|
||||
bool _cleanupReadyFlag;
|
||||
bool _renderReadyFlag;
|
||||
bool _terminationFlag;
|
||||
std::thread *_thread;
|
||||
bool _cleanupReadyFlag{ false };
|
||||
bool _renderReadyFlag{ false };
|
||||
bool _terminationFlag{ false };
|
||||
std::thread *_thread{ nullptr };
|
||||
std::vector<TPythonScreenRenderer *> _screens;
|
||||
std::string _lookupPath;
|
||||
void *_train;
|
||||
void _cleanup();
|
||||
void _freeTrainState();
|
||||
PyObject *_trainState;
|
||||
int m_updaterate { 200 };
|
||||
Timer::stopwatch m_updatestopwatch;
|
||||
|
||||
public:
|
||||
void reset(void *train);
|
||||
|
||||
Reference in New Issue
Block a user