Merge branch 'origin/master' - combine double-execution fixes
Both branches fixed the --exec double-execution bug with complementary approaches: - origin/master: Added executeStartupScripts() method for cleaner separation - HEAD: Avoided engine recreation to preserve state This merge keeps the best of both: executeStartupScripts() called on the existing engine without recreation. Also accepts deletion of flaky test_viewport_visual.py from origin/master. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
commit
a703bce196
5 changed files with 16 additions and 151 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()
|
||||
|
|
|
|||
|
|
@ -146,6 +146,7 @@ public:
|
|||
void run();
|
||||
void sUserInput();
|
||||
void cleanup(); // Clean up Python references before destruction
|
||||
void executeStartupScripts(); // Execute --exec scripts (called once after final engine setup)
|
||||
int getFrame() { return currentFrame; }
|
||||
float getFrameTime() { return frameTime; }
|
||||
sf::View getView() { return visible; }
|
||||
|
|
|
|||
|
|
@ -183,8 +183,8 @@ int run_python_interpreter(const McRogueFaceConfig& config)
|
|||
return 0;
|
||||
}
|
||||
else if (!config.exec_scripts.empty()) {
|
||||
// With --exec, scripts were already executed by the first GameEngine constructor.
|
||||
// Just configure auto-exit and run the existing engine to preserve timers/state.
|
||||
// Execute startup scripts on the existing engine (not in constructor to prevent double-execution)
|
||||
engine->executeStartupScripts();
|
||||
if (config.headless) {
|
||||
engine->setAutoExitAfterExec(true);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue