mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-24 08:32:34 +02:00
Code review
This commit is contained in:
parent
e3acb92863
commit
3b9372c51c
@ -200,11 +200,7 @@ double CSoundHandler::getSoundDuration(const AudioPath & sound)
|
|||||||
SDL_FreeWAV(audioBuf);
|
SDL_FreeWAV(audioBuf);
|
||||||
uint32_t sampleSize = SDL_AUDIO_BITSIZE(spec.format) / 8;
|
uint32_t sampleSize = SDL_AUDIO_BITSIZE(spec.format) / 8;
|
||||||
uint32_t sampleCount = audioLen / sampleSize;
|
uint32_t sampleCount = audioLen / sampleSize;
|
||||||
uint32_t sampleLen = 0;
|
uint32_t sampleLen = sampleCount / spec.channels;
|
||||||
if(spec.channels)
|
|
||||||
sampleLen = sampleCount / spec.channels;
|
|
||||||
else
|
|
||||||
sampleLen = sampleCount;
|
|
||||||
seconds = (double)sampleLen / (double)spec.freq;
|
seconds = (double)sampleLen / (double)spec.freq;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,40 +33,43 @@ CPrologEpilogVideo::CPrologEpilogVideo(CampaignScenarioPrologEpilog _spe, std::f
|
|||||||
videoSoundHandle = CCS->soundh->playSound(audioData);
|
videoSoundHandle = CCS->soundh->playSound(audioData);
|
||||||
CCS->videoh->open(spe.prologVideo);
|
CCS->videoh->open(spe.prologVideo);
|
||||||
CCS->musich->playMusic(spe.prologMusic, true, true);
|
CCS->musich->playMusic(spe.prologMusic, true, true);
|
||||||
voiceDuration = CCS->soundh->getSoundDuration(spe.prologVoice);
|
voiceDurationMilliseconds = CCS->soundh->getSoundDuration(spe.prologVoice) * 1000.0;
|
||||||
voiceSoundHandle = CCS->soundh->playSound(spe.prologVoice);
|
voiceSoundHandle = CCS->soundh->playSound(spe.prologVoice);
|
||||||
auto onVoiceStop = [this]()
|
auto onVoiceStop = [this]()
|
||||||
{
|
{
|
||||||
voiceStopped = true;
|
voiceStopped = true;
|
||||||
elapsedTime = 0.0;
|
elapsedTimeMilliseconds = 0;
|
||||||
};
|
};
|
||||||
CCS->soundh->setCallback(voiceSoundHandle, onVoiceStop);
|
CCS->soundh->setCallback(voiceSoundHandle, onVoiceStop);
|
||||||
|
|
||||||
text = std::make_shared<CMultiLineLabel>(Rect(100, 500, 600, 100), EFonts::FONT_BIG, ETextAlignment::CENTER, Colors::METALLIC_GOLD, spe.prologText.toString());
|
text = std::make_shared<CMultiLineLabel>(Rect(100, 500, 600, 100), EFonts::FONT_BIG, ETextAlignment::CENTER, Colors::METALLIC_GOLD, spe.prologText.toString());
|
||||||
text->scrollTextTo(-50);
|
text->scrollTextTo(-50); // beginning of text in the vertical middle of black area
|
||||||
|
}
|
||||||
|
|
||||||
|
void CPrologEpilogVideo::tick(uint32_t msPassed)
|
||||||
|
{
|
||||||
|
elapsedTimeMilliseconds += msPassed;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CPrologEpilogVideo::show(Canvas & to)
|
void CPrologEpilogVideo::show(Canvas & to)
|
||||||
{
|
{
|
||||||
elapsedTime += GH.framerate().getElapsedMilliseconds() / 1000.0;
|
|
||||||
|
|
||||||
to.drawColor(pos, Colors::BLACK);
|
to.drawColor(pos, Colors::BLACK);
|
||||||
//some videos are 800x600 in size while some are 800x400
|
//some videos are 800x600 in size while some are 800x400
|
||||||
CCS->videoh->update(pos.x, pos.y + (CCS->videoh->size().y == 400 ? 100 : 0), to.getInternalSurface(), true, false);
|
CCS->videoh->update(pos.x, pos.y + (CCS->videoh->size().y == 400 ? 100 : 0), to.getInternalSurface(), true, false);
|
||||||
|
|
||||||
const double speed = (voiceDuration == 0.0) ? 0.1 : (voiceDuration / (text->textSize.y));
|
const double speed = (voiceDurationMilliseconds == 0) ? 100 : (voiceDurationMilliseconds / (text->textSize.y));
|
||||||
|
|
||||||
if(elapsedTime > speed && text->textSize.y - 50 > positionCounter)
|
if(elapsedTimeMilliseconds > speed && text->textSize.y - 50 > positionCounter)
|
||||||
{
|
{
|
||||||
text->scrollTextBy(1);
|
text->scrollTextBy(1);
|
||||||
elapsedTime = 0.0;
|
elapsedTimeMilliseconds -= speed;
|
||||||
++positionCounter;
|
++positionCounter;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
text->showAll(to); // blit text over video, if needed
|
text->showAll(to); // blit text over video, if needed
|
||||||
|
|
||||||
if(elapsedTime > (voiceDuration == 0.0 ? 6.0 : 3.0) && voiceStopped)
|
if(elapsedTime > (voiceDuration == 0.0 ? 6000 : 3000) && voiceStopped) // pause after completed scrolling (longer for intros missing voice)
|
||||||
clickPressed(GH.getCursorPosition());
|
clickPressed(GH.getCursorPosition());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,8 +19,8 @@ class CPrologEpilogVideo : public CWindowObject
|
|||||||
CampaignScenarioPrologEpilog spe;
|
CampaignScenarioPrologEpilog spe;
|
||||||
int positionCounter;
|
int positionCounter;
|
||||||
int voiceSoundHandle;
|
int voiceSoundHandle;
|
||||||
double voiceDuration;
|
uint32_t voiceDurationMilliseconds;
|
||||||
double elapsedTime;
|
uint32_t elapsedTimeMilliseconds;
|
||||||
int videoSoundHandle;
|
int videoSoundHandle;
|
||||||
std::function<void()> exitCb;
|
std::function<void()> exitCb;
|
||||||
|
|
||||||
@ -31,6 +31,7 @@ class CPrologEpilogVideo : public CWindowObject
|
|||||||
public:
|
public:
|
||||||
CPrologEpilogVideo(CampaignScenarioPrologEpilog _spe, std::function<void()> callback);
|
CPrologEpilogVideo(CampaignScenarioPrologEpilog _spe, std::function<void()> callback);
|
||||||
|
|
||||||
|
void tick(uint32_t msPassed) override;
|
||||||
void clickPressed(const Point & cursorPosition) override;
|
void clickPressed(const Point & cursorPosition) override;
|
||||||
void show(Canvas & to) override;
|
void show(Canvas & to) override;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user