Added templates for the new variant types.

This commit is contained in:
Relintai 2023-06-02 12:08:05 +02:00
parent e0c74244ea
commit 5eeae5e6ba
9 changed files with 552 additions and 6 deletions

View File

@ -0,0 +1,36 @@
{%- block pxd_header %}
{% endblock -%}
{%- block pyx_header %}
{% endblock -%}
@cython.final
cdef class Projection:
{% block cdef_attributes %}
cdef pandemonium_projection _gd_data
{% endblock %}
{% block python_defs %}
def __init__(self, x_axis=None, y_axis=None, z_axis=None, w_axis=None):
if x_axis is None and y_axis is None and z_axis is None and w_axis is None:
{{ force_mark_rendered("pandemonium_projection_new_identity") }}
gdapi10.pandemonium_projection_new_identity(&self._gd_data)
else:
{{ force_mark_rendered("pandemonium_projection_new_vector4s") }}
gdapi10.pandemonium_projection_new_vector4s(
&self._gd_data,
&(<Vector4?>x_axis)._gd_data,
&(<Vector4?>y_axis)._gd_data,
&(<Vector4?>z_axis)._gd_data,
&(<Vector4?>origin)._gd_data,
)
def __repr__(Projection self):
return f"<Projection({self.as_string()})>"
{{ render_method("as_string") | indent }}
{% endblock %}
{%- block python_consts %}
IDENTITY = Projection(Vector4(1, 0, 0, 0), Vector4(0, 1, 0, 0), Vector4(0, 0, 1, 0), Vector4(0, 0, 0, 1))
{% endblock %}

View File

@ -0,0 +1,46 @@
{%- block pxd_header %}
{% endblock -%}
{%- block pyx_header %}
{% endblock -%}
@cython.final
cdef class Rect2i:
{% block cdef_attributes %}
cdef pandemonium_rect2i _gd_data
{% endblock %}
{% block python_defs %}
def __init__(self, pandemonium_real x=0.0, pandemonium_real y=0.0, pandemonium_real width=0.0, pandemonium_real height=0.0):
{{ force_mark_rendered("pandemonium_rect2i_new") }}
gdapi10.pandemonium_rect2i_new(&self._gd_data, x, y, width, height)
@staticmethod
def from_pos_size(Vector2 position not None, Vector2 size not None):
{{ force_mark_rendered("pandemonium_rect2i_new_with_position_and_size") }}
cdef Rect2i ret = Rect2i.__new__(Rect2i)
gdapi10.pandemonium_rect2i_new_with_position_and_size(&ret._gd_data, &position._gd_data, &size._gd_data)
return ret
def __repr__(Rect2i self):
return f"<Rect2i({self.as_string()})>"
{{ render_operator_eq() | indent }}
{{ render_operator_ne() | indent }}
{{ render_property("size", getter="get_size", setter="set_size") | indent }}
{{ render_property("position", getter="get_position", setter="set_position") | indent }}
@property
def end(Rect2i self) -> Vector2:
cdef pandemonium_vector2i position = gdapi10.pandemonium_rect2i_get_position(&self._gd_data)
cdef pandemonium_vector2i size = gdapi10.pandemonium_rect2i_get_size(&self._gd_data)
cdef Vector2 ret = Vector2.__new__(Vector2)
ret._gd_data = gdapi10.pandemonium_vector2i_operator_add(&position, &size)
return ret
{{ render_method("as_string") | indent }}
{% endblock %}
{%- block python_consts %}
{% endblock %}

View File

