Fix --exec interactive prompt bug and create comprehensive test suite

Major fixes:
- Fixed --exec entering Python REPL instead of game loop
- Resolved screenshot transparency issue (requires timer callbacks)
- Added debug output to trace Python initialization

Test suite created:
- 13 comprehensive tests covering all Python-exposed methods
- Tests use timer callback pattern for proper game loop interaction
- Discovered multiple critical bugs and missing features

Critical bugs found:
- Grid class segfaults on instantiation (blocks all Grid functionality)
- Issue #78 confirmed: Middle mouse click sends 'C' keyboard event
- Entity property setters have argument parsing errors
- Sprite texture setter returns improper error
- keypressScene() segfaults on non-callable arguments

Documentation updates:
- Updated CLAUDE.md with testing guidelines and TDD practices
- Created test reports documenting all findings
- Updated ROADMAP.md with test results and new priorities

The Grid segfault is now the highest priority as it blocks all Grid-based functionality.
This commit is contained in:
John McCardle 2025-07-03 19:25:49 -04:00
commit 18cfe93a44
36 changed files with 2386 additions and 13 deletions

View file

@ -63,6 +63,7 @@ GameEngine::GameEngine(const McRogueFaceConfig& cfg)
std::cout << "Executing script: " << exec_script << std::endl;
McRFPy_API::executeScript(exec_script.string());
}
std::cout << "All --exec scripts completed" << std::endl;
}
clock.restart();
@ -111,6 +112,7 @@ void GameEngine::setWindowScale(float multiplier)
void GameEngine::run()
{
std::cout << "GameEngine::run() starting main loop..." << std::endl;
float fps = 0.0;
clock.restart();
while (running)

View file

@ -87,12 +87,12 @@ PyObject* PyInit_mcrfpy()
auto t = pytypes[i];
while (t != nullptr)
{
std::cout << "Registering type: " << t->tp_name << std::endl;
//std::cout << "Registering type: " << t->tp_name << std::endl;
if (PyType_Ready(t) < 0) {
std::cout << "ERROR: PyType_Ready failed for " << t->tp_name << std::endl;
return NULL;
}
std::cout << " tp_alloc after PyType_Ready: " << (void*)t->tp_alloc << std::endl;
//std::cout << " tp_alloc after PyType_Ready: " << (void*)t->tp_alloc << std::endl;
PyModule_AddType(m, t);
i++;
t = pytypes[i];
@ -316,7 +316,9 @@ void McRFPy_API::executeScript(std::string filename)
{
FILE* PScriptFile = fopen(filename.c_str(), "r");
if(PScriptFile) {
std::cout << "Before PyRun_SimpleFile" << std::endl;
PyRun_SimpleFile(PScriptFile, filename.c_str());
std::cout << "After PyRun_SimpleFile" << std::endl;
fclose(PScriptFile);
}
}

View file

@ -165,14 +165,21 @@ int run_python_interpreter(const McRogueFaceConfig& config, int argc, char* argv
delete engine;
return result;
}
else if (config.interactive_mode || config.python_mode) {
// Interactive Python interpreter
else if (config.interactive_mode) {
// Interactive Python interpreter (only if explicitly requested with -i)
Py_InspectFlag = 1;
PyRun_InteractiveLoop(stdin, "<stdin>");
Py_Finalize();
delete engine;
return 0;
}
else if (!config.exec_scripts.empty()) {
// With --exec, run the game engine after scripts execute
engine->run();
Py_Finalize();
delete engine;
return 0;
}
delete engine;
return 0;