From e2ba5d8b144c1251ce68fc8b1c95ee89250cf169 Mon Sep 17 00:00:00 2001 From: Haru Date: Wed, 12 Apr 2017 02:16:48 +0200 Subject: Add option to recache individual maps Signed-off-by: Haru --- src/plugins/mapcache.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'src/plugins/mapcache.c') diff --git a/src/plugins/mapcache.c b/src/plugins/mapcache.c index 95e6ead04..f1dab97c1 100644 --- a/src/plugins/mapcache.c +++ b/src/plugins/mapcache.c @@ -70,6 +70,7 @@ struct old_mapcache_map_info { #define NO_WATER 1000000 VECTOR_DECL(char *) maplist; +bool needs_grfio; /** @@ -133,7 +134,7 @@ bool write_mapcache(const uint8 *buf, int32 buf_len, bool is_compressed, const c snprintf(file_path, sizeof(file_path), "%s%s%s.%s", "maps/", DBPATH, mapname, "mcache"); - new_mapcache_fp = fopen(file_path, "w+b"); + new_mapcache_fp = fopen(file_path, "wb"); if (new_mapcache_fp == NULL) { ShowWarning("Could not open file '%s', map cache creating failed.\n", file_path); @@ -332,8 +333,6 @@ bool mapcache_rebuild(void) } } - grfio->init("conf/grf-files.txt"); - for (i = 0; i < VECTOR_LENGTH(maplist); ++i) { ShowStatus("Creating mapcache: %s"CL_CLL"\r", VECTOR_INDEX(maplist, i)); mapcache_cache_map(VECTOR_INDEX(maplist, i)); @@ -350,21 +349,36 @@ CMDLINEARG(convertmapcache) CMDLINEARG(rebuild) { + needs_grfio = true; + grfio->init("conf/grf-files.txt"); map->minimal = true; return mapcache_rebuild(); } +CMDLINEARG(cachemap) +{ + needs_grfio = true; + grfio->init("conf/grf-files.txt"); + map->minimal = true; + return mapcache_cache_map(params); +} + HPExport void server_preinit(void) { addArg("--convert-old-mapcache", false, convertmapcache, "Converts an old db/"DBPATH"map_cache.dat file to the new format."); addArg("--rebuild-mapcache", false, rebuild, "Rebuilds the entire mapcache folder (maps/"DBPATH"), using db/map_index.txt as index."); + addArg("--map", true, cachemap, + "Rebuilds an individual map's cache into maps/"DBPATH" (usage: --map )."); + needs_grfio = false; VECTOR_INIT(maplist); } HPExport void plugin_final(void) { VECTOR_CLEAR(maplist); + if (needs_grfio) + grfio->final(); } -- cgit v1.2.3-70-g09d2