Skip to content
Snippets Groups Projects
Commit 9277898a authored by D-AIRY's avatar D-AIRY
Browse files

Move sound update to worker thread

parent c565f186
Branches
Tags
No related merge requests found
...@@ -382,6 +382,11 @@ void XMETHODCALLTYPE CCore::waitForLoop(ID id) ...@@ -382,6 +382,11 @@ void XMETHODCALLTYPE CCore::waitForLoop(ID id)
g_pTaskManager->waitFor(id); g_pTaskManager->waitFor(id);
} }
void XMETHODCALLTYPE CCore::addTask(ITask *pTask)
{
g_pTaskManager->addTask(pTask);
}
IXConsole* XMETHODCALLTYPE CCore::getConsole() IXConsole* XMETHODCALLTYPE CCore::getConsole()
{ {
return(m_pConsole); return(m_pConsole);
......
...@@ -55,6 +55,7 @@ public: ...@@ -55,6 +55,7 @@ public:
ID XMETHODCALLTYPE forLoop(int iStart, int iEnd, const IParallelForBody *pBody, int iMaxChunkSize = 0) override; ID XMETHODCALLTYPE forLoop(int iStart, int iEnd, const IParallelForBody *pBody, int iMaxChunkSize = 0) override;
void XMETHODCALLTYPE waitForLoop(ID id) override; void XMETHODCALLTYPE waitForLoop(ID id) override;
void XMETHODCALLTYPE addTask(ITask *pTask) override;
IBaseEventChannel* getEventChannelInternal(const XGUID &guid) override; IBaseEventChannel* getEventChannelInternal(const XGUID &guid) override;
protected: protected:
......
...@@ -369,7 +369,6 @@ GameData::GameData(HWND hWnd, bool isGame): ...@@ -369,7 +369,6 @@ GameData::GameData(HWND hWnd, bool isGame):
m_pSoundPlayer = m_pGuiLayer->newSoundPlayer("sounds/dip.wav", SOUND_SPACE_2D); m_pSoundPlayer = m_pGuiLayer->newSoundPlayer("sounds/dip.wav", SOUND_SPACE_2D);
m_pSoundPlayer->setLoop(SOUND_LOOP_SIMPLE); m_pSoundPlayer->setLoop(SOUND_LOOP_SIMPLE);
} }
pSound->update(float3(), float3(), float3());
loadFoostepsSounds(); loadFoostepsSounds();
isGame = true; isGame = true;
......
...@@ -181,10 +181,8 @@ bool XMETHODCALLTYPE CEngine::initGraphics(XWINDOW_OS_HANDLE hWindow, IXEngineCa ...@@ -181,10 +181,8 @@ bool XMETHODCALLTYPE CEngine::initGraphics(XWINDOW_OS_HANDLE hWindow, IXEngineCa
pMasterLayer->play(true); pMasterLayer->play(true);
IXSoundLayer *pGameLayer = pMasterLayer->newSoundLayer("xGame"); IXSoundLayer *pGameLayer = pMasterLayer->newSoundLayer("xGame");
IXSoundLayer *pGuiLayer = pMasterLayer->newSoundLayer("xGUI"); IXSoundLayer *pGuiLayer = pMasterLayer->newSoundLayer("xGUI");
pSound->update(float3(), float3(), float3());
pGameLayer->play(false); pGameLayer->play(false);
pGuiLayer->play(false); pGuiLayer->play(false);
pSound->update(float3(), float3(), float3());
/*IXSoundPlayer *pPlayer = pMasterLayer->newSoundPlayer("sounds/guitar_10.ogg", SOUND_DTYPE_3D); /*IXSoundPlayer *pPlayer = pMasterLayer->newSoundPlayer("sounds/guitar_10.ogg", SOUND_DTYPE_3D);
pPlayer->setWorldPos(float3(-11.084, 0.435, -18.707)); pPlayer->setWorldPos(float3(-11.084, 0.435, -18.707));
pPlayer->setLoop(SOUND_LOOP_SIMPLE); pPlayer->setLoop(SOUND_LOOP_SIMPLE);
......
...@@ -211,11 +211,13 @@ IXSoundLayer* XMETHODCALLTYPE CSoundLayer::newSoundLayer(const char *szName, con ...@@ -211,11 +211,13 @@ IXSoundLayer* XMETHODCALLTYPE CSoundLayer::newSoundLayer(const char *szName, con
CSoundLayer *pLayer = new CSoundLayer(); CSoundLayer *pLayer = new CSoundLayer();
pLayer->init(m_pSoundSystem, this, pDesc, szName); pLayer->init(m_pSoundSystem, this, pDesc, szName);
SndQueueMsg oMsg; addLayer(pLayer);
oMsg.type = SND_QUEUE_MSG_TYPE_LAYER_NEW;
oMsg.pLayer = pLayer; // SndQueueMsg oMsg;
oMsg.pOwner = this; // oMsg.type = SND_QUEUE_MSG_TYPE_LAYER_NEW;
m_pSoundSystem->addMessage(oMsg); // oMsg.pLayer = pLayer;
// oMsg.pOwner = this;
// m_pSoundSystem->addMessage(oMsg);
return pLayer; return pLayer;
} }
......
...@@ -48,7 +48,7 @@ void CSoundSystem::addMessage(SndQueueMsg &oMsg) ...@@ -48,7 +48,7 @@ void CSoundSystem::addMessage(SndQueueMsg &oMsg)
m_queue.push(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) if(m_pMasterLayer)
m_pMasterLayer->update(vListenerPos, vListenerDir, vListenerUp); m_pMasterLayer->update(vListenerPos, vListenerDir, vListenerUp);
......
...@@ -52,7 +52,7 @@ public: ...@@ -52,7 +52,7 @@ public:
virtual IXSoundLayer* XMETHODCALLTYPE createMasterLayer(const AudioRawDesc *pDesc, const char *szName) override; virtual IXSoundLayer* XMETHODCALLTYPE createMasterLayer(const AudioRawDesc *pDesc, const char *szName) override;
virtual IXSoundLayer* XMETHODCALLTYPE findLayer(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);
//######################################################################## //########################################################################
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "SoundSystem.h" #include "SoundSystem.h"
#include <Audio.h> #include <Audio.h>
#include <gcore/sxgcore.h> #include <gcore/sxgcore.h>
#include <core/ITask.h>
#if defined(_DEBUG) #if defined(_DEBUG)
#pragma comment(lib, "mital_d.lib") #pragma comment(lib, "mital_d.lib")
...@@ -51,6 +52,43 @@ protected: ...@@ -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> class CUpdatableSoundSystem: public IXUnknownImplementation<IXUpdatable>
{ {
public: public:
...@@ -113,6 +151,7 @@ protected: ...@@ -113,6 +151,7 @@ protected:
CObserverChangedEventListener *m_pObserverListener = NULL; CObserverChangedEventListener *m_pObserverListener = NULL;
IXSoundEmitter *m_pEmitter = NULL; IXSoundEmitter *m_pEmitter = NULL;
}; };
#endif
//########################################################################## //##########################################################################
...@@ -125,7 +164,8 @@ public: ...@@ -125,7 +164,8 @@ public:
m_pCore = pCore; m_pCore = pCore;
m_pSoundSystem = new CSoundSystem(m_pCore); m_pSoundSystem = new CSoundSystem(m_pCore);
m_pObserverListener = new CObserverChangedEventListener(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 void XMETHODCALLTYPE shutdown() override
...@@ -134,7 +174,7 @@ public: ...@@ -134,7 +174,7 @@ public:
UINT XMETHODCALLTYPE getInterfaceCount() override UINT XMETHODCALLTYPE getInterfaceCount() override
{ {
return(2); return(1);
} }
const XGUID* XMETHODCALLTYPE getInterfaceGUID(UINT id) override const XGUID* XMETHODCALLTYPE getInterfaceGUID(UINT id) override
{ {
...@@ -144,9 +184,9 @@ public: ...@@ -144,9 +184,9 @@ public:
case 0: case 0:
s_guid = IXSOUNDSYSTEM_GUID; s_guid = IXSOUNDSYSTEM_GUID;
break; break;
case 1: //case 1:
s_guid = IXUPDATABLE_GUID; // s_guid = IXUPDATABLE_GUID;
break; // break;
default: default:
return(NULL); return(NULL);
} }
...@@ -156,8 +196,8 @@ public: ...@@ -156,8 +196,8 @@ public:
{ {
if(guid == IXSOUNDSYSTEM_GUID) if(guid == IXSOUNDSYSTEM_GUID)
return(m_pSoundSystem); return(m_pSoundSystem);
if(guid == IXUPDATABLE_GUID) //if(guid == IXUPDATABLE_GUID)
return(m_pUpdatableSoundSystem); // return(m_pUpdatableSoundSystem);
return(NULL); return(NULL);
} }
...@@ -165,7 +205,7 @@ public: ...@@ -165,7 +205,7 @@ public:
protected: protected:
IXCore *m_pCore; IXCore *m_pCore;
CSoundSystem *m_pSoundSystem = NULL; CSoundSystem *m_pSoundSystem = NULL;
CUpdatableSoundSystem *m_pUpdatableSoundSystem = NULL; //CUpdatableSoundSystem *m_pUpdatableSoundSystem = NULL;
CObserverChangedEventListener *m_pObserverListener = NULL; CObserverChangedEventListener *m_pObserverListener = NULL;
}; };
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
class IPluginManager; class IPluginManager;
class IXResourceManager; class IXResourceManager;
class ITask;
class IXCore: public IXUnknown class IXCore: public IXUnknown
{ {
...@@ -47,6 +48,8 @@ public: ...@@ -47,6 +48,8 @@ public:
virtual ID XMETHODCALLTYPE forLoop(int iStart, int iEnd, const IParallelForBody *pBody, int iMaxChunkSize = 0) = 0; 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 waitForLoop(ID id) = 0;
virtual void XMETHODCALLTYPE addTask(ITask *pTask) = 0;
template<typename T> IEventChannel<T> *getEventChannel(const XGUID &guid) template<typename T> IEventChannel<T> *getEventChannel(const XGUID &guid)
{ {
return((IEventChannel<T>*)getEventChannelInternal(guid)); return((IEventChannel<T>*)getEventChannelInternal(guid));
......
...@@ -120,8 +120,6 @@ public: ...@@ -120,8 +120,6 @@ public:
virtual IXSoundLayer* XMETHODCALLTYPE createMasterLayer(const AudioRawDesc *pDesc, const char *szName) = 0; virtual IXSoundLayer* XMETHODCALLTYPE createMasterLayer(const AudioRawDesc *pDesc, const char *szName) = 0;
virtual IXSoundLayer* XMETHODCALLTYPE findLayer(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 #endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment