Skip to content

Commit

Permalink
Remove Art and related functions
Browse files Browse the repository at this point in the history
  • Loading branch information
glebm committed Aug 8, 2022
1 parent 580d3cb commit 9b65eca
Show file tree
Hide file tree
Showing 15 changed files with 6 additions and 284 deletions.
2 changes: 0 additions & 2 deletions Source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ set(libdevilutionx_SRCS
controls/modifier_hints.cpp
controls/plrctrls.cpp

DiabloUI/art.cpp
DiabloUI/art_draw.cpp
DiabloUI/button.cpp
DiabloUI/credits.cpp
DiabloUI/credits_lines.cpp
Expand Down
83 changes: 0 additions & 83 deletions Source/DiabloUI/art.cpp

This file was deleted.

57 changes: 0 additions & 57 deletions Source/DiabloUI/art.h

This file was deleted.

60 changes: 0 additions & 60 deletions Source/DiabloUI/art_draw.cpp

This file was deleted.

14 changes: 0 additions & 14 deletions Source/DiabloUI/art_draw.h

This file was deleted.

2 changes: 0 additions & 2 deletions Source/DiabloUI/credits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
#include <memory>
#include <vector>

#include "DiabloUI/art.h"
#include "DiabloUI/art_draw.h"
#include "DiabloUI/credits_lines.h"
#include "DiabloUI/diabloui.h"
#include "DiabloUI/support_lines.h"
Expand Down
1 change: 0 additions & 1 deletion Source/DiabloUI/diabloui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <algorithm>
#include <string>

#include "DiabloUI/art_draw.h"
#include "DiabloUI/button.h"
#include "DiabloUI/dialogs.h"
#include "DiabloUI/scrollbar.h"
Expand Down
1 change: 0 additions & 1 deletion Source/DiabloUI/diabloui.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <cstddef>
#include <cstdint>

#include "DiabloUI/art.h"
#include "DiabloUI/ui_item.h"
#include "engine/clx_sprite.hpp"
#include "player.h"
Expand Down
1 change: 0 additions & 1 deletion Source/DiabloUI/progress.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include <SDL.h>

#include "DiabloUI/art_draw.h"
#include "DiabloUI/button.h"
#include "DiabloUI/diabloui.h"
#include "control.h"
Expand Down
1 change: 0 additions & 1 deletion Source/DiabloUI/ui_item.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <string>
#include <vector>

#include "DiabloUI/art.h"
#include "DiabloUI/ui_flags.hpp"
#include "engine/clx_sprite.hpp"
#include "engine/render/text_render.hpp"
Expand Down
1 change: 0 additions & 1 deletion Source/cursor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#include <fmt/format.h>

#include "DiabloUI/art.h"
#include "DiabloUI/diabloui.h"
#include "control.h"
#include "controls/plrctrls.h"
Expand Down
6 changes: 6 additions & 0 deletions Source/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,10 @@ Direction GetDirection(Point start, Point destination);
*/
int CalculateWidth2(int width);

inline int GetAnimationFrame(int frames, int fps = 60)
{
int frame = (SDL_GetTicks() / fps) % frames;
return frame > frames ? 0 : frame;
}

} // namespace devilution
1 change: 0 additions & 1 deletion Source/engine/render/text_render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

#include <fmt/compile.h>

#include "DiabloUI/art_draw.h"
#include "DiabloUI/diabloui.h"
#include "DiabloUI/ui_item.h"
#include "engine.h"
Expand Down
58 changes: 0 additions & 58 deletions Source/utils/pcx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,62 +26,4 @@ bool LoadPcxMeta(SDL_RWops *handle, int &width, int &height, uint8_t &bpp)
return true;
}

bool LoadPcxPixelsAndPalette(SDL_RWops *handle, int width, int height, std::uint8_t bpp,
uint8_t *buffer, std::ptrdiff_t bufferPitch, SDL_Color *palette)
{
std::ptrdiff_t pixelDataSize = SDL_RWsize(handle);
if (pixelDataSize < 0) {
// Unable to determine size, or an error occurred.
return false;
}

// SDL_RWsize gives the total size of the file however we've already read the header from an earlier call to
// LoadPcxMeta, so we only need to read the remainder of the file.
const std::size_t readSize = pixelDataSize - PcxHeaderSize;
std::unique_ptr<uint8_t[]> fileBuffer { new uint8_t[readSize] };
if (SDL_RWread(handle, fileBuffer.get(), readSize, 1) == 0) {
return false;
}
const std::ptrdiff_t xSkip = bufferPitch - width;
const std::ptrdiff_t srcSkip = width % 2;
uint8_t *dataPtr = fileBuffer.get();
for (int j = 0; j < height; j++) {
for (int x = 0; x < width;) {
constexpr std::uint8_t PcxMaxSinglePixel = 0xBF;
const std::uint8_t byte = *dataPtr++;
if (byte <= PcxMaxSinglePixel) {
*buffer++ = byte;
++x;
continue;
}
constexpr std::uint8_t PcxRunLengthMask = 0x3F;
const std::uint8_t runLength = (byte & PcxRunLengthMask);
std::memset(buffer, *dataPtr++, runLength);
buffer += runLength;
x += runLength;
}
dataPtr += srcSkip;
buffer += xSkip;
}

if (palette != nullptr && bpp == 8) {
// The file has a 256 color palette that needs to be loaded.
[[maybe_unused]] constexpr unsigned PcxPaletteSeparator = 0x0C;
assert(*dataPtr == PcxPaletteSeparator); // sanity check the delimiter
++dataPtr;

auto *out = palette;
for (unsigned i = 0; i < NumPaletteColors; ++i) {
out->r = *dataPtr++;
out->g = *dataPtr++;
out->b = *dataPtr++;
#ifndef USE_SDL1
out->a = SDL_ALPHA_OPAQUE;
#endif
++out;
}
}
return true;
}

} // namespace devilution
2 changes: 0 additions & 2 deletions Source/utils/pcx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,5 @@ struct PCXHeader {
static constexpr size_t PcxHeaderSize = 128;

bool LoadPcxMeta(SDL_RWops *handle, int &width, int &height, uint8_t &bpp);
bool LoadPcxPixelsAndPalette(SDL_RWops *handle, int width, int height, std::uint8_t bpp,
uint8_t *buffer, std::ptrdiff_t bufferPitch, SDL_Color *palette);

} // namespace devilution

0 comments on commit 9b65eca

Please sign in to comment.