Compute checksum by entity type (#14383)

* Compute checksum by entity type

* Copy only the entity size

* Update replays and network version
This commit is contained in:
Duncan 2021-03-27 09:36:41 +00:00 committed by GitHub
parent e8e30e9c6a
commit 619b2afc15
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 31 deletions

View File

@ -48,8 +48,8 @@ set(TITLE_SEQUENCE_SHA1 "304d13a126c15bf2c86ff13b81a2f2cc1856ac8d")
set(OBJECTS_URL "https://github.com/OpenRCT2/objects/releases/download/v1.0.21/objects.zip")
set(OBJECTS_SHA1 "c38af45d51a6e440386180feacf76c64720b6ac5")
set(REPLAYS_URL "https://github.com/OpenRCT2/replays/releases/download/v0.0.35/replays.zip")
set(REPLAYS_SHA1 "5875A182E2828B8E0234F496B5D5E84CFE25EFCB")
set(REPLAYS_URL "https://github.com/OpenRCT2/replays/releases/download/v0.0.36/replays.zip")
set(REPLAYS_SHA1 "F539E5BD4F5062C2972C6E0DA974318DB01A0308")
option(FORCE32 "Force 32-bit build. It will add `-m32` to compiler flags.")
option(WITH_TESTS "Build tests")

View File

@ -48,8 +48,8 @@
<TitleSequencesSha1>304d13a126c15bf2c86ff13b81a2f2cc1856ac8d</TitleSequencesSha1>
<ObjectsUrl>https://github.com/OpenRCT2/objects/releases/download/v1.0.21/objects.zip</ObjectsUrl>
<ObjectsSha1>c38af45d51a6e440386180feacf76c64720b6ac5</ObjectsSha1>
<ReplaysUrl>https://github.com/OpenRCT2/replays/releases/download/v0.0.35/replays.zip</ReplaysUrl>
<ReplaysSha1>5875A182E2828B8E0234F496B5D5E84CFE25EFCB</ReplaysSha1>
<ReplaysUrl>https://github.com/OpenRCT2/replays/releases/download/v0.0.36/replays.zip</ReplaysUrl>
<ReplaysSha1>F539E5BD4F5062C2972C6E0DA974318DB01A0308</ReplaysSha1>
</PropertyGroup>
<ItemGroup>

View File

@ -36,7 +36,7 @@
// This string specifies which version of network stream current build uses.
// It is used for making sure only compatible builds get connected, even within
// single OpenRCT2 version.
#define NETWORK_STREAM_VERSION "6"
#define NETWORK_STREAM_VERSION "7"
#define NETWORK_STREAM_ID OPENRCT2_VERSION "-" NETWORK_STREAM_VERSION
static Peep* _pickup_peep = nullptr;

View File

@ -275,6 +275,36 @@ void reset_sprite_spatial_index()
#ifndef DISABLE_NETWORK
template<typename T> void ComputeChecksumForEntityType(Crypt::HashAlgorithm<20>* _entityHashAlg)
{
for (auto* ent : EntityList<T>())
{
T copy = *ent;
// Only required for rendering/invalidation, has no meaning to the game state.
copy.sprite_left = copy.sprite_right = copy.sprite_top = copy.sprite_bottom = 0;
copy.sprite_width = copy.sprite_height_negative = copy.sprite_height_positive = 0;
if constexpr (std::is_base_of_v<Peep, T>)
{
// Name is pointer and will not be the same across clients
copy.Name = {};
// We set this to 0 because as soon the client selects a guest the window will remove the
// invalidation flags causing the sprite checksum to be different than on server, the flag does not
// affect game state.
copy.WindowInvalidateFlags = 0;
}
_entityHashAlg->Update(&copy, sizeof(copy));
}
}
template<typename... T> void ComputeChecksumForEntityTypes(Crypt::HashAlgorithm<20>* _entityHashAlg)
{
(ComputeChecksumForEntityType<T>(_entityHashAlg), ...);
}
rct_sprite_checksum sprite_checksum()
{
using namespace Crypt;
@ -293,33 +323,8 @@ rct_sprite_checksum sprite_checksum()
}
_spriteHashAlg->Clear();
for (size_t i = 0; i < MAX_ENTITIES; i++)
{
// TODO create a way to copy only the specific type
auto sprite = GetEntity(i);
if (sprite != nullptr && sprite->Type != EntityType::Null && !sprite->Is<MiscEntity>())
{
// Upconvert it to rct_sprite so that the full size is copied.
auto copy = *reinterpret_cast<rct_sprite*>(sprite);
// Only required for rendering/invalidation, has no meaning to the game state.
copy.misc.sprite_left = copy.misc.sprite_right = copy.misc.sprite_top = copy.misc.sprite_bottom = 0;
copy.misc.sprite_width = copy.misc.sprite_height_negative = copy.misc.sprite_height_positive = 0;
if (copy.misc.Is<Peep>())
{
// Name is pointer and will not be the same across clients
copy.peep.Name = {};
// We set this to 0 because as soon the client selects a guest the window will remove the
// invalidation flags causing the sprite checksum to be different than on server, the flag does not
// affect game state.
copy.peep.WindowInvalidateFlags = 0;
}
_spriteHashAlg->Update(&copy, sizeof(copy));
}
}
ComputeChecksumForEntityTypes<Guest, Staff, Vehicle, Litter>(_spriteHashAlg.get());
checksum.raw = _spriteHashAlg->Finish();
}