mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-11-10 01:09:50 +00:00
Fixed: Sound CSheetID implementation (part 3) (partially tested)
--HG-- branch : sound_dev
This commit is contained in:
parent
9cd7498fe9
commit
f79f3fca48
7 changed files with 53 additions and 19 deletions
|
@ -49,6 +49,7 @@ void Init()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
CSheetId::initWithoutSheet();
|
||||||
|
|
||||||
CPath::addSearchPath(NL_SOUND_DATA"/data", true, false);
|
CPath::addSearchPath(NL_SOUND_DATA"/data", true, false);
|
||||||
|
|
||||||
|
|
|
@ -62,6 +62,7 @@ static void initSample()
|
||||||
{
|
{
|
||||||
if (!INelContext::isContextInitialised())
|
if (!INelContext::isContextInitialised())
|
||||||
new CApplicationContext();
|
new CApplicationContext();
|
||||||
|
CSheetId::initWithoutSheet();
|
||||||
CPath::addSearchPath(NL_SOUND_DATA"/data", true, false);
|
CPath::addSearchPath(NL_SOUND_DATA"/data", true, false);
|
||||||
|
|
||||||
printf("Sample demonstrating OGG playback using stream file .sound sheets.");
|
printf("Sample demonstrating OGG playback using stream file .sound sheets.");
|
||||||
|
|
|
@ -59,6 +59,7 @@ static void initSample()
|
||||||
{
|
{
|
||||||
if (!INelContext::isContextInitialised())
|
if (!INelContext::isContextInitialised())
|
||||||
new CApplicationContext();
|
new CApplicationContext();
|
||||||
|
CSheetId::initWithoutSheet();
|
||||||
CPath::addSearchPath(NL_SOUND_DATA"/database/build/", true, false);
|
CPath::addSearchPath(NL_SOUND_DATA"/database/build/", true, false);
|
||||||
|
|
||||||
printf("Sample demonstrating OGG playback using UStreamSource.");
|
printf("Sample demonstrating OGG playback using UStreamSource.");
|
||||||
|
|
|
@ -109,7 +109,11 @@ CSheetId::CSheetId( const string& sheetName )
|
||||||
CSheetId::CSheetId( const std::string& sheetName, const std::string &defaultType )
|
CSheetId::CSheetId( const std::string& sheetName, const std::string &defaultType )
|
||||||
{
|
{
|
||||||
if (CFile::getExtension(sheetName) == "" && defaultType != "")
|
if (CFile::getExtension(sheetName) == "" && defaultType != "")
|
||||||
*this = CSheetId(sheetName + "." + defaultType);
|
{
|
||||||
|
std::string withType = sheetName + "." + defaultType;
|
||||||
|
*this = CSheetId(withType);
|
||||||
|
nldebug("SHEETID: Constructing CSheetId from name '%s' without explicit type, defaulting as '%s' to '%s'", sheetName.c_str(), defaultType.c_str(), withType.c_str());
|
||||||
|
}
|
||||||
else
|
else
|
||||||
*this = CSheetId(sheetName);
|
*this = CSheetId(sheetName);
|
||||||
}
|
}
|
||||||
|
@ -131,6 +135,7 @@ bool CSheetId::buildSheetId(const std::string& sheetName)
|
||||||
if (it == _DevSheetNameToId.end())
|
if (it == _DevSheetNameToId.end())
|
||||||
{
|
{
|
||||||
// Create a new dynamic sheet ID.
|
// Create a new dynamic sheet ID.
|
||||||
|
nldebug("SHEETID: Creating a new dynamic sheet id for '%s'", sheetName.c_str());
|
||||||
std::string sheetType = CFile::getExtension(sheetNameLc);
|
std::string sheetType = CFile::getExtension(sheetNameLc);
|
||||||
std::string sheetName = CFile::getFilenameWithoutExtension(sheetNameLc);
|
std::string sheetName = CFile::getFilenameWithoutExtension(sheetNameLc);
|
||||||
std::map<std::string, uint32>::iterator tit = _DevTypeNameToId.find(sheetType);
|
std::map<std::string, uint32>::iterator tit = _DevTypeNameToId.find(sheetType);
|
||||||
|
@ -149,7 +154,9 @@ bool CSheetId::buildSheetId(const std::string& sheetName)
|
||||||
_DevSheetIdToName[typeId].push_back(sheetName);
|
_DevSheetIdToName[typeId].push_back(sheetName);
|
||||||
_Id.IdInfos.Type = typeId;
|
_Id.IdInfos.Type = typeId;
|
||||||
_Id.IdInfos.Id = _DevSheetIdToName[typeId].size() - 1;
|
_Id.IdInfos.Id = _DevSheetIdToName[typeId].size() - 1;
|
||||||
|
// nldebug("SHEETID: Type %i, id %i, sheetid %i", _Id.IdInfos.Type, _Id.IdInfos.Id, _Id.Id);
|
||||||
_DevSheetNameToId[sheetNameLc] = _Id.Id;
|
_DevSheetNameToId[sheetNameLc] = _Id.Id;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
_Id.Id = it->second;
|
_Id.Id = it->second;
|
||||||
return true;
|
return true;
|
||||||
|
@ -326,7 +333,8 @@ void CSheetId::init(bool removeUnknownSheet)
|
||||||
// allow multiple calls to init in case libraries depending on sheetid call this init from their own
|
// allow multiple calls to init in case libraries depending on sheetid call this init from their own
|
||||||
if (_Initialised)
|
if (_Initialised)
|
||||||
{
|
{
|
||||||
nlassert(!_DontHaveSheetKnowledge);
|
if (_DontHaveSheetKnowledge)
|
||||||
|
nlinfo("SHEETID: CSheetId is already initialized without sheet_id.bin");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -357,8 +365,9 @@ void CSheetId::initWithoutSheet()
|
||||||
_DevSheetIdToName[0].push_back("unknown");
|
_DevSheetIdToName[0].push_back("unknown");
|
||||||
_DevSheetNameToId["unknown.unknown"] = 0;*/
|
_DevSheetNameToId["unknown.unknown"] = 0;*/
|
||||||
|
|
||||||
CSheetId unknown = CSheetId("unknown.unknown");
|
CSheetId unknownunknown = CSheetId("unknown.unknown");
|
||||||
nlassert(unknown == CSheetId::Unknown);
|
// nldebug("SHEETID: unknown: %i, Unknown: %i", unknownunknown._Id, Unknown._Id);
|
||||||
|
nlassert(unknownunknown == CSheetId::Unknown);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -123,7 +123,9 @@ CSoundBank::~CSoundBank()
|
||||||
|
|
||||||
void CSoundBank::addSound(CSound *sound)
|
void CSoundBank::addSound(CSound *sound)
|
||||||
{
|
{
|
||||||
nlassert(_Sounds.size() > sound->getName().getShortId());
|
// nlassert(_Sounds.size() > sound->getName().getShortId());
|
||||||
|
if (_Sounds.size() <= sound->getName().getShortId())
|
||||||
|
_Sounds.resize(sound->getName().getShortId() + 1);
|
||||||
_Sounds[sound->getName().getShortId()] = sound;
|
_Sounds[sound->getName().getShortId()] = sound;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -274,9 +276,16 @@ void CSoundBank::load(const std::string &packedSheetDir, bool packedSheetUpdate)
|
||||||
maxShortId = first->first.getShortId();
|
maxShortId = first->first.getShortId();
|
||||||
}
|
}
|
||||||
++maxShortId; // inc for size = last idx + 1
|
++maxShortId; // inc for size = last idx + 1
|
||||||
nlassert(maxShortId < (container.size() * 8)); // ensure no ridiculous sheet id values
|
if (container.size() == 0)
|
||||||
if (maxShortId > _Sounds.size())
|
{
|
||||||
_Sounds.resize(maxShortId);
|
nlwarning("NLSOUND: No sound sheets have been loaded, missing sound sheet directory or packed sound sheets file");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
nlassert(maxShortId < (container.size() * 8)); // ensure no ridiculous sheet id values
|
||||||
|
if (maxShortId > _Sounds.size())
|
||||||
|
_Sounds.resize(maxShortId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// add all the loaded sound in the sound banks
|
// add all the loaded sound in the sound banks
|
||||||
|
@ -348,9 +357,15 @@ CSound* CSoundBank::getSound(const NLMISC::CSheetId &sheetId)
|
||||||
{
|
{
|
||||||
if (sheetId == NLMISC::CSheetId::Unknown)
|
if (sheetId == NLMISC::CSheetId::Unknown)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
nlassert(sheetId.getShortId() < _Sounds.size());
|
// nlassert(sheetId.getShortId() < _Sounds.size());
|
||||||
|
if (sheetId.getShortId() >= _Sounds.size())
|
||||||
|
{
|
||||||
|
std::string sheetName = sheetId.toString();
|
||||||
|
nlwarning("NLSOUND: Sound sheet id '%s' exceeds loaded sound sheets", sheetName.c_str());
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
return _Sounds[sheetId.getShortId()];
|
return _Sounds[sheetId.getShortId()];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -86,7 +86,7 @@ void CSoundPage::setEditedItem(CWorkspaceNode *ownerNode, NL3D::CPSLocatedBindab
|
||||||
_ui.pitchWidget->setWorkspaceNode(_Node);
|
_ui.pitchWidget->setWorkspaceNode(_Node);
|
||||||
_ui.pitchWidget->updateUi();
|
_ui.pitchWidget->updateUi();
|
||||||
|
|
||||||
_ui.soundNameLineEdit->setText(QString(NLMISC::CStringMapper::unmap(_Sound->getSoundName()).c_str()));
|
_ui.soundNameLineEdit->setText(QString(_Sound->getSoundName().toString().c_str()));
|
||||||
|
|
||||||
_ui.spawnCheckBox->setChecked(_Sound->getSpawn());
|
_ui.spawnCheckBox->setChecked(_Sound->getSpawn());
|
||||||
_ui.muteCheckBox->setChecked(_Sound->getMute());
|
_ui.muteCheckBox->setChecked(_Sound->getMute());
|
||||||
|
@ -95,7 +95,7 @@ void CSoundPage::setEditedItem(CWorkspaceNode *ownerNode, NL3D::CPSLocatedBindab
|
||||||
|
|
||||||
void CSoundPage::browse()
|
void CSoundPage::browse()
|
||||||
{
|
{
|
||||||
std::vector<NLMISC::TStringId> names;
|
std::vector<NLMISC::CSheetId> names;
|
||||||
|
|
||||||
|
|
||||||
NLSOUND::UAudioMixer *audioMixer = Modules::sound().getAudioMixer();
|
NLSOUND::UAudioMixer *audioMixer = Modules::sound().getAudioMixer();
|
||||||
|
@ -108,7 +108,7 @@ void CSoundPage::browse()
|
||||||
QStringList items;
|
QStringList items;
|
||||||
items << tr("");
|
items << tr("");
|
||||||
for(size_t i = 0; i < names.size(); ++i)
|
for(size_t i = 0; i < names.size(); ++i)
|
||||||
items << QString(names[i]->c_str());
|
items << QString(names[i].toString().c_str());
|
||||||
|
|
||||||
bool ok;
|
bool ok;
|
||||||
QString item = QInputDialog::getItem(this, tr("Select your sound"),
|
QString item = QInputDialog::getItem(this, tr("Select your sound"),
|
||||||
|
@ -162,7 +162,7 @@ void CSoundPage::setKeepPitch(bool state)
|
||||||
|
|
||||||
void CSoundPage::setSoundName(const QString &text)
|
void CSoundPage::setSoundName(const QString &text)
|
||||||
{
|
{
|
||||||
_Sound->setSoundName(NLMISC::CStringMapper::map(text.toStdString()));
|
_Sound->setSoundName(NLMISC::CSheetId(text.toStdString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSoundPage::setEmissionPercent(float value)
|
void CSoundPage::setEmissionPercent(float value)
|
||||||
|
@ -171,4 +171,4 @@ void CSoundPage::setEmissionPercent(float value)
|
||||||
updateModifiedFlag();
|
updateModifiedFlag();
|
||||||
}
|
}
|
||||||
|
|
||||||
} /* namespace NLQT */
|
} /* namespace NLQT */
|
||||||
|
|
|
@ -30,6 +30,8 @@
|
||||||
#include <nel/sound/sound_animation.h>
|
#include <nel/sound/sound_animation.h>
|
||||||
#include <nel/3d/u_particle_system_sound.h>
|
#include <nel/3d/u_particle_system_sound.h>
|
||||||
#include <nel/misc/path.h>
|
#include <nel/misc/path.h>
|
||||||
|
#include <nel/misc/sheet_id.h>
|
||||||
|
|
||||||
|
|
||||||
// Qt includes
|
// Qt includes
|
||||||
#include <QtCore/QSettings>
|
#include <QtCore/QSettings>
|
||||||
|
@ -67,6 +69,9 @@ void CSoundSystem::init()
|
||||||
{
|
{
|
||||||
//H_AUTO2
|
//H_AUTO2
|
||||||
nldebug("CSoundSystem::init");
|
nldebug("CSoundSystem::init");
|
||||||
|
|
||||||
|
// require sheet id without sheet id bin
|
||||||
|
NLMISC::CSheetId::initWithoutSheet();
|
||||||
|
|
||||||
// create audiomixer
|
// create audiomixer
|
||||||
_AudioMixer = NULL;
|
_AudioMixer = NULL;
|
||||||
|
@ -153,9 +158,10 @@ void CSoundSystem::play(const std::string &soundName)
|
||||||
{
|
{
|
||||||
if (_AudioMixer)
|
if (_AudioMixer)
|
||||||
{
|
{
|
||||||
NLSOUND::USource *src = _AudioMixer->createSource(NLMISC::CStringMapper::map(soundName), true);
|
NLSOUND::USource *src = _AudioMixer->createSource(NLMISC::CSheetId(soundName, "sound"), true);
|
||||||
if (src)
|
if (src)
|
||||||
{
|
{
|
||||||
|
// FIXME: Use relative positioning, and set pos to 0,0,0
|
||||||
src->setLooping(false);
|
src->setLooping(false);
|
||||||
const NLMISC::CVector &pos = _AudioMixer->getListener()->getPos();
|
const NLMISC::CVector &pos = _AudioMixer->getListener()->getPos();
|
||||||
src->setPos(pos);
|
src->setPos(pos);
|
||||||
|
@ -172,9 +178,10 @@ NLSOUND::USource *CSoundSystem::create(const std::string &soundName)
|
||||||
{
|
{
|
||||||
if (_AudioMixer)
|
if (_AudioMixer)
|
||||||
{
|
{
|
||||||
NLSOUND::USource *src = _AudioMixer->createSource(NLMISC::CStringMapper::map(soundName), false);
|
NLSOUND::USource *src = _AudioMixer->createSource(NLMISC::CSheetId(soundName, "sound"), false);
|
||||||
if (src)
|
if (src)
|
||||||
{
|
{
|
||||||
|
// FIXME: Use relative positioning, and set pos to 0,0,0
|
||||||
src->setLooping(false);
|
src->setLooping(false);
|
||||||
const NLMISC::CVector &pos = _AudioMixer->getListener()->getPos();
|
const NLMISC::CVector &pos = _AudioMixer->getListener()->getPos();
|
||||||
src->setPos(pos);
|
src->setPos(pos);
|
||||||
|
@ -236,4 +243,4 @@ void CSoundSystem::releaseGraphics()
|
||||||
NL3D::UParticleSystemSound::setPSSound(NULL);
|
NL3D::UParticleSystemSound::setPSSound(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
} /* namespace NLQT */
|
} /* namespace NLQT */
|
||||||
|
|
Loading…
Reference in a new issue