Browse Source

🚚 engine.h: Extract `CelGetFrame` and friends

pull/2207/head
Gleb Mazovetskiy 5 years ago committed by Anders Jenbo
parent
commit
14218080b6
  1. 42
      Source/engine.h
  2. 55
      Source/engine/cel_header.hpp
  3. 1
      Source/engine/render/cel_render.cpp
  4. 1
      Source/engine/render/cl2_render.cpp
  5. 1
      Source/missiles.cpp
  6. 1
      Source/monster.cpp
  7. 1
      Source/player.cpp
  8. 1
      Source/towners.cpp

42
Source/engine.h

@ -37,7 +37,6 @@
#include "engine/point.hpp"
#include "engine/size.hpp"
#include "miniwin/miniwin.h"
#include "utils/endian.hpp"
#include "utils/stdcompat/cstddef.hpp"
#define TILE_WIDTH 64
@ -45,47 +44,6 @@
namespace devilution {
inline byte *CelGetFrameStart(byte *pCelBuff, int nCel)
{
const uint32_t *pFrameTable = reinterpret_cast<const std::uint32_t *>(pCelBuff);
return &pCelBuff[SDL_SwapLE32(pFrameTable[nCel])];
}
inline byte *CelGetFrame(byte *pCelBuff, int nCel, int *nDataSize)
{
const uint32_t nCellStart = LoadLE32(&pCelBuff[nCel * sizeof(std::uint32_t)]);
*nDataSize = LoadLE32(&pCelBuff[(nCel + 1) * sizeof(std::uint32_t)]) - nCellStart;
return &pCelBuff[nCellStart];
}
inline const byte *CelGetFrame(const byte *pCelBuff, int nCel, int *nDataSize)
{
const uint32_t nCellStart = LoadLE32(&pCelBuff[nCel * sizeof(std::uint32_t)]);
*nDataSize = LoadLE32(&pCelBuff[(nCel + 1) * sizeof(std::uint32_t)]) - nCellStart;
return &pCelBuff[nCellStart];
}
struct FrameHeader {
uint16_t row0;
uint16_t row32;
uint16_t row64;
uint16_t row96;
uint16_t row128;
};
inline const byte *CelGetFrameClipped(const byte *pCelBuff, int nCel, int *nDataSize)
{
const byte *pRLEBytes = CelGetFrame(pCelBuff, nCel, nDataSize);
FrameHeader frameHeader;
memcpy(&frameHeader, pRLEBytes, sizeof(FrameHeader));
uint16_t nDataStart = SDL_SwapLE16(frameHeader.row0);
*nDataSize -= nDataStart;
return &pRLEBytes[nDataStart];
}
struct CelOutputBuffer {
// 8-bit palletized surface.

55
Source/engine/cel_header.hpp

@ -0,0 +1,55 @@
#pragma once
#include <cstdint>
#include <cstring>
#include <SDL_endian.h>
#include "utils/endian.hpp"
#include "utils/stdcompat/cstddef.hpp"
namespace devilution {
inline byte *CelGetFrameStart(byte *pCelBuff, int nCel)
{
const auto *pFrameTable = reinterpret_cast<const std::uint32_t *>(pCelBuff);
return &pCelBuff[SDL_SwapLE32(pFrameTable[nCel])];
}
inline byte *CelGetFrame(byte *pCelBuff, int nCel, int *nDataSize)
{
const std::uint32_t nCellStart = LoadLE32(&pCelBuff[nCel * sizeof(std::uint32_t)]);
*nDataSize = static_cast<int>(LoadLE32(&pCelBuff[(nCel + 1) * sizeof(std::uint32_t)]) - nCellStart);
return &pCelBuff[nCellStart];
}
inline const byte *CelGetFrame(const byte *pCelBuff, int nCel, int *nDataSize)
{
const std::uint32_t nCellStart = LoadLE32(&pCelBuff[nCel * sizeof(std::uint32_t)]);
*nDataSize = static_cast<int>(LoadLE32(&pCelBuff[(nCel + 1) * sizeof(std::uint32_t)]) - nCellStart);
return &pCelBuff[nCellStart];
}
struct FrameHeader {
uint16_t row0;
uint16_t row32;
uint16_t row64;
uint16_t row96;
uint16_t row128;
};
inline const byte *CelGetFrameClipped(const byte *pCelBuff, int nCel, int *nDataSize)
{
const byte *pRLEBytes = CelGetFrame(pCelBuff, nCel, nDataSize);
FrameHeader frameHeader;
std::memcpy(&frameHeader, pRLEBytes, sizeof(FrameHeader));
std::uint16_t nDataStart = SDL_SwapLE16(frameHeader.row0);
*nDataSize -= nDataStart;
return &pRLEBytes[nDataStart];
}
} // namespace devilution

1
Source/engine/render/cel_render.cpp

@ -8,6 +8,7 @@
#include <cstdint>
#include <cstring>
#include "engine/cel_header.hpp"
#include "engine/render/common_impl.h"
#include "options.h"
#include "palette.h"

1
Source/engine/render/cl2_render.cpp

@ -7,6 +7,7 @@
#include <algorithm>
#include "engine/cel_header.hpp"
#include "engine/render/common_impl.h"
#include "scrollrt.h"
#include "utils/attributes.h"

1
Source/missiles.cpp

@ -10,6 +10,7 @@
#include "control.h"
#include "cursor.h"
#include "dead.h"
#include "engine/cel_header.hpp"
#include "engine/load_file.hpp"
#include "init.h"
#include "inv.h"

1
Source/monster.cpp

@ -16,6 +16,7 @@
#include "dead.h"
#include "drlg_l1.h"
#include "drlg_l4.h"
#include "engine/cel_header.hpp"
#include "engine/load_file.hpp"
#include "engine/render/cl2_render.hpp"
#include "init.h"

1
Source/player.cpp

@ -9,6 +9,7 @@
#include "control.h"
#include "cursor.h"
#include "dead.h"
#include "engine/cel_header.hpp"
#include "engine/load_file.hpp"
#include "gamemenu.h"
#include "init.h"

1
Source/towners.cpp

@ -1,6 +1,7 @@
#include "towners.h"
#include "cursor.h"
#include "engine/cel_header.hpp"
#include "engine/load_file.hpp"
#include "inv.h"
#include "minitext.h"

Loading…
Cancel
Save