diff --git a/src/game/client/components/background.cpp b/src/game/client/components/background.cpp index 1d7c41c61..d0acd143e 100644 --- a/src/game/client/components/background.cpp +++ b/src/game/client/components/background.cpp @@ -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; } diff --git a/src/game/client/components/menu_background.cpp b/src/game/client/components/menu_background.cpp index a92f271f5..aa63454e8 100644 --- a/src/game/client/components/menu_background.cpp +++ b/src/game/client/components/menu_background.cpp @@ -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); diff --git a/src/game/client/gameclient.cpp b/src/game/client/gameclient.cpp index 4f811177a..23158a841 100644 --- a/src/game/client/gameclient.cpp +++ b/src/game/client/gameclient.cpp @@ -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(), false); m_Collision.Init(Layers()); m_GameWorld.m_Core.InitSwitchers(m_Collision.m_HighestSwitchNumber); m_RaceHelper.Init(this); diff --git a/src/game/layers.cpp b/src/game/layers.cpp index 52f97e079..a5a3f6a32 100644 --- a/src/game/layers.cpp +++ b/src/game/layers.cpp @@ -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(); + 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(pLayer); + bool IsEntities = false; + + if(pTilemap->m_Flags & TILESLAYERFLAG_GAME) { - CMapItemLayerTilemap *pTilemap = reinterpret_cast(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(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(pLayer); + CTile *pTiles = static_cast(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; } } } diff --git a/src/game/layers.h b/src/game/layers.h index 2ce957cc1..cc93a55ed 100644 --- a/src/game/layers.h +++ b/src/game/layers.h @@ -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; } diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index 6d9537f0b..092a19dc9 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -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(), false); m_Collision.Init(&m_Layers); m_World.m_pTuningList = m_aTuningList; m_World.m_Core.InitSwitchers(m_Collision.m_HighestSwitchNumber);