2015-08-27 14:28:25 +00:00
|
|
|
#include <base/system.h>
|
|
|
|
|
|
|
|
#include <engine/graphics.h>
|
2020-09-26 19:41:58 +00:00
|
|
|
#include <engine/map.h>
|
|
|
|
#include <engine/shared/config.h>
|
2015-08-27 14:28:25 +00:00
|
|
|
|
|
|
|
#include <game/client/components/camera.h>
|
|
|
|
#include <game/client/components/mapimages.h>
|
2020-09-26 19:41:58 +00:00
|
|
|
#include <game/client/components/maplayers.h>
|
2015-08-27 14:28:25 +00:00
|
|
|
|
2021-07-12 09:29:59 +00:00
|
|
|
#include <game/client/gameclient.h>
|
|
|
|
#include <game/layers.h>
|
|
|
|
|
2015-08-27 14:28:25 +00:00
|
|
|
#include "background.h"
|
|
|
|
|
2020-09-26 19:41:58 +00:00
|
|
|
CBackground::CBackground(int MapType, bool OnlineOnly) :
|
|
|
|
CMapLayers(MapType, OnlineOnly)
|
2015-08-27 14:28:25 +00:00
|
|
|
{
|
2017-09-12 18:13:53 +00:00
|
|
|
m_pLayers = new CLayers;
|
|
|
|
m_pBackgroundLayers = m_pLayers;
|
2015-08-27 14:28:25 +00:00
|
|
|
m_pImages = new CMapImages;
|
|
|
|
m_pBackgroundImages = m_pImages;
|
|
|
|
m_Loaded = false;
|
|
|
|
m_aMapName[0] = '\0';
|
2017-12-03 07:01:17 +00:00
|
|
|
m_LastLoad = 0;
|
2015-08-27 14:28:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CBackground::~CBackground()
|
|
|
|
{
|
2017-09-12 18:13:53 +00:00
|
|
|
delete m_pBackgroundLayers;
|
|
|
|
delete m_pBackgroundImages;
|
2015-08-27 14:28:25 +00:00
|
|
|
}
|
|
|
|
|
2020-09-18 16:45:42 +00:00
|
|
|
CBackgroundEngineMap *CBackground::CreateBGMap()
|
|
|
|
{
|
|
|
|
return new CBackgroundEngineMap;
|
|
|
|
}
|
|
|
|
|
2015-08-27 14:28:25 +00:00
|
|
|
void CBackground::OnInit()
|
|
|
|
{
|
2020-10-10 10:12:04 +00:00
|
|
|
m_pBackgroundMap = CreateBGMap();
|
|
|
|
m_pMap = m_pBackgroundMap;
|
|
|
|
|
2015-08-27 14:28:25 +00:00
|
|
|
m_pImages->m_pClient = GameClient();
|
2020-09-18 16:45:42 +00:00
|
|
|
Kernel()->RegisterInterface(m_pBackgroundMap);
|
2020-10-02 14:21:18 +00:00
|
|
|
if(g_Config.m_ClBackgroundEntities[0] != '\0' && str_comp(g_Config.m_ClBackgroundEntities, CURRENT_MAP))
|
2015-08-27 14:28:25 +00:00
|
|
|
LoadBackground();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBackground::LoadBackground()
|
|
|
|
{
|
2020-09-26 19:41:58 +00:00
|
|
|
if(time_get() - m_LastLoad < 10 * time_freq())
|
2015-08-27 14:28:25 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if(m_Loaded && m_pMap == m_pBackgroundMap)
|
|
|
|
m_pMap->Unload();
|
|
|
|
|
|
|
|
m_Loaded = false;
|
|
|
|
m_pMap = m_pBackgroundMap;
|
2017-09-12 18:13:53 +00:00
|
|
|
m_pLayers = m_pBackgroundLayers;
|
2015-08-27 14:28:25 +00:00
|
|
|
m_pImages = m_pBackgroundImages;
|
|
|
|
|
2020-08-29 10:10:38 +00:00
|
|
|
bool NeedImageLoading = false;
|
|
|
|
|
2016-05-02 19:35:32 +00:00
|
|
|
str_copy(m_aMapName, g_Config.m_ClBackgroundEntities, sizeof(m_aMapName));
|
2015-08-27 14:28:25 +00:00
|
|
|
char aBuf[128];
|
|
|
|
str_format(aBuf, sizeof(aBuf), "maps/%s", g_Config.m_ClBackgroundEntities);
|
2020-10-02 14:23:16 +00:00
|
|
|
if(str_comp(g_Config.m_ClBackgroundEntities, CURRENT_MAP) == 0)
|
2015-08-27 14:28:25 +00:00
|
|
|
{
|
2015-08-27 14:32:45 +00:00
|
|
|
m_pMap = Kernel()->RequestInterface<IEngineMap>();
|
2017-12-03 10:50:43 +00:00
|
|
|
if(m_pMap->IsLoaded())
|
2017-12-03 07:01:17 +00:00
|
|
|
{
|
|
|
|
m_pLayers = GameClient()->Layers();
|
2021-07-12 09:43:56 +00:00
|
|
|
m_pImages = &GameClient()->m_MapImages;
|
2017-12-03 07:01:17 +00:00
|
|
|
m_Loaded = true;
|
|
|
|
}
|
2015-08-27 14:28:25 +00:00
|
|
|
}
|
2020-10-02 14:23:16 +00:00
|
|
|
else if(m_pMap->Load(aBuf))
|
|
|
|
{
|
|
|
|
m_pLayers->InitBackground(m_pMap);
|
|
|
|
NeedImageLoading = true;
|
|
|
|
m_Loaded = true;
|
|
|
|
}
|
2020-09-18 16:45:42 +00:00
|
|
|
|
2020-08-29 10:10:38 +00:00
|
|
|
if(m_Loaded)
|
|
|
|
{
|
2017-09-12 18:13:53 +00:00
|
|
|
CMapLayers::OnMapLoad();
|
2020-08-29 10:10:38 +00:00
|
|
|
if(NeedImageLoading)
|
|
|
|
m_pImages->LoadBackground(m_pLayers, m_pMap);
|
|
|
|
}
|
2015-08-27 14:28:25 +00:00
|
|
|
|
|
|
|
m_LastLoad = time_get();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBackground::OnMapLoad()
|
|
|
|
{
|
2020-10-02 14:21:18 +00:00
|
|
|
if(str_comp(g_Config.m_ClBackgroundEntities, CURRENT_MAP) == 0 || str_comp(g_Config.m_ClBackgroundEntities, m_aMapName))
|
2017-12-03 07:01:17 +00:00
|
|
|
{
|
|
|
|
m_LastLoad = 0;
|
2015-08-27 14:28:25 +00:00
|
|
|
LoadBackground();
|
2017-12-03 07:01:17 +00:00
|
|
|
}
|
2015-08-27 14:28:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CBackground::OnRender()
|
|
|
|
{
|
|
|
|
//probably not the best place for this
|
2016-05-02 19:35:32 +00:00
|
|
|
if(g_Config.m_ClBackgroundEntities[0] != '\0' && str_comp(g_Config.m_ClBackgroundEntities, m_aMapName))
|
2015-08-27 14:28:25 +00:00
|
|
|
LoadBackground();
|
|
|
|
|
|
|
|
if(!m_Loaded)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(Client()->State() != IClient::STATE_ONLINE && Client()->State() != IClient::STATE_DEMOPLAYBACK)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(g_Config.m_ClOverlayEntities != 100)
|
|
|
|
return;
|
2020-09-26 19:41:58 +00:00
|
|
|
|
2017-09-12 18:13:53 +00:00
|
|
|
CMapLayers::OnRender();
|
2015-08-27 14:28:25 +00:00
|
|
|
}
|