forked from eu07/maszyna
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PyInt.h
94 lines (83 loc) · 2.32 KB
/
PyInt.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#ifndef PyIntH
#define PyIntH
#ifdef _POSIX_C_SOURCE
#undef _POSIX_C_SOURCE
#endif
#ifdef _XOPEN_SOURCE
#undef _XOPEN_SOURCE
#endif
#ifdef _DEBUG
#undef _DEBUG // bez tego macra Py_DECREF powoduja problemy przy linkowaniu
#include "Python.h"
#define _DEBUG
#else
#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)
#define PyGetInt(param) PyInt_FromLong(param)
#define PyGetFloatS(param) PyFloat_FromDouble(param)
#define PyGetBool(param) param ? Py_True : Py_False
#define PyGetString(param) PyString_FromString(param)
class TPythonInterpreter
{
protected:
TPythonInterpreter();
~TPythonInterpreter() {}
static TPythonInterpreter *_instance;
std::set<std::string> _classes;
PyObject *_main;
PyObject *_stdErr;
FILE *_getFile( std::string const &lookupPath, std::string const &className );
public:
static TPythonInterpreter *getInstance();
static void killInstance();
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();
};
class TPythonScreenRenderer
{
protected:
PyObject *_pyRenderer;
PyObject *_pyTexture;
int _textureId;
PyObject *_pyWidth;
PyObject *_pyHeight;
public:
TPythonScreenRenderer(int textureId, PyObject *renderer);
~TPythonScreenRenderer();
void render(PyObject *trainState);
void cleanup();
void updateTexture();
};
class TPythonScreens
{
protected:
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);
void setLookupPath(std::string const &path);
void init(cParser &parser, TModel3d *model, std::string const &name, int const cab);
void update();
TPythonScreens();
~TPythonScreens();
void run();
void start();
void finish();
};
#endif // PyIntH