Browse Source

Add OptionalOwnedCelSprite

pull/4858/merge
Gleb Mazovetskiy 4 years ago
parent
commit
d152d2c0fb
  1. 10
      Source/control.cpp
  2. 2
      Source/control.h
  3. 2
      Source/controls/modifier_hints.cpp
  4. 4
      Source/cursor.cpp
  5. 2
      Source/debug.cpp
  6. 2
      Source/debug.h
  7. 2
      Source/doom.cpp
  8. 79
      Source/engine/cel_sprite.hpp
  9. 2
      Source/engine/render/text_render.cpp
  10. 2
      Source/engine/render/text_render.hpp
  11. 8
      Source/gmenu.cpp
  12. 2
      Source/interfac.cpp
  13. 2
      Source/inv.cpp
  14. 2
      Source/items.cpp
  15. 2
      Source/levels/gendung.cpp
  16. 2
      Source/levels/gendung.h
  17. 2
      Source/minitext.cpp
  18. 2
      Source/panels/charpanel.cpp
  19. 2
      Source/panels/charpanel.hpp
  20. 4
      Source/panels/info_box.cpp
  21. 4
      Source/panels/info_box.hpp
  22. 6
      Source/panels/spell_book.cpp
  23. 2
      Source/panels/spell_icons.cpp
  24. 2
      Source/quests.cpp
  25. 2
      Source/quests.h

10
Source/control.cpp