@ -0,0 +1,45 @@
{%- block pxd_header %}
{% endblock -%}
{%- block pyx_header %}
{% endblock -%}
@cython.final
cdef class StringName:
{% block cdef_attributes %}
cdef pandemonium_string_name _gd_data
{% endblock %}
{% block python_defs %}
def __init__(self, from_):
{{ force_mark_rendered("pandemonium_string_name_new") }}
cdef pandemonium_string gd_from
try:
gdapi10.pandemonium_string_name_new(&self._gd_data, &(<GDString?>from_)._gd_data)
except TypeError:
if not isinstance(from_, str):
raise TypeError("`from_` must be str or GDString")
pyobj_to_pandemonium_string(from_, &gd_from)
gdapi10.pandemonium_string_name_new(&self._gd_data, &gd_from)
gdapi10.pandemonium_string_destroy(&gd_from)
def __dealloc__(StringName self):
{{ force_mark_rendered("pandemonium_string_name_destroy") }}
# /!\ if `__init__` is skipped, `_gd_data` must be initialized by
# hand otherwise we will get a segfault here
gdapi10.pandemonium_string_name_destroy(&self._gd_data)
def __repr__(StringName self):
return f"<StringName({self.as_string()})>"
def __str__(StringName self):
return str(self.as_string())
{{ render_operator_eq() | indent }}
{{ render_operator_ne() | indent }}
{{ render_method("destroy") | indent }}
{{ render_method("as_string") | indent }}
{% endblock %}
{%- block python_consts %}
{% endblock %}

View File

@ -1,6 +1,7 @@
{%- block pxd_header %}
{% endblock -%}
{%- block pyx_header %}
from pandemonium._hazmat.gdnative_api_struct cimport pandemonium_vector2_axis
import math
cdef inline Vector2 Vector2_multiply_vector(Vector2 self, Vector2 b):
@ -110,8 +111,10 @@ cdef class Vector2:
{% endblock %}
{%- block python_consts %}
AXIS_X = 0
AXIS_Y = 0
AXIS = IntEnum("AXIS", {
"X": pandemonium_vector2_axis.PANDEMONIUM_VECTOR2_AXIS_X,
"Y": pandemonium_vector2_axis.PANDEMONIUM_VECTOR2_AXIS_Y,
})
ZERO = Vector2(0, 0)
ONE = Vector2(1, 1)

View File

@ -0,0 +1,77 @@
{%- block pxd_header %}
{% endblock -%}
{%- block pyx_header %}
from pandemonium._hazmat.gdnative_api_struct cimport pandemonium_vector2i_axis
{% endblock -%}
@cython.final
cdef class Vector2i:
{% block cdef_attributes %}
cdef pandemonium_vector2i _gd_data
{% endblock %}
{% block python_defs %}
def __init__(self, pandemonium_int x=0, pandemonium_int y=0):
{{ force_mark_rendered("pandemonium_vector2i_new") }}
gdapi10.pandemonium_vector2i_new(&self._gd_data, x, y)
def __repr__(Vector2i self):
return f"<Vector2i(x={self.x}, y={self.y})>"
{{ render_operator_eq() | indent }}
{{ render_operator_ne() | indent }}
{{ render_operator_lt() | indent }}
{{ render_method("operator_neg", py_name="__neg__") | indent }}
def __pos__(Vector2i self):
return self
{{ render_method("operator_add", py_name="__add__") | indent }}
{{ render_method("operator_subtract", py_name="__sub__") | indent }}
def __mul__(Vector2i self, val):
cdef Vector2i _val
try:
_val = <Vector2i?>val
except TypeError:
return Vector2i_multiply_scalar(self, val)
else:
return Vector2i_multiply_vector(self, _val)
def __truediv__(Vector2i self, val):
cdef Vector2i _val
try:
_val = <Vector2i?>val
except TypeError:
if val is 0:
raise ZeroDivisionError()
return Vector2i_divide_scalar(self, val)
else:
if _val.x == 0 or _val.y == 0:
raise ZeroDivisionError()
return Vector2i_divide_vector(self, _val)
{{ render_property("x", "get_x", "set_x") | indent }}
{{ render_property("y", "get_y", "set_y") | indent }}
{{ render_property("width", "get_x", "set_x") | indent }}
{{ render_property("height", "get_y", "set_y") | indent }}
{{ render_method("as_string") | indent }}
{% endblock %}
{%- block python_consts %}
AXIS = IntEnum("AXIS", {
"X": pandemonium_vector2i_axis.PANDEMONIUM_VECTOR2I_AXIS_X,
"Y": pandemonium_vector2i_axis.PANDEMONIUM_VECTOR2I_AXIS_Y,
})
ZERO = Vector2i(0, 0)
ONE = Vector2i(1, 1)
INF = Vector2i(math.inf, math.inf)
LEFT = Vector2i(-1, 0)
RIGHT = Vector2i(1, 0)
UP = Vector2i(0, -1)
DOWN = Vector2i(0, 1)
{% endblock %}

