From ca7e02f20b9bbc8b082d767dd590d02d5dfd5ee7 Mon Sep 17 00:00:00 2001 From: Lance Date: Sun, 2 Apr 2006 04:09:00 +0000 Subject: * Loading waterheight aliases from resnametable.txt. git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@5858 54d463be-8e91-2dee-dedb-b68131a5f0ec --- Changelog-Trunk.txt | 1 + src/common/grfio.c | 23 +++++++++++++++-- src/common/grfio.h | 2 ++ src/map/map.c | 74 +++++++++++++++++++++++++++-------------------------- 4 files changed, 62 insertions(+), 38 deletions(-) diff --git a/Changelog-Trunk.txt b/Changelog-Trunk.txt index 9a048316e..3c1195d2f 100644 --- a/Changelog-Trunk.txt +++ b/Changelog-Trunk.txt @@ -4,6 +4,7 @@ AS OF SVN REV. 5091, WE ARE NOW USING TRUNK. ALL UNTESTED BUGFIXES/FEATURES GO IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK. 2006/04/02 + * Loading waterheight aliases from resnametable.txt. [Lance] * Workround the warnings for clif.c (what to do? the original codes are ugly.. passing values as pointers omgwtfbbq). [Lance] diff --git a/src/common/grfio.c b/src/common/grfio.c index 9830ca85c..98ddb59da 100644 --- a/src/common/grfio.c +++ b/src/common/grfio.c @@ -66,6 +66,7 @@ typedef struct { int cycle; char type; char fn[128-4*5]; // file name + char *fnd; char gentry; // read grf file select } FILELIST; //gentry ... 0 : It acquires from a local file. @@ -76,7 +77,7 @@ typedef struct { //Since char defines *FILELIST.gentry, the maximum which can be added by grfio_add becomes by 127 pieces. -#define GENTRY_LIMIT 127 +#define GENTRY_LIMIT 512 #define FILELIST_LIMIT 1048576 // temporary maximum, and a theory top maximum are 2G. static FILELIST *filelist = NULL; @@ -454,6 +455,10 @@ static FILELIST *filelist_find(char *fname) return (hash >= 0) ? &filelist[hash] : NULL; } +char *grfio_find_file(char *fname){ + return ((filelist_find(fname)->fnd == NULL)? filelist_find(fname)->fn: filelist_find(fname)->fnd); +} + /*========================================== * File List : Filelist add *------------------------------------------ @@ -540,6 +545,7 @@ int grfio_size(char *fname) if (stat(lfname, &st) == 0) { strncpy(lentry.fn, fname, sizeof(lentry.fn) - 1); + lentry.fnd = NULL; lentry.declen = st.st_size; lentry.gentry = 0; // 0:LocalFile entry = filelist_modify(&lentry); @@ -586,6 +592,7 @@ void* grfio_reads(char *fname, int *size) fread(buf2, 1, lentry.declen, in); fclose(in); strncpy(lentry.fn, fname, sizeof(lentry.fn) - 1); + lentry.fnd = NULL; lentry.gentry = 0; // 0:LocalFile entry = filelist_modify(&lentry); } else { @@ -733,6 +740,7 @@ static int grfio_entryread(char *gfname,int gentry) aentry.cycle = srccount; aentry.type = type; strncpy(aentry.fn, fname,sizeof(aentry.fn)-1); + aentry.fnd = NULL; #ifdef GRFIO_LOCAL aentry.gentry = -(gentry+1); // As Flag for making it a negative number carrying out the first time LocalFileCheck #else @@ -811,6 +819,7 @@ static int grfio_entryread(char *gfname,int gentry) aentry.cycle = srccount; aentry.type = type; strncpy(aentry.fn,fname,sizeof(aentry.fn)-1); + aentry.fnd = NULL; #ifdef GRFIO_LOCAL aentry.gentry = -(gentry+1); // As Flag for making it a negative number carrying out the first time LocalFileCheck #else @@ -865,6 +874,7 @@ static void grfio_resourcecheck(void) FILELIST fentry; memcpy(&fentry, entry, sizeof(FILELIST)); strncpy(fentry.fn, src, sizeof(fentry.fn) - 1); + fentry.fnd = grfio_alloc_ptr(w2); filelist_modify(&fentry); i++; } @@ -893,6 +903,7 @@ static void grfio_resourcecheck(void) FILELIST fentry; memcpy(&fentry, entry, sizeof(FILELIST)); strncpy(fentry.fn, src, sizeof(fentry.fn) - 1); + fentry.fnd = grfio_alloc_ptr(w2); filelist_modify(&fentry); i++; } @@ -916,6 +927,13 @@ static void grfio_resourcecheck(void) #define GENTRY_ADDS 4 // The number increment of gentry_table entries static int grfio_add(char *fname) +{ + grfio_alloc_ptr(fname); + + return grfio_entryread(fname, gentry_entrys - 1); +} + +static char *grfio_alloc_ptr(char *fname) { int len; char *buf; @@ -935,7 +953,7 @@ static int grfio_add(char *fname) strcpy(buf, fname); gentry_table[gentry_entrys++] = buf; - return grfio_entryread(fname, gentry_entrys - 1); + return buf; } /*========================================== @@ -946,6 +964,7 @@ void grfio_final(void) { if (filelist != NULL) aFree(filelist); + filelist_entrys = filelist_maxentry = 0; if (gentry_table != NULL) { diff --git a/src/common/grfio.h b/src/common/grfio.h index aba9db391..e2a70ae75 100644 --- a/src/common/grfio.h +++ b/src/common/grfio.h @@ -7,6 +7,8 @@ void grfio_init(char*); // GRFIO Initialize void grfio_final(void); // GRFIO Finalize void* grfio_reads(char*,int*); // GRFIO data file read & size get +char *grfio_find_file(char *fname); +char *grfio_alloc_ptr(char *fname); #define grfio_read(fn) grfio_reads(fn, NULL) diff --git a/src/map/map.c b/src/map/map.c index 7a37f6c43..385525be8 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -2294,9 +2294,9 @@ int map_eraseipport(unsigned short mapindex,unsigned long ip,int port) * 水場高さ設定 *------------------------------------------ */ -static struct waterlist_ { - char mapname[MAP_NAME_LENGTH], clonemapname[MAP_NAME_LENGTH]; -} *waterlist=NULL; +//static struct waterlist_ { +// char mapname[MAP_NAME_LENGTH], clonemapname[MAP_NAME_LENGTH]; +//} *waterlist=NULL; #define NO_WATER 1000000 @@ -2354,14 +2354,16 @@ int map_waterheight(char *mapname) { int wh; //Look up for clone map. - if(waterlist){ - int i; - for(i=0;waterlist[i].mapname[0] && i < MAX_MAP_PER_SERVER;i++) - if(strcmp(waterlist[i].mapname,mapname)==0) - return map_waterheight(waterlist[i].clonemapname); - } + //if(waterlist){ + // int i; + // for(i=0;waterlist[i].mapname[0] && i < MAX_MAP_PER_SERVER;i++) + // if(strcmp(waterlist[i].mapname,mapname)==0) + // return map_waterheight(waterlist[i].clonemapname); + //} //Look up for the rsw sprintf(fn,"data\\%s",mapname); + + strcpy(fn,grfio_find_file(fn)); rsw = strstr(fn, "."); if (rsw && strstr(fn, ".rsw") == NULL) @@ -2380,30 +2382,30 @@ int map_waterheight(char *mapname) { return NO_WATER; } -static void map_readwater(char *watertxt) { - char line[1024],w1[1024],w2[1024]; - FILE *fp=NULL; - int n=0; - - fp=fopen(watertxt,"r"); - if(fp==NULL){ - ShowError("file not found: %s\n",watertxt); - return; - } - if(waterlist==NULL) - waterlist = (struct waterlist_*)aCallocA(MAX_MAP_PER_SERVER,sizeof(*waterlist)); - while(fgets(line,1020,fp) && n < MAX_MAP_PER_SERVER){ - if(line[0] == '/' && line[1] == '/') - continue; - if(sscanf(line,"%s %s",w1,w2) < 2){ - continue; - } - memcpy(waterlist[n].mapname,w1, MAP_NAME_LENGTH-1); - memcpy(waterlist[n].clonemapname, w2, MAP_NAME_LENGTH-1); - n++; - } - fclose(fp); -} +//static void map_readwater(char *watertxt) { +// char line[1024],w1[1024],w2[1024]; +// FILE *fp=NULL; +// int n=0; +// +// fp=fopen(watertxt,"r"); +// if(fp==NULL){ +// ShowError("file not found: %s\n",watertxt); +// return; +// } +// if(waterlist==NULL) +// waterlist = (struct waterlist_*)aCallocA(MAX_MAP_PER_SERVER,sizeof(*waterlist)); +// while(fgets(line,1020,fp) && n < MAX_MAP_PER_SERVER){ +// if(line[0] == '/' && line[1] == '/') +// continue; +// if(sscanf(line,"%s %s",w1,w2) < 2){ +// continue; +// } +// memcpy(waterlist[n].mapname,w1, MAP_NAME_LENGTH-1); +// memcpy(waterlist[n].clonemapname, w2, MAP_NAME_LENGTH-1); +// n++; +// } +// fclose(fp); +//} /*========================================== * マップキャッシュに追加する *===========================================*/ @@ -3126,7 +3128,7 @@ int map_readallmaps (void) } // finished map loading - aFree(waterlist); + //aFree(waterlist); printf("\r"); ShowInfo("Successfully loaded '"CL_WHITE"%d"CL_RESET"' maps.%30s\n",map_num,""); @@ -3286,8 +3288,8 @@ int map_config_read(char *cfgName) { } else if (strcmpi(w1, "map_port") == 0) { clif_setport(atoi(w2)); map_port = (atoi(w2)); - } else if (strcmpi(w1, "water_height") == 0) { - map_readwater(w2); + //} else if (strcmpi(w1, "water_height") == 0) { + // map_readwater(w2); } else if (strcmpi(w1, "map") == 0) { map_addmap(w2); } else if (strcmpi(w1, "delmap") == 0) { -- cgit v1.2.3-60-g2f50