Exit functionality via game engine, because sys.exit was making a mess

This commit is contained in:
John McCardle 2024-03-08 10:17:26 -05:00
parent db548c9183
commit e8240cb380
2 changed files with 9 additions and 1 deletions

View File

@ -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"}, {"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`"}, {"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} {NULL, NULL, 0, NULL}
}; };
@ -471,3 +471,9 @@ PyObject* McRFPy_API::_delTimer(PyObject* self, PyObject* args) {
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
} }
PyObject* McRFPy_API::_exit(PyObject* self, PyObject* args) {
game->quit();
Py_INCREF(Py_None);
return Py_None;
}

View File

@ -79,6 +79,8 @@ public:
static PyObject* _setTimer(PyObject*, PyObject*); static PyObject* _setTimer(PyObject*, PyObject*);
static PyObject* _delTimer(PyObject*, PyObject*); static PyObject* _delTimer(PyObject*, PyObject*);
static PyObject* _exit(PyObject*, PyObject*);
// accept keyboard input from scene // accept keyboard input from scene
static sf::Vector2i cursor_position; static sf::Vector2i cursor_position;
static void player_input(int, int); static void player_input(int, int);