Add support for sound sources

This commit is contained in:
BeaR 2014-10-09 12:44:03 +02:00
parent 2bd9df2626
commit 5df94f772f
5 changed files with 64 additions and 5 deletions

View file

@ -283,6 +283,25 @@ void CMapLayers::OnRender()
Graphics()->BlendNormal();
RenderTools()->RenderQuads(pQuads, pQLayer->m_NumQuads, LAYERRENDERFLAG_TRANSPARENT, EnvelopeEval, this);
}
else if(pLayer->m_Type == LAYERTYPE_SOUNDS)
{
CMapItemLayerSounds *pSoundLayer = (CMapItemLayerSounds *)pLayer;
CSoundSource *pSources = (CSoundSource *)m_pLayers->Map()->GetDataSwapped(pSoundLayer->m_Data);
Graphics()->TextureSet(-1);
Graphics()->BlendNormal();
Graphics()->QuadsBegin();
Graphics()->SetColor(1.0f, 0.0f, 1.0f, 1.0f);
for(int i = 0; i < pSoundLayer->m_NumSources; i++)
{
IGraphics::CQuadItem QuadItem(fx2f(pSources[i].m_Position.x), fx2f(pSources[i].m_Position.y), 32.0f, 32.0f);
Graphics()->QuadsDraw(&QuadItem, 1);
}
Graphics()->QuadsEnd();
}
//layershot_end();
}

View file

@ -1001,6 +1001,31 @@ void CEditor::DoToolbar(CUIRect ToolBar)
}
}
// sound source manipulation
{
// do add button
TB_Top.VSplitLeft(10.0f, &Button, &TB_Top);
TB_Top.VSplitLeft(60.0f, &Button, &TB_Top);
static int s_NewButton = 0;
CLayerSounds *pSoundLayer = (CLayerSounds *)GetSelectedLayerType(0, LAYERTYPE_SOUNDS);
if(DoButton_Editor(&s_NewButton, "Add Source", pSoundLayer?0:-1, &Button, 0, "Adds a new sound source"))
{
if(pSoundLayer)
{
float Mapping[4];
CLayerGroup *g = GetSelectedGroup();
g->Mapping(Mapping);
int AddX = f2fx(Mapping[0] + (Mapping[2]-Mapping[0])/2);
int AddY = f2fx(Mapping[1] + (Mapping[3]-Mapping[1])/2);
CSoundSource *pSource = pSoundLayer->NewSource();
pSource->m_Position.x += AddX;
pSource->m_Position.y += AddY;
}
}
}
// tile manipulation
{
TB_Bottom.VSplitLeft(40.0f, &Button, &TB_Bottom);

View file

@ -1064,6 +1064,7 @@ public:
~CLayerSounds();
virtual void Render();
CSoundSource *NewSource();
virtual void BrushSelecting(CUIRect Rect);
virtual int BrushGrab(CLayerGroup *pBrush, CUIRect Rect);
@ -1073,9 +1074,8 @@ public:
virtual void ModifySoundIndex(INDEX_MODIFY_FUNC pfnFunc);
void GetSize(float *w, float *h);
int m_Sound;
array<CSoundSource> m_lSources;
};

View file

@ -427,7 +427,9 @@ int CEditorMap::Save(class IStorage *pStorage, const char *pFileName)
Item.m_Layer.m_Type = pLayer->m_Type;
Item.m_Sound = pLayer->m_Sound;
// TODO: add the data
// add the data
Item.m_NumSources = pLayer->m_lSources.size();
Item.m_Data = df.AddDataSwapped(pLayer->m_lSources.size()*sizeof(CSoundSource), pLayer->m_lSources.base_ptr());
// save layer name
StrToInts(Item.m_aName, sizeof(Item.m_aName)/sizeof(int), pLayer->m_aName);
@ -921,9 +923,12 @@ int CEditorMap::Load(class IStorage *pStorage, const char *pFileName, int Storag
if(pSoundsItem->m_Version >= 1)
IntsToStr(pSoundsItem->m_aName, sizeof(pSounds->m_aName)/sizeof(int), pSounds->m_aName);
// TODO: load data
// load data
void *pData = DataFile.GetDataSwapped(pSoundsItem->m_Data);
pGroup->AddLayer(pSounds);
pSounds->m_lSources.set_size(pSoundsItem->m_NumSources);
mem_copy(pSounds->m_lSources.base_ptr(), pData, sizeof(CSoundSource)*pSoundsItem->m_NumSources);
DataFile.UnloadData(pSoundsItem->m_Data);
}
if(pLayer)

View file

@ -328,12 +328,22 @@ struct CMapItemEnvelope : public CMapItemEnvelope_v1
int m_Synchronized;
};
struct CSoundSource
{
CPoint m_Position;
int m_Global;
int m_Loop;
};
struct CMapItemLayerSounds
{
enum { CURRENT_VERSION=1 };
CMapItemLayer m_Layer;
int m_Version;
int m_NumSources;
int m_Data;
int m_Sound;
int m_aName[3];