Pol  Revision:f37d500
inmemorymapserver.cpp
Go to the documentation of this file.
1 
6 #include "inmemorymapserver.h"
7 
8 #include "../clib/binaryfile.h"
9 #include "../clib/passert.h"
10 #include "mapblock.h"
11 
12 namespace Pol
13 {
14 namespace Plib
15 {
17 {
18  unsigned n_blocks =
20 
21  Clib::BinaryFile mapfile( descriptor.path( "base.dat" ), std::ios::in );
22 
23  _mapblocks.resize( n_blocks );
24 
25  mapfile.Read( &_mapblocks[0], n_blocks );
26 }
27 
29 
30 MAPCELL InMemoryMapServer::GetMapCell( unsigned short x, unsigned short y ) const
31 {
33 
34  unsigned short xblock = x >> MAPBLOCK_SHIFT;
35  unsigned short xcell = x & MAPBLOCK_CELLMASK;
36  unsigned short yblock = y >> MAPBLOCK_SHIFT;
37  unsigned short ycell = y & MAPBLOCK_CELLMASK;
38 
39  int block_index = yblock * ( _descriptor.width >> MAPBLOCK_SHIFT ) + xblock;
40  const MAPBLOCK& mapblock = _mapblocks[block_index];
41  return mapblock.cell[xcell][ycell];
42 }
43 
45 {
46  size_t size = sizeof( *this ) + MapServer::sizeEstimate();
47  size += 3 * sizeof( MAPBLOCK* ) + _mapblocks.capacity() * sizeof( MAPBLOCK );
48  return size;
49 }
50 }
51 }
const unsigned MAPBLOCK_CELLMASK
Definition: mapblock.h:20
virtual MAPCELL GetMapCell(unsigned short x, unsigned short y) const POL_OVERRIDE
virtual size_t sizeEstimate() const
Definition: mapserver.cpp:167
InMemoryMapServer(const RealmDescriptor &descriptor)
std::vector< MAPBLOCK > _mapblocks
#define passert(exp)
Definition: passert.h:62
FILE * mapfile
Definition: uofile00.cpp:21
const RealmDescriptor _descriptor
Definition: mapserver.h:37
std::string path(const std::string &filename) const
virtual size_t sizeEstimate() const POL_OVERRIDE
const unsigned MAPBLOCK_SHIFT
Definition: mapblock.h:19
Definition: berror.cpp:12