diff options
author | megamage <none@none> | 2009-02-17 15:42:04 -0600 |
---|---|---|
committer | megamage <none@none> | 2009-02-17 15:42:04 -0600 |
commit | 68cfb7c5a492ca1cc691cce831421af98bd6fe45 (patch) | |
tree | 5d1733d5b59eaa2137b03c4a8dd7fc39e30f1c74 | |
parent | 89e07d7c41698c1594e7d5ca947315f1441d064d (diff) |
[7291] Better map height calculation by use client data format.
Need re extract map files by use new ad.exe
Author: DiSlord
--HG--
branch : trunk
-rw-r--r-- | contrib/extractor/System.cpp | 8 | ||||
-rw-r--r-- | contrib/extractor/ad.exe | bin | 160768 -> 159744 bytes | |||
-rw-r--r-- | contrib/extractor/adt.cpp | 87 | ||||
-rw-r--r-- | src/game/GridDefines.h | 2 | ||||
-rw-r--r-- | src/game/Map.cpp | 93 | ||||
-rw-r--r-- | src/game/Map.h | 3 | ||||
-rw-r--r-- | src/shared/revision_nr.h | 2 |
7 files changed, 84 insertions, 111 deletions
diff --git a/contrib/extractor/System.cpp b/contrib/extractor/System.cpp index 3c319172723..f9f684014c2 100644 --- a/contrib/extractor/System.cpp +++ b/contrib/extractor/System.cpp @@ -70,7 +70,7 @@ bool FileExists( const char* FileName ) void Usage(char* prg) { - printf("Usage:\n%s -[var] [value]\n-i set input path\n-o set output path\n-r set resolution\n-e extract only MAP(1)/DBC(2) - standard: both(3)\nExample: %s -r 256 -i \"c:\\games\\game\"", prg, prg); + printf("Usage:\n%s -[var] [value]\n-i set input path\n-o set output path\n-e extract only MAP(1)/DBC(2) - standard: both(3)\nExample: %s -r 256 -i \"c:\\games\\game\"", prg, prg); exit(1); } @@ -99,12 +99,6 @@ void HandleArgs(int argc, char * arg[]) else Usage(arg[0]); break; - case 'r': - if(c + 1 < argc) // all ok - iRes=atoi(arg[(c++) + 1]); - else - Usage(arg[0]); - break; case 'e': if(c + 1 < argc) // all ok { diff --git a/contrib/extractor/ad.exe b/contrib/extractor/ad.exe Binary files differindex f483f3892f9..402f3ae3172 100644 --- a/contrib/extractor/ad.exe +++ b/contrib/extractor/ad.exe diff --git a/contrib/extractor/adt.cpp b/contrib/extractor/adt.cpp index 5cace2a70a5..70316a358e4 100644 --- a/contrib/extractor/adt.cpp +++ b/contrib/extractor/adt.cpp @@ -15,7 +15,6 @@ #include "adt.h" #include "mpq_libmpq.h" -uint32 iRes = 256; extern uint16 *areas; extern uint16 *LiqType; extern uint32 maxAreaId; @@ -301,68 +300,6 @@ inline void LoadMapChunk(MPQFile &mf, chunk *_chunk) } } -double solve (vec *v,vec *p) -{ - double a = v[0].y * (v[1].z - v[2].z) + v[1].y * (v[2].z - v[0].z) + v[2].y * (v[0].z - v[1].z); - double b = v[0].z * (v[1].x - v[2].x) + v[1].z * (v[2].x - v[0].x) + v[2].z * (v[0].x - v[1].x); - double c = v[0].x * (v[1].y - v[2].y) + v[1].x * (v[2].y - v[0].y) + v[2].x * (v[0].y - v[1].y); - double d = v[0].x * (v[1].y * v[2].z - v[2].y * v[1].z) + v[1].x * (v[2].y * v[0].z - v[0].y * v[2].z) + v[2].x * (v[0].y * v[1].z - v[1].y * v[0].z); - // -d - - // plane equation ax+by+cz+d=0 - return ((a*p->x+c*p->z-d)/b); -} - -inline double GetZ(double x, double z) -{ - vec v[3]; - vec p; - { - // find out quadrant - int xc = (int)(x / UNITSIZE); - int zc = (int)(z / UNITSIZE); - if(xc > 127) xc = 127; - if(zc > 127) zc = 127; - - double lx = x - xc * UNITSIZE; - double lz = z - zc * UNITSIZE; - p.x = lx; - p.z = lz; - - v[0].x = UNITSIZE / 2; - v[0].y = cell->v8[xc][zc]; - v[0].z = UNITSIZE / 2; - - if(lx > lz) - { - v[1].x = UNITSIZE; - v[1].y = cell->v9[xc + 1][zc]; - v[1].z = 0.0f; - } - else - { - v[1].x = 0.0f; - v[1].y = cell->v9[xc][zc + 1]; - v[1].z = UNITSIZE; - } - - if(lz > UNITSIZE - lx) - { - v[2].x = UNITSIZE; - v[2].y = cell->v9[xc + 1][zc + 1]; - v[2].z = UNITSIZE; - } - else - { - v[2].x = 0.0f; - v[2].y = cell->v9[xc][zc]; - v[2].z = 0.0f; - } - - return -solve(v, &p); - } -} - inline void TransformData() { cell = new Cell; @@ -371,14 +308,14 @@ inline void TransformData() { for(uint32 y = 0; y < 128; ++y) { - cell->v8[x][y] = (float)mcells->ch[x / 8][y / 8].v8[x % 8][y % 8]; - cell->v9[x][y] = (float)mcells->ch[x / 8][y / 8].v9[x % 8][y % 8]; + cell->v8[y][x] = (float)mcells->ch[x / 8][y / 8].v8[x % 8][y % 8]; + cell->v9[y][x] = (float)mcells->ch[x / 8][y / 8].v9[x % 8][y % 8]; } // extra 1 point on bounds - cell->v9[x][128] = (float)mcells->ch[x / 8][15].v9[x % 8][8]; + cell->v9[128][x] = (float)mcells->ch[x / 8][15].v9[x % 8][8]; // x == y - cell->v9[128][x] = (float)mcells->ch[15][x / 8].v9[8][x % 8]; + cell->v9[x][128] = (float)mcells->ch[15][x / 8].v9[8][x % 8]; } @@ -388,7 +325,7 @@ inline void TransformData() delete mcells; } -const char MAP_MAGIC[] = "MAP_2.01"; +const char MAP_MAGIC[] = "MAP_3.00"; bool ConvertADT(char *filename, char *filename2) { @@ -434,18 +371,8 @@ bool ConvertADT(char *filename, char *filename2) TransformData(); - for(uint32 x = 0; x < iRes; ++x) - { - for(uint32 y = 0; y < iRes; ++y) - { - float z = (float)GetZ( - (((double)(y)) * TILESIZE) / ((double)(iRes - 1)), - (((double)(x)) * TILESIZE) / ((double)(iRes - 1))); - - fwrite(&z, 1, sizeof(z), output); - } - } - + fwrite(&cell->v9, 1, sizeof(cell->v9), output); + fwrite(&cell->v8, 1, sizeof(cell->v8), output); fclose(output); delete cell; diff --git a/src/game/GridDefines.h b/src/game/GridDefines.h index 58871f68c03..b45bfe92913 100644 --- a/src/game/GridDefines.h +++ b/src/game/GridDefines.h @@ -57,7 +57,7 @@ class Player; #define TOTAL_NUMBER_OF_CELLS_PER_MAP (MAX_NUMBER_OF_GRIDS*MAX_NUMBER_OF_CELLS) -#define MAP_RESOLUTION 256 +#define MAP_RESOLUTION 128 #define MAP_SIZE (SIZE_OF_GRIDS*MAX_NUMBER_OF_GRIDS) #define MAP_HALFSIZE (MAP_SIZE/2) diff --git a/src/game/Map.cpp b/src/game/Map.cpp index f0fdbd346df..5ea2de9efb4 100644 --- a/src/game/Map.cpp +++ b/src/game/Map.cpp @@ -45,7 +45,7 @@ #define MAX_GRID_LOAD_TIME 50 // magic *.map header -const char MAP_MAGIC[] = "MAP_2.01"; +const char MAP_MAGIC[] = "MAP_3.00"; GridState* si_GridStates[MAX_GRID_STATE]; @@ -1193,26 +1193,77 @@ float Map::GetHeight(float x, float y, float z, bool pUseVmaps) const int ly_int = (int)ly; // In some very rare case this will happen. Need find a better way. - if(lx_int == MAP_RESOLUTION) --lx_int; - if(ly_int == MAP_RESOLUTION) --ly_int; - - float zi[4]; - // Probe 4 nearest points (except border cases) - zi[0] = gmap->Z[lx_int][ly_int]; - zi[1] = lx < MAP_RESOLUTION-1 ? gmap->Z[lx_int+1][ly_int] : zi[0]; - zi[2] = ly < MAP_RESOLUTION-1 ? gmap->Z[lx_int][ly_int+1] : zi[0]; - zi[3] = lx < MAP_RESOLUTION-1 && ly < MAP_RESOLUTION-1 ? gmap->Z[lx_int+1][ly_int+1] : zi[0]; - // Recalculate them like if their x,y positions were in the range 0,1 - float b[4]; - b[0] = zi[0]; - b[1] = zi[1]-zi[0]; - b[2] = zi[2]-zi[0]; - b[3] = zi[0]-zi[1]-zi[2]+zi[3]; - // Normalize the dx and dy to be in range 0..1 - float fact_x = lx - lx_int; - float fact_y = ly - ly_int; - // Use the simplified bilinear equation, as described in [url="http://en.wikipedia.org/wiki/Bilinear_interpolation"]http://en.wikipedia.org/wiki/Bilinear_interpolation[/url] - float _mapheight = b[0] + (b[1]*fact_x) + (b[2]*fact_y) + (b[3]*fact_x*fact_y); + //if(lx_int == MAP_RESOLUTION) --lx_int; + //if(ly_int == MAP_RESOLUTION) --ly_int; + + lx -= lx_int; + ly -= ly_int; + + // Height stored as: h5 - its v8 grid, h1-h4 - its v9 grid + // +--------------> X + // | h1-------h2 Coordinates is: + // | | \ 1 / | h1 0,0 + // | | \ / | h2 0,1 + // | | 2 h5 3 | h3 1,0 + // | | / \ | h4 1,1 + // | | / 4 \ | h5 1/2,1/2 + // | h3-------h4 + // V Y + // For find height need + // 1 - detect triangle + // 2 - solve linear equation from triangle points + + // Calculate coefficients for solve h = a*x + b*y + c + float a,b,c; + // Select triangle: + if (lx+ly < 1) + { + if (lx > ly) + { + // 1 triangle (h1, h2, h5 points) + float h1 = gmap->v9[lx_int][ly_int]; + float h2 = gmap->v9[lx_int+1][ly_int]; + float h5 = 2 * gmap->v8[lx_int][ly_int]; + a = h2-h1; + b = h5-h1-h2; + c = h1; + } + else + { + // 2 triangle (h1, h3, h5 points) + float h1 = gmap->v9[lx_int][ly_int]; + float h3 = gmap->v9[lx_int][ly_int+1]; + float h5 = 2 * gmap->v8[lx_int][ly_int]; + a = h5 - h1 - h3; + b = h3 - h1; + c = h1; + } + } + else + { + if (lx > ly) + { + // 3 triangle (h2, h4, h5 points) + float h2 = gmap->v9[lx_int+1][ly_int]; + float h4 = gmap->v9[lx_int+1][ly_int+1]; + float h5 = 2 * gmap->v8[lx_int][ly_int]; + a = h2 + h4 - h5; + b = h4 - h2; + c = h5 - h4; + } + else + { + // 4 triangle (h3, h4, h5 points) + float h3 = gmap->v9[lx_int][ly_int+1]; + float h4 = gmap->v9[lx_int+1][ly_int+1]; + float h5 = 2 * gmap->v8[lx_int][ly_int]; + a = h4 - h3; + b = h3 + h4 - h5; + c = h5 - h4; + } + } + // Calculate height + float _mapheight = a * lx + b * ly + c; // look from a bit higher pos to find the floor, ignore under surface case if(z + 2.0f > _mapheight) diff --git a/src/game/Map.h b/src/game/Map.h index 92274932362..3c227b47e88 100644 --- a/src/game/Map.h +++ b/src/game/Map.h @@ -75,7 +75,8 @@ typedef struct uint16 area_flag[16][16]; uint8 terrain_type[16][16]; float liquid_level[128][128]; - float Z[MAP_RESOLUTION][MAP_RESOLUTION]; + float v9[MAP_RESOLUTION + 1][MAP_RESOLUTION + 1]; + float v8[MAP_RESOLUTION][MAP_RESOLUTION]; }GridMap; struct CreatureMover diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index 8c65ce49575..3d9e1623b01 100644 --- a/src/shared/revision_nr.h +++ b/src/shared/revision_nr.h @@ -1,4 +1,4 @@ #ifndef __REVISION_NR_H__ #define __REVISION_NR_H__ - #define REVISION_NR "7290" + #define REVISION_NR "7291" #endif // __REVISION_NR_H__ |