View File

@ -0,0 +1,105 @@
{%- block pxd_header %}
{% endblock -%}
{%- block pyx_header %}
from pandemonium._hazmat.gdnative_api_struct cimport pandemonium_vector3i_axis
{% endblock -%}
@cython.final
cdef class Vector3i:
{% block cdef_attributes %}
cdef pandemonium_vector3i _gd_data
{% endblock %}
{% block python_defs %}
def __init__(self, pandemonium_int x=0, pandemonium_int y=0, pandemonium_int z=0):
{{ force_mark_rendered("pandemonium_vector3i_new") }}
gdapi10.pandemonium_vector3i_new(&self._gd_data, x, y, z)
def __repr__(self):
return f"<Vector3i(x={self.x}, y={self.y}, z={self.z})>"
@property
def x(self) -> pandemonium_int:
{{ force_mark_rendered("pandemonium_vector3i_get_axis") }}
return gdapi10.pandemonium_vector3i_get_axis(&self._gd_data, pandemonium_vector3i_axis.PANDEMONIUM_VECTOR3I_AXIS_X)
@x.setter
def x(self, pandemonium_int val) -> None:
{{ force_mark_rendered("pandemonium_vector3i_set_axis") }}
gdapi10.pandemonium_vector3i_set_axis(&self._gd_data, pandemonium_vector3i_axis.PANDEMONIUM_VECTOR3I_AXIS_X, val)
@property
def y(self) -> pandemonium_int:
{{ force_mark_rendered("pandemonium_vector3i_get_axis") }}
return gdapi10.pandemonium_vector3i_get_axis(&self._gd_data, pandemonium_vector3i_axis.PANDEMONIUM_VECTOR3I_AXIS_Y)
@y.setter
def y(self, pandemonium_int val) -> None:
{{ force_mark_rendered("pandemonium_vector3i_set_axis") }}
gdapi10.pandemonium_vector3i_set_axis(&self._gd_data, pandemonium_vector3i_axis.PANDEMONIUM_VECTOR3I_AXIS_Y, val)
@property
def z(self) -> pandemonium_int:
{{ force_mark_rendered("pandemonium_vector3i_get_axis") }}
return gdapi10.pandemonium_vector3i_get_axis(&self._gd_data, pandemonium_vector3i_axis.PANDEMONIUM_VECTOR3I_AXIS_Z)
@z.setter
def z(self, pandemonium_int val) -> None:
{{ force_mark_rendered("pandemonium_vector3i_set_axis") }}
gdapi10.pandemonium_vector3i_set_axis(&self._gd_data, pandemonium_vector3i_axis.PANDEMONIUM_VECTOR3I_AXIS_Z, val)
{{ render_operator_eq() | indent }}
{{ render_operator_ne() | indent }}
{{ render_operator_lt() | indent }}
{{ render_method("operator_neg", py_name="__neg__") | indent }}
def __pos__(Vector3i self):
return self
{{ render_method("operator_add", py_name="__add__") | indent }}
{{ render_method("operator_subtract", py_name="__sub__") | indent }}
def __mul__(Vector3i self, val):
cdef Vector3i _val
try:
_val = <Vector3i?>val
except TypeError:
return Vector3i_multiply_scalar(self, val)
else:
return Vector3i_multiply_vector(self, _val)
def __truediv__(Vector3i self, val):
cdef Vector3i _val
try:
_val = <Vector3i?>val
except TypeError:
if val is 0:
raise ZeroDivisionError()
return Vector3i_divide_scalar(self, val)
else:
if _val.x == 0 or _val.y == 0 or _val.z == 0:
raise ZeroDivisionError()
return Vector3i_divide_vector(self, _val)
{{ render_method("as_string") | indent }}
{% endblock %}
{%- block python_consts %}
AXIS = IntEnum("AXIS", {
"X": pandemonium_vector3i_axis.PANDEMONIUM_VECTOR3I_AXIS_X,
"Y": pandemonium_vector3i_axis.PANDEMONIUM_VECTOR3I_AXIS_Y,
"Z": pandemonium_vector3i_axis.PANDEMONIUM_VECTOR3I_AXIS_Z,
})
ZERO = Vector3i(0, 0, 0) # Zero vector.
ONE = Vector3i(1, 1, 1) # One vector.
INF = Vector3i(math.inf, math.inf, math.inf) # Infinite vector.
LEFT = Vector3i(-1, 0, 0) # Left unit vector.
RIGHT = Vector3i(1, 0, 0) # Right unit vector.
UP = Vector3i(0, 1, 0) # Up unit vector.
DOWN = Vector3i(0, -1, 0) # Down unit vector.
FORWARD = Vector3i(0, 0, -1) # Forward unit vector.
BACK = Vector3i(0, 0, 1) # Back unit vector.
{% endblock %}

