From 14d383ef157c7309754f45f1f3966c3abd488c5e Mon Sep 17 00:00:00 2001 From: Jupeyy Date: Wed, 26 Aug 2020 15:06:51 +0200 Subject: [PATCH] Fix background map loading --- src/game/client/components/background.cpp | 10 ++++++++-- src/game/client/components/mapimages.cpp | 16 ++++++++++------ src/game/client/components/mapimages.h | 3 ++- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/game/client/components/background.cpp b/src/game/client/components/background.cpp index 1d35dfa03..40282a30b 100644 --- a/src/game/client/components/background.cpp +++ b/src/game/client/components/background.cpp @@ -50,14 +50,16 @@ void CBackground::LoadBackground() m_pLayers = m_pBackgroundLayers; m_pImages = m_pBackgroundImages; + bool NeedImageLoading = false; + str_copy(m_aMapName, g_Config.m_ClBackgroundEntities, sizeof(m_aMapName)); char aBuf[128]; str_format(aBuf, sizeof(aBuf), "maps/%s", g_Config.m_ClBackgroundEntities); if(m_pMap->Load(aBuf)) { m_pLayers->InitBackground(m_pMap); - m_pImages->LoadBackground(m_pMap); RenderTools()->RenderTilemapGenerateSkip(m_pLayers); + NeedImageLoading = true; m_Loaded = true; } else if(str_comp(g_Config.m_ClBackgroundEntities, CURRENT) == 0) @@ -71,8 +73,12 @@ void CBackground::LoadBackground() } } - if(m_Loaded) + if(m_Loaded) + { CMapLayers::OnMapLoad(); + if(NeedImageLoading) + m_pImages->LoadBackground(m_pLayers, m_pMap); + } m_LastLoad = time_get(); } diff --git a/src/game/client/components/mapimages.cpp b/src/game/client/components/mapimages.cpp index f0b8f77e3..f44dcf0bb 100644 --- a/src/game/client/components/mapimages.cpp +++ b/src/game/client/components/mapimages.cpp @@ -29,10 +29,8 @@ void CMapImages::OnInit() InitOverlayTextures(); } -void CMapImages::OnMapLoad() +void CMapImages::OnMapLoadImpl(class CLayers *pLayers, IMap *pMap) { - IMap *pMap = Kernel()->RequestInterface(); - // unload all textures for(int i = 0; i < m_Count; i++) { @@ -45,7 +43,6 @@ void CMapImages::OnMapLoad() int Start; pMap->GetType(MAPITEMTYPE_IMAGE, &Start, &m_Count); - CLayers *pLayers = m_pClient->Layers(); for(int g = 0; g < pLayers->NumGroups(); g++) { CMapItemGroup *pGroup = pLayers->GetGroup(g); @@ -99,9 +96,16 @@ void CMapImages::OnMapLoad() } } -void CMapImages::LoadBackground(class IMap *pMap) +void CMapImages::OnMapLoad() { - CMapImages::OnMapLoad(); + IMap *pMap = Kernel()->RequestInterface(); + CLayers *pLayers = m_pClient->Layers(); + OnMapLoadImpl(pLayers, pMap); +} + +void CMapImages::LoadBackground(class CLayers *pLayers, class IMap *pMap) +{ + OnMapLoadImpl(pLayers, pMap); } IGraphics::CTextureHandle CMapImages::GetEntities() diff --git a/src/game/client/components/mapimages.h b/src/game/client/components/mapimages.h index 099730f5f..107cd7488 100644 --- a/src/game/client/components/mapimages.h +++ b/src/game/client/components/mapimages.h @@ -20,9 +20,10 @@ public: IGraphics::CTextureHandle Get(int Index) const { return m_aTextures[Index]; } int Num() const { return m_Count; } + void OnMapLoadImpl(class CLayers *pLayers, class IMap *pMap); virtual void OnMapLoad(); virtual void OnInit(); - void LoadBackground(class IMap *pMap); + void LoadBackground(class CLayers *pLayers, class IMap *pMap); // DDRace IGraphics::CTextureHandle GetEntities();