Browse Source

Split lighting shades from trn tables

pull/6014/head
Anders Jenbo 3 years ago
parent
commit
dc2d97c112
  1. 2
      Source/engine/load_pcx.cpp
  2. 4
      Source/engine/render/clx_render.hpp
  3. 2
      Source/engine/render/dun_render.cpp
  4. 2
      Source/engine/render/dun_render.hpp
  5. 6
      Source/engine/trn.cpp
  6. 24
      Source/lighting.cpp
  7. 9
      Source/lighting.h

2
Source/engine/load_pcx.cpp

@ -45,7 +45,7 @@ OptionalOwnedClxSpriteList LoadPcxSpriteList(const char *filename, int numFrames
if (outPalette != nullptr) {
std::memcpy(pathEnd - 3, "pal", 3);
std::array<uint8_t, 256 * 3> palette;
LoadFileInMem(path, &palette[0], palette.size());
LoadFileInMem(path, palette);
for (unsigned i = 0; i < 256; i++) {
outPalette[i].r = palette[i * 3];
outPalette[i].g = palette[i * 3 + 1];

4
Source/engine/render/clx_render.hpp

@ -94,7 +94,7 @@ extern int LightTableIndex;
inline void ClxDrawLight(const Surface &out, Point position, ClxSprite clx)
{
if (LightTableIndex != 0)
ClxDrawTRN(out, position, clx, &LightTables[LightTableIndex * 256]);
ClxDrawTRN(out, position, clx, LightTables[LightTableIndex].data());
else
ClxDraw(out, position, clx);
}
@ -107,7 +107,7 @@ inline void ClxDrawLight(const Surface &out, Point position, ClxSprite clx)
*/
inline void ClxDrawLightBlended(const Surface &out, Point position, ClxSprite clx)
{
ClxDrawBlendedTRN(out, position, clx, &LightTables[LightTableIndex * 256]);
ClxDrawBlendedTRN(out, position, clx, LightTables[LightTableIndex].data());
}
/**

2
Source/engine/render/dun_render.cpp

@ -1143,7 +1143,7 @@ void RenderTile(const Surface &out, Point position,
if (clip.width <= 0 || clip.height <= 0)
return;
const uint8_t *tbl = &LightTables[256 * lightTableIndex];
const uint8_t *tbl = LightTables[LightTableIndex].data();
const auto *pFrameTable = reinterpret_cast<const uint32_t *>(pDungeonCels.get());
const auto *src = reinterpret_cast<const uint8_t *>(&pDungeonCels[SDL_SwapLE32(pFrameTable[levelCelBlock.frame()])]);
uint8_t *dst = out.at(static_cast<int>(position.x + clip.left), static_cast<int>(position.y - clip.bottom));

2
Source/engine/render/dun_render.hpp

@ -262,7 +262,7 @@ string_view MaskTypeToString(MaskType maskType);
* @param position Target buffer coordinates
* @param levelCelBlock The MIN block of the level CEL file.
* @param maskType The mask to use,
* @param lightTableIndex The light level to use for rendering (index into LightTables / 256).
* @param lightTableIndex The light level to use for rendering (index into LightTables).
*/
void RenderTile(const Surface &out, Point position,
LevelCelBlock levelCelBlock, MaskType maskType, uint8_t lightTableIndex);

6
Source/engine/trn.cpp

@ -12,17 +12,17 @@ namespace devilution {
uint8_t *GetInfravisionTRN()
{
return &LightTables[16 * 256];
return InfravisionTable.data();
}
uint8_t *GetStoneTRN()
{
return &LightTables[17 * 256];
return StoneTable.data();
}
uint8_t *GetPauseTRN()
{
return &LightTables[18 * 256];
return PauseTable.data();
}
std::optional<std::array<uint8_t, 256>> GetClassTRN(Player &player)

24
Source/lighting.cpp

@ -20,7 +20,10 @@ int VisionId;
Light Lights[MAXLIGHTS];
uint8_t ActiveLights[MAXLIGHTS];
int ActiveLightCount;
std::array<uint8_t, LIGHTSIZE> LightTables;
std::array<std::array<uint8_t, 256>, NumLightingLevels> LightTables;
std::array<uint8_t, 256> InfravisionTable;
std::array<uint8_t, 256> StoneTable;
std::array<uint8_t, 256> PauseTable;
bool DisableLighting;
bool UpdateLighting;
@ -336,7 +339,7 @@ void DoVision(Point position, int radius, MapExplorationType doAutomap, bool vis
void MakeLightTable()
{
uint8_t *tbl = LightTables.data();
uint8_t *tbl = LightTables[0].data();
int shade = 0;
int lights = 15;
@ -396,7 +399,7 @@ void MakeLightTable()
if (leveltype == DTYPE_HELL) {
uint8_t blood[16];
tbl = LightTables.data();
tbl = LightTables[0].data();
for (int i = 0; i < lights; i++) {
int l1 = lights - i;
int l2 = l1;
@ -436,7 +439,7 @@ void MakeLightTable()
tbl += 224;
}
if (IsAnyOf(leveltype, DTYPE_NEST, DTYPE_CRYPT)) {
tbl = LightTables.data();
tbl = LightTables[0].data();
for (int i = 0; i < lights; i++) {
*tbl++ = 0;
for (int j = 1; j < 16; j++)
@ -449,14 +452,9 @@ void MakeLightTable()
tbl += 240;
}
LoadFileInMem("plrgfx\\infra.trn", tbl, 256);
tbl += 256;
LoadFileInMem("plrgfx\\stone.trn", tbl, 256);
tbl += 256;
LoadFileInMem("gendata\\pause.trn", tbl, 256);
tbl += 256;
LoadFileInMem("plrgfx\\infra.trn", InfravisionTable);
LoadFileInMem("plrgfx\\stone.trn", StoneTable);
LoadFileInMem("gendata\\pause.trn", PauseTable);
for (int j = 0; j < 16; j++) {
for (int i = 0; i < 128; i++) {
@ -788,7 +786,7 @@ void lighting_color_cycling()
return;
}
uint8_t *tbl = LightTables.data();
uint8_t *tbl = LightTables[0].data();
for (int j = 0; j < 16; j++) {
tbl++;

9
Source/lighting.h

@ -21,8 +21,8 @@ namespace devilution {
#define MAXLIGHTS 32
#define MAXVISION 32
/** 16 light levels + infravision + stone curse + red for pause/death screen */
#define LIGHTSIZE (19 * 256)
/** @brief Number of supported light levels */
constexpr size_t NumLightingLevels = 16;
#define NO_LIGHT -1
struct LightPosition {
@ -50,7 +50,10 @@ extern Light Lights[MAXLIGHTS];
extern uint8_t ActiveLights[MAXLIGHTS];
extern int ActiveLightCount;
constexpr char LightsMax = 15;
extern std::array<uint8_t, LIGHTSIZE> LightTables;
extern std::array<std::array<uint8_t, 256>, NumLightingLevels> LightTables;
extern std::array<uint8_t, 256> InfravisionTable;
extern std::array<uint8_t, 256> StoneTable;
extern std::array<uint8_t, 256> PauseTable;
extern bool DisableLighting;
extern bool UpdateLighting;

Loading…
Cancel
Save