Horizon Official Technical Documentation
Horizon::Libraries::MapCache Class Reference

#include <MapCache.hpp>

Public Member Functions

 MapCache ()
 
 ~MapCache ()
 
mcache_error_type initialize ()
 
bool Exists ()
 
mcache_import_error_type ImportFromCacheFile ()
 
int BuildInternalCache ()
 
bool BuildExternalCache ()
 
bool AppendHeader ()
 
bool CreateNewCacheWithHeader ()
 
bool AppendToCache (std::string const &name)
 
bool GetMapFromGRF (GRF &grf, std::string const &name)
 Reads a map from GRF's GAT and RSW files. More...
 
bool ParseGRFReadResult (GRF &grf, std::string const &filename, grf_read_error_type error)
 
mcache_config_error_type ReadMapListConfig ()
 
mcache_grf_config_error_type ReadGRFListConfig ()
 
std::pair< uint8_t, grf_load_result_typeLoadGRFs ()
 
void PrintCacheForMap (std::string const &map_name)
 
GRFgetGRF (uint8_t id)
 
void addGRF (uint8_t id, GRF &grf)
 
boost::filesystem::path & getMapCachePath ()
 
void setMapCachePath (std::string const &file)
 
int getCompressionLevel ()
 
void setCompressionLevel (int level)
 
const boost::filesystem::path & getMapListPath () const
 
void setMapListPath (std::string const &path)
 
const boost::filesystem::path & getGRFListPath () const
 
void setGRFListPath (std::string const &path)
 
void addToMapList (std::string const &map)
 
const boost::filesystem::path & getGRFPath (uint8_t id)
 
void setGRFPath (uint8_t id, std::string const &path)
 
const boost::filesystem::path & getResourcePath ()
 
void setResourcePath (std::string const &path)
 
void setVerbose ()
 
void unsetVerbose ()
 
bool getVerbose ()
 
std::shared_ptr< map_cachegetMCache ()
 
const std::unordered_map< uint8_t, GRF > & getGRFs ()
 

Private Attributes

boost::filesystem::path _map_list_path
 
boost::filesystem::path _grf_list_path
 
boost::filesystem::path _resource_path
 
boost::filesystem::path _map_cache_path
 
std::unordered_map< uint8_t, GRF_grfs
 
int _compression_level {6}
 
std::map< std::string, map_data_map_cache_data
 
std::vector< std::string > _map_list
 
std::shared_ptr< map_cachem_cache
 
bool _verbose {false}
 

Constructor & Destructor Documentation

◆ MapCache()

Horizon::Libraries::MapCache::MapCache ( )
47: m_cache(std::make_shared<map_cache>())
48{
49}
std::shared_ptr< map_cache > m_cache
Definition: MapCache.hpp:241

◆ ~MapCache()

Horizon::Libraries::MapCache::~MapCache ( )
53{
54}

Member Function Documentation

◆ addGRF()

void Horizon::Libraries::MapCache::addGRF ( uint8_t  id,
GRF grf 
)
inline
195{ _grfs[id] = grf; }
std::unordered_map< uint8_t, GRF > _grfs
Definition: MapCache.hpp:237

References _grfs.

◆ addToMapList()

void Horizon::Libraries::MapCache::addToMapList ( std::string const &  map)
inline
214{ _map_list.push_back(map); }
std::vector< std::string > _map_list
Definition: MapCache.hpp:240

References _map_list.

◆ AppendHeader()

bool Horizon::Libraries::MapCache::AppendHeader ( )

◆ AppendToCache()

bool Horizon::Libraries::MapCache::AppendToCache ( std::string const &  name)

◆ BuildExternalCache()

bool Horizon::Libraries::MapCache::BuildExternalCache ( )
350{
351 std::ofstream ofs(getMapCachePath().c_str(), std::ios::out | std::ios::binary | std::ios::trunc);
352 unsigned long file_size = 0, compressed_size = 0;
353 uint8_t *uncompressed_buf, *compressed_buf;
354 int version = m_cache->getHeader().getVersion();
355 boost::crc_32_type crc_32;
356
357 // Pre-determine the file size.
358 for (auto m : m_cache->maps) {
359 map_data data = m.second;
360 file_size += sizeof(struct map_info) + data.info.length;
361 }
362
363 uncompressed_buf = new uint8_t[file_size];
364 compressed_buf = new uint8_t[file_size];
365 compressed_size = compressBound(file_size);
366
367 int pos = 0;
368 // Content
369 for (auto m : m_cache->maps) {
370 map_data data = m.second;
371 memcpy(uncompressed_buf + pos, &data.info, sizeof(data.info));
372 pos += sizeof(data.info);
373 memcpy(uncompressed_buf + pos, data.cells.data(), data.cells.size());
374 pos += data.cells.size();
375 PrintCacheForMap(m.first);
376 }
377
378 compress2((Bytef *) compressed_buf, &compressed_size, (const Bytef *) uncompressed_buf, file_size, getCompressionLevel());
379 crc_32.process_bytes(compressed_buf, compressed_size);
380
381 // Header
382 m_cache->getHeader().setMapCount(m_cache->maps.size());
383 m_cache->getHeader().setFileSize(file_size);
384 m_cache->getHeader().setVersion(++version);
385 m_cache->getHeader().setChecksum(crc_32.checksum());
386
387 ofs.write((char *) &m_cache->getHeader(), sizeof(mapcache_header));
388 ofs.write((char *) compressed_buf, compressed_size);
389
390 delete[] uncompressed_buf;
391 delete[] compressed_buf;
392 return true;
393}
int getCompressionLevel()
Definition: MapCache.hpp:202
void PrintCacheForMap(std::string const &map_name)
Definition: MapCache.cpp:304
boost::filesystem::path & getMapCachePath()
Definition: MapCache.hpp:198
Definition: MapCache.hpp:72
std::vector< uint8_t > cells
Definition: MapCache.hpp:80
map_info info
Definition: MapCache.hpp:79
Definition: MapCache.hpp:63
uint32_t length
Definition: MapCache.hpp:67
Definition: MapCache.hpp:42

References map_data::cells, mapcache_header::file_size, map_data::info, map_info::length, and mapcache_header::version.

Referenced by main().

+ Here is the caller graph for this function:

◆ BuildInternalCache()

int Horizon::Libraries::MapCache::BuildInternalCache ( )
285{
286 int new_maps = 0;
287
288 for (std::size_t i = 0; i < _map_list.size(); ++i) {
289 std::string map_name = _map_list.at(i);
290
291 if (!m_cache->getMap(map_name)) {
292 for (auto &grf : _grfs) {
293 if (GetMapFromGRF(grf.second, map_name)) {
294 new_maps++;
295 break;
296 }
297 }
298 }
299 }
300
301 return new_maps;
302}
bool GetMapFromGRF(GRF &grf, std::string const &name)
Reads a map from GRF's GAT and RSW files.
Definition: MapCache.cpp:423

Referenced by main().

+ Here is the caller graph for this function:

◆ CreateNewCacheWithHeader()

bool Horizon::Libraries::MapCache::CreateNewCacheWithHeader ( )

◆ Exists()

bool Horizon::Libraries::MapCache::Exists ( )
167{
168 std::ifstream ifs(getMapCachePath().c_str(), std::ios::in | std::ios::binary);
169 return ifs.good();
170}

Referenced by main().

+ Here is the caller graph for this function:

◆ getCompressionLevel()

int Horizon::Libraries::MapCache::getCompressionLevel ( )
inline
202{ return _compression_level; }
int _compression_level
Definition: MapCache.hpp:238

References _compression_level.

Referenced by main().

+ Here is the caller graph for this function:

◆ getGRF()

GRF & Horizon::Libraries::MapCache::getGRF ( uint8_t  id)
inline
194{ return _grfs.at(id); }

References _grfs.

◆ getGRFListPath()

const boost::filesystem::path & Horizon::Libraries::MapCache::getGRFListPath ( ) const
inline
210{ return _grf_list_path; }
boost::filesystem::path _grf_list_path
Definition: MapCache.hpp:235

References _grf_list_path.

◆ getGRFPath()

const boost::filesystem::path & Horizon::Libraries::MapCache::getGRFPath ( uint8_t  id)
inline
217{ return _grfs[id].getGRFPath(); }

References _grfs.

◆ getGRFs()

const std::unordered_map< uint8_t, GRF > & Horizon::Libraries::MapCache::getGRFs ( )
inline
232{ return _grfs; }

References _grfs.

◆ getMapCachePath()

boost::filesystem::path & Horizon::Libraries::MapCache::getMapCachePath ( )
inline
198{ return _map_cache_path; }
boost::filesystem::path _map_cache_path
Definition: MapCache.hpp:236

References _map_cache_path.

Referenced by Horizon::Zone::GameLogicProcess::load_map_cache(), and main().

+ Here is the caller graph for this function:

◆ GetMapFromGRF()

bool Horizon::Libraries::MapCache::GetMapFromGRF ( GRF grf,
std::string const &  name 
)

Reads a map from GRF's GAT and RSW files.

Parameters
[in]namename of the map.
Returns
true on success, false on failure.
424{
425 char filename[256];
426 std::pair<grf_read_error_type, uint8_t *> gat, rsw;
427 int water_height;
428 map_data m;
429
430 // Set the Map Name.
431 std::strncpy(m.info.name, name.c_str(), sizeof(m.info.name));
432
433 // Search and retrieve the map's GAT file.
434 std::sprintf(filename, "data\\%s.gat", name.c_str());
435
436 gat = grf.read(filename, nullptr);
437
438 if (!ParseGRFReadResult(grf, filename, gat.first))
439 return false;
440
441 // Search and retrieve the map's RSW file.
442 std::sprintf(filename, "data\\%s.rsw", name.c_str());
443
444 rsw = grf.read(filename, nullptr);
445
446 if (!ParseGRFReadResult(grf, filename, rsw.first))
447 return false;
448
449 // Determine the water height of the map.
450 if (rsw.second != nullptr) {
451 water_height = GetULong((unsigned char *) rsw.second + 166);
452 delete rsw.second;
453 } else
454 water_height = NO_WATER;
455
456 // Determine the map size and allocate needed memory.
457 m.info.total_x = (int16_t) GetULong((unsigned char *) (gat.second + 6));
458 m.info.total_y = (int16_t) GetULong((unsigned char *) (gat.second + 10));
459
460 if (m.info.total_x <= 0 || m.info.total_y <= 0) {
461 delete gat.second;
462 return false;
463 }
464
465 // Set the length of total map cell data as part of the each cache entry.
467
468 // Set cell information.
469 int offset = 14;
470
471 for (std::size_t i = 0; i < m.info.length; ++i) {
472 // Height of the bottom-left corner
473 // The actual start of the map.
474 float height = GetFloat((unsigned char *) (gat.second + offset));
475 // Type of cell
476 uint32_t type = GetULong((unsigned char *) (gat.second + offset + 16));
477
478 if (type == 0 && water_height != NO_WATER && height > water_height)
479 type = 3; // Cell is 0 (walkable) but under water level, set to 3 (walkable water)
480
481 offset += 20;
482
483 // Maps are stored starting (0, map_height), (1, map_height) ... (map_width, 0)
484 m.cells.push_back(type);
485 }
486
487 // Push into our internal cache.
488 m_cache->addMap(m);
489
490 delete gat.second;
491
492 return true;
493}
#define NO_WATER
Definition: MapCache.cpp:44
float GetFloat(const unsigned char *buf)
Definition: Utility.cpp:175
unsigned int GetULong(unsigned char *p)
Definition: Utility.cpp:169
std::pair< grf_read_error_type, uint8_t * > read(const char *in_name, int *size)
Definition: GRF.cpp:345
bool ParseGRFReadResult(GRF &grf, std::string const &filename, grf_read_error_type error)
Definition: MapCache.cpp:395
int16_t total_x
Definition: MapCache.hpp:65
char name[12]
Definition: MapCache.hpp:64
int16_t total_y
Definition: MapCache.hpp:66

References map_data::cells, GetFloat(), GetULong(), map_data::info, map_info::length, map_info::name, NO_WATER, GRF::read(), map_info::total_x, and map_info::total_y.

+ Here is the call graph for this function:

◆ getMapListPath()

const boost::filesystem::path & Horizon::Libraries::MapCache::getMapListPath ( ) const
inline
206{ return _map_list_path; }
boost::filesystem::path _map_list_path
Definition: MapCache.hpp:234

References _map_list_path.

Referenced by Horizon::Zone::GameLogicProcess::load_map_cache(), and main().

+ Here is the caller graph for this function:

◆ getMCache()

std::shared_ptr< map_cache > Horizon::Libraries::MapCache::getMCache ( )
inline
230{ return m_cache; }

References m_cache.

Referenced by Horizon::Zone::GameLogicProcess::load_map_cache(), and main().

+ Here is the caller graph for this function:

◆ getResourcePath()