@ -85,7 +85,7 @@ Rectangle MainPanel;
Rectangle LeftPanel;
Rectangle RightPanel;
std::optional<OwnedSurface> pBtmBuff;
std::optional<OwnedCelSprite> pGBoxBuff;
OptionalOwnedCelSprite pGBoxBuff;
const Rectangle &GetMainPanel()
{
@ -135,10 +135,10 @@ namespace {
std::optional<OwnedSurface> pLifeBuff;
std::optional<OwnedSurface> pManaBuff;
std::optional<OwnedCelSprite> talkButtons;
std::optional<OwnedCelSprite> pDurIcons;
std::optional<OwnedCelSprite> multiButtons;
std::optional<OwnedCelSprite> pPanelButtons;
OptionalOwnedCelSprite talkButtons;
OptionalOwnedCelSprite pDurIcons;
OptionalOwnedCelSprite multiButtons;
OptionalOwnedCelSprite pPanelButtons;
bool PanelButtons[8];
int PanelButtonIndex;

2
Source/control.h

@ -52,7 +52,7 @@ const Rectangle &GetRightPanel();
bool IsLeftPanelOpen();
bool IsRightPanelOpen();
extern std::optional<OwnedSurface> pBtmBuff;
extern std::optional<OwnedCelSprite> pGBoxBuff;
extern OptionalOwnedCelSprite pGBoxBuff;
extern SDL_Rect PanBtnPos[8];
void CalculatePanelAreas();

2
Source/controls/modifier_hints.cpp

@ -16,7 +16,7 @@
namespace devilution {
extern std::optional<OwnedCelSprite> pSBkIconCels;
extern OptionalOwnedCelSprite pSBkIconCels;
namespace {

4
Source/cursor.cpp

@ -31,8 +31,8 @@
namespace devilution {
namespace {
/** Cursor images CEL */
std::optional<OwnedCelSprite> pCursCels;
std::optional<OwnedCelSprite> pCursCels2;
OptionalOwnedCelSprite pCursCels;
OptionalOwnedCelSprite pCursCels2;
/** Maps from objcurs.cel frame number to frame width. */
const uint16_t InvItemWidth1[] = {

2
Source/debug.cpp

@ -35,7 +35,7 @@
namespace devilution {
std::string TestMapPath;
std::optional<OwnedCelSprite> pSquareCel;
OptionalOwnedCelSprite pSquareCel;
bool DebugToggle = false;
bool DebugGodMode = false;
bool DebugVision = false;

2
Source/debug.h

@ -15,7 +15,7 @@
namespace devilution {
extern std::string TestMapPath;
extern std::optional<OwnedCelSprite> pSquareCel;
extern OptionalOwnedCelSprite pSquareCel;
extern bool DebugToggle;
extern bool DebugGodMode;
extern bool DebugVision;

2
Source/doom.cpp

@ -14,7 +14,7 @@
namespace devilution {
namespace {
std::optional<OwnedCelSprite> DoomCel;
OptionalOwnedCelSprite DoomCel;
} // namespace
bool DoomFlag;

79
Source/engine/cel_sprite.hpp

@ -142,6 +142,8 @@ private:
CelSprite sprite_;
};
class OptionalOwnedCelSprite;
/**
* Stores a CEL or CL2 sprite and its width(s).
* Owns the data.
@ -169,10 +171,87 @@ public:
}
private:
// for OptionalOwnedCelSprite.
OwnedCelSprite()
: data_(nullptr)
, width_(nullptr)
{
}
std::unique_ptr<byte[]> data_;
PointerOrValue<uint16_t> width_;
friend class CelSprite;
friend class OptionalOwnedCelSprite;
};
/**
* @brief Equivalent to `std::optional<OwnedCelSprite>` but smaller.
*/
class OptionalOwnedCelSprite {
public:
OptionalOwnedCelSprite() = default;
OptionalOwnedCelSprite(OwnedCelSprite &&sprite)
: sprite_(std::move(sprite))
{
}
OptionalOwnedCelSprite(std::nullopt_t)
: OptionalOwnedCelSprite()
{
}
template <typename... Args>
OwnedCelSprite &emplace(Args &&...args)
{
sprite_ = OwnedCelSprite(std::forward<Args>(args)...);
return sprite_;
}
OptionalOwnedCelSprite &operator=(OwnedCelSprite &&sprite)
{
sprite_ = std::move(sprite);
return *this;
}
OptionalOwnedCelSprite &operator=(std::nullopt_t)
{
sprite_ = {};
return *this;
}
OwnedCelSprite &operator*()
{
assert(sprite_.data_ != nullptr);
return sprite_;
}
const OwnedCelSprite &operator*() const
{
assert(sprite_.data_ != nullptr);
return sprite_;
}
OwnedCelSprite *operator->()
{
assert(sprite_.data_ != nullptr);
return &sprite_;
}
const OwnedCelSprite *operator->() const
{
assert(sprite_.data_ != nullptr);
return &sprite_;
}
operator bool() const
{
return sprite_.data_ != nullptr;
}
private:
OwnedCelSprite sprite_;
};
inline CelSprite::CelSprite(const OwnedCelSprite &owned)

2
Source/engine/render/text_render.cpp

@ -31,7 +31,7 @@
namespace devilution {
std::optional<OwnedCelSprite> pSPentSpn2Cels;
OptionalOwnedCelSprite pSPentSpn2Cels;
namespace {

2
Source/engine/render/text_render.hpp

@ -123,7 +123,7 @@ private:
*
* Also used in the stores and the quest log.
*/
extern std::optional<OwnedCelSprite> pSPentSpn2Cels;
extern OptionalOwnedCelSprite pSPentSpn2Cels;
void LoadSmallSelectionSpinner();

8
Source/gmenu.cpp

@ -24,10 +24,10 @@ namespace devilution {
namespace {
std::optional<OwnedCelSprite> optbar_cel;
std::optional<OwnedCelSprite> PentSpin_cel;
std::optional<OwnedCelSprite> option_cel;
std::optional<OwnedCelSprite> sgpLogo;
OptionalOwnedCelSprite optbar_cel;
OptionalOwnedCelSprite PentSpin_cel;
OptionalOwnedCelSprite option_cel;
OptionalOwnedCelSprite sgpLogo;
bool mouseNavigation;
TMenuItem *sgpCurrItem;
int LogoAnim_tick;

2
Source/interfac.cpp

@ -30,7 +30,7 @@ namespace devilution {
namespace {
std::optional<OwnedCelSprite> sgpBackCel;
OptionalOwnedCelSprite sgpBackCel;
bool IsProgress;
uint32_t sgdwProgress;

2
Source/inv.cpp

@ -137,7 +137,7 @@ const Point InvRect[] = {
namespace {
std::optional<OwnedCelSprite> pInvCels;
OptionalOwnedCelSprite pInvCels;
/**
* @brief Adds an item to a player's InvGrid array

2
Source/items.cpp

@ -131,7 +131,7 @@ _sfx_id ItemInvSnds[] = {
namespace {
std::optional<OwnedCelSprite> itemanims[ITEMTYPES];
OptionalOwnedCelSprite itemanims[ITEMTYPES];
enum class PlayerArmorGraphic : uint8_t {
// clang-format off

2
Source/levels/gendung.cpp

@ -21,7 +21,7 @@ Bitset2d<DMAXX, DMAXY> Protected;
Rectangle SetPieceRoom;
Rectangle SetPiece;
std::unique_ptr<uint16_t[]> pSetPiece;
std::optional<OwnedCelSprite> pSpecialCels;
OptionalOwnedCelSprite pSpecialCels;
std::unique_ptr<MegaTile[]> pMegaTiles;
std::unique_ptr<byte[]> pDungeonCels;
std::array<TileProperties, MAXTILES> SOLData;

2
Source/levels/gendung.h

@ -148,7 +148,7 @@ extern Rectangle SetPieceRoom;
extern Rectangle SetPiece;
/** Contains the contents of the single player quest DUN file. */
extern std::unique_ptr<uint16_t[]> pSetPiece;
extern std::optional<OwnedCelSprite> pSpecialCels;
extern OptionalOwnedCelSprite pSpecialCels;
/** Specifies the tile definitions of the active dungeon type; (e.g. levels/l1data/l1.til). */
extern DVL_API_FOR_TEST std::unique_ptr<MegaTile[]> pMegaTiles;
extern std::unique_ptr<byte[]> pDungeonCels;

2
Source/minitext.cpp

@ -30,7 +30,7 @@ int qtextSpd;
/** Start time of scrolling */
Uint32 ScrollStart;
/** Graphics for the window border */
std::optional<OwnedCelSprite> pTextBoxCels;
OptionalOwnedCelSprite pTextBoxCels;
/** Pixels for a line of text and the empty space under it. */
const int LineHeight = 38;

2
Source/panels/charpanel.cpp

@ -17,7 +17,7 @@
namespace devilution {
std::optional<OwnedCelSprite> pChrButtons;
OptionalOwnedCelSprite pChrButtons;
/** Map of hero class names */
const char *const ClassStrTbl[] = {

2
Source/panels/charpanel.hpp

@ -5,7 +5,7 @@
namespace devilution {
extern std::optional<OwnedCelSprite> pChrButtons;
extern OptionalOwnedCelSprite pChrButtons;
extern const char *const ClassStrTbl[];
void DrawChr(const Surface &);

4
Source/panels/info_box.cpp

@ -4,8 +4,8 @@
namespace devilution {
std::optional<OwnedCelSprite> pSTextBoxCels;
std::optional<OwnedCelSprite> pSTextSlidCels;
OptionalOwnedCelSprite pSTextBoxCels;
OptionalOwnedCelSprite pSTextSlidCels;
void InitInfoBoxGfx()
{

4
Source/panels/info_box.hpp

@ -9,14 +9,14 @@ namespace devilution {
*
* Used in stores, the quest log, the help window, and the unique item info window.
*/
extern std::optional<OwnedCelSprite> pSTextBoxCels;
extern OptionalOwnedCelSprite pSTextBoxCels;
/**
* @brief Info box scrollbar graphics.
*
* Used in stores and `DrawDiabloMsg`.
*/
extern std::optional<OwnedCelSprite> pSTextSlidCels;
extern OptionalOwnedCelSprite pSTextSlidCels;
void InitInfoBoxGfx();
void FreeInfoBoxGfx();

6
Source/panels/spell_book.cpp

@ -21,12 +21,12 @@
namespace devilution {
std::optional<OwnedCelSprite> pSBkIconCels;
OptionalOwnedCelSprite pSBkIconCels;
namespace {
std::optional<OwnedCelSprite> pSBkBtnCel;
std::optional<OwnedCelSprite> pSpellBkCel;
OptionalOwnedCelSprite pSBkBtnCel;
OptionalOwnedCelSprite pSpellBkCel;
/** Maps from spellbook page number and position to spell_id. */
spell_id SpellPages[6][7] = {

2
Source/panels/spell_icons.cpp

@ -9,7 +9,7 @@
namespace devilution {
namespace {
std::optional<OwnedCelSprite> pSpellCels;
OptionalOwnedCelSprite pSpellCels;
uint8_t SplTransTbl[256];
} // namespace

2
Source/quests.cpp

@ -30,7 +30,7 @@
namespace devilution {
bool QuestLogIsOpen;
std::optional<OwnedCelSprite> pQLogCel;
OptionalOwnedCelSprite pQLogCel;
/** Contains the quests of the current game. */
Quest Quests[MAXQUESTS];
Point ReturnLvlPosition;

2
Source/quests.h

@ -73,7 +73,7 @@ struct QuestData {
};
extern bool QuestLogIsOpen;
extern std::optional<OwnedCelSprite> pQLogCel;
extern OptionalOwnedCelSprite pQLogCel;
extern DVL_API_FOR_TEST Quest Quests[MAXQUESTS];
extern Point ReturnLvlPosition;
extern dungeon_type ReturnLevelType;

Loading…
Cancel
Save