* 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:
parent
8ff8117e53
commit
0165102288
@ -69,6 +69,7 @@ PseuInstance::~PseuInstance()
|
|||||||
if(_cli)
|
if(_cli)
|
||||||
{
|
{
|
||||||
_cli->stop();
|
_cli->stop();
|
||||||
|
// delete _cli; // ok this is a little mem leak... can be fixed sometime in future
|
||||||
}
|
}
|
||||||
|
|
||||||
if(_rmcontrol)
|
if(_rmcontrol)
|
||||||
|
|||||||
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -10,6 +10,7 @@ public:
|
|||||||
~MapMgr();
|
~MapMgr();
|
||||||
void Update(float,float,uint32);
|
void Update(float,float,uint32);
|
||||||
void Flush(void);
|
void Flush(void);
|
||||||
|
float GetZ(float,float);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MapTileStorage *_tiles;
|
MapTileStorage *_tiles;
|
||||||
|
|||||||
@ -24,6 +24,15 @@ void World::Update(void)
|
|||||||
{
|
{
|
||||||
_mapmgr->Update(_x,_y,_mapId);
|
_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)
|
void World::UpdatePos(float x, float y, uint32 m)
|
||||||
@ -37,4 +46,13 @@ void World::UpdatePos(float x, float y)
|
|||||||
_x = x;
|
_x = x;
|
||||||
_y = 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;
|
||||||
|
}
|
||||||
|
|
||||||
@ -11,18 +11,19 @@ public:
|
|||||||
World(WorldSession*);
|
World(WorldSession*);
|
||||||
~World();
|
~World();
|
||||||
|
|
||||||
uint32 GetMapId(void) { return _mapId; }
|
inline uint32 GetMapId(void) { return _mapId; }
|
||||||
WorldSession *GetSession(void) { return _session; }
|
inline WorldSession *GetSession(void) { return _session; }
|
||||||
void Update(void);
|
void Update(void);
|
||||||
void UpdatePos(float,float,uint32);
|
void UpdatePos(float,float,uint32);
|
||||||
void UpdatePos(float,float);
|
void UpdatePos(float,float);
|
||||||
//GetPosZ(float x, float y);
|
inline float GetPosZ(float x, float y);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
WorldSession *_session;
|
WorldSession *_session;
|
||||||
MapMgr *_mapmgr;
|
MapMgr *_mapmgr;
|
||||||
uint32 _mapId;
|
uint32 _mapId;
|
||||||
float _x,_y;
|
float _x,_y;
|
||||||
|
float _lastx,_lasty;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "MapTile.h"
|
#include "MapTile.h"
|
||||||
|
#include "log.h"
|
||||||
|
|
||||||
|
|
||||||
MapTile::MapTile()
|
MapTile::MapTile()
|
||||||
@ -23,9 +24,9 @@ void MapTile::ImportFromADT(ADTFile *adt)
|
|||||||
// import the height map
|
// import the height map
|
||||||
for(uint32 ch=0; ch<CHUNKS_PER_TILE; ch++)
|
for(uint32 ch=0; ch<CHUNKS_PER_TILE; ch++)
|
||||||
{
|
{
|
||||||
_chunks[ch].xbase = adt->_chunks[ch].hdr.xbase;
|
_chunks[ch].basex = adt->_chunks[ch].hdr.zbase; // ADT files store (x/z) as ground coords and (y) as the height!
|
||||||
_chunks[ch].ybase = adt->_chunks[ch].hdr.ybase;
|
_chunks[ch].basey = adt->_chunks[ch].hdr.xbase; // here converting it to (x/y) on ground and basehight as actual height.
|
||||||
_chunks[ch].zbase = adt->_chunks[ch].hdr.zbase;
|
_chunks[ch].baseheight = adt->_chunks[ch].hdr.ybase; // strange coords they use... :S
|
||||||
uint32 fcnt=0, rcnt=0;
|
uint32 fcnt=0, rcnt=0;
|
||||||
while(true) //9*9 + 8*8
|
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)
|
void MapTileStorage::_DebugDump(void)
|
||||||
{
|
{
|
||||||
std::string out;
|
std::string out;
|
||||||
@ -60,4 +60,36 @@ void MapTileStorage::_DebugDump(void)
|
|||||||
}
|
}
|
||||||
printf("MAP TILE MAP DEBUG DUMP, 64x64 TILES:\n");
|
printf("MAP TILE MAP DEBUG DUMP, 64x64 TILES:\n");
|
||||||
printf(out.c_str());
|
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;
|
||||||
|
}
|
||||||
|
|||||||
@ -17,7 +17,7 @@ class MapChunk
|
|||||||
public:
|
public:
|
||||||
float hmap_rough[9*9];
|
float hmap_rough[9*9];
|
||||||
float hmap_fine[8*8];
|
float hmap_fine[8*8];
|
||||||
float xbase,ybase,zbase;
|
float basex,basey,baseheight;
|
||||||
//... TODO: implement the rest of this
|
//... TODO: implement the rest of this
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -29,6 +29,7 @@ public:
|
|||||||
MapTile();
|
MapTile();
|
||||||
~MapTile();
|
~MapTile();
|
||||||
void ImportFromADT(ADTFile*);
|
void ImportFromADT(ADTFile*);
|
||||||
|
float GetZ(float,float);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MapChunk _chunks[256]; // 16x16
|
MapChunk _chunks[256]; // 16x16
|
||||||
@ -91,6 +92,7 @@ public:
|
|||||||
return _tiles[pos];
|
return _tiles[pos];
|
||||||
}
|
}
|
||||||
void _DebugDump(void);
|
void _DebugDump(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MapTile *_tiles[4096]; //64x64
|
MapTile *_tiles[4096]; //64x64
|
||||||
std::bitset<4096> _hasTile;
|
std::bitset<4096> _hasTile;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user