Skip to content

Commit

Permalink
Merge branch 'master' of github.com:kaaengine/kaa into matmul
Browse files Browse the repository at this point in the history
  • Loading branch information
labuzm committed Jun 16, 2020
2 parents caf48c5 + 04644e2 commit b5b581a
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 14 deletions.
10 changes: 10 additions & 0 deletions docs/reference/geometry.rst
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,16 @@ Instance Methods:
Returns a distance from (x,y) to (other_vector.x, other_vector.y), in other words: distance between two points.
other_vector parameter must be :class:`geometry.Vector`

.. method:: Vector.angle_between(other_vector)

Returns angle between this vector and :code:`other_vector`, in radians. The other_vector parameter must
be :class:`geometry.Vector`

.. method:: Vector.angle_between_degrees(other_vector)

Returns angle between this vector and :code:`other_vector`, in degrees. The other_vector parameter must
be :class:`geometry.Vector`

.. method:: Vector.normalize()

Returns a new vector, normalized (i.e. unit vector)
Expand Down
22 changes: 20 additions & 2 deletions docs/reference/input.rst
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,17 @@ Mouse manager can be accessed via the :ref:`InputManager.mouse <InputManager.mou
The manager allows to check for the mouse buttons state (pressed/released). It also
allows to get the mouse pointer position.

Instance properties:

.. attribute:: MouseManager.relative_mode

Gets or sets relative mode (as bool). Default is :code:`False`. Enabling relative mode has two effects: it
hides the mouse pointer and it makes mouse motion events (:class:`MouseMotionEvent`) be published all the time
(by default those events are published only if mouse moves within game's window). Disabling the relative mode
shows the mouse pointer and makes mouse motion events be published only if mouse movement occurs within the
window.


Instance methods:

.. method:: MouseManager.is_pressed(mousebutton)
Expand Down Expand Up @@ -572,7 +583,10 @@ Instance properties:

.. class:: MouseMotionEvent

Represents a mouse motion event (changing mouse pointer position)
Represents a mouse motion event (changing mouse pointer position). By default those events are published when
mouse pointer is within the window. You can enable the :code:`relative_mode` on the :class:`MouseManager` - it hides the
mouse pointer and makes mouse motion events be published whenever the pointer is moved (inside or outside of the
window).

.. code-block:: python
Expand All @@ -587,13 +601,17 @@ Instance properties:

Returns mouse pointer position as :class:`geometry.Vector`.

.. attribute:: MouseButtonEvent.motion

Returns mouse pointer motion (difference between the current and previous position) as :class:`geometry.Vector`.


:class:`MouseWheelEvent` reference
-----------------------------------

.. class:: MouseWheelEvent

Represents a mouse wheel related event
Represents a mouse wheel related event.

Instance properties:

Expand Down
35 changes: 30 additions & 5 deletions src/kaa/custom_transitions.pxi
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import cython
from libc.stdint cimport uintptr_t
from libcpp.memory cimport unique_ptr
from cpython.ref cimport PyObject

Expand Down Expand Up @@ -57,19 +58,43 @@ cdef cppclass CPyNodeCustomTransition(CNodeTransitionCustomizable):
this.internal_duration = duration
this.warping = warping

unique_ptr[CTransitionStateBase] prepare_state(CNodePtr c_node_ptr) const:
cdef object state_object = (<object>this.prepare_func.py_callback)(get_node_wrapper(c_node_ptr))
unique_ptr[CTransitionStateBase] prepare_state(CNodePtr c_node_ptr) nogil const:
cdef CPyNodeCustomTransitionState* state_ptr = \
<CPyNodeCustomTransitionState*>this._py_prepare_state(c_node_ptr).unwrap_result()

return <unique_ptr[CTransitionStateBase]> \
unique_ptr[CPyNodeCustomTransitionState](
state_ptr
)

CPythonicCallbackResult[uintptr_t] _py_prepare_state(CNodePtr c_node_ptr) with gil const:
cdef object state_object
try:
state_object = (<object>this.prepare_func.py_callback)(get_node_wrapper(c_node_ptr))
except BaseException as exc:
return CPythonicCallbackResult[uintptr_t](<PyObject*>exc)
else:
return CPythonicCallbackResult[uintptr_t](
<uintptr_t>
new CPyNodeCustomTransitionState(state_object)
)

void evaluate(CTransitionStateBase* state, CNodePtr c_node_ptr, const double t) const:
void evaluate(CTransitionStateBase* state, CNodePtr c_node_ptr, const double t) nogil const:
this._py_evaluate(state, c_node_ptr, t).unwrap_result()

CPythonicCallbackResult[void] _py_evaluate(
CTransitionStateBase* state, CNodePtr c_node_ptr, const double t
) with gil const:
cdef CPyNodeCustomTransitionState* custom_state = \
<CPyNodeCustomTransitionState*>state

(<object>this.evaluate_func.py_callback)(custom_state.state_object,
get_node_wrapper(c_node_ptr), t)
try:
(<object>this.evaluate_func.py_callback)(custom_state.state_object,
get_node_wrapper(c_node_ptr), t)
except BaseException as exc:
return CPythonicCallbackResult[void](<PyObject*>exc)
else:
return CPythonicCallbackResult[void]()


@cython.final
Expand Down
8 changes: 5 additions & 3 deletions src/kaa/extra/include/python_exceptions_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ struct PythonException : std::exception {

~PythonException()
{
PyGILState_STATE gstate = PyGILState_Ensure();
Py_DECREF(this->py_exception);
PyGILState_Release(gstate);
if (this->py_exception != nullptr) {
PyGILState_STATE gstate = PyGILState_Ensure();
Py_DECREF(this->py_exception);
PyGILState_Release(gstate);
}
}

PythonException(const PythonException& exc)
Expand Down
4 changes: 2 additions & 2 deletions src/kaa/kaacore/custom_transitions.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ cdef extern from "kaacore/transitions.h":
CNodeTransitionCustomizable(const double duration, const CTransitionWarping& warping) \
except +raise_py_error

unique_ptr[CTransitionStateBase] prepare_state(CNodePtr node) const
void evaluate(CTransitionStateBase* state, CNodePtr node, const double t) const
unique_ptr[CTransitionStateBase] prepare_state(CNodePtr node) nogil const
void evaluate(CTransitionStateBase* state, CNodePtr node, const double t) nogil const

ctypedef function[void(CNodePtr)] CNodeTransitionCallbackFunc "kaacore::NodeTransitionCallbackFunc";

Expand Down
4 changes: 2 additions & 2 deletions src/kaa/kaacore/input.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,8 @@ cdef extern from "kaacore/input.h" nogil:
bint is_released(CMouseButton mb) except +raise_py_error
CDVec2 get_position() except +raise_py_error

bint relative_mode()
void relative_mode(const bint rel)
bint relative_mode() except +raise_py_error
void relative_mode(const bint rel) except +raise_py_error

cdef cppclass CControllerManager "kaacore::InputManager::ControllerManager":
bint is_connected(int32_t id_) except +raise_py_error
Expand Down

0 comments on commit b5b581a

Please sign in to comment.