diff --git a/src/Client/World/MapMgr.cpp b/src/Client/World/MapMgr.cpp index 2a93e5b..4563ee4 100644 --- a/src/Client/World/MapMgr.cpp +++ b/src/Client/World/MapMgr.cpp @@ -33,14 +33,12 @@ void MapMgr::Update(float x, float y, uint32 m) _mapid = m; _gridx = _gridy = (-1); // must load tiles now } - uint32 xg,yg; // MapTile IDs. Range 0..64 - xg = GetGridCoord(x); - yg = GetGridCoord(y); - if(xg != _gridx || yg != _gridy) + GridCoordPair gcoords = GetTransformGridCoordPair(x,y); + if(gcoords.x != _gridx || gcoords.y != _gridy) { - _LoadNearTiles(xg,yg,m); - _gridx = xg; - _gridy = yg; + _LoadNearTiles(gcoords.x,gcoords.y,m); + _gridx = gcoords.x; + _gridy = gcoords.y; _UnloadOldTiles(); } _mapid = m; @@ -145,6 +143,11 @@ uint32 MapMgr::GetGridCoord(float f) return (ZEROPOINT - f) / TILESIZE; } +GridCoordPair MapMgr::GetTransformGridCoordPair(float x, float y) +{ + return GridCoordPair(GetGridCoord(y), GetGridCoord(x)); // i have no idea why they are swapping x and y map coords in ADT files... +} + uint32 MapMgr::GetLoadedMapsCount(void) { uint32 counter = 0; @@ -160,10 +163,9 @@ uint32 MapMgr::GetLoadedMapsCount(void) float MapMgr::GetZ(float x, float y) { - uint32 xg,yg; // MapTile IDs. Range 0..64 - xg = GetGridCoord(x); - yg = GetGridCoord(y); - MapTile *tile = _tiles->GetTile(xg,yg); + return -99999.0f; // for now return lowest possible number, GetZ() will be implemented correctly later +/* GridCoordPair gcoords = GetTransformGridCoordPair(x,y); + MapTile *tile = _tiles->GetTile(gcoords.x,gcoords.y); if(tile) { #ifdef _DEBUG @@ -173,7 +175,7 @@ float MapMgr::GetZ(float x, float y) return tile->GetZ(x,y); } - logerror("MapMgr::GetZ() called for not loaded MapTile (%u, %u) for (%f, %f)",xg,yg,x,y); - return 0; + logerror("MapMgr::GetZ() called for not loaded MapTile (%u, %u) for (%f, %f)",gcoords.x,gcoords.y,x,y); + return 0;*/ } diff --git a/src/Client/World/MapMgr.h b/src/Client/World/MapMgr.h index 20b7982..6e71af3 100644 --- a/src/Client/World/MapMgr.h +++ b/src/Client/World/MapMgr.h @@ -4,6 +4,14 @@ class MapTileStorage; class MapTile; +struct GridCoordPair +{ + GridCoordPair() {} + GridCoordPair(uint32 xu, uint32 yu) { x = xu; y = yu; } + uint32 x; + uint32 y; +}; + class MapMgr { public: @@ -12,7 +20,8 @@ public: void Update(float,float,uint32); void Flush(void); float GetZ(float,float); - uint32 GetGridCoord(float f); + static uint32 GetGridCoord(float f); + static GridCoordPair GetTransformGridCoordPair(float x, float y); MapTile *GetTile(uint32 xg, uint32 yg, bool forceLoad = false); MapTile *GetCurrentTile(void); MapTile *GetNearTile(int32, int32); @@ -21,7 +30,6 @@ public: inline uint32 GetGridX(void) { return _gridx; } inline uint32 GetGridY(void) { return _gridy; } - private: MapTileStorage *_tiles; void _LoadTile(uint32,uint32,uint32); diff --git a/src/Client/World/World.cpp b/src/Client/World/World.cpp index 387f833..552d8af 100644 --- a/src/Client/World/World.cpp +++ b/src/Client/World/World.cpp @@ -32,18 +32,21 @@ void World::Clear(void) void World::Update(void) { + if(_mapId == uint32(-1)) // to prevent unexpected behaviour + return; + if(_mapmgr) { _mapmgr->Update(_x,_y,_mapId); } // some debug code for testing... - if(_mapmgr && _x != _lastx || _y != _lasty) + /*if(_mapmgr && _x != _lastx || _y != _lasty) { logdetail("WORLD: relocation, to x=%f y=%f, calculated z=%f",_x,_y,this->GetPosZ(_x,_y)); _lastx = _x; _lasty = _y; - } + }*/ } diff --git a/src/shared/MapTile.cpp b/src/shared/MapTile.cpp index ead0d8a..e5d2375 100644 --- a/src/shared/MapTile.cpp +++ b/src/shared/MapTile.cpp @@ -24,8 +24,8 @@ void MapTile::ImportFromADT(ADTFile *adt) for(uint32 ch=0; ch_chunks[ch].hdr.zbase; // ADT files store (x/z) as ground coords and (y) as the height! - _chunks[ch].basey = adt->_chunks[ch].hdr.xbase; // here converting it to (x/y) on ground and basehight as actual height. - _chunks[ch].basex = adt->_chunks[ch].hdr.ybase; // strange coords they use... :S + _chunks[ch].basex = adt->_chunks[ch].hdr.xbase; // here converting it to (x/y) on ground and basehight as actual height. + _chunks[ch].basey = adt->_chunks[ch].hdr.ybase; // strange coords they use... :S uint32 fcnt=0, rcnt=0; while(true) //9*9 + 8*8 { @@ -43,6 +43,7 @@ void MapTile::ImportFromADT(ADTFile *adt) } } } + DEBUG(logdebug("MapTile first chunk base: h=%f x=%f y=%f",_chunks[0].baseheight,_chunks[0].basex,_chunks[0].basey)); } void MapTileStorage::_DebugDump(void) @@ -65,7 +66,7 @@ void MapTileStorage::_DebugDump(void) // TODO: use inner vertices also // TODO: interpolate values instead of choosing closest vertex // formula taken from BoogieBot, thx! -float MapTile::GetZ(float x, float y) +/*float MapTile::GetZ(float x, float y) { float bx,by; bx = _chunks[0].basex; // world base coords of tile @@ -91,7 +92,7 @@ float MapTile::GetZ(float x, float y) float real_z = ch.hmap_rough[vy*9 + vx] + ch.baseheight; return real_z; -} +}*/ void MapTile::DebugDumpToFile(void) {