2010-11-20 10:37:14 +00:00
|
|
|
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
|
|
|
|
/* If you are missing that file, acquire a complete release at teeworlds.com. */
|
2010-05-29 07:25:38 +00:00
|
|
|
#include "layers.h"
|
2008-01-13 11:15:32 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
CLayers::CLayers()
|
|
|
|
{
|
|
|
|
m_GroupsNum = 0;
|
|
|
|
m_GroupsStart = 0;
|
|
|
|
m_LayersNum = 0;
|
|
|
|
m_LayersStart = 0;
|
|
|
|
m_pGameGroup = 0;
|
|
|
|
m_pGameLayer = 0;
|
|
|
|
m_pMap = 0;
|
2011-04-09 06:41:31 +00:00
|
|
|
|
2010-08-10 04:28:17 +00:00
|
|
|
m_pTeleLayer = 0;
|
|
|
|
m_pSpeedupLayer = 0;
|
2010-08-27 05:19:10 +00:00
|
|
|
m_pFrontLayer = 0;
|
2010-08-27 23:30:50 +00:00
|
|
|
m_pSwitchLayer = 0;
|
2014-03-12 22:07:19 +00:00
|
|
|
m_pTuneLayer = 0;
|
2010-05-29 07:25:38 +00:00
|
|
|
}
|
2008-01-13 11:15:32 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CLayers::Init(class IKernel *pKernel)
|
2008-01-13 11:15:32 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
m_pMap = pKernel->RequestInterface<IMap>();
|
|
|
|
m_pMap->GetType(MAPITEMTYPE_GROUP, &m_GroupsStart, &m_GroupsNum);
|
|
|
|
m_pMap->GetType(MAPITEMTYPE_LAYER, &m_LayersStart, &m_LayersNum);
|
2011-04-09 06:41:31 +00:00
|
|
|
|
2011-03-16 17:48:16 +00:00
|
|
|
m_pTeleLayer = 0;
|
|
|
|
m_pSpeedupLayer = 0;
|
|
|
|
m_pFrontLayer = 0;
|
|
|
|
m_pSwitchLayer = 0;
|
2014-03-12 22:07:19 +00:00
|
|
|
m_pTuneLayer = 0;
|
2011-04-13 23:27:49 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
for(int g = 0; g < NumGroups(); g++)
|
2008-01-13 11:15:32 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
CMapItemGroup *pGroup = GetGroup(g);
|
|
|
|
for(int l = 0; l < pGroup->m_NumLayers; l++)
|
2008-01-13 11:15:32 +00:00
|
|
|
{
|
2020-09-26 19:41:58 +00:00
|
|
|
CMapItemLayer *pLayer = GetLayer(pGroup->m_StartLayer + l);
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
if(pLayer->m_Type == LAYERTYPE_TILES)
|
2008-01-13 11:15:32 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
CMapItemLayerTilemap *pTilemap = reinterpret_cast<CMapItemLayerTilemap *>(pLayer);
|
2011-08-26 11:46:22 +00:00
|
|
|
|
2020-09-26 19:41:58 +00:00
|
|
|
if(pTilemap->m_Flags & TILESLAYERFLAG_GAME)
|
2008-01-29 21:39:41 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
m_pGameLayer = pTilemap;
|
|
|
|
m_pGameGroup = pGroup;
|
|
|
|
|
|
|
|
// make sure the game group has standard settings
|
|
|
|
m_pGameGroup->m_OffsetX = 0;
|
|
|
|
m_pGameGroup->m_OffsetY = 0;
|
|
|
|
m_pGameGroup->m_ParallaxX = 100;
|
|
|
|
m_pGameGroup->m_ParallaxY = 100;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-11-29 19:33:38 +00:00
|
|
|
if(m_pGameGroup->m_Version >= 2)
|
|
|
|
{
|
|
|
|
m_pGameGroup->m_UseClipping = 0;
|
|
|
|
m_pGameGroup->m_ClipX = 0;
|
|
|
|
m_pGameGroup->m_ClipY = 0;
|
|
|
|
m_pGameGroup->m_ClipW = 0;
|
|
|
|
m_pGameGroup->m_ClipH = 0;
|
|
|
|
}
|
2010-05-29 07:25:38 +00:00
|
|
|
|
2010-07-29 05:21:18 +00:00
|
|
|
//break;
|
2008-01-29 21:39:41 +00:00
|
|
|
}
|
2020-09-26 19:41:58 +00:00
|
|
|
if(pTilemap->m_Flags & TILESLAYERFLAG_TELE)
|
2011-08-27 13:02:39 +00:00
|
|
|
{
|
|
|
|
if(pTilemap->m_Version <= 2)
|
|
|
|
{
|
2020-09-26 19:41:58 +00:00
|
|
|
pTilemap->m_Tele = *((int *)(pTilemap) + 15);
|
2011-08-27 13:02:39 +00:00
|
|
|
}
|
2010-08-10 04:28:17 +00:00
|
|
|
m_pTeleLayer = pTilemap;
|
2011-08-27 13:02:39 +00:00
|
|
|
}
|
2020-09-26 19:41:58 +00:00
|
|
|
if(pTilemap->m_Flags & TILESLAYERFLAG_SPEEDUP)
|
2011-08-27 13:02:39 +00:00
|
|
|
{
|
|
|
|
if(pTilemap->m_Version <= 2)
|
|
|
|
{
|
2020-09-26 19:41:58 +00:00
|
|
|
pTilemap->m_Speedup = *((int *)(pTilemap) + 16);
|
2011-08-27 13:02:39 +00:00
|
|
|
}
|
2010-08-10 04:28:17 +00:00
|
|
|
m_pSpeedupLayer = pTilemap;
|
2011-08-27 13:02:39 +00:00
|
|
|
}
|
2020-09-26 19:41:58 +00:00
|
|
|
if(pTilemap->m_Flags & TILESLAYERFLAG_FRONT)
|
2011-08-27 13:02:39 +00:00
|
|
|
{
|
|
|
|
if(pTilemap->m_Version <= 2)
|
|
|
|
{
|
2020-09-26 19:41:58 +00:00
|
|
|
pTilemap->m_Front = *((int *)(pTilemap) + 17);
|
2011-08-27 13:02:39 +00:00
|
|
|
}
|
2010-08-27 05:19:10 +00:00
|
|
|
m_pFrontLayer = pTilemap;
|
2011-08-27 13:02:39 +00:00
|
|
|
}
|
2020-09-26 19:41:58 +00:00
|
|
|
if(pTilemap->m_Flags & TILESLAYERFLAG_SWITCH)
|
2011-08-27 13:02:39 +00:00
|
|
|
{
|
|
|
|
if(pTilemap->m_Version <= 2)
|
|
|
|
{
|
2020-09-26 19:41:58 +00:00
|
|
|
pTilemap->m_Switch = *((int *)(pTilemap) + 18);
|
2011-08-27 13:02:39 +00:00
|
|
|
}
|
2010-08-27 23:30:50 +00:00
|
|
|
m_pSwitchLayer = pTilemap;
|
2011-08-27 13:02:39 +00:00
|
|
|
}
|
2020-09-26 19:41:58 +00:00
|
|
|
if(pTilemap->m_Flags & TILESLAYERFLAG_TUNE)
|
2015-07-09 00:08:14 +00:00
|
|
|
{
|
|
|
|
if(pTilemap->m_Version <= 2)
|
|
|
|
{
|
2020-09-26 19:41:58 +00:00
|
|
|
pTilemap->m_Tune = *((int *)(pTilemap) + 19);
|
2015-07-09 00:08:14 +00:00
|
|
|
}
|
|
|
|
m_pTuneLayer = pTilemap;
|
2014-03-12 22:07:19 +00:00
|
|
|
}
|
2011-04-13 18:37:12 +00:00
|
|
|
}
|
2008-01-13 11:15:32 +00:00
|
|
|
}
|
|
|
|
}
|
2022-01-19 21:20:28 +00:00
|
|
|
|
|
|
|
InitTilemapSkip();
|
2008-01-13 11:15:32 +00:00
|
|
|
}
|
|
|
|
|
2015-08-25 00:11:04 +00:00
|
|
|
void CLayers::InitBackground(class IMap *pMap)
|
|
|
|
{
|
|
|
|
m_pMap = pMap;
|
|
|
|
m_pMap->GetType(MAPITEMTYPE_GROUP, &m_GroupsStart, &m_GroupsNum);
|
|
|
|
m_pMap->GetType(MAPITEMTYPE_LAYER, &m_LayersStart, &m_LayersNum);
|
2017-02-21 16:10:08 +00:00
|
|
|
|
2015-08-25 00:11:04 +00:00
|
|
|
//following is here to prevent crash using standard map as background
|
|
|
|
m_pTeleLayer = 0;
|
|
|
|
m_pSpeedupLayer = 0;
|
|
|
|
m_pFrontLayer = 0;
|
|
|
|
m_pSwitchLayer = 0;
|
|
|
|
m_pTuneLayer = 0;
|
|
|
|
|
|
|
|
for(int g = 0; g < NumGroups(); g++)
|
|
|
|
{
|
|
|
|
CMapItemGroup *pGroup = GetGroup(g);
|
|
|
|
for(int l = 0; l < pGroup->m_NumLayers; l++)
|
|
|
|
{
|
2020-09-26 19:41:58 +00:00
|
|
|
CMapItemLayer *pLayer = GetLayer(pGroup->m_StartLayer + l);
|
2015-08-25 00:11:04 +00:00
|
|
|
|
|
|
|
if(pLayer->m_Type == LAYERTYPE_TILES)
|
|
|
|
{
|
|
|
|
CMapItemLayerTilemap *pTilemap = reinterpret_cast<CMapItemLayerTilemap *>(pLayer);
|
|
|
|
|
2020-09-26 19:41:58 +00:00
|
|
|
if(pTilemap->m_Flags & TILESLAYERFLAG_GAME)
|
2015-08-25 00:11:04 +00:00
|
|
|
{
|
|
|
|
m_pGameLayer = pTilemap;
|
|
|
|
m_pGameGroup = pGroup;
|
|
|
|
|
|
|
|
// make sure the game group has standard settings
|
|
|
|
m_pGameGroup->m_OffsetX = 0;
|
|
|
|
m_pGameGroup->m_OffsetY = 0;
|
|
|
|
m_pGameGroup->m_ParallaxX = 100;
|
|
|
|
m_pGameGroup->m_ParallaxY = 100;
|
|
|
|
|
|
|
|
if(m_pGameGroup->m_Version >= 2)
|
|
|
|
{
|
|
|
|
m_pGameGroup->m_UseClipping = 0;
|
|
|
|
m_pGameGroup->m_ClipX = 0;
|
|
|
|
m_pGameGroup->m_ClipY = 0;
|
|
|
|
m_pGameGroup->m_ClipW = 0;
|
|
|
|
m_pGameGroup->m_ClipH = 0;
|
|
|
|
}
|
2017-02-21 16:10:08 +00:00
|
|
|
//We don't care about tile layers.
|
2015-08-25 00:11:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-01-19 21:20:28 +00:00
|
|
|
|
|
|
|
InitTilemapSkip();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CLayers::InitTilemapSkip()
|
|
|
|
{
|
|
|
|
for(int g = 0; g < NumGroups(); g++)
|
|
|
|
{
|
2022-01-19 21:27:59 +00:00
|
|
|
const CMapItemGroup *pGroup = GetGroup(g);
|
2022-01-19 21:20:28 +00:00
|
|
|
|
|
|
|
for(int l = 0; l < pGroup->m_NumLayers; l++)
|
|
|
|
{
|
2022-01-19 21:27:59 +00:00
|
|
|
const CMapItemLayer *pLayer = GetLayer(pGroup->m_StartLayer + l);
|
2022-01-19 21:20:28 +00:00
|
|
|
|
|
|
|
if(pLayer->m_Type == LAYERTYPE_TILES)
|
|
|
|
{
|
2022-01-19 21:27:59 +00:00
|
|
|
const CMapItemLayerTilemap *pTilemap = (CMapItemLayerTilemap *)pLayer;
|
|
|
|
CTile *pTiles = (CTile *)m_pMap->GetData(pTilemap->m_Data);
|
|
|
|
for(int y = 0; y < pTilemap->m_Height; y++)
|
2022-01-19 21:20:28 +00:00
|
|
|
{
|
2022-01-19 21:27:59 +00:00
|
|
|
for(int x = 1; x < pTilemap->m_Width;)
|
2022-01-19 21:20:28 +00:00
|
|
|
{
|
2022-01-19 21:27:59 +00:00
|
|
|
int SkippedX;
|
|
|
|
for(SkippedX = 1; x + SkippedX < pTilemap->m_Width && SkippedX < 255; SkippedX++)
|
2022-01-19 21:20:28 +00:00
|
|
|
{
|
2022-01-19 21:27:59 +00:00
|
|
|
if(pTiles[y * pTilemap->m_Width + x + SkippedX].m_Index)
|
2022-01-19 21:20:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-01-19 21:27:59 +00:00
|
|
|
pTiles[y * pTilemap->m_Width + x].m_Skip = SkippedX - 1;
|
|
|
|
x += SkippedX;
|
2022-01-19 21:20:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-08-25 00:11:04 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
CMapItemGroup *CLayers::GetGroup(int Index) const
|
2008-01-13 11:15:32 +00:00
|
|
|
{
|
2020-09-26 19:41:58 +00:00
|
|
|
return static_cast<CMapItemGroup *>(m_pMap->GetItem(m_GroupsStart + Index, 0, 0));
|
2008-01-13 11:15:32 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
CMapItemLayer *CLayers::GetLayer(int Index) const
|
2008-01-13 11:15:32 +00:00
|
|
|
{
|
2020-09-26 19:41:58 +00:00
|
|
|
return static_cast<CMapItemLayer *>(m_pMap->GetItem(m_LayersStart + Index, 0, 0));
|
2008-01-13 11:15:32 +00:00
|
|
|
}
|