From 8f060dc87beadfa814b554ab23a5d187d6695c90 Mon Sep 17 00:00:00 2001 From: John McCardle Date: Fri, 15 Mar 2024 22:20:03 -0400 Subject: [PATCH] Removing std::cout debugging statements --- src/GameEngine.cpp | 11 +++-------- src/PyCallable.cpp | 11 +---------- 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/src/GameEngine.cpp b/src/GameEngine.cpp index 6c3d95d..d1d035f 100644 --- a/src/GameEngine.cpp +++ b/src/GameEngine.cpp @@ -69,17 +69,14 @@ void GameEngine::run() void GameEngine::manageTimer(std::string name, PyObject* target, int interval) { - //std::cout << "Manage timer called. " << name << " " << interval << std::endl; auto it = timers.find(name); if (it != timers.end()) // overwrite existing { - if (target == NULL || target == Py_None) // delete + if (target == NULL || target == Py_None) { - //Py_DECREF(timers[name].target); - std::cout << "Erasing a timer" << std::endl; - //timers.erase(it); + // Delete: Overwrite existing timer with one that calls None. This will be deleted in the next timer check + // see gitea issue #4: this allows for a timer to be deleted during its own call to itself timers[name] = std::make_shared(Py_None, 1000, runtime.getElapsedTime().asMilliseconds()); - std::cout << "It was erased" << std::endl; return; } } @@ -89,13 +86,11 @@ void GameEngine::manageTimer(std::string name, PyObject* target, int interval) return; } timers[name] = std::make_shared(target, interval, runtime.getElapsedTime().asMilliseconds()); - //Py_INCREF(target); } void GameEngine::testTimers() { int now = runtime.getElapsedTime().asMilliseconds(); - //for (auto& [name, timer]: timers) auto it = timers.begin(); while (it != timers.end()) { diff --git a/src/PyCallable.cpp b/src/PyCallable.cpp index 2aca5c2..6d44501 100644 --- a/src/PyCallable.cpp +++ b/src/PyCallable.cpp @@ -3,10 +3,6 @@ PyCallable::PyCallable(PyObject* _target) { target = Py_XNewRef(_target); - if (target) - { - //std::cout << PyUnicode_AsUTF8(PyObject_Repr(target)) << std::endl; - } } PyCallable::~PyCallable() @@ -17,9 +13,6 @@ PyCallable::~PyCallable() PyObject* PyCallable::call(PyObject* args, PyObject* kwargs) { - std::cout << "Calling object with args: "; - std::cout << PyUnicode_AsUTF8(PyObject_Repr(target)) << " <- "; - std::cout << PyUnicode_AsUTF8(PyObject_Repr(args)) << std::endl; return PyObject_Call(target, args, kwargs); } @@ -43,12 +36,10 @@ bool PyTimerCallable::hasElapsed(int now) void PyTimerCallable::call(int now) { - std::cout << "PyTimerCallable called. (" << (target == NULL) << ")" << std::endl; PyObject* args = Py_BuildValue("(i)", now); PyObject* retval = PyCallable::call(args, NULL); if (!retval) { - std::cout << "timer has raised an exception. It's going to STDERR and being dropped:" << std::endl; PyErr_Print(); PyErr_Clear(); } else if (retval != Py_None) @@ -60,7 +51,6 @@ void PyTimerCallable::call(int now) bool PyTimerCallable::test(int now) { - std::cout << "PyTimerCallable tested. (" << (target == NULL) << ")" << interval << " " << last_ran << std::endl; if(hasElapsed(now)) { call(now); @@ -109,6 +99,7 @@ PyKeyCallable::PyKeyCallable() void PyKeyCallable::call(std::string key, std::string action) { + if (target == Py_None || target == NULL) return; PyObject* args = Py_BuildValue("(ss)", key.c_str(), action.c_str()); PyObject* retval = PyCallable::call(args, NULL); if (!retval)