View File

@ -0,0 +1,125 @@
{%- block pxd_header %}
{% endblock -%}
{%- block pyx_header %}
from pandemonium._hazmat.gdnative_api_struct cimport pandemonium_vector4_axis
import math
from enum import IntEnum
cdef inline Vector4_multiply_vector(Vector4 self, Vector4 b):
cdef Vector4 ret = Vector4.__new__(Vector4)
{{ force_mark_rendered("pandemonium_vector4_operator_multiply_vector") }}
ret._gd_data = gdapi10.pandemonium_vector4_operator_multiply_vector(&self._gd_data, &b._gd_data)
return ret
cdef inline Vector4_multiply_scalar(Vector4 self, pandemonium_real b):
cdef Vector4 ret = Vector4.__new__(Vector4)
{{ force_mark_rendered("pandemonium_vector4_operator_multiply_scalar") }}
ret._gd_data = gdapi10.pandemonium_vector4_operator_multiply_scalar(&self._gd_data, b)
return ret
cdef inline Vector4_divide_vector(Vector4 self, Vector4 b):
cdef Vector4 ret = Vector4.__new__(Vector4)
{{ force_mark_rendered("pandemonium_vector4_operator_divide_vector") }}
ret._gd_data = gdapi10.pandemonium_vector4_operator_divide_vector(&self._gd_data, &b._gd_data)
return ret
cdef inline Vector4_divide_scalar(Vector4 self, pandemonium_real b):
cdef Vector4 ret = Vector4.__new__(Vector4)
{{ force_mark_rendered("pandemonium_vector4_operator_divide_scalar") }}
ret._gd_data = gdapi10.pandemonium_vector4_operator_divide_scalar(&self._gd_data, b)
return ret
{% endblock -%}
@cython.final
cdef class Vector4:
{% block cdef_attributes %}
cdef pandemonium_vector4 _gd_data
{% endblock %}
{% block python_defs %}
def __init__(self, pandemonium_real x=0.0, pandemonium_real y=0.0, pandemonium_real z=0.0, pandemonium_real w=0.0):
{{ force_mark_rendered("pandemonium_vector4_new") }}
gdapi10.pandemonium_vector4_new(&self._gd_data, x, y, z, w)
def __repr__(self):
return f"<Vector4(x={self.x}, y={self.y}, z={self.z})>"
@property
def x(self) -> pandemonium_real:
{{ force_mark_rendered("pandemonium_vector4_get_axis") }}
return gdapi10.pandemonium_vector4_get_axis(&self._gd_data, pandemonium_vector4_axis.PANDEMONIUM_VECTOR4_AXIS_X)
@x.setter
def x(self, pandemonium_real val) -> None:
{{ force_mark_rendered("pandemonium_vector4_set_axis") }}
gdapi10.pandemonium_vector4_set_axis(&self._gd_data, pandemonium_vector4_axis.PANDEMONIUM_VECTOR4_AXIS_X, val)
@property
def y(self) -> pandemonium_real:
{{ force_mark_rendered("pandemonium_vector4_get_axis") }}
return gdapi10.pandemonium_vector4_get_axis(&self._gd_data, pandemonium_vector4_axis.PANDEMONIUM_VECTOR4_AXIS_Y)
@y.setter
def y(self, pandemonium_real val) -> None:
{{ force_mark_rendered("pandemonium_vector4_set_axis") }}
gdapi10.pandemonium_vector4_set_axis(&self._gd_data, pandemonium_vector4_axis.PANDEMONIUM_VECTOR4_AXIS_Y, val)
@property
def z(self) -> pandemonium_real:
{{ force_mark_rendered("pandemonium_vector4_get_axis") }}
return gdapi10.pandemonium_vector4_get_axis(&self._gd_data, pandemonium_vector4_axis.PANDEMONIUM_VECTOR4_AXIS_Z)
@z.setter
def z(self, pandemonium_real val) -> None:
{{ force_mark_rendered("pandemonium_vector4_set_axis") }}
gdapi10.pandemonium_vector4_set_axis(&self._gd_data, pandemonium_vector4_axis.PANDEMONIUM_VECTOR4_AXIS_Z, val)
{{ render_operator_eq() | indent }}
{{ render_operator_ne() | indent }}
{{ render_operator_lt() | indent }}
{{ render_method("operator_neg", py_name="__neg__") | indent }}
def __pos__(Vector4 self):
return self
{{ render_method("operator_add", py_name="__add__") | indent }}
{{ render_method("operator_subtract", py_name="__sub__") | indent }}
def __mul__(Vector4 self, val):
cdef Vector4 _val
try:
_val = <Vector4?>val
except TypeError:
return Vector4_multiply_scalar(self, val)
else:
return Vector4_multiply_vector(self, _val)
def __truediv__(Vector4 self, val):
cdef Vector4 _val
try:
_val = <Vector4?>val
except TypeError:
if val is 0:
raise ZeroDivisionError()
return Vector4_divide_scalar(self, val)
else:
if _val.x == 0 or _val.y == 0 or _val.z == 0:
raise ZeroDivisionError()
return Vector4_divide_vector(self, _val)
{{ render_method("as_string") | indent }}
{% endblock %}
{%- block python_consts %}
AXIS = IntEnum("AXIS", {
"X": pandemonium_vector4_axis.PANDEMONIUM_VECTOR4_AXIS_X,
"Y": pandemonium_vector4_axis.PANDEMONIUM_VECTOR4_AXIS_Y,
"Z": pandemonium_vector4_axis.PANDEMONIUM_VECTOR4_AXIS_Z,
"W": pandemonium_vector4_axis.PANDEMONIUM_VECTOR4_AXIS_W,
})
{% endblock %}

