Fix hash bucketing of paint entries

This commit is contained in:
ζeh Matt 2021-09-07 17:43:38 +03:00
parent c6e4dc5ef1
commit 876329da87
No known key found for this signature in database
GPG Key ID: 18CE582C71A225B0
2 changed files with 7 additions and 4 deletions

View File

@ -56,7 +56,7 @@ static void PaintPSImageWithBoundingBoxes(rct_drawpixelinfo* dpi, paint_struct*
static void PaintPSImage(rct_drawpixelinfo* dpi, paint_struct* ps, uint32_t imageId, int32_t x, int32_t y);
static uint32_t PaintPSColourifyImage(uint32_t imageId, ViewportInteractionItem spriteType, uint32_t viewFlags);
static constexpr int32_t CalculatePositionHash(const paint_struct& ps, uint8_t rotation)
static constexpr uint32_t CalculatePositionHash(const paint_struct& ps, uint8_t rotation)
{
auto pos = CoordsXY{ ps.bounds.x, ps.bounds.y }.Rotate(rotation);
switch (rotation)
@ -72,13 +72,13 @@ static constexpr int32_t CalculatePositionHash(const paint_struct& ps, uint8_t r
break;
}
return pos.x + pos.y;
return static_cast<uint32_t>(pos.x + pos.y);
}
static void PaintSessionAddPSToQuadrant(paint_session* session, paint_struct* ps)
{
auto positionHash = CalculatePositionHash(*ps, session->CurrentRotation);
uint32_t paintQuadrantIndex = std::clamp(positionHash / 32, 0, MAX_PAINT_QUADRANTS - 1);
uint32_t paintQuadrantIndex = (positionHash / 32) % MAX_PAINT_QUADRANTS;
ps->quadrant_index = paintQuadrantIndex;
ps->next_quadrant_ps = session->Quadrants[paintQuadrantIndex];
session->Quadrants[paintQuadrantIndex] = ps;

View File

@ -113,7 +113,10 @@ struct tunnel_entry
uint8_t type;
};
#define MAX_PAINT_QUADRANTS 512
// NOTE: This should be preferably a prime number. This is the amount of
// buckets used with the position hash, so the bucket is hash % max.
#define MAX_PAINT_QUADRANTS 521
#define TUNNEL_MAX_COUNT 65
/**