mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-17 13:38:18 +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))
|
||||
{
|
||||
m_pLayers->InitBackground(m_pMap);
|
||||
m_pLayers->Init(m_pMap, true);
|
||||
NeedImageLoading = true;
|
||||
m_Loaded = true;
|
||||
}
|
||||
|
|
|
@ -254,7 +254,7 @@ void CMenuBackground::LoadMenuBackground(bool HasDayHint, bool HasNightHint)
|
|||
|
||||
if(m_Loaded)
|
||||
{
|
||||
m_pLayers->InitBackground(m_pMap);
|
||||
m_pLayers->Init(m_pMap, true);
|
||||
|
||||
CMapLayers::OnMapLoad();
|
||||
m_pImages->LoadBackground(m_pLayers, m_pMap);
|
||||
|
|
|
@ -532,7 +532,7 @@ void CGameClient::OnConnected()
|
|||
const char *pLoadMapContent = Localize("Initializing map logic");
|
||||
// render loading before skip is calculated
|
||||
m_Menus.RenderLoading(pConnectCaption, pLoadMapContent, 0, false);
|
||||
m_Layers.Init(Kernel());
|
||||
m_Layers.Init(Kernel()->RequestInterface<IMap>(), false);
|
||||
m_Collision.Init(Layers());
|
||||
m_GameWorld.m_Core.InitSwitchers(m_Collision.m_HighestSwitchNumber);
|
||||
m_RaceHelper.Init(this);
|
||||
|
|
|
@ -11,23 +11,23 @@ CLayers::CLayers()
|
|||
Unload();
|
||||
}
|
||||
|
||||
void CLayers::Init(class IKernel *pKernel)
|
||||
void CLayers::Init(IMap *pMap, bool GameOnly)
|
||||
{
|
||||
Unload();
|
||||
|
||||
m_pMap = pKernel->RequestInterface<IMap>();
|
||||
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++)
|
||||
for(int GroupIndex = 0; GroupIndex < NumGroups(); GroupIndex++)
|
||||
{
|
||||
CMapItemGroup *pGroup = GetGroup(g);
|
||||
for(int l = 0; l < pGroup->m_NumLayers; l++)
|
||||
CMapItemGroup *pGroup = GetGroup(GroupIndex);
|
||||
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;
|
||||
|
||||
|
@ -52,8 +52,10 @@ void CLayers::Init(class IKernel *pKernel)
|
|||
}
|
||||
|
||||
IsEntities = true;
|
||||
//break;
|
||||
}
|
||||
|
||||
if(!GameOnly)
|
||||
{
|
||||
if(pTilemap->m_Flags & TILESLAYERFLAG_TELE)
|
||||
{
|
||||
if(pTilemap->m_Version <= 2)
|
||||
|
@ -63,6 +65,7 @@ void CLayers::Init(class IKernel *pKernel)
|
|||
m_pTeleLayer = pTilemap;
|
||||
IsEntities = true;
|
||||
}
|
||||
|
||||
if(pTilemap->m_Flags & TILESLAYERFLAG_SPEEDUP)
|
||||
{
|
||||
if(pTilemap->m_Version <= 2)
|
||||
|
@ -72,6 +75,7 @@ void CLayers::Init(class IKernel *pKernel)
|
|||
m_pSpeedupLayer = pTilemap;
|
||||
IsEntities = true;
|
||||
}
|
||||
|
||||
if(pTilemap->m_Flags & TILESLAYERFLAG_FRONT)
|
||||
{
|
||||
if(pTilemap->m_Version <= 2)
|
||||
|
@ -81,6 +85,7 @@ void CLayers::Init(class IKernel *pKernel)
|
|||
m_pFrontLayer = pTilemap;
|
||||
IsEntities = true;
|
||||
}
|
||||
|
||||
if(pTilemap->m_Flags & TILESLAYERFLAG_SWITCH)
|
||||
{
|
||||
if(pTilemap->m_Version <= 2)
|
||||
|
@ -90,6 +95,7 @@ void CLayers::Init(class IKernel *pKernel)
|
|||
m_pSwitchLayer = pTilemap;
|
||||
IsEntities = true;
|
||||
}
|
||||
|
||||
if(pTilemap->m_Flags & TILESLAYERFLAG_TUNE)
|
||||
{
|
||||
if(pTilemap->m_Version <= 2)
|
||||
|
@ -99,61 +105,15 @@ void CLayers::Init(class IKernel *pKernel)
|
|||
m_pTuneLayer = pTilemap;
|
||||
IsEntities = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(IsEntities)
|
||||
{ // Ensure default color for entities layers
|
||||
{
|
||||
// Ensure default color for entities layers
|
||||
pTilemap->m_Color = CColor(255, 255, 255, 255);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
InitTilemapSkip();
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
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.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
InitTilemapSkip();
|
||||
}
|
||||
|
@ -178,18 +138,17 @@ void CLayers::Unload()
|
|||
|
||||
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++)
|
||||
{
|
||||
const CMapItemLayer *pLayer = GetLayer(pGroup->m_StartLayer + LayerIndex);
|
||||
if(pLayer->m_Type != LAYERTYPE_TILES)
|
||||
continue;
|
||||
|
||||
for(int l = 0; l < pGroup->m_NumLayers; l++)
|
||||
{
|
||||
const CMapItemLayer *pLayer = GetLayer(pGroup->m_StartLayer + l);
|
||||
|
||||
if(pLayer->m_Type == LAYERTYPE_TILES)
|
||||
{
|
||||
const CMapItemLayerTilemap *pTilemap = (CMapItemLayerTilemap *)pLayer;
|
||||
CTile *pTiles = (CTile *)m_pMap->GetData(pTilemap->m_Data);
|
||||
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++)
|
||||
{
|
||||
for(int x = 1; x < pTilemap->m_Width;)
|
||||
|
@ -208,7 +167,6 @@ void CLayers::InitTilemapSkip()
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CMapItemGroup *CLayers::GetGroup(int Index) const
|
||||
{
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
#ifndef GAME_LAYERS_H
|
||||
#define GAME_LAYERS_H
|
||||
|
||||
class IKernel;
|
||||
class IMap;
|
||||
|
||||
struct CMapItemGroup;
|
||||
|
@ -14,8 +13,7 @@ class CLayers
|
|||
{
|
||||
public:
|
||||
CLayers();
|
||||
void Init(IKernel *pKernel);
|
||||
void InitBackground(IMap *pMap);
|
||||
void Init(IMap *pMap, bool GameOnly);
|
||||
void Unload();
|
||||
|
||||
int NumGroups() const { return m_GroupsNum; }
|
||||
|
|
|
@ -3862,7 +3862,7 @@ void CGameContext::OnInit(const void *pPersistentData)
|
|||
for(int i = 0; i < NUM_NETOBJTYPES; 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_World.m_pTuningList = m_aTuningList;
|
||||
m_World.m_Core.InitSwitchers(m_Collision.m_HighestSwitchNumber);
|
||||
|
|
Loading…
Reference in a new issue