allow to re-start arenas

This commit is contained in:
2026-05-03 20:41:59 +02:00
parent 55b42a03d9
commit 6405ad6b3f
4 changed files with 18 additions and 6 deletions

View File

@@ -67,6 +67,7 @@ void ArenaWidget::buildLayout(const std::string& arenaName)
void ArenaWidget::startSimulation()
{
m_running = true;
m_wasFinished = false;
m_startButton->setEnabled(false);
setStyleSheet("ArenaWidget { border: 2px solid #3366ff; padding: 8px; }");
}
@@ -107,6 +108,8 @@ void ArenaWidget::updateStatus(const ArenaStatus& status)
if (status.finished && !m_wasFinished)
{
m_wasFinished = true;
m_running = false;
m_startButton->setEnabled(true);
setStyleSheet("ArenaWidget { border: 2px solid #33cc33; padding: 8px; }");
}
}

View File

@@ -7,6 +7,8 @@ BalancingWindow::BalancingWindow(const BalancingConfig& balancingConfig,
const GameConfig& gameConfig,
QWidget* parent)
: QWidget(parent)
, m_gameConfig(gameConfig)
, m_nextSeed(0)
{
setWindowTitle("DotaFactory — Balancing Tool");
resize(800, 600);
@@ -26,14 +28,14 @@ BalancingWindow::BalancingWindow(const BalancingConfig& balancingConfig,
contentLayout->setSpacing(8);
contentLayout->setContentsMargins(8, 8, 8, 8);
unsigned int seed = 0;
for (const ArenaConfig& arenaConfig : balancingConfig.arenas)
{
int index = static_cast<int>(m_arenas.size());
ArenaEntry entry;
entry.config = arenaConfig;
entry.simulation = std::make_unique<ArenaSimulation>(
gameConfig, arenaConfig, seed++);
m_gameConfig, arenaConfig, m_nextSeed++);
entry.widget = new ArenaWidget(arenaConfig.name, scrollContent);
contentLayout->addWidget(entry.widget);
@@ -97,9 +99,13 @@ void BalancingWindow::startArena(int index)
ArenaEntry& entry = m_arenas[index];
if (entry.worker.joinable())
{
return;
entry.simulation->requestStop();
entry.worker.join();
}
entry.simulation = std::make_unique<ArenaSimulation>(
m_gameConfig, entry.config, m_nextSeed++);
entry.widget->startSimulation();
entry.widget->updateStatus(entry.simulation->status());
ArenaSimulation* sim = entry.simulation.get();
entry.worker = std::thread([sim]() { sim->run(); });
updateStartAllButton();
@@ -109,7 +115,7 @@ void BalancingWindow::updateStartAllButton()
{
for (ArenaEntry& entry : m_arenas)
{
if (!entry.worker.joinable())
if (!entry.worker.joinable() || entry.simulation->status().finished)
{
m_startAllButton->setEnabled(true);
return;

View File

@@ -33,12 +33,15 @@ private:
struct ArenaEntry
{
ArenaConfig config;
std::unique_ptr<ArenaSimulation> simulation;
std::thread worker;
ArenaWidget* widget;
};
std::vector<ArenaEntry> m_arenas;
const GameConfig& m_gameConfig;
unsigned int m_nextSeed;
QPushButton* m_startAllButton;
QTimer* m_pollTimer;
};