Skip to content

Commit

Permalink
Merge pull request #674 from Wargus/cleanup
Browse files Browse the repository at this point in the history
Cleanup
  • Loading branch information
Jarod42 committed May 11, 2024
2 parents 9dfb6ab + d4424ef commit 2dd280b
Show file tree
Hide file tree
Showing 39 changed files with 386 additions and 488 deletions.
2 changes: 1 addition & 1 deletion src/editor/editloop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,7 @@ static void DrawStartLocations()
LoadUnitTypeSprite(*const_cast<CUnitType *>(type));
}
#endif
DrawUnitType(*type, type->Sprite, i, 0, startScreenPos);
DrawUnitType(*type, type->Sprite.get(), i, 0, startScreenPos);
} else { // Draw a cross
DrawCross(startScreenPos, Map.Tileset->getPixelTileSize(), Players[i].Color);
}
Expand Down
8 changes: 5 additions & 3 deletions src/include/construct.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@
-- Declarations
----------------------------------------------------------------------------*/

#include <memory>

class CGraphic;
class CPlayerColorGraphic;

Expand All @@ -124,7 +126,7 @@ class CConstruction
{
public:
CConstruction() = default;
~CConstruction();
~CConstruction() = default;
void Clean();
void Load(bool force = false);

Expand All @@ -139,10 +141,10 @@ class CConstruction

// --- FILLED UP ---

CPlayerColorGraphic *Sprite = nullptr;/// construction sprite image
std::shared_ptr<CPlayerColorGraphic> Sprite;/// construction sprite image
int Width = 0; /// sprite width
int Height = 0; /// sprite height
CGraphic *ShadowSprite = nullptr; /// construction shadow sprite image
std::shared_ptr<CGraphic> ShadowSprite; /// construction shadow sprite image
int ShadowWidth = 0; /// shadow sprite width
int ShadowHeight = 0; /// shadow sprite height
};
Expand Down
2 changes: 1 addition & 1 deletion src/include/cursor.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class CCursor

// --- FILLED UP ---

CGraphic *G = nullptr; /// Cursor sprite image
std::shared_ptr<CGraphic> G; /// Cursor sprite image

private:
std::vector<sdl2::CursorPtr> SdlCursors;
Expand Down
8 changes: 4 additions & 4 deletions src/include/font.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ class CFont : public gcn::Font
explicit CFont(std::string ident) : Ident(std::move(ident)) {}

public:
~CFont() override;
~CFont() override = default;

static CFont *New(const std::string &ident, CGraphic *g);
static CFont *New(const std::string &ident, std::shared_ptr<CGraphic> g);
static CFont *Get(std::string_view ident);

int Height() const;
Expand All @@ -100,7 +100,7 @@ class CFont : public gcn::Font

void Load();

CGraphic *GetGraphic() const;
std::shared_ptr<CGraphic> GetGraphic() const;

template<bool CLIP>
unsigned int DrawChar(CGraphic &g, int utf8, int x, int y, const CFontColor &fc) const;
Expand All @@ -113,7 +113,7 @@ class CFont : public gcn::Font
private:
std::string Ident; /// Ident of the font.
std::vector<char> CharWidth; /// Real font width (starting with ' ')
CGraphic *G = nullptr; /// Graphic object used to draw
std::shared_ptr<CGraphic> G; /// Graphic object used to draw
bool is_normal = true;
};

Expand Down
4 changes: 2 additions & 2 deletions src/include/fow.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ class CFogOfWar
/// ThisPlayer and his allies in normal games
/// Any set of players for observers and in the replays

static CGraphic *TiledFogSrc; /// Graphic for tiled fog of war
CGraphic *TiledAlphaFog {nullptr}; /// Working set of graphic for tiled fog of war with alpha channel
static std::shared_ptr<CGraphic> TiledFogSrc; /// Graphic for tiled fog of war
std::shared_ptr<CGraphic> TiledAlphaFog; /// Working set of graphic for tiled fog of war with alpha channel
SDL_Surface *TileOfFogOnly {nullptr}; /// Tile contains only fog. Used for legacy rendering of tiled fog

/**
Expand Down
22 changes: 12 additions & 10 deletions src/include/icons.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@

//@{

#include "vec2i.h"
#include "color.h"
#include "vec2i.h"

#include <memory>
#include <string>

/*----------------------------------------------------------------------------
Expand Down Expand Up @@ -110,7 +112,7 @@ class CIcon
{
public:
explicit CIcon(const std::string &ident);
~CIcon();
~CIcon() = default;

static CIcon *New(const std::string &ident);
static CIcon *Get(std::string_view ident);
Expand All @@ -137,15 +139,15 @@ class CIcon

/// Modify the extra icon graphics
void ClearExtraGraphics();
void AddSingleSelectionGraphic(CPlayerColorGraphic *g);
void AddGroupSelectionGraphic(CPlayerColorGraphic *g);
void AddContainedGraphic(CPlayerColorGraphic *g);
void AddSingleSelectionGraphic(std::shared_ptr<CPlayerColorGraphic> g);
void AddGroupSelectionGraphic(std::shared_ptr<CPlayerColorGraphic> g);
void AddContainedGraphic(std::shared_ptr<CPlayerColorGraphic> g);

void SetPaletteSwaps(std::vector<PaletteSwap> &newSwaps);

public:
CPlayerColorGraphic *G = nullptr; /// Graphic data
CPlayerColorGraphic *GScale = nullptr; /// Icon when drawn grayscaled
std::shared_ptr<CPlayerColorGraphic> G; /// Graphic data
std::shared_ptr<CPlayerColorGraphic> GScale; /// Icon when drawn grayscaled
int Frame = 0; /// Frame number in graphic
private:
std::string Ident; /// Icon identifier
Expand All @@ -157,9 +159,9 @@ class CIcon
* way, units can have different (damaged) icons. all of these are optional, the default is to just use
* the graphic stored in the *G field above.
*/
std::vector<CPlayerColorGraphic *> SingleSelectionG; /// graphics by health status for single-selection
std::vector<CPlayerColorGraphic *> GroupSelectionG; /// graphics by health status for multi-selection
std::vector<CPlayerColorGraphic *> ContainedG; /// graphics by health status when in a container
std::vector<std::shared_ptr<CPlayerColorGraphic>> SingleSelectionG; /// graphics by health status for single-selection
std::vector<std::shared_ptr<CPlayerColorGraphic>> GroupSelectionG; /// graphics by health status for multi-selection
std::vector<std::shared_ptr<CPlayerColorGraphic>> ContainedG; /// graphics by health status when in a container

