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

Return-To-The-Roots / s25client / 12454926545

22 Dec 2024 02:06PM UTC coverage: 50.23% (+0.005%) from 50.225%
12454926545

Pull #1681

github

web-flow
Merge 2ae89be01 into 17844c810
Pull Request #1681: Add support for campaign status

57 of 112 new or added lines in 10 files covered. (50.89%)

3 existing lines in 3 files now uncovered.

22360 of 44515 relevant lines covered (50.23%)

35626.14 hits per line

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

0.0
/libs/s25main/GameManager.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 "GameManager.h"
6
#include "GlobalVars.h"
7
#include "Loader.h"
8
#include "RTTR_Assert.h"
9
#include "RttrConfig.h"
10
#include "Settings.h"
11
#include "WindowManager.h"
12
#include "desktops/dskCampaignVictory.h"
13
#include "desktops/dskLobby.h"
14
#include "desktops/dskMainMenu.h"
15
#include "desktops/dskSplash.h"
16
#include "drivers/AudioDriverWrapper.h"
17
#include "drivers/VideoDriverWrapper.h"
18
#include "files.h"
19
#include "network/GameClient.h"
20
#include "network/GameServer.h"
21
#include "ogl/glArchivItem_Bitmap.h"
22
#include "liblobby/LobbyClient.h"
23
#include "libsiedler2/Archiv.h"
24
#include "s25util/Log.h"
25
#include "s25util/error.h"
26
#include <boost/pointer_cast.hpp>
27

28
GameManager::GameManager(Log& log, Settings& settings, VideoDriverWrapper& videoDriver, AudioDriverWrapper& audioDriver,
×
29
                         WindowManager& windowManager)
×
30
    : log_(log), settings_(settings), videoDriver_(videoDriver), audioDriver_(audioDriver),
31
      windowManager_(windowManager)
×
32
{
33
    ResetAverageGFPS();
×
34
}
×
35

36
/**
37
 *  Spiel starten
38
 */
39
bool GameManager::Start()
×
40
{
41
    // Einstellungen laden
42
    settings_.Load();
×
43

44
    /// Videotreiber laden
45
    if(!videoDriver_.LoadDriver(settings_.driver.video))
×
46
    {
47
        s25util::error(_("Video driver couldn't be loaded!"));
×
48
        return false;
×
49
    }
50

51
    // Fenster erstellen
52
    const auto screenSize =
×
53
      settings_.video.fullscreen ? settings_.video.fullscreenSize : settings_.video.windowedSize; //-V807
×
54
    if(!videoDriver_.CreateScreen(screenSize, settings_.video.fullscreen))
×
55
        return false;
×
56
    videoDriver_.setTargetFramerate(settings_.video.framerate);
×
57
    videoDriver_.SetMouseWarping(settings_.global.smartCursor);
×
58
    videoDriver_.setGuiScalePercent(settings_.video.guiScale);
×
59

60
    /// Audiodriver laden
61
    if(!audioDriver_.LoadDriver(settings_.driver.audio))
×
62
    {
63
        s25util::warning(_("Audio driver couldn't be loaded!"));
×
64
        // return false;
65
    }
66

67
    /// Lautstärken gleich mit setzen
68
    audioDriver_.SetMasterEffectVolume(settings_.sound.effectsVolume); //-V807
×
69
    audioDriver_.SetMusicVolume(settings_.sound.musicVolume);
×
70

71
    // Treibereinstellungen abspeichern
72
    settings_.Save();
×
73

74
    log_.write(_("\nStarting the game\n"));
×
75
    return ShowSplashscreen();
×
76
}
77

78
/**
79
 *  Spiel beenden.
80
 */
81
void GameManager::Stop()
×
82
{
83
    GAMECLIENT.Stop();
×
84
    GAMESERVER.Stop();
×
85
    LOBBYCLIENT.Stop();
×
86
    // Global Einstellungen speichern
87
    settings_.Save();
×
88

89
    // Fenster beenden
90
    videoDriver_.DestroyScreen();
×
91
}
×
92

93
/**
94
 *  Hauptschleife.
95
 */
