Fix parallax scrolling for audio sources and remove global property

This commit is contained in:
BeaR 2014-10-13 12:10:56 +02:00
parent ef3b801999
commit b67fab8fdb
4 changed files with 60 additions and 26 deletions

View file

@ -2,6 +2,7 @@
#include <engine/engine.h>
#include <engine/sound.h>
#include <game/client/components/camera.h>
#include <game/client/components/maplayers.h> // envelope
#include <game/client/components/sounds.h>
@ -120,10 +121,7 @@ void CMapSounds::OnRender()
CSourceVoice Voice;
Voice.m_pSource = pSource->m_pSource;
if(pSource->m_pSource->m_Global)
Voice.m_Voice = m_pClient->m_pSounds->PlaySample(CSounds::CHN_AMBIENT, m_aSounds[pSource->m_Sound], 1.0f, Flags);
else
Voice.m_Voice = m_pClient->m_pSounds->PlaySampleAt(CSounds::CHN_AMBIENT, m_aSounds[pSource->m_Sound], 1.0f, vec2(fx2f(pSource->m_pSource->m_Position.x), fx2f(pSource->m_pSource->m_Position.y)), Flags);
Voice.m_Voice = m_pClient->m_pSounds->PlaySampleAt(CSounds::CHN_AMBIENT, m_aSounds[pSource->m_Sound], 1.0f, vec2(fx2f(pSource->m_pSource->m_Position.x), fx2f(pSource->m_pSource->m_Position.y)), Flags);
Sound()->SetVoiceMaxDistance(Voice.m_Voice, pSource->m_pSource->m_FalloffDistance);
@ -132,31 +130,72 @@ void CMapSounds::OnRender()
}
}
// update voices
for(int i = 0; i < m_lVoices.size(); i++)
vec2 Center = m_pClient->m_pCamera->m_Center;
for(int g = 0; g < Layers()->NumGroups(); g++)
{
CSourceVoice *pVoice = &m_lVoices[i];;
CMapItemGroup *pGroup = Layers()->GetGroup(g);
if(!pVoice->m_Voice.IsValid())
if(!pGroup)
continue;
if(pVoice->m_pSource->m_PosEnv >= 0)
for(int l = 0; l < pGroup->m_NumLayers; l++)
{
float aChannels[4];
CMapLayers::EnvelopeEval(pVoice->m_pSource->m_PosEnvOffset/1000.0f, pVoice->m_pSource->m_PosEnv, aChannels, m_pClient->m_pMapLayersBackGround);
float OffsetX = aChannels[0];
float OffsetY = aChannels[1];
CMapItemLayer *pLayer = Layers()->GetLayer(pGroup->m_StartLayer+l);
Sound()->SetVoiceLocation(pVoice->m_Voice, fx2f(pVoice->m_pSource->m_Position.x)+OffsetX, fx2f(pVoice->m_pSource->m_Position.y)+OffsetY);
}
if(!pLayer)
continue;
if(pVoice->m_pSource->m_SoundEnv >= 0)
{
float aChannels[4];
CMapLayers::EnvelopeEval(pVoice->m_pSource->m_SoundEnvOffset/1000.0f, pVoice->m_pSource->m_SoundEnv, aChannels, m_pClient->m_pMapLayersBackGround);
float Volume = clamp(aChannels[0], 0.0f, 1.0f);
if(pLayer->m_Type == LAYERTYPE_SOUNDS)
{
CMapItemLayerSounds *pSoundLayer = (CMapItemLayerSounds *)pLayer;
Sound()->SetVoiceVolume(pVoice->m_Voice, Volume);
CSoundSource *pSources = (CSoundSource *)Layers()->Map()->GetDataSwapped(pSoundLayer->m_Data);
if(!pSources)
continue;
for(int s = 0; s < pSoundLayer->m_NumSources; s++) {
for(int i = 0; i < m_lVoices.size(); i++)
{
CSourceVoice *pVoice = &m_lVoices[i];
if(pVoice->m_pSource != &pSources[s])
continue;
if(!pVoice->m_Voice.IsValid())
continue;
float OffsetX = 0, OffsetY = 0;
if(pVoice->m_pSource->m_PosEnv >= 0)
{
float aChannels[4];
CMapLayers::EnvelopeEval(pVoice->m_pSource->m_PosEnvOffset/1000.0f, pVoice->m_pSource->m_PosEnv, aChannels, m_pClient->m_pMapLayersBackGround);
OffsetX = aChannels[0];
OffsetY = aChannels[1];
}
float x = fx2f(pVoice->m_pSource->m_Position.x)+OffsetX;
float y = fx2f(pVoice->m_pSource->m_Position.y)+OffsetY;
x += Center.x*(1.0f-pGroup->m_ParallaxX/100.0f);
y += Center.y*(1.0f-pGroup->m_ParallaxY/100.0f);
x -= pGroup->m_OffsetX; y -= pGroup->m_OffsetY;
Sound()->SetVoiceLocation(pVoice->m_Voice, x, y);
if(pVoice->m_pSource->m_SoundEnv >= 0)
{
float aChannels[4];
CMapLayers::EnvelopeEval(pVoice->m_pSource->m_SoundEnvOffset/1000.0f, pVoice->m_pSource->m_SoundEnv, aChannels, m_pClient->m_pMapLayersBackGround);
float Volume = clamp(aChannels[0], 0.0f, 1.0f);
Sound()->SetVoiceVolume(pVoice->m_Voice, Volume);
}
}
}
}
}
}
}

