fix issue where beams were also disappearing while the game was paused

This commit is contained in:
2026-06-20 08:24:10 +02:00
parent 405206211e
commit c43225b6fa
4 changed files with 14 additions and 16 deletions

View File

@@ -102,7 +102,6 @@ GameWorldView::GameWorldView(Simulation* sim, const GameConfig* config,
, m_sim(sim)
, m_config(config)
, m_visuals(visuals)
, m_wallMs(0)
, m_gameSpeedMultiplier(1.0)
, m_prevNonZeroSpeed(1.0)
, m_scrollXTiles(0.0f)
@@ -144,7 +143,6 @@ void GameWorldView::initializeGL()
void GameWorldView::onFrame()
{
const qint64 elapsed = m_frameTimer.restart();
m_wallMs += elapsed;
// Advance simulation
{
@@ -166,12 +164,14 @@ void GameWorldView::onFrame()
}
}
// Expire old beams
// Expire old beams. Lifetime is measured in game ticks so beams stay
// visible while the simulation is paused or slowed (REQ-SHP-FIRING-BEAM).
{
const Tick now = m_sim->currentTick();
std::vector<ActiveBeam> live;
for (const ActiveBeam& b : m_activeBeams)
{
if (m_wallMs - b.emittedWallMs < kBeamLifetimeMs)
if (now - b.event.emittedAt < kBeamLifetimeTicks)
{
live.push_back(b);
}
@@ -1603,7 +1603,6 @@ void GameWorldView::handleEvent(std::shared_ptr<const BeamFiredEvent> event)
ActiveBeam beam;
beam.event = *event;
beam.emittedWallMs = m_wallMs;
beam.targetOffset = QVector2D(radius * std::cos(angle),
radius * std::sin(angle));
m_activeBeams.push_back(beam);

View File

@@ -141,11 +141,12 @@ private:
struct ActiveBeam
{
BeamFiredEvent event;
qint64 emittedWallMs;
QVector2D targetOffset;
};
static constexpr qint64 kBeamLifetimeMs = 300;
// Beam lifetime in game ticks so beams freeze with the simulation when
// paused or slowed, instead of fading on wall-clock time (REQ-SHP-FIRING-BEAM).
static constexpr Tick kBeamLifetimeTicks = secondsToTicks(0.3);
static constexpr float kScrollSpeedTilesPerSec = 10.0f;
Simulation* m_sim;
@@ -154,7 +155,6 @@ private:
TickDriver m_tickDriver;
QElapsedTimer m_frameTimer;
qint64 m_wallMs;
std::mt19937 m_rng;
double m_gameSpeedMultiplier;
double m_prevNonZeroSpeed;