From e8240cb38002283a009750ec86263f5e99c48394 Mon Sep 17 00:00:00 2001 From: John McCardle Date: Fri, 8 Mar 2024 10:17:26 -0500 Subject: [PATCH] Exit functionality via game engine, because sys.exit was making a mess --- src/McRFPy_API.cpp | 8 +++++++- src/McRFPy_API.h | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/McRFPy_API.cpp b/src/McRFPy_API.cpp index 042f22e..cbda5a4 100644 --- a/src/McRFPy_API.cpp +++ b/src/McRFPy_API.cpp @@ -34,7 +34,7 @@ static PyMethodDef mcrfpyMethods[] = { {"setTimer", McRFPy_API::_setTimer, METH_VARARGS, "setTimer(name:str, callable:object, interval:int) - callable will be called with args (runtime:float) every `interval` milliseconds"}, {"delTimer", McRFPy_API::_delTimer, METH_VARARGS, "delTimer(name:str) - stop calling the timer labelled with `name`"}, - + {"exit", McRFPy_API::_exit, METH_VARARGS, "exit() - close down the game engine"}, {NULL, NULL, 0, NULL} }; @@ -471,3 +471,9 @@ PyObject* McRFPy_API::_delTimer(PyObject* self, PyObject* args) { Py_INCREF(Py_None); return Py_None; } + +PyObject* McRFPy_API::_exit(PyObject* self, PyObject* args) { + game->quit(); + Py_INCREF(Py_None); + return Py_None; +} diff --git a/src/McRFPy_API.h b/src/McRFPy_API.h index 52730c8..7148b11 100644 --- a/src/McRFPy_API.h +++ b/src/McRFPy_API.h @@ -79,6 +79,8 @@ public: static PyObject* _setTimer(PyObject*, PyObject*); static PyObject* _delTimer(PyObject*, PyObject*); + static PyObject* _exit(PyObject*, PyObject*); + // accept keyboard input from scene static sf::Vector2i cursor_position; static void player_input(int, int);