1 | #include <base/system.h> |
2 | |
3 | #include <engine/map.h> |
4 | #include <engine/shared/config.h> |
5 | |
6 | #include <game/client/components/mapimages.h> |
7 | #include <game/client/components/maplayers.h> |
8 | |
9 | #include <game/client/gameclient.h> |
10 | #include <game/layers.h> |
11 | |
12 | #include "background.h" |
13 | |
14 | CBackground::CBackground(int MapType, bool OnlineOnly) : |
15 | CMapLayers(MapType, OnlineOnly) |
16 | { |
17 | m_pLayers = new CLayers; |
18 | m_pBackgroundLayers = m_pLayers; |
19 | m_pImages = new CMapImages; |
20 | m_pBackgroundImages = m_pImages; |
21 | m_Loaded = false; |
22 | m_aMapName[0] = '\0'; |
23 | } |
24 | |
25 | CBackground::~CBackground() |
26 | { |
27 | delete m_pBackgroundLayers; |
28 | delete m_pBackgroundImages; |
29 | } |
30 | |
31 | CBackgroundEngineMap *CBackground::CreateBGMap() |
32 | { |
33 | return new CBackgroundEngineMap; |
34 | } |
35 | |
36 | void CBackground::OnInit() |
37 | { |
38 | m_pBackgroundMap = CreateBGMap(); |
39 | m_pMap = m_pBackgroundMap; |
40 | |
41 | m_pImages->m_pClient = GameClient(); |
42 | Kernel()->RegisterInterface(pInterface: m_pBackgroundMap); |
43 | if(g_Config.m_ClBackgroundEntities[0] != '\0' && str_comp(a: g_Config.m_ClBackgroundEntities, CURRENT_MAP)) |
44 | LoadBackground(); |
45 | } |
46 | |
47 | void CBackground::LoadBackground() |
48 | { |
49 | if(m_Loaded && m_pMap == m_pBackgroundMap) |
50 | m_pMap->Unload(); |
51 | |
52 | m_Loaded = false; |
53 | m_pMap = m_pBackgroundMap; |
54 | m_pLayers = m_pBackgroundLayers; |
55 | m_pImages = m_pBackgroundImages; |
56 | |
57 | str_copy(dst&: m_aMapName, src: g_Config.m_ClBackgroundEntities); |
58 | if(g_Config.m_ClBackgroundEntities[0] != '\0') |
59 | { |
60 | bool NeedImageLoading = false; |
61 | |
62 | char aBuf[IO_MAX_PATH_LENGTH]; |
63 | str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "maps/%s%s" , g_Config.m_ClBackgroundEntities, str_endswith(str: g_Config.m_ClBackgroundEntities, suffix: ".map" ) ? "" : ".map" ); |
64 | if(str_comp(a: g_Config.m_ClBackgroundEntities, CURRENT_MAP) == 0) |
65 | { |
66 | m_pMap = Kernel()->RequestInterface<IEngineMap>(); |
67 | if(m_pMap->IsLoaded()) |
68 | { |
69 | m_pLayers = GameClient()->Layers(); |
70 | m_pImages = &GameClient()->m_MapImages; |
71 | m_Loaded = true; |
72 | } |
73 | } |
74 | else if(m_pMap->Load(pMapName: aBuf)) |
75 | { |
76 | m_pLayers->InitBackground(pMap: m_pMap); |
77 | NeedImageLoading = true; |
78 | m_Loaded = true; |
79 | } |
80 | |
81 | if(m_Loaded) |
82 | { |
83 | CMapLayers::OnMapLoad(); |
84 | if(NeedImageLoading) |
85 | m_pImages->LoadBackground(pLayers: m_pLayers, pMap: m_pMap); |
86 | } |
87 | } |
88 | } |
89 | |
90 | void CBackground::OnMapLoad() |
91 | { |
92 | if(str_comp(a: g_Config.m_ClBackgroundEntities, CURRENT_MAP) == 0 || str_comp(a: g_Config.m_ClBackgroundEntities, b: m_aMapName)) |
93 | { |
94 | LoadBackground(); |
95 | } |
96 | } |
97 | |
98 | void CBackground::OnRender() |
99 | { |
100 | if(!m_Loaded) |
101 | return; |
102 | |
103 | if(Client()->State() != IClient::STATE_ONLINE && Client()->State() != IClient::STATE_DEMOPLAYBACK) |
104 | return; |
105 | |
106 | if(g_Config.m_ClOverlayEntities != 100) |
107 | return; |
108 | |
109 | CMapLayers::OnRender(); |
110 | } |
111 | |