View File

@ -0,0 +1,96 @@
{%- block pxd_header %}
{% endblock -%}
{%- block pyx_header %}
from pandemonium._hazmat.gdnative_api_struct cimport pandemonium_vector4i_axis
{% endblock -%}
@cython.final
cdef class Vector4i:
{% block cdef_attributes %}
cdef pandemonium_vector4i _gd_data
{% endblock %}
{% block python_defs %}
def __init__(self, pandemonium_int x=0, pandemonium_int y=0, pandemonium_int z=0, pandemonium_int w=0):
{{ force_mark_rendered("pandemonium_vector4i_new") }}
gdapi10.pandemonium_vector4i_new(&self._gd_data, x, y, z, w)
def __repr__(self):
return f"<Vector4i(x={self.x}, y={self.y}, z={self.z})>"
@property
def x(self) -> pandemonium_int:
{{ force_mark_rendered("pandemonium_vector4i_get_axis") }}
return gdapi10.pandemonium_vector4i_get_axis(&self._gd_data, pandemonium_vector4i_axis.PANDEMONIUM_VECTOR4I_AXIS_X)
@x.setter
def x(self, pandemonium_int val) -> None:
{{ force_mark_rendered("pandemonium_vector4i_set_axis") }}
gdapi10.pandemonium_vector4i_set_axis(&self._gd_data, pandemonium_vector4i_axis.PANDEMONIUM_VECTOR4I_AXIS_X, val)
@property
def y(self) -> pandemonium_int:
{{ force_mark_rendered("pandemonium_vector4i_get_axis") }}
return gdapi10.pandemonium_vector4i_get_axis(&self._gd_data, pandemonium_vector4i_axis.PANDEMONIUM_VECTOR4I_AXIS_Y)
@y.setter
def y(self, pandemonium_int val) -> None:
{{ force_mark_rendered("pandemonium_vector4i_set_axis") }}
gdapi10.pandemonium_vector4i_set_axis(&self._gd_data, pandemonium_vector4i_axis.PANDEMONIUM_VECTOR4I_AXIS_Y, val)
@property
def z(self) -> pandemonium_int:
{{ force_mark_rendered("pandemonium_vector4i_get_axis") }}
return gdapi10.pandemonium_vector4i_get_axis(&self._gd_data, pandemonium_vector4i_axis.PANDEMONIUM_VECTOR4I_AXIS_Z)
@z.setter
def z(self, pandemonium_int val) -> None:
{{ force_mark_rendered("pandemonium_vector4i_set_axis") }}
gdapi10.pandemonium_vector4i_set_axis(&self._gd_data, pandemonium_vector4i_axis.PANDEMONIUM_VECTOR4I_AXIS_Z, val)
{{ render_operator_eq() | indent }}
{{ render_operator_ne() | indent }}
{{ render_operator_lt() | indent }}
{{ render_method("operator_neg", py_name="__neg__") | indent }}
def __pos__(Vector4i self):
return self
{{ render_method("operator_add", py_name="__add__") | indent }}
{{ render_method("operator_subtract", py_name="__sub__") | indent }}
def __mul__(Vector4i self, val):
cdef Vector4i _val
try:
_val = <Vector4i?>val
except TypeError:
return Vector4i_multiply_scalar(self, val)
else:
return Vector4i_multiply_vector(self, _val)
def __truediv__(Vector4i self, val):
cdef Vector4i _val
try:
_val = <Vector4i?>val
except TypeError:
if val is 0:
raise ZeroDivisionError()
return Vector4i_divide_scalar(self, val)
else:
if _val.x == 0 or _val.y == 0 or _val.z == 0:
raise ZeroDivisionError()
return Vector4i_divide_vector(self, _val)
{{ render_method("as_string") | indent }}
{% endblock %}
{%- block python_consts %}
AXIS = IntEnum("AXIS", {
"X": pandemonium_vector4i_axis.PANDEMONIUM_VECTOR4I_AXIS_X,
"Y": pandemonium_vector4i_axis.PANDEMONIUM_VECTOR4I_AXIS_Y,
"Z": pandemonium_vector4i_axis.PANDEMONIUM_VECTOR4I_AXIS_Z,
"W": pandemonium_vector4_axis.PANDEMONIUM_VECTOR4_AXIS_W,
})
{% endblock %}

