* first try to calc Z coord for given x/y coords using map data. doesnt want to work (for now), more things have to be done.

* fixed crash on shutdown
This commit is contained in:
False.Genesis 2007-06-27 21:15:14 +00:00
parent 8ff8117e53
commit 0165102288
7 changed files with 81 additions and 9 deletions

View File

@ -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)

View File

@ -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;
}

View File

@ -10,6 +10,7 @@ public:
~MapMgr();
void Update(float,float,uint32);
void Flush(void);
float GetZ(float,float);
private:
MapTileStorage *_tiles;

View File

@ -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)
@ -38,3 +47,12 @@ void World::UpdatePos(float x, float y)
_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;
}

View File

@ -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;
};

View File

@ -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_PER_TILE; ch++)
{
_chunks[ch].xbase = adt->_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;
@ -61,3 +61,35 @@ void MapTileStorage::_DebugDump(void)
printf("MAP TILE MAP DEBUG DUMP, 64x64 TILES:\n");
printf(out.c_str());
}
// 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;
}

View File

@ -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;