|
| 1 | +// this file automaticly generated from UniginePlayer.h |
| 2 | +#include "python3_unigine_player.h" |
| 3 | + |
| 4 | +#include <string> |
| 5 | +#include <UniginePlayers.h> |
| 6 | +#include <UnigineLog.h> |
| 7 | +#include <Python.h> |
| 8 | +#include <structmember.h> |
| 9 | + |
| 10 | +#include <iostream> |
| 11 | + |
| 12 | +#include "python3_unigine_vec3.h" |
| 13 | + |
| 14 | +namespace PyUnigine { |
| 15 | + |
| 16 | +// ------------------------------------------------------------------------------------------ |
| 17 | +// unigine_Player |
| 18 | + |
| 19 | +typedef struct { |
| 20 | + PyObject_HEAD |
| 21 | + // Type-specific fields go here. |
| 22 | + Unigine::Ptr<Unigine::Player> unigine_object_ptr; |
| 23 | +} unigine_Player; |
| 24 | + |
| 25 | +static void unigine_Player_dealloc(unigine_Player* self) { |
| 26 | + // Unigine::Log::message("unigine_Player_dealloc\n"); |
| 27 | + Py_TYPE(self)->tp_free((PyObject*)self); |
| 28 | +} |
| 29 | + |
| 30 | +static PyObject *unigine_Player_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { |
| 31 | + // Unigine::Log::message("unigine_Player_new\n"); |
| 32 | + unigine_Player *self; |
| 33 | + self = (unigine_Player *)type->tp_alloc(type, 0); |
| 34 | + self->unigine_object_ptr = nullptr; |
| 35 | + return (PyObject *)self; |
| 36 | +} |
| 37 | + |
| 38 | +static int unigine_Player_init(unigine_Player *self, PyObject *args, PyObject *kwds) { |
| 39 | + return 0; |
| 40 | +} |
| 41 | + |
| 42 | +// public (inherit from Node): getWorldPosition |
| 43 | +static PyObject * unigine_Player_get_world_position(unigine_Player* self) { |
| 44 | + PyErr_Clear(); |
| 45 | + PyObject *ret = NULL; |
| 46 | + // parse args: |
| 47 | + |
| 48 | + class LocalRunner : public Python3Runner { |
| 49 | + public: |
| 50 | + virtual void run() override { |
| 51 | + retOriginal = unigine_object_ptr->getWorldPosition(); |
| 52 | + }; |
| 53 | + Unigine::Ptr<Unigine::Player> unigine_object_ptr; |
| 54 | + // return |
| 55 | + Unigine::Math::Vec3 retOriginal; |
| 56 | + }; |
| 57 | + auto *pRunner = new LocalRunner(); |
| 58 | + pRunner->unigine_object_ptr = self->unigine_object_ptr; |
| 59 | + Python3Runner::runInMainThread(pRunner); |
| 60 | + while (!pRunner->mutexAsync.tryLock(5)) { // milliseconds |
| 61 | + } |
| 62 | + pRunner->mutexAsync.unlock(); |
| 63 | + Unigine::Math::Vec3 retOriginal = pRunner->retOriginal; |
| 64 | + delete pRunner; |
| 65 | + Unigine::Math::vec3 *retOriginal2 = new Unigine::Math::vec3(retOriginal); |
| 66 | + ret = PyUnigine::vec3::NewObject(retOriginal2); |
| 67 | + |
| 68 | + // end |
| 69 | + // return: Unigine::Math::Vec3 |
| 70 | + return ret; |
| 71 | +}; |
| 72 | + |
| 73 | +static PyMethodDef unigine_Player_methods[] = { |
| 74 | + { |
| 75 | + "get_world_position", (PyCFunction)unigine_Player_get_world_position, METH_NOARGS, |
| 76 | + "public : getWorldPosition" |
| 77 | + }, |
| 78 | + {NULL} /* Sentinel */ |
| 79 | +}; |
| 80 | + |
| 81 | +static PyTypeObject unigine_PlayerType = { |
| 82 | + PyVarObject_HEAD_INIT(NULL, 0) |
| 83 | + "unigine.Player", // tp_name |
| 84 | + sizeof(unigine_Player) + 256, // tp_basicsize (TODO magic 256 bytes!!!) |
| 85 | + 0, // tp_itemsize |
| 86 | + (destructor)unigine_Player_dealloc, // tp_dealloc |
| 87 | + 0, // tp_vectorcall_offset |
| 88 | + 0, // tp_getattr |
| 89 | + 0, // tp_setattr |
| 90 | + 0, // tp_as_async |
| 91 | + 0, // tp_repr |
| 92 | + 0, // tp_as_number |
| 93 | + 0, // tp_as_sequence |
| 94 | + 0, // tp_as_mapping |
| 95 | + 0, // tp_hash |
| 96 | + 0, // tp_call |
| 97 | + 0, // tp_str |
| 98 | + 0, // tp_getattro |
| 99 | + 0, // tp_setattro |
| 100 | + 0, // tp_as_buffer |
| 101 | + Py_TPFLAGS_DEFAULT, // tp_flags |
| 102 | + "Player Object", // tp_doc |
| 103 | + 0, // traverseproc tp_traverse |
| 104 | + 0, // inquiry tp_clear |
| 105 | + 0, // richcmpfunc tp_richcompare |
| 106 | + 0, // Py_ssize_t tp_weaklistoffset |
| 107 | + 0, // getiterfunc tp_iter |
| 108 | + 0, // iternextfunc tp_iternext |
| 109 | + unigine_Player_methods, // tp_methods |
| 110 | + 0, // tp_members |
| 111 | + 0, // tp_getset |
| 112 | + 0, // tp_base |
| 113 | + 0, // tp_dict |
| 114 | + 0, // tp_descr_get |
| 115 | + 0, // tp_descr_set |
| 116 | + 0, // tp_dictoffset |
| 117 | + (initproc)unigine_Player_init, // tp_init |
| 118 | + 0, // tp_alloc |
| 119 | + unigine_Player_new, // tp_new |
| 120 | +}; |
| 121 | + |
| 122 | + |
| 123 | +// UniginePyTypeObjectPlayer |
| 124 | + |
| 125 | +bool Python3UniginePlayer::isReady() { |
| 126 | + // Initialize tp_dict with empty dictionary |
| 127 | + if (!unigine_PlayerType.tp_dict) { |
| 128 | + unigine_PlayerType.tp_dict = PyDict_New(); |
| 129 | + |
| 130 | + } |
| 131 | + if (PyType_Ready(&unigine_PlayerType) < 0) { |
| 132 | + return false; |
| 133 | + } |
| 134 | + return true; |
| 135 | +} |
| 136 | + |
| 137 | +bool Python3UniginePlayer::addClassDefinitionToModule(PyObject* pModule) { |
| 138 | + Py_INCREF(&unigine_PlayerType); |
| 139 | + if (PyModule_AddObject(pModule, "Player", (PyObject *)&unigine_PlayerType) < 0) { |
| 140 | + Py_DECREF(&unigine_PlayerType); |
| 141 | + return false; |
| 142 | + } |
| 143 | + return true; |
| 144 | +} |
| 145 | + |
| 146 | +PyObject * Player::NewObject(Unigine::Ptr<Unigine::Player> unigine_object_ptr) { |
| 147 | + // std::cout << "sizeof(unigine_Player) = " << sizeof(unigine_Player) << std::endl; |
| 148 | + unigine_Player *pInst = PyObject_New(unigine_Player, &unigine_PlayerType); |
| 149 | + pInst->unigine_object_ptr = unigine_object_ptr; |
| 150 | + // Py_INCREF(pInst); |
| 151 | + return (PyObject *)pInst; |
| 152 | +} |
| 153 | + |
| 154 | +Unigine::Ptr<Unigine::Player> Player::Convert(PyObject *pObject) { |
| 155 | + if (Py_IS_TYPE(pObject, &unigine_PlayerType) == 0) { |
| 156 | + Unigine::Log::error("Invalid type, expected 'Unigine::Ptr<Unigine::Player>', but got some another"); |
| 157 | + } |
| 158 | + unigine_Player *pInst = (unigine_Player *)pObject; |
| 159 | + return pInst->unigine_object_ptr; |
| 160 | +} |
| 161 | + |
| 162 | +}; // namespace PyUnigine |
0 commit comments