mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-17 21:48:19 +00:00
Merge pull request #9152 from Robyt3/CLayers-Refactoring
Minor refactoring of `CLayers`
This commit is contained in:
commit
3e9ca3314f
|
@ -73,7 +73,7 @@ void CBackground::LoadBackground()
|
||||||
}
|
}
|
||||||
else if(m_pMap->Load(aBuf))
|
else if(m_pMap->Load(aBuf))
|
||||||
{
|
{
|
||||||
m_pLayers->InitBackground(m_pMap);
|
m_pLayers->Init(m_pMap, true);
|
||||||
NeedImageLoading = true;
|
NeedImageLoading = true;
|
||||||
m_Loaded = true;
|
m_Loaded = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -254,7 +254,7 @@ void CMenuBackground::LoadMenuBackground(bool HasDayHint, bool HasNightHint)
|
||||||
|
|
||||||
if(m_Loaded)
|
if(m_Loaded)
|
||||||
{
|
{
|
||||||
m_pLayers->InitBackground(m_pMap);
|
m_pLayers->Init(m_pMap, true);
|
||||||
|
|
||||||
CMapLayers::OnMapLoad();
|
CMapLayers::OnMapLoad();
|
||||||
m_pImages->LoadBackground(m_pLayers, m_pMap);
|
m_pImages->LoadBackground(m_pLayers, m_pMap);
|
||||||
|
|
|
@ -532,7 +532,7 @@ void CGameClient::OnConnected()
|
||||||
const char *pLoadMapContent = Localize("Initializing map logic");
|
const char *pLoadMapContent = Localize("Initializing map logic");
|
||||||
// render loading before skip is calculated
|
// render loading before skip is calculated
|
||||||
m_Menus.RenderLoading(pConnectCaption, pLoadMapContent, 0, false);
|
m_Menus.RenderLoading(pConnectCaption, pLoadMapContent, 0, false);
|
||||||
m_Layers.Init(Kernel());
|
m_Layers.Init(Kernel()->RequestInterface<IMap>(), false);
|
||||||
m_Collision.Init(Layers());
|
m_Collision.Init(Layers());
|
||||||
m_GameWorld.m_Core.InitSwitchers(m_Collision.m_HighestSwitchNumber);
|
m_GameWorld.m_Core.InitSwitchers(m_Collision.m_HighestSwitchNumber);
|
||||||
m_RaceHelper.Init(this);
|
m_RaceHelper.Init(this);
|
||||||
|
|
|
@ -11,49 +11,51 @@ CLayers::CLayers()
|
||||||
Unload();
|
Unload();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CLayers::Init(class IKernel *pKernel)
|
void CLayers::Init(IMap *pMap, bool GameOnly)
|
||||||
{
|
{
|
||||||
Unload();
|
Unload();
|
||||||
|
|
||||||
m_pMap = pKernel->RequestInterface<IMap>();
|
m_pMap = pMap;
|
||||||
m_pMap->GetType(MAPITEMTYPE_GROUP, &m_GroupsStart, &m_GroupsNum);
|
m_pMap->GetType(MAPITEMTYPE_GROUP, &m_GroupsStart, &m_GroupsNum);
|
||||||
m_pMap->GetType(MAPITEMTYPE_LAYER, &m_LayersStart, &m_LayersNum);
|
m_pMap->GetType(MAPITEMTYPE_LAYER, &m_LayersStart, &m_LayersNum);
|
||||||
|
|
||||||
for(int g = 0; g < NumGroups(); g++)
|
for(int GroupIndex = 0; GroupIndex < NumGroups(); GroupIndex++)
|
||||||
{
|
{
|
||||||
CMapItemGroup *pGroup = GetGroup(g);
|
CMapItemGroup *pGroup = GetGroup(GroupIndex);
|
||||||
for(int l = 0; l < pGroup->m_NumLayers; l++)
|
for(int LayerIndex = 0; LayerIndex < pGroup->m_NumLayers; LayerIndex++)
|
||||||
{
|
{
|
||||||
CMapItemLayer *pLayer = GetLayer(pGroup->m_StartLayer + l);
|
CMapItemLayer *pLayer = GetLayer(pGroup->m_StartLayer + LayerIndex);
|
||||||
|
if(pLayer->m_Type != LAYERTYPE_TILES)
|
||||||
|
continue;
|
||||||
|
|
||||||
if(pLayer->m_Type == LAYERTYPE_TILES)
|
CMapItemLayerTilemap *pTilemap = reinterpret_cast<CMapItemLayerTilemap *>(pLayer);
|
||||||
|
bool IsEntities = false;
|
||||||
|
|
||||||
|
if(pTilemap->m_Flags & TILESLAYERFLAG_GAME)
|
||||||
{
|
{
|
||||||
CMapItemLayerTilemap *pTilemap = reinterpret_cast<CMapItemLayerTilemap *>(pLayer);
|
m_pGameLayer = pTilemap;
|
||||||
bool IsEntities = false;
|
m_pGameGroup = pGroup;
|
||||||
|
|
||||||
if(pTilemap->m_Flags & TILESLAYERFLAG_GAME)
|
// 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_pGameLayer = pTilemap;
|
m_pGameGroup->m_UseClipping = 0;
|
||||||
m_pGameGroup = pGroup;
|
m_pGameGroup->m_ClipX = 0;
|
||||||
|
m_pGameGroup->m_ClipY = 0;
|
||||||
// make sure the game group has standard settings
|
m_pGameGroup->m_ClipW = 0;
|
||||||
m_pGameGroup->m_OffsetX = 0;
|
m_pGameGroup->m_ClipH = 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
IsEntities = true;
|
|
||||||
//break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IsEntities = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!GameOnly)
|
||||||
|
{
|
||||||
if(pTilemap->m_Flags & TILESLAYERFLAG_TELE)
|
if(pTilemap->m_Flags & TILESLAYERFLAG_TELE)
|
||||||
{
|
{
|
||||||
if(pTilemap->m_Version <= 2)
|
if(pTilemap->m_Version <= 2)
|
||||||
|
@ -63,6 +65,7 @@ void CLayers::Init(class IKernel *pKernel)
|
||||||
m_pTeleLayer = pTilemap;
|
m_pTeleLayer = pTilemap;
|
||||||
IsEntities = true;
|
IsEntities = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(pTilemap->m_Flags & TILESLAYERFLAG_SPEEDUP)
|
if(pTilemap->m_Flags & TILESLAYERFLAG_SPEEDUP)
|
||||||
{
|
{
|
||||||
if(pTilemap->m_Version <= 2)
|
if(pTilemap->m_Version <= 2)
|
||||||
|
@ -72,6 +75,7 @@ void CLayers::Init(class IKernel *pKernel)
|
||||||
m_pSpeedupLayer = pTilemap;
|
m_pSpeedupLayer = pTilemap;
|
||||||
IsEntities = true;
|
IsEntities = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(pTilemap->m_Flags & TILESLAYERFLAG_FRONT)
|
if(pTilemap->m_Flags & TILESLAYERFLAG_FRONT)
|
||||||
{
|
{
|
||||||
if(pTilemap->m_Version <= 2)
|
if(pTilemap->m_Version <= 2)
|
||||||
|
@ -81,6 +85,7 @@ void CLayers::Init(class IKernel *pKernel)
|
||||||
m_pFrontLayer = pTilemap;
|
m_pFrontLayer = pTilemap;
|
||||||
IsEntities = true;
|
IsEntities = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(pTilemap->m_Flags & TILESLAYERFLAG_SWITCH)
|
if(pTilemap->m_Flags & TILESLAYERFLAG_SWITCH)
|
||||||
{
|
{
|
||||||
if(pTilemap->m_Version <= 2)
|
if(pTilemap->m_Version <= 2)
|
||||||
|
@ -90,6 +95,7 @@ void CLayers::Init(class IKernel *pKernel)
|
||||||
m_pSwitchLayer = pTilemap;
|
m_pSwitchLayer = pTilemap;
|
||||||
IsEntities = true;
|
IsEntities = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(pTilemap->m_Flags & TILESLAYERFLAG_TUNE)
|
if(pTilemap->m_Flags & TILESLAYERFLAG_TUNE)
|
||||||
{
|
{
|
||||||
if(pTilemap->m_Version <= 2)
|
if(pTilemap->m_Version <= 2)
|
||||||
|
@ -99,58 +105,12 @@ void CLayers::Init(class IKernel *pKernel)
|
||||||
m_pTuneLayer = pTilemap;
|
m_pTuneLayer = pTilemap;
|
||||||
IsEntities = true;
|
IsEntities = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(IsEntities)
|
|
||||||
{ // Ensure default color for entities layers
|
|
||||||
pTilemap->m_Color = CColor(255, 255, 255, 255);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
InitTilemapSkip();
|
if(IsEntities)
|
||||||
}
|
|
||||||
|
|
||||||
void CLayers::InitBackground(class IMap *pMap)
|
|
||||||
{
|
|
||||||
Unload();
|
|
||||||
|
|
||||||
m_pMap = pMap;
|
|
||||||
m_pMap->GetType(MAPITEMTYPE_GROUP, &m_GroupsStart, &m_GroupsNum);
|
|
||||||
m_pMap->GetType(MAPITEMTYPE_LAYER, &m_LayersStart, &m_LayersNum);
|
|
||||||
|
|
||||||
for(int g = 0; g < NumGroups(); g++)
|
|
||||||
{
|
|
||||||
CMapItemGroup *pGroup = GetGroup(g);
|
|
||||||
for(int l = 0; l < pGroup->m_NumLayers; l++)
|
|
||||||
{
|
|
||||||
CMapItemLayer *pLayer = GetLayer(pGroup->m_StartLayer + l);
|
|
||||||
|
|
||||||
if(pLayer->m_Type == LAYERTYPE_TILES)
|
|
||||||
{
|
{
|
||||||
CMapItemLayerTilemap *pTilemap = reinterpret_cast<CMapItemLayerTilemap *>(pLayer);
|
// Ensure default color for entities layers
|
||||||
|
pTilemap->m_Color = CColor(255, 255, 255, 255);
|
||||||
if(pTilemap->m_Flags & TILESLAYERFLAG_GAME)
|
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
//We don't care about tile layers.
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -178,32 +138,30 @@ void CLayers::Unload()
|
||||||
|
|
||||||
void CLayers::InitTilemapSkip()
|
void CLayers::InitTilemapSkip()
|
||||||
{
|
{
|
||||||
for(int g = 0; g < NumGroups(); g++)
|
for(int GroupIndex = 0; GroupIndex < NumGroups(); GroupIndex++)
|
||||||
{
|
{
|
||||||
const CMapItemGroup *pGroup = GetGroup(g);
|
const CMapItemGroup *pGroup = GetGroup(GroupIndex);
|
||||||
|
for(int LayerIndex = 0; LayerIndex < pGroup->m_NumLayers; LayerIndex++)
|
||||||
for(int l = 0; l < pGroup->m_NumLayers; l++)
|
|
||||||
{
|
{
|
||||||
const CMapItemLayer *pLayer = GetLayer(pGroup->m_StartLayer + l);
|
const CMapItemLayer *pLayer = GetLayer(pGroup->m_StartLayer + LayerIndex);
|
||||||
|
if(pLayer->m_Type != LAYERTYPE_TILES)
|
||||||
|
continue;
|
||||||
|
|
||||||
if(pLayer->m_Type == LAYERTYPE_TILES)
|
const CMapItemLayerTilemap *pTilemap = reinterpret_cast<const CMapItemLayerTilemap *>(pLayer);
|
||||||
|
CTile *pTiles = static_cast<CTile *>(m_pMap->GetData(pTilemap->m_Data));
|
||||||
|
for(int y = 0; y < pTilemap->m_Height; y++)
|
||||||
{
|
{
|
||||||
const CMapItemLayerTilemap *pTilemap = (CMapItemLayerTilemap *)pLayer;
|
for(int x = 1; x < pTilemap->m_Width;)
|
||||||
CTile *pTiles = (CTile *)m_pMap->GetData(pTilemap->m_Data);
|
|
||||||
for(int y = 0; y < pTilemap->m_Height; y++)
|
|
||||||
{
|
{
|
||||||
for(int x = 1; x < pTilemap->m_Width;)
|
int SkippedX;
|
||||||
|
for(SkippedX = 1; x + SkippedX < pTilemap->m_Width && SkippedX < 255; SkippedX++)
|
||||||
{
|
{
|
||||||
int SkippedX;
|
if(pTiles[y * pTilemap->m_Width + x + SkippedX].m_Index)
|
||||||
for(SkippedX = 1; x + SkippedX < pTilemap->m_Width && SkippedX < 255; SkippedX++)
|
break;
|
||||||
{
|
|
||||||
if(pTiles[y * pTilemap->m_Width + x + SkippedX].m_Index)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
pTiles[y * pTilemap->m_Width + x].m_Skip = SkippedX - 1;
|
|
||||||
x += SkippedX;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pTiles[y * pTilemap->m_Width + x].m_Skip = SkippedX - 1;
|
||||||
|
x += SkippedX;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
#ifndef GAME_LAYERS_H
|
#ifndef GAME_LAYERS_H
|
||||||
#define GAME_LAYERS_H
|
#define GAME_LAYERS_H
|
||||||
|
|
||||||
class IKernel;
|
|
||||||
class IMap;
|
class IMap;
|
||||||
|
|
||||||
struct CMapItemGroup;
|
struct CMapItemGroup;
|
||||||
|
@ -14,8 +13,7 @@ class CLayers
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CLayers();
|
CLayers();
|
||||||
void Init(IKernel *pKernel);
|
void Init(IMap *pMap, bool GameOnly);
|
||||||
void InitBackground(IMap *pMap);
|
|
||||||
void Unload();
|
void Unload();
|
||||||
|
|
||||||
int NumGroups() const { return m_GroupsNum; }
|
int NumGroups() const { return m_GroupsNum; }
|
||||||
|
|
|
@ -3862,7 +3862,7 @@ void CGameContext::OnInit(const void *pPersistentData)
|
||||||
for(int i = 0; i < NUM_NETOBJTYPES; i++)
|
for(int i = 0; i < NUM_NETOBJTYPES; i++)
|
||||||
Server()->SnapSetStaticsize(i, m_NetObjHandler.GetObjSize(i));
|
Server()->SnapSetStaticsize(i, m_NetObjHandler.GetObjSize(i));
|
||||||
|
|
||||||
m_Layers.Init(Kernel());
|
m_Layers.Init(Kernel()->RequestInterface<IMap>(), false);
|
||||||
m_Collision.Init(&m_Layers);
|
m_Collision.Init(&m_Layers);
|
||||||
m_World.m_pTuningList = m_aTuningList;
|
m_World.m_pTuningList = m_aTuningList;
|
||||||
m_World.m_Core.InitSwitchers(m_Collision.m_HighestSwitchNumber);
|
m_World.m_Core.InitSwitchers(m_Collision.m_HighestSwitchNumber);
|
||||||
|
|
Loading…
Reference in a new issue