From 310fd08bd9068babd668d39f1febb79c248a9b18 Mon Sep 17 00:00:00 2001 From: Jarod42 Date: Wed, 24 Apr 2024 21:05:31 +0200 Subject: [PATCH] Clean up headers: - member initializations - add some missing `const` - add some missing `explicit` - `default` some default constructor - remove declaration without definition `CUpgrade::SetIcon` --- src/include/icons.h | 8 +- src/include/iolib.h | 4 +- src/include/map.h | 12 +-- src/include/net_message.h | 147 +++++++++++++++--------------- src/include/net_serialization.h | 3 + src/include/particle.h | 14 ++- src/include/pathfinder.h | 22 ++--- src/include/player.h | 44 ++++----- src/include/sdl2_helper.h | 86 ++++++++--------- src/include/settings.h | 28 +++--- src/include/sound.h | 8 +- src/include/spells.h | 2 +- src/include/st_backtrace.h | 24 ++--- src/include/tileset.h | 71 +++++++-------- src/include/ui.h | 5 +- src/include/unit.h | 50 +++++----- src/include/unitptr.h | 4 +- src/include/unittype.h | 6 +- src/include/upgrade_structs.h | 2 - src/include/vec2i.h | 6 +- src/include/video.h | 25 +++-- src/include/viewport.h | 8 +- src/include/wav.h | 22 ++--- src/include/widgets.h | 82 ++++++++--------- src/map/map_draw.cpp | 9 -- src/network/net_message.cpp | 10 +- src/particle/graphicanimation.cpp | 2 +- src/pathfinder/pathfinder.cpp | 11 --- src/ui/icons.cpp | 3 +- src/ui/widgets.cpp | 89 ++++-------------- 30 files changed, 353 insertions(+), 454 deletions(-) diff --git a/src/include/icons.h b/src/include/icons.h index 0ae3a3297b..ec17b6a987 100644 --- a/src/include/icons.h +++ b/src/include/icons.h @@ -109,7 +109,7 @@ class ButtonStyle; class CIcon { public: - CIcon(const std::string &ident); + explicit CIcon(const std::string &ident); ~CIcon(); static CIcon *New(const std::string &ident); @@ -144,9 +144,9 @@ class CIcon void SetPaletteSwaps(std::vector &newSwaps); public: - CPlayerColorGraphic *G; /// Graphic data - CPlayerColorGraphic *GScale; /// Icon when drawn grayscaled - int Frame; /// Frame number in graphic + CPlayerColorGraphic *G = nullptr; /// Graphic data + CPlayerColorGraphic *GScale = nullptr; /// Icon when drawn grayscaled + int Frame = 0; /// Frame number in graphic private: std::string Ident; /// Icon identifier diff --git a/src/include/iolib.h b/src/include/iolib.h index 0153677be0..8b1e5bbe1e 100644 --- a/src/include/iolib.h +++ b/src/include/iolib.h @@ -82,7 +82,7 @@ std::unique_ptr CreateFileWriter(const fs::path &filename); class FileList { public: - FileList() : type(0) {} + FileList() = default; bool operator < (const FileList &rhs) const { @@ -93,7 +93,7 @@ class FileList } public: fs::path name; /// Name of the file - int type; /// Type of the file + int type = 0; /// Type of the file }; diff --git a/src/include/map.h b/src/include/map.h index 32f409d5a5..0cb28d5aa5 100644 --- a/src/include/map.h +++ b/src/include/map.h @@ -139,14 +139,14 @@ class CMapInfo std::string Filename; /// Map filename std::string Preamble; /// Map preamble script std::string Postamble; /// Map postamble script - int MapWidth; /// Map width - int MapHeight; /// Map height - PlayerTypes PlayerType[PlayerMax]; /// Same player->Type - int PlayerSide[PlayerMax]; /// Same player->Side - unsigned int MapUID; /// Unique Map ID (hash) + int MapWidth = 0; /// Map width + int MapHeight = 0; /// Map height + PlayerTypes PlayerType[PlayerMax]{}; /// Same player->Type + int PlayerSide[PlayerMax]{}; /// Same player->Side + unsigned int MapUID = 0; /// Unique Map ID (hash) private: - bool HighgroundsEnabled = false; /// Map has highgrounds + bool HighgroundsEnabled = false; /// Map has highgrounds }; /*---------------------------------------------------------------------------- diff --git a/src/include/net_message.h b/src/include/net_message.h index d51482c5bb..f3b6e3d608 100644 --- a/src/include/net_message.h +++ b/src/include/net_message.h @@ -54,7 +54,7 @@ class CNetworkHost { public: - CNetworkHost() { Clear(); } + CNetworkHost() = default; size_t Serialize(unsigned char *buf) const; size_t Deserialize(const unsigned char *buf); void Clear(); @@ -64,10 +64,10 @@ class CNetworkHost bool IsValid() const { return (PlyNr != 0) || (PlyName[0] != '\0'); } - uint32_t Host; /// Host address - uint16_t Port; /// Port on host - uint16_t PlyNr; /// Player number - char PlyName[NetPlayerNameSize]; /// Name of player + uint32_t Host = 0; /// Host address + uint16_t Port = 0; /// Port on host + uint16_t PlyNr = 0; /// Player number + char PlyName[NetPlayerNameSize]{}; /// Name of player }; ENUM_CLASS SlotOption : uint8_t { @@ -79,10 +79,10 @@ ENUM_CLASS SlotOption : uint8_t { #if USING_TOLUAPP class ServerSetupStateRacesArray { public: - ServerSetupStateRacesArray() : p(nullptr) {} + ServerSetupStateRacesArray() = default; int8_t& operator[](int idx) { return p[idx].Race; } int8_t& operator[](int idx) const { return p[idx].Race; } - SettingsPresets *p; + SettingsPresets *p = nullptr; }; #endif @@ -134,31 +134,31 @@ class CServerSetup bool operator != (const CServerSetup &rhs) const { return !(*this == rhs); } public: Settings ServerGameSettings; - SlotOption CompOpt[PlayerMax]; /// Free slot option selection {"Available", "Computer", "Closed" } - uint8_t Ready[PlayerMax]; /// Client ready state + SlotOption CompOpt[PlayerMax]{}; /// Free slot option selection {"Available", "Computer", "Closed" } + uint8_t Ready[PlayerMax]{}; /// Client ready state // Fill in here... #if USING_TOLUAPP // TODO: can be removed once tolua++ is gone - inline char get_ResourcesOption() { return (char)ServerGameSettings.Resources; } - inline char get_UnitsOption() { return (char)ServerGameSettings.NumUnits; } - inline char get_FogOfWar() { return (char)!ServerGameSettings.NoFogOfWar; } - inline char get_Inside() { return (char)ServerGameSettings.Inside; } - inline char get_RevealMap() { return (char)ServerGameSettings.RevealMap; } - inline char get_GameTypeOption() { return (char)ServerGameSettings.GameType; } - inline char get_Difficulty() { return (char)ServerGameSettings.Difficulty; } - inline char get_Opponents() { return (char)ServerGameSettings.Opponents; } - inline char set_ResourcesOption(char v) { return ServerGameSettings.Resources = v; } - inline char set_UnitsOption(char v) { return ServerGameSettings.NumUnits = v; } - inline char set_FogOfWar(char v) { return ServerGameSettings.NoFogOfWar = !v; } - inline char set_Inside(char v) { return ServerGameSettings.Inside = v; } - inline char set_RevealMap(char v) { return ServerGameSettings.RevealMap = (MapRevealModes)v; } - inline char set_GameTypeOption(char v) { return ServerGameSettings.GameType = (GameTypes)v; } - inline char set_Difficulty(char v) { return ServerGameSettings.Difficulty = v; } - inline char set_Opponents(char v) { return ServerGameSettings.Opponents = v; } + char get_ResourcesOption() const { return (char)ServerGameSettings.Resources; } + char get_UnitsOption() const { return (char)ServerGameSettings.NumUnits; } + char get_FogOfWar() const { return (char)!ServerGameSettings.NoFogOfWar; } + char get_Inside() const { return (char)ServerGameSettings.Inside; } + char get_RevealMap() const { return (char)ServerGameSettings.RevealMap; } + char get_GameTypeOption() const { return (char)ServerGameSettings.GameType; } + char get_Difficulty() const { return (char)ServerGameSettings.Difficulty; } + char get_Opponents() const { return (char)ServerGameSettings.Opponents; } + char set_ResourcesOption(char v) { return ServerGameSettings.Resources = v; } + char set_UnitsOption(char v) { return ServerGameSettings.NumUnits = v; } + char set_FogOfWar(char v) { return ServerGameSettings.NoFogOfWar = !v; } + char set_Inside(char v) { return ServerGameSettings.Inside = v; } + char set_RevealMap(char v) { return ServerGameSettings.RevealMap = (MapRevealModes)v; } + char set_GameTypeOption(char v) { return ServerGameSettings.GameType = (GameTypes)v; } + char set_Difficulty(char v) { return ServerGameSettings.Difficulty = v; } + char set_Opponents(char v) { return ServerGameSettings.Opponents = v; } ServerSetupStateRacesArray racesArray; - inline ServerSetupStateRacesArray *get_Race() { + ServerSetupStateRacesArray *get_Race() { if (racesArray.p == nullptr) { racesArray.p = ((SettingsPresets*)ServerGameSettings.Presets); } @@ -202,7 +202,7 @@ enum _ic_message_subtype_ { class CInitMessage_Header { public: - CInitMessage_Header() {} + CInitMessage_Header() = default; CInitMessage_Header(unsigned char type, unsigned char subtype) : type(type), subtype(subtype) @@ -215,14 +215,14 @@ class CInitMessage_Header size_t Deserialize(const unsigned char *p); static size_t Size() { return 2; } private: - unsigned char type; - unsigned char subtype; + unsigned char type = 0; + unsigned char subtype = 0; }; class CInitMessage_Hello { public: - CInitMessage_Hello() {} + CInitMessage_Hello() = default; explicit CInitMessage_Hello(const char *name); const CInitMessage_Header &GetHeader() const { return header; } std::vector Serialize() const; @@ -231,9 +231,9 @@ class CInitMessage_Hello private: CInitMessage_Header header; public: - char PlyName[NetPlayerNameSize]; /// Name of player - int32_t Stratagus; /// Stratagus engine version - uint32_t Version; /// Lua files version + char PlyName[NetPlayerNameSize]{}; /// Name of player + int32_t Stratagus = 0; /// Stratagus engine version + uint32_t Version = 0; /// Lua files version }; class CInitMessage_Config @@ -247,7 +247,7 @@ class CInitMessage_Config private: CInitMessage_Header header; public: - uint8_t clientIndex; /// index of the receiving client in the compacted host array + uint8_t clientIndex = 0; /// index of the receiving client in the compacted host array CNetworkHost hosts[PlayerMax]; /// Participant information }; @@ -262,7 +262,7 @@ class CInitMessage_EngineMismatch private: CInitMessage_Header header; public: - int32_t Stratagus; /// Stratagus engine version + int32_t Stratagus = 0; /// Stratagus engine version }; class CInitMessage_LuaFilesMismatch @@ -290,16 +290,16 @@ class CInitMessage_Welcome private: CInitMessage_Header header; public: - CNetworkHost hosts[PlayerMax]; /// Participants information - uint16_t NetHostSlot; /// slot for the receiving host in the server host array - int32_t Lag; /// Lag time - int32_t gameCyclesPerUpdate; /// Update frequency + CNetworkHost hosts[PlayerMax]{}; /// Participants information + uint16_t NetHostSlot = 0; /// slot for the receiving host in the server host array + int32_t Lag = 0; /// Lag time + int32_t gameCyclesPerUpdate = 0; /// Update frequency }; class CInitMessage_Map { public: - CInitMessage_Map() {} + CInitMessage_Map() = default; CInitMessage_Map(const char *path, uint32_t mapUID); const CInitMessage_Header &GetHeader() const { return header; } std::vector Serialize() const; @@ -308,16 +308,16 @@ class CInitMessage_Map private: CInitMessage_Header header; public: - char MapPath[256]; - uint32_t MapUID; /// UID of map to play. + char MapPath[256]{}; + uint32_t MapUID = 0; /// UID of map to play. }; class CInitMessage_MapFileFragment { public: - CInitMessage_MapFileFragment() {} + CInitMessage_MapFileFragment() = default; CInitMessage_MapFileFragment(const char *path, const std::vector &data, uint32_t Fragment); - CInitMessage_MapFileFragment(uint32_t Fragment); + explicit CInitMessage_MapFileFragment(uint32_t Fragment); const CInitMessage_Header &GetHeader() const { return header; } std::vector Serialize() const; void Deserialize(const unsigned char *p); @@ -325,16 +325,16 @@ class CInitMessage_MapFileFragment private: CInitMessage_Header header; public: - char Data[384]; // path directly followed by data fragment - uint8_t PathSize; - uint16_t DataSize; - uint32_t FragmentIndex; + char Data[384]{}; // path directly followed by data fragment + uint8_t PathSize = 0; + uint16_t DataSize = 0; + uint32_t FragmentIndex = 0; }; class CInitMessage_State { public: - CInitMessage_State() {} + CInitMessage_State() = default; CInitMessage_State(int type, const CServerSetup &data); const CInitMessage_Header &GetHeader() const { return header; } std::vector Serialize() const; @@ -427,7 +427,7 @@ enum _extended_message_type_ { class CNetworkCommand { public: - CNetworkCommand() : Unit(0), X(0), Y(0), Dest(0) {} + CNetworkCommand() = default; void Clear() { this->Unit = this->X = this->Y = this->Dest = 0; } size_t Serialize(unsigned char *buf) const; @@ -435,10 +435,10 @@ class CNetworkCommand static size_t Size() { return 2 + 2 + 2 + 2; } public: - uint16_t Unit; /// Command for unit - uint16_t X; /// Map position X - uint16_t Y; /// Map position Y - uint16_t Dest; /// Destination unit + uint16_t Unit = 0; /// Command for unit + uint16_t X = 0; /// Map position X + uint16_t Y = 0; /// Map position Y + uint16_t Dest = 0; /// Destination unit }; /** @@ -447,17 +447,17 @@ class CNetworkCommand class CNetworkExtendedCommand { public: - CNetworkExtendedCommand() : ExtendedType(0), Arg1(0), Arg2(0), Arg3(0), Arg4(0) {} + CNetworkExtendedCommand() = default; size_t Serialize(unsigned char *buf) const; size_t Deserialize(const unsigned char *buf); static size_t Size() { return 1 + 1 + 2 + 2 + 2; } - uint8_t ExtendedType; /// Extended network command type - uint8_t Arg1; /// Argument 1 - uint16_t Arg2; /// Argument 2 - uint16_t Arg3; /// Argument 3 - uint16_t Arg4; /// Argument 4 + uint8_t ExtendedType = 0; /// Extended network command type + uint8_t Arg1 = 0; /// Argument 1 + uint16_t Arg2 = 0; /// Argument 2 + uint16_t Arg3 = 0; /// Argument 3 + uint16_t Arg4 = 0; /// Argument 4 }; /** @@ -480,14 +480,14 @@ class CNetworkChat class CNetworkCommandSync { public: - CNetworkCommandSync() : syncSeed(0), syncHash(0) {} + CNetworkCommandSync() = default; size_t Serialize(unsigned char *buf) const; size_t Deserialize(const unsigned char *buf); static size_t Size() { return 4 + 4; }; public: - uint32_t syncSeed; - uint32_t syncHash; + uint32_t syncSeed = 0; + uint32_t syncHash = 0; }; /** @@ -496,13 +496,13 @@ class CNetworkCommandSync class CNetworkCommandQuit { public: - CNetworkCommandQuit() : player(0) {} + CNetworkCommandQuit() = default; size_t Serialize(unsigned char *buf) const; size_t Deserialize(const unsigned char *buf); static size_t Size() { return 2; }; public: - uint16_t player; + uint16_t player = 0; }; /** @@ -511,14 +511,14 @@ class CNetworkCommandQuit class CNetworkSelection { public: - CNetworkSelection() : player(0) {} + CNetworkSelection() = default; size_t Serialize(unsigned char *buf) const; size_t Deserialize(const unsigned char *buf); size_t Size() const; public: - uint16_t player; + uint16_t player = 0; std::vector Units; /// Selection Units }; @@ -530,20 +530,15 @@ class CNetworkSelection class CNetworkPacketHeader { public: - CNetworkPacketHeader() - { - Cycle = 0; - memset(Type, 0, sizeof(Type)); - OrigPlayer = 255; - } + CNetworkPacketHeader() = default; size_t Serialize(unsigned char *buf) const; size_t Deserialize(const unsigned char *buf); static size_t Size() { return 1 + 1 + 1 * MaxNetworkCommands; } - uint8_t Type[MaxNetworkCommands]; /// Commands in packet - uint8_t Cycle; /// Destination game cycle - uint8_t OrigPlayer; /// Host address + uint8_t Type[MaxNetworkCommands]{}; /// Commands in packet + uint8_t Cycle = 0; /// Destination game cycle + uint8_t OrigPlayer = 255; /// Host address }; /** diff --git a/src/include/net_serialization.h b/src/include/net_serialization.h index 9efeeb10b2..d5bfbb082b 100644 --- a/src/include/net_serialization.h +++ b/src/include/net_serialization.h @@ -29,6 +29,9 @@ #ifndef NET_SERIALIZATION_H #define NET_SERIALIZATION_H +#include +#include + extern size_t serialize32(unsigned char *buf, uint32_t data); extern size_t serialize32(unsigned char *buf, int32_t data); extern size_t serialize16(unsigned char *buf, uint16_t data); diff --git a/src/include/particle.h b/src/include/particle.h index 89b2e21026..2bcac3f156 100644 --- a/src/include/particle.h +++ b/src/include/particle.h @@ -48,8 +48,8 @@ class GraphicAnimation { CGraphic *g; int ticksPerFrame; - int currentFrame; - int currTicks; + int currentFrame = 0; + int currTicks = 0; public: GraphicAnimation(CGraphic *g, int ticksPerFrame); ~GraphicAnimation() {} @@ -78,9 +78,7 @@ class GraphicAnimation class CParticle { public: - CParticle(CPosition position, int drawlevel = 0) : - pos(position), destroyed(false), drawLevel(drawlevel) - {} + CParticle(CPosition position, int drawlevel = 0) : pos(position), drawLevel(drawlevel) {} virtual ~CParticle() {} virtual CParticle *clone() = 0; @@ -89,15 +87,15 @@ class CParticle virtual void update(int) = 0; void destroy() { destroyed = true; } - bool isDestroyed() { return destroyed; } + bool isDestroyed() const { return destroyed; } int getDrawLevel() const { return drawLevel; } void setDrawLevel(int value) { drawLevel = value; } protected: CPosition pos; - bool destroyed; - int drawLevel; + bool destroyed = false; + int drawLevel = 0; }; diff --git a/src/include/pathfinder.h b/src/include/pathfinder.h index e020a950ef..e524ef30ee 100644 --- a/src/include/pathfinder.h +++ b/src/include/pathfinder.h @@ -69,7 +69,7 @@ enum _move_return_ { class PathFinderInput { public: - PathFinderInput(); + PathFinderInput() = default; CUnit *GetUnit() const { return unit; } const Vec2i &GetUnitPos() const; Vec2i GetUnitSize() const; @@ -90,13 +90,13 @@ class PathFinderInput void Load(lua_State *l); private: - CUnit *unit; - Vec2i unitSize; - Vec2i goalPos; - Vec2i goalSize; - int minRange; - int maxRange; - bool isRecalculatePathNeeded; + CUnit *unit = nullptr; + Vec2i unitSize{0, 0}; + Vec2i goalPos{-1, -1}; + Vec2i goalSize{0, 0}; + int minRange = 0; + int maxRange = 0; + bool isRecalculatePathNeeded = true; }; class PathFinderOutput @@ -113,7 +113,7 @@ class PathFinderOutput void Load(lua_State *l); public: uint16_t Cycles; /// how much Cycles we move. - unsigned Fast:4; /// Flag fast move (one step). Fits at most MAX_FAST + unsigned Fast:4; /// Flag fast move (one step). Fits at most MAX_FAST unsigned OverflowLength:4; /// overflow length not stored in Path (may be more). Fits at most MAX_OVERFLOW uint8_t Length; /// stored path length char Path[MAX_PATH_LENGTH]; /// directions of stored path @@ -172,8 +172,8 @@ class TerrainTraversal private: std::vector m_values; std::queue m_queue; - unsigned int m_extented_width; - unsigned int m_height; + unsigned int m_extented_width = 0; + unsigned int m_height = 0; }; template diff --git a/src/include/player.h b/src/include/player.h index 7b32daa486..c0ff7b3591 100644 --- a/src/include/player.h +++ b/src/include/player.h @@ -216,17 +216,17 @@ class CPlayer void SetRevealed(const bool revealed); public: - int Index; /// player as number + int Index = 0; /// player as number std::string Name; /// name of non computer PlayerTypes Type; /// type of player (human,computer,...) - int Race; /// race of player (orc,human,...) + int Race = 0; /// race of player (orc,human,...) std::string AiName; /// AI for computer // friend enemy detection - int Team; /// team of player + int Team = 0; /// team of player - Vec2i StartPos; /// map tile start position + Vec2i StartPos{-1, -1}; /// map tile start position void SetStartView(const Vec2i &pos) { StartPos = pos; } @@ -239,32 +239,32 @@ class CPlayer int SpeedResourcesHarvest[MaxCosts]{}; /// speed factor for harvesting resources int SpeedResourcesReturn[MaxCosts]{}; /// speed factor for returning resources - int SpeedBuild; /// speed factor for building - int SpeedTrain; /// speed factor for training - int SpeedUpgrade; /// speed factor for upgrading - int SpeedResearch; /// speed factor for researching + int SpeedBuild = 0; /// speed factor for building + int SpeedTrain = 0; /// speed factor for training + int SpeedUpgrade = 0; /// speed factor for upgrading + int SpeedResearch = 0; /// speed factor for researching // FIXME: shouldn't use the constant int UnitTypesCount[UnitTypeMax]{}; /// total units of unit-type int UnitTypesAiActiveCount [UnitTypeMax]{}; /// total units of unit-type that have their AI set to active - bool AiEnabled; /// handle AI on local computer + bool AiEnabled = false; /// handle AI on local computer std::unique_ptr Ai; /// Ai structure pointer - int NumBuildings; /// # buildings - int Supply; /// supply available/produced - int Demand; /// demand of player + int NumBuildings = 0; /// # buildings + int Supply = 0; /// supply available/produced + int Demand = 0; /// demand of player - int UnitLimit; /// # food units allowed - int BuildingLimit; /// # buildings allowed - int TotalUnitLimit; /// # total unit number allowed + int UnitLimit = 0; /// # food units allowed + int BuildingLimit = 0; /// # buildings allowed + int TotalUnitLimit = 0; /// # total unit number allowed - int Score; /// Points for killing ... - int TotalUnits; - int TotalBuildings; + int Score = 0; /// Points for killing ... + int TotalUnits = 0; + int TotalBuildings = 0; int TotalResources[MaxCosts]{}; - int TotalRazings; - int TotalKills; /// How many unit killed + int TotalRazings = 0; + int TotalKills = 0; /// How many unit killed int LostMainFacilityTimer { 0 };/// The timer for when the player lost the last town hall /// (to make the player's units be revealed) @@ -279,8 +279,8 @@ class CPlayer CUnitColors UnitColors; /// Unit colors for new units std::vector Units; /// units of this player std::vector FreeWorkers; /// Container for free workers - unsigned int Enemy; /// enemy bit field for this player - unsigned int Allied; /// allied bit field for this player + unsigned int Enemy = 0; /// enemy bit field for this player + unsigned int Allied = 0; /// allied bit field for this player std::set HasVisionFrom; /// set of player indexes that have shared their vision with this player std::set GaveVisionTo; /// set of player indexes that this player has shared vision with diff --git a/src/include/sdl2_helper.h b/src/include/sdl2_helper.h index 9c1177c652..0632e4e79a 100644 --- a/src/include/sdl2_helper.h +++ b/src/include/sdl2_helper.h @@ -32,50 +32,50 @@ //@{ -namespace sdl2 { - struct SDL_Deleter - { - void operator()(SDL_Cursor *ptr) const - { - if (ptr) SDL_FreeCursor(ptr); - } - void operator()(SDL_Surface *ptr) const - { - if (ptr) SDL_FreeSurface(ptr); - } - void operator()(SDL_Texture *ptr) const - { - if (ptr) SDL_DestroyTexture(ptr); - } - void operator()(SDL_Renderer *ptr) const - { - if (ptr) SDL_DestroyRenderer(ptr); - } - void operator()(SDL_Window *ptr) const - { - if (ptr) SDL_DestroyWindow(ptr); - } - }; +namespace sdl2 +{ +struct SDL_Deleter +{ + void operator()(SDL_Cursor *ptr) const + { + if (ptr) SDL_FreeCursor(ptr); + } + void operator()(SDL_Surface *ptr) const + { + if (ptr) SDL_FreeSurface(ptr); + } + void operator()(SDL_Texture *ptr) const + { + if (ptr) SDL_DestroyTexture(ptr); + } + void operator()(SDL_Renderer *ptr) const + { + if (ptr) SDL_DestroyRenderer(ptr); + } + void operator()(SDL_Window *ptr) const + { + if (ptr) SDL_DestroyWindow(ptr); + } +}; - template - struct _shared_ptr : public std::shared_ptr - { - explicit _shared_ptr(T* t = nullptr) : std::shared_ptr(t, SDL_Deleter()) {} +template +struct _shared_ptr : public std::shared_ptr +{ + explicit _shared_ptr(T *t = nullptr) : std::shared_ptr(t, SDL_Deleter()) {} - void reset(T* t = nullptr) { std::shared_ptr::reset(t, SDL_Deleter()); } - }; + void reset(T *t = nullptr) { std::shared_ptr::reset(t, SDL_Deleter()); } +}; - - using CursorPtr = std::unique_ptr; - using SurfacePtr = std::unique_ptr; - using TexturePtr = std::unique_ptr; - using RendererPtr = std::unique_ptr; - using WindowPtr = std::unique_ptr; - using SurfaceShPtr = _shared_ptr; - using TextureShPtr = _shared_ptr; - using RendererShPtr = _shared_ptr; - using WindowShPtr = _shared_ptr; -} -using sequence_of_imagesPtrs = std::vector; -using sequence_of_images = std::vector; +using CursorPtr = std::unique_ptr; +using SurfacePtr = std::unique_ptr; +using TexturePtr = std::unique_ptr; +using RendererPtr = std::unique_ptr; +using WindowPtr = std::unique_ptr; +using SurfaceShPtr = _shared_ptr; +using TextureShPtr = _shared_ptr; +using RendererShPtr = _shared_ptr; +using WindowShPtr = _shared_ptr; +} // namespace sdl2 +using sequence_of_imagesPtrs = std::vector; +using sequence_of_images = std::vector; //@} diff --git a/src/include/settings.h b/src/include/settings.h index b665db4c22..06cd25e7b8 100644 --- a/src/include/settings.h +++ b/src/include/settings.h @@ -129,11 +129,11 @@ static_assert(MAX_RACES < 256, "Race selection needs to fit into 8 bits"); static_assert(PlayerMax < 256, "Team number must fit into 8 bits"); struct SettingsPresets { - int8_t PlayerColor; /// Color of a player + int8_t PlayerColor = 0; /// Color of a player std::string AIScript; /// AI script for computer to use - int8_t Race; /// Race of the player - int8_t Team; /// Team of player - PlayerTypes Type; /// Type of player (for network games) + int8_t Race = 0; /// Race of the player + int8_t Team = 0; /// Team of player + PlayerTypes Type = PlayerTypes::PlayerUnset; /// Type of player (for network games) void Save(const std::function & f) { f(std::string("PlayerColor = ") + std::to_string(PlayerColor)); @@ -226,21 +226,21 @@ ENUM_CLASS FieldOfViewTypes : uint8_t { ** */ struct Settings { - NetGameTypes NetGameType; /// Multiplayer or single player + NetGameTypes NetGameType = NetGameTypes::Unset; /// Multiplayer or single player // Individual presets: // For single-player game only Presets[0] will be used.. - SettingsPresets Presets[PlayerMax]; + SettingsPresets Presets[PlayerMax]{}; // Common settings: - int8_t Resources; /// Preset resource factor - int8_t NumUnits; /// Preset # of units - int8_t Opponents; /// Preset # of ai-opponents - int8_t Difficulty; /// Terrain type (summer,winter,...) - GameTypes GameType; /// Game type (melee, free for all,...) - FieldOfViewTypes FoV; /// Which field of view is used - important to be shared for unit sight - MapRevealModes RevealMap; /// Reveal map kind - RevealTypes DefeatReveal; + int8_t Resources = 0; /// Preset resource factor + int8_t NumUnits = 0; /// Preset # of units + int8_t Opponents = 0; /// Preset # of ai-opponents + int8_t Difficulty = 0; /// Terrain type (summer,winter,...) + GameTypes GameType = GameTypes::SettingsGameTypeMapDefault; /// Game type (melee, free for all,...) + FieldOfViewTypes FoV = FieldOfViewTypes::cShadowCasting; /// Which field of view is used - important to be shared for unit sight + MapRevealModes RevealMap = MapRevealModes::cHidden; /// Reveal map kind + RevealTypes DefeatReveal = RevealTypes::cNoRevelation; unsigned NoFogOfWar:1; /// if dynamic fog of war is disabled unsigned Inside:1; /// if game uses interior tileset or is generally "inside" for the purpose of obstacles diff --git a/src/include/sound.h b/src/include/sound.h index dc99c9b18b..49e015464f 100644 --- a/src/include/sound.h +++ b/src/include/sound.h @@ -101,10 +101,10 @@ class CSound : public std::enable_shared_from_this class Key { friend CSound; - Key(){}; + Key(){} }; public: - explicit CSound(Key){} + explicit CSound(Key) {} ~CSound(); CSound(const CSound &) = delete; @@ -133,8 +133,8 @@ class CSound : public std::enable_shared_from_this ** Origin of a sound */ struct Origin { - const void *Base; /// pointer on a Unit - unsigned Id; /// unique identifier (if the pointer has been shared) + const void *Base = nullptr; /// pointer on a Unit + unsigned Id = 0; /// unique identifier (if the pointer has been shared) }; diff --git a/src/include/spells.h b/src/include/spells.h index e53a3fbbe3..26defa4349 100644 --- a/src/include/spells.h +++ b/src/include/spells.h @@ -191,7 +191,7 @@ class SpellType int Slot; /// Spell numeric identifier // Spell Specifications - ETarget Target; /// Targeting information. See TargetType. + ETarget Target = ETarget::Self; /// Targeting information. See TargetType. std::vector> Action; /// More arguments for spell (damage, delay, additional sounds...). int Range = 0; /// Max range of the target. diff --git a/src/include/st_backtrace.h b/src/include/st_backtrace.h index a26bf9e516..c0db4bca1d 100644 --- a/src/include/st_backtrace.h +++ b/src/include/st_backtrace.h @@ -24,33 +24,23 @@ inline void print_backtrace(int sz = 100) { #undef DELETE inline void print_backtrace(int sz = 100) { - unsigned int i; void *stack[100]; - unsigned short frames; - SYMBOL_INFO *symbol; - HANDLE process; - DWORD displacement; - IMAGEHLP_LINE64 *line; - char* name; - process = GetCurrentProcess(); + HANDLE process = GetCurrentProcess(); SymInitialize(process, nullptr, TRUE); - frames = CaptureStackBackTrace(0, sz, stack, nullptr); + unsigned short frames = CaptureStackBackTrace(0, sz, stack, nullptr); fprintf(stderr, "backtrace returned %d addresses\n", frames); - symbol = (SYMBOL_INFO*)calloc(sizeof(SYMBOL_INFO) + 1024 * sizeof(char), 1); + SYMBOL_INFO *symbol = (SYMBOL_INFO*)calloc(sizeof(SYMBOL_INFO) + 1024 * sizeof(char), 1); symbol->MaxNameLen = 1024; symbol->SizeOfStruct = sizeof(SYMBOL_INFO); - line = (IMAGEHLP_LINE64 *)malloc(sizeof(IMAGEHLP_LINE64)); + IMAGEHLP_LINE64 *line = (IMAGEHLP_LINE64 *)malloc(sizeof(IMAGEHLP_LINE64)); line->SizeOfStruct = sizeof(IMAGEHLP_LINE64); - for(i = 0; i < frames; i++) { + for(unsigned int i = 0; i < frames; i++) { SymFromAddr(process, (DWORD64)(stack[i]), 0, symbol); - if (symbol->Name) { - name = symbol->Name; - } else { - name = ""; - } + const char* name = symbol->Name ? symbol->Name : ""; + DWORD displacement; if (SymGetLineFromAddr64(process, (DWORD64)(stack[i]), &displacement, line)) { fprintf(stderr, "%d: %s in %s:%d 0x%llx\n", frames - i - 1, name, line->FileName, line->LineNumber, symbol->Address); } else { diff --git a/src/include/tileset.h b/src/include/tileset.h index 4d1fe6bf80..60ed01aa37 100644 --- a/src/include/tileset.h +++ b/src/include/tileset.h @@ -112,8 +112,7 @@ enum class ETileType : unsigned char { /// Single tile definition struct CTileInfo { public: - CTileInfo() : BaseTerrain(0), MixTerrain(0) - {} + CTileInfo() = default; CTileInfo(terrain_typeIdx base, terrain_typeIdx mix) : BaseTerrain(base), MixTerrain(mix) {} @@ -124,8 +123,8 @@ struct CTileInfo { bool operator !=(const CTileInfo &rhs) const { return !(*this == rhs); } public: - terrain_typeIdx BaseTerrain; /// Basic terrain of the tile - terrain_typeIdx MixTerrain; /// Terrain mixed with this + terrain_typeIdx BaseTerrain = 0; /// Basic terrain of the tile + terrain_typeIdx MixTerrain = 0; /// Terrain mixed with this }; /// Definition for a terrain type @@ -137,12 +136,12 @@ struct SolidTerrainInfo { class CTile { public: - CTile() : tile(0), flag(0) {} + CTile() = default; public: - graphic_index tile; /// graphical pos - tile_flags flag; /// Flag - CTileInfo tileinfo; /// Tile descriptions + graphic_index tile = 0; /// graphical pos + tile_flags flag = 0; /// Flag + CTileInfo tileinfo; /// Tile descriptions }; /// Tileset definition @@ -244,26 +243,26 @@ class CTileset PixelSize pixelTileSize; /// Size of a tile in pixel // some cached values based on pixelTileSize and the logical tile size in the game - uint8_t logicalTileToGraphicalTileMultiplier; /// By what to multiply logical tile coordinates to get graphical tile coordinates - uint8_t logicalTileToGraphicalTileShift; /// By what to shift logical tile coordinates to get graphical tile coordinates - uint8_t graphicalTileSizeShiftX; /// 1< solidTerrainTypes; /// Information about solid terrains. #if 1 - std::vector mixedLookupTable; /// Lookup for what part of tile used - graphic_index topOneTreeTile; /// Tile for one tree top - graphic_index midOneTreeTile; /// Tile for one tree middle - graphic_index botOneTreeTile; /// Tile for one tree bottom - graphic_index removedTreeTile; /// Tile placed where trees are gone - int woodTable[20]; /// Table for tree removable - graphic_index topOneRockTile; /// Tile for one rock top - graphic_index midOneRockTile; /// Tile for one rock middle - graphic_index botOneRockTile; /// Tile for one rock bottom - graphic_index removedRockTile; /// Tile placed where rocks are gone - int rockTable[20]; /// Removed rock placement table - tile_index humanWallTable[16]; /// Human wall placement table - tile_index orcWallTable[16]; /// Orc wall placement table + std::vector mixedLookupTable; /// Lookup for what part of tile used + graphic_index topOneTreeTile = 0; /// Tile for one tree top + graphic_index midOneTreeTile = 0; /// Tile for one tree middle + graphic_index botOneTreeTile = 0; /// Tile for one tree bottom + graphic_index removedTreeTile = 0; /// Tile placed where trees are gone + int woodTable[20]{}; /// Table for tree removable + graphic_index topOneRockTile = 0; /// Tile for one rock top + graphic_index midOneRockTile = 0; /// Tile for one rock middle + graphic_index botOneRockTile = 0; /// Tile for one rock bottom + graphic_index removedRockTile = 0; /// Tile placed where rocks are gone + int rockTable[20]{}; /// Removed rock placement table + tile_index humanWallTable[16]{}; /// Human wall placement table + tile_index orcWallTable[16]{}; /// Orc wall placement table #endif }; @@ -403,13 +402,13 @@ class CTilesetGraphicGenerator void parseExtended(lua_State *luaStack); private: - const CTileset *SrcTileset {nullptr}; - const CGraphic *SrcTilesetGraphic {nullptr}; - const CGraphic *SrcImgGraphic {nullptr}; + const CTileset *SrcTileset{nullptr}; + const CGraphic *SrcTilesetGraphic{nullptr}; + const CGraphic *SrcImgGraphic{nullptr}; struct TilesGraphics { - std::queue Indexes; + std::queue Indexes; std::queue Images; }; TilesGraphics Result; @@ -447,16 +446,14 @@ class CTilesetParser void parseExtended(lua_State *luaStack); private: - CTileset *BaseTileset {nullptr}; - const CGraphic *BaseGraphic {nullptr}; - CGraphic *SrcImgGraphic {nullptr}; + CTileset *BaseTileset{nullptr}; + const CGraphic *BaseGraphic{nullptr}; + CGraphic *SrcImgGraphic{nullptr}; - sequence_of_images ExtGraphic; - std::map ExtTiles; + sequence_of_images ExtGraphic; + std::map ExtTiles; }; -/*---------------------------------------------------------------------------- --- Functions -----------------------------------------------------------------------------*/ + //@} #endif // !TILESET_H diff --git a/src/include/ui.h b/src/include/ui.h index 42009d166b..1204b5a885 100644 --- a/src/include/ui.h +++ b/src/include/ui.h @@ -336,7 +336,7 @@ class CResourceInfo class CInfoPanel { public: - CInfoPanel() : G(nullptr), X(0), Y(0) {} + CInfoPanel() = default; void Draw(); @@ -365,7 +365,6 @@ class CUserInterface void Load(); - bool MouseScroll = false; /// Enable mouse scrolling bool KeyScroll = false; /// Enable keyboard scrolling /// Key Scroll Speed @@ -426,7 +425,7 @@ class CUserInterface // Completed bar CColor CompletedBarColorRGB; /// color for completed bar IntColor CompletedBarColor; /// color for completed bar - bool CompletedBarShadow; /// should complete bar have shadow + bool CompletedBarShadow = false; /// should complete bar have shadow // Button panel CButtonPanel ButtonPanel; diff --git a/src/include/unit.h b/src/include/unit.h index f9f6d52f64..0120ad3080 100644 --- a/src/include/unit.h +++ b/src/include/unit.h @@ -319,13 +319,13 @@ class CUnit }; public: // @note int is faster than shorts - unsigned int Refs; /// Reference counter - unsigned int ReleaseCycle; /// When this unit could be recycled + unsigned int Refs = 0; /// Reference counter + unsigned int ReleaseCycle = 0; /// When this unit could be recycled CUnitManagerData UnitManagerData; - size_t PlayerSlot; /// index in Player->Units + size_t PlayerSlot = 0; /// index in Player->Units - int InsideCount; /// Number of units inside. - int BoardCount; /// Number of units transported inside. + int InsideCount = 0; /// Number of units inside. + int BoardCount = 0; /// Number of units transported inside. CUnit *UnitInside = nullptr; /// Pointer to one of the units inside. CUnit *Container = nullptr; /// Pointer to the unit containing it (or 0) CUnit *NextContained = nullptr; /// Next unit in the container. @@ -334,36 +334,36 @@ class CUnit CUnit *NextWorker = nullptr; //pointer to next assigned worker to "Goal" resource. struct { CUnit *Workers = nullptr; /// pointer to first assigned worker to this resource. - int Assigned; /// how many units are assigned to harvesting from the resource. - int Active; /// how many units are harvesting from the resource. + int Assigned = 0; /// how many units are assigned to harvesting from the resource. + int Active = 0; /// how many units are harvesting from the resource. } Resource; /// Resource still Vec2i tilePos{-1, -1}; /// Map position - unsigned int Offset;/// Map position as flat index offset (x + y * w) + unsigned int Offset = -1;/// Map position as flat index offset (x + y * w) const CUnitType *Type = nullptr; /// Pointer to unit-type (peon,...) - CPlayer *Player = nullptr; /// Owner of this unit - CUnitStats *Stats = nullptr; /// Current unit stats - int CurrentSightRange; /// Unit's Current Sight Range + CPlayer *Player = nullptr; /// Owner of this unit + CUnitStats *Stats = nullptr; /// Current unit stats + int CurrentSightRange = 0; /// Unit's Current Sight Range // Pathfinding stuff: std::unique_ptr pathFinderData; // DISPLAY: - int Frame; /// Image frame: <0 is mirrored + int Frame = 0; /// Image frame: <0 is mirrored int Colors = -1; /// custom colors bool IndividualUpgrades[UpgradeMax]{}; /// individual upgrades which the unit has - signed char IX; /// X image displacement to map position - signed char IY; /// Y image displacement to map position - unsigned char Direction; //: 8; /// angle (0-255) unit looking - unsigned char CurrentResource; - int ResourcesHeld; /// Resources Held by a unit + signed char IX = 0; /// X image displacement to map position + signed char IY = 0; /// Y image displacement to map position + unsigned char Direction = 0; //: 8; /// angle (0-255) unit looking + unsigned char CurrentResource = 0; + int ResourcesHeld = 0; /// Resources Held by a unit - unsigned char DamagedType; /// Index of damage type of unit which damaged this unit - unsigned long Attacked; /// gamecycle unit was last attacked - unsigned long Summoned; /// GameCycle unit was summoned using spells + unsigned char DamagedType = 0; /// Index of damage type of unit which damaged this unit + unsigned long Attacked = 0; /// gamecycle unit was last attacked + unsigned long Summoned = 0; /// GameCycle unit was summoned using spells unsigned Blink : 3; /// Let selection rectangle blink unsigned Moving : 2; /// The unit is moving unsigned ReCast : 1; /// Recast again next cycle @@ -386,7 +386,7 @@ class CUnit unsigned JustMoved : 3; /// The unit last moved of its own accord this amount of cycles of standing still ago - unsigned TeamSelected; /// unit is selected by a team member. + unsigned TeamSelected = 0; /// unit is selected by a team member. CPlayer *RescuedFrom = nullptr; /// The original owner of a rescued unit. /// nullptr if the unit was not rescued. /* Seen stuff. */ @@ -494,22 +494,22 @@ class CPreference #if USING_TOLUAPP public: - bool get_AiExplores() { return AiExplores; } + bool get_AiExplores() const { return AiExplores; } void set_AiExplores(bool v) { AiExplores = v; GameSettings.AiExplores = v; } - bool get_SimplifiedAutoTargeting() { return SimplifiedAutoTargeting; } + bool get_SimplifiedAutoTargeting() const { return SimplifiedAutoTargeting; } void set_SimplifiedAutoTargeting(bool v) { SimplifiedAutoTargeting = v; GameSettings.SimplifiedAutoTargeting = v; } - bool get_AiChecksDependencies() { return AiChecksDependencies; } + bool get_AiChecksDependencies() const { return AiChecksDependencies; } void set_AiChecksDependencies(bool v) { AiChecksDependencies = v; GameSettings.AiChecksDependencies = v; } - bool get_AllyDepositsAllowed() { return AllyDepositsAllowed; } + bool get_AllyDepositsAllowed() const { return AllyDepositsAllowed; } void set_AllyDepositsAllowed(bool v) { AllyDepositsAllowed = v; GameSettings.AllyDepositsAllowed = v; diff --git a/src/include/unitptr.h b/src/include/unitptr.h index 87323c1144..565309815f 100644 --- a/src/include/unitptr.h +++ b/src/include/unitptr.h @@ -41,7 +41,7 @@ class CUnit; class CUnitPtr { public: - CUnitPtr() : unit(nullptr) {} + CUnitPtr() = default; CUnitPtr(std::nullptr_t) : unit(nullptr) {} explicit CUnitPtr(CUnit *u); CUnitPtr(const CUnitPtr &u); @@ -61,7 +61,7 @@ class CUnitPtr bool operator!= (CUnit *u) const { return this->unit != u; } private: - CUnit *unit; + CUnit *unit = nullptr; }; //@} diff --git a/src/include/unittype.h b/src/include/unittype.h index 525df0074c..177b08ccb0 100644 --- a/src/include/unittype.h +++ b/src/include/unittype.h @@ -741,7 +741,7 @@ class CUnitTypeVar return lhs.key < rhs.key; } std::string_view key; - int offset; + int offset = 0; }; CKeys(): TotalKeys(SIZE) {} @@ -773,7 +773,7 @@ class CUnitTypeVar ** ** @return Index of the variable, -1 if not found. */ - int operator[](std::string_view key) + int operator[](std::string_view key) const { DataKey k; k.key = key; @@ -811,7 +811,7 @@ class CUnitTypeVar CVariableKeys(); }; - CUnitTypeVar() {} + CUnitTypeVar() = default; void Init(); void Clear(); diff --git a/src/include/upgrade_structs.h b/src/include/upgrade_structs.h index 1e94bb6365..7a579b5087 100644 --- a/src/include/upgrade_structs.h +++ b/src/include/upgrade_structs.h @@ -135,8 +135,6 @@ class CUpgrade static CUpgrade *New(std::string ident); static CUpgrade *Get(std::string_view ident); - void SetIcon(CIcon *icon); - std::string Ident; /// identifier std::string Name; /// upgrade label int ID = 0; /// numerical id diff --git a/src/include/vec2i.h b/src/include/vec2i.h index a6e26f29ed..e7c20abec9 100644 --- a/src/include/vec2i.h +++ b/src/include/vec2i.h @@ -36,11 +36,11 @@ template class Vec2T { public: - Vec2T() : x(0), y(0) {} + Vec2T() = default; Vec2T(T x, T y) : x(x), y(y) {} public: - T x; - T y; + T x{}; + T y{}; }; diff --git a/src/include/video.h b/src/include/video.h index 06fb38fdbc..2c0b1b5083 100644 --- a/src/include/video.h +++ b/src/include/video.h @@ -98,8 +98,8 @@ class CGraphic : public gcn::SDLImage { public: struct frame_pos_t { - short int x; - short int y; + short int x = 0; + short int y = 0; }; protected: @@ -208,9 +208,7 @@ class CGraphic : public gcn::SDLImage class CPlayerColorGraphic : public CGraphic { protected: - CPlayerColorGraphic() - { - } + CPlayerColorGraphic() = default; public: void DrawPlayerColorFrameClipX(int colorIndex, unsigned frame, int x, int y, @@ -307,24 +305,23 @@ class Mng : public gcn::Image struct EventCallback { /// Callback for mouse button press - void (*ButtonPressed)(unsigned buttons); + void (*ButtonPressed)(unsigned buttons) = nullptr; /// Callback for mouse button release - void (*ButtonReleased)(unsigned buttons); + void (*ButtonReleased)(unsigned buttons) = nullptr; /// Callback for mouse move - void (*MouseMoved)(const PixelPos &screenPos); + void (*MouseMoved)(const PixelPos &screenPos) = nullptr; /// Callback for mouse exit of game window - void (*MouseExit)(); + void (*MouseExit)() = nullptr; /// Callback for key press - void (*KeyPressed)(unsigned keycode, unsigned keychar); + void (*KeyPressed)(unsigned keycode, unsigned keychar) = nullptr; /// Callback for key release - void (*KeyReleased)(unsigned keycode, unsigned keychar); + void (*KeyReleased)(unsigned keycode, unsigned keychar) = nullptr; /// Callback for key repeated - void (*KeyRepeated)(unsigned keycode, unsigned keychar); + void (*KeyRepeated)(unsigned keycode, unsigned keychar) = nullptr; /// Callback for network event - void (*NetworkEvent)(); - + void (*NetworkEvent)() = nullptr; }; diff --git a/src/include/viewport.h b/src/include/viewport.h index c59de7fe9e..53cff52c1b 100644 --- a/src/include/viewport.h +++ b/src/include/viewport.h @@ -67,7 +67,7 @@ using fieldHighlightChecker = bool(*)(const CMapField&); // type alias class CViewport { public: - CViewport(); + CViewport() = default; ~CViewport(); /// Check if pos pixels are within map area @@ -158,10 +158,10 @@ class CViewport public: Vec2i MapPos; /// Map tile left-upper corner PixelDiff Offset; /// Offset within MapX, MapY - int MapWidth; /// Width in map tiles - int MapHeight; /// Height in map tiles + int MapWidth = 0; /// Width in map tiles + int MapHeight = 0; /// Height in map tiles - CUnit *Unit; /// Bound to this unit + CUnit *Unit = nullptr; /// Bound to this unit private: SDL_Surface *FogSurface { nullptr }; /// Texture for fog of war. Viewport sized. diff --git a/src/include/wav.h b/src/include/wav.h index e584d92a03..c502b53db6 100644 --- a/src/include/wav.h +++ b/src/include/wav.h @@ -68,29 +68,29 @@ ** General chunk found in the WAV file */ struct WavHeader { - unsigned int MagicRiff; - unsigned int Length; - unsigned int MagicWave; + unsigned int MagicRiff = 0; + unsigned int Length = 0; + unsigned int MagicWave = 0; }; /** ** Wav format */ struct WavFMT { - unsigned short Encoding; /// 1 = PCM - unsigned short Channels; /// 1 = mono, 2 = stereo - unsigned int Frequency; /// One of 11025, 22050, or 44100 Hz - unsigned int ByteRate; /// Average bytes per second - unsigned short SampleSize; /// Bytes per sample block - unsigned short BitsPerSample; /// One of 8, 12, 16 + unsigned short Encoding = 0; /// 1 = PCM + unsigned short Channels = 0; /// 1 = mono, 2 = stereo + unsigned int Frequency = 0; /// One of 11025, 22050, or 44100 Hz + unsigned int ByteRate = 0; /// Average bytes per second + unsigned short SampleSize = 0; /// Bytes per sample block + unsigned short BitsPerSample = 0; /// One of 8, 12, 16 }; /** ** General chunk found in the WAV file */ struct WavChunk { - unsigned int Magic; - unsigned int Length; + unsigned int Magic = 0; + unsigned int Length = 0; }; //@} diff --git a/src/include/widgets.h b/src/include/widgets.h index f4c166e1c7..6ae210561f 100644 --- a/src/include/widgets.h +++ b/src/include/widgets.h @@ -115,15 +115,15 @@ class CImageButton : public gcn::Button void setPressedImage(gcn::Image *image) { pressedImage = image; } void setDisabledImage(gcn::Image *image) { disabledImage = image; } - gcn::Image *normalImage; - gcn::Image *pressedImage; - gcn::Image *disabledImage; + gcn::Image *normalImage = nullptr; + gcn::Image *pressedImage = nullptr; + gcn::Image *disabledImage = nullptr; }; class ImageRadioButton : public gcn::RadioButton { public: - ImageRadioButton(); + ImageRadioButton() = default; ImageRadioButton(const std::string &caption, const std::string &group, bool marked); @@ -142,19 +142,19 @@ class ImageRadioButton : public gcn::RadioButton void setCheckedPressedImage(gcn::Image *image) { checkedPressedImage = image; } void setCheckedDisabledImage(gcn::Image *image) { checkedDisabledImage = image; } - gcn::Image *uncheckedNormalImage; - gcn::Image *uncheckedPressedImage; - gcn::Image *uncheckedDisabledImage; - gcn::Image *checkedNormalImage; - gcn::Image *checkedPressedImage; - gcn::Image *checkedDisabledImage; - bool mMouseDown; + gcn::Image *uncheckedNormalImage = nullptr; + gcn::Image *uncheckedPressedImage = nullptr; + gcn::Image *uncheckedDisabledImage = nullptr; + gcn::Image *checkedNormalImage = nullptr; + gcn::Image *checkedPressedImage = nullptr; + gcn::Image *checkedDisabledImage = nullptr; + bool mMouseDown = false; }; class ImageCheckBox : public gcn::CheckBox { public: - ImageCheckBox(); + ImageCheckBox() = default; ImageCheckBox(const std::string &caption, bool marked = false); void draw(gcn::Graphics *graphics) override; @@ -172,13 +172,13 @@ class ImageCheckBox : public gcn::CheckBox void setCheckedPressedImage(gcn::Image *image) { checkedPressedImage = image; } void setCheckedDisabledImage(gcn::Image *image) { checkedDisabledImage = image; } - gcn::Image *uncheckedNormalImage; - gcn::Image *uncheckedPressedImage; - gcn::Image *uncheckedDisabledImage; - gcn::Image *checkedNormalImage; - gcn::Image *checkedPressedImage; - gcn::Image *checkedDisabledImage; - bool mMouseDown; + gcn::Image *uncheckedNormalImage = nullptr; + gcn::Image *uncheckedPressedImage = nullptr; + gcn::Image *uncheckedDisabledImage = nullptr; + gcn::Image *checkedNormalImage = nullptr; + gcn::Image *checkedPressedImage = nullptr; + gcn::Image *checkedDisabledImage = nullptr; + bool mMouseDown = false; }; class ImageSlider : public gcn::Slider @@ -194,26 +194,26 @@ class ImageSlider : public gcn::Slider void setBackgroundImage(gcn::Image *image); void setDisabledBackgroundImage(gcn::Image *image); - gcn::Image *markerImage; - gcn::Image *backgroundImage; - gcn::Image *disabledBackgroundImage; + gcn::Image *markerImage = nullptr; + gcn::Image *backgroundImage = nullptr; + gcn::Image *disabledBackgroundImage = nullptr; }; class MultiLineLabel : public gcn::Widget { public: - MultiLineLabel(); + MultiLineLabel() = default; explicit MultiLineLabel(const std::string &caption); void setCaption(const std::string &caption); const std::string &getCaption() const; void setAlignment(gcn::Graphics::Alignment alignment); void setAlignment(unsigned int alignment) { setAlignment(static_cast(alignment)); } // TOLUA - gcn::Graphics::Alignment getAlignment(); + gcn::Graphics::Alignment getAlignment() const; void setVerticalAlignment(unsigned int alignment); - unsigned int getVerticalAlignment(); + unsigned int getVerticalAlignment() const; void setLineWidth(int width); - int getLineWidth(); + int getLineWidth() const; void adjustSize(); void draw(gcn::Graphics *graphics) override; void drawFrame(gcn::Graphics *graphics) override; @@ -231,9 +231,9 @@ class MultiLineLabel : public gcn::Widget std::string mCaption; std::vector mTextRows; - gcn::Graphics::Alignment mAlignment; - unsigned int mVerticalAlignment; - int mLineWidth; + gcn::Graphics::Alignment mAlignment = gcn::Graphics::Alignment::Left; + unsigned int mVerticalAlignment = TOP; + int mLineWidth = 0; }; class ScrollingWidget : public gcn::ScrollArea @@ -249,8 +249,8 @@ class ScrollingWidget : public gcn::ScrollArea private: gcn::Container container; /// Data container float speedY; /// vertical speed of the container (positive number: go up). - float containerY; /// Y position of the container - bool finished; /// True while scrolling ends. + float containerY = 0; /// Y position of the container + bool finished = false; /// True while scrolling ends. }; class Windows : public gcn::Window @@ -311,13 +311,13 @@ class CTextField : public gcn::TextField class ImageTextField : public CTextField { public: - ImageTextField() : CTextField(), itemImage(nullptr) {} - ImageTextField(const std::string &text) : CTextField(text), itemImage(nullptr) {} + ImageTextField() = default; + ImageTextField(const std::string &text) : CTextField(text) {} void draw(gcn::Graphics *graphics) override; void drawFrame(gcn::Graphics *graphics) override; void setItemImage(CGraphic *image) { itemImage = image; } private: - CGraphic *itemImage; + CGraphic *itemImage = nullptr; }; class StringListModel : public gcn::ListModel @@ -335,7 +335,7 @@ class LuaListModel : public gcn::ListModel { std::vector list; public: - LuaListModel() {} + LuaListModel() = default; void setList(lua_State *lua, lua_Object *lo); int getNumberOfElements() override { return list.size(); } @@ -346,7 +346,7 @@ class LuaListModel : public gcn::ListModel class ImageListBox : public gcn::ListBox { public: - ImageListBox(); + ImageListBox() = default; explicit ImageListBox(gcn::ListModel *listModel); void draw(gcn::Graphics *graphics) override; void drawFrame(gcn::Graphics *graphics) override; @@ -534,11 +534,11 @@ class MenuScreen : public gcn::Container bool getDrawMenusUnder() const { return this->drawUnder; } private: - bool runLoop; - int loopResult; - gcn::Widget *oldtop; - LuaActionListener *logiclistener; - bool drawUnder; + bool runLoop = true; + int loopResult = 0; + gcn::Widget *oldtop = nullptr; + LuaActionListener *logiclistener = nullptr; + bool drawUnder = false; }; #endif diff --git a/src/map/map_draw.cpp b/src/map/map_draw.cpp index e1506505c2..0d2d8bdbaf 100644 --- a/src/map/map_draw.cpp +++ b/src/map/map_draw.cpp @@ -52,15 +52,6 @@ bool CViewport::ShowGrid = false; bool CViewport::ShowAStarPassability = false; - -CViewport::CViewport() : MapWidth(0), MapHeight(0), Unit(nullptr) -{ - this->TopLeftPos.x = this->TopLeftPos.y = 0; - this->BottomRightPos.x = this->BottomRightPos.y = 0; - this->MapPos.x = this->MapPos.y = 0; - this->Offset.x = this->Offset.y = 0; -} - CViewport::~CViewport() { this->Clean(); diff --git a/src/network/net_message.cpp b/src/network/net_message.cpp index a9a46d4f28..ecd0c6c4c3 100644 --- a/src/network/net_message.cpp +++ b/src/network/net_message.cpp @@ -467,9 +467,9 @@ void CInitMessage_EngineMismatch::Deserialize(const unsigned char *p) // CInitMessage_LuaFilesMismatch::CInitMessage_LuaFilesMismatch() : - header(MessageInit_FromServer, ICMLuaFilesMismatch) + header(MessageInit_FromServer, ICMLuaFilesMismatch), + Version(FileChecksums) { - this->Version = FileChecksums; } std::vector CInitMessage_LuaFilesMismatch::Serialize() const @@ -493,10 +493,10 @@ void CInitMessage_LuaFilesMismatch::Deserialize(const unsigned char *p) // CInitMessage_Welcome::CInitMessage_Welcome() : - header(MessageInit_FromServer, ICMWelcome) + header(MessageInit_FromServer, ICMWelcome), + Lag(CNetworkParameter::Instance.NetworkLag), + gameCyclesPerUpdate(CNetworkParameter::Instance.gameCyclesPerUpdate) { - this->Lag = CNetworkParameter::Instance.NetworkLag; - this->gameCyclesPerUpdate = CNetworkParameter::Instance.gameCyclesPerUpdate; } std::vector CInitMessage_Welcome::Serialize() const diff --git a/src/particle/graphicanimation.cpp b/src/particle/graphicanimation.cpp index 7e83fc8575..6669fb1eef 100644 --- a/src/particle/graphicanimation.cpp +++ b/src/particle/graphicanimation.cpp @@ -39,7 +39,7 @@ #include "video.h" GraphicAnimation::GraphicAnimation(CGraphic *g, int ticksPerFrame) : - g(g), ticksPerFrame(ticksPerFrame), currentFrame(0), currTicks(0) + g(g), ticksPerFrame(ticksPerFrame) { Assert(g); } diff --git a/src/pathfinder/pathfinder.cpp b/src/pathfinder/pathfinder.cpp index b19dad8c49..dcb331fbe8 100644 --- a/src/pathfinder/pathfinder.cpp +++ b/src/pathfinder/pathfinder.cpp @@ -306,17 +306,6 @@ int CalcPathLengthToUnit(const CUnit &src, const CUnit &dst, const int minrange, -- REAL PATH-FINDER ----------------------------------------------------------------------------*/ -PathFinderInput::PathFinderInput() : unit(nullptr), minRange(0), maxRange(0), - isRecalculatePathNeeded(true) -{ - unitSize.x = 0; - unitSize.y = 0; - goalPos.x = -1; - goalPos.y = -1; - goalSize.x = 0; - goalSize.y = 0; -} - const Vec2i &PathFinderInput::GetUnitPos() const { return unit->tilePos; } Vec2i PathFinderInput::GetUnitSize() const { diff --git a/src/ui/icons.cpp b/src/ui/icons.cpp index 3e3a73d913..da0653e0f1 100644 --- a/src/ui/icons.cpp +++ b/src/ui/icons.cpp @@ -62,9 +62,8 @@ static IconMap Icons; /// Map of ident to icon. /** ** CIcon constructor */ -CIcon::CIcon(const std::string &ident) : G(nullptr), GScale(nullptr), Frame(0), Ident(ident) +CIcon::CIcon(const std::string &ident) : Ident(ident) { - this->PaletteSwaps.clear(); } /** diff --git a/src/ui/widgets.cpp b/src/ui/widgets.cpp index afb8f6c6ee..62eb006656 100644 --- a/src/ui/widgets.cpp +++ b/src/ui/widgets.cpp @@ -354,9 +354,7 @@ LuaActionListener::~LuaActionListener() /** ** ImageButton constructor */ -CImageButton::CImageButton() : - Button(), normalImage(nullptr), pressedImage(nullptr), - disabledImage(nullptr) +CImageButton::CImageButton() : Button() { setForegroundColor(0xffffff); } @@ -366,9 +364,7 @@ CImageButton::CImageButton() : ** ** @param caption Caption text */ -CImageButton::CImageButton(const std::string &caption) : - Button(caption), normalImage(nullptr), pressedImage(nullptr), - disabledImage(nullptr) +CImageButton::CImageButton(const std::string &caption) : Button(caption) { setForegroundColor(0xffffff); } @@ -465,26 +461,12 @@ void CImageButton::adjustSize() -- ImageRadioButton ----------------------------------------------------------------------------*/ - -/** -** ImageRadioButton constructor -*/ -ImageRadioButton::ImageRadioButton() : gcn::RadioButton(), - uncheckedNormalImage(nullptr), uncheckedPressedImage(nullptr), uncheckedDisabledImage(nullptr), - checkedNormalImage(nullptr), checkedPressedImage(nullptr), checkedDisabledImage(nullptr), - mMouseDown(false) -{ -} - /** ** ImageRadioButton constructor */ ImageRadioButton::ImageRadioButton(const std::string &caption, const std::string &group, bool marked) : - gcn::RadioButton(caption, group, marked), - uncheckedNormalImage(nullptr), uncheckedPressedImage(nullptr), uncheckedDisabledImage(nullptr), - checkedNormalImage(nullptr), checkedPressedImage(nullptr), checkedDisabledImage(nullptr), - mMouseDown(false) + gcn::RadioButton(caption, group, marked) { } @@ -607,27 +589,12 @@ void ImageRadioButton::adjustSize() -- ImageCheckbox ----------------------------------------------------------------------------*/ - -/** -** Image checkbox constructor -*/ -ImageCheckBox::ImageCheckBox() : gcn::CheckBox(), - uncheckedNormalImage(nullptr), uncheckedPressedImage(nullptr), uncheckedDisabledImage(nullptr), - checkedNormalImage(nullptr), checkedPressedImage(nullptr), checkedDisabledImage(nullptr), - mMouseDown(false) -{ -} - /** ** Image checkbox constructor */ ImageCheckBox::ImageCheckBox(const std::string &caption, bool marked) : - gcn::CheckBox(caption, marked), - uncheckedNormalImage(nullptr), uncheckedPressedImage(nullptr), uncheckedDisabledImage(nullptr), - checkedNormalImage(nullptr), checkedPressedImage(nullptr), checkedDisabledImage(nullptr), - mMouseDown(false) -{ -} + gcn::CheckBox(caption, marked) +{} /** ** Draw the image checkbox @@ -750,18 +717,14 @@ void ImageCheckBox::adjustSize() /** ** Image slider constructor */ -ImageSlider::ImageSlider(double scaleEnd) : - Slider(scaleEnd), markerImage(nullptr), backgroundImage(nullptr), disabledBackgroundImage(nullptr) -{ -} +ImageSlider::ImageSlider(double scaleEnd) : Slider(scaleEnd) +{} /** ** Image slider constructor */ -ImageSlider::ImageSlider(double scaleStart, double scaleEnd) : - Slider(scaleStart, scaleEnd), markerImage(nullptr), backgroundImage(nullptr), disabledBackgroundImage(nullptr) -{ -} +ImageSlider::ImageSlider(double scaleStart, double scaleEnd) : Slider(scaleStart, scaleEnd) +{} /** ** Draw the image slider marker @@ -840,25 +803,12 @@ void ImageSlider::setDisabledBackgroundImage(gcn::Image *image) -- MultiLineLabel ----------------------------------------------------------------------------*/ - -/** -** MultiLineLabel constructor -*/ -MultiLineLabel::MultiLineLabel() -{ - this->mAlignment = gcn::Graphics::Alignment::Left; - this->mVerticalAlignment = TOP; - this->mLineWidth = 0; -} - /** ** MultiLineLabel constructor */ MultiLineLabel::MultiLineLabel(const std::string &caption) { this->mCaption = caption; - this->mAlignment = gcn::Graphics::Alignment::Left; - this->mVerticalAlignment = TOP; this->mLineWidth = 999999; this->wordWrap(); @@ -893,7 +843,7 @@ void MultiLineLabel::setAlignment(gcn::Graphics::Alignment alignment) /** ** Get the horizontal alignment */ -gcn::Graphics::Alignment MultiLineLabel::getAlignment() +gcn::Graphics::Alignment MultiLineLabel::getAlignment() const { return this->mAlignment; } @@ -909,7 +859,7 @@ void MultiLineLabel::setVerticalAlignment(unsigned int alignment) /** ** Get the vertical alignment */ -unsigned int MultiLineLabel::getVerticalAlignment() +unsigned int MultiLineLabel::getVerticalAlignment() const { return this->mVerticalAlignment; } @@ -926,7 +876,7 @@ void MultiLineLabel::setLineWidth(int width) /** ** Get the line width */ -int MultiLineLabel::getLineWidth() +int MultiLineLabel::getLineWidth() const { return this->mLineWidth; } @@ -1117,7 +1067,7 @@ void MultiLineLabel::wordWrap() */ ScrollingWidget::ScrollingWidget(int width, int height) : gcn::ScrollArea(nullptr, gcn::ScrollArea::ScrollPolicy::ShowNever, gcn::ScrollArea::ScrollPolicy::ShowNever), - speedY(1.f), containerY(0.f), finished(false) + speedY(1.f) { container.setDimension(gcn::Rectangle(0, 0, width, height)); container.setOpaque(false); @@ -1727,11 +1677,7 @@ int LuaListModel::getIdxOfElement(std::string_view element) -- ImageListBox ----------------------------------------------------------------------------*/ -ImageListBox::ImageListBox() : gcn::ListBox(), itemImage(nullptr) -{ -} - -ImageListBox::ImageListBox(gcn::ListModel *listModel) : gcn::ListBox(listModel), itemImage(nullptr) +ImageListBox::ImageListBox(gcn::ListModel *listModel) : gcn::ListBox(listModel) { } @@ -1887,9 +1833,7 @@ ListBoxWidget::ListBoxWidget(unsigned int width, unsigned int height) ** ** @todo Size should be parametrable, maybe remove default constructor? */ -ImageListBoxWidget::ImageListBoxWidget(unsigned int width, unsigned int height) : ListBoxWidget(width, height), - upButtonImage(nullptr), downButtonImage(nullptr), leftButtonImage(nullptr), rightButtonImage(nullptr), hBarButtonImage(nullptr), - vBarButtonImage(nullptr), markerImage(nullptr) +ImageListBoxWidget::ImageListBoxWidget(unsigned int width, unsigned int height) : ListBoxWidget(width, height) { setDimension(gcn::Rectangle(0, 0, width, height)); setContent(&listbox); @@ -2699,8 +2643,7 @@ int StatBoxWidget::getPercent() const /** ** MenuScreen constructor */ -MenuScreen::MenuScreen() : - Container(), runLoop(true), logiclistener(nullptr), drawUnder(false) +MenuScreen::MenuScreen() : Container(), runLoop(true) { setDimension(gcn::Rectangle(0, 0, Video.Width, Video.Height)); setOpaque(false);