Fix #12257: Fix refactoring of is_sprite_interacted_with_palette_set (#12258)

* Fix #12257: Change type of paint x/y to int32_t

This corrects an issue with integer conversions due to signness.

* Change types to 16bit and correct functions parameters

* Fix test paint.

Co-authored-by: duncanspumpkin <duncans_pumpkin@hotmail.co.uk>
This commit is contained in:
frutiemax 2020-07-14 07:20:53 -04:00 committed by GitHub
parent db52ac09aa
commit c8b66dd289
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 14 deletions

View file

@ -1451,8 +1451,8 @@ static bool is_sprite_interacted_with_palette_set(
}
int32_t round = std::max(1, 1 * dpi->zoom_level);
auto origin = coords;
auto origin = coords;
if (g1->flags & G1_FLAG_RLE_COMPRESSION)
{
origin.y -= (round - 1);
@ -1614,8 +1614,7 @@ InteractionInfo set_interaction_info_from_paint_session(paint_session* session,
for (attached_paint_struct* attached_ps = ps->attached_ps; attached_ps != nullptr; attached_ps = attached_ps->next)
{
if (is_sprite_interacted_with(
dpi, attached_ps->image_id, { (attached_ps->x + ps->x) & 0xFFFF, (attached_ps->y + ps->y) & 0xFFFF }))
if (is_sprite_interacted_with(dpi, attached_ps->image_id, { (attached_ps->x + ps->x), (attached_ps->y + ps->y) }))
{
if (PSSpriteTypeIsInFilter(ps, filter))
{

View file

@ -522,8 +522,7 @@ static void paint_attached_ps(rct_drawpixelinfo* dpi, paint_struct* ps, uint32_t
attached_paint_struct* attached_ps = ps->attached_ps;
for (; attached_ps; attached_ps = attached_ps->next)
{
auto screenCoords = ScreenCoordsXY{ attached_ps->x + static_cast<int16_t>(ps->x),
attached_ps->y + static_cast<int16_t>(ps->y) };
auto screenCoords = ScreenCoordsXY{ attached_ps->x + ps->x, attached_ps->y + ps->y };
uint32_t imageId = paint_ps_colourify_image(attached_ps->image_id, ps->sprite_type, viewFlags);
if (attached_ps->flags & PAINT_STRUCT_FLAG_IS_MASKED)
@ -995,7 +994,7 @@ paint_struct* sub_98199C(
* @param y (cx)
* @return (!CF) success
*/
bool paint_attach_to_previous_attach(paint_session* session, uint32_t image_id, uint16_t x, uint16_t y)
bool paint_attach_to_previous_attach(paint_session* session, uint32_t image_id, int16_t x, int16_t y)
{
if (session->UnkF1AD2C == nullptr)
{
@ -1032,7 +1031,7 @@ bool paint_attach_to_previous_attach(paint_session* session, uint32_t image_id,
* @param y (cx)
* @return (!CF) success
*/
bool paint_attach_to_previous_ps(paint_session* session, uint32_t image_id, uint16_t x, uint16_t y)
bool paint_attach_to_previous_ps(paint_session* session, uint32_t image_id, int16_t x, int16_t y)
{
if (session->NextFreePaintStruct >= session->EndOfPaintStructArray)
{

View file

@ -27,8 +27,8 @@ struct attached_paint_struct
// If masked image_id is masked_id
uint32_t colour_image_id;
};
uint16_t x; // 0x08
uint16_t y; // 0x0A
int16_t x; // 0x08
int16_t y; // 0x0A
uint8_t flags; // 0x0C
uint8_t pad_0D;
attached_paint_struct* next; // 0x0E
@ -66,8 +66,8 @@ struct paint_struct
uint32_t colour_image_id; // 0x04
};
paint_struct_bound_box bounds; // 0x08
uint16_t x; // 0x14
uint16_t y; // 0x16
int16_t x; // 0x14
int16_t y; // 0x16
uint16_t quadrant_index;
uint8_t flags;
uint8_t quadrant_flags;
@ -214,8 +214,8 @@ paint_struct* sub_98199C_rotated(
void paint_util_push_tunnel_rotated(paint_session* session, uint8_t direction, uint16_t height, uint8_t type);
bool paint_attach_to_previous_attach(paint_session* session, uint32_t image_id, uint16_t x, uint16_t y);
bool paint_attach_to_previous_ps(paint_session* session, uint32_t image_id, uint16_t x, uint16_t y);
bool paint_attach_to_previous_attach(paint_session* session, uint32_t image_id, int16_t x, int16_t y);
bool paint_attach_to_previous_ps(paint_session* session, uint32_t image_id, int16_t x, int16_t y);
void paint_floating_money_effect(
paint_session* session, money32 amount, rct_string_id string_id, int16_t y, int16_t z, int8_t y_offsets[], int16_t offset_x,
uint32_t rotation);

View file

@ -371,7 +371,7 @@ paint_struct* sub_98199C(
bound_box_offset_x, bound_box_offset_y, bound_box_offset_z, session->CurrentRotation);
}
bool paint_attach_to_previous_ps(paint_session* session, uint32_t image_id, uint16_t x, uint16_t y)
bool paint_attach_to_previous_ps(paint_session* session, uint32_t image_id, int16_t x, int16_t y)
{
return false;
}