diff --git a/src/Client/PseuWoW.cpp b/src/Client/PseuWoW.cpp index acab2a6..eab904e 100644 --- a/src/Client/PseuWoW.cpp +++ b/src/Client/PseuWoW.cpp @@ -69,6 +69,7 @@ PseuInstance::~PseuInstance() if(_cli) { _cli->stop(); + // delete _cli; // ok this is a little mem leak... can be fixed sometime in future } if(_rmcontrol) diff --git a/src/Client/World/MapMgr.cpp b/src/Client/World/MapMgr.cpp index 77c99a1..c751b64 100644 --- a/src/Client/World/MapMgr.cpp +++ b/src/Client/World/MapMgr.cpp @@ -115,4 +115,21 @@ void MapMgr::_UnloadOldTiles(void) } } +float MapMgr::GetZ(float x, float y) +{ + uint32 xg,yg; // MapTile IDs. Range 0..64 + xg = (uint32)( (ZEROPOINT - x) / TILESIZE); + yg = (uint32)( (ZEROPOINT - y) / TILESIZE); + MapTile *tile = _tiles->GetTile(xg,yg); + if(tile) + { + return tile->GetZ(x,y); + } + + logerror("MapMgr::GetZ() called for not loaded MapTile (%u, %u) for (%f, %f)",xg,yg,x,y); + return 0; +} + + + diff --git a/src/Client/World/MapMgr.h b/src/Client/World/MapMgr.h index c90d516..12f1a59 100644 --- a/src/Client/World/MapMgr.h +++ b/src/Client/World/MapMgr.h @@ -10,6 +10,7 @@ public: ~MapMgr(); void Update(float,float,uint32); void Flush(void); + float GetZ(float,float); private: MapTileStorage *_tiles; diff --git a/src/Client/World/World.cpp b/src/Client/World/World.cpp index d617fdf..11cbace 100644 --- a/src/Client/World/World.cpp +++ b/src/Client/World/World.cpp @@ -24,6 +24,15 @@ void World::Update(void) { _mapmgr->Update(_x,_y,_mapId); } + + // some debug code for testing... + 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; + } + } void World::UpdatePos(float x, float y, uint32 m) @@ -37,4 +46,13 @@ void World::UpdatePos(float x, float y) _x = x; _y = y; } + +float World::GetPosZ(float x, float y) +{ + if(_mapmgr) + return _mapmgr->GetZ(x,y); + + logdebug("WORLD: GetPosZ() called, but no MapMgr exists (do you really use maps?)"); + return 0; +} \ No newline at end of file diff --git a/src/Client/World/World.h b/src/Client/World/World.h index d6a4c37..716c19c 100644 --- a/src/Client/World/World.h +++ b/src/Client/World/World.h @@ -11,18 +11,19 @@ public: World(WorldSession*); ~World(); - uint32 GetMapId(void) { return _mapId; } - WorldSession *GetSession(void) { return _session; } + inline uint32 GetMapId(void) { return _mapId; } + inline WorldSession *GetSession(void) { return _session; } void Update(void); void UpdatePos(float,float,uint32); void UpdatePos(float,float); - //GetPosZ(float x, float y); + inline float GetPosZ(float x, float y); private: WorldSession *_session; MapMgr *_mapmgr; uint32 _mapId; float _x,_y; + float _lastx,_lasty; }; diff --git a/src/shared/MapTile.cpp b/src/shared/MapTile.cpp index 4ae91bc..a2984ec 100644 --- a/src/shared/MapTile.cpp +++ b/src/shared/MapTile.cpp @@ -1,5 +1,6 @@ #include "common.h" #include "MapTile.h" +#include "log.h" MapTile::MapTile() @@ -23,9 +24,9 @@ void MapTile::ImportFromADT(ADTFile *adt) // import the height map for(uint32 ch=0; ch_chunks[ch].hdr.xbase; - _chunks[ch].ybase = adt->_chunks[ch].hdr.ybase; - _chunks[ch].zbase = adt->_chunks[ch].hdr.zbase; + _chunks[ch].basex = adt->_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].baseheight = adt->_chunks[ch].hdr.ybase; // strange coords they use... :S uint32 fcnt=0, rcnt=0; while(true) //9*9 + 8*8 { @@ -45,7 +46,6 @@ void MapTile::ImportFromADT(ADTFile *adt) } } -// seems to be somewhat buggy... wtf? void MapTileStorage::_DebugDump(void) { std::string out; @@ -60,4 +60,36 @@ void MapTileStorage::_DebugDump(void) } printf("MAP TILE MAP DEBUG DUMP, 64x64 TILES:\n"); printf(out.c_str()); -} \ No newline at end of file +} + +// get approx Z position for world position (x,y). +// 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 bx,by; + bx = _chunks[0].basex; // world base coords of tile + by = _chunks[0].basey; + uint32 chx = (uint32)fabs((bx - x) / CHUNKSIZE); // get chunk id for given coords + uint32 chy = (uint32)fabs((by - y) / CHUNKSIZE); + if( chx > 15 || chy > 15) + { + logerror("MapTile::GetZ() wrong chunk indexes (%d, %d) for (%f, %f)",chx,chy,x,y); + logerror(" - These coords are NOT on this tile!"); + return 0; + } + MapChunk& ch = _chunks[chy*16 + chx]; + uint32 vx,vy; // get vertex position (0,0) ... (8,8); + vx = (uint32)floor(fabs(ch.basex - x / UNITSIZE) + 0.5f); + vy = (uint32)floor(fabs(ch.basey - x / UNITSIZE) + 0.5f); + if(vx > 8 || vy > 8) + { + logerror("MapTile::GetZ() wrong vertex indexes (%d, %d) for chunk (%d, %d) for (%f, %f)",vx,vy,chx,chy,x,y); + return 0; + } + + float real_z = ch.hmap_rough[vy*9 + vx] + ch.baseheight; + + return real_z; +} diff --git a/src/shared/MapTile.h b/src/shared/MapTile.h index 12ccb6e..3dac359 100644 --- a/src/shared/MapTile.h +++ b/src/shared/MapTile.h @@ -17,7 +17,7 @@ class MapChunk public: float hmap_rough[9*9]; float hmap_fine[8*8]; - float xbase,ybase,zbase; + float basex,basey,baseheight; //... TODO: implement the rest of this }; @@ -29,6 +29,7 @@ public: MapTile(); ~MapTile(); void ImportFromADT(ADTFile*); + float GetZ(float,float); private: MapChunk _chunks[256]; // 16x16 @@ -91,6 +92,7 @@ public: return _tiles[pos]; } void _DebugDump(void); + private: MapTile *_tiles[4096]; //64x64 std::bitset<4096> _hasTile;