mirror of
https://port.numenaute.org/aleajactaest/khanat-code-old.git
synced 2024-12-24 01:38:45 +00:00
Fixed: Sound CSheetID implementation (part 3) (partially tested)
This commit is contained in:
parent
c935b00119
commit
1ac3f3f170
7 changed files with 53 additions and 19 deletions
|
@ -49,6 +49,7 @@ void Init()
|
|||
{
|
||||
try
|
||||
{
|
||||
CSheetId::initWithoutSheet();
|
||||
|
||||
CPath::addSearchPath(NL_SOUND_DATA"/data", true, false);
|
||||
|
||||
|
|
|
@ -62,6 +62,7 @@ static void initSample()
|
|||
{
|
||||
if (!INelContext::isContextInitialised())
|
||||
new CApplicationContext();
|
||||
CSheetId::initWithoutSheet();
|
||||
CPath::addSearchPath(NL_SOUND_DATA"/data", true, false);
|
||||
|
||||
printf("Sample demonstrating OGG playback using stream file .sound sheets.");
|
||||
|
|
|
@ -59,6 +59,7 @@ static void initSample()
|
|||
{
|
||||
if (!INelContext::isContextInitialised())
|
||||
new CApplicationContext();
|
||||
CSheetId::initWithoutSheet();
|
||||
CPath::addSearchPath(NL_SOUND_DATA"/database/build/", true, false);
|
||||
|
||||
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 )
|
||||
{
|
||||
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
|
||||
*this = CSheetId(sheetName);
|
||||
}
|
||||
|
@ -131,6 +135,7 @@ bool CSheetId::buildSheetId(const std::string& sheetName)
|
|||
if (it == _DevSheetNameToId.end())
|
||||
{
|
||||
// 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 sheetName = CFile::getFilenameWithoutExtension(sheetNameLc);
|
||||
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);
|
||||
_Id.IdInfos.Type = typeId;
|
||||
_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;
|
||||
return true;
|
||||
}
|
||||
_Id.Id = it->second;
|
||||
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
|
||||
if (_Initialised)
|
||||
{
|
||||
nlassert(!_DontHaveSheetKnowledge);
|
||||
if (_DontHaveSheetKnowledge)
|
||||
nlinfo("SHEETID: CSheetId is already initialized without sheet_id.bin");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -357,8 +365,9 @@ void CSheetId::initWithoutSheet()
|
|||
_DevSheetIdToName[0].push_back("unknown");
|
||||
_DevSheetNameToId["unknown.unknown"] = 0;*/
|
||||
|
||||
CSheetId unknown = CSheetId("unknown.unknown");
|
||||
nlassert(unknown == CSheetId::Unknown);
|
||||
CSheetId unknownunknown = CSheetId("unknown.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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -274,9 +276,16 @@ void CSoundBank::load(const std::string &packedSheetDir, bool packedSheetUpdate)
|
|||
maxShortId = first->first.getShortId();
|
||||
}
|
||||
++maxShortId; // inc for size = last idx + 1
|
||||
nlassert(maxShortId < (container.size() * 8)); // ensure no ridiculous sheet id values
|
||||
if (maxShortId > _Sounds.size())
|
||||
_Sounds.resize(maxShortId);
|
||||
if (container.size() == 0)
|
||||
{
|
||||
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
|
||||
|
@ -348,9 +357,15 @@ CSound* CSoundBank::getSound(const NLMISC::CSheetId &sheetId)
|
|||
{
|
||||
if (sheetId == NLMISC::CSheetId::Unknown)
|
||||
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()];
|
||||
}
|
||||
|
||||
|
|
|
@ -86,7 +86,7 @@ void CSoundPage::setEditedItem(CWorkspaceNode *ownerNode, NL3D::CPSLocatedBindab
|
|||
_ui.pitchWidget->setWorkspaceNode(_Node);
|
||||
_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.muteCheckBox->setChecked(_Sound->getMute());
|
||||
|
@ -95,7 +95,7 @@ void CSoundPage::setEditedItem(CWorkspaceNode *ownerNode, NL3D::CPSLocatedBindab
|
|||
|
||||
void CSoundPage::browse()
|
||||
{
|
||||
std::vector<NLMISC::TStringId> names;
|
||||
std::vector<NLMISC::CSheetId> names;
|
||||
|
||||
|
||||
NLSOUND::UAudioMixer *audioMixer = Modules::sound().getAudioMixer();
|
||||
|
@ -108,7 +108,7 @@ void CSoundPage::browse()
|
|||
QStringList items;
|
||||
items << tr("");
|
||||
for(size_t i = 0; i < names.size(); ++i)
|
||||
items << QString(names[i]->c_str());
|
||||
items << QString(names[i].toString().c_str());
|
||||
|
||||
bool ok;
|
||||
QString item = QInputDialog::getItem(this, tr("Select your sound"),
|
||||
|
@ -162,7 +162,7 @@ void CSoundPage::setKeepPitch(bool state)
|
|||
|
||||
void CSoundPage::setSoundName(const QString &text)
|
||||
{
|
||||
_Sound->setSoundName(NLMISC::CStringMapper::map(text.toStdString()));
|
||||
_Sound->setSoundName(NLMISC::CSheetId(text.toStdString()));
|
||||
}
|
||||
|
||||
void CSoundPage::setEmissionPercent(float value)
|
||||
|
@ -171,4 +171,4 @@ void CSoundPage::setEmissionPercent(float value)
|
|||
updateModifiedFlag();
|
||||
}
|
||||
|
||||
} /* namespace NLQT */
|
||||
} /* namespace NLQT */
|
||||
|
|
|
@ -30,6 +30,8 @@
|
|||
#include <nel/sound/sound_animation.h>
|
||||
#include <nel/3d/u_particle_system_sound.h>
|
||||
#include <nel/misc/path.h>
|
||||
#include <nel/misc/sheet_id.h>
|
||||
|
||||
|
||||
// Qt includes
|
||||
#include <QtCore/QSettings>
|
||||
|
@ -67,6 +69,9 @@ void CSoundSystem::init()
|
|||
{
|
||||
//H_AUTO2
|
||||
nldebug("CSoundSystem::init");
|
||||
|
||||
// require sheet id without sheet id bin
|
||||
NLMISC::CSheetId::initWithoutSheet();
|
||||
|
||||
// create audiomixer
|
||||
_AudioMixer = NULL;
|
||||
|
@ -153,9 +158,10 @@ void CSoundSystem::play(const std::string &soundName)
|
|||
{
|
||||
if (_AudioMixer)
|
||||
{
|
||||
NLSOUND::USource *src = _AudioMixer->createSource(NLMISC::CStringMapper::map(soundName), true);
|
||||
NLSOUND::USource *src = _AudioMixer->createSource(NLMISC::CSheetId(soundName, "sound"), true);
|
||||
if (src)
|
||||
{
|
||||
// FIXME: Use relative positioning, and set pos to 0,0,0
|
||||
src->setLooping(false);
|
||||
const NLMISC::CVector &pos = _AudioMixer->getListener()->getPos();
|
||||
src->setPos(pos);
|
||||
|
@ -172,9 +178,10 @@ NLSOUND::USource *CSoundSystem::create(const std::string &soundName)
|
|||
{
|
||||
if (_AudioMixer)
|
||||
{
|
||||
NLSOUND::USource *src = _AudioMixer->createSource(NLMISC::CStringMapper::map(soundName), false);
|
||||
NLSOUND::USource *src = _AudioMixer->createSource(NLMISC::CSheetId(soundName, "sound"), false);
|
||||
if (src)
|
||||
{
|
||||
// FIXME: Use relative positioning, and set pos to 0,0,0
|
||||
src->setLooping(false);
|
||||
const NLMISC::CVector &pos = _AudioMixer->getListener()->getPos();
|
||||
src->setPos(pos);
|
||||
|
@ -236,4 +243,4 @@ void CSoundSystem::releaseGraphics()
|
|||
NL3D::UParticleSystemSound::setPSSound(NULL);
|
||||
}
|
||||
|
||||
} /* namespace NLQT */
|
||||
} /* namespace NLQT */
|
||||
|
|
Loading…
Reference in a new issue