diff options
author | ai4rei <ai4rei@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2011-01-01 20:43:02 +0000 |
---|---|---|
committer | ai4rei <ai4rei@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2011-01-01 20:43:02 +0000 |
commit | 6c4ccacfc199765bb6837da08341f6c7f21464bf (patch) | |
tree | bb4e4b7eb6a2a489826b6e5308bd74791def6bd5 /src/tool/mapcache.c | |
parent | 231c0084678af14b7443cbd47da99ebe380fe85c (diff) | |
download | hercules-6c4ccacfc199765bb6837da08341f6c7f21464bf.tar.gz hercules-6c4ccacfc199765bb6837da08341f6c7f21464bf.tar.bz2 hercules-6c4ccacfc199765bb6837da08341f6c7f21464bf.tar.xz hercules-6c4ccacfc199765bb6837da08341f6c7f21464bf.zip |
* Updates to map cache generator tool.
- Removed unmaintained grfio library copy and made the tool use the one in /common instead (related r12726).
- Updated makefile to use compile options/libraries determined by configure (bugreport:1109).
- Fixed error messages from the tool and grfio library overlapping each other (bugreport:2403).
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@14646 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/tool/mapcache.c')
-rw-r--r-- | src/tool/mapcache.c | 58 |
1 files changed, 31 insertions, 27 deletions
diff --git a/src/tool/mapcache.c b/src/tool/mapcache.c index 49e1826ab..f782331ca 100644 --- a/src/tool/mapcache.c +++ b/src/tool/mapcache.c @@ -1,6 +1,12 @@ // Copyright (c) Athena Dev Teams - Licensed under GNU GPL // For more information, see LICENCE in the main folder +#include "../common/cbasetypes.h" +#include "../common/grfio.h" +#include "../common/malloc.h" +#include "../common/mmo.h" +#include "../common/showmsg.h" + #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -9,11 +15,6 @@ #include <unistd.h> #endif -#include "../common/cbasetypes.h" -#include "grfio.h" - -#define MAP_NAME_LENGTH 12 -#define MAP_NAME_LENGTH_EXT 16 #define NO_WATER 1000000 char grf_list_file[256] = "conf/grf-files.txt"; @@ -124,7 +125,7 @@ int read_map(char *name, struct map_data *m) // Read water height if (rsw) { water_height = (int)GetFloat(rsw+166); - free(rsw); + aFree(rsw); } else water_height = NO_WATER; @@ -132,11 +133,11 @@ int read_map(char *name, struct map_data *m) m->xs = (int16)GetULong(gat+6); m->ys = (int16)GetULong(gat+10); if (m->xs <= 0 || m->ys <= 0) { - free(gat); + aFree(gat); return 0; } num_cells = (size_t)m->xs*(size_t)m->ys; - m->cells = (unsigned char *)malloc(num_cells); + m->cells = (unsigned char *)aMalloc(num_cells); // Set cell properties off = 14; @@ -154,7 +155,7 @@ int read_map(char *name, struct map_data *m) m->cells[xy] = (unsigned char)type; } - free(gat); + aFree(gat); return 1; } @@ -168,7 +169,7 @@ void cache_map(char *name, struct map_data *m) // Create an output buffer twice as big as the uncompressed map... this way we're sure it fits len = (unsigned long)m->xs*(unsigned long)m->ys*2; - write_buf = (unsigned char *)malloc(len); + write_buf = (unsigned char *)aMalloc(len); // Compress the cells and get the compressed length encode_zip(write_buf, &len, m->cells, m->xs*m->ys); @@ -185,8 +186,8 @@ void cache_map(char *name, struct map_data *m) header.file_size += sizeof(struct map_info) + len; header.map_count++; - free(write_buf); - free(m->cells); + aFree(write_buf); + aFree(m->cells); return; } @@ -245,7 +246,7 @@ void process_args(int argc, char *argv[]) } -int main(int argc, char *argv[]) +int do_init(int argc, char *argv[]) { FILE *list; char line[1024]; @@ -255,15 +256,15 @@ int main(int argc, char *argv[]) // Process the command-line arguments process_args(argc, argv); - printf("Initializing grfio with %s\n", grf_list_file); + ShowStatus("Initializing grfio with %s\n", grf_list_file); grfio_init(grf_list_file); // Attempt to open the map cache file and force rebuild if not found - printf("Opening map cache: %s\n", map_cache_file); + ShowStatus("Opening map cache: %s\n", map_cache_file); if(!rebuild) { map_cache_fp = fopen(map_cache_file, "rb"); if(map_cache_fp == NULL) { - printf("Existing map cache not found, forcing rebuild mode\n"); + ShowNotice("Existing map cache not found, forcing rebuild mode\n"); rebuild = 1; } else fclose(map_cache_fp); @@ -273,15 +274,15 @@ int main(int argc, char *argv[]) else map_cache_fp = fopen(map_cache_file, "r+b"); if(map_cache_fp == NULL) { - printf("Failure when opening map cache file %s\n", map_cache_file); + ShowError("Failure when opening map cache file %s\n", map_cache_file); exit(EXIT_FAILURE); } // Open the map list - printf("Opening map list: %s\n", map_list_file); + ShowStatus("Opening map list: %s\n", map_list_file); list = fopen(map_list_file, "r"); if(list == NULL) { - printf("Failure when opening maps list file %s\n", map_list_file); + ShowError("Failure when opening maps list file %s\n", map_list_file); exit(EXIT_FAILURE); } @@ -309,30 +310,33 @@ int main(int argc, char *argv[]) name[MAP_NAME_LENGTH_EXT-1] = '\0'; remove_extension(name); - printf("%s", name); if(find_map(name)) - printf(" already in cache!\n"); + ShowInfo("Map '"CL_WHITE"%s"CL_RESET"' already in cache.\n", name); else if(read_map(name, &map)) { cache_map(name, &map); - printf(" successfully cached\n"); + ShowInfo("Map '"CL_WHITE"%s"CL_RESET"' successfully cached.\n", name); } else - printf(" not found in GRF!\n"); + ShowError("Map '"CL_WHITE"%s"CL_RESET"' not found!\n", name); } - printf("Closing map list: %s\n", map_list_file); + ShowStatus("Closing map list: %s\n", map_list_file); fclose(list); // Write the main header and close the map cache - printf("Closing map cache: %s\n", map_cache_file); + ShowStatus("Closing map cache: %s\n", map_cache_file); fseek(map_cache_fp, 0, SEEK_SET); fwrite(&header, sizeof(struct main_header), 1, map_cache_fp); fclose(map_cache_fp); - printf("Finalizing grfio\n"); + ShowStatus("Finalizing grfio\n"); grfio_final(); - printf("%d maps now in cache\n", header.map_count); + ShowInfo("%d maps now in cache\n", header.map_count); return 0; } + +void do_final(void) +{ +} |