@@ -1328,18 +1328,18 @@ static void getTriangleColor(const bobMAP& map, Uint8 rawTextureId, Sint16& r, S
13281328 b = 128 ;
13291329}
13301330
1331- void CMap::drawMinimap (SDL_Surface* Window )
1331+ void CMap::drawMinimap (std::vector< uint32_t >& pixels, int w, int h, int & num_x, int & num_y )
13321332{
1333- // this variables are needed to reduce the size of minimap-windows of big maps
1334- int num_x = (map->width > 256 ? map->width / 256 : 1 );
1335- int num_y = (map->height > 256 ? map->height / 256 : 1 );
1333+ // Scale factors to keep minimap within a reasonable size
1334+ num_x = (map->width > 256 ? map->width / 256 : 1 );
1335+ num_y = (map->height > 256 ? map->height / 256 : 1 );
13361336
1337- // make sure the minimap has the same proportions as the "real" map, so scale the same rate
1337+ // Keep aspect ratio uniform
13381338 num_x = (num_x > num_y ? num_x : num_y);
1339- num_y = ( num_x > num_y ? num_x : num_y) ;
1339+ num_y = num_x;
13401340
1341- // if (Window->w < map->width || Window->h < map->height)
1342- // return ;
1341+ // Ensure pixel buffer is the right size
1342+ pixels. assign ( static_cast < size_t >(w) * h, 0 ) ;
13431343
13441344 for (int y = 0 ; y < map->height ; y++)
13451345 {
@@ -1354,9 +1354,12 @@ void CMap::drawMinimap(SDL_Surface* Window)
13541354 Sint16 r, g, b;
13551355 getTriangleColor (*map, map->getVertex (x, y).rsuTexture , r, g, b);
13561356
1357- Uint32* row = (Uint32*)Window->pixels + (y / num_y + 20 ) * Window->pitch / 4 ; // -V206
1358- // +6 because of the left window frame
1359- Uint32* pixel = row + x / num_x + 6 ;
1357+ const int py = y / num_y;
1358+ const int px = x / num_x;
1359+ if (py >= h || px >= w)
1360+ continue ;
1361+
1362+ auto & pixel = pixels[static_cast <size_t >(py) * w + px];
13601363
13611364 Sint32 vertexLighting = map->getVertex (x, y).i ;
13621365 r = ((r * vertexLighting) >> 16 );
@@ -1365,32 +1368,10 @@ void CMap::drawMinimap(SDL_Surface* Window)
13651368 const auto r8 = (Uint8)(r > 255 ? 255 : (r < 0 ? 0 : r));
13661369 const auto g8 = (Uint8)(g > 255 ? 255 : (g < 0 ? 0 : g));
13671370 const auto b8 = (Uint8)(b > 255 ? 255 : (b < 0 ? 0 : b));
1368- *pixel = ((r8 << Window->format ->Rshift ) + (g8 << Window->format ->Gshift ) + (b8 << Window->format ->Bshift ));
1369- }
1370- }
1371-
1372- // draw the player flags
1373- for (int i = 0 ; i < MAXPLAYERS ; i++)
1374- {
1375- if (PlayerHQx[i] != 0xFFFF && PlayerHQy[i] != 0xFFFF )
1376- {
1377- // draw flag
1378- // %7 cause in the original game there are only 7 players and 7 different flags
1379- CSurface::Draw (Window, global::bmpArray[FLAG_BLUE_DARK + i % 7 ].surface ,
1380- 6 + PlayerHQx[i] / num_x - global::bmpArray[FLAG_BLUE_DARK + i % 7 ].nx ,
1381- 20 + PlayerHQy[i] / num_y - global::bmpArray[FLAG_BLUE_DARK + i % 7 ].ny );
1382- // write player number
1383- CFont::writeText (Window, std::to_string (i + 1 ), 6 + PlayerHQx[i] / num_x, 20 + PlayerHQy[i] / num_y,
1384- FontSize::Small, FontColor::MintGreen);
1371+ // BGRA format: A<<24 | R<<16 | G<<8 | B
1372+ pixel = (0xFFu << 24 ) | (r8 << 16 ) | (g8 << 8 ) | b8;
13851373 }
13861374 }
1387-
1388- // draw the arrow --> 6px is width of left window frame and 20px is the height of the upper window frame
1389- CSurface::Draw (Window, global::bmpArray[MAPPIC_ARROWCROSS_ORANGE ].surface ,
1390- 6 + (displayRect.left + displayRect.getSize ().x / 2 ) / triangleWidth / num_x
1391- - global::bmpArray[MAPPIC_ARROWCROSS_ORANGE ].nx ,
1392- 20 + (displayRect.top + displayRect.getSize ().y / 2 ) / triangleHeight / num_y
1393- - global::bmpArray[MAPPIC_ARROWCROSS_ORANGE ].ny );
13941375}
13951376
13961377void CMap::modifyVertex ()
0 commit comments