Skip to content

Commit 12dc570

Browse files
author
Morgan Christiansson
committed
Simplify
1 parent ecd7dc1 commit 12dc570

3 files changed

Lines changed: 46 additions & 66 deletions

File tree

CMap.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -259,17 +259,17 @@ std::unique_ptr<bobMAP> CMap::generateMap(int width, int height, MapType type, T
259259
{
260260
for(int i = 0; i < myMap->width; i++)
261261
{
262-
MapNode& curVertex = myMap->getVertex(i, j);
262+
MapNode& curVertex = myMap->getVertex(clientUsdVertexPos(i, j));
263263
curVertex.h = 0x0A;
264264

265265
if((j < border || myMap->height - j <= border) || (i < border || myMap->width - i <= border))
266266
{
267267
curVertex.rsuTexture = border_texture;
268-
myMap->getVertex(clientUsdVertexPos(i, j)).usdTexture = border_texture;
268+
curVertex.usdTexture = border_texture;
269269
} else
270270
{
271271
curVertex.rsuTexture = texture;
272-
myMap->getVertex(clientUsdVertexPos(i, j)).usdTexture = texture;
272+
curVertex.usdTexture = texture;
273273
}
274274

275275
// initialize all other blocks -- outcommented blocks are recalculated at map load
@@ -1838,6 +1838,7 @@ void CMap::modifyShading(Position pos)
18381838

18391839
void CMap::modifyTexture(Position pos, bool rsu, bool usd)
18401840
{
1841+
MapNode& vertex = map->getVertex(clientUsdVertexPos(pos));
18411842
if(modeContent == TRIANGLE_TEXTURE_MEADOW_MIXED || modeContent == TRIANGLE_TEXTURE_MEADOW_MIXED_HARBOUR)
18421843
{
18431844
int newContent = rand() % 3;
@@ -1861,15 +1862,15 @@ void CMap::modifyTexture(Position pos, bool rsu, bool usd)
18611862
newContent = TRIANGLE_TEXTURE_MEADOW3_HARBOUR;
18621863
}
18631864
if(rsu)
1864-
map->getVertex(pos.x, pos.y).rsuTexture = newContent;
1865+
vertex.rsuTexture = newContent;
18651866
if(usd)
1866-
map->getVertex(clientUsdVertexPos(pos)).usdTexture = newContent;
1867+
vertex.usdTexture = newContent;
18671868
} else
18681869
{
18691870
if(rsu)
1870-
map->getVertex(pos.x, pos.y).rsuTexture = modeContent;
1871+
vertex.rsuTexture = modeContent;
18711872
if(usd)
1872-
map->getVertex(clientUsdVertexPos(pos)).usdTexture = modeContent;
1873+
vertex.usdTexture = modeContent;
18731874
}
18741875

18751876
// at least setup the possible building and the resources at the vertex and 1 section/2 sections around

CSurface.cpp

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -334,47 +334,42 @@ void CSurface::DrawTriangleField(SDL_Surface* display, const DisplayRectangle& d
334334
{
335335
if(y % 2 == 0)
336336
{
337-
// first RightSideUp (edge wrap)
337+
// first RightSideUp
338338
tempP2 = myMap.getVertex(width - 1, y + 1);
339339
tempP2.x = 0;
340340
DrawTriangle(display, displayRect, myMap, type, myMap.getVertex(0, y), tempP2,
341341
myMap.getVertex(0, y + 1));
342-
// first UpSideDown (s25client convention, visual column 0)
342+
// first UpSideDown
343343
const auto usd0 = clientUsdTriangleVertices(0, y);
344344
DrawTriangle(display, displayRect, myMap, type, myMap.getVertex(usd0.p1x, usd0.p1y),
345345
myMap.getVertex(usd0.p2x, usd0.p2y), myMap.getVertex(usd0.p3x, usd0.p3y));
346346
for(unsigned x = std::max(col_start, 1); x < width - 1u && x <= static_cast<unsigned>(col_end); x++)
347347
{
348-
// RightSideUp (same in both conventions)
348+
// RightSideUp
349349
DrawTriangle(display, displayRect, myMap, type, myMap.getVertex(x, y),
350350
myMap.getVertex(x - 1, y + 1), myMap.getVertex(x, y + 1));
351-
// UpSideDown (s25client convention)
351+
// UpSideDown
352352
const auto usd = clientUsdTriangleVertices(x, y);
353353
DrawTriangle(display, displayRect, myMap, type, myMap.getVertex(usd.p1x, usd.p1y),
354354
myMap.getVertex(usd.p2x, usd.p2y), myMap.getVertex(usd.p3x, usd.p3y));
355355
}
356356
// 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)
357+
DrawTriangle(display, displayRect, myMap, type, myMap.getVertex(width - 1, y),
358+
myMap.getVertex(width - 2, y + 1),
359+
myMap.getVertex(width - 1, y + 1));
360+
// last UpSideDown
361+
tempP3 = myMap.getVertex(0, y);
362+
tempP3.x = myMap.getVertex(width - 1, y).x + triangleWidth;
363+
DrawTriangle(display, displayRect, myMap, type, myMap.getVertex(width - 1, y + 1),
364+
myMap.getVertex(width - 1, y), tempP3);
370365
} else
371366
{
372367
for(unsigned x = col_start; x < width - 1u && x <= static_cast<unsigned>(col_end); x++)
373368
{
374-
// RightSideUp (same in both conventions)
369+
// RightSideUp
375370
DrawTriangle(display, displayRect, myMap, type, myMap.getVertex(x, y),
376371
myMap.getVertex(x, y + 1), myMap.getVertex(x + 1, y + 1));
377-
// UpSideDown (s25client convention)
372+
// UpSideDown
378373
const auto usd = clientUsdTriangleVertices(x, y);
379374
DrawTriangle(display, displayRect, myMap, type, myMap.getVertex(usd.p1x, usd.p1y),
380375
myMap.getVertex(usd.p2x, usd.p2y), myMap.getVertex(usd.p3x, usd.p3y));
@@ -384,17 +379,12 @@ void CSurface::DrawTriangleField(SDL_Surface* display, const DisplayRectangle& d
384379
tempP3.x = myMap.getVertex(width - 1, y + 1).x + triangleWidth;
385380
DrawTriangle(display, displayRect, myMap, type, myMap.getVertex(width - 1, y),
386381
myMap.getVertex(width - 1, y + 1), 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
382+
// last UpSideDown
383+
tempP1 = myMap.getVertex(0, y + 1);
384+
tempP1.x = myMap.getVertex(width - 1, y + 1).x + triangleWidth;
385+
tempP3 = myMap.getVertex(0, y);
386+
tempP3.x = myMap.getVertex(width - 1, y).x + triangleWidth;
387+
DrawTriangle(display, displayRect, myMap, type, tempP1, myMap.getVertex(width - 1, y), tempP3);
398388
}
399389
}
400390

GEOMETRY.md

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,26 @@ SPDX-License-Identifier: GPL-3.0-or-later
66

77
# Map geometry alignment with s25client
88

9-
The editor and s25client both use a staggered hexagonal grid. RSU triangles are
10-
identical, but the **USD triangle label convention differs on even rows**.
9+
The editor and s25client both use the same staggered hexagonal grid. **RSU
10+
triangles are identical** in both conventions. **USD triangles differ only on
11+
even rows**: the old editor convention stored the texture for visual USD(x, y)
12+
at `vertex(x-1, y)` on even rows. The new s25client convention stores it at
13+
`vertex(x, y)` — identity mapping on all rows. Odd rows were already identity
14+
and unchanged.
1115

12-
## The mapping
16+
## Changes by component
1317

14-
Same physical triangle, different visual label:
15-
16-
```
17-
s25client USD(x, y) ≡ editor USD(x + !(y & 1), y)
18-
editor USD(x, y) ≡ s25client USD(x - !(y & 1), y)
19-
```
20-
21-
Odd rows (`y & 1 == 1`) are identical.
22-
23-
## In-memory convention: s25client
24-
25-
bobMAP now uses s25client convention throughout:
26-
`vertex(x,y).usdTexture` ≡ texture for visual USD(x, y) (s25client naming).
27-
28-
| Component | Change |
29-
|-----------|--------|
30-
| **Rendering** (`CSurface.cpp`) | `DrawTriangleField` uses `clientUsdTriangleVertices(x, y)` — reads `vertex(x,y).usdTexture` for visual USD(x,y) |
31-
| **File load** (`CIO/CFile.cpp`) | Read each file byte at (i,j); for even rows store at `memory(i+1, j)`, for odd at `memory(i, j)`. Formula: `memory(i, j) = file(i - !(j&1), j)` |
32-
| **File save** (`CIO/CFile.cpp`) | For even rows read from `memory(i+1, j)` and write sequentially; for odd read from `memory(i, j)`. Formula: `file(i, j) = memory(i - !(j&1), j)` |
33-
| **Map generation** (`CMap.cpp`) | Already correct — border check is vertex-position-based, matching s25client's identity mapping |
18+
| Component | What changed |
19+
|-----------|-------------|
20+
| **File I/O** (`CIO/CFile.cpp`) | Load/save shift USD data between file and memory on even rows: `memory(i,j) = file(i-1, j)` / `file(i,j) = memory(i+1, j)` |
21+
| **Rendering** (`CSurface.cpp`) | `DrawTriangleField` uses `clientUsdTriangleVertices(x,y)` which maps visual USD(x,y) → correct vertices (identity) |
22+
| **In-memory** (`CMap.cpp`) | All USD texture accesses use `vertex(x,y).usdTexture` directly — no offset needed |
3423

3524
## Wrappers (`include/Geometry.h`)
3625

37-
| Function | Returns | Use |
38-
|----------|---------|-----|
39-
| `clientUsdX(x, y)` | `x` | Native — matches in-memory s25client storage |
40-
| `editorUsdX(x, y)` | `x - !(y & 1)` | Backward compat for non-updated code |
41-
| `clientUsdTriangleVertices(x, y)` | USD vertex coords | Native — s25client label → vertices |
42-
| `editorUsdTriangleVertices(x, y)` | USD vertex coords | Backward compat — editor label → vertices |
26+
| Function | Returns | Purpose |
27+
|----------|---------|---------|
28+
| `clientUsdX(x, y)` | `x` | Identity — matches s25client storage |
29+
| `editorUsdX(x, y)` | `x - !(y & 1)` | Transition helper for non-updated code |
30+
| `clientUsdTriangleVertices(x, y)` | USD vertex coords | s25client convention → vertices |
31+
| `editorUsdTriangleVertices(x, y)` | USD vertex coords | Old convention → vertices |

0 commit comments

Comments
 (0)