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

Return-To-The-Roots / s25client / 20580964505

29 Dec 2025 07:24PM UTC coverage: 50.48% (-0.02%) from 50.503%
20580964505

Pull #1804

github

web-flow
Merge fa9b1433c into af2863637
Pull Request #1804: Android build

66 of 229 new or added lines in 13 files covered. (28.82%)

2 existing lines in 2 files now uncovered.

22599 of 44768 relevant lines covered (50.48%)

36851.81 hits per line

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

13.09
/libs/s25main/world/GameWorldView.cpp
1
// Copyright (C) 2005 - 2021 Settlers Freaks (sf-team at siedler25.org)
2
//
3
// SPDX-License-Identifier: GPL-2.0-or-later
4

5
#include "world/GameWorldView.h"
6
#include "CatapultStone.h"
7
#include "FOWObjects.h"
8
#include "GamePlayer.h"
9
#include "GlobalGameSettings.h"
10
#include "Loader.h"
11
#include "MapGeometry.h"
12
#include "Settings.h"
13
#include "addons/AddonMaxWaterwayLength.h"
14
#include "buildings/noBuildingSite.h"
15
#include "buildings/nobMilitary.h"
16
#include "buildings/nobUsual.h"
17
#include "drivers/VideoDriverWrapper.h"
18
#include "helpers/EnumArray.h"
19
#include "helpers/containerUtils.h"
20
#include "helpers/toString.h"
21
#include "ogl/FontStyle.h"
22
#include "ogl/glArchivItem_Bitmap.h"
23
#include "ogl/glFont.h"
24
#include "ogl/glSmartBitmap.h"
25
#include "world/GameWorldBase.h"
26
#include "world/GameWorldViewer.h"
27
#include "gameTypes/RoadBuildState.h"
28
#include "gameData/BuildingConsts.h"
29
#include "gameData/GuiConsts.h"
30
#include "gameData/MapConsts.h"
31
#include "s25util/error.h"
32
#include "s25util/warningSuppression.h"
33
#include <glad/glad.h>
34
#include <boost/format.hpp>
35
#include <cmath>
36

37
GameWorldView::GameWorldView(const GameWorldViewer& gwv, const Position& pos, const Extent& size)
9✔
38
    : selPt(0, 0), show_bq(SETTINGS.ingame.showBQ), show_names(SETTINGS.ingame.showNames),
9✔
39
      show_productivity(SETTINGS.ingame.showProductivity), offset(0, 0), lastOffset(0, 0), gwv(gwv), origin_(pos),
18✔
40
      size_(size), zoomFactor_(1.f), targetZoomFactor_(1.f), zoomSpeed_(0.f)
18✔
41
{
42
    updateEffectiveZoomFactor();
9✔
43
    MoveBy({0, 0});
9✔
44
}
9✔
45

46
const GameWorldBase& GameWorldView::GetWorld() const
80✔
47
{
48
    return gwv.GetWorld();
80✔
49
}
50

51
SoundManager& GameWorldView::GetSoundMgr()
×
52
{
53
    return const_cast<GameWorldViewer&>(gwv).GetSoundMgr();
×
54
}
55

56
void GameWorldView::SetNextZoomFactor()
×
57
{
58
    if(zoomFactor_ == targetZoomFactor_) // == with float is ok here, is explicitly set in last step //-V550
×
59
        return;
×
60

61
    float remainingZoomDiff = targetZoomFactor_ - zoomFactor_;
×
62

63
    if(std::abs(remainingZoomDiff) <= 0.5 * zoomSpeed_ * zoomSpeed_ / ZOOM_ACCELERATION)
×
64
    {
65
        // deceleration towards zero zoom speed
66
        if(zoomSpeed_ > 0)
×
67
            zoomSpeed_ -= ZOOM_ACCELERATION;
×
68
        else
69
            zoomSpeed_ += ZOOM_ACCELERATION;
×
70
    } else
71
    {
72
        // acceleration to unlimited speed
73
        if(remainingZoomDiff > 0)
×
74
            zoomSpeed_ += ZOOM_ACCELERATION;
×
75
        else
76
            zoomSpeed_ -= ZOOM_ACCELERATION;
×
77
    }
78

79
    if(std::abs(remainingZoomDiff) < std::abs(zoomSpeed_))
×
80
    {
81
        // last step
82
        zoomFactor_ = targetZoomFactor_;
×
83
        zoomSpeed_ = 0;
×
84
    }
85

86
    zoomFactor_ = zoomFactor_ + zoomSpeed_;
×
87
    updateEffectiveZoomFactor();
×
88
    CalcFxLx();
×
89
}
90

91
float GameWorldView::SetZoomFactor(float zoomFactor, bool smoothTransition /* = true*/)
38✔
92
{
93
    targetZoomFactor_ = zoomFactor;
38✔
94
    if(!smoothTransition)
38✔
95
    {
96
        zoomFactor_ = targetZoomFactor_;
×
97
        updateEffectiveZoomFactor();
×
98
        CalcFxLx();
×
99
    }
100
    return targetZoomFactor_;
38✔
101
}
102

103
float GameWorldView::GetCurrentTargetZoomFactor() const
54✔
104
{
105
    return targetZoomFactor_;
54✔
106
}
107

108
Position GameWorldView::ViewPosToMap(Position pos) const
3✔
109
{
110
    pos -= origin_;
3✔
111
    if(effectiveZoomFactor_ != 1.f)
3✔
112
    {
NEW
113
        PointF diff(size_.x - size_.x / effectiveZoomFactor_, size_.y - size_.y / effectiveZoomFactor_);
×
NEW
114
        diff /= 2.f;
×
NEW
115
        pos = Position(PointF(pos) / effectiveZoomFactor_ + diff);
×
116
    }
117

118
    return pos;
3✔
119
}
120

121
struct ObjectBetweenLines
122
{
123
    noBase& obj;
124
    DrawPoint pos; // Zeichenposition
125

126
    ObjectBetweenLines(noBase& obj, const DrawPoint& pos) : obj(obj), pos(pos) {}
×
127
};
128

129
void GameWorldView::Draw(const RoadBuildState& rb, const MapPoint selected, bool drawMouse, unsigned* water)
×
130
{
131
    SetNextZoomFactor();
×
132

133
    const auto windowSize = VIDEODRIVER.GetWindowSize();
×
134
    const auto& guiScale = VIDEODRIVER.getGuiScale();
×
135
    const auto screenOrigin = guiScale.viewToScreen(origin_);
×
136
    const auto screenSize = guiScale.viewToScreen(size_);
×
137
    glScissor(screenOrigin.x, windowSize.height - (screenOrigin.y + screenSize.y), screenSize.x, screenSize.y);
×
138

139
    int shortestDistToMouse = 100000;
×
140
    Position mousePos = VIDEODRIVER.GetMousePos();
×
141
    mousePos -= Position(origin_);
×
142
    if(effectiveZoomFactor_ != 1.f) //-V550
×
143
    {
144
        glMatrixMode(GL_PROJECTION);
×
145
        glPushMatrix();
×
146
        glScalef(effectiveZoomFactor_, effectiveZoomFactor_, 1);
×
147
        // Offset to center view
148
        PointF diff(size_.x - size_.x / effectiveZoomFactor_, size_.y - size_.y / effectiveZoomFactor_);
×
149
        diff = diff / 2.f;
×
150
        glTranslatef(-diff.x, -diff.y, 0.f);
×
151
        // Also adjust mouse
152
        mousePos = Position(PointF(mousePos) / effectiveZoomFactor_ + diff);
×
153
        glMatrixMode(GL_MODELVIEW);
×
154
    }
155

156
    glTranslatef(static_cast<GLfloat>(origin_.x) / effectiveZoomFactor_,
×
157
                 static_cast<GLfloat>(origin_.y) / effectiveZoomFactor_, 0.0f);
×
158

159
    glTranslatef(static_cast<GLfloat>(-offset.x), static_cast<GLfloat>(-offset.y), 0.0f);
×
160
    const TerrainRenderer& terrainRenderer = gwv.GetTerrainRenderer();
×
161
    terrainRenderer.Draw(GetFirstPt(), GetLastPt(), gwv, water);
×
162
    glTranslatef(static_cast<GLfloat>(offset.x), static_cast<GLfloat>(offset.y), 0.0f);
×
163

164
    for(int y = firstPt.y; y <= lastPt.y; ++y)
×
165
    {
166
        // Figuren speichern, die in dieser Zeile gemalt werden müssen
167
        // und sich zwischen zwei Zeilen befinden, da sie dazwischen laufen
168
        std::vector<ObjectBetweenLines> between_lines;
×
169

170
        for(int x = firstPt.x; x <= lastPt.x; ++x)
×
171
        {
172
            Position curOffset;
×
173
            const MapPoint curPt = terrainRenderer.ConvertCoords(Position(x, y), &curOffset);
×
174
            DrawPoint curPos = GetWorld().GetNodePos(curPt) - offset + curOffset;
×
175

176
            Position mouseDist = mousePos - curPos;
×
177
            mouseDist *= mouseDist;
×
178
            if(std::abs(mouseDist.x) + std::abs(mouseDist.y) < shortestDistToMouse)
×
179
            {
180
                selPt = curPt;
×
181
                selPtOffset = curOffset;
×
182
                shortestDistToMouse = std::abs(mouseDist.x) + std::abs(mouseDist.y);
×
183
            }
184

185
            Visibility visibility = gwv.GetVisibility(curPt);
×
186

187
            DrawBoundaryStone(curPt, curPos, visibility);
×
188

189
            if(visibility == Visibility::Visible)
×
190
            {
191
                DrawObject(curPt, curPos);
×
192
                DrawMovingFiguresFromBelow(terrainRenderer, Position(x, y), between_lines);
×
193
                DrawFigures(curPt, curPos, between_lines);
×
194

195
                // Construction aid mode
196
                if(show_bq)
×
197
                    DrawConstructionAid(curPt, curPos);
×
198
            } else if(visibility == Visibility::FogOfWar)
×
199
            {
200
                const FOWObject* fowobj = gwv.GetYoungestFOWObject(MapPoint(curPt));
×
201
                if(fowobj)
×
202
                    fowobj->Draw(curPos);
×
203
            }
204

205
            for(IDrawNodeCallback* callback : drawNodeCallbacks)
×
206
                callback->onDraw(curPt, curPos);
×
207
        }
208

209
        // Figuren zwischen den Zeilen zeichnen
210
        for(auto& between_line : between_lines)
×
211
            between_line.obj.Draw(between_line.pos);
×
212
    }
213

214
    if(show_names || show_productivity)
×
215
        DrawNameProductivityOverlay(terrainRenderer);
×
216

217
    DrawGUI(rb, terrainRenderer, selected, drawMouse);
×
218

219
    // Umherfliegende Katapultsteine zeichnen
220
    for(auto* catapult_stone : GetWorld().catapult_stones)
×
221
    {
222
        if(gwv.GetVisibility(catapult_stone->dest_building) == Visibility::Visible
×
223
           || gwv.GetVisibility(catapult_stone->dest_map) == Visibility::Visible)
×
224
            catapult_stone->Draw(offset);
×
225
    }
226

227
    if(effectiveZoomFactor_ != 1.f) //-V550
×
228
    {
229
        glMatrixMode(GL_PROJECTION);
×
230
        glPopMatrix();
×
231
        glMatrixMode(GL_MODELVIEW);
×
232
    }
233
    glTranslatef(-static_cast<GLfloat>(origin_.x) / effectiveZoomFactor_,
×
234
                 -static_cast<GLfloat>(origin_.y) / effectiveZoomFactor_, 0.0f);
×
235

236
    glScissor(0, 0, windowSize.width, windowSize.height);
×
237
}
×
238

239
void GameWorldView::DrawGUI(const RoadBuildState& rb, const TerrainRenderer& terrainRenderer,
×
240
                            const MapPoint& selectedPt, bool drawMouse)