const boost::filesystem::path & Horizon::Libraries::MapCache::getResourcePath ( )
inline
221{ return _resource_path; }
boost::filesystem::path _resource_path
Definition: MapCache.hpp:235

References _resource_path.

◆ getVerbose()

bool Horizon::Libraries::MapCache::getVerbose ( )
inline
227{ return _verbose; }
bool _verbose
Definition: MapCache.hpp:242

References _verbose.

◆ ImportFromCacheFile()

mcache_import_error_type Horizon::Libraries::MapCache::ImportFromCacheFile ( )
57{
58 std::ifstream ifs(getMapCachePath().c_str(), std::ios::in | std::ios::binary);
59 struct mapcache_header header;
60 uint8_t *compressed_buf, *uncompressed_buf;
61 unsigned long compressed_size = 0, uncompressed_size = 0;
62 boost::crc_32_type crc_32;
63
64 if (!ifs.good())
66
67 // Determine the File Size.
68 ifs.seekg(0, ifs.end);
69 compressed_size = ifs.tellg();
70 compressed_size -= sizeof(mapcache_header);
71 ifs.seekg(0, ifs.beg);
72
73 // Read Header.
74 if (!ifs.read((char *) &header, sizeof(mapcache_header)))
76
77 m_cache->setHeader(header);
78
79 // Compressed Size.
80 compressed_buf = new uint8_t[compressed_size];
81 memset(compressed_buf, '\0', compressed_size);
82
83 // Uncompressed Size.
84 uncompressed_size = header.getFileSize();
85 uncompressed_buf = new uint8_t[uncompressed_size];
86 memset(uncompressed_buf, '\0', uncompressed_size);
87
88 // Read the remaining size.
89 if (!ifs.read((char *) compressed_buf, compressed_size)) {
90 delete[] uncompressed_buf;
91 delete[] compressed_buf;
93 }
94
95 crc_32.process_bytes(compressed_buf, compressed_size);
96
97 if (crc_32.checksum() != m_cache->getHeader().getChecksum()) {
98 delete[] uncompressed_buf;
99 delete[] compressed_buf;
101 }
102
103 // Unpack the file.
104 if (uncompress((Bytef *) uncompressed_buf, &uncompressed_size, (const Bytef *) compressed_buf, compressed_size) != Z_OK) {
105 delete[] uncompressed_buf;
106 delete[] compressed_buf;
108 }
109
110 for (int i = 0, pos = 0; i < m_cache->getHeader().getMapCount(); ++i) {
111 map_data m{};
112 uint8_t *cells = nullptr;
113
114 if (memcpy(&m.info, uncompressed_buf + pos, sizeof(map_info)) == nullptr) {
115 delete[] uncompressed_buf;
116 delete[] compressed_buf;
118 }
119
120 cells = new uint8_t[m.info.length];
121 pos += sizeof(map_info);
122
123 if (memcpy(cells, uncompressed_buf + pos, m.info.length) == nullptr) {
124 delete[] cells;
125 delete[] uncompressed_buf;
126 delete[] compressed_buf;
128 }
129
130 for (uint32_t c = 0; c < m.info.length; ++c)
131 m.cells.push_back(cells[c]);
132
133 delete[] cells;
134
135 pos += m.info.length;
136
137 m_cache->addMap(m);
138 }
139
140 delete[] compressed_buf;
141 delete[] uncompressed_buf;
142
143 return MCACHE_IMPORT_OK;
144}
@ MCACHE_IMPORT_INVALID_CHECKSUM
Definition: MapCache.hpp:146
@ MCACHE_IMPORT_NONEXISTENT_FILE
Definition: MapCache.hpp:144
@ MCACHE_IMPORT_OK
Definition: MapCache.hpp:143
@ MCACHE_IMPORT_READ_ERROR
Definition: MapCache.hpp:145
@ MCACHE_IMPORT_DECOMPRESS_ERROR
Definition: MapCache.hpp:147
@ MCACHE_IMPORT_MAPINFO_ERROR
Definition: MapCache.hpp:148
@ MCACHE_IMPORT_CELLINFO_ERROR
Definition: MapCache.hpp:149
uint16_t getMapCount()
Definition: MapCache.hpp:46

