fix: Resolve --exec double script execution bug
Scripts passed to --exec were executing twice because GameEngine constructor ran scripts, and main.cpp created two GameEngine instances. - Move exec_scripts from constructor to new executeStartupScripts() method - Call executeStartupScripts() once after final engine setup in main.cpp - Remove double-execution workarounds from tests - Delete duplicate test_viewport_visual.py (flaky due to race condition) - Fix test constructor syntax and callback signatures 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
b173f59f22
commit
ce0be78b73
9 changed files with 118 additions and 451 deletions
|
|
@ -63,23 +63,31 @@ GameEngine::GameEngine(const McRogueFaceConfig& cfg)
|
|||
McRFPy_API::executePyString("import mcrfpy");
|
||||
McRFPy_API::executeScript("scripts/game.py");
|
||||
}
|
||||
|
||||
|
||||
// Note: --exec scripts are NOT executed here.
|
||||
// They are executed via executeStartupScripts() after the final engine is set up.
|
||||
// This prevents double-execution when main.cpp creates multiple GameEngine instances.
|
||||
|
||||
clock.restart();
|
||||
runtime.restart();
|
||||
}
|
||||
|
||||
void GameEngine::executeStartupScripts()
|
||||
{
|
||||
// Execute any --exec scripts in order
|
||||
// This is called ONCE from main.cpp after the final engine is set up
|
||||
if (!config.exec_scripts.empty()) {
|
||||
if (!Py_IsInitialized()) {
|
||||
McRFPy_API::api_init();
|
||||
}
|
||||
McRFPy_API::executePyString("import mcrfpy");
|
||||
|
||||
|
||||
for (const auto& exec_script : config.exec_scripts) {
|
||||
std::cout << "Executing script: " << exec_script << std::endl;
|
||||
McRFPy_API::executeScript(exec_script.string());
|
||||
}
|
||||
std::cout << "All --exec scripts completed" << std::endl;
|
||||
}
|
||||
|
||||
clock.restart();
|
||||
runtime.restart();
|
||||
}
|
||||
|
||||
GameEngine::~GameEngine()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue