• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

polserver / polserver / 21100551564

17 Jan 2026 08:40PM UTC coverage: 60.504% (+0.01%) from 60.492%
21100551564

Pull #857

github

turleypol
fixed scope
Pull Request #857: ClangTidy readability-else-after-return

837 of 1874 new or added lines in 151 files covered. (44.66%)

48 existing lines in 26 files now uncovered.

44445 of 73458 relevant lines covered (60.5%)

515341.61 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

91.03
/pol-core/plib/mapserver.cpp
1
/** @file
2
 *
3
 * @par History
4
 */
5

6

7
#include "mapserver.h"
8

9
#include <stddef.h>
10
#include <stdexcept>
11
#include <string>
12

13
#include "../clib/binaryfile.h"
14
#include "../clib/passert.h"
15
#include "../clib/stlutil.h"
16
#include "../clib/strutil.h"
17
#include "filemapserver.h"
18
#include "inmemorymapserver.h"
19
#include "mapcell.h"
20
#include "mapshape.h"
21
#include "mapsolid.h"
22

23

24
namespace Pol::Plib
25
{
26
MapServer::MapServer( const RealmDescriptor& descriptor ) : _descriptor( descriptor )
6✔
27
{
28
  LoadSolids();
6✔
29

30
  // the first-level index points into the second-level index, so load the second-level index first.
31
  LoadSecondLevelIndex();
6✔
32

33
  LoadFirstLevelIndex();
6✔
34
}
6✔
35

36
void MapServer::LoadSolids()
6✔
37
{
38
  std::string filename = _descriptor.path( "solids.dat" );
6✔
39

40
  Clib::BinaryFile infile( filename, std::ios::in );
6✔
41
  infile.ReadVector( _shapedata );
6✔
42
}
6✔
43

44
void MapServer::LoadSecondLevelIndex()
6✔
45
{
46
  std::string filename = _descriptor.path( "solidx2.dat" );
6✔
47

48
  Clib::BinaryFile infile( filename, std::ios::in );
6✔
49
  std::fstream::pos_type filesize = infile.FileSize();
6✔
50
  if ( filesize < std::fstream::pos_type( SOLIDX2_FILLER_SIZE ) )
6✔
51
    throw std::runtime_error( filename + " must have size of at least " +
×
52
                              Clib::tostring( SOLIDX2_FILLER_SIZE ) + " bytes." );
×
53

54
  std::fstream::pos_type databytes = filesize - std::fstream::pos_type( SOLIDX2_FILLER_SIZE );
6✔
55
  if ( ( databytes % sizeof( SOLIDX2_ELEM ) ) != 0 )
6✔
56
    throw std::runtime_error( filename + " does not contain an integral number of elements." );
×
57

58
  size_t count = static_cast<size_t>( databytes / sizeof( SOLIDX2_ELEM ) );
6✔
59
  _index2.resize( count );
6✔
60
  infile.Seek( SOLIDX2_FILLER_SIZE );
6✔
61
  infile.Read( &_index2[0], count );
6✔
62

63
  // integrity check
64
  for ( const auto& elem : _index2 )
2,550✔
65
  {
66
    passert( elem.baseindex < _shapedata.size() );
2,544✔
67

68
    for ( unsigned x = 0; x < SOLIDX_X_SIZE; ++x )
22,896✔
69
    {
70
      for ( unsigned y = 0; y < SOLIDX_Y_SIZE; ++y )
183,168✔
71
      {
72
        size_t idx = elem.baseindex + elem.addindex[x][y];
162,816✔
73
        passert( idx < _shapedata.size() );
162,816✔
74
      }
75
    }
76
  }
77
}
6✔
78

79
void MapServer::LoadFirstLevelIndex()
6✔
80
{
81
  std::string filename = _descriptor.path( "solidx1.dat" );
6✔
82

83
  Clib::BinaryFile infile( filename, std::ios::in );
6✔
84

85
  size_t n_blocks = ( _descriptor.width / SOLIDX_X_SIZE ) * ( _descriptor.height / SOLIDX_Y_SIZE );
6✔
86
  _index1.resize( n_blocks );
6✔
87

88
  for ( size_t i = 0; i < n_blocks; ++i )
121,734✔
89
  {
90
    unsigned int tmp;
91
    infile.Read( tmp );
121,728✔
92
    if ( tmp )
121,728✔
93
    {
94
      // tmp is an offset, in the file..  turn it into a pointer into the second-level index.
95
      tmp = ( tmp - SOLIDX2_FILLER_SIZE ) / sizeof( SOLIDX2_ELEM );
2,544✔
96
      _index1[i] = &_index2.at( tmp );
2,544✔
97
    }
98
    else
99
    {
100
      _index1[i] = nullptr;
119,184✔
101
    }
102
  }
103
}
6✔
104

105
void MapServer::GetMapShapes( MapShapeList& shapes, unsigned short x, unsigned short y,
4,046✔
106
                              unsigned int anyflags ) const
107
{
108
  passert( x < _descriptor.width && y < _descriptor.height );
4,046✔
109

110
  MAPCELL cell = GetMapCell( x, y );
4,046✔
111
  MapShape shape;
112

113
  if ( cell.flags & anyflags )
4,046✔
114
  {
115
    shape.flags = cell.flags;
4,046✔
116
    shape.z = cell.z - 1;  // assume now map is at z-1 with height 1 for solidity
4,046✔
117
    shape.height = 1;
4,046✔
118
    shapes.push_back( shape );
4,046✔
119
  }
120

121
  if ( cell.flags & FLAG::MORE_SOLIDS )
4,046✔
122
  {
123
    unsigned short xblock = x >> SOLIDX_X_SHIFT;
66✔
124
    unsigned short xcell = x & SOLIDX_X_CELLMASK;
66✔
125
    unsigned short yblock = y >> SOLIDX_Y_SHIFT;
66✔
126
    unsigned short ycell = y & SOLIDX_Y_CELLMASK;
66✔
127

128
    size_t block = static_cast<size_t>( yblock ) * ( _descriptor.width >> SOLIDX_X_SHIFT ) + xblock;
66✔
129
    SOLIDX2_ELEM* pIndex2 = _index1[block];
66✔
130
    unsigned int index = pIndex2->baseindex + pIndex2->addindex[xcell][ycell];
66✔
131
    const SOLIDS_ELEM* pElem = &_shapedata[index];
66✔
132
    for ( ;; )
133
    {
134
      if ( pElem->flags & anyflags )
66✔
135
      {
136
        shape.z = pElem->z;
66✔
137
        shape.height = pElem->height;
66✔
138
        shape.flags = pElem->flags;
66✔
139
        shapes.push_back( shape );
66✔
140
      }
141
      if ( pElem->flags & FLAG::MORE_SOLIDS )
66✔
142
        ++pElem;
×
143
      else
144
        break;
66✔
145
    }
146
  }
147
}
4,046✔
148

149
MapServer* MapServer::Create( const RealmDescriptor& descriptor )
6✔
150
{
151
  if ( descriptor.mapserver_type == "memory" )
6✔
152
  {
153
    return new InMemoryMapServer( descriptor );
6✔
154
  }
NEW
155
  if ( descriptor.mapserver_type == "file" )
×
156
  {
157
    return new FileMapServer( descriptor );
×
158
  }
159

NEW
160
  throw std::runtime_error( "Undefined mapserver type: " + descriptor.mapserver_type );
×
161
}
162

163
size_t MapServer::sizeEstimate() const
2✔
164
{
165
  return sizeof( *this ) + _descriptor.sizeEstimate() + Clib::memsize( _index1 ) +
2✔
166
         Clib::memsize( _index2 ) + Clib::memsize( _shapedata );
2✔
167
}
168
}  // namespace Pol::Plib
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc