From a1ea1dc4fb8013649a5acd91ddeb5c940ddcf092 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Sat, 27 Nov 2021 15:55:24 +0200 Subject: [PATCH] Move painting to Litter entity --- src/openrct2/entity/Litter.cpp | 41 ++++++++++++++++++- src/openrct2/entity/Litter.h | 3 +- src/openrct2/paint/sprite/Paint.Litter.cpp | 47 ---------------------- 3 files changed, 42 insertions(+), 49 deletions(-) diff --git a/src/openrct2/entity/Litter.cpp b/src/openrct2/entity/Litter.cpp index f6648fd126..fe694f7b7a 100644 --- a/src/openrct2/entity/Litter.cpp +++ b/src/openrct2/entity/Litter.cpp @@ -4,6 +4,8 @@ #include "../Game.h" #include "../core/DataSerialiser.h" #include "../localisation/StringIds.h" +#include "../paint/Paint.h" +#include "../sprites.h" #include "../world/Map.h" #include "EntityList.h" #include "EntityRegistry.h" @@ -145,6 +147,43 @@ void Litter::Serialise(DataSerialiser& stream) stream << creationTick; } -void Litter::Paint() const +struct LitterSprite { + uint16_t base_id; + uint8_t direction_mask; +}; + +/** rct2: 0x0097EF6C */ +static constexpr const LitterSprite _litterSprites[] = { + { SPR_LITTER_SICK, 0x1 }, + { SPR_LITTER_SICK_ALT, 0x1 }, + { SPR_LITTER_EMPTY_CAN, 0x1 }, + { SPR_LITTER_RUBBISH, 0x1 }, + { SPR_LITTER_EMPTY_BURGER_BOX, 0x1 }, + { SPR_LITTER_EMPTY_CUP, 0x1 }, + { SPR_LITTER_EMPTY_BOX, 0x1 }, + { SPR_LITTER_EMPTY_BOTTLE, 0x1 }, + { SPR_LITTER_EMPTY_BOWL_RED, 0x3 }, + { SPR_LITTER_EMPTY_DRINK_CART, 0x3 }, + { SPR_LITTER_EMPTY_JUICE_CUP, 0x3 }, + { SPR_LITTER_EMPTY_BOWL_BLUE, 0x3 }, +}; + +void Litter::Paint(paint_session* session, int32_t imageDirection) const +{ + rct_drawpixelinfo& dpi = session->DPI; + if (dpi.zoom_level > 0) + return; // If zoomed at all no litter drawn + + // litter has no sprite direction so remove that + imageDirection >>= 3; + // Some litter types have only 1 direction so remove + // anything that isn't required. + imageDirection &= _litterSprites[EnumValue(SubType)].direction_mask; + + uint32_t image_id = imageDirection + _litterSprites[EnumValue(SubType)].base_id; + + // In the following call to PaintAddImageAsParent, we add 4 (instead of 2) to the + // bound_box_offset_z to make sure litter is drawn on top of railways + PaintAddImageAsParent(session, image_id, { 0, 0, z }, { 4, 4, -1 }, { -4, -4, z + 4 }); } diff --git a/src/openrct2/entity/Litter.h b/src/openrct2/entity/Litter.h index 3f34ce31cd..64f7811617 100644 --- a/src/openrct2/entity/Litter.h +++ b/src/openrct2/entity/Litter.h @@ -14,6 +14,7 @@ class DataSerialiser; struct CoordsXYZ; struct CoordsXYZD; +struct paint_session; struct Litter : EntityBase { @@ -41,5 +42,5 @@ struct Litter : EntityBase void Serialise(DataSerialiser& stream); rct_string_id GetName() const; uint32_t GetAge() const; - void Paint() const; + void Paint(paint_session* session, int32_t imageDirection) const; }; diff --git a/src/openrct2/paint/sprite/Paint.Litter.cpp b/src/openrct2/paint/sprite/Paint.Litter.cpp index 540e2a4e01..0bdd962daa 100644 --- a/src/openrct2/paint/sprite/Paint.Litter.cpp +++ b/src/openrct2/paint/sprite/Paint.Litter.cpp @@ -12,50 +12,3 @@ #include "../Paint.h" #include "../sprites.h" #include "Paint.Sprite.h" - -struct litter_sprite -{ - uint16_t base_id; - uint8_t direction_mask; -}; - -/** rct2: 0x0097EF6C */ -static constexpr const litter_sprite litter_sprites[] = { - { SPR_LITTER_SICK, 0x1 }, - { SPR_LITTER_SICK_ALT, 0x1 }, - { SPR_LITTER_EMPTY_CAN, 0x1 }, - { SPR_LITTER_RUBBISH, 0x1 }, - { SPR_LITTER_EMPTY_BURGER_BOX, 0x1 }, - { SPR_LITTER_EMPTY_CUP, 0x1 }, - { SPR_LITTER_EMPTY_BOX, 0x1 }, - { SPR_LITTER_EMPTY_BOTTLE, 0x1 }, - { SPR_LITTER_EMPTY_BOWL_RED, 0x3 }, - { SPR_LITTER_EMPTY_DRINK_CART, 0x3 }, - { SPR_LITTER_EMPTY_JUICE_CUP, 0x3 }, - { SPR_LITTER_EMPTY_BOWL_BLUE, 0x3 }, -}; - -/** - * Litter Paint Setup - * rct2: 0x006736FC - */ -template<> void PaintEntity(paint_session* session, const Litter* litter, int32_t imageDirection) -{ - rct_drawpixelinfo* dpi; - - dpi = &session->DPI; - if (dpi->zoom_level > 0) - return; // If zoomed at all no litter drawn - - // litter has no sprite direction so remove that - imageDirection >>= 3; - // Some litter types have only 1 direction so remove - // anything that isn't required. - imageDirection &= litter_sprites[EnumValue(litter->SubType)].direction_mask; - - uint32_t image_id = imageDirection + litter_sprites[EnumValue(litter->SubType)].base_id; - - // In the following call to PaintAddImageAsParent, we add 4 (instead of 2) to the - // bound_box_offset_z to make sure litter is drawn on top of railways - PaintAddImageAsParent(session, image_id, { 0, 0, litter->z }, { 4, 4, -1 }, { -4, -4, litter->z + 4 }); -}