mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-21 01:19:18 +02:00
Conversion to cpp 20
This commit is contained in:
131
PyInt.h
131
PyInt.h
@@ -19,8 +19,8 @@ http://mozilla.org/MPL/2.0/.
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning( push )
|
||||
#pragma warning( disable : 5033 )
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 5033)
|
||||
#endif
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC diagnostic push
|
||||
@@ -44,12 +44,13 @@ http://mozilla.org/MPL/2.0/.
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning( pop )
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
#include "Classes.h"
|
||||
#include "utilities.h"
|
||||
#include "Texture.h"
|
||||
#include <thread>
|
||||
|
||||
#define PyGetFloat(param) PyFloat_FromDouble(param)
|
||||
#define PyGetInt(param) PyInt_FromLong(param)
|
||||
@@ -57,10 +58,11 @@ http://mozilla.org/MPL/2.0/.
|
||||
#define PyGetString(param) PyString_FromString(param)
|
||||
|
||||
// python rendertarget
|
||||
struct python_rt {
|
||||
struct python_rt
|
||||
{
|
||||
std::mutex mutex;
|
||||
|
||||
ITexture* shared_tex;
|
||||
ITexture *shared_tex;
|
||||
|
||||
int format;
|
||||
int components;
|
||||
@@ -72,83 +74,86 @@ struct python_rt {
|
||||
};
|
||||
|
||||
// TODO: extract common base and inherit specialization from it
|
||||
class render_task {
|
||||
class render_task
|
||||
{
|
||||
|
||||
public:
|
||||
// constructors
|
||||
render_task( PyObject *Renderer, std::shared_ptr<dictionary_source> Input, std::shared_ptr<python_rt> Target ) :
|
||||
m_renderer( Renderer ), m_input( Input ), m_target( Target )
|
||||
{}
|
||||
// methods
|
||||
public:
|
||||
// constructors
|
||||
render_task(PyObject *Renderer, std::shared_ptr<dictionary_source> Input, std::shared_ptr<python_rt> Target) : m_renderer(Renderer), m_input(Input), m_target(Target) {}
|
||||
// methods
|
||||
void run();
|
||||
void upload();
|
||||
void cancel();
|
||||
auto target() const -> std::shared_ptr<python_rt> { return m_target; }
|
||||
void cancel();
|
||||
auto target() const -> std::shared_ptr<python_rt>
|
||||
{
|
||||
return m_target;
|
||||
}
|
||||
|
||||
private:
|
||||
// members
|
||||
PyObject *m_renderer {nullptr};
|
||||
std::shared_ptr<dictionary_source> m_input{nullptr};
|
||||
std::shared_ptr<python_rt> m_target { nullptr };
|
||||
private:
|
||||
// members
|
||||
PyObject *m_renderer{nullptr};
|
||||
std::shared_ptr<dictionary_source> m_input{nullptr};
|
||||
std::shared_ptr<python_rt> m_target{nullptr};
|
||||
};
|
||||
|
||||
class python_taskqueue {
|
||||
class python_taskqueue
|
||||
{
|
||||
|
||||
public:
|
||||
// types
|
||||
struct task_request {
|
||||
public:
|
||||
// types
|
||||
struct task_request
|
||||
{
|
||||
|
||||
std::string const &renderer;
|
||||
std::shared_ptr<dictionary_source> input;
|
||||
std::string const &renderer;
|
||||
std::shared_ptr<dictionary_source> input;
|
||||
std::shared_ptr<python_rt> target;
|
||||
};
|
||||
// constructors
|
||||
python_taskqueue() = default;
|
||||
// methods
|
||||
// initializes the module. returns true on success
|
||||
auto init() -> bool;
|
||||
// shuts down the module
|
||||
void exit();
|
||||
// adds specified task along with provided collection of data to the work queue. returns true on success
|
||||
auto insert( task_request const &Task ) -> bool;
|
||||
// executes python script stored in specified file. returns true on success
|
||||
auto run_file( std::string const &File, std::string const &Path = "" ) -> bool;
|
||||
// acquires the python gil and sets the main thread as current
|
||||
void acquire_lock();
|
||||
// releases the python gil and swaps the main thread out
|
||||
void release_lock();
|
||||
};
|
||||
// constructors
|
||||
python_taskqueue() = default;
|
||||
// methods
|
||||
// initializes the module. returns true on success
|
||||
auto init() -> bool;
|
||||
// shuts down the module
|
||||
void exit();
|
||||
// adds specified task along with provided collection of data to the work queue. returns true on success
|
||||
auto insert(task_request const &Task) -> bool;
|
||||
// executes python script stored in specified file. returns true on success
|
||||
auto run_file(std::string const &File, std::string const &Path = "") -> bool;
|
||||
// acquires the python gil and sets the main thread as current
|
||||
void acquire_lock();
|
||||
// releases the python gil and swaps the main thread out
|
||||
void release_lock();
|
||||
|
||||
void update();
|
||||
|
||||
private:
|
||||
// types
|
||||
static int const WORKERCOUNT { 1 };
|
||||
using worker_array = std::array<std::thread, WORKERCOUNT >;
|
||||
using rendertask_sequence = threading::lockable< std::deque<std::shared_ptr<render_task>> >;
|
||||
using uploadtask_sequence = threading::lockable< std::deque<std::shared_ptr<render_task>> >;
|
||||
// methods
|
||||
auto fetch_renderer( std::string const Renderer ) -> PyObject *;
|
||||
void run(GLFWwindow *Context, rendertask_sequence &Tasks, uploadtask_sequence &Upload_Tasks, threading::condition_variable &Condition, std::atomic<bool> &Exit );
|
||||
void error();
|
||||
private:
|
||||
// types
|
||||
static int const WORKERCOUNT{1};
|
||||
using worker_array = std::array<std::jthread, WORKERCOUNT>;
|
||||
using rendertask_sequence = threading::lockable<std::deque<std::shared_ptr<render_task>>>;
|
||||
using uploadtask_sequence = threading::lockable<std::deque<std::shared_ptr<render_task>>>;
|
||||
// methods
|
||||
auto fetch_renderer(std::string const Renderer) -> PyObject *;
|
||||
void run(GLFWwindow *Context, rendertask_sequence &Tasks, uploadtask_sequence &Upload_Tasks, threading::condition_variable &Condition, std::atomic<bool> &Exit);
|
||||
void error();
|
||||
|
||||
// members
|
||||
PyObject *m_main { nullptr };
|
||||
PyObject *m_stderr { nullptr };
|
||||
PyThreadState *m_mainthread{ nullptr };
|
||||
worker_array m_workers;
|
||||
threading::condition_variable m_condition; // wakes up the workers
|
||||
std::atomic<bool> m_exit { false }; // signals the workers to quit
|
||||
std::unordered_map<std::string, PyObject *> m_renderers; // cache of python classes
|
||||
rendertask_sequence m_tasks;
|
||||
PyObject *m_main{nullptr};
|
||||
PyObject *m_stderr{nullptr};
|
||||
PyThreadState *m_mainthread{nullptr};
|
||||
worker_array m_workers;
|
||||
threading::condition_variable m_condition; // wakes up the workers
|
||||
std::atomic<bool> m_exit{false}; // signals the workers to quit
|
||||
std::unordered_map<std::string, PyObject *> m_renderers; // cache of python classes
|
||||
rendertask_sequence m_tasks;
|
||||
uploadtask_sequence m_uploadtasks;
|
||||
bool m_initialized { false };
|
||||
bool m_initialized{false};
|
||||
};
|
||||
|
||||
class python_external_utils
|
||||
{
|
||||
public:
|
||||
static std::vector<std::string> PyObjectToStringArray(PyObject *pyList);
|
||||
|
||||
public:
|
||||
static std::vector<std::string> PyObjectToStringArray(PyObject *pyList);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user