replace combined stateUpdated signal with individual events
This commit is contained in:
@@ -34,6 +34,10 @@
|
||||
#include "SurfaceMask.h"
|
||||
#include "Tick.h"
|
||||
#include "TracePrintRequestedEvent.h"
|
||||
#include "BossWaveUpdatedEvent.h"
|
||||
#include "BuildingBlocksChangedEvent.h"
|
||||
#include "GameSpeedChangedEvent.h"
|
||||
#include "TickAdvancedEvent.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
@@ -239,12 +243,33 @@ void GameWorldView::onFrame()
|
||||
clampScroll();
|
||||
}
|
||||
|
||||
// Emit state update for header bar / build grid
|
||||
emit stateUpdated(m_sim->currentTick(),
|
||||
m_sim->buildingBlocksStock(),
|
||||
m_gameSpeedMultiplier,
|
||||
m_sim->bossWaveCounter(),
|
||||
m_sim->bossCountdownTicks());
|
||||
// Fire events for any state that changed since the last frame
|
||||
{
|
||||
const Tick newTick = m_sim->currentTick();
|
||||
const int newBlocks = m_sim->buildingBlocksStock();
|
||||
const int newBoss = m_sim->bossWaveCounter();
|
||||
const Tick newCountdown = m_sim->bossCountdownTicks();
|
||||
|
||||
if (newTick != m_lastTick)
|
||||
{
|
||||
m_lastTick = newTick;
|
||||
EventManager::getInstance()->sendEventImmediately(
|
||||
std::make_shared<TickAdvancedEvent>(newTick));
|
||||
}
|
||||
if (newBlocks != m_lastBlocks)
|
||||
{
|
||||
m_lastBlocks = newBlocks;
|
||||
EventManager::getInstance()->sendEventImmediately(
|
||||
std::make_shared<BuildingBlocksChangedEvent>(newBlocks));
|
||||
}
|
||||
if (newBoss != m_lastBossCounter || newCountdown != m_lastBossCountdown)
|
||||
{
|
||||
m_lastBossCounter = newBoss;
|
||||
m_lastBossCountdown = newCountdown;
|
||||
EventManager::getInstance()->sendEventImmediately(
|
||||
std::make_shared<BossWaveUpdatedEvent>(newBoss, newCountdown));
|
||||
}
|
||||
}
|
||||
|
||||
// Game over check
|
||||
if (m_sim->isGameOver() && !m_gameOverShown)
|
||||
@@ -1403,11 +1428,8 @@ double GameWorldView::gameSpeed() const
|
||||
void GameWorldView::setGameSpeed(double multiplier)
|
||||
{
|
||||
m_gameSpeedMultiplier = multiplier;
|
||||
emit stateUpdated(m_sim->currentTick(),
|
||||
m_sim->buildingBlocksStock(),
|
||||
m_gameSpeedMultiplier,
|
||||
m_sim->bossWaveCounter(),
|
||||
m_sim->bossCountdownTicks());
|
||||
EventManager::getInstance()->sendEventImmediately(
|
||||
std::make_shared<GameSpeedChangedEvent>(m_gameSpeedMultiplier));
|
||||
}
|
||||
|
||||
void GameWorldView::resetForNewGame()
|
||||
@@ -1427,8 +1449,12 @@ void GameWorldView::resetForNewGame()
|
||||
m_scrollLeft = false;
|
||||
m_scrollRight = false;
|
||||
m_gameOverShown = false;
|
||||
m_gameSpeedMultiplier = 1.0;
|
||||
m_prevNonZeroSpeed = 1.0;
|
||||
m_lastTick = Tick(-1);
|
||||
m_lastBlocks = -1;
|
||||
m_lastBossCounter = -1;
|
||||
m_lastBossCountdown = Tick(-1);
|
||||
emit selectionChanged({});
|
||||
setGameSpeed(1.0);
|
||||
update();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user