/*
* These following lists are used to map percentages of arbitrary unit variables (e.g. health, shield,
Expand Down
2 changes: 1 addition & 1 deletion src/include/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ class CMap

CTileset *Tileset = nullptr; /// tileset data
fs::path TileModelsFileName; /// lua filename that loads all tilemodels
CGraphic *TileGraphic = nullptr; /// graphic for all the tiles
std::shared_ptr<CGraphic> TileGraphic; /// graphic for all the tiles
bool isMapInitialized = false ;

CMapInfo Info; /// descriptive information
Expand Down
4 changes: 2 additions & 2 deletions src/include/missile.h
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ class MissileType
{
public:
explicit MissileType(const std::string &ident) : Ident(ident) {}
~MissileType();
~MissileType() = default;

/// load the graphics for a missile type
void LoadMissileSprite();
Expand Down Expand Up @@ -405,7 +405,7 @@ class MissileType
mutable LuaCallback<void(int attackerSlot, int targetSlot, int damage)> OnImpact; /// called when

// --- FILLED UP ---
CGraphic *G = nullptr; /// missile graphic
std::shared_ptr<CGraphic> G; /// missile graphic
};

/*----------------------------------------------------------------------------
Expand Down
22 changes: 11 additions & 11 deletions src/include/tileset.h
Original file line number Diff line number Diff line change
Expand Up @@ -337,10 +337,15 @@ GenerateExtendedTileset(
class CTilesetGraphicGenerator
{
public:
CTilesetGraphicGenerator(lua_State *luaStack, int tablePos, int argPos, const CTileset *srcTileset,
const CGraphic *srcGraphic,
const CGraphic *srcImgGraphic)
: SrcTileset(srcTileset), SrcTilesetGraphic(srcGraphic), SrcImgGraphic (srcImgGraphic)
CTilesetGraphicGenerator(lua_State *luaStack,
int tablePos,
int argPos,
const CTileset *srcTileset,
const CGraphic *srcGraphic,
const CGraphic *srcImgGraphic) :
SrcTileset(srcTileset),
SrcTilesetGraphic(srcGraphic),
SrcImgGraphic(srcImgGraphic)
{
lua_rawgeti(luaStack, tablePos, argPos);
parseExtended(luaStack);
Expand Down Expand Up @@ -428,12 +433,7 @@ class CTilesetParser
}
/// TODO: add constructor to parse base tileset (if we decide to move base tileset parser here)

~CTilesetParser()
{
if (SrcImgGraphic) {
CGraphic::Free(SrcImgGraphic);
}
}
~CTilesetParser() = default;
const std::map<tile_index, CTile> &getTiles() const { return ExtTiles; }
const sequence_of_images& getGraphic() const { return ExtGraphic; }

Expand All @@ -448,7 +448,7 @@ class CTilesetParser
private:
CTileset *BaseTileset{nullptr};
const CGraphic *BaseGraphic{nullptr};
CGraphic *SrcImgGraphic{nullptr};
std::shared_ptr<CGraphic> SrcImgGraphic;

sequence_of_images ExtGraphic;
std::map<tile_index, CTile> ExtTiles;
Expand Down
16 changes: 8 additions & 8 deletions src/include/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class ButtonStyleProperties
public:
ButtonStyleProperties() = default;

CGraphic *Sprite = nullptr;
std::shared_ptr<CGraphic> Sprite;
int Frame = 0;
CColor BorderColorRGB;
IntColor BorderColor = 0;
Expand Down Expand Up @@ -252,7 +252,7 @@ class CFiller
}
return false;
}
CGraphic *G = nullptr; /// Graphic
std::shared_ptr<CGraphic> G; /// Graphic
int X = 0; /// X coordinate
int Y = 0; /// Y coordinate
};
Expand Down Expand Up @@ -289,7 +289,7 @@ class CButtonPanel


public:
CGraphic *G = nullptr;
std::shared_ptr<CGraphic> G;
int X = 0;
int Y = 0;
std::vector<CUIButton> Buttons;
Expand All @@ -302,7 +302,7 @@ class CPieMenu
public:
CPieMenu() = default;

CGraphic *G = nullptr; /// Optional background image
std::shared_ptr<CGraphic> G; /// Optional background image
int MouseButton = NoButton; /// Which mouse button pops up the piemenu, deactivate with NoButton
int X[9]{}; /// X position of the pies
int Y[9]{}; /// Y position of the pies
Expand All @@ -323,7 +323,7 @@ class CResourceInfo
public:
CResourceInfo() = default;

CGraphic *G = nullptr; /// icon graphic
std::shared_ptr<CGraphic> G; /// icon graphic
int IconFrame = 0; /// icon frame
int IconX = 0; /// icon X position
int IconY = 0; /// icon Y position
Expand All @@ -340,7 +340,7 @@ class CInfoPanel

void Draw();

CGraphic *G = nullptr;
std::shared_ptr<CGraphic> G;
int X = 0;
int Y = 0;
};
Expand Down Expand Up @@ -497,8 +497,8 @@ class CUserInterface
/// SoundConfig PlacementSuccess; /// played on placements success
/// SoundConfig Click; /// click noice used often

CGraphic *VictoryBackgroundG = nullptr; /// Victory background graphic
CGraphic *DefeatBackgroundG = nullptr; /// Defeat background graphic
std::shared_ptr<CGraphic> VictoryBackgroundG; /// Victory background graphic
std::shared_ptr<CGraphic> DefeatBackgroundG; /// Defeat background graphic
};

extern std::vector<ButtonAction> CurrentButtons; /// Current Selected Buttons
Expand Down
4 changes: 2 additions & 2 deletions src/include/unit.h
Original file line number Diff line number Diff line change
Expand Up @@ -472,8 +472,8 @@ class CPreference
int ShowNameDelay = 0; /// How many cycles need to wait until unit's name popup will appear.
int ShowNameTime = 0; /// How many cycles need to show unit's name popup.
int AutosaveMinutes = 5; /// Autosave the game every X minutes; autosave is disabled if the value is 0
CGraphic *IconFrameG = nullptr;
CGraphic *PressedIconFrameG = nullptr;
std::shared_ptr<CGraphic> IconFrameG;
std::shared_ptr<CGraphic> PressedIconFrameG;

// these are "preferences" in the sense that the user wants to set these
// persistently across launches for single player games. However, they are
Expand Down
10 changes: 5 additions & 5 deletions src/include/unittype.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ class ResourceInfo
bool HarvestFromOutside = false; /// Unit harvests without entering the building.
bool RefineryHarvester = false; /// Unit have to build Refinery buildings for harvesting.
// Runtime info:
CPlayerColorGraphic *SpriteWhenLoaded = nullptr; /// The graphic corresponding to FileWhenLoaded.
CPlayerColorGraphic *SpriteWhenEmpty = nullptr; /// The graphic corresponding to FileWhenEmpty
std::shared_ptr<CPlayerColorGraphic> SpriteWhenLoaded; /// The graphic corresponding to FileWhenLoaded.
std::shared_ptr<CPlayerColorGraphic> SpriteWhenEmpty; /// The graphic corresponding to FileWhenEmpty
};

/**
Expand Down Expand Up @@ -711,9 +711,9 @@ class CUnitType
/// @todo This stats should? be moved into the player struct
CUnitStats Stats[PlayerMax]; /// Unit status for each player

CPlayerColorGraphic *Sprite = nullptr; /// Sprite images
CPlayerColorGraphic *AltSprite = nullptr; /// Alternative sprite images
CGraphic *ShadowSprite = nullptr; /// Shadow sprite image
std::shared_ptr<CPlayerColorGraphic> Sprite; /// Sprite images
std::shared_ptr<CPlayerColorGraphic> AltSprite; /// Alternative sprite images
std::shared_ptr<CGraphic> ShadowSprite; /// Shadow sprite image
};

/*----------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit 2dd280b

Please sign in to comment.