|
6 | 6 | #include "CSurface.h" |
7 | 7 | #include "CGame.h" |
8 | 8 | #include "CMap.h" |
| 9 | +#include "Geometry.h" |
9 | 10 | #include "Rect.h" |
10 | 11 | #include "SGE/sge_blib.h" |
11 | 12 | #include "SGE/sge_rotation.h" |
@@ -333,47 +334,67 @@ void CSurface::DrawTriangleField(SDL_Surface* display, const DisplayRectangle& d |
333 | 334 | { |
334 | 335 | if(y % 2 == 0) |
335 | 336 | { |
336 | | - // first RightSideUp |
| 337 | + // first RightSideUp (edge wrap) |
337 | 338 | tempP2 = myMap.getVertex(width - 1, y + 1); |
338 | 339 | tempP2.x = 0; |
339 | 340 | DrawTriangle(display, displayRect, myMap, type, myMap.getVertex(0, y), tempP2, |
340 | 341 | myMap.getVertex(0, y + 1)); |
341 | | - for(unsigned x = std::max(col_start, 1); x < width && x <= static_cast<unsigned>(col_end); x++) |
| 342 | + // first UpSideDown (s25client convention, visual column 0) |
| 343 | + const auto usd0 = clientUsdTriangleVertices(0, y); |
| 344 | + DrawTriangle(display, displayRect, myMap, type, myMap.getVertex(usd0.p1x, usd0.p1y), |
| 345 | + myMap.getVertex(usd0.p2x, usd0.p2y), myMap.getVertex(usd0.p3x, usd0.p3y)); |
| 346 | + for(unsigned x = std::max(col_start, 1); x < width - 1u && x <= static_cast<unsigned>(col_end); x++) |
342 | 347 | { |
343 | | - // RightSideUp |
| 348 | + // RightSideUp (same in both conventions) |
344 | 349 | DrawTriangle(display, displayRect, myMap, type, myMap.getVertex(x, y), |
345 | 350 | myMap.getVertex(x - 1, y + 1), myMap.getVertex(x, y + 1)); |
346 | | - // UpSideDown |
347 | | - DrawTriangle(display, displayRect, myMap, type, myMap.getVertex(x - 1, y + 1), |
348 | | - myMap.getVertex(x - 1, y), myMap.getVertex(x, y)); |
| 351 | + // UpSideDown (s25client convention) |
| 352 | + const auto usd = clientUsdTriangleVertices(x, y); |
| 353 | + DrawTriangle(display, displayRect, myMap, type, myMap.getVertex(usd.p1x, usd.p1y), |
| 354 | + myMap.getVertex(usd.p2x, usd.p2y), myMap.getVertex(usd.p3x, usd.p3y)); |
349 | 355 | } |
350 | | - // last UpSideDown |
351 | | - tempP3 = myMap.getVertex(0, y); |
352 | | - tempP3.x = myMap.getVertex(width - 1, y).x + triangleWidth; |
353 | | - DrawTriangle(display, displayRect, myMap, type, myMap.getVertex(width - 1, y + 1), |
354 | | - myMap.getVertex(width - 1, y), tempP3); |
| 356 | + // last RightSideUp |
| 357 | + DrawTriangle(display, displayRect, myMap, type, myMap.getVertex(static_cast<int>(width) - 1, y), |
| 358 | + myMap.getVertex(static_cast<int>(width) - 2, static_cast<int>(y) + 1), |
| 359 | + myMap.getVertex(static_cast<int>(width) - 1, static_cast<int>(y) + 1)); |
| 360 | + // last UpSideDown (wrap edge, s25client convention) |
| 361 | + // Visual column width-1, source vertex = width-1, P3 wraps to 0 |
| 362 | + const int sx = clientUsdX(static_cast<int>(width) - 1, static_cast<int>(y)); |
| 363 | + const int sx_p3 = (sx + 1 >= static_cast<int>(width)) ? sx + 1 - static_cast<int>(width) : sx + 1; |
| 364 | + MapNode tP3 = myMap.getVertex(sx_p3, y); |
| 365 | + tP3.x = myMap.getVertex(sx, y).x + triangleWidth; |
| 366 | + DrawTriangle(display, displayRect, myMap, type, |
| 367 | + myMap.getVertex(sx, y + 1), // P1 = bottom-left (even y: y&1=0) |
| 368 | + myMap.getVertex(sx, y), // P2 = top |
| 369 | + tP3); // P3 = bottom-right, wrapped to (0,y) |
355 | 370 | } else |
356 | 371 | { |
357 | 372 | for(unsigned x = col_start; x < width - 1u && x <= static_cast<unsigned>(col_end); x++) |
358 | 373 | { |
359 | | - // RightSideUp |
| 374 | + // RightSideUp (same in both conventions) |
360 | 375 | DrawTriangle(display, displayRect, myMap, type, myMap.getVertex(x, y), |
361 | 376 | myMap.getVertex(x, y + 1), myMap.getVertex(x + 1, y + 1)); |
362 | | - // UpSideDown |
363 | | - DrawTriangle(display, displayRect, myMap, type, myMap.getVertex(x + 1, y + 1), |
364 | | - myMap.getVertex(x, y), myMap.getVertex(x + 1, y)); |
| 377 | + // UpSideDown (s25client convention) |
| 378 | + const auto usd = clientUsdTriangleVertices(x, y); |
| 379 | + DrawTriangle(display, displayRect, myMap, type, myMap.getVertex(usd.p1x, usd.p1y), |
| 380 | + myMap.getVertex(usd.p2x, usd.p2y), myMap.getVertex(usd.p3x, usd.p3y)); |
365 | 381 | } |
366 | 382 | // last RightSideUp |
367 | 383 | tempP3 = myMap.getVertex(0, y + 1); |
368 | 384 | tempP3.x = myMap.getVertex(width - 1, y + 1).x + triangleWidth; |
369 | 385 | DrawTriangle(display, displayRect, myMap, type, myMap.getVertex(width - 1, y), |
370 | 386 | myMap.getVertex(width - 1, y + 1), tempP3); |
371 | | - // last UpSideDown |
372 | | - tempP1 = myMap.getVertex(0, y + 1); |
373 | | - tempP1.x = myMap.getVertex(width - 1, y + 1).x + triangleWidth; |
374 | | - tempP3 = myMap.getVertex(0, y); |
375 | | - tempP3.x = myMap.getVertex(width - 1, y).x + triangleWidth; |
376 | | - DrawTriangle(display, displayRect, myMap, type, tempP1, myMap.getVertex(width - 1, y), tempP3); |
| 387 | + // last UpSideDown (wrap edge, s25client convention) |
| 388 | + const int sx = clientUsdX(static_cast<int>(width) - 1, static_cast<int>(y)); |
| 389 | + const int sx1_w = (sx + 1 >= static_cast<int>(width)) ? sx + 1 - static_cast<int>(width) : sx + 1; |
| 390 | + MapNode tP1 = myMap.getVertex(sx1_w, y + 1); |
| 391 | + tP1.x = myMap.getVertex(sx, y + 1).x + triangleWidth; |
| 392 | + MapNode tP3 = myMap.getVertex(sx1_w, y); |
| 393 | + tP3.x = myMap.getVertex(sx, y).x + triangleWidth; |
| 394 | + DrawTriangle(display, displayRect, myMap, type, |
| 395 | + tP1, // P1 = bottom-left (odd y: y&1=1) |
| 396 | + myMap.getVertex(sx, y), // P2 = top |
| 397 | + tP3); // P3 = bottom-right, wrapped |
377 | 398 | } |
378 | 399 | } |
379 | 400 |
|
|
0 commit comments