References mapcache_header::getFileSize(), mapcache_header::getMapCount(), MCACHE_IMPORT_CELLINFO_ERROR, MCACHE_IMPORT_DECOMPRESS_ERROR, MCACHE_IMPORT_INVALID_CHECKSUM, MCACHE_IMPORT_MAPINFO_ERROR, MCACHE_IMPORT_NONEXISTENT_FILE, MCACHE_IMPORT_OK, and MCACHE_IMPORT_READ_ERROR.

Referenced by Horizon::Zone::GameLogicProcess::load_map_cache(), and main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ initialize()

mcache_error_type Horizon::Libraries::MapCache::initialize ( )
147{
148 if (getGRFListPath().empty())
150
151 if (getMapListPath().empty())
153
154 if (getMapCachePath().empty())
156
159
162
163 return MCACHE_OK;
164}
@ MCACHE_GRF_CONF_OK
Definition: MapCache.hpp:135
@ MCACHE_INVALID_OUTPUT_PATH
Definition: MapCache.hpp:120
@ MCACHE_INVALID_GRF_PATH
Definition: MapCache.hpp:118
@ MCACHE_CONFIG_READ_ERROR
Definition: MapCache.hpp:121
@ MCACHE_INVALID_CONFIG_PATH
Definition: MapCache.hpp:119
@ MCACHE_OK
Definition: MapCache.hpp:117
@ MCACHE_GRF_CONFIG_READ_ERROR
Definition: MapCache.hpp:122
@ MCACHE_CONFIG_OK
Definition: MapCache.hpp:128
const boost::filesystem::path & getGRFListPath() const
Definition: MapCache.hpp:210
mcache_config_error_type ReadMapListConfig()
Definition: MapCache.cpp:172
const boost::filesystem::path & getMapListPath() const
Definition: MapCache.hpp:206
mcache_grf_config_error_type ReadGRFListConfig()
Definition: MapCache.cpp:221

References MCACHE_CONFIG_OK, MCACHE_CONFIG_READ_ERROR, MCACHE_GRF_CONF_OK, MCACHE_GRF_CONFIG_READ_ERROR, MCACHE_INVALID_CONFIG_PATH, MCACHE_INVALID_GRF_PATH, MCACHE_INVALID_OUTPUT_PATH, and MCACHE_OK.

Referenced by main().

+ Here is the caller graph for this function:

◆ LoadGRFs()

std::pair< uint8_t, grf_load_result_type > Horizon::Libraries::MapCache::LoadGRFs ( )
274{
276
277 for (auto &grf : _grfs)
278 if ((res = grf.second.load()) != GRF_LOAD_OK)
279 return std::make_pair(grf.second.get_id(), res);
280
281 return std::pair<uint8_t, grf_load_result_type>(-1, GRF_LOAD_OK);
282}
grf_load_result_type
Definition: GRF.hpp:47
@ GRF_LOAD_OK
Definition: GRF.hpp:48

References GRF_LOAD_OK.

Referenced by main().

+ Here is the caller graph for this function:

◆ ParseGRFReadResult()

bool Horizon::Libraries::MapCache::ParseGRFReadResult ( GRF grf,
std::string const &  filename,
grf_read_error_type  error 
)
396{
397 std::string grf_name = grf.getGRFPath().filename().string();
398
399 switch (error)
400 {
401 case GRE_OK:
402 default:
403 break;
404 case GRE_NOT_FOUND:
405 printf("Warning: File '%s' could not be located in GRF '%s'.\n", filename.c_str(), grf_name.c_str());
406 return false;
408 printf("Warning: File '%s' decompressed size mismatch in GRF '%s'.\n", filename.c_str(), grf_name.c_str());
409 return false;
410 case GRE_READ_ERROR:
411 printf("Warning: File '%s' could not be read in GRF '%s'.\n", filename.c_str(), grf_name.c_str());
412 return false;
413 }
414
415 return true;
416}
@ GRE_READ_ERROR
Definition: GRF.hpp:69
@ GRE_NOT_FOUND
Definition: GRF.hpp:68
@ GRE_DECOMPRESS_SIZE_MISMATCH
Definition: GRF.hpp:70
@ GRE_OK
Definition: GRF.hpp:67
const boost::filesystem::path & getGRFPath() const
Definition: GRF.hpp:105

References GRF::getGRFPath(), GRE_DECOMPRESS_SIZE_MISMATCH, GRE_NOT_FOUND, GRE_OK, and GRE_READ_ERROR.

+ Here is the call graph for this function:

◆ PrintCacheForMap()

