mirror of
https://github.com/polserver/polserver
synced 2026-08-13 08:23:08 -04:00
* tidy * Automated clang-tidy change: modernize-concat-nested-namespaces * compile test * fix namespace --------- Co-authored-by: Clang Tidy <clang-tidy@users.noreply.github.com>
46 lines
1.2 KiB
C++
46 lines
1.2 KiB
C++
/** @file
|
|
*
|
|
* @par History
|
|
*/
|
|
|
|
#include "inmemorymapserver.h"
|
|
|
|
#include "../clib/binaryfile.h"
|
|
#include "../clib/passert.h"
|
|
#include "../clib/stlutil.h"
|
|
#include "mapblock.h"
|
|
|
|
|
|
namespace Pol::Plib
|
|
{
|
|
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
|
|
{
|
|
return sizeof( *this ) + MapServer::sizeEstimate() + Clib::memsize( _mapblocks );
|
|
}
|
|
} // namespace Pol::Plib
|