241
{
242
    // Falls im Straßenbaumodus: Punkte um den aktuellen Straßenbaupunkt herum ermitteln
243
    helpers::EnumArray<MapPoint, Direction> road_points;
×
244

245
    unsigned maxWaterWayLen = 0;
×
246
    if(rb.mode != RoadBuildMode::Disabled)
×
247
    {
248
        for(const auto dir : helpers::EnumRange<Direction>{})
×
249
            road_points[dir] = GetWorld().GetNeighbour(rb.point, dir);
×
250

251
        const unsigned index = GetWorld().GetGGS().getSelection(AddonId::MAX_WATERWAY_LENGTH);
×
252
        RTTR_Assert(index < waterwayLengths.size());
×
253
        maxWaterWayLen = waterwayLengths[index];
×
254
    }
255

256
    for(int x = firstPt.x; x <= lastPt.x; ++x)
×
257
    {
258
        for(int y = firstPt.y; y <= lastPt.y; ++y)
×
259
        {
260
            // Coordinates transform
261
            Position curOffset;
×
262
            MapPoint curPt = terrainRenderer.ConvertCoords(Position(x, y), &curOffset);
×
263
            Position curPos = GetWorld().GetNodePos(curPt) - offset + curOffset;
×
264

265
            /// Current point indicated by Mouse
266
            if(drawMouse && selPt == curPt)
×
267
            {
268
                // Mauszeiger am boden
269
                unsigned mid = 22;
×
270
                if(rb.mode == RoadBuildMode::Disabled)
×
271
                {
272
                    switch(gwv.GetBQ(curPt))
×
273
                    {
274
                        case BuildingQuality::Flag: mid = 40; break;
×
275
                        case BuildingQuality::Mine: mid = 41; break;
×
276
                        case BuildingQuality::Hut: mid = 42; break;
×
277
                        case BuildingQuality::House: mid = 43; break;
×
278
                        case BuildingQuality::Castle: mid = 44; break;
×
279
                        case BuildingQuality::Harbor: mid = 45; break;
×
280
                        default: break;
×
281
                    }
282
                }
283
                LOADER.GetMapTexture(mid)->DrawFull(curPos);
×
284
            }
285

286
            // Currently selected point
287
            if(selectedPt == curPt)
×
288
                LOADER.GetMapTexture(20)->DrawFull(curPos);
×
289

290
            // not building roads, no further action needed
291
            if(rb.mode == RoadBuildMode::Disabled)
×
292
                continue;
×
293

294
            // we dont own curPt, no need for any rendering...
295
            if(!gwv.IsPlayerTerritory(curPt))
×
296
                continue;
×
297

298
            // we are in road build mode
299
            // highlight current route pt
300
            if(rb.point == curPt)
×
301
            {
302
                LOADER.GetMapTexture(21)->DrawFull(curPos);
×
303
                continue;
×
304
            }
305

306
            // ensure that curPt is a neighbour of rb.point
307
            if(!helpers::contains(road_points, curPt))
×
308
            {
309
                continue;
×
310
            }
311

312
            // test on maximal water way length
313
            if(rb.mode == RoadBuildMode::Boat && maxWaterWayLen != 0 && rb.route.size() >= maxWaterWayLen)
×
314
                continue;
×
315

316
            // render special icon for route revert
317
            if(!rb.route.empty() && road_points[rb.route.back() + 3u] == curPt)
×
318
            {
319
                LOADER.GetMapTexture(67)->DrawFull(curPos);
×
320
                continue;
×
321
            }
322

323
            // is a flag but not the route start flag, as it would revert the route.
324
            const bool targetFlag = GetWorld().GetNO(curPt)->GetType() == NodalObjectType::Flag && curPt != rb.start;
×
325
            int altitude = GetWorld().GetNode(rb.point).altitude;
×
326
            if(targetFlag || gwv.IsRoadAvailable(rb.mode == RoadBuildMode::Boat, curPt))
×
327
            {
328
                unsigned id;
329
                switch(int(GetWorld().GetNode(curPt).altitude) - altitude)
×
330
                {
331
                    case 1: id = 61; break;
×
332
                    case 2:
×
333
                    case 3: id = 62; break;
×
334
                    case 4:
×
335
                    case 5: id = 63; break;
×
336
                    case -1: id = 64; break;
×
337
                    case -2:
×
338
                    case -3: id = 65; break;
×
339
                    case -4:
×
340
                    case -5: id = 66; break;
×
341
                    default: id = 60; break;
×
342
                }
343
                if(!targetFlag)
×
344
                    LOADER.GetMapTexture(id)->DrawFull(curPos);
×
345
                else
346
                {
347
                    DrawPoint lastPos = GetWorld().GetNodePos(rb.point) - offset + curOffset;
×
348
                    DrawPoint halfWayPos = (curPos + lastPos) / 2;
×
349
                    LOADER.GetMapTexture(id)->DrawFull(halfWayPos);
×
350
                    LOADER.GetMapTexture(20)->DrawFull(curPos);
×
351
                }
352
            }
353
        }
354
    }
355
}
×
356

357
void GameWorldView::DrawNameProductivityOverlay(const TerrainRenderer& terrainRenderer)
×
358
{
359
    for(int x = firstPt.x; x <= lastPt.x; ++x)
×
360
    {
361
        for(int y = firstPt.y; y <= lastPt.y; ++y)
×
362
        {
363
            // Coordinate transform
364
            Position curOffset;
×
365
            MapPoint pt = terrainRenderer.ConvertCoords(Position(x, y), &curOffset);
×
366

367
            const auto* no = GetWorld().GetSpecObj<noBaseBuilding>(pt);
×
368
            if(!no)
×
369
                continue;
×
370

371
            Position curPos = GetWorld().GetNodePos(pt) - offset + curOffset;
×
372
            curPos.y -= 22;
×
373

374
            // Is object not belonging to local player?
375
            if(no->GetPlayer() != gwv.GetPlayerId())
×
376
            {
377
                if(GetWorld().GetGGS().getSelection(AddonId::MILITARY_AID) == 2 && gwv.GetNumSoldiersForAttack(pt) > 0)
×
378
                {
379
                    auto* attackAidImage = LOADER.GetImageN("map_new", 20000);
×
380
                    attackAidImage->DrawFull(curPos - DrawPoint(0, attackAidImage->getHeight()));
×
381
                }
382
                continue;
×
383
            }
384

385
            // Draw object name
386
            if(show_names)
×
387
            {
388
                unsigned color = (no->GetGOT() == GO_Type::Buildingsite) ? COLOR_GREY : COLOR_YELLOW;
×
389
                SmallFont->Draw(curPos, _(BUILDING_NAMES[no->GetBuildingType()]),
×
390
                                FontStyle::CENTER | FontStyle::VCENTER, color);
391
                curPos.y += SmallFont->getHeight();
×
392
            }
393

394
            // Draw productivity/soldiers
395
            if(show_productivity)
×
396
                DrawProductivity(*no, curPos);
×
397
        }
398
    }
399
}
×
400

401
void GameWorldView::DrawProductivity(const noBaseBuilding& no, const DrawPoint& curPos)
×
402
{
403
    const GO_Type got = no.GetGOT();
×
404
    if(got == GO_Type::Buildingsite)
×
405
    {
406
        unsigned color = COLOR_GREY;
×
407

408
        unsigned short p = static_cast<const noBuildingSite&>(no).GetBuildProgress();
×
409
        SmallFont->Draw(curPos, (boost::format("(%1% %%)") % p).str(), FontStyle::CENTER | FontStyle::VCENTER, color);
×
410
    } else if(got == GO_Type::NobUsual || got == GO_Type::NobShipyard || got == GO_Type::NobTemple)
×
411
    {
412
        const auto& n = static_cast<const nobUsual&>(no);
×
413
        std::string text;
×
414
        unsigned color = COLOR_0_PERCENT;
×
415

416
        if(!n.HasWorker())
×
417
            text = _("(House unoccupied)");
×
418
        else if(n.IsProductionDisabledVirtual())
×
419
            text = _("(stopped)");
×
420
        else
421
        {
422
            // Catapult and Lookout tower doesn't have productivity!
423
            if(n.GetBuildingType() == BuildingType::Catapult || n.GetBuildingType() == BuildingType::LookoutTower)
×
424
                return;
×
425

426
            unsigned short p = n.GetProductivity();
×
427
            text = helpers::toString(p) + " %";
×
428
            if(p >= 60)
×
429
                color = COLOR_60_PERCENT;
×
430
            else if(p >= 30)
×
431
                color = COLOR_30_PERCENT;
×
432
            else if(p >= 20)
×
433
                color = COLOR_20_PERCENT;
×
434
        }
435
        SmallFont->Draw(curPos, text, FontStyle::CENTER | FontStyle::VCENTER, color);
×
436
    } else if(got == GO_Type::NobMilitary)
×
437
    {
438
        // Display amount of soldiers
439
        unsigned soldiers_count = static_cast<const nobMilitary&>(no).GetNumTroops();
×
440
        std::string sSoldiers;
×
441
        if(soldiers_count == 1)
×
442
            sSoldiers = _("(1 soldier)");
×
443
        else
444
            sSoldiers = boost::str(boost::format(_("(%d soldiers)")) % soldiers_count);
×
445

446
        SmallFont->Draw(curPos, sSoldiers, FontStyle::CENTER | FontStyle::VCENTER,
×
447
                        (soldiers_count > 0) ? COLOR_YELLOW : COLOR_RED);
×
448
    }
449
}
450

451
void GameWorldView::DrawFigures(const MapPoint& pt, const DrawPoint& curPos,
×
452
                                std::vector<ObjectBetweenLines>& between_lines) const
453
{
454
    for(noBase& figure : GetWorld().GetFigures(pt))
×
455
    {
456
        if(figure.IsMoving())
×
457
        {
458
            // Drawn from above
459
            Direction curMoveDir = static_cast<noMovable&>(figure).GetCurMoveDir();
×
460
            if(curMoveDir == Direction::NorthEast || curMoveDir == Direction::NorthWest)
×
461
                continue;
×
462
            // Draw later
463
            between_lines.push_back(ObjectBetweenLines(figure, curPos));
×
464
        } else if(figure.GetGOT() == GO_Type::Ship)
×
465
            between_lines.push_back(ObjectBetweenLines(figure, curPos)); // TODO: Why special handling for ships?
×
466
        else
467
            // Ansonsten jetzt schon zeichnen
468
            figure.Draw(curPos);
×
469
    }
470
}
×
471

472
void GameWorldView::DrawMovingFiguresFromBelow(const TerrainRenderer& terrainRenderer, const DrawPoint& curPos,
×
473
                                               std::vector<ObjectBetweenLines>& between_lines)
474
{
475
    // First draw figures moving towards this point from below
476
    static const std::array<Direction, 2> aboveDirs = {{Direction::NorthEast, Direction::NorthWest}};
477
    for(Direction dir : aboveDirs)
×
478
    {
479
        // Get figures opposite the current dir and check if they are moving in this dir
480
        // Coordinates transform
481
        Position curOffset;
×
482
        MapPoint curPt = terrainRenderer.ConvertCoords(GetNeighbour(curPos, dir + 3u), &curOffset);
×
483
        Position figPos = GetWorld().GetNodePos(curPt) - offset + curOffset;
×
484

485
        for(noBase& figure : GetWorld().GetFigures(curPt))
×
486
        {
487
            if(figure.IsMoving() && static_cast<noMovable&>(figure).GetCurMoveDir() == dir)
×
488
                between_lines.push_back(ObjectBetweenLines(figure, figPos));
×
489
        }
490
    }
491
}
×
492

493
constexpr auto getBqImgs()
494
{
495
    helpers::EnumArray<unsigned, BuildingQuality> imgs{};
496
    imgs[BuildingQuality::Flag] = 50;
497
    imgs[BuildingQuality::Hut] = 51;
498
    imgs[BuildingQuality::House] = 52;
499
    imgs[BuildingQuality::Castle] = 53;
500
    imgs[BuildingQuality::Mine] = 54;
501
    imgs[BuildingQuality::Harbor] = 55;
502
    return imgs;
503
}
504

505
void GameWorldView::DrawConstructionAid(const MapPoint& pt, const DrawPoint& curPos)
×
506
{
507
    BuildingQuality bq = gwv.GetBQ(pt);
×
508
    if(bq != BuildingQuality::Nothing)
×
509
    {
510
        constexpr auto bqImgs = getBqImgs();
×
511
        auto* bm = LOADER.GetMapTexture(bqImgs[bq]);
×
512
        // Draw building quality icon
513
        bm->DrawFull(curPos);
×
514
        // Show ability to construct military buildings
515
        if(GetWorld().GetGGS().isEnabled(AddonId::MILITARY_AID))
×
516
        {
517
            if(!GetWorld().IsMilitaryBuildingNearNode(pt, gwv.GetPlayerId())
×
518
               && (bq == BuildingQuality::Hut || bq == BuildingQuality::House || bq == BuildingQuality::Castle
×
519
                   || bq == BuildingQuality::Harbor))
×
520
                LOADER.GetImageN("map_new", 20000)->DrawFull(curPos - DrawPoint(-1, bm->GetSize().y + 5));
×
521
        }
522
    }
523
}
×
524

