fix issue where beams were also disappearing while the game was paused
This commit is contained in:
@@ -40,7 +40,6 @@ ArenaView::ArenaView(ArenaSimulation* sim, const VisualsConfig* visuals,
|
||||
: QOpenGLWidget(parent)
|
||||
, m_sim(sim)
|
||||
, m_visuals(visuals)
|
||||
, m_wallMs(0)
|
||||
, m_gameSpeedMultiplier(1.0)
|
||||
, m_prevNonZeroSpeed(1.0)
|
||||
, m_rng(std::random_device{}())
|
||||
@@ -99,7 +98,6 @@ void ArenaView::togglePause()
|
||||
void ArenaView::onFrame()
|
||||
{
|
||||
const qint64 elapsed = m_frameTimer.restart();
|
||||
m_wallMs += elapsed;
|
||||
|
||||
{
|
||||
const int ticks = m_tickDriver.advance(
|
||||
@@ -120,12 +118,14 @@ void ArenaView::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);
|
||||
}
|
||||
@@ -165,7 +165,6 @@ void ArenaView::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);
|
||||
|
||||
@@ -67,18 +67,18 @@ 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);
|
||||
|
||||
ArenaSimulation* m_sim;
|
||||
const VisualsConfig* m_visuals;
|
||||
|
||||
TickDriver m_tickDriver;
|
||||
QElapsedTimer m_frameTimer;
|
||||
qint64 m_wallMs;
|
||||
std::mt19937 m_rng;
|
||||
double m_gameSpeedMultiplier;
|
||||
double m_prevNonZeroSpeed;
|
||||
|
||||
Reference in New Issue
Block a user