From 704f5e250038400f91f2bf58e9f32cc0b98e22a7 Mon Sep 17 00:00:00 2001 From: Rubidium Date: Tue, 18 Feb 2025 19:37:17 +0100 Subject: [PATCH] Codechange: explicitly initialise Sign member variables --- src/signs.cpp | 8 -------- src/signs_base.h | 15 ++++++++------- src/signs_cmd.cpp | 9 ++------- 3 files changed, 10 insertions(+), 22 deletions(-) diff --git a/src/signs.cpp b/src/signs.cpp index e8e85364b9..a2bf7ab979 100644 --- a/src/signs.cpp +++ b/src/signs.cpp @@ -24,14 +24,6 @@ SignPool _sign_pool("Sign"); INSTANTIATE_POOL_METHODS(Sign) -/** - * Creates a new sign - */ -Sign::Sign(Owner owner) -{ - this->owner = owner; -} - /** Destroy the sign */ Sign::~Sign() { diff --git a/src/signs_base.h b/src/signs_base.h index 2d02817b0b..2973cb48f7 100644 --- a/src/signs_base.h +++ b/src/signs_base.h @@ -19,14 +19,15 @@ typedef Pool SignPool; extern SignPool _sign_pool; struct Sign : SignPool::PoolItem<&_sign_pool> { - std::string name; - TrackedViewportSign sign; - int32_t x; - int32_t y; - int32_t z; - Owner owner; // placed by this company. Anyone can delete them though. OWNER_NONE for gray signs from old games. + std::string name{}; + TrackedViewportSign sign{}; + int32_t x = 0; + int32_t y = 0; + int32_t z = 0; + Owner owner = INVALID_OWNER; // placed by this company. Anyone can delete them though. OWNER_NONE for gray signs from old games. - Sign(Owner owner = INVALID_OWNER); + Sign() {} + Sign(Owner owner, int32_t x, int32_t y, int32_t z, const std::string &name) : name(name), x(x), y(y), z(z), owner(owner) {} ~Sign(); void UpdateVirtCoord(); diff --git a/src/signs_cmd.cpp b/src/signs_cmd.cpp index e9e74a3fb2..0e02401129 100644 --- a/src/signs_cmd.cpp +++ b/src/signs_cmd.cpp @@ -42,16 +42,11 @@ std::tuple CmdPlaceSign(DoCommandFlags flags, TileIndex til /* When we execute, really make the sign */ if (flags.Test(DoCommandFlag::Execute)) { - Sign *si = new Sign(_game_mode == GM_EDITOR ? OWNER_DEITY : _current_company); int x = TileX(tile) * TILE_SIZE; int y = TileY(tile) * TILE_SIZE; - si->x = x; - si->y = y; - si->z = GetSlopePixelZ(x, y); - if (!text.empty()) { - si->name = text; - } + Sign *si = new Sign(_game_mode == GM_EDITOR ? OWNER_DEITY : _current_company, x, y, GetSlopePixelZ(x, y), text); + si->UpdateVirtCoord(); InvalidateWindowData(WC_SIGN_LIST, 0, 0); return { CommandCost(), si->index };