diff --git a/source/core/Core.cpp b/source/core/Core.cpp index f47153f650e00a051c83223b2fec2f9a7b5d10b7..ff4e801983b66f458fbbe597cfe8445c4ec1356c 100644 --- a/source/core/Core.cpp +++ b/source/core/Core.cpp @@ -382,6 +382,11 @@ void XMETHODCALLTYPE CCore::waitForLoop(ID id) g_pTaskManager->waitFor(id); } +void XMETHODCALLTYPE CCore::addTask(ITask *pTask) +{ + g_pTaskManager->addTask(pTask); +} + IXConsole* XMETHODCALLTYPE CCore::getConsole() { return(m_pConsole); diff --git a/source/core/Core.h b/source/core/Core.h index aea449140636ed5cd1c8f097f5c6de6a60cde8f4..e4490ca904217b3b4a249b9a0e28339ed934d547 100644 --- a/source/core/Core.h +++ b/source/core/Core.h @@ -55,6 +55,7 @@ public: ID XMETHODCALLTYPE forLoop(int iStart, int iEnd, const IParallelForBody *pBody, int iMaxChunkSize = 0) override; void XMETHODCALLTYPE waitForLoop(ID id) override; + void XMETHODCALLTYPE addTask(ITask *pTask) override; IBaseEventChannel* getEventChannelInternal(const XGUID &guid) override; protected: diff --git a/source/game/GameData.cpp b/source/game/GameData.cpp index 75df4dc378ee72850ebfc26a183badac4c428e3d..3d9cf94a937222edaa322cf733aaa9c241f8484d 100644 --- a/source/game/GameData.cpp +++ b/source/game/GameData.cpp @@ -369,7 +369,6 @@ GameData::GameData(HWND hWnd, bool isGame): m_pSoundPlayer = m_pGuiLayer->newSoundPlayer("sounds/dip.wav", SOUND_SPACE_2D); m_pSoundPlayer->setLoop(SOUND_LOOP_SIMPLE); } - pSound->update(float3(), float3(), float3()); loadFoostepsSounds(); isGame = true; diff --git a/source/xEngine/Engine.cpp b/source/xEngine/Engine.cpp index f12f97802c4579e35fec2a49fa234b46516e2a15..2673e4639c74861db7005e3114824d0e053cb66f 100644 --- a/source/xEngine/Engine.cpp +++ b/source/xEngine/Engine.cpp @@ -181,10 +181,8 @@ bool XMETHODCALLTYPE CEngine::initGraphics(XWINDOW_OS_HANDLE hWindow, IXEngineCa pMasterLayer->play(true); IXSoundLayer *pGameLayer = pMasterLayer->newSoundLayer("xGame"); IXSoundLayer *pGuiLayer = pMasterLayer->newSoundLayer("xGUI"); - pSound->update(float3(), float3(), float3()); pGameLayer->play(false); pGuiLayer->play(false); - pSound->update(float3(), float3(), float3()); /*IXSoundPlayer *pPlayer = pMasterLayer->newSoundPlayer("sounds/guitar_10.ogg", SOUND_DTYPE_3D); pPlayer->setWorldPos(float3(-11.084, 0.435, -18.707)); pPlayer->setLoop(SOUND_LOOP_SIMPLE); diff --git a/source/xSound/SoundLayer.cpp b/source/xSound/SoundLayer.cpp index c21e89c02dccbad56704025d2b265c7720a4d61f..d099813898a91176af0bcb534a3381f5a57471d9 100644 --- a/source/xSound/SoundLayer.cpp +++ b/source/xSound/SoundLayer.cpp @@ -211,11 +211,13 @@ IXSoundLayer* XMETHODCALLTYPE CSoundLayer::newSoundLayer(const char *szName, con CSoundLayer *pLayer = new CSoundLayer(); pLayer->init(m_pSoundSystem, this, pDesc, szName); - SndQueueMsg oMsg; - oMsg.type = SND_QUEUE_MSG_TYPE_LAYER_NEW; - oMsg.pLayer = pLayer; - oMsg.pOwner = this; - m_pSoundSystem->addMessage(oMsg); + addLayer(pLayer); + +// SndQueueMsg oMsg; +// oMsg.type = SND_QUEUE_MSG_TYPE_LAYER_NEW; +// oMsg.pLayer = pLayer; +// oMsg.pOwner = this; +// m_pSoundSystem->addMessage(oMsg); return pLayer; } diff --git a/source/xSound/SoundSystem.cpp b/source/xSound/SoundSystem.cpp index 9ddceb66f7f703ed53ecced0d0be5ff1d35b089c..e50ed965b1aa2288b3926d27165b660750f47ff1 100644 --- a/source/xSound/SoundSystem.cpp +++ b/source/xSound/SoundSystem.cpp @@ -48,7 +48,7 @@ void CSoundSystem::addMessage(SndQueueMsg &oMsg) m_queue.push(oMsg); } -void XMETHODCALLTYPE CSoundSystem::update(const float3 &vListenerPos, const float3 &vListenerDir, const float3 &vListenerUp) +void CSoundSystem::update(const float3 &vListenerPos, const float3 &vListenerDir, const float3 &vListenerUp) { if(m_pMasterLayer) m_pMasterLayer->update(vListenerPos, vListenerDir, vListenerUp); diff --git a/source/xSound/SoundSystem.h b/source/xSound/SoundSystem.h index 024533a24a06c4a4dac34e5d2e5adf8f8bcaebef..7ec85c8903cac13865306d19c427de45d3d024a0 100644 --- a/source/xSound/SoundSystem.h +++ b/source/xSound/SoundSystem.h @@ -52,7 +52,7 @@ public: virtual IXSoundLayer* XMETHODCALLTYPE createMasterLayer(const AudioRawDesc *pDesc, const char *szName) override; virtual IXSoundLayer* XMETHODCALLTYPE findLayer(const char *szName) override; - virtual void XMETHODCALLTYPE update(const float3 &vListenerPos, const float3 &vListenerDir, const float3 &vListenerUp) override; + virtual void update(const float3 &vListenerPos, const float3 &vListenerDir, const float3 &vListenerUp); //######################################################################## diff --git a/source/xSound/plugin_main.cpp b/source/xSound/plugin_main.cpp index 979f2955f02b15c82723c8a2f09041a0e9e2e3d4..94f754071a9789b9f45ca950b17de7925b7a5e9e 100644 --- a/source/xSound/plugin_main.cpp +++ b/source/xSound/plugin_main.cpp @@ -4,6 +4,7 @@ #include "SoundSystem.h" #include <Audio.h> #include <gcore/sxgcore.h> +#include <core/ITask.h> #if defined(_DEBUG) #pragma comment(lib, "mital_d.lib") @@ -51,6 +52,43 @@ protected: //########################################################################## +class CUpdateTask: public ITaskImpl<ITask> +{ +public: + CUpdateTask(CSoundSystem *pSoundSystem, CObserverChangedEventListener *pObserverListener): + m_pSoundSystem(pSoundSystem), + m_pObserverListener(pObserverListener), + ITaskImpl(CORE_TASK_FLAG_BACKGROUND_REPEATING) + { + } + + ~CUpdateTask() + { + mem_release(m_pSoundSystem); + } + + void run() override + { + float3 vPos, vLook, vUp; + + if(m_pObserverListener) + m_pObserverListener->getObserverParam(&vPos, &vLook, &vUp); + + if(m_pSoundSystem) + m_pSoundSystem->update(vPos, vLook, vUp); + } + + uint64_t getRepeatInterval() override + { + return(20000); // 20ms + } + +protected: + CSoundSystem *m_pSoundSystem = NULL; + CObserverChangedEventListener *m_pObserverListener = NULL; +}; + +#if 0 class CUpdatableSoundSystem: public IXUnknownImplementation<IXUpdatable> { public: @@ -113,6 +151,7 @@ protected: CObserverChangedEventListener *m_pObserverListener = NULL; IXSoundEmitter *m_pEmitter = NULL; }; +#endif //########################################################################## @@ -125,7 +164,8 @@ public: m_pCore = pCore; m_pSoundSystem = new CSoundSystem(m_pCore); m_pObserverListener = new CObserverChangedEventListener(m_pCore); - m_pUpdatableSoundSystem = new CUpdatableSoundSystem(m_pSoundSystem, m_pObserverListener); + m_pCore->addTask(new CUpdateTask(m_pSoundSystem, m_pObserverListener)); + //m_pUpdatableSoundSystem = new CUpdatableSoundSystem(m_pSoundSystem, m_pObserverListener); } void XMETHODCALLTYPE shutdown() override @@ -134,7 +174,7 @@ public: UINT XMETHODCALLTYPE getInterfaceCount() override { - return(2); + return(1); } const XGUID* XMETHODCALLTYPE getInterfaceGUID(UINT id) override { @@ -144,9 +184,9 @@ public: case 0: s_guid = IXSOUNDSYSTEM_GUID; break; - case 1: - s_guid = IXUPDATABLE_GUID; - break; + //case 1: + // s_guid = IXUPDATABLE_GUID; + // break; default: return(NULL); } @@ -156,8 +196,8 @@ public: { if(guid == IXSOUNDSYSTEM_GUID) return(m_pSoundSystem); - if(guid == IXUPDATABLE_GUID) - return(m_pUpdatableSoundSystem); + //if(guid == IXUPDATABLE_GUID) + // return(m_pUpdatableSoundSystem); return(NULL); } @@ -165,7 +205,7 @@ public: protected: IXCore *m_pCore; CSoundSystem *m_pSoundSystem = NULL; - CUpdatableSoundSystem *m_pUpdatableSoundSystem = NULL; + //CUpdatableSoundSystem *m_pUpdatableSoundSystem = NULL; CObserverChangedEventListener *m_pObserverListener = NULL; }; diff --git a/source/xcommon/IXCore.h b/source/xcommon/IXCore.h index ac558821fac2677099e41d79f657523ee5709b25..a5d6d59ad441a7f616e31a29f0fa9be242430270 100644 --- a/source/xcommon/IXCore.h +++ b/source/xcommon/IXCore.h @@ -16,6 +16,7 @@ class IPluginManager; class IXResourceManager; +class ITask; class IXCore: public IXUnknown { @@ -47,6 +48,8 @@ public: virtual ID XMETHODCALLTYPE forLoop(int iStart, int iEnd, const IParallelForBody *pBody, int iMaxChunkSize = 0) = 0; virtual void XMETHODCALLTYPE waitForLoop(ID id) = 0; + virtual void XMETHODCALLTYPE addTask(ITask *pTask) = 0; + template<typename T> IEventChannel<T> *getEventChannel(const XGUID &guid) { return((IEventChannel<T>*)getEventChannelInternal(guid)); diff --git a/source/xcommon/IXSoundSystem.h b/source/xcommon/IXSoundSystem.h index 2bc35b5b280fd4bc37ebfc4ee075a9fd2738ce18..f33663b531408d3aea0737fe65e9a9c4a1a3795b 100644 --- a/source/xcommon/IXSoundSystem.h +++ b/source/xcommon/IXSoundSystem.h @@ -120,8 +120,6 @@ public: virtual IXSoundLayer* XMETHODCALLTYPE createMasterLayer(const AudioRawDesc *pDesc, const char *szName) = 0; virtual IXSoundLayer* XMETHODCALLTYPE findLayer(const char *szName) = 0; - - virtual void XMETHODCALLTYPE update(const float3 &vListenerPos, const float3 &vListenerDir, const float3 &vListenerUp) = 0; }; #endif