Check whether DoCommand test execution changes the random seed

desync-debugging
Jonathan G Rennison 5 years ago
parent 0f897eefe2
commit b826232e2e

@ -25,6 +25,7 @@
#include "core/backup_type.hpp"
#include "object_base.h"
#include "string_func.h"
#include "core/random_func.hpp"
#include <array>
#include "table/strings.h"
@ -751,6 +752,8 @@ CommandCost DoCommandPInternal(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd,
bool test_and_exec_can_differ = (cmd_flags & CMD_NO_TEST) != 0;
GameRandomSeedChecker random_state;
/* Test the command. */
_cleared_object_areas.clear();
SetTownRatingTestMode(true);
@ -759,6 +762,11 @@ CommandCost DoCommandPInternal(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd,
BasePersistentStorageArray::SwitchMode(PSM_LEAVE_TESTMODE);
SetTownRatingTestMode(false);
if (!random_state.Check()) {
DEBUG(desync, 0, "Random seed changed in test command: date{%08x; %02x}; company: %02x; tile: %06x (%u x %u); p1: %08x; p2: %08x; cmd: %08x; \"%s\" (%s)",
_date, _date_fract, (int)_current_company, tile, TileX(tile), TileY(tile), p1, p2, cmd & ~CMD_NETWORK_COMMAND, text, GetCommandName(cmd));
}
CommandLogEntryFlag log_flags;
log_flags = CLEF_NONE;
if (res.Failed()) log_flags |= CLEF_CMD_FAILED;

@ -47,7 +47,7 @@ static inline void SaveRandomSeeds(SavedRandomSeeds *storage)
/**
* Restores previously saved seeds
* @param storage Storage where SaveRandomSeeds() stored th seeds
* @param storage Storage where SaveRandomSeeds() stored the seeds
*/
static inline void RestoreRandomSeeds(const SavedRandomSeeds &storage)
{
@ -55,6 +55,22 @@ static inline void RestoreRandomSeeds(const SavedRandomSeeds &storage)
_interactive_random = storage.interactive_random;
}
struct GameRandomSeedChecker {
private:
Randomizer random;
public:
GameRandomSeedChecker()
{
this->random = _random;
}
bool Check() const
{
return (this->random.state[0] == _random.state[0] && this->random.state[1] == _random.state[1]);
}
};
void SetRandomSeed(uint32 seed);
#ifdef RANDOM_DEBUG
#ifdef __APPLE__

Loading…
Cancel
Save