void Horizon::Libraries::MapCache::PrintCacheForMap ( std::string const &  map_name)
305{
306 boost::optional<map_data> data;
307 std::ofstream ofs("../../../maps/"+map_name+".txt", std::ios::out);
308
309 if (!(data = m_cache->getMap(map_name))) {
310 printf("map not found\n");
311 return;
312 }
313
314 int **cells = (int **) std::malloc(sizeof(int *) * data->width());
315 cells[0] = (int *) std::malloc(sizeof(int) * data->width() * data->height());
316
317 for (int i = 0; i < data->width(); i++)
318 cells[i] = (*cells) + data->height() * i;
319
320 for (int y = 0, idx = 0; y < data->height(); y++) {
321 for (int x = 0; x < data->width(); x++) {
322 cells[x][y] = data->getCells().at(idx++);
323 }
324 }
325
326 for (int y = data->height() - 1; y >= 0; --y) {
327 for (int x = 0; x < data->width(); x++) {
328 int type = cells[x][y];
329 // char s;
330 // switch (type)
331 // {
332 // case 3: s = '~'; break; // walkable water
333 // case 0: // walkable ground
334 // case 2: // ???
335 // case 4: // ???
336 // case 6: s = '.'; break; // ???
337 // case 5: s = 'O'; break; // gap (snipable)
338 // case 1: s = '#'; break; // non-walkable ground
339 // }
340 ofs.write(std::string("%d,", type).c_str(), 1);
341 }
342 ofs.write("\n", 1);
343 }
344
345 std::free(cells[0]);
346 std::free(cells);
347}

◆ ReadGRFListConfig()

mcache_grf_config_error_type Horizon::Libraries::MapCache::ReadGRFListConfig ( )
222{
223 sol::state lua;
224 sol::table grf_tbl;
225 if (getGRFListPath().empty())
227
228 // Read the file. If there is an error, report it and exit.
229 try {
230 sol::load_result fx = lua.load_file(getGRFListPath().string());
231
232 if (!fx.valid()) {
233 sol::error err = fx;
234 printf("GRFList Parse error at %s.\n", err.what());
236 }
237
238 sol::protected_function_result result = fx();
239
240 if (!result.valid()) {
241 sol::error err = result;
242 printf("GRFList Parse error at %s.\n", err.what());
244 }
245
246 grf_tbl = result;
247
248 } catch(const std::exception &e) {
249 printf("Error: GRFList Parse error at %s.\n", e.what());
251 }
252
253 setResourcePath(grf_tbl.get_or("grf_resource_path", std::string("./")));
254
255 sol::table grf_list = grf_tbl.get<sol::table>("grf_list");
256
257 grf_list.for_each([this](sol::object const &key, sol::object const &value) {
258 int id = key.as<int>();
259 std::string path = value.as<std::string>();
260
261 if (path.empty())
262 return;
263
264 GRF grf;
265 grf.set_id(id);
266 grf.setGRFPath(getGRFListPath().parent_path().string() + "/" + path);
267 addGRF(id, grf);
268 });
269
270 return MCACHE_GRF_CONF_OK;
271}
@ MCACHE_GRF_CONF_INVALID_FILE
Definition: MapCache.hpp:136
@ MCACHE_GRF_CONF_PARSE_ERROR
Definition: MapCache.hpp:137
Definition: GRF.hpp:86
void set_id(uint8_t id)
Definition: GRF.hpp:102
void setGRFPath(std::string const &path)
Definition: GRF.hpp:106
void setResourcePath(std::string const &path)
Definition: MapCache.hpp:222
void addGRF(uint8_t id, GRF &grf)
Definition: MapCache.hpp:195

References MCACHE_GRF_CONF_INVALID_FILE, MCACHE_GRF_CONF_OK, MCACHE_GRF_CONF_PARSE_ERROR, GRF::set_id(), and GRF::setGRFPath().

+ Here is the call graph for this function:

◆ ReadMapListConfig()

