Skip to content

Commit fe1d17b

Browse files
committed
Tftd video corrections.
Pressing a mouse button or a keyboard button should skip the video without waiting. Corrected the video path, the default should be linux one. Fixed a crash when no video is found. Fixed black pixels in the Earth sequence, thanks to AndO3131.
1 parent 2914896 commit fe1d17b

4 files changed

Lines changed: 47 additions & 23 deletions

File tree

‎bin/data/Ruleset/Xcom1Ruleset.rul‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9323,7 +9323,7 @@ alienItemLevels:
93239323
cutscenes:
93249324
- type: intro
93259325
videos:
9326-
- UFOINTRO\UFOINT.FLI
9326+
- UFOINTRO/UFOINT.FLI
93279327
MCDPatches:
93289328
# pathFinding Hacks.
93299329
# bigWall 1 = regular bigwall, no movement allowed.

‎src/Engine/FlcPlayer.cpp‎

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ enum ChunkOpcodes
7171
MASK = SKIP_LINES
7272
};
7373

74+
enum PlayingState
75+
{
76+
PLAYING,
77+
FINISHED,
78+
SKIPPED
79+
};
80+
7481
FlcPlayer::FlcPlayer() : _fileBuf(0), _mainScreen(0), _realScreen(0), _game(0)
7582
{
7683
}
@@ -182,7 +189,7 @@ void FlcPlayer::deInit()
182189
*/
183190
void FlcPlayer::play(bool skipLastFrame)
184191
{
185-
_quit = false;
192+
_playingState = PLAYING;
186193

187194
// Vertically center the video
188195
_dy = (_mainScreen->h - _headerHeight) / 2;
@@ -193,17 +200,17 @@ void FlcPlayer::play(bool skipLastFrame)
193200
_videoFrameData = _fileBuf + 128;
194201
_audioFrameData = _videoFrameData;
195202

196-
while (!_quit)
203+
while (!shouldQuit())
197204
{
198205
if (_frameCallBack)
199206
(*_frameCallBack)();
200207
else // TODO: support both, in the case the callback is not some audio?
201208
decodeAudio(2);
202209

203-
if (!_quit)
210+
if (!shouldQuit())
204211
decodeVideo(skipLastFrame);
205-
206-
if(!_quit)
212+
213+
if(!shouldQuit())
207214
SDLPolling();
208215
}
209216

@@ -212,7 +219,7 @@ void FlcPlayer::play(bool skipLastFrame)
212219
void FlcPlayer::delay(Uint32 milliseconds)
213220
{
214221
Uint32 pauseStart = SDL_GetTicks();
215-
while(SDL_GetTicks() < (pauseStart + milliseconds))
222+
while(_playingState != SKIPPED && SDL_GetTicks() < (pauseStart + milliseconds))
216223
{
217224
SDLPolling();
218225
}
@@ -226,7 +233,7 @@ void FlcPlayer::SDLPolling()
226233
{
227234
case SDL_MOUSEBUTTONDOWN:
228235
case SDL_KEYDOWN:
229-
_quit = true;
236+
_playingState = SKIPPED;
230237
break;
231238
case SDL_VIDEORESIZE:
232239
if (Options::allowResize)
@@ -252,6 +259,11 @@ void FlcPlayer::SDLPolling()
252259
}
253260
}
254261

262+
bool FlcPlayer::shouldQuit()
263+
{
264+
return _playingState == FINISHED || _playingState == SKIPPED;
265+
}
266+
255267
void FlcPlayer::readFileHeader()
256268
{
257269
readU32(_headerSize, _fileBuf);
@@ -279,7 +291,7 @@ void FlcPlayer::decodeAudio(int frames)
279291
{
280292
if (!isValidFrame(_audioFrameData, _audioFrameSize, _audioFrameType))
281293
{
282-
_quit = true;
294+
_playingState = FINISHED;
283295
break;
284296
}
285297

@@ -315,7 +327,7 @@ void FlcPlayer::decodeVideo(bool skipLastFrame)
315327
{
316328
if (!isValidFrame(_videoFrameData, _videoFrameSize, _videoFrameType))
317329
{
318-
_quit = true;
330+
_playingState = FINISHED;
319331
break;
320332
}
321333

@@ -345,10 +357,10 @@ void FlcPlayer::decodeVideo(bool skipLastFrame)
345357
_videoFrameData += _videoFrameSize;
346358
// If this frame is the last one, don't play it
347359
if(isEndOfFile(_videoFrameData))
348-
_quit = true;
360+
_playingState = FINISHED;
349361

350-
if(!_quit || !skipLastFrame)
351-
playVideoFrame();
362+
if(!shouldQuit() || !skipLastFrame)
363+
playVideoFrame();
352364

353365
videoFrameFound = true;
354366

@@ -475,7 +487,7 @@ void FlcPlayer::color256()
475487

476488
while (numColorPackets--)
477489
{
478-
numColorsSkip = *(pSrc++);
490+
numColorsSkip = *(pSrc++) + numColors;
479491
numColors = *(pSrc++);
480492
if (numColors == 0)
481493
{
@@ -490,6 +502,11 @@ void FlcPlayer::color256()
490502
}
491503

492504
_realScreen->setPalette(_colors, numColorsSkip, numColors, true);
505+
506+
if (numColorPackets >= 1)
507+
{
508+
++numColors;
509+
}
493510
}
494511
}
495512

@@ -576,7 +593,7 @@ void FlcPlayer::fliBRun()
576593
{
577594
Uint8 *pSrc, *pDst, *pTmpDst, fill;
578595
Sint8 countData;
579-
int heightCount, packetsCount;
596+
int heightCount;
580597

581598
heightCount = _headerHeight;
582599
pSrc = _chunkData + 6; // Skip chunk header
@@ -585,7 +602,7 @@ void FlcPlayer::fliBRun()
585602
while (heightCount--)
586603
{
587604
pTmpDst = pDst;
588-
packetsCount = *(pSrc++);
605+
++pSrc; // Read and skip the packet count value
589606

590607
int pixels = 0;
591608
while (pixels != _headerWidth)
@@ -825,7 +842,7 @@ void FlcPlayer::deInitAudio()
825842

826843
void FlcPlayer::stop()
827844
{
828-
_quit = true;
845+
_playingState = FINISHED;
829846
}
830847

831848
bool FlcPlayer::isEndOfFile(Uint8 *pos)

‎src/Engine/FlcPlayer.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class FlcPlayer
6868
int _screenDepth;
6969
int _dx, _dy;
7070
int _offset;
71-
bool _quit;
71+
int _playingState;
7272
bool _hasAudio;
7373
int _videoDelay;
7474

@@ -111,6 +111,7 @@ class FlcPlayer
111111
void decodeAudio(int frames);
112112
void waitForNextFrame(Uint32 delay);
113113
void SDLPolling();
114+
bool shouldQuit();
114115

115116
void playVideoFrame();
116117
void color256();

‎src/Menu/IntroState.cpp‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,19 @@ IntroState::IntroState(bool wasLetterBoxed) : _wasLetterBoxed(wasLetterBoxed)
5151
const std::map<std::string, RuleVideo*> *videoRulesets = rules->getVideos();
5252

5353

54-
const RuleVideo *videoRule = videoRulesets->find("intro")->second;
55-
const std::vector<std::string> *videos = videoRule->getVideos();
54+
std::map<std::string, RuleVideo*>::const_iterator videoRuleIt = videoRulesets->find("intro");
5655

57-
std::vector<std::string>::const_iterator it;
58-
for(it = videos->begin(); it != videos->end(); ++it)
56+
if(videoRuleIt != videoRulesets->end())
5957
{
60-
_introFiles.push_back(CrossPlatform::getDataFile(*it));
58+
const RuleVideo *videoRule = videoRuleIt->second;
59+
60+
const std::vector<std::string> *videos = videoRule->getVideos();
61+
62+
std::vector<std::string>::const_iterator it;
63+
for(it = videos->begin(); it != videos->end(); ++it)
64+
{
65+
_introFiles.push_back(CrossPlatform::getDataFile(*it));
66+
}
6167
}
6268

6369
_introSoundFileDOS = CrossPlatform::getDataFile("SOUND/INTRO.CAT");

0 commit comments

Comments
 (0)