parent
69e52e5f24
commit
ebffda717b
|
@ -3478,6 +3478,8 @@ bool CRobotMain::EventFrame(const Event &event)
|
||||||
CheckEndMission(true);
|
CheckEndMission(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UpdateAudio(true);
|
||||||
|
|
||||||
if (m_winDelay > 0.0f && !m_editLock)
|
if (m_winDelay > 0.0f && !m_editLock)
|
||||||
{
|
{
|
||||||
m_winDelay -= event.rTime;
|
m_winDelay -= event.rTime;
|
||||||
|
@ -3824,6 +3826,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
|
||||||
m_lockedSatCom = false;
|
m_lockedSatCom = false;
|
||||||
m_endingWinRank = 0;
|
m_endingWinRank = 0;
|
||||||
m_endingLostRank = 0;
|
m_endingLostRank = 0;
|
||||||
|
m_audioChangeTotal = 0;
|
||||||
m_endTakeTotal = 0;
|
m_endTakeTotal = 0;
|
||||||
m_endTakeResearch = 0;
|
m_endTakeResearch = 0;
|
||||||
m_endTakeWinDelay = 2.0f;
|
m_endTakeWinDelay = 2.0f;
|
||||||
|
@ -3983,6 +3986,24 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
|
||||||
m_audioRepeat = OpInt(line, "repeat", 1);
|
m_audioRepeat = OpInt(line, "repeat", 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Cmd(line, "AudioChange") && !resetObject && m_version >= 2)
|
||||||
|
{
|
||||||
|
int i = m_audioChangeTotal;
|
||||||
|
if (i < 10)
|
||||||
|
{
|
||||||
|
m_audioChange[i].pos = OpPos(line, "pos")*g_unit;
|
||||||
|
m_audioChange[i].dist = OpFloat(line, "dist", 8.0f)*g_unit;
|
||||||
|
m_audioChange[i].type = OpTypeObject(line, "type", OBJECT_NULL);
|
||||||
|
m_audioChange[i].min = OpInt(line, "min", 1);
|
||||||
|
m_audioChange[i].max = OpInt(line, "max", 9999);
|
||||||
|
OpString(line, "filename", m_audioChange[i].music);
|
||||||
|
m_audioChange[i].repeat = OpInt(line, "repeat", 1);
|
||||||
|
m_audioChange[i].changed = false;
|
||||||
|
m_audioChangeTotal ++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (Cmd(line, "AmbientColor") && !resetObject)
|
if (Cmd(line, "AmbientColor") && !resetObject)
|
||||||
{
|
{
|
||||||
m_engine->SetAmbientColor(OpColor(line, "air", Gfx::Color(0.533f, 0.533f, 0.533f, 0.533f)), 0);
|
m_engine->SetAmbientColor(OpColor(line, "air", Gfx::Color(0.533f, 0.533f, 0.533f, 0.533f)), 0);
|
||||||
|
@ -6567,6 +6588,64 @@ void CRobotMain::ResetCreate()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! Updates the audiotracks
|
||||||
|
void CRobotMain::UpdateAudio(bool frame)
|
||||||
|
{
|
||||||
|
CInstanceManager* iMan = CInstanceManager::GetInstancePointer();
|
||||||
|
|
||||||
|
for (int t = 0; t < m_audioChangeTotal; t++)
|
||||||
|
{
|
||||||
|
Math::Vector bPos = m_audioChange[t].pos;
|
||||||
|
bPos.y = 0.0f;
|
||||||
|
|
||||||
|
Math::Vector oPos;
|
||||||
|
|
||||||
|
int nb = 0;
|
||||||
|
for (int i = 0; i < 1000000; i++)
|
||||||
|
{
|
||||||
|
CObject* obj = static_cast<CObject*>(iMan->SearchInstance(CLASS_OBJECT, i));
|
||||||
|
if (obj == nullptr) break;
|
||||||
|
|
||||||
|
// Do not use GetActif () because an invisible worm (underground)
|
||||||
|
// should be regarded as existing here!
|
||||||
|
if (obj->GetLock()) continue;
|
||||||
|
if (obj->GetRuin()) continue;
|
||||||
|
if (!obj->GetEnable()) continue;
|
||||||
|
|
||||||
|
ObjectType type = obj->GetType();
|
||||||
|
if (type == OBJECT_SCRAP2 ||
|
||||||
|
type == OBJECT_SCRAP3 ||
|
||||||
|
type == OBJECT_SCRAP4 ||
|
||||||
|
type == OBJECT_SCRAP5) // wastes?
|
||||||
|
{
|
||||||
|
type = OBJECT_SCRAP1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type != m_audioChange[t].type) continue;
|
||||||
|
|
||||||
|
if (obj->GetTruck() == 0)
|
||||||
|
oPos = obj->GetPosition(0);
|
||||||
|
else
|
||||||
|
oPos = obj->GetTruck()->GetPosition(0);
|
||||||
|
|
||||||
|
oPos.y = 0.0f;
|
||||||
|
|
||||||
|
if (Math::DistanceProjected(oPos, bPos) <= m_audioChange[t].dist)
|
||||||
|
nb ++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nb >= m_audioChange[t].min &&
|
||||||
|
nb <= m_audioChange[t].max &&
|
||||||
|
!m_audioChange[t].changed)
|
||||||
|
{
|
||||||
|
CLogger::GetInstancePointer()->Debug("Changing music...\n");
|
||||||
|
m_sound->StopMusic();
|
||||||
|
m_sound->PlayMusic(std::string(m_audioChange[t].music), m_audioChange[t].repeat);
|
||||||
|
m_audioChange[t].changed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//! Checks if the mission is over
|
//! Checks if the mission is over
|
||||||
Error CRobotMain::CheckEndMission(bool frame)
|
Error CRobotMain::CheckEndMission(bool frame)
|
||||||
{
|
{
|
||||||
|
@ -7067,6 +7146,7 @@ float CRobotMain::GetTracePrecision()
|
||||||
//! Starts music with a mission
|
//! Starts music with a mission
|
||||||
void CRobotMain::StartMusic()
|
void CRobotMain::StartMusic()
|
||||||
{
|
{
|
||||||
|
CLogger::GetInstancePointer()->Debug("Starting music...\n");
|
||||||
if (m_audioTrack != 0)
|
if (m_audioTrack != 0)
|
||||||
{
|
{
|
||||||
m_sound->StopMusic();
|
m_sound->StopMusic();
|
||||||
|
|
|
@ -106,6 +106,18 @@ struct EndTake
|
||||||
char message[100];
|
char message[100];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct AudioChange
|
||||||
|
{
|
||||||
|
Math::Vector pos;
|
||||||
|
float dist;
|
||||||
|
ObjectType type;
|
||||||
|
int min; // change if >
|
||||||
|
int max; // change if <
|
||||||
|
char music[100];
|
||||||
|
bool repeat;
|
||||||
|
bool changed;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
const int MAXNEWSCRIPTNAME = 20;
|
const int MAXNEWSCRIPTNAME = 20;
|
||||||
|
|
||||||
|
@ -248,6 +260,7 @@ public:
|
||||||
|
|
||||||
void ResetObject();
|
void ResetObject();
|
||||||
void ResetCreate();
|
void ResetCreate();
|
||||||
|
void UpdateAudio(bool frame);
|
||||||
Error CheckEndMission(bool frame);
|
Error CheckEndMission(bool frame);
|
||||||
void CheckEndMessage(const char* message);
|
void CheckEndMessage(const char* message);
|
||||||
int GetObligatoryToken();
|
int GetObligatoryToken();
|
||||||
|
@ -523,6 +536,9 @@ protected:
|
||||||
float m_endTakeWinDelay;
|
float m_endTakeWinDelay;
|
||||||
float m_endTakeLostDelay;
|
float m_endTakeLostDelay;
|
||||||
|
|
||||||
|
int m_audioChangeTotal;
|
||||||
|
AudioChange m_audioChange[10];
|
||||||
|
|
||||||
int m_obligatoryTotal;
|
int m_obligatoryTotal;
|
||||||
char m_obligatoryToken[100][20];
|
char m_obligatoryToken[100][20];
|
||||||
int m_prohibitedTotal;
|
int m_prohibitedTotal;
|
||||||
|
|
|
@ -539,44 +539,32 @@ void ALSound::SetListener(Math::Vector eye, Math::Vector lookat)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool ALSound::PlayMusic(int rank, bool bRepeat)
|
bool ALSound::PlayMusic(int rank, bool bRepeat)
|
||||||
|
{
|
||||||
|
std::stringstream filename;
|
||||||
|
filename << "music" << std::setfill('0') << std::setw(3) << rank << ".ogg";
|
||||||
|
return PlayMusic(filename.str(), bRepeat);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ALSound::PlayMusic(std::string filename, bool bRepeat)
|
||||||
{
|
{
|
||||||
if (!mEnabled) {
|
if (!mEnabled) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (static_cast<int>(mCurrentMusic->GetSoundType()) != rank) {
|
std::stringstream file;
|
||||||
// check if we have music in cache
|
file << m_soundPath << "/" << filename;
|
||||||
for (auto music : mMusicCache) {
|
|
||||||
if (static_cast<int>(music->GetSoundType()) == rank) {
|
|
||||||
GetLogger()->Debug("Music loaded from cache\n");
|
|
||||||
mCurrentMusic->SetBuffer(music);
|
|
||||||
|
|
||||||
mCurrentMusic->SetVolume(mMusicVolume);
|
if (!boost::filesystem::exists(file.str())) {
|
||||||
mCurrentMusic->SetLoop(bRepeat);
|
GetLogger()->Warn("Requested music %s was not found.\n", filename.c_str());
|
||||||
mCurrentMusic->Play();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// we cache only 3 music files
|
|
||||||
if (mMusicCache.size() == 3) {
|
|
||||||
mCurrentMusic->FreeBuffer();
|
|
||||||
mMusicCache.pop_back();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mMusic.find(rank) == mMusic.end()) {
|
|
||||||
GetLogger()->Info("Requested music %d was not found.\n", rank);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Cache
|
||||||
|
|
||||||
Buffer *buffer = new Buffer();
|
Buffer *buffer = new Buffer();
|
||||||
mMusicCache.push_front(buffer);
|
buffer->LoadFromFile(file.str(), static_cast<Sound>(-1));
|
||||||
buffer->LoadFromFile(mMusic.at(rank), static_cast<Sound>(rank));
|
|
||||||
mCurrentMusic->SetBuffer(buffer);
|
mCurrentMusic->SetBuffer(buffer);
|
||||||
mMusicCache[rank] = buffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
mCurrentMusic->SetVolume(mMusicVolume);
|
mCurrentMusic->SetVolume(mMusicVolume);
|
||||||
mCurrentMusic->SetLoop(bRepeat);
|
mCurrentMusic->SetLoop(bRepeat);
|
||||||
|
|
|
@ -66,6 +66,7 @@ class ALSound : public CSoundInterface
|
||||||
bool MuteAll(bool bMute);
|
bool MuteAll(bool bMute);
|
||||||
|
|
||||||
bool PlayMusic(int rank, bool bRepeat);
|
bool PlayMusic(int rank, bool bRepeat);
|
||||||
|
bool PlayMusic(std::string filename, bool bRepeat);
|
||||||
bool RestartMusic();
|
bool RestartMusic();
|
||||||
void SuspendMusic();
|
void SuspendMusic();
|
||||||
void StopMusic();
|
void StopMusic();
|
||||||
|
@ -91,7 +92,6 @@ class ALSound : public CSoundInterface
|
||||||
ALCcontext* mContext;
|
ALCcontext* mContext;
|
||||||
std::map<Sound, Buffer*> mSounds;
|
std::map<Sound, Buffer*> mSounds;
|
||||||
std::map<int, Channel*> mChannels;
|
std::map<int, Channel*> mChannels;
|
||||||
std::deque<Buffer*> mMusicCache;
|
|
||||||
Channel *mCurrentMusic;
|
Channel *mCurrentMusic;
|
||||||
Math::Vector mEye;
|
Math::Vector mEye;
|
||||||
Math::Vector mLookat;
|
Math::Vector mLookat;
|
||||||
|
|
|
@ -177,12 +177,7 @@ class CSoundInterface
|
||||||
|
|
||||||
/** Function called to add all music files to list */
|
/** Function called to add all music files to list */
|
||||||
inline void AddMusicFiles(std::string path) {
|
inline void AddMusicFiles(std::string path) {
|
||||||
for ( int i = 1; i <= 12; i++ ) {
|
m_soundPath = path;
|
||||||
std::stringstream filename;
|
|
||||||
filename << path << "/music" << std::setfill('0') << std::setw(3) << i << ".ogg";
|
|
||||||
if (boost::filesystem::exists(filename.str()))
|
|
||||||
mMusic[i] = filename.str();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Function called to cache sound effect file.
|
/** Function called to cache sound effect file.
|
||||||
|
@ -317,6 +312,13 @@ class CSoundInterface
|
||||||
*/
|
*/
|
||||||
inline virtual bool PlayMusic(int rank, bool bRepeat) {return true;};
|
inline virtual bool PlayMusic(int rank, bool bRepeat) {return true;};
|
||||||
|
|
||||||
|
/** Start playing music
|
||||||
|
* \param filename - name of file to play
|
||||||
|
* \param bRepeat - repeat playing
|
||||||
|
* \return return true on success
|
||||||
|
*/
|
||||||
|
inline virtual bool PlayMusic(std::string filename, bool bRepeat) {return true;};
|
||||||
|
|
||||||
/** Restart music
|
/** Restart music
|
||||||
* @return return true on success
|
* @return return true on success
|
||||||
*/
|
*/
|
||||||
|
@ -338,6 +340,6 @@ class CSoundInterface
|
||||||
inline virtual bool IsPlayingMusic() {return true;};
|
inline virtual bool IsPlayingMusic() {return true;};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::map<int, std::string> mMusic;
|
std::string m_soundPath;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue