|
| 1 | +#include "UnrealEnginePythonPrivatePCH.h" |
| 2 | + |
| 3 | +static PyObject *py_ue_frandomstream_frand(ue_PyFRandomStream *self, PyObject * args) { |
| 4 | + return PyFloat_FromDouble(self->rstream.FRand()); |
| 5 | +} |
| 6 | + |
| 7 | +static PyObject *py_ue_frandomstream_frand_range(ue_PyFRandomStream *self, PyObject * args) { |
| 8 | + float min; |
| 9 | + float max; |
| 10 | + if (!PyArg_ParseTuple(args, "ff:frand_range", &min, &max)) |
| 11 | + return NULL; |
| 12 | + return PyFloat_FromDouble(self->rstream.FRandRange(min, max)); |
| 13 | +} |
| 14 | + |
| 15 | +static PyObject *py_ue_frandomstream_generate_new_seed(ue_PyFRandomStream *self, PyObject * args) { |
| 16 | + self->rstream.GenerateNewSeed(); |
| 17 | + Py_INCREF(Py_None); |
| 18 | + return Py_None; |
| 19 | +} |
| 20 | + |
| 21 | +static PyObject *py_ue_frandomstream_get_current_seed(ue_PyFRandomStream *self, PyObject * args) { |
| 22 | + return PyLong_FromLong(self->rstream.GetCurrentSeed()); |
| 23 | +} |
| 24 | + |
| 25 | +static PyObject *py_ue_frandomstream_get_fraction(ue_PyFRandomStream *self, PyObject * args) { |
| 26 | + return PyFloat_FromDouble(self->rstream.GetFraction()); |
| 27 | +} |
| 28 | + |
| 29 | +static PyObject *py_ue_frandomstream_get_initial_seed(ue_PyFRandomStream *self, PyObject * args) { |
| 30 | + return PyLong_FromLong(self->rstream.GetInitialSeed()); |
| 31 | +} |
| 32 | + |
| 33 | +static PyObject *py_ue_frandomstream_get_unit_vector(ue_PyFRandomStream *self, PyObject * args) { |
| 34 | + return py_ue_new_fvector(self->rstream.GetUnitVector()); |
| 35 | +} |
| 36 | + |
| 37 | +static PyObject *py_ue_frandomstream_get_unsigned_int(ue_PyFRandomStream *self, PyObject * args) { |
| 38 | + return PyLong_FromUnsignedLong(self->rstream.GetUnsignedInt()); |
| 39 | +} |
| 40 | + |
| 41 | +static PyObject *py_ue_frandomstream_initialize(ue_PyFRandomStream *self, PyObject * args) { |
| 42 | + int seed; |
| 43 | + if (!PyArg_ParseTuple(args, "i:initialize", &seed)) |
| 44 | + return NULL; |
| 45 | + self->rstream.Initialize(seed); |
| 46 | + Py_INCREF(Py_None); |
| 47 | + return Py_None; |
| 48 | +} |
| 49 | + |
| 50 | +static PyObject *py_ue_frandomstream_rand_helper(ue_PyFRandomStream *self, PyObject * args) { |
| 51 | + int max; |
| 52 | + if (!PyArg_ParseTuple(args, "i:rand_helper", &max)) |
| 53 | + return NULL; |
| 54 | + return PyLong_FromLong(self->rstream.RandHelper(max)); |
| 55 | +} |
| 56 | + |
| 57 | +static PyObject *py_ue_frandomstream_rand_range(ue_PyFRandomStream *self, PyObject * args) { |
| 58 | + int min; |
| 59 | + int max; |
| 60 | + if (!PyArg_ParseTuple(args, "ii:rand_range", &min, &max)) |
| 61 | + return NULL; |
| 62 | + return PyLong_FromLong(self->rstream.RandRange(min, max)); |
| 63 | +} |
| 64 | + |
| 65 | +static PyObject *py_ue_frandomstream_reset(ue_PyFRandomStream *self, PyObject * args) { |
| 66 | + self->rstream.Reset(); |
| 67 | + Py_INCREF(Py_None); |
| 68 | + return Py_None; |
| 69 | +} |
| 70 | + |
| 71 | +static PyObject *py_ue_frandomstream_vrand(ue_PyFRandomStream *self, PyObject * args) { |
| 72 | + return py_ue_new_fvector(self->rstream.VRand()); |
| 73 | +} |
| 74 | + |
| 75 | +static PyObject *py_ue_frandomstream_vrand_cone(ue_PyFRandomStream *self, PyObject * args) { |
| 76 | + PyObject *py_obj; |
| 77 | + float horizontal = 0; |
| 78 | + float vertical = -1; |
| 79 | + if (!PyArg_ParseTuple(args, "Of|f:vrand_cone", &py_obj, &horizontal, &vertical)) |
| 80 | + return NULL; |
| 81 | + ue_PyFVector *py_vec = py_ue_is_fvector(py_obj); |
| 82 | + if (!py_vec) |
| 83 | + return PyErr_Format(PyExc_TypeError, "argument is not a FVector"); |
| 84 | + if (vertical < 0) |
| 85 | + vertical = horizontal; |
| 86 | + return py_ue_new_fvector(self->rstream.VRandCone(py_vec->vec, horizontal, vertical)); |
| 87 | +} |
| 88 | + |
| 89 | + |
| 90 | +static PyMethodDef ue_PyFRandomStream_methods[] = { |
| 91 | + |
| 92 | + { "frand", (PyCFunction)py_ue_frandomstream_frand, METH_VARARGS, "" }, |
| 93 | + { "frand_range", (PyCFunction)py_ue_frandomstream_frand_range, METH_VARARGS, "" }, |
| 94 | + { "generate_new_seed", (PyCFunction)py_ue_frandomstream_generate_new_seed, METH_VARARGS, "" }, |
| 95 | + { "get_current_seed", (PyCFunction)py_ue_frandomstream_get_current_seed, METH_VARARGS, "" }, |
| 96 | + { "get_fraction", (PyCFunction)py_ue_frandomstream_get_fraction, METH_VARARGS, "" }, |
| 97 | + { "get_initial_seed", (PyCFunction)py_ue_frandomstream_get_initial_seed, METH_VARARGS, "" }, |
| 98 | + { "get_unit_vector", (PyCFunction)py_ue_frandomstream_get_unit_vector, METH_VARARGS, "" }, |
| 99 | + { "get_unsigned_int", (PyCFunction)py_ue_frandomstream_get_unsigned_int, METH_VARARGS, "" }, |
| 100 | + { "initialize", (PyCFunction)py_ue_frandomstream_initialize, METH_VARARGS, "" }, |
| 101 | + { "rand_helper", (PyCFunction)py_ue_frandomstream_rand_helper, METH_VARARGS, "" }, |
| 102 | + { "rand_range", (PyCFunction)py_ue_frandomstream_rand_range, METH_VARARGS, "" }, |
| 103 | + { "reset", (PyCFunction)py_ue_frandomstream_reset, METH_VARARGS, "" }, |
| 104 | + { "vrand", (PyCFunction)py_ue_frandomstream_vrand, METH_VARARGS, "" }, |
| 105 | + { "vrand_cone", (PyCFunction)py_ue_frandomstream_vrand_cone, METH_VARARGS, "" }, |
| 106 | + { NULL } /* Sentinel */ |
| 107 | +}; |
| 108 | + |
| 109 | + |
| 110 | + |
| 111 | +static PyObject *ue_PyFRandomStream_str(ue_PyFRandomStream *self) |
| 112 | +{ |
| 113 | + return PyUnicode_FromFormat("<unreal_engine.FRandomStream {'seed': %d}>", |
| 114 | + self->rstream.GetCurrentSeed()); |
| 115 | +} |
| 116 | + |
| 117 | +static PyTypeObject ue_PyFRandomStreamType = { |
| 118 | + PyVarObject_HEAD_INIT(NULL, 0) |
| 119 | + "unreal_engine.FRandomStream", /* tp_name */ |
| 120 | + sizeof(ue_PyFRandomStream), /* tp_basicsize */ |
| 121 | + 0, /* tp_itemsize */ |
| 122 | + 0, /* tp_dealloc */ |
| 123 | + 0, /* tp_print */ |
| 124 | + 0, /* tp_getattr */ |
| 125 | + 0, /* tp_setattr */ |
| 126 | + 0, /* tp_reserved */ |
| 127 | + 0, /* tp_repr */ |
| 128 | + 0, /* tp_as_number */ |
| 129 | + 0, /* tp_as_sequence */ |
| 130 | + 0, /* tp_as_mapping */ |
| 131 | + 0, /* tp_hash */ |
| 132 | + 0, /* tp_call */ |
| 133 | + (reprfunc)ue_PyFRandomStream_str, /* tp_str */ |
| 134 | + 0, /* tp_getattro */ |
| 135 | + 0, /* tp_setattro */ |
| 136 | + 0, /* tp_as_buffer */ |
| 137 | + Py_TPFLAGS_DEFAULT, /* tp_flags */ |
| 138 | + "Unreal Engine FRandomStream", /* tp_doc */ |
| 139 | + 0, /* tp_traverse */ |
| 140 | + 0, /* tp_clear */ |
| 141 | + 0, /* tp_richcompare */ |
| 142 | + 0, /* tp_weaklistoffset */ |
| 143 | + 0, /* tp_iter */ |
| 144 | + 0, /* tp_iternext */ |
| 145 | + ue_PyFRandomStream_methods, /* tp_methods */ |
| 146 | + 0, |
| 147 | + 0, |
| 148 | +}; |
| 149 | + |
| 150 | +static int ue_py_frandomstream_init(ue_PyFRandomStream *self, PyObject *args, PyObject *kwargs) { |
| 151 | + self->rstream.GenerateNewSeed(); |
| 152 | + return 0; |
| 153 | +} |
| 154 | + |
| 155 | +void ue_python_init_frandomstream(PyObject *ue_module) { |
| 156 | + ue_PyFRandomStreamType.tp_new = PyType_GenericNew; |
| 157 | + |
| 158 | + ue_PyFRandomStreamType.tp_init = (initproc)ue_py_frandomstream_init; |
| 159 | + |
| 160 | + if (PyType_Ready(&ue_PyFRandomStreamType) < 0) |
| 161 | + return; |
| 162 | + |
| 163 | + Py_INCREF(&ue_PyFRandomStreamType); |
| 164 | + PyModule_AddObject(ue_module, "FRandomStream", (PyObject *)&ue_PyFRandomStreamType); |
| 165 | +} |
| 166 | + |
| 167 | + |
0 commit comments