mirror of https://github.com/OpenRCT2/OpenRCT2.git
Merge pull request #15366 from ZehMatt/fix/quadrant-buckets
Fix hash bucketing of paint entries
This commit is contained in:
commit
75c2dbcf74
|
@ -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 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 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);
|
auto pos = CoordsXY{ ps.bounds.x, ps.bounds.y }.Rotate(rotation);
|
||||||
switch (rotation)
|
switch (rotation)
|
||||||
|
@ -72,13 +72,13 @@ static constexpr int32_t CalculatePositionHash(const paint_struct& ps, uint8_t r
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return pos.x + pos.y;
|
return static_cast<uint32_t>(pos.x + pos.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void PaintSessionAddPSToQuadrant(paint_session* session, paint_struct* ps)
|
static void PaintSessionAddPSToQuadrant(paint_session* session, paint_struct* ps)
|
||||||
{
|
{
|
||||||
auto positionHash = CalculatePositionHash(*ps, session->CurrentRotation);
|
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->quadrant_index = paintQuadrantIndex;
|
||||||
ps->next_quadrant_ps = session->Quadrants[paintQuadrantIndex];
|
ps->next_quadrant_ps = session->Quadrants[paintQuadrantIndex];
|
||||||
session->Quadrants[paintQuadrantIndex] = ps;
|
session->Quadrants[paintQuadrantIndex] = ps;
|
||||||
|
|
|
@ -113,7 +113,10 @@ struct tunnel_entry
|
||||||
uint8_t type;
|
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
|
#define TUNNEL_MAX_COUNT 65
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue