From d1327742e7ae13b6ae39952928a6899453a57542 Mon Sep 17 00:00:00 2001 From: BeaR Date: Thu, 27 Nov 2014 16:18:15 +0100 Subject: [PATCH] Start adding support for custom shaped audio fields Add version check for sound layers --- src/game/client/components/mapsounds.cpp | 6 ++++ src/game/editor/io.cpp | 3 ++ src/game/mapitems.h | 35 +++++++++++++++++++++++- 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/game/client/components/mapsounds.cpp b/src/game/client/components/mapsounds.cpp index 7f1e578e9..408d72c9d 100644 --- a/src/game/client/components/mapsounds.cpp +++ b/src/game/client/components/mapsounds.cpp @@ -63,6 +63,9 @@ void CMapSounds::OnMapLoad() { CMapItemLayerSounds *pSoundLayer = (CMapItemLayerSounds *)pLayer; + if(pSoundLayer->m_Version < 1 || pSoundLayer->m_Version > CMapItemLayerSounds::CURRENT_VERSION) + continue; + if(pSoundLayer->m_Sound == -1) continue; @@ -149,6 +152,9 @@ void CMapSounds::OnRender() if(pLayer->m_Type == LAYERTYPE_SOUNDS) { CMapItemLayerSounds *pSoundLayer = (CMapItemLayerSounds *)pLayer; + + if(pSoundLayer->m_Version < 1 || pSoundLayer->m_Version > CMapItemLayerSounds::CURRENT_VERSION) + continue; CSoundSource *pSources = (CSoundSource *)Layers()->Map()->GetDataSwapped(pSoundLayer->m_Data); diff --git a/src/game/editor/io.cpp b/src/game/editor/io.cpp index e46d4f310..bf67892f4 100644 --- a/src/game/editor/io.cpp +++ b/src/game/editor/io.cpp @@ -996,6 +996,9 @@ int CEditorMap::Load(class IStorage *pStorage, const char *pFileName, int Storag else if(pLayerItem->m_Type == LAYERTYPE_SOUNDS) { CMapItemLayerSounds *pSoundsItem = (CMapItemLayerSounds *)pLayerItem; + if(pSoundsItem->m_Version < 1 || pSoundsItem->m_Version > CMapItemLayerSounds::CURRENT_VERSION) + continue; + CLayerSounds *pSounds = new CLayerSounds; pSounds->m_pEditor = m_pEditor; pLayer = pSounds; diff --git a/src/game/mapitems.h b/src/game/mapitems.h index b0aa01a95..e603d42eb 100644 --- a/src/game/mapitems.h +++ b/src/game/mapitems.h @@ -18,6 +18,7 @@ enum LAYERTYPE_SPEEDUP, LAYERTYPE_SWITCH, LAYERTYPE_TUNE, + LAYERTYPE_SOUNDS_DEPRECATED, // deprecated! do not use this, this is just for compatibility reasons LAYERTYPE_SOUNDS, MAPITEMTYPE_VERSION=0, @@ -329,23 +330,55 @@ struct CMapItemEnvelope : public CMapItemEnvelope_v1 int m_Synchronized; }; +struct CSoundShape +{ + enum + { + SHAPE_RECTANGLE, + SHAPE_CIRCLE, + NUM_SHAPES, + }; + + struct CRectangle + { + int m_PosX, m_PosY; // fxp 22.10 + int m_Width, m_Height; // fxp 22.10 + }; + + struct CCircle + { + int m_PosX, m_PosY; // fxp 22.10 + int m_Radius; // fxp 22.10 + }; + + int m_Type; + + union + { + CRectangle m_Rectangle; + CCircle m_Circle; + }; +}; + struct CSoundSource { CPoint m_Position; int m_Loop; int m_TimeDelay; // in s int m_FalloffDistance; + int m_Falloff; // [0,255] // 0 - No falloff, 255 - full int m_PosEnv; int m_PosEnvOffset; int m_SoundEnv; int m_SoundEnvOffset; + CSoundShape m_Shape; }; struct CMapItemLayerSounds { - enum { CURRENT_VERSION=1 }; + enum { CURRENT_VERSION=2 }; CMapItemLayer m_Layer; int m_Version;