Pol  Revision:f37d500
maptileserver.cpp
Go to the documentation of this file.
1 
7 #include "maptileserver.h"
8 
9 namespace Pol
10 {
11 namespace Plib
12 {
14  : _descriptor( descriptor ),
15  _file( _descriptor.path( "maptile.dat" ), std::ios::in ),
16  _cur_block_index( -1L )
17 {
19  _cur_block_index = 0;
20 }
21 
23 
24 MAPTILE_CELL MapTileServer::GetMapTile( unsigned short x, unsigned short y )
25 {
26  unsigned short xblock = x >> MAPTILE_SHIFT;
27  unsigned short xcell = x & MAPTILE_CELLMASK;
28  unsigned short yblock = y >> MAPTILE_SHIFT;
29  unsigned short ycell = y & MAPTILE_CELLMASK;
30 
31  int block_index = yblock * ( _descriptor.width >> MAPTILE_SHIFT ) + xblock;
32  if ( block_index != _cur_block_index )
33  {
34  size_t offset = block_index * sizeof _cur_block;
35 
36  _file.Seek( offset );
37  _file.Read( _cur_block );
38 
39  _cur_block_index = block_index;
40  }
41 
42  return _cur_block.cell[xcell][ycell];
43 }
44 
46 {
47  return sizeof( *this ) + _descriptor.sizeEstimate() + _file.sizeEstimate();
48 }
49 }
50 }
size_t sizeEstimate() const
Definition: binaryfile.cpp:101
MAPTILE_CELL cell[MAPTILE_CHUNK][MAPTILE_CHUNK]
Definition: maptile.h:27
STL namespace.
MAPTILE_BLOCK _cur_block
Definition: maptileserver.h:32
const unsigned MAPTILE_SHIFT
Definition: maptile.h:14
MapTileServer(const RealmDescriptor &descriptor)
void Seek(std::fstream::pos_type abs_offset)
Definition: binaryfile.cpp:50
const RealmDescriptor _descriptor
Definition: maptileserver.h:28
void Read(T &val)
Definition: binaryfile.h:29
Clib::BinaryFile _file
Definition: maptileserver.h:30
MAPTILE_CELL GetMapTile(unsigned short x, unsigned short y)
Definition: berror.cpp:12
size_t sizeEstimate() const
const unsigned MAPTILE_CELLMASK
Definition: maptile.h:15