* fixed swapped x/y values (now really loading correct map tiles)
* commented out GetZ() for now
This commit is contained in:
parent
b5298c9713
commit
fb1e696551
@ -33,14 +33,12 @@ void MapMgr::Update(float x, float y, uint32 m)
|
|||||||
_mapid = m;
|
_mapid = m;
|
||||||
_gridx = _gridy = (-1); // must load tiles now
|
_gridx = _gridy = (-1); // must load tiles now
|
||||||
}
|
}
|
||||||
uint32 xg,yg; // MapTile IDs. Range 0..64
|
GridCoordPair gcoords = GetTransformGridCoordPair(x,y);
|
||||||
xg = GetGridCoord(x);
|
if(gcoords.x != _gridx || gcoords.y != _gridy)
|
||||||
yg = GetGridCoord(y);
|
|
||||||
if(xg != _gridx || yg != _gridy)
|
|
||||||
{
|
{
|
||||||
_LoadNearTiles(xg,yg,m);
|
_LoadNearTiles(gcoords.x,gcoords.y,m);
|
||||||
_gridx = xg;
|
_gridx = gcoords.x;
|
||||||
_gridy = yg;
|
_gridy = gcoords.y;
|
||||||
_UnloadOldTiles();
|
_UnloadOldTiles();
|
||||||
}
|
}
|
||||||
_mapid = m;
|
_mapid = m;
|
||||||
@ -145,6 +143,11 @@ uint32 MapMgr::GetGridCoord(float f)
|
|||||||
return (ZEROPOINT - f) / TILESIZE;
|
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 MapMgr::GetLoadedMapsCount(void)
|
||||||
{
|
{
|
||||||
uint32 counter = 0;
|
uint32 counter = 0;
|
||||||
@ -160,10 +163,9 @@ uint32 MapMgr::GetLoadedMapsCount(void)
|
|||||||
|
|
||||||
float MapMgr::GetZ(float x, float y)
|
float MapMgr::GetZ(float x, float y)
|
||||||
{
|
{
|
||||||
uint32 xg,yg; // MapTile IDs. Range 0..64
|
return -99999.0f; // for now return lowest possible number, GetZ() will be implemented correctly later
|
||||||
xg = GetGridCoord(x);
|
/* GridCoordPair gcoords = GetTransformGridCoordPair(x,y);
|
||||||
yg = GetGridCoord(y);
|
MapTile *tile = _tiles->GetTile(gcoords.x,gcoords.y);
|
||||||
MapTile *tile = _tiles->GetTile(xg,yg);
|
|
||||||
if(tile)
|
if(tile)
|
||||||
{
|
{
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
@ -173,7 +175,7 @@ float MapMgr::GetZ(float x, float y)
|
|||||||
return tile->GetZ(x,y);
|
return tile->GetZ(x,y);
|
||||||
}
|
}
|
||||||
|
|
||||||
logerror("MapMgr::GetZ() called for not loaded MapTile (%u, %u) for (%f, %f)",xg,yg,x,y);
|
logerror("MapMgr::GetZ() called for not loaded MapTile (%u, %u) for (%f, %f)",gcoords.x,gcoords.y,x,y);
|
||||||
return 0;
|
return 0;*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -4,6 +4,14 @@
|
|||||||
class MapTileStorage;
|
class MapTileStorage;
|
||||||
class MapTile;
|
class MapTile;
|
||||||
|
|
||||||
|
struct GridCoordPair
|
||||||
|
{
|
||||||
|
GridCoordPair() {}
|
||||||
|
GridCoordPair(uint32 xu, uint32 yu) { x = xu; y = yu; }
|
||||||
|
uint32 x;
|
||||||
|
uint32 y;
|
||||||
|
};
|
||||||
|
|
||||||
class MapMgr
|
class MapMgr
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -12,7 +20,8 @@ public:
|
|||||||
void Update(float,float,uint32);
|
void Update(float,float,uint32);
|
||||||
void Flush(void);
|
void Flush(void);
|
||||||
float GetZ(float,float);
|
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 *GetTile(uint32 xg, uint32 yg, bool forceLoad = false);
|
||||||
MapTile *GetCurrentTile(void);
|
MapTile *GetCurrentTile(void);
|
||||||
MapTile *GetNearTile(int32, int32);
|
MapTile *GetNearTile(int32, int32);
|
||||||
@ -21,7 +30,6 @@ public:
|
|||||||
inline uint32 GetGridX(void) { return _gridx; }
|
inline uint32 GetGridX(void) { return _gridx; }
|
||||||
inline uint32 GetGridY(void) { return _gridy; }
|
inline uint32 GetGridY(void) { return _gridy; }
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MapTileStorage *_tiles;
|
MapTileStorage *_tiles;
|
||||||
void _LoadTile(uint32,uint32,uint32);
|
void _LoadTile(uint32,uint32,uint32);
|
||||||
|
|||||||
@ -32,18 +32,21 @@ void World::Clear(void)
|
|||||||
|
|
||||||
void World::Update(void)
|
void World::Update(void)
|
||||||
{
|
{
|
||||||
|
if(_mapId == uint32(-1)) // to prevent unexpected behaviour
|
||||||
|
return;
|
||||||
|
|
||||||
if(_mapmgr)
|
if(_mapmgr)
|
||||||
{
|
{
|
||||||
_mapmgr->Update(_x,_y,_mapId);
|
_mapmgr->Update(_x,_y,_mapId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// some debug code for testing...
|
// 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));
|
logdetail("WORLD: relocation, to x=%f y=%f, calculated z=%f",_x,_y,this->GetPosZ(_x,_y));
|
||||||
_lastx = _x;
|
_lastx = _x;
|
||||||
_lasty = _y;
|
_lasty = _y;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -24,8 +24,8 @@ void MapTile::ImportFromADT(ADTFile *adt)
|
|||||||
for(uint32 ch=0; ch<CHUNKS_PER_TILE; ch++)
|
for(uint32 ch=0; ch<CHUNKS_PER_TILE; ch++)
|
||||||
{
|
{
|
||||||
_chunks[ch].baseheight = adt->_chunks[ch].hdr.zbase; // ADT files store (x/z) as ground coords and (y) as the height!
|
_chunks[ch].baseheight = 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].basex = 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].basey = 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
|
||||||
{
|
{
|
||||||
@ -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)
|
void MapTileStorage::_DebugDump(void)
|
||||||
@ -65,7 +66,7 @@ void MapTileStorage::_DebugDump(void)
|
|||||||
// TODO: use inner vertices also
|
// TODO: use inner vertices also
|
||||||
// TODO: interpolate values instead of choosing closest vertex
|
// TODO: interpolate values instead of choosing closest vertex
|
||||||
// formula taken from BoogieBot, thx!
|
// formula taken from BoogieBot, thx!
|
||||||
float MapTile::GetZ(float x, float y)
|
/*float MapTile::GetZ(float x, float y)
|
||||||
{
|
{
|
||||||
float bx,by;
|
float bx,by;
|
||||||
bx = _chunks[0].basex; // world base coords of tile
|
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;
|
float real_z = ch.hmap_rough[vy*9 + vx] + ch.baseheight;
|
||||||
|
|
||||||
return real_z;
|
return real_z;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
void MapTile::DebugDumpToFile(void)
|
void MapTile::DebugDumpToFile(void)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user