2016-01-28 14:52:40 +01:00
|
|
|
/** @file
|
|
|
|
|
*
|
|
|
|
|
* @par History
|
|
|
|
|
*/
|
2016-02-11 22:54:43 +01:00
|
|
|
|
|
|
|
|
#include "inmemorymapserver.h"
|
|
|
|
|
|
2018-01-29 21:55:48 +01:00
|
|
|
#include "../clib/binaryfile.h"
|
2016-02-11 22:54:43 +01:00
|
|
|
#include "../clib/passert.h"
|
2024-07-28 10:42:47 +02:00
|
|
|
#include "../clib/stlutil.h"
|
2018-01-29 21:55:48 +01:00
|
|
|
#include "mapblock.h"
|
2016-02-11 22:54:43 +01:00
|
|
|
|
2026-01-17 10:30:21 +01:00
|
|
|
|
|
|
|
|
namespace Pol::Plib
|
2016-02-19 19:26:35 +01:00
|
|
|
{
|
|
|
|
|
InMemoryMapServer::InMemoryMapServer( const RealmDescriptor& descriptor ) : MapServer( descriptor )
|
|
|
|
|
{
|
|
|
|
|
unsigned n_blocks =
|
|
|
|
|
( _descriptor.width >> MAPBLOCK_SHIFT ) * ( _descriptor.height >> MAPBLOCK_SHIFT );
|
|
|
|
|
|
|
|
|
|
Clib::BinaryFile mapfile( descriptor.path( "base.dat" ), std::ios::in );
|
|
|
|
|
|
|
|
|
|
_mapblocks.resize( n_blocks );
|
|
|
|
|
|
|
|
|
|
mapfile.Read( &_mapblocks[0], n_blocks );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MAPCELL InMemoryMapServer::GetMapCell( unsigned short x, unsigned short y ) const
|
|
|
|
|
{
|
|
|
|
|
passert( x < _descriptor.width && y < _descriptor.height );
|
|
|
|
|
|
|
|
|
|
unsigned short xblock = x >> MAPBLOCK_SHIFT;
|
|
|
|
|
unsigned short xcell = x & MAPBLOCK_CELLMASK;
|
|
|
|
|
unsigned short yblock = y >> MAPBLOCK_SHIFT;
|
|
|
|
|
unsigned short ycell = y & MAPBLOCK_CELLMASK;
|
|
|
|
|
|
|
|
|
|
int block_index = yblock * ( _descriptor.width >> MAPBLOCK_SHIFT ) + xblock;
|
|
|
|
|
const MAPBLOCK& mapblock = _mapblocks[block_index];
|
|
|
|
|
return mapblock.cell[xcell][ycell];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t InMemoryMapServer::sizeEstimate() const
|
|
|
|
|
{
|
2024-07-28 10:42:47 +02:00
|
|
|
return sizeof( *this ) + MapServer::sizeEstimate() + Clib::memsize( _mapblocks );
|
2016-02-11 22:54:43 +01:00
|
|
|
}
|
2026-01-17 10:30:21 +01:00
|
|
|
} // namespace Pol::Plib
|