525
void GameWorldView::DrawObject(const MapPoint& pt, const DrawPoint& curPos) const
×
526
{
527
    noBase* obj = GetWorld().GetNode(pt).obj;
×
528
    if(!obj)
×
529
        return;
×
530

531
    obj->Draw(curPos);
×
532
}
533

534
void GameWorldView::DrawBoundaryStone(const MapPoint& pt, const DrawPoint pos, Visibility vis)
×
535
{
536
    if(vis == Visibility::Invisible)
×
537
        return;
×
538

539
    const bool isFoW = vis == Visibility::FogOfWar;
×
540

541
    const BoundaryStones& boundary_stones =
542
      isFoW ? gwv.GetYoungestFOWNode(pt).boundary_stones : GetWorld().GetNode(pt).boundary_stones;
×
543
    const unsigned char owner = boundary_stones[BorderStonePos::OnPoint];
×
544

545
    if(!owner)
×
546
        return;
×
547

548
    const Nation nation = GetWorld().GetPlayer(owner - 1).nation;
×
549
    unsigned player_color = GetWorld().GetPlayer(owner - 1).color;
×
550
    if(isFoW)
×
551
        player_color = CalcPlayerFOWDrawColor(player_color);
×
552

553
    const auto curVertexPos = gwv.GetTerrainRenderer().GetVertexPos(pt);
×
554
    for(const auto bPos : helpers::EnumRange<BorderStonePos>{})
×
555
    {
556
        DrawPoint curPos;
×
557
        if(bPos == BorderStonePos::OnPoint)
×
558
            curPos = pos;
×
559
        else if(boundary_stones[bPos])
×
560
            curPos = pos
561
                     - DrawPoint((curVertexPos - gwv.GetTerrainRenderer().GetNeighbourVertexPos(pt, toDirection(bPos)))
×
562
                                 / 2.0f);
×
563
        else
564
            continue;
×
565
        LOADER.boundary_stone_cache[nation].draw(curPos, isFoW ? FOW_DRAW_COLOR : COLOR_WHITE, player_color);
×
566
    }
567
}
568

569
void GameWorldView::ToggleShowBQ()
×
570
{
571
    show_bq = !show_bq;
×
572
    SaveIngameSettingsValues();
×
573
    onHudSettingsChanged();
×
574
}
×
575

576
void GameWorldView::ToggleShowNames()
×
577
{
578
    show_names = !show_names;
×
579
    SaveIngameSettingsValues();
×
580
    onHudSettingsChanged();
×
581
}
×
582

583
void GameWorldView::ToggleShowProductivity()
×
584
{
585
    show_productivity = !show_productivity;
×
586
    SaveIngameSettingsValues();
×
587
    onHudSettingsChanged();
×
588
}
×
589

590
void GameWorldView::ToggleShowNamesAndProductivity()
×
591
{
592
    if(show_productivity && show_names)
×
593
        show_productivity = show_names = false;
×
594
    else
595
        show_productivity = show_names = true;
×
596
    SaveIngameSettingsValues();
×
597
    onHudSettingsChanged();
×
598
}
×
599

600
void GameWorldView::CopyHudSettingsTo(GameWorldView& other, bool copyBQ) const
×
601
{
602
    other.show_bq = (copyBQ ? show_bq : false);
×
603
    other.show_names = show_names;
×
604
    other.show_productivity = show_productivity;
×
605
}
×
606

607
void GameWorldView::MoveBy(const DrawPoint& numPixels)
23✔
608
{
609
    MoveTo(offset + numPixels);
23✔
610
}
23✔
611

