mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-22 19:49:19 +02: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.getTokens(1, false);
|
||||||
Parser >> asLang;
|
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" ) {
|
else if( token == "uitextcolor" ) {
|
||||||
// color of the ui text. NOTE: will be obsolete once the real ui is in place
|
// color of the ui text. NOTE: will be obsolete once the real ui is in place
|
||||||
Parser.getTokens( 3, false );
|
Parser.getTokens( 3, false );
|
||||||
@@ -571,11 +582,9 @@ global_settings::ConfigParse(cParser &Parser) {
|
|||||||
>> UITextColor.r
|
>> UITextColor.r
|
||||||
>> UITextColor.g
|
>> UITextColor.g
|
||||||
>> UITextColor.b;
|
>> UITextColor.b;
|
||||||
UITextColor.r = clamp( UITextColor.r, 0.0f, 255.0f );
|
glm::clamp( UITextColor, 0.f, 255.f );
|
||||||
UITextColor.g = clamp( UITextColor.g, 0.0f, 255.0f );
|
UITextColor = UITextColor / 255.f;
|
||||||
UITextColor.b = clamp( UITextColor.b, 0.0f, 255.0f );
|
UITextColor.a = 1.f;
|
||||||
UITextColor = UITextColor / 255.0f;
|
|
||||||
UITextColor.a = 1.0f;
|
|
||||||
}
|
}
|
||||||
else if( token == "input.gamepad" ) {
|
else if( token == "input.gamepad" ) {
|
||||||
// czy grupować eventy o tych samych nazwach
|
// czy grupować eventy o tych samych nazwach
|
||||||
|
|||||||
@@ -88,6 +88,7 @@ struct global_settings {
|
|||||||
bool bJoinEvents{ false }; // czy grupować eventy o tych samych nazwach
|
bool bJoinEvents{ false }; // czy grupować eventy o tych samych nazwach
|
||||||
int iHiddenEvents{ 1 }; // czy łączyć eventy z torami poprzez nazwę toru
|
int iHiddenEvents{ 1 }; // czy łączyć eventy z torami poprzez nazwę toru
|
||||||
// ui
|
// ui
|
||||||
|
int PythonScreenUpdateRate { 200 }; // delay between python-based screen updates, in milliseconds
|
||||||
int iTextMode{ 0 }; // tryb pracy wyświetlacza tekstowego
|
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
|
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
|
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 "stdafx.h"
|
||||||
#include "PyInt.h"
|
#include "PyInt.h"
|
||||||
|
|
||||||
|
#include "globals.h"
|
||||||
#include "parser.h"
|
#include "parser.h"
|
||||||
#include "renderer.h"
|
#include "renderer.h"
|
||||||
#include "Model3d.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" );
|
WriteLog( "Python Screen: null renderer for " + pyClassName + " - Ignoring screen" );
|
||||||
return; // nie mozna utworzyc obiektu Pythonowego
|
return; // nie mozna utworzyc obiektu Pythonowego
|
||||||
}
|
}
|
||||||
|
m_updaterate = Global.PythonScreenUpdateRate;
|
||||||
TPythonScreenRenderer *renderer = new TPythonScreenRenderer(textureId, pyRenderer);
|
TPythonScreenRenderer *renderer = new TPythonScreenRenderer(textureId, pyRenderer);
|
||||||
_screens.push_back(renderer);
|
_screens.push_back(renderer);
|
||||||
WriteLog( "Created python screen " + pyClassName + " on submodel " + subModelName + " (" + std::to_string(textureId) + ")" );
|
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()
|
TPythonScreens::TPythonScreens()
|
||||||
{
|
{
|
||||||
TPythonInterpreter::getInstance()->loadClassFile("", "abstractscreenrenderer");
|
TPythonInterpreter::getInstance()->loadClassFile("", "abstractscreenrenderer");
|
||||||
_terminationFlag = false;
|
|
||||||
_renderReadyFlag = false;
|
|
||||||
_cleanupReadyFlag = false;
|
|
||||||
_thread = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TPythonScreens::~TPythonScreens()
|
TPythonScreens::~TPythonScreens()
|
||||||
@@ -512,6 +510,7 @@ void TPythonScreens::run()
|
|||||||
{
|
{
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
|
m_updatestopwatch.start();
|
||||||
if (_terminationFlag)
|
if (_terminationFlag)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@@ -535,12 +534,17 @@ void TPythonScreens::run()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_renderReadyFlag = true;
|
_renderReadyFlag = true;
|
||||||
|
m_updatestopwatch.stop();
|
||||||
while (!_cleanupReadyFlag && !_terminationFlag)
|
while (!_cleanupReadyFlag && !_terminationFlag)
|
||||||
{
|
{
|
||||||
|
auto const sleeptime {
|
||||||
|
std::max(
|
||||||
|
100,
|
||||||
|
m_updaterate - static_cast<int>( m_updatestopwatch.average() ) ) };
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
Sleep(100);
|
Sleep( sleeptime );
|
||||||
#elif __linux__
|
#elif __linux__
|
||||||
usleep(100*1000);
|
usleep( sleeptime * 1000 );
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
if (_terminationFlag)
|
if (_terminationFlag)
|
||||||
@@ -553,7 +557,7 @@ void TPythonScreens::run()
|
|||||||
|
|
||||||
void TPythonScreens::finish()
|
void TPythonScreens::finish()
|
||||||
{
|
{
|
||||||
_thread = NULL;
|
// nothing to do here, proper clean up takes place afterwards
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenRendererThread(TPythonScreens* renderer)
|
void ScreenRendererThread(TPythonScreens* renderer)
|
||||||
|
|||||||
26
PyInt.h
26
PyInt.h
@@ -17,6 +17,7 @@
|
|||||||
#include "Python.h"
|
#include "Python.h"
|
||||||
#endif
|
#endif
|
||||||
#include "Classes.h"
|
#include "Classes.h"
|
||||||
|
#include "timer.h"
|
||||||
|
|
||||||
#define PyGetFloat(param) PyFloat_FromDouble(param >= 0 ? param : -param)
|
#define PyGetFloat(param) PyFloat_FromDouble(param >= 0 ? param : -param)
|
||||||
#define PyGetFloatS(param) PyFloat_FromDouble(param)
|
#define PyGetFloatS(param) PyFloat_FromDouble(param)
|
||||||
@@ -25,34 +26,21 @@
|
|||||||
#define PyGetBool(param) param ? Py_True : Py_False
|
#define PyGetBool(param) param ? Py_True : Py_False
|
||||||
#define PyGetString(param) PyString_FromString(param)
|
#define PyGetString(param) PyString_FromString(param)
|
||||||
|
|
||||||
struct ltstr
|
|
||||||
{
|
|
||||||
bool operator()(const char *s1, const char *s2) const
|
|
||||||
{
|
|
||||||
return strcmp(s1, s2) < 0;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class TPythonInterpreter
|
class TPythonInterpreter
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
TPythonInterpreter();
|
TPythonInterpreter();
|
||||||
~TPythonInterpreter() {}
|
~TPythonInterpreter() {}
|
||||||
static TPythonInterpreter *_instance;
|
static TPythonInterpreter *_instance;
|
||||||
// std::set<const char *, ltstr> _classes;
|
|
||||||
std::set<std::string> _classes;
|
std::set<std::string> _classes;
|
||||||
PyObject *_main;
|
PyObject *_main;
|
||||||
PyObject *_stdErr;
|
PyObject *_stdErr;
|
||||||
// FILE *_getFile(const char *lookupPath, const char *className);
|
|
||||||
FILE *_getFile( std::string const &lookupPath, std::string const &className );
|
FILE *_getFile( std::string const &lookupPath, std::string const &className );
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static TPythonInterpreter *getInstance();
|
static TPythonInterpreter *getInstance();
|
||||||
static void killInstance();
|
static void killInstance();
|
||||||
/* bool loadClassFile(const char *lookupPath, const char *className);
|
bool loadClassFile( std::string const &lookupPath, std::string const &className );
|
||||||
PyObject *newClass(const char *className);
|
|
||||||
PyObject *newClass(const char *className, PyObject *argsTuple);
|
|
||||||
*/ bool loadClassFile( std::string const &lookupPath, std::string const &className );
|
|
||||||
PyObject *newClass( std::string const &className );
|
PyObject *newClass( std::string const &className );
|
||||||
PyObject *newClass( std::string const &className, PyObject *argsTuple );
|
PyObject *newClass( std::string const &className, PyObject *argsTuple );
|
||||||
void handleError();
|
void handleError();
|
||||||
@@ -78,16 +66,18 @@ class TPythonScreenRenderer
|
|||||||
class TPythonScreens
|
class TPythonScreens
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
bool _cleanupReadyFlag;
|
bool _cleanupReadyFlag{ false };
|
||||||
bool _renderReadyFlag;
|
bool _renderReadyFlag{ false };
|
||||||
bool _terminationFlag;
|
bool _terminationFlag{ false };
|
||||||
std::thread *_thread;
|
std::thread *_thread{ nullptr };
|
||||||
std::vector<TPythonScreenRenderer *> _screens;
|
std::vector<TPythonScreenRenderer *> _screens;
|
||||||
std::string _lookupPath;
|
std::string _lookupPath;
|
||||||
void *_train;
|
void *_train;
|
||||||
void _cleanup();
|
void _cleanup();
|
||||||
void _freeTrainState();
|
void _freeTrainState();
|
||||||
PyObject *_trainState;
|
PyObject *_trainState;
|
||||||
|
int m_updaterate { 200 };
|
||||||
|
Timer::stopwatch m_updatestopwatch;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void reset(void *train);
|
void reset(void *train);
|
||||||
|
|||||||
Reference in New Issue
Block a user