Skip to content

Commit c455347

Browse files
committed
apply fix for helicopter screen Hz rate
1 parent e7d4bd8 commit c455347

3 files changed

Lines changed: 36 additions & 49 deletions

File tree

Source/Briefing.cpp

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -122,30 +122,30 @@ void cFodder::Briefing_Helicopter_Check(double dtSeconds)
122122

123123
mBriefingHelicopter_TransitionCounterSeconds += dtSeconds;
124124

125-
auto doTransitionStepIfDue = [&]() -> bool {
125+
auto consumeTransitionSteps = [&]() -> int {
126126
if (mBriefingHelicopter_TransitionCounterSeconds < kTransitionStepSeconds)
127-
return false;
128-
// keep remainder so it’s stable under varying dt
129-
mBriefingHelicopter_TransitionCounterSeconds =
130-
std::fmod(mBriefingHelicopter_TransitionCounterSeconds, kTransitionStepSeconds);
131-
return true;
127+
return 0;
128+
129+
const int steps = (int)(mBriefingHelicopter_TransitionCounterSeconds / kTransitionStepSeconds);
130+
mBriefingHelicopter_TransitionCounterSeconds -= (double)steps * kTransitionStepSeconds;
131+
return steps;
132132
};
133133

134134
// ---- “Fade in until ready, then start heli movement” ----
135135
if (!mMouse_Exit_Loop || !mPhase_Aborted) {
136136

137137
if (mBriefingHelicopter_ScreenX > 0x30) {
138138

139-
if (doTransitionStepIfDue()) {
139+
int transitionSteps = consumeTransitionSteps();
140+
while (transitionSteps-- > 0) {
140141
// Original: 16 steps total for fade-in.
141142
if (mBriefingHelicopter_Moving < 16) {
142143
mBriefingHelicopter_Moving++;
143144
mPaletteLevel++;
144-
return;
145145
}
146146
}
147147

148-
// Once fade-in complete, advance helicopter sim (60Hz tick wrapper)
148+
// Once fade-in complete, advance helicopter sim (50Hz tick wrapper)
149149
if (mBriefingHelicopter_Moving >= 16) {
150150
Briefing_Update_Helicopter_Frame(dtSeconds);
151151
}
@@ -154,15 +154,19 @@ void cFodder::Briefing_Helicopter_Check(double dtSeconds)
154154
}
155155

156156
// ---- “Fade out / exit path” ----
157-
if (doTransitionStepIfDue()) {
157+
int transitionSteps = consumeTransitionSteps();
158+
while (transitionSteps-- > 0) {
158159
if (mBriefingHelicopter_Moving == 0 && mBriefingHelicopter_NotDone) {
159160
mBriefingHelicopter_NotDone = 0;
160161
mGraphics->mImageMissionIntro.CopyPalette(mGraphics->mPalette, 0x100, 0);
162+
break;
161163
}
162164
else {
163165
if (mBriefingHelicopter_Moving > 0 || mPaletteLevel > 0) {
164-
mBriefingHelicopter_Moving--;
165-
mPaletteLevel--;
166+
if (mBriefingHelicopter_Moving > 0)
167+
mBriefingHelicopter_Moving--;
168+
if (mPaletteLevel > 0)
169+
mPaletteLevel--;
166170
mSurface->paletteNew_SetToBlack();
167171
}
168172
}
@@ -448,7 +452,10 @@ void cFodder::Briefing_Intro_Helicopter_Start() {
448452

449453
mBriefingHelicopter_TransitionCounterSeconds = 0;
450454
mBriefingHelicopter_AccumSeconds = 0.0;
451-
mBriefingHelicopter_StepSeconds = 1.0 / 60.0;
455+
mHeliIntro_AccumSeconds = 0.0;
456+
// Original briefing helicopter simulation cadence is PAL 50Hz.
457+
// Keep this in sync with offsets/countdowns that are defined in 50Hz ticks.
458+
mBriefingHelicopter_StepSeconds = 1.0 / 50.0;
452459
mHeliParallax_SubPx = 0;
453460
mHeliText_SubPx = 0;
454461

Source/Fodder.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,7 @@ class cFodder {
565565
double mBriefingHelicopter_AccumSeconds = 0.0;
566566
double mBriefingHelicopter_StepSeconds = 1.0 / 50.0;
567567
double mBriefingHelicopter_TransitionCounterSeconds = 0;
568+
double mHeliIntro_AccumSeconds = 0.0;
568569
double mHeliParallax_SubPx = 0.0; // accumulates fractional scroll in 16.16 units
569570
double mHeliText_SubPx = 0.0; // accumulates fractional text movement in pixels
570571

Source/Graphics.cpp

Lines changed: 15 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -165,46 +165,23 @@ void cGraphics::Sidebar_Copy_ScreenBuffer_Common(uint16 pRow, int16 pRows, int16
165165

166166
void cGraphics::HeliIntro_TickParallaxAndText(double dtSeconds)
167167
{
168-
// ----- Text slide (PAL) -----
169-
//
170-
// Original Amiga PAL behaviour:
171-
// Each step moves 4 pixels
172-
// => 4 * 50 = 200 px/sec toward 0x0C.
173-
const double textVelPxPerSec = 200.0;
174-
175-
if (Heli_TextPosBottom != 0x0C) {
176-
g_Fodder->mHeliText_SubPx += textVelPxPerSec * dtSeconds;
177-
178-
const int32_t stepPx = (int32_t)std::floor(g_Fodder->mHeliText_SubPx);
179-
if (stepPx > 0) {
180-
g_Fodder->mHeliText_SubPx -= (double)stepPx;
181-
Heli_TextPosBottom -= stepPx;
182-
183-
if (Heli_TextPosBottom <= 0x0C) {
184-
Heli_TextPosBottom = 0x0C;
185-
g_Fodder->mHeliText_SubPx = 0.0;
186-
}
187-
}
188-
}
189-
190-
Heli_TextPos = 344 - Heli_TextPosBottom;
168+
// Keep briefing intro parallax and text on fixed PAL 50Hz ticks.
169+
// This mirrors original cadence and avoids variable-dt jitter.
170+
const double tickSeconds = 1.0 / 50.0;
171+
g_Fodder->mHeliIntro_AccumSeconds += dtSeconds;
191172

192-
// ----- Parallax scroll (PAL) -----
193-
//
194-
// Original behaviour per PAL frame (50Hz):
195-
// baseSpeed = 0x8000 (16.16 units) per frame
196-
// => per-second speed = 0x8000 * 50 (16.16 units/sec)
197-
const double baseSpeed_16_16_per_sec = (double)0x8000 * 50.0;
173+
const int32_t wrap = 320 << 16;
198174

199-
g_Fodder->mHeliParallax_SubPx += baseSpeed_16_16_per_sec * dtSeconds;
175+
while (g_Fodder->mHeliIntro_AccumSeconds >= tickSeconds) {
176+
g_Fodder->mHeliIntro_AccumSeconds -= tickSeconds;
200177

201-
const int32_t baseStep = (int32_t)std::floor(g_Fodder->mHeliParallax_SubPx);
202-
if (baseStep != 0) {
203-
g_Fodder->mHeliParallax_SubPx -= (double)baseStep;
204-
205-
const int32_t wrap = 320 << 16;
178+
if (Heli_TextPosBottom > 0x0C) {
179+
Heli_TextPosBottom -= 4;
180+
if (Heli_TextPosBottom < 0x0C)
181+
Heli_TextPosBottom = 0x0C;
182+
}
206183

207-
int32_t d0 = baseStep;
184+
int32_t d0 = 0x8000;
208185

209186
Heli_VeryBack -= d0;
210187
if (Heli_VeryBack < 0) Heli_VeryBack += wrap;
@@ -221,4 +198,6 @@ void cGraphics::HeliIntro_TickParallaxAndText(double dtSeconds)
221198
Heli_Front -= d0;
222199
if (Heli_Front < 0) Heli_Front += wrap;
223200
}
201+
202+
Heli_TextPos = 344 - Heli_TextPosBottom;
224203
}

0 commit comments

Comments
 (0)