Browse Source

Use `uint16_t` for sprite widths

pull/4127/head
Gleb Mazovetskiy 4 years ago
parent
commit
f4bce38875
  1. 10
      Source/cursor.cpp
  2. 2
      Source/dead.h
  3. 14
      Source/engine/cel_sprite.hpp
  4. 4
      Source/engine/load_cel.cpp
  5. 6
      Source/engine/load_cel.hpp
  6. 4
      Source/loadsave.cpp
  7. 2
      Source/misdat.cpp
  8. 10
      Source/misdat.h
  9. 4
      Source/missiles.h
  10. 4
      Source/monster.h
  11. 2
      Source/objdat.h
  12. 2
      Source/objects.h
  13. 2
      Source/panels/spell_book.cpp
  14. 9
      Source/scrollrt.cpp
  15. 7
      Source/towners.h

10
Source/cursor.cpp

@ -29,10 +29,10 @@ namespace {
/** Cursor images CEL */
std::optional<OwnedCelSprite> pCursCels;
std::optional<OwnedCelSprite> pCursCels2;
constexpr int InvItems1Size = 180;
constexpr uint16_t InvItems1Size = 180;
/** Maps from objcurs.cel frame number to frame width. */
const int InvItemWidth1[] = {
const uint16_t InvItemWidth1[] = {
// clang-format off
// Cursors
0, 33, 32, 32, 32, 32, 32, 32, 32, 32, 32, 23,
@ -55,7 +55,7 @@ const int InvItemWidth1[] = {
2 * 28, 2 * 28, 2 * 28, 2 * 28, 2 * 28, 2 * 28, 2 * 28, 2 * 28, 2 * 28, 2 * 28,
2 * 28, 2 * 28, 2 * 28, 2 * 28, 2 * 28, 2 * 28, 2 * 28, 2 * 28,
};
const int InvItemWidth2[] = {
const uint16_t InvItemWidth2[] = {
0,
1 * 28, 1 * 28, 1 * 28, 1 * 28, 1 * 28, 1 * 28, 1 * 28, 1 * 28, 1 * 28, 1 * 28,
1 * 28, 1 * 28, 1 * 28, 1 * 28, 1 * 28, 1 * 28, 1 * 28, 1 * 28, 1 * 28, 1 * 28,
@ -67,7 +67,7 @@ const int InvItemWidth2[] = {
};
/** Maps from objcurs.cel frame number to frame height. */
const int InvItemHeight1[] = {
const uint16_t InvItemHeight1[] = {
// clang-format off
// Cursors
0, 29, 32, 32, 32, 32, 32, 32, 32, 32, 32, 35,
@ -90,7 +90,7 @@ const int InvItemHeight1[] = {
3 * 28, 3 * 28, 3 * 28, 3 * 28, 3 * 28, 3 * 28, 3 * 28, 3 * 28, 3 * 28, 3 * 28,
3 * 28, 3 * 28, 3 * 28, 3 * 28, 3 * 28, 3 * 28, 3 * 28, 3 * 28,
};
const int InvItemHeight2[] = {
const uint16_t InvItemHeight2[] = {
0,
1 * 28, 1 * 28, 1 * 28, 1 * 28, 1 * 28, 1 * 28, 1 * 28, 1 * 28, 1 * 28, 1 * 28,
1 * 28, 1 * 28, 1 * 28, 1 * 28, 1 * 28, 1 * 28, 1 * 28, 1 * 28, 1 * 28, 1 * 28,

2
Source/dead.h

@ -18,7 +18,7 @@ static constexpr unsigned MaxCorpses = 31;
struct Corpse {
std::array<const byte *, 8> data;
int frame;
unsigned width;
uint16_t width;
uint8_t translationPaletteIndex;
};

14
Source/engine/cel_sprite.hpp

@ -15,13 +15,13 @@ class OwnedCelSprite;
*/
class CelSprite {
public:
CelSprite(const byte *data, int width)
CelSprite(const byte *data, uint16_t width)
: data_ptr_(data)
, width_(width)
{
}
CelSprite(const byte *data, const int *widths)
CelSprite(const byte *data, const uint16_t *widths)
: data_ptr_(data)
, widths_(widths)
{
@ -39,7 +39,7 @@ public:
return data_ptr_;
}
[[nodiscard]] int Width(std::size_t frame = 1) const
[[nodiscard]] uint16_t Width(std::size_t frame = 1) const
{
return widths_ == nullptr ? width_ : widths_[frame];
}
@ -55,8 +55,8 @@ public:
private:
const byte *data_ptr_;
int width_ = 0;
const int *widths_ = nullptr; // unowned
uint16_t width_ = 0;
const uint16_t *widths_ = nullptr; // unowned
};
/**
@ -65,13 +65,13 @@ private:
*/
class OwnedCelSprite : public CelSprite {
public:
OwnedCelSprite(std::unique_ptr<byte[]> data, int width)
OwnedCelSprite(std::unique_ptr<byte[]> data, uint16_t width)
: CelSprite(data.get(), width)
, data_(std::move(data))
{
}
OwnedCelSprite(std::unique_ptr<byte[]> data, const int *widths)
OwnedCelSprite(std::unique_ptr<byte[]> data, const uint16_t *widths)
: CelSprite(data.get(), widths)
, data_(std::move(data))
{

4
Source/engine/load_cel.cpp

@ -4,12 +4,12 @@
namespace devilution {
OwnedCelSprite LoadCel(const char *pszName, int width)
OwnedCelSprite LoadCel(const char *pszName, uint16_t width)
{
return OwnedCelSprite(LoadFileInMem(pszName), width);
}
OwnedCelSprite LoadCel(const char *pszName, const int *widths)
OwnedCelSprite LoadCel(const char *pszName, const uint16_t *widths)
{
return OwnedCelSprite(LoadFileInMem(pszName), widths);
}

6
Source/engine/load_cel.hpp

@ -1,5 +1,7 @@
#pragma once
#include <cstdint>
#include "engine/cel_sprite.hpp"
namespace devilution {
@ -7,7 +9,7 @@ namespace devilution {
/**
* @brief Loads a Cel sprite and sets its width
*/
OwnedCelSprite LoadCel(const char *pszName, int width);
OwnedCelSprite LoadCel(const char *pszName, const int *widths);
OwnedCelSprite LoadCel(const char *pszName, uint16_t width);
OwnedCelSprite LoadCel(const char *pszName, const uint16_t *widths);
} // namespace devilution

4
Source/loadsave.cpp

@ -732,7 +732,7 @@ void LoadObject(LoadHelper &file, Object &object)
object._oAnimCnt = file.NextLE<int32_t>();
object._oAnimLen = file.NextLE<uint32_t>();
object._oAnimFrame = file.NextLE<uint32_t>();
object._oAnimWidth = file.NextLE<int32_t>();
object._oAnimWidth = static_cast<uint16_t>(file.NextLE<int32_t>());
file.Skip(4); // Skip _oAnimWidth2
object._oDelFlag = file.NextBool32();
object._oBreak = file.NextLE<int8_t>();
@ -1403,7 +1403,7 @@ void SaveObject(SaveHelper &file, const Object &object)
file.WriteLE<uint32_t>(object._oAnimLen);
file.WriteLE<uint32_t>(object._oAnimFrame);
file.WriteLE<int32_t>(object._oAnimWidth);
file.WriteLE<int32_t>(CalculateWidth2(object._oAnimWidth)); // Write _oAnimWidth2 for vanilla compatibility
file.WriteLE<int32_t>(CalculateWidth2(static_cast<int>(object._oAnimWidth))); // Write _oAnimWidth2 for vanilla compatibility
file.WriteLE<uint32_t>(object._oDelFlag ? 1 : 0);
file.WriteLE<int8_t>(object._oBreak);
file.Skip(3); // Alignment

2
Source/misdat.cpp

@ -217,7 +217,7 @@ std::array<T, 16> maybeAutofill(std::initializer_list<T> list)
MissileFileData::MissileFileData(string_view name, uint8_t animName, uint8_t animFAmt, MissileDataFlags flags,
std::initializer_list<uint8_t> animDelay, std::initializer_list<uint8_t> animLen,
int16_t animWidth, int16_t animWidth2)
uint16_t animWidth, int16_t animWidth2)
: name(name)
, animName(animName)
, animFAmt(animFAmt)

10
Source/misdat.h

@ -10,6 +10,7 @@
#include "effects.h"
#include "engine.h"
#include "engine/cel_sprite.hpp"
#include "utils/stdcompat/cstddef.hpp"
#include "utils/stdcompat/string_view.hpp"
@ -141,14 +142,14 @@ struct MissileFileData {
MissileDataFlags flags;
std::array<uint8_t, 16> animDelay = {};
std::array<uint8_t, 16> animLen = {};
int16_t animWidth;
uint16_t animWidth;
int16_t animWidth2;
std::unique_ptr<byte[]> animData;
std::array<uint32_t, 16> frameOffsets;
MissileFileData(string_view name, uint8_t animName, uint8_t animFAmt, MissileDataFlags flags,
std::initializer_list<uint8_t> animDelay, std::initializer_list<uint8_t> animLen,
int16_t animWidth, int16_t animWidth2);
uint16_t animWidth, int16_t animWidth2);
void LoadGFX();
@ -164,6 +165,11 @@ struct MissileFileData {
return animData.get() + frameOffsets[i];
}
CelSprite Sprite() const
{
return CelSprite { GetFirstFrame(), animWidth };
}
void FreeGFX()
{
animData = nullptr;

4
Source/missiles.h

@ -97,8 +97,8 @@ struct Missile {
const byte *_miAnimData;
int _miAnimDelay; // Tick length of each frame in the current animation
int _miAnimLen; // Number of frames in current animation
int _miAnimWidth;
int _miAnimWidth2;
uint16_t _miAnimWidth;
int16_t _miAnimWidth2;
int _miAnimCnt; // Increases by one each game tick, counting how close we are to _pAnimDelay
int _miAnimAdd;
int _miAnimFrame; // Current frame of animation.

4
Source/monster.h

@ -137,11 +137,11 @@ struct AnimStruct {
const byte *spriteData = CelSpritesForDirections[static_cast<size_t>(direction)];
if (spriteData == nullptr)
return std::nullopt;
return CelSprite(spriteData, static_cast<int>(Width));
return CelSprite(spriteData, Width);
}
std::array<byte *, 8> CelSpritesForDirections;
unsigned Width;
uint16_t Width;
int Frames;
int Rate;
};

2
Source/objdat.h

@ -234,7 +234,7 @@ struct ObjectData {
int oAnimFlag; // TODO Create enum
int oAnimDelay; // Tick length of each frame in the current animation
int oAnimLen; // Number of frames in current animation
int oAnimWidth;
uint16_t oAnimWidth;
bool oSolidFlag;
bool oMissFlag;
bool oLightFlag;

2
Source/objects.h

@ -29,7 +29,7 @@ struct Object {
int _oAnimCnt; // Increases by one each game tick, counting how close we are to _pAnimDelay
uint32_t _oAnimLen; // Number of frames in current animation
uint32_t _oAnimFrame; // Current frame of animation.
int _oAnimWidth;
uint16_t _oAnimWidth;
bool _oDelFlag;
int8_t _oBreak;
bool _oSolidFlag;

2
Source/panels/spell_book.cpp

@ -85,7 +85,7 @@ void InitSpellBook()
pSpellBkCel = LoadCel("Data\\SpellBk.CEL", SPANEL_WIDTH);
if (gbIsHellfire) {
static const int SBkBtnHellfireWidths[] = { 0, 61, 61, 61, 61, 61, 76 };
static const uint16_t SBkBtnHellfireWidths[] = { 0, 61, 61, 61, 61, 61, 76 };
pSBkBtnCel = LoadCel("Data\\SpellBkB.CEL", SBkBtnHellfireWidths);
} else {
pSBkBtnCel = LoadCel("Data\\SpellBkB.CEL", 76);

9
Source/scrollrt.cpp

@ -455,12 +455,9 @@ void DrawMonster(const Surface &out, Point tilePosition, Point targetBufferPosit
*/
void DrawPlayerIconHelper(const Surface &out, int pnum, missile_graphic_id missileGraphicId, Point position, bool lighting)
{
position.x += CalculateWidth2(Players[pnum].AnimInfo.celSprite->Width()) - MissileSpriteData[missileGraphicId].animWidth2;
position.x += CalculateWidth2(static_cast<int>(Players[pnum].AnimInfo.celSprite->Width()) - MissileSpriteData[missileGraphicId].animWidth2);
int width = MissileSpriteData[missileGraphicId].animWidth;
const byte *pCelBuff = MissileSpriteData[missileGraphicId].GetFirstFrame();
CelSprite cel { pCelBuff, width };
const CelSprite cel = MissileSpriteData[missileGraphicId].Sprite();
if (pnum == MyPlayerId) {
Cl2Draw(out, position.x, position.y, cel, 1);
@ -750,7 +747,7 @@ void DrawMonsterHelper(const Surface &out, Point tilePosition, Point targetBuffe
auto &towner = Towners[mi];
int px = targetBufferPosition.x - CalculateWidth2(towner._tAnimWidth);
const Point position { px, targetBufferPosition.y };
CelSprite sprite { towner._tAnimData, towner._tAnimWidth };
const CelSprite sprite = towner.Sprite();
if (mi == pcursmonst) {
CelBlitOutlineTo(out, 166, position, sprite, towner._tAnimFrame);
}

7
Source/towners.h

@ -43,7 +43,7 @@ struct Towner {
int16_t seed;
/** Tile position of NPC */
Point position;
int16_t _tAnimWidth;
uint16_t _tAnimWidth;
/** Tick length of each frame in the current animation */
int16_t _tAnimDelay;
/** Increases by one each game tick, counting how close we are to _pAnimDelay */
@ -59,6 +59,11 @@ struct Towner {
std::size_t animOrderSize;
void (*talk)(Player &player, Towner &towner);
_talker_id _ttype;
CelSprite Sprite() const
{
return CelSprite { _tAnimData, _tAnimWidth };
}
};
extern Towner Towners[NUM_TOWNERS];

Loading…
Cancel
Save