View File

@ -29,6 +29,13 @@ from type_specs import (
TYPE_NODEPATH,
TYPE_DICTIONARY,
TYPE_ARRAY,
TYPE_STRING_NAME,
TYPE_RECT2I,
TYPE_PROJECTION,
TYPE_VECTOR2I,
TYPE_VECTOR3I,
TYPE_VECTOR4,
TYPE_VECTOR4I,
)
@ -107,9 +114,9 @@ ALL_TYPES = [
is_builtin=True,
),
TypeSpec(
gdapi_type="pandemonium_string_name",
c_type="pandemonium_string_name",
cy_type="pandemonium_string_name",
gdapi_type="pandemonium_char_16_string",
c_type="pandemonium_char_16_string",
cy_type="pandemonium_char_16_string",
py_type="str",
is_builtin=True,
),
@ -142,9 +149,15 @@ TARGET_TO_TYPE_SPEC = {
"node_path": TYPE_NODEPATH,
"dictionary": TYPE_DICTIONARY,
"array": TYPE_ARRAY,
"string_name": TYPE_STRING_NAME,
"rect2i": TYPE_RECT2I,
"projection": TYPE_PROJECTION,
"vector2i": TYPE_VECTOR2I,
"vector3i": TYPE_VECTOR3I,
"vector4": TYPE_VECTOR4,
"vector4i": TYPE_VECTOR4I,
}
@dataclass
class ArgumentSpec:
name: str