mcache_config_error_type Horizon::Libraries::MapCache::ReadMapListConfig ( )
173{
174 sol::state lua;
175 sol::table map_tbl;
176
177 // Read the file. If there is an error, report it and exit.
178 try {
179 sol::load_result fx = lua.load_file(getMapListPath().string());
180 // Check if the load result is valid
181 if (!fx.valid()) {
182 sol::error err = fx;
183 printf("MapList Config Error: Parse error at %s.\n", err.what());
185 }
186
187 sol::protected_function_result result = fx();
188
189 if (!result.valid()) {
190 sol::error err = result;
191 printf("MapList Config Error: Result parse error at %s.\n", err.what());
193 }
194
195 map_tbl = result;
196 // Check if map_tbl is a table
197 if (!map_tbl.valid() || map_tbl.get_type() != sol::type::table) {
198 printf("MapList Config Error: Expected a table but received a different type.\n");
200 }
201 } catch(const sol::error &e) {
202 printf("MapList Config Error: Parse error at %s.\n", e.what());
204 } catch(const std::exception &e) {
205 printf("MapList Config Error: Parse error at %s.\n", e.what());
207 } catch(...) {
208 printf("MapList Config Error: Parse error.\n");
210 }
211
212 map_tbl.for_each([this](sol::object const &key, sol::object const &value) {
213 if (key.get_type() != sol::type::number)
214 return;
215 addToMapList(value.as<std::string>());
216 });
217
218 return MCACHE_CONFIG_OK;
219}
@ MCACHE_CONFIG_PARSE_ERROR
Definition: MapCache.hpp:129
void addToMapList(std::string const &map)
Definition: MapCache.hpp:214

References MCACHE_CONFIG_OK, and MCACHE_CONFIG_PARSE_ERROR.

Referenced by Horizon::Zone::GameLogicProcess::load_map_cache().

+ Here is the caller graph for this function:

◆ setCompressionLevel()

void Horizon::Libraries::MapCache::setCompressionLevel ( int  level)
inline
203{ _compression_level = level; }

References _compression_level.

◆ setGRFListPath()

void Horizon::Libraries::MapCache::setGRFListPath ( std::string const &  path)
inline
211{ _grf_list_path = path; }

References _grf_list_path.

◆ setGRFPath()

void Horizon::Libraries::MapCache::setGRFPath ( uint8_t  id,
std::string const &  path 
)
inline
218{ _grfs[id].setGRFPath(path); }

References _grfs.

◆ setMapCachePath()

void Horizon::Libraries::MapCache::setMapCachePath ( std::string const &  file)
inline
199{ _map_cache_path = file; }

References _map_cache_path.

Referenced by Horizon::Zone::GameLogicProcess::load_map_cache().

+ Here is the caller graph for this function:

◆ setMapListPath()

void Horizon::Libraries::MapCache::setMapListPath ( std::string const &  path)
inline
207{ _map_list_path = path; }

References _map_list_path.

Referenced by Horizon::Zone::GameLogicProcess::load_map_cache().

+ Here is the caller graph for this function:

◆ setResourcePath()

void Horizon::Libraries::MapCache::setResourcePath ( std::string const &  path)
inline
222{ _resource_path = path; }

References _resource_path.

◆ setVerbose()

void Horizon::Libraries::MapCache::setVerbose ( )
inline
225{ _verbose = true; }

References _verbose.

◆ unsetVerbose()

void Horizon::Libraries::MapCache::unsetVerbose ( )
inline
226{ _verbose = false; }

References _verbose.

Member Data Documentation

◆ _compression_level

int Horizon::Libraries::MapCache::_compression_level {6}
private

◆ _grf_list_path

boost::filesystem::path Horizon::Libraries::MapCache::_grf_list_path
private

Referenced by getGRFListPath(), and setGRFListPath().

◆ _grfs

std::unordered_map<uint8_t, GRF> Horizon::Libraries::MapCache::_grfs
private

◆ _map_cache_data

std::map<std::string, map_data> Horizon::Libraries::MapCache::_map_cache_data
private

◆ _map_cache_path

boost::filesystem::path Horizon::Libraries::MapCache::_map_cache_path
private

Referenced by getMapCachePath(), and setMapCachePath().

◆ _map_list

std::vector<std::string> Horizon::Libraries::MapCache::_map_list
private

Referenced by addToMapList().

◆ _map_list_path

boost::filesystem::path Horizon::Libraries::MapCache::_map_list_path
private

Referenced by getMapListPath(), and setMapListPath().

◆ _resource_path

boost::filesystem::path Horizon::Libraries::MapCache::_resource_path
private

Referenced by getResourcePath(), and setResourcePath().

◆ _verbose

bool Horizon::Libraries::MapCache::_verbose {false}
private

◆ m_cache

std::shared_ptr<map_cache> Horizon::Libraries::MapCache::m_cache
private

Referenced by getMCache().


The documentation for this class was generated from the following files: