Merge pull request #9152 from Robyt3/CLayers-Refactoring

Minor refactoring of `CLayers`
This commit is contained in:
Dennis Felsing 2024-10-15 20:56:55 +00:00 committed by GitHub
commit 3e9ca3314f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 61 additions and 105 deletions

View file

@ -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;
}

View file

@ -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);

View file

@ -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);

View file

@ -11,49 +11,51 @@ 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;
if(pTilemap->m_Flags & TILESLAYERFLAG_GAME)
{
CMapItemLayerTilemap *pTilemap = reinterpret_cast<CMapItemLayerTilemap *>(pLayer);
bool IsEntities = false;
m_pGameLayer = pTilemap;
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 = 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;
}
IsEntities = true;
//break;
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;
}
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,58 +105,12 @@ void CLayers::Init(class IKernel *pKernel)
m_pTuneLayer = pTilemap;
IsEntities = true;
}
if(IsEntities)
{ // 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)
if(IsEntities)
{
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.
}
// Ensure default color for entities layers
pTilemap->m_Color = CColor(255, 255, 255, 255);
}
}
}
@ -178,32 +138,30 @@ 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);
for(int l = 0; l < pGroup->m_NumLayers; l++)
const CMapItemGroup *pGroup = GetGroup(GroupIndex);
for(int LayerIndex = 0; LayerIndex < pGroup->m_NumLayers; LayerIndex++)
{
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;
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;)
{
for(int x = 1; x < pTilemap->m_Width;)
int SkippedX;
for(SkippedX = 1; x + SkippedX < pTilemap->m_Width && SkippedX < 255; SkippedX++)
{
int SkippedX;
for(SkippedX = 1; x + SkippedX < pTilemap->m_Width && SkippedX < 255; SkippedX++)
{
if(pTiles[y * pTilemap->m_Width + x + SkippedX].m_Index)
break;
}
pTiles[y * pTilemap->m_Width + x].m_Skip = SkippedX - 1;
x += SkippedX;
if(pTiles[y * pTilemap->m_Width + x + SkippedX].m_Index)
break;
}
pTiles[y * pTilemap->m_Width + x].m_Skip = SkippedX - 1;
x += SkippedX;
}
}
}

View file

@ -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; }

View file

@ -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);