1
0
Fork 0

Codechange: Move usage of ResolverObjects to newgrf_xxx.cpp (#14116)

pull/14120/head
frosch 2025-04-26 20:53:50 +02:00 committed by GitHub
parent be39a05327
commit f62f728187
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 55 additions and 43 deletions

View File

@ -514,6 +514,45 @@ void DrawNewHouseTile(TileInfo *ti, HouseID house_id)
}
}
/**
* Draw representation of a house tile for GUI purposes.
* @param x Position x of image.
* @param y Position y of image.
* @param spec House spec to draw.
* @param house_id House ID to draw.
* @param view The house's 'view'.
*/
void DrawNewHouseTileInGUI(int x, int y, const HouseSpec *spec, HouseID house_id, int view)
{
HouseResolverObject object(house_id, INVALID_TILE, nullptr, CBID_NO_CALLBACK, 0, 0, true, view);
const SpriteGroup *group = object.Resolve();
if (group == nullptr || group->type != SGT_TILELAYOUT) return;
uint8_t stage = TOWN_HOUSE_COMPLETED;
const DrawTileSprites *dts = reinterpret_cast<const TileLayoutSpriteGroup *>(group)->ProcessRegisters(&stage);
PaletteID palette = GetColourPalette(spec->random_colour[0]);
if (spec->callback_mask.Test(HouseCallbackMask::Colour)) {
uint16_t callback = GetHouseCallback(CBID_HOUSE_COLOUR, 0, 0, house_id, nullptr, INVALID_TILE, true, view);
if (callback != CALLBACK_FAILED) {
/* If bit 14 is set, we should use a 2cc colour map, else use the callback value. */
palette = HasBit(callback, 14) ? GB(callback, 0, 8) + SPR_2CCMAP_BASE : callback;
}
}
SpriteID image = dts->ground.sprite;
PaletteID pal = dts->ground.pal;
if (HasBit(image, SPRITE_MODIFIER_CUSTOM_SPRITE)) image += stage;
if (HasBit(pal, SPRITE_MODIFIER_CUSTOM_SPRITE)) pal += stage;
if (GB(image, 0, SPRITE_WIDTH) != 0) {
DrawSprite(image, GroundSpritePaletteTransform(image, pal, palette), x, y);
}
DrawNewGRFTileSeqInGUI(x, y, dts, stage, palette);
}
/* Simple wrapper for GetHouseCallback to keep the animation unified. */
uint16_t GetSimpleHouseCallback(CallbackID callback, uint32_t param1, uint32_t param2, const HouseSpec *spec, Town *town, TileIndex tile, CargoTypes extra_data)
{

View File

@ -98,6 +98,7 @@ void DecreaseBuildingCount(Town *t, HouseID house_id);
std::span<const uint> GetBuildingHouseIDCounts();
void DrawNewHouseTile(TileInfo *ti, HouseID house_id);
void DrawNewHouseTileInGUI(int x, int y, const HouseSpec *spec, HouseID house_id, int view);
void AnimateNewHouseTile(TileIndex tile);
/* see also: void TriggerHouseAnimation_TileLoop(TileIndex tile, uint16_t random_bits) */
void TriggerHouseAnimation_ConstructionStageChanged(TileIndex tile, bool first_call);

View File

@ -21,6 +21,7 @@
#include "window_type.h"
#include "timer/timer_game_calendar.h"
#include "town.h"
#include "tile_cmd.h"
#include "viewport_func.h"
#include "newgrf_animation_base.h"
#include "newgrf_sound.h"
@ -349,6 +350,14 @@ void DrawRoadStopTile(int x, int y, RoadType roadtype, const RoadStopSpec *spec,
DrawCommonTileSeqInGUI(x, y, dts, 0, 0, palette, true);
}
const TileLayoutSpriteGroup *GetRoadStopLayout(TileInfo *ti, const RoadStopSpec *spec, BaseStation *st, StationType type, int view)
{
RoadStopResolverObject object(spec, st, ti->tile, INVALID_ROADTYPE, type, view);
const SpriteGroup *group = object.Resolve();
if (group == nullptr || group->type != SGT_TILELAYOUT) return nullptr;
return static_cast<const TileLayoutSpriteGroup *>(group);
}
/** Wrapper for animation control, see GetRoadStopCallback. */
uint16_t GetAnimRoadStopCallback(CallbackID callback, uint32_t param1, uint32_t param2, const RoadStopSpec *roadstopspec, BaseStation *st, TileIndex tile, int)
{

View File

@ -21,6 +21,8 @@
#include "newgrf_town.h"
#include "road.h"
struct TileInfo;
/** The maximum amount of roadstops a single GRF is allowed to add */
static const int NUM_ROADSTOPS_PER_GRF = UINT16_MAX - 1;
@ -169,6 +171,7 @@ struct RoadStopSpec : NewGRFSpecBase<RoadStopClassID> {
using RoadStopClass = NewGRFClass<RoadStopSpec, RoadStopClassID, ROADSTOP_CLASS_MAX>;
const TileLayoutSpriteGroup *GetRoadStopLayout(TileInfo *ti, const RoadStopSpec *spec, BaseStation *st, StationType type, int view);
void DrawRoadStopTile(int x, int y, RoadType roadtype, const RoadStopSpec *spec, StationType type, int view);
uint16_t GetRoadStopCallback(CallbackID callback, uint32_t param1, uint32_t param2, const RoadStopSpec *roadstopspec, BaseStation *st, TileIndex tile, RoadType roadtype, StationType type, uint8_t view);

View File

@ -3328,16 +3328,15 @@ draw_default_foundation:
if (stopspec != nullptr) {
stop_draw_mode = stopspec->draw_mode;
st = BaseStation::GetByTile(ti->tile);
RoadStopResolverObject object(stopspec, st, ti->tile, INVALID_ROADTYPE, type, view);
const SpriteGroup *group = object.Resolve();
if (group != nullptr && group->type == SGT_TILELAYOUT) {
const TileLayoutSpriteGroup *group = GetRoadStopLayout(ti, stopspec, st, type, view);
if (group != nullptr) {
if (stopspec->flags.Test(RoadStopSpecFlag::DrawModeRegister)) {
stop_draw_mode = static_cast<RoadStopDrawMode>(GetRegister(0x100));
}
if (type == StationType::RoadWaypoint && stop_draw_mode.Test(RoadStopDrawMode::WaypGround)) {
draw_ground = true;
}
t = ((const TileLayoutSpriteGroup *)group)->ProcessRegisters(nullptr);
t = group->ProcessRegisters(nullptr);
}
}

View File

@ -1334,45 +1334,6 @@ void InitializeTownGui()
_town_local_authority_kdtree.Clear();
}
/**
* Draw representation of a house tile for GUI purposes.
* @param x Position x of image.
* @param y Position y of image.
* @param spec House spec to draw.
* @param house_id House ID to draw.
* @param view The house's 'view'.
*/
void DrawNewHouseTileInGUI(int x, int y, const HouseSpec *spec, HouseID house_id, int view)
{
HouseResolverObject object(house_id, INVALID_TILE, nullptr, CBID_NO_CALLBACK, 0, 0, true, view);
const SpriteGroup *group = object.Resolve();
if (group == nullptr || group->type != SGT_TILELAYOUT) return;
uint8_t stage = TOWN_HOUSE_COMPLETED;
const DrawTileSprites *dts = reinterpret_cast<const TileLayoutSpriteGroup *>(group)->ProcessRegisters(&stage);
PaletteID palette = GetColourPalette(spec->random_colour[0]);
if (spec->callback_mask.Test(HouseCallbackMask::Colour)) {
uint16_t callback = GetHouseCallback(CBID_HOUSE_COLOUR, 0, 0, house_id, nullptr, INVALID_TILE, true, view);
if (callback != CALLBACK_FAILED) {
/* If bit 14 is set, we should use a 2cc colour map, else use the callback value. */
palette = HasBit(callback, 14) ? GB(callback, 0, 8) + SPR_2CCMAP_BASE : callback;
}
}
SpriteID image = dts->ground.sprite;
PaletteID pal = dts->ground.pal;
if (HasBit(image, SPRITE_MODIFIER_CUSTOM_SPRITE)) image += stage;
if (HasBit(pal, SPRITE_MODIFIER_CUSTOM_SPRITE)) pal += stage;
if (GB(image, 0, SPRITE_WIDTH) != 0) {
DrawSprite(image, GroundSpritePaletteTransform(image, pal, palette), x, y);
}
DrawNewGRFTileSeqInGUI(x, y, dts, stage, palette);
}
/**
* Draw a house that does not exist.
* @param x Position x of image.