1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-25 22:42:04 +02:00

Progress update on client side

This commit is contained in:
nordsoft
2023-08-21 18:56:01 +04:00
parent 584dd20943
commit 45f13c7964
10 changed files with 51 additions and 12 deletions

View File

@@ -181,7 +181,10 @@ void CClient::newGame(CGameState * initializedGameState)
gs->preInit(VLC);
logNetwork->trace("\tCreating gamestate: %i", CSH->th->getDiff());
if(!initializedGameState)
gs->init(&mapService, CSH->si.get(), settings["general"]["saveRandomMaps"].Bool());
{
Load::Progress * progressTrackingPointer = nullptr;
gs->init(&mapService, CSH->si.get(), progressTrackingPointer, settings["general"]["saveRandomMaps"].Bool());
}
logNetwork->trace("Initializing GameState (together): %d ms", CSH->th->getDiff());
initMapHandler();

View File

@@ -131,7 +131,10 @@ void ApplyOnLobbyHandlerNetPackVisitor::visitLobbyStartGame(LobbyStartGame & pac
void ApplyOnLobbyScreenNetPackVisitor::visitLobbyLoadProgress(LobbyLoadProgress & pack)
{
if(auto w = GH.windows().topWindow<CLoadingScreen>())
{
w->set(pack.progress);
w->redraw();
}
else
GH.windows().createAndPushWindow<CLoadingScreen>();
}

View File

@@ -585,7 +585,22 @@ void CSimpleJoinScreen::connectThread(const std::string & addr, ui16 port)
CLoadingScreen::CLoadingScreen()
: CWindowObject(BORDERED, getBackground())
{
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
CCS->musich->stopMusic(5000);
const auto & conf = CMainMenuConfig::get().getConfig()["loading"];
const int posx = conf["x"].Integer(), posy = conf["y"].Integer();
const int blockSize = conf["size"].Integer();
const int blocksAmount = conf["amount"].Integer();
for(int i = 0; i < blocksAmount; ++i)
{
progressBlocks.push_back(std::make_shared<CAnimImage>(conf["name"].String(), i, 0, posx + i * blockSize, posy));
progressBlocks.back()->deactivate();
progressBlocks.back()->visible = false;
}
}
CLoadingScreen::~CLoadingScreen()
@@ -597,13 +612,23 @@ void CLoadingScreen::showAll(Canvas & to)
//FIXME: filling screen with transparency? BLACK intended?
//Rect rect(0, 0, to->w, to->h);
//CSDL_Ext::fillRect(to, rect, Colors::TRANSPARENCY);
if(!progressBlocks.empty())
{
int status = float(get()) / (2.55f * progressBlocks.size());
for(int i = 0; i < status; ++i)
{
progressBlocks.at(i)->activate();
progressBlocks.at(i)->visible = true;
}
}
CWindowObject::showAll(to);
}
std::string CLoadingScreen::getBackground()
{
const auto & conf = CMainMenuConfig::get().getConfig()["loading"].Vector();
const auto & conf = CMainMenuConfig::get().getConfig()["loading"]["background"].Vector();
if(conf.empty())
{

View File

@@ -9,6 +9,7 @@
*/
#pragma once
#include "../widgets/Images.h"
#include "../windows/CWindowObject.h"
#include "../../lib/JsonNode.h"
#include "../../lib/LoadProgress.h"
@@ -26,6 +27,7 @@ class CTabbedInt;
class CAnimation;
class CButton;
class CFilledTexture;
class CLabel;
// TODO: Find new location for these enums
@@ -181,6 +183,8 @@ public:
class CLoadingScreen : virtual public CWindowObject, virtual public Load::Progress
{
std::vector<std::shared_ptr<CAnimImage>> progressBlocks;
std::string getBackground();
public:

View File

@@ -2,7 +2,11 @@
//images used in game selection screen
"game-select" : ["gamselb0", "gamselb1"],
"loading" : ["loadbar"],
"loading" :
{
"background" : ["loadbar"],
"x": 395, "y": 548, "size": 18, "amount": 20, "name": "loadprog"
},
//Main menu window, consists of several sub-menus aka items
"window":

View File

@@ -404,7 +404,7 @@ void CGameState::preInit(Services * services)
this->services = services;
}
void CGameState::init(const IMapService * mapService, StartInfo * si, bool allowSavingRandomMap, Load::Progress * progressTracking)
void CGameState::init(const IMapService * mapService, StartInfo * si, Load::Progress *& progressTracking, bool allowSavingRandomMap)
{
preInitAuto();
logGlobal->info("\tUsing random seed: %d", si->seedToBeUsed);
@@ -535,7 +535,7 @@ void CGameState::preInitAuto()
}
}
void CGameState::initNewGame(const IMapService * mapService, bool allowSavingRandomMap, Load::Progress * progressTracking)
void CGameState::initNewGame(const IMapService * mapService, bool allowSavingRandomMap, Load::Progress *& progressTracking)
{
if(scenarioOps->createRandomMap())
{

View File

@@ -90,7 +90,7 @@ public:
void preInit(Services * services);
void init(const IMapService * mapService, StartInfo * si, bool allowSavingRandomMap = false, Load::Progress * progressTracking = nullptr);
void init(const IMapService * mapService, StartInfo * si, Load::Progress *&, bool allowSavingRandomMap = false);
void updateOnLoad(StartInfo * si);
ConstTransitivePtr<StartInfo> scenarioOps, initialOpts; //second one is a copy of settings received from pregame (not randomized)
@@ -167,7 +167,7 @@ public:
private:
// ----- initialization -----
void preInitAuto();
void initNewGame(const IMapService * mapService, bool allowSavingRandomMap, Load::Progress * progressTracking = nullptr);
void initNewGame(const IMapService * mapService, bool allowSavingRandomMap, Load::Progress *& progressTracking);
void checkMapChecksum();
void initGlobalBonuses();
void initGrailPosition();

View File

@@ -1599,7 +1599,7 @@ void CGameHandler::reinitScripting()
#endif
}
void CGameHandler::init(StartInfo *si, Load::Progress * progressTracking)
void CGameHandler::init(StartInfo *si, Load::Progress *& progressTracking)
{
if (si->seedToBeUsed == 0)
{
@@ -1609,7 +1609,7 @@ void CGameHandler::init(StartInfo *si, Load::Progress * progressTracking)
gs = new CGameState();
gs->preInit(VLC);
logGlobal->info("Gamestate created!");
gs->init(&mapService, si, false, progressTracking);
gs->init(&mapService, si, progressTracking);
logGlobal->info("Gamestate initialized!");
// reset seed, so that clients can't predict any following random values

View File

@@ -237,7 +237,7 @@ public:
void expGiven(const CGHeroInstance *hero); //triggers needed level-ups, handles also commander of this hero
//////////////////////////////////////////////////////////////////////////
void init(StartInfo *si, Load::Progress * progressTracking = nullptr);
void init(StartInfo *si, Load::Progress *& progressTracking);
void handleClientDisconnection(std::shared_ptr<CConnection> c);
void handleReceivedPack(CPackForServer * pack);
PlayerColor getPlayerAt(std::shared_ptr<CConnection> c) const;

View File

@@ -291,7 +291,7 @@ bool CVCMIServer::prepareToStartGame()
loadProgress->progress = progressTracking->get();
addToAnnounceQueue(std::move(loadProgress));
}
std::this_thread::sleep_for(std::chrono::milliseconds(100));
std::this_thread::sleep_for(std::chrono::milliseconds(200));
}
progressTrackingFinished = false;
});