612
void GameWorldView::MoveTo(const DrawPoint& newPos)
33✔
613
{
614
    offset = newPos;
33✔
615
    DrawPoint size(GetWorld().GetWidth() * TR_W, GetWorld().GetHeight() * TR_H);
33✔
616
    if(size.x && size.y)
33✔
617
    {
618
        offset.x %= size.x;
33✔
619
        offset.y %= size.y;
33✔
620

621
        if(offset.x < 0)
33✔
622
            offset.x += size.x;
5✔
623
        if(offset.y < 0)
33✔
624
            offset.y += size.y;
6✔
625
    }
626

627
    CalcFxLx();
33✔
628
}
33✔
629

630
void GameWorldView::MoveToMapPt(const MapPoint pt)
6✔
631
{
632
    if(!pt.isValid())
6✔
633
        return;
×
634

635
    lastOffset = offset;
6✔
636
    Position nodePos = GetWorld().GetNodePos(pt);
6✔
637

638
    MoveTo(nodePos - GetSize() / 2u);
6✔
639
}
640

641
void GameWorldView::MoveToLastPosition()
×
642
{
643
    Position newLastOffset = offset;
×
644

645
    MoveTo(lastOffset);
×
646

647
    lastOffset = newLastOffset;
×
648
}
×
649

650
void GameWorldView::AddDrawNodeCallback(IDrawNodeCallback* newCallback)
×
651
{
652
    RTTR_Assert(newCallback);
×
653
    drawNodeCallbacks.push_back(newCallback);
×
654
}
×
655

656
void GameWorldView::RemoveDrawNodeCallback(IDrawNodeCallback* callbackToRemove)
×
657
{
658
    auto itPos = helpers::find(drawNodeCallbacks, callbackToRemove);
×
659
    RTTR_Assert(itPos != drawNodeCallbacks.end());
×
660
    drawNodeCallbacks.erase(itPos);
×
661
}
×
662

663
void GameWorldView::CalcFxLx()
33✔
664
{
665
    // Calc first and last point in map units (with 1 extra for incomplete triangles)
666
    firstPt.x = offset.x / TR_W - 1;
33✔
667
    firstPt.y = offset.y / TR_H - 1;
33✔
668
    lastPt.x = (offset.x + size_.x) / TR_W + 1;
33✔
669
    const auto maxAltitude = gwv.getMaxNodeAltitude();
33✔
670
    lastPt.y = (offset.y + size_.y + maxAltitude * HEIGHT_FACTOR) / TR_H + 1;
33✔
671

672
    if(effectiveZoomFactor_ != 1.f) //-V550
33✔
673
    {
674
        // Calc pixels we can remove from sides, as they are not drawn due to zoom
675
        PointF diff(size_.x - size_.x / effectiveZoomFactor_, size_.y - size_.y / effectiveZoomFactor_);
×
676
        // Stay centered by removing half the pixels from opposite sites
677
        diff = diff / 2.f;
×
678
        // Convert to map points
679
        diff.x /= TR_W;
×
680
        diff.y /= TR_H;
×
681
        // Don't remove to much
682
        diff.x = std::floor(diff.x);
×
683
        diff.y = std::floor(diff.y);
×
684
        firstPt = Position(PointF(firstPt) + diff);
×
685
        lastPt = Position(PointF(lastPt) - diff);
×
686
    }
687
}
33✔
688

689
void GameWorldView::Resize(const Extent& newSize)
×
690
{
691
    size_ = newSize;
×
692
    CalcFxLx();
×
693
}
×
694

695
void GameWorldView::SaveIngameSettingsValues() const
×
696
{
697
    auto& ingameSettings = SETTINGS.ingame;
×
698
    ingameSettings.showBQ = show_bq;
×
699
    ingameSettings.showNames = show_names;
×
700
    ingameSettings.showProductivity = show_productivity;
×
701
}
×
702

703
void GameWorldView::updateEffectiveZoomFactor()
9✔
704
{
705
    // partially "undo" GUI scale depending on DPI scale
706
    // => zoom levels should look the same on screens with different DPI regardless of GUI scale
707
    effectiveZoomFactor_ = VIDEODRIVER.getGuiScale().screenToView(zoomFactor_ * VIDEODRIVER.getDpiScale());
9✔
708
}
9✔
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