diff --git a/proj/sxgame/vs2013/sxgame.vcxproj b/proj/sxgame/vs2013/sxgame.vcxproj index 68c8350f5c9ecd251f00065532e92a422c0bcefa..a867ed7d5d6d21a2bac09eec943028b698ef42e8 100644 --- a/proj/sxgame/vs2013/sxgame.vcxproj +++ b/proj/sxgame/vs2013/sxgame.vcxproj @@ -230,6 +230,7 @@ <ClCompile Include="..\..\..\source\game\BaseTool.cpp" /> <ClCompile Include="..\..\..\source\game\BaseWeapon.cpp" /> <ClCompile Include="..\..\..\source\game\SettingsWriter.cpp" /> + <ClCompile Include="..\..\..\source\game\SoundPlayer.cpp" /> <ClCompile Include="..\..\..\source\game\sxgame_dll.cpp" /> <ClCompile Include="..\..\..\source\game\Player.cpp" /> <ClCompile Include="..\..\..\source\game\PlayerSpawn.cpp" /> @@ -296,6 +297,7 @@ <ClInclude Include="..\..\..\source\game\BaseTool.h" /> <ClInclude Include="..\..\..\source\game\BaseWeapon.h" /> <ClInclude Include="..\..\..\source\game\SettingsWriter.h" /> + <ClInclude Include="..\..\..\source\game\SoundPlayer.h" /> <ClInclude Include="..\..\..\source\game\sxgame.h" /> <ClInclude Include="..\..\..\source\game\Player.h" /> <ClInclude Include="..\..\..\source\game\PlayerSpawn.h" /> diff --git a/proj/sxgame/vs2013/sxgame.vcxproj.filters b/proj/sxgame/vs2013/sxgame.vcxproj.filters index 14e94410a9924cfda60a057cba1fc8cae9f108fa..71f76362f986dc8aadad08bdd70e8444ce6fbbf2 100644 --- a/proj/sxgame/vs2013/sxgame.vcxproj.filters +++ b/proj/sxgame/vs2013/sxgame.vcxproj.filters @@ -267,6 +267,9 @@ <ClCompile Include="..\..\..\source\game\FuncTrain.cpp"> <Filter>Source Files\ents\func</Filter> </ClCompile> + <ClCompile Include="..\..\..\source\game\SoundPlayer.cpp"> + <Filter>Header Files\ents</Filter> + </ClCompile> </ItemGroup> <ItemGroup> <ClInclude Include="..\..\..\source\game\sxgame.h"> @@ -464,5 +467,8 @@ <ClInclude Include="..\..\..\source\game\FuncTrain.h"> <Filter>Header Files\ents\func</Filter> </ClInclude> + <ClInclude Include="..\..\..\source\game\SoundPlayer.h"> + <Filter>Header Files\ents</Filter> + </ClInclude> </ItemGroup> </Project> \ No newline at end of file diff --git a/source/core/ResourceManager.cpp b/source/core/ResourceManager.cpp index 8c2dbfb016ebcb8ea6496a6842d8b20809df669b..8a07980a2eba96de5df742df5e0b379edb79100b 100644 --- a/source/core/ResourceManager.cpp +++ b/source/core/ResourceManager.cpp @@ -11,6 +11,7 @@ #include <xcommon/resource/IXModelProvider.h> #include <xcommon/resource/IXResourceManager.h> #include <xcommon/resource/IXResourceModel.h> +#include <xcommon/IXAudioCodec.h> #endif @@ -65,6 +66,28 @@ CResourceManager::CResourceManager(IXCore *pCore): } } } + + { + IXAudioCodec *pAudioCodec; + UINT ic = 0; + while ((pAudioCodec = (IXAudioCodec*)pPluginManager->getInterface(IXAUDIOCODEC_GUID, ic++))) + { + if (pAudioCodec->getVersion() == IXAUDIOCODEC_VERSION) + { + //LibReport(REPORT_MSG_LEVEL_NOTICE, "Registered sound loader:\n %s\n By %s\n %s\n", pAudioCodec->getDescription(), pAudioCodec->getAuthor(), pAudioCodec->getCopyright()); + + for (UINT i = 0, l = pAudioCodec->getExtCount(); i < l; ++i) + { + AAString sExt; + sExt.setName(pAudioCodec->getExt(i)); + strlwr(const_cast<char*>(sExt.getName())); + m_aSoundExts.push_back({ pAudioCodec->getExt(i), pAudioCodec->getExt(i) }); + LibReport(REPORT_MSG_LEVEL_NOTICE, " Ext: " COLOR_LCYAN "%s" COLOR_RESET ": " COLOR_WHITE "%s" COLOR_RESET "\n", pAudioCodec->getExt(i), pAudioCodec->getExt(i)); + } + LibReport(REPORT_MSG_LEVEL_NOTICE, " \n"); + } + } + } } bool XMETHODCALLTYPE CResourceManager::getModel(const char *szName, IXResourceModel **ppOut, bool bForceReload) @@ -339,7 +362,21 @@ void XMETHODCALLTYPE CResourceManager::addModel(const char *szName, IXResourceMo pResource->setFileName(m_mpModels.TmpNode->Key.c_str()); } +//########################################################################## + +UINT XMETHODCALLTYPE CResourceManager::getSoundSupportedFormats() +{ + return(m_aSoundExts.size()); +} + +const XFormatName* XMETHODCALLTYPE CResourceManager::getSoundSupportedFormat(UINT uIndex) +{ + assert(uIndex < m_aSoundExts.size()); + + return(&m_aSoundExts[uIndex]); +} +//########################################################################## diff --git a/source/core/ResourceManager.h b/source/core/ResourceManager.h index 26da34a11c3afae9a7507bd9cb3046343e5bd92c..de08f5a2960beb18786363ef807387451d05b83d 100644 --- a/source/core/ResourceManager.h +++ b/source/core/ResourceManager.h @@ -54,6 +54,9 @@ public: } } + UINT XMETHODCALLTYPE getSoundSupportedFormats() override; + const XFormatName* XMETHODCALLTYPE getSoundSupportedFormat(UINT uIndex) override; + protected: IXCore *m_pCore; @@ -69,6 +72,8 @@ protected: Array<XFormatName> m_aTextureExts; const char* getExtension(const char *szName); + + Array<XFormatName> m_aSoundExts; }; #endif diff --git a/source/game/SoundPlayer.cpp b/source/game/SoundPlayer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..17491fd4a92b613ae4c3d1a46b2112ad277c320e --- /dev/null +++ b/source/game/SoundPlayer.cpp @@ -0,0 +1,47 @@ + +#include "SoundPlayer.h" + +/*! \skydocent sound_player + +*/ + +BEGIN_PROPTABLE(CSoundPlayer) + +DEFINE_FIELD_STRINGFN(m_szPathSound, 0, "file", "Sound file", setSound, EDITOR_SOUND) + +DEFINE_FIELD_FLOAT(m_fDist, 0, "distance", "Hearing distance", EDITOR_TEXTFIELD) + +END_PROPTABLE() + +REGISTER_ENTITY(CSoundPlayer, sound_player); + +//########################################################################## + +CSoundPlayer::CSoundPlayer(CEntityManager *pMgr): + BaseClass(pMgr), + m_pPlayer(NULL) +{ + +} + +void CSoundPlayer::setSound(const char *szSound) +{ + mem_release(m_pPlayer); + IXSoundSystem *pSound = (IXSoundSystem*)(Core_GetIXCore()->getPluginManager()->getInterface(IXSOUNDSYSTEM_GUID)); + IXSoundLayer *pMasterLayer = pSound->findLayer("master"); + m_pPlayer = pMasterLayer->newSoundPlayer(szSound, SOUND_DTYPE_3D); + if (m_pPlayer) + { + m_pPlayer->setLoop(SOUND_LOOP_SIMPLE); + m_pPlayer->play(); + } +} + +void CSoundPlayer::onSync() +{ + if (!m_pPlayer) + return; + + float3 vPos = getPos(); + m_pPlayer->setWorldPos(vPos); +} \ No newline at end of file diff --git a/source/game/SoundPlayer.h b/source/game/SoundPlayer.h new file mode 100644 index 0000000000000000000000000000000000000000..58d463da065e65c05d0d3bd4053c4aeed2fb3744 --- /dev/null +++ b/source/game/SoundPlayer.h @@ -0,0 +1,45 @@ +/***************************************************** +Copyright � DogmaNet Team, 2020 +Site: dogmanet.ru +See the license in LICENSE +*****************************************************/ + +/*! + \file + ����� ��������� ������ +*/ +#ifndef __SOUND_PLAYER_H +#define __SOUND_PLAYER_H + +#include "PointEntity.h" +#include <xcommon/IXSoundSystem.h> + + +/*! ����� ��������� ������ + \ingroup cpointentity +*/ +class CSoundPlayer : public CPointEntity +{ + DECLARE_CLASS(CSoundPlayer, CPointEntity); + DECLARE_PROPTABLE(); +public: + //CSoundPlayer() = default; + CSoundPlayer(CEntityManager * pMgr); + + virtual void setSound(const char *szSound); + + void onSync() override; + + void stop(); + + void play(); + +protected: + + IXSoundPlayer *m_pPlayer = NULL; + const char *m_szPathSound = ""; + + float m_fDist = 10.f; +}; + +#endif diff --git a/source/game/proptable.h b/source/game/proptable.h index d5a09df641874ff6d9d39ef596b8149b7aac9e1f..c90aba93396e76695ab658068774968e9321df09 100644 --- a/source/game/proptable.h +++ b/source/game/proptable.h @@ -370,6 +370,7 @@ const char * GetEmptyString(); #define EDITOR_YESNO EDITOR_COMBOBOX COMBO_OPTION("Yes", "1") COMBO_OPTION("No", "0") EDITOR_COMBO_END() #define EDITOR_MODEL EDITOR_FILEFIELD FILE_OPTION("Select model", "dse") EDITOR_FILE_END() +#define EDITOR_SOUND EDITOR_FILEFIELD FILE_OPTION("Select sound", "ogg") EDITOR_FILE_END() #define DEFINE_FIELD_STRING(field, flags, keyname, edname, editor) , {(fieldtype)&DataClass::field, PDF_STRING, flags, keyname, edname, editor #define DEFINE_FIELD_VECTOR(field, flags, keyname, edname, editor) , {(fieldtype)&DataClass::field, PDF_VECTOR, flags, keyname, edname, editor diff --git a/source/terrax/PropertyWindow.cpp b/source/terrax/PropertyWindow.cpp index 76aa87e87df4ecdd158a8b9bb44fd3f3fb092559..f36b28edfb302a1bb3c03612eb42b2122a897858 100644 --- a/source/terrax/PropertyWindow.cpp +++ b/source/terrax/PropertyWindow.cpp @@ -353,11 +353,28 @@ INT_PTR CALLBACK CPropertyWindow::dlgProc(HWND hWnd, UINT msg, WPARAM wParam, LP } else if(!fstrcmp(szCurrentFileType, "sound")) { - szTmp += swprintf(szTmp, L"All supported formats") + 1; + /*szTmp += swprintf(szTmp, L"All supported formats") + 1; szTmp += swprintf(szTmp, L"*.ogg") + 1; szTmp += swprintf(szTmp, L"Ogg Vorbis (*.ogg)") + 1; - szTmp += swprintf(szTmp, L"*.ogg") + 1; + szTmp += swprintf(szTmp, L"*.ogg") + 1;*/ + + auto pMgr = Core_GetIXCore()->getResourceManager(); + UINT uFormatCount = pMgr->getSoundSupportedFormats(); + + szTmp += swprintf(szTmp, L"All supported formats") + 1; + for (UINT i = 0; i < uFormatCount; ++i) + { + auto pFmt = pMgr->getSoundSupportedFormat(i); + szTmp += swprintf(szTmp, L"*.%S;", pFmt->szExtension); + } + szTmp[-1] = 0; + for (UINT i = 0; i < uFormatCount; ++i) + { + auto pFmt = pMgr->getSoundSupportedFormat(i); + szTmp += swprintf(szTmp, L"%S (*.%S)", pFmt->szDescription, pFmt->szExtension) + 1; + szTmp += swprintf(szTmp, L"*.%S", pFmt->szExtension) + 1; + } } else { diff --git a/source/xSound/SoundLayer.cpp b/source/xSound/SoundLayer.cpp index 618aa56a9650bd946883516992dba4eb1be6b336..88ef9d7594ccbcbd6537ffdc423c026a6cd1b164 100644 --- a/source/xSound/SoundLayer.cpp +++ b/source/xSound/SoundLayer.cpp @@ -93,6 +93,7 @@ void CSoundLayer::delSndPlayer(const CSoundPlayer *pSndPlayer) { if (m_mapSndPlayers[i.first] == pSndPlayer) { + m_mapSndPlayers[i.first] = NULL; m_mapSndPlayers.erase(i.first); break; } @@ -226,7 +227,8 @@ IXSoundPlayer* XMETHODCALLTYPE CSoundLayer::newSoundPlayer(const char *szName, S if (m_mapSndPlayers.KeyExists(szName)) { - pPlayer = m_mapSndPlayers[szName]; + if (m_mapSndPlayers[szName]) + pPlayer = m_mapSndPlayers[szName]; //return pPlayer->newInstance(); } else @@ -283,13 +285,22 @@ bool XMETHODCALLTYPE CSoundLayer::isPlaying() const void CSoundLayer::update(const float3 &vListenerPos, const float3 &vListenerDir, const float3 &vListenerUp) { for (maplayer::Iterator i = m_mapLayers.begin(); i; i++) - m_mapLayers[i.first]->update(vListenerPos, vListenerDir, vListenerUp); + { + if (m_mapLayers[i.first]) + m_mapLayers[i.first]->update(vListenerPos, vListenerDir, vListenerUp); + } for (mapsoundplayer::Iterator i = m_mapSndPlayers.begin(); i; i++) - m_mapSndPlayers[i.first]->update(vListenerPos, vListenerDir, vListenerUp); + { + if (m_mapSndPlayers[i.first]) + m_mapSndPlayers[i.first]->update(vListenerPos, vListenerDir, vListenerUp); + } for (mapsoundemitter::Iterator i = m_mapSndEmitters.begin(); i; i++) - m_mapSndEmitters[i.first]->update(vListenerPos, vListenerDir, vListenerUp); + { + if (m_mapSndEmitters[i.first]) + m_mapSndEmitters[i.first]->update(vListenerPos, vListenerDir, vListenerUp); + } } void CSoundLayer::getObserverParam(float3 *pPos, float3 *pLook, float3 *pUp) diff --git a/source/xcommon/resource/IXResourceManager.h b/source/xcommon/resource/IXResourceManager.h index 37c30eb6b1873c52b57dfa8ef2161bfa7eb12717..30f20064c0a588b465d07b6bf82ceb12731ad777 100644 --- a/source/xcommon/resource/IXResourceManager.h +++ b/source/xcommon/resource/IXResourceManager.h @@ -45,6 +45,9 @@ public: virtual IXResourceTexture2D* XMETHODCALLTYPE newResourceTexture2D() = 0; virtual IXResourceTextureCube* XMETHODCALLTYPE newResourceTextureCube() = 0; virtual void XMETHODCALLTYPE addTexture(const char *szName, IXResourceTexture *pTexture) = 0; + + virtual UINT XMETHODCALLTYPE getSoundSupportedFormats() = 0; + virtual const XFormatName* XMETHODCALLTYPE getSoundSupportedFormat(UINT uIndex) = 0; }; #endif