View file

@ -75,7 +75,6 @@ CSoundSource *CLayerSounds::NewSource()
pSource->m_Position.x = 0;
pSource->m_Position.y = 0;
pSource->m_Global = 0;
pSource->m_Loop = 1;
pSource->m_TimeDelay = 0;
pSource->m_FalloffDistance = 1500;

View file

@ -628,7 +628,6 @@ int CEditor::PopupSource(CEditor *pEditor, CUIRect View)
{
PROP_POS_X=0,
PROP_POS_Y,
PROP_GLOBAL,
PROP_LOOP,
PROP_TIME_DELAY,
PROP_DISTANCE,
@ -642,7 +641,6 @@ int CEditor::PopupSource(CEditor *pEditor, CUIRect View)
CProperty aProps[] = {
{"Pos X", pSource->m_Position.x/1000, PROPTYPE_INT_SCROLL, -1000000, 1000000},
{"Pos Y", pSource->m_Position.y/1000, PROPTYPE_INT_SCROLL, -1000000, 1000000},
{"Global", pSource->m_Global, PROPTYPE_BOOL, 0, 1},
{"Loop", pSource->m_Loop, PROPTYPE_BOOL, 0, 1},
{"Delay", pSource->m_TimeDelay, PROPTYPE_INT_SCROLL, 0, 1000000},
{"Distance", pSource->m_FalloffDistance, PROPTYPE_INT_SCROLL, 0, 1000000},
@ -662,7 +660,6 @@ int CEditor::PopupSource(CEditor *pEditor, CUIRect View)
if(Prop == PROP_POS_X) pSource->m_Position.x = NewVal*1000;
if(Prop == PROP_POS_Y) pSource->m_Position.y = NewVal*1000;
if(Prop == PROP_GLOBAL) pSource->m_Global = NewVal;
if(Prop == PROP_LOOP) pSource->m_Loop = NewVal;
if(Prop == PROP_TIME_DELAY) pSource->m_TimeDelay = NewVal;
if(Prop == PROP_DISTANCE) pSource->m_FalloffDistance = NewVal;

View file

@ -332,7 +332,6 @@ struct CMapItemEnvelope : public CMapItemEnvelope_v1
struct CSoundSource
{
CPoint m_Position;
int m_Global;
int m_Loop;
int m_TimeDelay; // in s
int m_FalloffDistance;