96
bool GameManager::Run()
×
97
{
98
    // Nachrichtenschleife
99
    if(!videoDriver_.Run())
×
100
        GLOBALVARS.notdone = false;
×
101

102
    LOBBYCLIENT.Run();
×
103

104
    // Get this before the run so we know if we are currently skipping
105
    const unsigned targetSkipGF = GAMECLIENT.skiptogf;
×
106
    GAMECLIENT.Run();
×
107
    GAMESERVER.Run();
×
108

109
    if(targetSkipGF)
×
110
    {
111
        // if we skip drawing write a comment every 5k gf
112
        unsigned current_time = videoDriver_.GetTickCount();
×
113
        const unsigned curGF = GAMECLIENT.GetGFNumber();
×
114
        if(targetSkipGF > curGF)
×
115
        {
116
            if(curGF % 5000 == 0)
×
117
            {
118
                if(lastSkipReport)
×
119
                {
120
                    // Elapsed time in ms
121
                    const auto timeDiff = static_cast<double>(current_time - lastSkipReport->time);
×
122
                    const unsigned numGFPassed = curGF - lastSkipReport->gf;
×
123
                    log_.write(_("jumping to gf %i, now at gf %i, time for last 5k gf: %.3f s, avg gf time %.3f ms \n"))
×
124
                      % targetSkipGF % curGF % (timeDiff / 1000) % (timeDiff / numGFPassed);
×
125
                } else
126
                    log_.write(_("jumping to gf %i, now at gf %i \n")) % targetSkipGF % curGF;
×
127
                lastSkipReport = SkipReport{current_time, curGF};
×
128
            } else if(!lastSkipReport)
×
129
                lastSkipReport = SkipReport{current_time, curGF};
×
130
        } else
131
        {
132
            // Jump just completed
133
            RTTR_Assert(!GAMECLIENT.skiptogf);
×
134
            if(lastSkipReport)
×
135
            {
136
                const auto timeDiff = static_cast<double>(current_time - lastSkipReport->time);
×
137
                const unsigned numGFPassed = curGF - lastSkipReport->gf;
×
138
                log_.write(_("jump to gf %i complete, time for last %i gf: %.3f s, avg gf time %.3f ms \n"))
×
139
                  % targetSkipGF % numGFPassed % (timeDiff / 1000) % (timeDiff / numGFPassed);
×
140
                lastSkipReport.reset();
×
141
            } else
142
            {
143
                log_.write(_("jump to gf %1% complete\n")) % targetSkipGF;
×
144
            }
145
        }
146
    } else
147
    {
148
        videoDriver_.ClearScreen();
×
149
        windowManager_.Draw();
×
150
        videoDriver_.SwapBuffers();
×
151
    }
152
    gfCounter_.update();
×
153

154
    // Fenstermanager aufräumen
155
    if(!GLOBALVARS.notdone)
×
156
        windowManager_.CleanUp();
×
157

158
    return GLOBALVARS.notdone;
×
159
}
160

161
bool GameManager::ShowSplashscreen()
×
162
{
163
    libsiedler2::Archiv arSplash;
×
164
    if(!LOADER.Load(arSplash, RTTRCONFIG.ExpandPath(s25::files::splash)))
×
165
        return false;
×
166
    auto image = boost::dynamic_pointer_cast<glArchivItem_Bitmap>(arSplash.release(0));
×
167
    if(!image)
×
168
    {
169
        s25util::error(_("Splash screen couldn't be loaded!"));
×
170
        return false;
×
171
    }
172
    windowManager_.Switch(std::make_unique<dskSplash>(std::move(image)));
×
173
    return true;
×
174
}
175

176
/**
177
 *  zeigt das Hauptmenü.
178
 */
179
bool GameManager::ShowMenu()
×
180
{
181
    GAMECLIENT.Stop();
×
182
    GAMESERVER.Stop();
×
183

184
    if(LOBBYCLIENT.IsLoggedIn())
×
185
        // Lobby zeigen
186
        windowManager_.Switch(std::make_unique<dskLobby>());
×
NEW
187
    else if(GAMECLIENT.IsCampaignCompleted())
×
NEW
188
        WINDOWMANAGER.Switch(std::make_unique<dskCampaignVictory>(0));
×
NEW
189
    else if(const auto chapter = GAMECLIENT.GetCampaignChapterCompleted())
×
NEW
190
        WINDOWMANAGER.Switch(std::make_unique<dskCampaignVictory>(chapter));
×
191
    else
192
        // Hauptmenü zeigen
193
        windowManager_.Switch(std::make_unique<dskMainMenu>());
×
194

195
    return true;
×
196
}
197

198
void GameManager::ResetAverageGFPS()
×
199
{
200
    gfCounter_ = FrameCounter(FrameCounter::clock::duration::max()); // Never update
×
201
}
×
202

203
static GameManager* globalGameManager = nullptr;
204

205
GameManager& getGlobalGameManager()
×
206
{
207
    return *globalGameManager;
×
208
}
209
void setGlobalGameManager(GameManager* gameManager)
×
210
{
211
    globalGameManager = gameManager;
×
212
}
×
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