mirror of
https://github.com/vcmi/vcmi.git
synced 2025-04-21 12:06:49 +02:00
code review
This commit is contained in:
parent
fa19ed4e7c
commit
994da3fcf2
@ -190,8 +190,6 @@ int CSoundHandler::playSound(const AudioPath & sound, int repeats, bool cache)
|
|||||||
initCallback(channel);
|
initCallback(channel);
|
||||||
else
|
else
|
||||||
initCallback(channel, [chunk](){ Mix_FreeChunk(chunk);});
|
initCallback(channel, [chunk](){ Mix_FreeChunk(chunk);});
|
||||||
|
|
||||||
channelPlaying[channel] = true;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
channel = -1;
|
channel = -1;
|
||||||
@ -211,11 +209,6 @@ void CSoundHandler::stopSound(int handler)
|
|||||||
Mix_HaltChannel(handler);
|
Mix_HaltChannel(handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CSoundHandler::isSoundPlaying(int handler)
|
|
||||||
{
|
|
||||||
return initialized && handler != -1 && channelPlaying[handler];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sets the sound volume, from 0 (mute) to 100
|
// Sets the sound volume, from 0 (mute) to 100
|
||||||
void CSoundHandler::setVolume(ui32 percent)
|
void CSoundHandler::setVolume(ui32 percent)
|
||||||
{
|
{
|
||||||
@ -259,8 +252,6 @@ void CSoundHandler::setCallback(int channel, std::function<void()> function)
|
|||||||
|
|
||||||
void CSoundHandler::soundFinishedCallback(int channel)
|
void CSoundHandler::soundFinishedCallback(int channel)
|
||||||
{
|
{
|
||||||
channelPlaying[channel] = false;
|
|
||||||
|
|
||||||
boost::mutex::scoped_lock lockGuard(mutexCallbacks);
|
boost::mutex::scoped_lock lockGuard(mutexCallbacks);
|
||||||
|
|
||||||
if (callbacks.count(channel) == 0)
|
if (callbacks.count(channel) == 0)
|
||||||
|
@ -60,7 +60,6 @@ private:
|
|||||||
|
|
||||||
std::map<AudioPath, int> ambientChannels;
|
std::map<AudioPath, int> ambientChannels;
|
||||||
std::map<int, int> channelVolumes;
|
std::map<int, int> channelVolumes;
|
||||||
std::map<int, bool> channelPlaying;
|
|
||||||
|
|
||||||
void initCallback(int channel, const std::function<void()> & function);
|
void initCallback(int channel, const std::function<void()> & function);
|
||||||
void initCallback(int channel);
|
void initCallback(int channel);
|
||||||
@ -79,7 +78,6 @@ public:
|
|||||||
int playSound(const AudioPath & sound, int repeats=0, bool cache=false);
|
int playSound(const AudioPath & sound, int repeats=0, bool cache=false);
|
||||||
int playSoundFromSet(std::vector<soundBase::soundID> &sound_vec);
|
int playSoundFromSet(std::vector<soundBase::soundID> &sound_vec);
|
||||||
void stopSound(int handler);
|
void stopSound(int handler);
|
||||||
bool isSoundPlaying(int handler);
|
|
||||||
|
|
||||||
void setCallback(int channel, std::function<void()> function);
|
void setCallback(int channel, std::function<void()> function);
|
||||||
void soundFinishedCallback(int channel);
|
void soundFinishedCallback(int channel);
|
||||||
|
@ -30,6 +30,11 @@ CPrologEpilogVideo::CPrologEpilogVideo(CampaignScenarioPrologEpilog _spe, std::f
|
|||||||
CCS->videoh->open(spe.prologVideo);
|
CCS->videoh->open(spe.prologVideo);
|
||||||
CCS->musich->playMusic(spe.prologMusic, true, true);
|
CCS->musich->playMusic(spe.prologMusic, true, true);
|
||||||
voiceSoundHandle = CCS->soundh->playSound(spe.prologVoice);
|
voiceSoundHandle = CCS->soundh->playSound(spe.prologVoice);
|
||||||
|
auto onVoiceStop = [this]()
|
||||||
|
{
|
||||||
|
voiceStopped = true;
|
||||||
|
};
|
||||||
|
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);
|
text = std::make_shared<CMultiLineLabel>(Rect(100, 500, 600, 100), EFonts::FONT_BIG, ETextAlignment::CENTER, Colors::METALLIC_GOLD, spe.prologText);
|
||||||
text->scrollTextTo(-100);
|
text->scrollTextTo(-100);
|
||||||
@ -50,7 +55,7 @@ void CPrologEpilogVideo::show(Canvas & to)
|
|||||||
else
|
else
|
||||||
text->showAll(to); // blit text over video, if needed
|
text->showAll(to); // blit text over video, if needed
|
||||||
|
|
||||||
if(text->textSize.y + 100 < positionCounter / 5 && !CCS->soundh->isSoundPlaying(voiceSoundHandle))
|
if(text->textSize.y + 100 < positionCounter / 5 && voiceStopped)
|
||||||
clickPressed(GH.getCursorPosition());
|
clickPressed(GH.getCursorPosition());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,6 +23,8 @@ class CPrologEpilogVideo : public CWindowObject
|
|||||||
|
|
||||||
std::shared_ptr<CMultiLineLabel> text;
|
std::shared_ptr<CMultiLineLabel> text;
|
||||||
|
|
||||||
|
bool voiceStopped = false;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CPrologEpilogVideo(CampaignScenarioPrologEpilog _spe, std::function<void()> callback);
|
CPrologEpilogVideo(CampaignScenarioPrologEpilog _spe, std::function<void()> callback);
|
||||||
|
|
||||||
|
@ -404,8 +404,7 @@ CampaignScenario CampaignHandler::readScenarioFromMemory( CBinaryReader & reader
|
|||||||
ret.hasPrologEpilog = reader.readUInt8();
|
ret.hasPrologEpilog = reader.readUInt8();
|
||||||
if(ret.hasPrologEpilog)
|
if(ret.hasPrologEpilog)
|
||||||
{
|
{
|
||||||
std::string originalCampaigns[] = { "DATA/GOOD1", "DATA/EVIL1", "DATA/GOOD2", "DATA/NEUTRAL1", "DATA/EVIL2", "DATA/GOOD3", "DATA/SECRET1", "DATA/AB", "DATA/BLOOD", "DATA/SLAYER", "DATA/FESTIVAL", "DATA/FIRE", "DATA/FOOL", "DATA/GEM", "DATA/GELU", "DATA/CRAG", "DATA/SANDRO", "DATA/YOG", "DATA/FINAL", "DATA/SECRET" };
|
bool isOriginalCampaign = boost::starts_with(header.getFilename(), "DATA/");
|
||||||
bool isOriginalCampaign = std::find(std::begin(originalCampaigns), std::end(originalCampaigns), header.getFilename()) != std::end(originalCampaigns);
|
|
||||||
|
|
||||||
ui8 index = reader.readUInt8();
|
ui8 index = reader.readUInt8();
|
||||||
ret.prologVideo = CampaignHandler::prologVideoName(index);
|
ret.prologVideo = CampaignHandler::prologVideoName(index);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user