1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-12 02:28:11 +02:00

Remove no longer used random seeds from StartInfo

This commit is contained in:
Ivan Savenko 2024-06-01 16:20:32 +00:00
parent 0d66ddbeec
commit 55bf75c43e
6 changed files with 15 additions and 55 deletions

View File

@ -123,9 +123,6 @@ struct DLL_LINKAGE StartInfo : public Serializeable
using TPlayerInfos = std::map<PlayerColor, PlayerSettings>;
TPlayerInfos playerInfos; //color indexed
ui32 seedToBeUsed; //0 if not sure (client requests server to decide, will be send in reply pack)
ui32 seedPostInit; //so we know that game is correctly synced at the start; 0 if not known yet
ui32 mapfileChecksum; //0 if not relevant
std::string startTimeIso8601;
std::string fileURI;
SimturnsInfo simturnsInfo;
@ -153,9 +150,13 @@ struct DLL_LINKAGE StartInfo : public Serializeable
h & mode;
h & difficulty;
h & playerInfos;
h & seedToBeUsed;
h & seedPostInit;
h & mapfileChecksum;
if (h.version < Handler::Version::REMOVE_LIB_RNG)
{
uint32_t oldSeeds;
h & oldSeeds;
h & oldSeeds;
h & oldSeeds;
}
h & startTimeIso8601;
h & fileURI;
h & simturnsInfo;
@ -169,8 +170,10 @@ struct DLL_LINKAGE StartInfo : public Serializeable
h & campState;
}
StartInfo() : mode(EStartMode::INVALID), difficulty(1), seedToBeUsed(0), seedPostInit(0),
mapfileChecksum(0), startTimeIso8601(vstd::getDateTimeISO8601Basic(std::time(nullptr))), fileURI("")
StartInfo()
: mode(EStartMode::INVALID)
, difficulty(1)
, startTimeIso8601(vstd::getDateTimeISO8601Basic(std::time(nullptr)))
{
}

View File

@ -203,8 +203,6 @@ void CGameState::init(const IMapService * mapService, StartInfo * si, Load::Prog
}
logGlobal->info("Map loaded!");
checkMapChecksum();
day = 0;
logGlobal->debug("Initialization:");
@ -236,18 +234,6 @@ void CGameState::init(const IMapService * mapService, StartInfo * si, Load::Prog
logGlobal->debug("\tChecking objectives");
map->checkForObjectives(); //needs to be run when all objects are properly placed
auto seedAfterInit = getRandomGenerator().nextInt();
logGlobal->info("Seed after init is %d (before was %d)", seedAfterInit, scenarioOps->seedToBeUsed);
if(scenarioOps->seedPostInit > 0)
{
//RNG must be in the same state on all machines when initialization is done (otherwise we have desync)
assert(scenarioOps->seedPostInit == seedAfterInit);
}
else
{
scenarioOps->seedPostInit = seedAfterInit; //store the post init "seed"
}
}
void CGameState::updateEntity(Metatype metatype, int32_t index, const JsonNode & data)
@ -307,7 +293,7 @@ void CGameState::initNewGame(const IMapService * mapService, bool allowSavingRan
CStopWatch sw;
// Gen map
CMapGenerator mapGenerator(*scenarioOps->mapGenOptions, callback, scenarioOps->seedToBeUsed);
CMapGenerator mapGenerator(*scenarioOps->mapGenOptions, callback, getRandomGenerator().nextInt());
progressTracking.include(mapGenerator);
std::unique_ptr<CMap> randomMap = mapGenerator.generate();
@ -323,10 +309,9 @@ void CGameState::initNewGame(const IMapService * mapService, bool allowSavingRan
std::shared_ptr<CMapGenOptions> options = scenarioOps->mapGenOptions;
const std::string templateName = options->getMapTemplate()->getName();
const ui32 seed = scenarioOps->seedToBeUsed;
const std::string dt = vstd::getDateTimeISO8601Basic(std::time(nullptr));
const std::string fileName = boost::str(boost::format("%s_%s_%d.vmap") % dt % templateName % seed );
const std::string fileName = boost::str(boost::format("%s_%s_%d.vmap") % dt % templateName );
const auto fullPath = path / fileName;
randomMap->name.appendRawString(boost::str(boost::format(" %s") % dt));
@ -380,24 +365,6 @@ void CGameState::initCampaign()
map = campaign->getCurrentMap().release();
}
void CGameState::checkMapChecksum()
{
logGlobal->info("\tOur checksum for the map: %d", map->checksum);
if(scenarioOps->mapfileChecksum)
{
logGlobal->info("\tServer checksum for %s: %d", scenarioOps->mapname, scenarioOps->mapfileChecksum);
if(map->checksum != scenarioOps->mapfileChecksum)
{
logGlobal->error("Wrong map checksum!!!");
throw std::runtime_error("Wrong checksum");
}
}
else
{
scenarioOps->mapfileChecksum = map->checksum;
}
}
void CGameState::initGlobalBonuses()
{
const JsonNode & baseBonuses = VLC->settings()->getValue(EGameSettings::BONUSES_GLOBAL);

View File

@ -201,7 +201,6 @@ public:
private:
// ----- initialization -----
void initNewGame(const IMapService * mapService, bool allowSavingRandomMap, Load::ProgressAccumulator & progressTracking);
void checkMapChecksum();
void initGlobalBonuses();
void initGrailPosition();
void initRandomFactionsForPlayers();

View File

@ -548,11 +548,8 @@ void CGameHandler::reinitScripting()
void CGameHandler::init(StartInfo *si, Load::ProgressAccumulator & progressTracking)
{
if (si->seedToBeUsed == 0)
si->seedToBeUsed = CRandomGenerator::getDefault().nextInt();
logGlobal->info("Using random seed: %d", si->seedToBeUsed);
randomNumberGenerator = std::make_unique<CRandomGenerator>(si->seedToBeUsed);
randomNumberGenerator = std::make_unique<CRandomGenerator>();
logGlobal->info("Using random seed: %d", randomNumberGenerator->nextInt());
CMapService mapService;
gs = new CGameState();
@ -561,9 +558,6 @@ void CGameHandler::init(StartInfo *si, Load::ProgressAccumulator & progressTrack
gs->init(&mapService, si, progressTracking);
logGlobal->info("Gamestate initialized!");
// reset seed, so that clients can't predict any following random values
randomNumberGenerator = std::make_unique<CRandomGenerator>();
for (auto & elem : gs->players)
turnOrder->addPlayer(elem.first);

View File

@ -253,7 +253,6 @@ void CVCMIServer::prepareToRestart()
}
* si = * gh->gs->initialOpts;
si->seedToBeUsed = si->seedPostInit = 0;
setState(EServerState::LOBBY);
if (si->campState)
{

View File

@ -142,9 +142,7 @@ public:
StartInfo si;
si.mapname = "anything";//does not matter, map service mocked
si.difficulty = 0;
si.mapfileChecksum = 0;
si.mode = EStartMode::NEW_GAME;
si.seedToBeUsed = 42;
std::unique_ptr<CMapHeader> header = mapService.loadMapHeader(ResourcePath(si.mapname));