You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1767 lines
50 KiB
1767 lines
50 KiB
|
6 years ago
|
/**
|
||
|
5 years ago
|
* @file scrollrt.cpp
|
||
|
6 years ago
|
*
|
||
|
|
* Implementation of functionality for rendering the dungeons, monsters and calling other render routines.
|
||
|
|
*/
|
||
|
5 years ago
|
|
||
|
4 years ago
|
#include "DiabloUI/ui_flags.hpp"
|
||
|
5 years ago
|
#include "automap.h"
|
||
|
4 years ago
|
#include "controls/plrctrls.h"
|
||
|
5 years ago
|
#include "controls/touch/renderers.h"
|
||
|
5 years ago
|
#include "cursor.h"
|
||
|
5 years ago
|
#include "dead.h"
|
||
|
5 years ago
|
#include "doom.h"
|
||
|
4 years ago
|
#include "engine/dx.h"
|
||
|
5 years ago
|
#include "engine/render/cel_render.hpp"
|
||
|
5 years ago
|
#include "engine/render/cl2_render.hpp"
|
||
|
5 years ago
|
#include "engine/render/dun_render.hpp"
|
||
|
5 years ago
|
#include "engine/render/text_render.hpp"
|
||
|
4 years ago
|
#include "engine/trn.hpp"
|
||
|
5 years ago
|
#include "error.h"
|
||
|
|
#include "gmenu.h"
|
||
|
|
#include "help.h"
|
||
|
5 years ago
|
#include "hwcursor.hpp"
|
||
|
5 years ago
|
#include "init.h"
|
||
|
|
#include "inv.h"
|
||
|
|
#include "lighting.h"
|
||
|
|
#include "minitext.h"
|
||
|
|
#include "missiles.h"
|
||
|
|
#include "nthread.h"
|
||
|
4 years ago
|
#include "panels/charpanel.hpp"
|
||
|
5 years ago
|
#include "plrmsg.h"
|
||
|
4 years ago
|
#include "qol/chatlog.h"
|
||
|
5 years ago
|
#include "qol/itemlabels.h"
|
||
|
5 years ago
|
#include "qol/monhealthbar.h"
|
||
|
4 years ago
|
#include "qol/stash.h"
|
||
|
5 years ago
|
#include "qol/xpbar.h"
|
||
|
5 years ago
|
#include "stores.h"
|
||
|
|
#include "towners.h"
|
||
|
4 years ago
|
#include "utils/bitset2d.hpp"
|
||
|
5 years ago
|
#include "utils/display.h"
|
||
|
5 years ago
|
#include "utils/endian.hpp"
|
||
|
5 years ago
|
#include "utils/log.hpp"
|
||
|
8 years ago
|
|
||
|
5 years ago
|
#ifdef _DEBUG
|
||
|
|
#include "debug.h"
|
||
|
|
#endif
|
||
|
|
|
||
|
5 years ago
|
namespace devilution {
|
||
|
7 years ago
|
|
||
|
5 years ago
|
/**
|
||
|
|
* Specifies the current light entry.
|
||
|
|
*/
|
||
|
|
int LightTableIndex;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Specifies the current MIN block of the level CEL file, as used during rendering of the level tiles.
|
||
|
|
*
|
||
|
|
* frameNum := block & 0x0FFF
|
||
|
|
* frameType := block & 0x7000 >> 12
|
||
|
|
*/
|
||
|
|
uint32_t level_cel_block;
|
||
|
|
bool AutoMapShowItems;
|
||
|
|
/**
|
||
|
|
* Specifies the type of arches to render.
|
||
|
|
*/
|
||
|
|
char arch_draw_type;
|
||
|
|
/**
|
||
|
|
* Specifies whether transparency is active for the current CEL file being decoded.
|
||
|
|
*/
|
||
|
|
bool cel_transparency_active;
|
||
|
|
/**
|
||
|
|
* Specifies whether foliage (tile has extra content that overlaps previous tile) being rendered.
|
||
|
|
*/
|
||
|
|
bool cel_foliage_active = false;
|
||
|
|
/**
|
||
|
|
* Specifies the current dungeon piece ID of the level, as used during rendering of the level tiles.
|
||
|
|
*/
|
||
|
|
int level_piece_id;
|
||
|
|
|
||
|
|
// DevilutionX extension.
|
||
|
|
extern void DrawControllerModifierHints(const Surface &out);
|
||
|
|
|
||
|
4 years ago
|
bool frameflag;
|
||
|
|
|
||
|
5 years ago
|
namespace {
|
||
|
|
/**
|
||
|
|
* @brief Hash algorithm for point
|
||
|
|
*/
|
||
|
|
struct PointHash {
|
||
|
|
std::size_t operator()(Point const &s) const noexcept
|
||
|
|
{
|
||
|
|
return s.x ^ (s.y << 1);
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @brief Contains all Missile at rendering position
|
||
|
|
*/
|
||
|
5 years ago
|
std::unordered_multimap<Point, Missile *, PointHash> MissilesAtRenderingTile;
|
||
|
5 years ago
|
|
||
|
|
/**
|
||
|
|
* @brief Could the missile (at the next game tick) collide? This method is a simplified version of CheckMissileCol (for example without random).
|
||
|
|
*/
|
||
|
|
bool CouldMissileCollide(Point tile, bool checkPlayerAndMonster)
|
||
|
|
{
|
||
|
4 years ago
|
if (!InDungeonBounds(tile))
|
||
|
5 years ago
|
return true;
|
||
|
|
if (checkPlayerAndMonster) {
|
||
|
|
if (dMonster[tile.x][tile.y] > 0)
|
||
|
|
return true;
|
||
|
|
if (dPlayer[tile.x][tile.y] > 0)
|
||
|
|
return true;
|
||
|
|
}
|
||
|
4 years ago
|
|
||
|
|
return IsMissileBlockedByTile(tile);
|
||
|
5 years ago
|
}
|
||
|
|
|
||
|
5 years ago
|
void UpdateMissileRendererData(Missile &m)
|
||
|
5 years ago
|
{
|
||
|
|
m.position.tileForRendering = m.position.tile;
|
||
|
|
m.position.offsetForRendering = m.position.offset;
|
||
|
|
|
||
|
5 years ago
|
const MissileMovementDistrubution missileMovement = MissilesData[m._mitype].MovementDistribution;
|
||
|
5 years ago
|
// don't calculate missile position if they don't move
|
||
|
5 years ago
|
if (missileMovement == MissileMovementDistrubution::Disabled || m.position.velocity == Displacement {})
|
||
|
5 years ago
|
return;
|
||
|
|
|
||
|
|
float fProgress = gfProgressToNextGameTick;
|
||
|
|
Displacement velocity = m.position.velocity * fProgress;
|
||
|
|
Displacement traveled = m.position.traveled + velocity;
|
||
|
|
|
||
|
|
int mx = traveled.deltaX >> 16;
|
||
|
|
int my = traveled.deltaY >> 16;
|
||
|
|
int dx = (mx + 2 * my) / 64;
|
||
|
|
int dy = (2 * my - mx) / 64;
|
||
|
|
|
||
|
|
// calculcate the future missile position
|
||
|
|
m.position.tileForRendering = m.position.start + Displacement { dx, dy };
|
||
|
|
m.position.offsetForRendering = { mx + (dy * 32) - (dx * 32), my - (dx * 16) - (dy * 16) };
|
||
|
|
|
||
|
|
// In some cases this calculcated position is invalid.
|
||
|
|
// For example a missile shouldn't move inside a wall.
|
||
|
|
// In this case the game logic don't advance the missile position and removes the missile or shows an explosion animation at the old position.
|
||
|
|
// For the animation distribution logic this means we are not allowed to move to a tile where the missile could collide, cause this could be a invalid position.
|
||
|
|
|
||
|
|
// If we are still at the current tile, this tile was already checked and is a valid tile
|
||
|
|
if (m.position.tileForRendering == m.position.tile)
|
||
|
|
return;
|
||
|
|
|
||
|
|
// If no collision can happen at the new tile we can advance
|
||
|
|
if (!CouldMissileCollide(m.position.tileForRendering, missileMovement == MissileMovementDistrubution::Blockable))
|
||
|
|
return;
|
||
|
|
|
||
|
|
// The new tile could be invalid, so don't advance to it.
|
||
|
|
// We search the last offset that is in the old (valid) tile.
|
||
|
|
// Implementation note: If someone knows the correct math to calculate this without the loop, I would really appreciate it.
|
||
|
|
while (m.position.tile != m.position.tileForRendering) {
|
||
|
5 years ago
|
fProgress -= 0.01F;
|
||
|
5 years ago
|
|
||
|
5 years ago
|
if (fProgress <= 0.0F) {
|
||
|
5 years ago
|
m.position.tileForRendering = m.position.tile;
|
||
|
|
m.position.offsetForRendering = m.position.offset;
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
velocity = m.position.velocity * fProgress;
|
||
|
|
traveled = m.position.traveled + velocity;
|
||
|
|
|
||
|
|
mx = traveled.deltaX >> 16;
|
||
|
|
my = traveled.deltaY >> 16;
|
||
|
|
dx = (mx + 2 * my) / 64;
|
||
|
|
dy = (2 * my - mx) / 64;
|
||
|
|
|
||
|
|
m.position.tileForRendering = m.position.start + Displacement { dx, dy };
|
||
|
|
m.position.offsetForRendering = { mx + (dy * 32) - (dx * 32), my - (dx * 16) - (dy * 16) };
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
void UpdateMissilesRendererData()
|
||
|
|
{
|
||
|
|
MissilesAtRenderingTile.clear();
|
||
|
|
|
||
|
4 years ago
|
for (auto &m : Missiles) {
|
||
|
5 years ago
|
UpdateMissileRendererData(m);
|
||
|
|
MissilesAtRenderingTile.insert(std::make_pair(m.position.tileForRendering, &m));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
5 years ago
|
uint32_t sgdwCursWdtOld;
|
||
|
5 years ago
|
int sgdwCursX;
|
||
|
|
int sgdwCursY;
|
||
|
6 years ago
|
/**
|
||
|
|
* Lower bound of back buffer.
|
||
|
|
*/
|
||
|
5 years ago
|
uint32_t sgdwCursHgt;
|
||
|
6 years ago
|
|
||
|
5 years ago
|
int sgdwCursXOld;
|
||
|
|
int sgdwCursYOld;
|
||
|
5 years ago
|
|
||
|
5 years ago
|
uint32_t sgdwCursWdt;
|
||
|
7 years ago
|
BYTE sgSaveBack[8192];
|
||
|
5 years ago
|
uint32_t sgdwCursHgtOld;
|
||
|
8 years ago
|
|
||
|
4 years ago
|
/**
|
||
|
|
* @brief Keeps track of which tiles have been rendered already.
|
||
|
|
*/
|
||
|
|
Bitset2d<MAXDUNX, MAXDUNY> dRendered;
|
||
|
6 years ago
|
|
||
|
5 years ago
|
int frameend;
|
||
|
|
int framerate;
|
||
|
|
int framestart;
|
||
|
8 years ago
|
|
||
|
5 years ago
|
const char *const PlayerModeNames[] = {
|
||
|
5 years ago
|
"standing",
|
||
|
|
"walking (1)",
|
||
|
|
"walking (2)",
|
||
|
|
"walking (3)",
|
||
|
|
"attacking (melee)",
|
||
|
|
"attacking (ranged)",
|
||
|
|
"blocking",
|
||
|
|
"getting hit",
|
||
|
|
"dying",
|
||
|
|
"casting a spell",
|
||
|
|
"changing levels",
|
||
|
|
"quitting"
|
||
|
|
};
|
||
|
|
|
||
|
5 years ago
|
void BlitCursor(BYTE *dst, std::uint32_t dstPitch, BYTE *src, std::uint32_t srcPitch)
|
||
|
5 years ago
|
{
|
||
|
5 years ago
|
for (std::uint32_t i = 0; i < sgdwCursHgt; ++i, src += srcPitch, dst += dstPitch) {
|
||
|
5 years ago
|
memcpy(dst, src, sgdwCursWdt);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
6 years ago
|
/**
|
||
|
5 years ago
|
* @brief Remove the cursor from the buffer
|
||
|
6 years ago
|
*/
|
||
|
5 years ago
|
void UndrawCursor(const Surface &out)
|
||
|
7 years ago
|
{
|
||
|
|
if (sgdwCursWdt == 0) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
5 years ago
|
BlitCursor(out.at(sgdwCursX, sgdwCursY), out.pitch(), sgSaveBack, sgdwCursWdt);
|
||
|
7 years ago
|
|
||
|
|
sgdwCursXOld = sgdwCursX;
|
||
|
|
sgdwCursYOld = sgdwCursY;
|
||
|
|
sgdwCursWdtOld = sgdwCursWdt;
|
||
|
|
sgdwCursHgtOld = sgdwCursHgt;
|
||
|
|
sgdwCursWdt = 0;
|
||
|
|
}
|
||
|
|
|
||
|
5 years ago
|
bool ShouldShowCursor()
|
||
|
5 years ago
|
{
|
||
|
4 years ago
|
if (ControlMode == ControlTypes::KeyboardAndMouse)
|
||
|
4 years ago
|
return true;
|
||
|
|
if (pcurs == CURSOR_TELEPORT)
|
||
|
|
return true;
|
||
|
|
if (invflag)
|
||
|
|
return true;
|
||
|
4 years ago
|
if (chrflag && MyPlayer->_pStatPts > 0)
|
||
|
4 years ago
|
return true;
|
||
|
|
|
||
|
|
return false;
|
||
|
5 years ago
|
}
|
||
|
|
|
||
|
6 years ago
|
/**
|
||
|
5 years ago
|
* @brief Save the content behind the cursor to a temporary buffer, then draw the cursor.
|
||
|
6 years ago
|
*/
|
||
|
5 years ago
|
void DrawCursor(const Surface &out)
|
||
|
7 years ago
|
{
|
||
|
4 years ago
|
if (pcurs <= CURSOR_NONE || !ShouldShowCursor()) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
Size cursSize = GetInvItemSize(pcurs);
|
||
|
|
if (cursSize.width == 0 || cursSize.height == 0) {
|
||
|
7 years ago
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
5 years ago
|
// Copy the buffer before the item cursor and its 1px outline are drawn to a temporary buffer.
|
||
|
4 years ago
|
const int outlineWidth = !MyPlayer->HoldItem.isEmpty() ? 1 : 0;
|
||
|
5 years ago
|
|
||
|
5 years ago
|
if (MousePosition.x < -cursSize.width - outlineWidth || MousePosition.x - outlineWidth >= out.w() || MousePosition.y < -cursSize.height - outlineWidth || MousePosition.y - outlineWidth >= out.h())
|
||
|
7 years ago
|
return;
|
||
|
|
|
||
|
5 years ago
|
constexpr auto Clip = [](int &pos, std::uint32_t &length, std::uint32_t posEnd) {
|
||
|
|
if (pos < 0) {
|
||
|
|
length += pos;
|
||
|
|
pos = 0;
|
||
|
|
} else if (pos + length > posEnd) {
|
||
|
|
length = posEnd - pos;
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
5 years ago
|
sgdwCursX = MousePosition.x - outlineWidth;
|
||
|
5 years ago
|
sgdwCursWdt = cursSize.width + 2 * outlineWidth;
|
||
|
5 years ago
|
Clip(sgdwCursX, sgdwCursWdt, out.w());
|
||
|
5 years ago
|
|
||
|
5 years ago
|
sgdwCursY = MousePosition.y - outlineWidth;
|
||
|
5 years ago
|
sgdwCursHgt = cursSize.height + 2 * outlineWidth;
|
||
|
5 years ago
|
Clip(sgdwCursY, sgdwCursHgt, out.h());
|
||
|
5 years ago
|
|
||
|
5 years ago
|
BlitCursor(sgSaveBack, sgdwCursWdt, out.at(sgdwCursX, sgdwCursY), out.pitch());
|
||
|
5 years ago
|
CelDrawCursor(out, MousePosition + Displacement { 0, cursSize.height - 1 }, pcurs);
|
||
|
7 years ago
|
}
|
||
|
|
|
||
|
6 years ago
|
/**
|
||
|
6 years ago
|
* @brief Render a missile sprite
|
||
|
5 years ago
|
* @param out Output buffer
|
||
|
5 years ago
|
* @param m Pointer to Missile struct
|
||
|
5 years ago
|
* @param targetBufferPosition Output buffer coordinate
|
||
|
6 years ago
|
* @param pre Is the sprite in the background
|
||
|
|
*/
|
||
|
5 years ago
|
void DrawMissilePrivate(const Surface &out, const Missile &missile, Point targetBufferPosition, bool pre)
|
||
|
8 years ago
|
{
|
||
|
5 years ago
|
if (missile._miPreFlag != pre || !missile._miDrawFlag)
|
||
|
7 years ago
|
return;
|
||
|
|
|
||
|
5 years ago
|
if (missile._miAnimData == nullptr) {
|
||
|
|
Log("Draw Missile 2 type {}: NULL Cel Buffer", missile._mitype);
|
||
|
5 years ago
|
return;
|
||
|
|
}
|
||
|
4 years ago
|
int nCel = missile._miAnimFrame - 1;
|
||
|
4 years ago
|
const uint32_t frames = LoadLE32(missile._miAnimData);
|
||
|
4 years ago
|
if (nCel < 0 || frames > 50 || nCel >= static_cast<int>(frames)) {
|
||
|
5 years ago
|
Log("Draw Missile 2: frame {} of {}, missile type=={}", nCel, frames, missile._mitype);
|
||
|
5 years ago
|
return;
|
||
|
|
}
|
||
|
5 years ago
|
|
||
|
|
const Point missileRenderPosition { targetBufferPosition + missile.position.offsetForRendering - Displacement { missile._miAnimWidth2, 0 } };
|
||
|
5 years ago
|
CelSprite cel { missile._miAnimData, missile._miAnimWidth };
|
||
|
|
if (missile._miUniqTrans != 0)
|
||
|
4 years ago
|
Cl2DrawTRN(out, missileRenderPosition.x, missileRenderPosition.y, cel, nCel, Monsters[missile._misource].uniqueTRN.get());
|
||
|
5 years ago
|
else if (missile._miLightFlag)
|
||
|
4 years ago
|
Cl2DrawLight(out, missileRenderPosition.x, missileRenderPosition.y, cel, nCel);
|
||
|
7 years ago
|
else
|
||
|
4 years ago
|
Cl2Draw(out, missileRenderPosition.x, missileRenderPosition.y, cel, nCel);
|
||
|
8 years ago
|
}
|
||
|
|
|
||
|
6 years ago
|
/**
|
||
|
6 years ago
|
* @brief Render a missile sprites for a given tile
|
||
|
5 years ago
|
* @param out Output buffer
|
||
|
5 years ago
|
* @param tilePosition dPiece coordinates
|
||
|
|
* @param targetBufferPosition Output buffer coordinates
|
||
|
6 years ago
|
* @param pre Is the sprite in the background
|
||
|
|
*/
|
||
|
5 years ago
|
void DrawMissile(const Surface &out, Point tilePosition, Point targetBufferPosition, bool pre)
|
||
|
8 years ago
|
{
|
||
|
5 years ago
|
const auto range = MissilesAtRenderingTile.equal_range(tilePosition);
|
||
|
5 years ago
|
for (auto it = range.first; it != range.second; it++) {
|
||
|
5 years ago
|
DrawMissilePrivate(out, *it->second, targetBufferPosition, pre);
|
||
|
8 years ago
|
}
|
||
|
|
}
|
||
|
|
|
||
|
6 years ago
|
/**
|
||
|
6 years ago
|
* @brief Render a monster sprite
|
||
|
5 years ago
|
* @param out Output buffer
|
||
|
5 years ago
|
* @param tilePosition dPiece coordinates
|
||
|
|
* @param targetBufferPosition Output buffer coordinates
|
||
|
6 years ago
|
* @param m Id of monster
|
||
|
6 years ago
|
*/
|
||
|
5 years ago
|
void DrawMonster(const Surface &out, Point tilePosition, Point targetBufferPosition, const Monster &monster)
|
||
|
8 years ago
|
{
|
||
|
4 years ago
|
if (!monster.AnimInfo.celSprite) {
|
||
|
5 years ago
|
Log("Draw Monster \"{}\": NULL Cel Buffer", monster.mName);
|
||
|
5 years ago
|
return;
|
||
|
|
}
|
||
|
7 years ago
|
|
||
|
5 years ago
|
constexpr auto getMonsterModeDisplayName = [](MonsterMode monsterMode) {
|
||
|
5 years ago
|
switch (monsterMode) {
|
||
|
5 years ago
|
case MonsterMode::Stand:
|
||
|
5 years ago
|
return "standing";
|
||
|
|
|
||
|
5 years ago
|
case MonsterMode::MoveNorthwards:
|
||
|
|
return "moving (northwards)";
|
||
|
5 years ago
|
|
||
|
5 years ago
|
case MonsterMode::MoveSouthwards:
|
||
|
|
return "moving (southwards)";
|
||
|
5 years ago
|
|
||
|
5 years ago
|
case MonsterMode::MoveSideways:
|
||
|
|
return "moving (sideways)";
|
||
|
5 years ago
|
|
||
|
5 years ago
|
case MonsterMode::MeleeAttack:
|
||
|
|
return "attacking (melee)";
|
||
|
5 years ago
|
|
||
|
5 years ago
|
case MonsterMode::HitRecovery:
|
||
|
5 years ago
|
return "getting hit";
|
||
|
|
|
||
|
5 years ago
|
case MonsterMode::Death:
|
||
|
5 years ago
|
return "dying";
|
||
|
|
|
||
|
5 years ago
|
case MonsterMode::SpecialMeleeAttack:
|
||
|
|
return "attacking (special melee)";
|
||
|
5 years ago
|
|
||
|
5 years ago
|
case MonsterMode::FadeIn:
|
||
|
5 years ago
|
return "fading in";
|
||
|
|
|
||
|
5 years ago
|
case MonsterMode::FadeOut:
|
||
|
5 years ago
|
return "fading out";
|
||
|
|
|
||
|
5 years ago
|
case MonsterMode::RangedAttack:
|
||
|
5 years ago
|
return "attacking (ranged)";
|
||
|
|
|
||
|
5 years ago
|
case MonsterMode::SpecialStand:
|
||
|
5 years ago
|
return "standing (special)";
|
||
|
|
|
||
|
5 years ago
|
case MonsterMode::SpecialRangedAttack:
|
||
|
5 years ago
|
return "attacking (special ranged)";
|
||
|
|
|
||
|
5 years ago
|
case MonsterMode::Delay:
|
||
|
5 years ago
|
return "delaying";
|
||
|
|
|
||
|
5 years ago
|
case MonsterMode::Charge:
|
||
|
5 years ago
|
return "charging";
|
||
|
|
|
||
|
5 years ago
|
case MonsterMode::Petrified:
|
||
|
|
return "petrified";
|
||
|
5 years ago
|
|
||
|
5 years ago
|
case MonsterMode::Heal:
|
||
|
5 years ago
|
return "healing";
|
||
|
|
|
||
|
5 years ago
|
case MonsterMode::Talk:
|
||
|
5 years ago
|
return "talking";
|
||
|
|
|
||
|
|
default:
|
||
|
|
app_fatal("Invalid monster mode.");
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
5 years ago
|
int nCel = monster.AnimInfo.GetFrameToUseForRendering();
|
||
|
4 years ago
|
const uint32_t frames = LoadLE32(monster.AnimInfo.celSprite->Data());
|
||
|
4 years ago
|
if (nCel < 0 || frames > 50 || nCel >= static_cast<int>(frames)) {
|
||
|
5 years ago
|
Log(
|
||
|
|
"Draw Monster \"{}\" {}: facing {}, frame {} of {}",
|
||
|
5 years ago
|
monster.mName,
|
||
|
5 years ago
|
getMonsterModeDisplayName(monster._mmode),
|
||
|
4 years ago
|
DirectionToString(monster._mdir),
|
||
|
5 years ago
|
nCel,
|
||
|
|
frames);
|
||
|
|
return;
|
||
|
|
}
|
||
|
7 years ago
|
|
||
|
4 years ago
|
const auto &cel = *monster.AnimInfo.celSprite;
|
||
|
5 years ago
|
|
||
|
4 years ago
|
if (!IsTileLit(tilePosition)) {
|
||
|
4 years ago
|
Cl2DrawTRN(out, targetBufferPosition.x, targetBufferPosition.y, cel, nCel, GetInfravisionTRN());
|
||
|
5 years ago
|
return;
|
||
|
7 years ago
|
}
|
||
|
4 years ago
|
uint8_t *trn = nullptr;
|
||
|
5 years ago
|
if (monster._uniqtype != 0)
|
||
|
4 years ago
|
trn = monster.uniqueTRN.get();
|
||
|
5 years ago
|
if (monster._mmode == MonsterMode::Petrified)
|
||
|
4 years ago
|
trn = GetStoneTRN();
|
||
|
4 years ago
|
if (MyPlayer->_pInfraFlag && LightTableIndex > 8)
|
||
|
4 years ago
|
trn = GetInfravisionTRN();
|
||
|
|
if (trn != nullptr)
|
||
|
|
Cl2DrawTRN(out, targetBufferPosition.x, targetBufferPosition.y, cel, nCel, trn);
|
||
|
5 years ago
|
else
|
||
|
5 years ago
|
Cl2DrawLight(out, targetBufferPosition.x, targetBufferPosition.y, cel, nCel);
|
||
|
7 years ago
|
}
|
||
|
|
|
||
|
5 years ago
|
/**
|
||
|
5 years ago
|
* @brief Helper for rendering a specific player icon (Mana Shield or Reflect)
|
||
|
5 years ago
|
*/
|
||
|
5 years ago
|
void DrawPlayerIconHelper(const Surface &out, int pnum, missile_graphic_id missileGraphicId, Point position, bool lighting)
|
||
|
5 years ago
|
{
|
||
|
4 years ago
|
position.x -= MissileSpriteData[missileGraphicId].animWidth2;
|
||
|
5 years ago
|
|
||
|
4 years ago
|
const CelSprite cel = MissileSpriteData[missileGraphicId].Sprite();
|
||
|
5 years ago
|
|
||
|
5 years ago
|
if (pnum == MyPlayerId) {
|
||
|
4 years ago
|
Cl2Draw(out, position.x, position.y, cel, 0);
|
||
|
5 years ago
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (lighting) {
|
||
|
4 years ago
|
Cl2DrawTRN(out, position.x, position.y, cel, 0, GetInfravisionTRN());
|
||
|
5 years ago
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
4 years ago
|
Cl2DrawLight(out, position.x, position.y, cel, 0);
|
||
|
5 years ago
|
}
|
||
|
|
|
||
|
5 years ago
|
/**
|
||
|
|
* @brief Helper for rendering player icons (Mana Shield and Reflect)
|
||
|
|
* @param out Output buffer
|
||
|
|
* @param pnum Player id
|
||
|
5 years ago
|
* @param position Output buffer coordinates
|
||
|
5 years ago
|
* @param lighting Should lighting be applied
|
||
|
|
*/
|
||
|
5 years ago
|
void DrawPlayerIcons(const Surface &out, int pnum, Point position, bool lighting)
|
||
|
5 years ago
|
{
|
||
|
4 years ago
|
Player &player = Players[pnum];
|
||
|
5 years ago
|
if (player.pManaShield)
|
||
|
5 years ago
|
DrawPlayerIconHelper(out, pnum, MFILE_MANASHLD, position, lighting);
|
||
|
5 years ago
|
if (player.wReflections > 0)
|
||
|
5 years ago
|
DrawPlayerIconHelper(out, pnum, MFILE_REFLECT, position + Displacement { 0, 16 }, lighting);
|
||
|
5 years ago
|
}
|
||
|
|
|
||
|
6 years ago
|
/**
|
||
|
6 years ago
|
* @brief Render a player sprite
|
||
|
5 years ago
|
* @param out Output buffer
|
||
|
6 years ago
|
* @param pnum Player id
|
||
|
5 years ago
|
* @param tilePosition dPiece coordinates
|
||
|
|
* @param targetBufferPosition Output buffer coordinates
|
||
|
6 years ago
|
* @param pCelBuff sprite buffer
|
||
|
|
* @param nCel frame
|
||
|
|
* @param nWidth width
|
||
|
|
*/
|
||
|
5 years ago
|
void DrawPlayer(const Surface &out, int pnum, Point tilePosition, Point targetBufferPosition)
|
||
|
8 years ago
|
{
|
||
|
4 years ago
|
if (!IsTileLit(tilePosition) && !MyPlayer->_pInfraFlag && leveltype != DTYPE_TOWN) {
|
||
|
5 years ago
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
4 years ago
|
Player &player = Players[pnum];
|
||
|
5 years ago
|
|
||
|
4 years ago
|
std::optional<CelSprite> sprite = player.AnimInfo.celSprite;
|
||
|
5 years ago
|
int nCel = player.AnimInfo.GetFrameToUseForRendering();
|
||
|
5 years ago
|
|
||
|
4 years ago
|
if (player.previewCelSprite) {
|
||
|
|
sprite = player.previewCelSprite;
|
||
|
4 years ago
|
nCel = 0;
|
||
|
5 years ago
|
}
|
||
|
|
|
||
|
4 years ago
|
if (!sprite) {
|
||
|
5 years ago
|
Log("Drawing player {} \"{}\": NULL CelSprite", pnum, player._pName);
|
||
|
5 years ago
|
return;
|
||
|
|
}
|
||
|
5 years ago
|
|
||
|
4 years ago
|
Point spriteBufferPosition = targetBufferPosition - Displacement { CalculateWidth2(sprite ? sprite->Width() : 96), 0 };
|
||
|
5 years ago
|
|
||
|
4 years ago
|
const uint32_t frames = LoadLE32(sprite->Data());
|
||
|
|
if (nCel < 0 || frames > 50 || nCel >= static_cast<int>(frames)) {
|
||
|
5 years ago
|
const char *szMode = "unknown action";
|
||
|
5 years ago
|
if (player._pmode <= PM_QUIT)
|
||
|
5 years ago
|
szMode = PlayerModeNames[player._pmode];
|
||
|
5 years ago
|
Log(
|
||
|
|
"Drawing player {} \"{}\" {}: facing {}, frame {} of {}",
|
||
|
5 years ago
|
pnum,
|
||
|
5 years ago
|
player._pName,
|
||
|
5 years ago
|
szMode,
|
||
|
4 years ago
|
DirectionToString(player._pdir),
|
||
|
5 years ago
|
nCel,
|
||
|
|
frames);
|
||
|
|
return;
|
||
|
|
}
|
||
|
5 years ago
|
|
||
|
|
if (pnum == pcursplr)
|
||
|
4 years ago
|
Cl2DrawOutline(out, 165, spriteBufferPosition.x, spriteBufferPosition.y, *sprite, nCel);
|
||
|
5 years ago
|
|
||
|
5 years ago
|
if (pnum == MyPlayerId) {
|
||
|
4 years ago
|
Cl2Draw(out, spriteBufferPosition.x, spriteBufferPosition.y, *sprite, nCel);
|
||
|
5 years ago
|
DrawPlayerIcons(out, pnum, targetBufferPosition, true);
|
||
|
5 years ago
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
4 years ago
|
if (!IsTileLit(tilePosition) || (MyPlayer->_pInfraFlag && LightTableIndex > 8)) {
|
||
|
4 years ago
|
Cl2DrawTRN(out, spriteBufferPosition.x, spriteBufferPosition.y, *sprite, nCel, GetInfravisionTRN());
|
||
|
5 years ago
|
DrawPlayerIcons(out, pnum, targetBufferPosition, true);
|
||
|
5 years ago
|
return;
|
||
|
8 years ago
|
}
|
||
|
5 years ago
|
|
||
|
5 years ago
|
int l = LightTableIndex;
|
||
|
|
if (LightTableIndex < 5)
|
||
|
|
LightTableIndex = 0;
|
||
|
5 years ago
|
else
|
||
|
5 years ago
|
LightTableIndex -= 5;
|
||
|
5 years ago
|
|
||
|
4 years ago
|
Cl2DrawLight(out, spriteBufferPosition.x, spriteBufferPosition.y, *sprite, nCel);
|
||
|
5 years ago
|
DrawPlayerIcons(out, pnum, targetBufferPosition, false);
|
||
|
5 years ago
|
|
||
|
5 years ago
|
LightTableIndex = l;
|
||
|
8 years ago
|
}
|
||
|
|
|
||
|
6 years ago
|
/**
|
||
|
6 years ago
|
* @brief Render a player sprite
|
||
|
5 years ago
|
* @param out Output buffer
|
||
|
5 years ago
|
* @param tilePosition dPiece coordinates
|
||
|
|
* @param targetBufferPosition Output buffer coordinates
|
||
|
6 years ago
|
*/
|
||
|
5 years ago
|
void DrawDeadPlayer(const Surface &out, Point tilePosition, Point targetBufferPosition)
|
||
|
8 years ago
|
{
|
||
|
4 years ago
|
dFlags[tilePosition.x][tilePosition.y] &= ~DungeonFlag::DeadPlayer;
|
||
|
8 years ago
|
|
||
|
5 years ago
|
for (int i = 0; i < MAX_PLRS; i++) {
|
||
|
4 years ago
|
Player &player = Players[i];
|
||
|
4 years ago
|
if (player.plractive && player._pHitPoints == 0 && player.isOnActiveLevel() && player.position.tile == tilePosition) {
|
||
|
4 years ago
|
dFlags[tilePosition.x][tilePosition.y] |= DungeonFlag::DeadPlayer;
|
||
|
4 years ago
|
const Point playerRenderPosition { targetBufferPosition + player.position.offset };
|
||
|
5 years ago
|
DrawPlayer(out, i, tilePosition, playerRenderPosition);
|
||
|
7 years ago
|
}
|
||
|
|
}
|
||
|
8 years ago
|
}
|
||
|
|
|
||
|
6 years ago
|
/**
|
||
|
|
* @brief Render an object sprite
|
||
|
5 years ago
|
* @param out Output buffer
|
||
|
5 years ago
|
* @param tilePosition dPiece coordinates
|
||
|
|
* @param targetBufferPosition Output buffer coordinates
|
||
|
6 years ago
|
* @param pre Is the sprite in the background
|
||
|
|
*/
|
||
|
5 years ago
|
void DrawObject(const Surface &out, Point tilePosition, Point targetBufferPosition, bool pre)
|
||
|
8 years ago
|
{
|
||
|
4 years ago
|
if (LightTableIndex >= LightsMax) {
|
||
|
7 years ago
|
return;
|
||
|
4 years ago
|
}
|
||
|
7 years ago
|
|
||
|
4 years ago
|
Object *object = ObjectAtPosition(tilePosition);
|
||
|
|
if (object == nullptr) {
|
||
|
4 years ago
|
return;
|
||
|
|
}
|
||
|
5 years ago
|
|
||
|
4 years ago
|
const Object &objectToDraw = *object;
|
||
|
4 years ago
|
if (objectToDraw._oPreFlag != pre) {
|
||
|
|
return;
|
||
|
7 years ago
|
}
|
||
|
7 years ago
|
|
||
|
4 years ago
|
Point screenPosition = targetBufferPosition - Displacement { CalculateWidth2(objectToDraw._oAnimWidth), 0 };
|
||
|
|
if (objectToDraw.position != tilePosition) {
|
||
|
|
// drawing a large or offset object, calculate the correct position for the center of the sprite
|
||
|
4 years ago
|
Displacement worldOffset = objectToDraw.position - tilePosition;
|
||
|
|
screenPosition -= worldOffset.worldToScreen();
|
||
|
4 years ago
|
}
|
||
|
7 years ago
|
|
||
|
4 years ago
|
byte *pCelBuff = objectToDraw._oAnimData;
|
||
|
5 years ago
|
if (pCelBuff == nullptr) {
|
||
|
4 years ago
|
Log("Draw Object type {}: NULL Cel Buffer", objectToDraw._otype);
|
||
|
5 years ago
|
return;
|
||
|
|
}
|
||
|
7 years ago
|
|
||
|
4 years ago
|
const uint32_t nCel = objectToDraw._oAnimFrame - 1;
|
||
|
|
const uint32_t frames = LoadLE32(pCelBuff);
|
||
|
|
if (nCel == static_cast<uint32_t>(-1) || frames > 50 || nCel >= frames) {
|
||
|
4 years ago
|
Log("Draw Object: frame {} of {}, object type=={}", nCel, frames, objectToDraw._otype);
|
||
|
5 years ago
|
return;
|
||
|
|
}
|
||
|
7 years ago
|
|
||
|
4 years ago
|
CelSprite cel { objectToDraw._oAnimData, objectToDraw._oAnimWidth };
|
||
|
|
if (pcursobj != -1 && &objectToDraw == &Objects[pcursobj]) {
|
||
|
4 years ago
|
CelBlitOutlineTo(out, 194, screenPosition, cel, nCel);
|
||
|
4 years ago
|
}
|
||
|
|
if (objectToDraw._oLight) {
|
||
|
4 years ago
|
CelClippedDrawLightTo(out, screenPosition, cel, nCel);
|
||
|
7 years ago
|
} else {
|
||
|
4 years ago
|
CelClippedDrawTo(out, screenPosition, cel, nCel);
|
||
|
8 years ago
|
}
|
||
|
7 years ago
|
}
|
||
|
7 years ago
|
|
||
|
5 years ago
|
static void DrawDungeon(const Surface & /*out*/, Point /*tilePosition*/, Point /*targetBufferPosition*/);
|
||
|
7 years ago
|
|
||
|
6 years ago
|
/**
|
||
|
6 years ago
|
* @brief Render a cell
|
||
|
5 years ago
|
* @param out Target buffer
|
||
|
5 years ago
|
* @param tilePosition dPiece coordinates
|
||
|
|
* @param targetBufferPosition Target buffer coordinates
|
||
|
6 years ago
|
*/
|
||
|
5 years ago
|
void DrawCell(const Surface &out, Point tilePosition, Point targetBufferPosition)
|
||
|
7 years ago
|
{
|
||
|
5 years ago
|
level_piece_id = dPiece[tilePosition.x][tilePosition.y];
|
||
|
4 years ago
|
MICROS *pMap = &DPieceMicros[level_piece_id];
|
||
|
4 years ago
|
cel_transparency_active = TileHasAny(level_piece_id, TileProperties::Transparent) && TransList[dTransVal[tilePosition.x][tilePosition.y]];
|
||
|
|
cel_foliage_active = !TileHasAny(level_piece_id, TileProperties::Solid);
|
||
|
5 years ago
|
for (int i = 0; i < (MicroTileLen / 2); i++) {
|
||
|
6 years ago
|
level_cel_block = pMap->mt[2 * i];
|
||
|
|
if (level_cel_block != 0) {
|
||
|
6 years ago
|
arch_draw_type = i == 0 ? 1 : 0;
|
||
|
5 years ago
|
RenderTile(out, targetBufferPosition);
|
||
|
6 years ago
|
}
|
||
|
|
level_cel_block = pMap->mt[2 * i + 1];
|
||
|
|
if (level_cel_block != 0) {
|
||
|
6 years ago
|
arch_draw_type = i == 0 ? 2 : 0;
|
||
|
5 years ago
|
RenderTile(out, targetBufferPosition + Displacement { TILE_WIDTH / 2, 0 });
|
||
|
6 years ago
|
}
|
||
|
5 years ago
|
targetBufferPosition.y -= TILE_HEIGHT;
|
||
|
6 years ago
|
}
|
||
|
6 years ago
|
cel_foliage_active = false;
|
||
|
6 years ago
|
}
|
||
|
7 years ago
|
|
||
|
6 years ago
|
/**
|
||
|
|
* @brief Render a floor tiles
|
||
|
5 years ago
|
* @param out Target buffer
|
||
|
5 years ago
|
* @param tilePosition dPiece coordinates
|
||
|
|
* @param targetBufferPosition Target buffer coordinate
|
||
|
6 years ago
|
*/
|
||
|
5 years ago
|
void DrawFloor(const Surface &out, Point tilePosition, Point targetBufferPosition)
|
||
|
6 years ago
|
{
|
||
|
5 years ago
|
cel_transparency_active = false;
|
||
|
5 years ago
|
LightTableIndex = dLight[tilePosition.x][tilePosition.y];
|
||
|
7 years ago
|
|
||
|
6 years ago
|
arch_draw_type = 1; // Left
|
||
|
4 years ago
|
int pn = dPiece[tilePosition.x][tilePosition.y];
|
||
|
|
level_cel_block = DPieceMicros[pn].mt[0];
|
||
|
6 years ago
|
if (level_cel_block != 0) {
|
||
|
5 years ago
|
RenderTile(out, targetBufferPosition);
|
||
|
6 years ago
|
}
|
||
|
6 years ago
|
arch_draw_type = 2; // Right
|
||
|
4 years ago
|
level_cel_block = DPieceMicros[pn].mt[1];
|
||
|
6 years ago
|
if (level_cel_block != 0) {
|
||
|
5 years ago
|
RenderTile(out, targetBufferPosition + Displacement { TILE_WIDTH / 2, 0 });
|
||
|
6 years ago
|
}
|
||
|
7 years ago
|
}
|
||
|
|
|
||
|
6 years ago
|
/**
|
||
|
6 years ago
|
* @brief Draw item for a given tile
|
||
|
5 years ago
|
* @param out Output buffer
|
||
|
5 years ago
|
* @param tilePosition dPiece coordinates
|
||
|
|
* @param targetBufferPosition Output buffer coordinates
|
||
|
6 years ago
|
* @param pre Is the sprite in the background
|
||
|
6 years ago
|
*/
|
||
|
5 years ago
|
void DrawItem(const Surface &out, Point tilePosition, Point targetBufferPosition, bool pre)
|
||
|
7 years ago
|
{
|
||
|
5 years ago
|
int8_t bItem = dItem[tilePosition.x][tilePosition.y];
|
||
|
7 years ago
|
|
||
|
5 years ago
|
if (bItem <= 0)
|
||
|
7 years ago
|
return;
|
||
|
|
|
||
|
5 years ago
|
auto &item = Items[bItem - 1];
|
||
|
|
if (item._iPostDraw == pre)
|
||
|
7 years ago
|
return;
|
||
|
|
|
||
|
4 years ago
|
std::optional<CelSprite> cel = item.AnimInfo.celSprite;
|
||
|
|
if (!cel) {
|
||
|
5 years ago
|
Log("Draw Item \"{}\" 1: NULL CelSprite", item._iIName);
|
||
|
5 years ago
|
return;
|
||
|
|
}
|
||
|
5 years ago
|
|
||
|
5 years ago
|
int nCel = item.AnimInfo.GetFrameToUseForRendering();
|
||
|
4 years ago
|
const uint32_t frames = LoadLE32(cel->Data());
|
||
|
4 years ago
|
if (nCel < 0 || frames > 50 || nCel >= static_cast<int>(frames)) {
|
||
|
4 years ago
|
Log("Draw \"{}\" Item 1: frame {} of {}, item type=={}", item._iIName, nCel, frames, ItemTypeToString(item._itype));
|
||
|
5 years ago
|
return;
|
||
|
|
}
|
||
|
5 years ago
|
|
||
|
5 years ago
|
int px = targetBufferPosition.x - CalculateWidth2(cel->Width());
|
||
|
|
const Point position { px, targetBufferPosition.y };
|
||
|
5 years ago
|
if (bItem - 1 == pcursitem || AutoMapShowItems) {
|
||
|
5 years ago
|
CelBlitOutlineTo(out, GetOutlineColor(item, false), position, *cel, nCel);
|
||
|
7 years ago
|
}
|
||
|
5 years ago
|
CelClippedDrawLightTo(out, position, *cel, nCel);
|
||
|
4 years ago
|
if (item.AnimInfo.CurrentFrame == item.AnimInfo.NumberOfFrames - 1 || item._iCurs == ICURS_MAGIC_ROCK)
|
||
|
5 years ago
|
AddItemToLabelQueue(bItem - 1, px, targetBufferPosition.y);
|
||
|
7 years ago
|
}
|
||
|
|
|
||
|
6 years ago
|
/**
|
||
|
5 years ago
|
* @brief Check if and how a monster should be rendered
|
||
|
5 years ago
|
* @param out Output buffer
|
||
|
5 years ago
|
* @param tilePosition dPiece coordinates
|
||
|
|
* @param targetBufferPosition Output buffer coordinates
|
||
|
6 years ago
|
*/
|
||
|
5 years ago
|
void DrawMonsterHelper(const Surface &out, Point tilePosition, Point targetBufferPosition)
|
||
|
7 years ago
|
{
|
||
|
4 years ago
|
int mi = abs(dMonster[tilePosition.x][tilePosition.y]) - 1;
|
||
|
7 years ago
|
|
||
|
|
if (leveltype == DTYPE_TOWN) {
|
||
|
5 years ago
|
auto &towner = Towners[mi];
|
||
|
5 years ago
|
int px = targetBufferPosition.x - CalculateWidth2(towner._tAnimWidth);
|
||
|
|
const Point position { px, targetBufferPosition.y };
|
||
|
4 years ago
|
const CelSprite sprite = towner.Sprite();
|
||
|
7 years ago
|
if (mi == pcursmonst) {
|
||
|
4 years ago
|
CelBlitOutlineTo(out, 166, position, sprite, towner._tAnimFrame);
|
||
|
7 years ago
|
}
|
||
|
5 years ago
|
assert(towner._tAnimData);
|
||
|
4 years ago
|
CelClippedDrawTo(out, position, sprite, towner._tAnimFrame);
|
||
|
7 years ago
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
4 years ago
|
if (!IsTileLit(tilePosition) && !MyPlayer->_pInfraFlag)
|
||
|
6 years ago
|
return;
|
||
|
|
|
||
|
5 years ago
|
if (mi < 0 || mi >= MAXMONSTERS) {
|
||
|
5 years ago
|
Log("Draw Monster: tried to draw illegal monster {}", mi);
|
||
|
5 years ago
|
return;
|
||
|
|
}
|
||
|
7 years ago
|
|
||
|
5 years ago
|
const auto &monster = Monsters[mi];
|
||
|
|
if ((monster._mFlags & MFLAG_HIDDEN) != 0) {
|
||
|
7 years ago
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
5 years ago
|
if (monster.MType == nullptr) {
|
||
|
|
Log("Draw Monster \"{}\": uninitialized monster", monster.mName);
|
||
|
5 years ago
|
return;
|
||
|
|
}
|
||
|
7 years ago
|
|
||
|
4 years ago
|
CelSprite cel = *monster.AnimInfo.celSprite;
|
||
|
5 years ago
|
|
||
|
5 years ago
|
Displacement offset = monster.position.offset;
|
||
|
|
if (monster.IsWalking()) {
|
||
|
|
offset = GetOffsetForWalking(monster.AnimInfo, monster._mdir);
|
||
|
5 years ago
|
}
|
||
|
|
|
||
|
5 years ago
|
const Point monsterRenderPosition { targetBufferPosition + offset - Displacement { CalculateWidth2(cel.Width()), 0 } };
|
||
|
7 years ago
|
if (mi == pcursmonst) {
|
||
|
5 years ago
|
Cl2DrawOutline(out, 233, monsterRenderPosition.x, monsterRenderPosition.y, cel, monster.AnimInfo.GetFrameToUseForRendering());
|
||
|
7 years ago
|
}
|
||
|
5 years ago
|
DrawMonster(out, tilePosition, monsterRenderPosition, monster);
|
||
|
7 years ago
|
}
|
||
|
|
|
||
|
6 years ago
|
/**
|
||
|
|
* @brief Check if and how a player should be rendered
|
||
|
5 years ago
|
* @param out Output buffer
|
||
|
5 years ago
|
* @param tilePosition dPiece coordinates
|
||
|
|
* @param targetBufferPosition Output buffer coordinates
|
||
|
6 years ago
|
*/
|
||
|
5 years ago
|
void DrawPlayerHelper(const Surface &out, Point tilePosition, Point targetBufferPosition)
|
||
|
7 years ago
|
{
|
||
|
4 years ago
|
int8_t p = abs(dPlayer[tilePosition.x][tilePosition.y]) - 1;
|
||
|
7 years ago
|
|
||
|
5 years ago
|
if (p < 0 || p >= MAX_PLRS) {
|
||
|
5 years ago
|
Log("draw player: tried to draw illegal player {}", p);
|
||
|
5 years ago
|
return;
|
||
|
|
}
|
||
|
4 years ago
|
Player &player = Players[p];
|
||
|
7 years ago
|
|
||
|
5 years ago
|
Displacement offset = player.position.offset;
|
||
|
5 years ago
|
if (player.IsWalking()) {
|
||
|
|
offset = GetOffsetForWalking(player.AnimInfo, player._pdir);
|
||
|
5 years ago
|
}
|
||
|
7 years ago
|
|
||
|
5 years ago
|
const Point playerRenderPosition { targetBufferPosition + offset };
|
||
|
5 years ago
|
|
||
|
5 years ago
|
DrawPlayer(out, p, tilePosition, playerRenderPosition);
|
||
|
7 years ago
|
}
|
||
|
|
|
||
|
6 years ago
|
/**
|
||
|
6 years ago
|
* @brief Render object sprites
|
||
|
5 years ago
|
* @param out Target buffer
|
||
|
5 years ago
|
* @param tilePosition dPiece coordinates
|
||
|
|
* @param targetBufferPosition Target buffer coordinates
|
||
|
6 years ago
|
*/
|
||
|
5 years ago
|
void DrawDungeon(const Surface &out, Point tilePosition, Point targetBufferPosition)
|
||
|
8 years ago
|
{
|
||
|
4 years ago
|
assert(InDungeonBounds(tilePosition));
|
||
|
6 years ago
|
|
||
|
4 years ago
|
if (dRendered.test(tilePosition.x, tilePosition.y))
|
||
|
6 years ago
|
return;
|
||
|
4 years ago
|
dRendered.set(tilePosition.x, tilePosition.y);
|
||
|
6 years ago
|
|
||
|
5 years ago
|
LightTableIndex = dLight[tilePosition.x][tilePosition.y];
|
||
|
6 years ago
|
|
||
|
5 years ago
|
DrawCell(out, tilePosition, targetBufferPosition);
|
||
|
6 years ago
|
|
||
|
5 years ago
|
int8_t bDead = dCorpse[tilePosition.x][tilePosition.y];
|
||
|
5 years ago
|
int8_t bMap = dTransVal[tilePosition.x][tilePosition.y];
|
||
|
7 years ago
|
|
||
|
5 years ago
|
#ifdef _DEBUG
|
||
|
4 years ago
|
if (DebugVision && IsTileLit(tilePosition)) {
|
||
|
4 years ago
|
CelClippedDrawTo(out, targetBufferPosition, CelSprite { *pSquareCel }, 1);
|
||
|
7 years ago
|
}
|
||
|
5 years ago
|
#endif
|
||
|
7 years ago
|
|
||
|
7 years ago
|
if (MissilePreFlag) {
|
||
|
5 years ago
|
DrawMissile(out, tilePosition, targetBufferPosition, true);
|
||
|
7 years ago
|
}
|
||
|
7 years ago
|
|
||
|
5 years ago
|
if (LightTableIndex < LightsMax && bDead != 0) {
|
||
|
5 years ago
|
do {
|
||
|
5 years ago
|
Corpse *pDeadGuy = &Corpses[(bDead & 0x1F) - 1];
|
||
|
5 years ago
|
int px = targetBufferPosition.x - CalculateWidth2(pDeadGuy->width);
|
||
|
5 years ago
|
const byte *pCelBuff = pDeadGuy->data[(bDead >> 5) & 7];
|
||
|
5 years ago
|
assert(pCelBuff != nullptr);
|
||
|
4 years ago
|
const uint32_t frames = LoadLE32(pCelBuff);
|
||
|
4 years ago
|
const int nCel = pDeadGuy->frame;
|
||
|
|
if (nCel < 0 || frames >= 50 || nCel > static_cast<int>(frames)) {
|
||
|
5 years ago
|
Log("Unclipped dead: frame {} of {}, deadnum=={}", nCel, frames, (bDead & 0x1F) - 1);
|
||
|
5 years ago
|
break;
|
||
|
5 years ago
|
}
|
||
|
5 years ago
|
if (pDeadGuy->translationPaletteIndex != 0) {
|
||
|
4 years ago
|
uint8_t *trn = Monsters[pDeadGuy->translationPaletteIndex - 1].uniqueTRN.get();
|
||
|
|
Cl2DrawTRN(out, px, targetBufferPosition.y, CelSprite(pCelBuff, pDeadGuy->width), nCel, trn);
|
||
|
7 years ago
|
} else {
|
||
|
5 years ago
|
Cl2DrawLight(out, px, targetBufferPosition.y, CelSprite(pCelBuff, pDeadGuy->width), nCel);
|
||
|
8 years ago
|
}
|
||
|
5 years ago
|
} while (false);
|
||
|
7 years ago
|
}
|
||
|
5 years ago
|
DrawObject(out, tilePosition, targetBufferPosition, true);
|
||
|
5 years ago
|
DrawItem(out, tilePosition, targetBufferPosition, true);
|
||
|
5 years ago
|
|
||
|
4 years ago
|
if (TileContainsDeadPlayer(tilePosition)) {
|
||
|
5 years ago
|
DrawDeadPlayer(out, tilePosition, targetBufferPosition);
|
||
|
7 years ago
|
}
|
||
|
5 years ago
|
if (dPlayer[tilePosition.x][tilePosition.y] > 0) {
|
||
|
5 years ago
|
DrawPlayerHelper(out, tilePosition, targetBufferPosition);
|
||
|
8 years ago
|
}
|
||
|
5 years ago
|
if (dMonster[tilePosition.x][tilePosition.y] > 0) {
|
||
|
5 years ago
|
DrawMonsterHelper(out, tilePosition, targetBufferPosition);
|
||
|
7 years ago
|
}
|
||
|
5 years ago
|
DrawMissile(out, tilePosition, targetBufferPosition, false);
|
||
|
5 years ago
|
DrawObject(out, tilePosition, targetBufferPosition, false);
|
||
|
5 years ago
|
DrawItem(out, tilePosition, targetBufferPosition, false);
|
||
|
7 years ago
|
|
||
|
6 years ago
|
if (leveltype != DTYPE_TOWN) {
|
||
|
5 years ago
|
char bArch = dSpecial[tilePosition.x][tilePosition.y];
|
||
|
6 years ago
|
if (bArch != 0) {
|
||
|
|
cel_transparency_active = TransList[bMap];
|
||
|
5 years ago
|
#ifdef _DEBUG
|
||
|
5 years ago
|
if (GetAsyncKeyState(DVL_VK_MENU)) {
|
||
|
5 years ago
|
cel_transparency_active = false; // Turn transparency off here for debugging
|
||
|
5 years ago
|
}
|
||
|
|
#endif
|
||
|
4 years ago
|
CelClippedBlitLightTransTo(out, targetBufferPosition, CelSprite { *pSpecialCels }, bArch - 1);
|
||
|
5 years ago
|
#ifdef _DEBUG
|
||
|
5 years ago
|
if (GetAsyncKeyState(DVL_VK_MENU)) {
|
||
|
5 years ago
|
cel_transparency_active = TransList[bMap]; // Turn transparency back to its normal state
|
||
|
|
}
|
||
|
|
#endif
|
||
|
6 years ago
|
}
|
||
|
|
} else {
|
||
|
5 years ago
|
// Tree leaves should always cover player when entering or leaving the tile,
|
||
|
|
// So delay the rendering until after the next row is being drawn.
|
||
|
6 years ago
|
// This could probably have been better solved by sprites in screen space.
|
||
|
5 years ago
|
if (tilePosition.x > 0 && tilePosition.y > 0 && targetBufferPosition.y > TILE_HEIGHT) {
|
||
|
|
char bArch = dSpecial[tilePosition.x - 1][tilePosition.y - 1];
|
||
|
6 years ago
|
if (bArch != 0) {
|
||
|
4 years ago
|
CelDrawTo(out, targetBufferPosition + Displacement { 0, -TILE_HEIGHT }, CelSprite { *pSpecialCels }, bArch - 1);
|
||
|
6 years ago
|
}
|
||
|
7 years ago
|
}
|
||
|
8 years ago
|
}
|
||
|
|
}
|
||
|
|
|
||
|
6 years ago
|
/**
|
||
|
6 years ago
|
* @brief Render a row of tiles
|
||
|
5 years ago
|
* @param out Buffer to render to
|
||
|
5 years ago
|
* @param tilePosition dPiece coordinates
|
||
|
|
* @param targetBufferPosition Target buffer coordinates
|
||
|
6 years ago
|
* @param rows Number of rows
|
||
|
|
* @param columns Tile in a row
|
||
|
6 years ago
|
*/
|
||
|
5 years ago
|
void DrawFloor(const Surface &out, Point tilePosition, Point targetBufferPosition, int rows, int columns)
|
||
|
8 years ago
|
{
|
||
|
6 years ago
|
for (int i = 0; i < rows; i++) {
|
||
|
|
for (int j = 0; j < columns; j++) {
|
||
|
4 years ago
|
if (InDungeonBounds(tilePosition)) {
|
||
|
4 years ago
|
if (!TileHasAny(dPiece[tilePosition.x][tilePosition.y], TileProperties::Solid))
|
||
|
|
DrawFloor(out, tilePosition, targetBufferPosition);
|
||
|
7 years ago
|
} else {
|
||
|
5 years ago
|
world_draw_black_tile(out, targetBufferPosition.x, targetBufferPosition.y);
|
||
|
7 years ago
|
}
|
||
|
5 years ago
|
tilePosition += Direction::East;
|
||
|
5 years ago
|
targetBufferPosition.x += TILE_WIDTH;
|
||
|
6 years ago
|
}
|
||
|
|
// Return to start of row
|
||
|
5 years ago
|
tilePosition += Displacement(Direction::West) * columns;
|
||
|
5 years ago
|
targetBufferPosition.x -= columns * TILE_WIDTH;
|
||
|
6 years ago
|
|
||
|
|
// Jump to next row
|
||
|
5 years ago
|
targetBufferPosition.y += TILE_HEIGHT / 2;
|
||
|
5 years ago
|
if ((i & 1) != 0) {
|
||
|
5 years ago
|
tilePosition.x++;
|
||
|
6 years ago
|
columns--;
|
||
|
5 years ago
|
targetBufferPosition.x += TILE_WIDTH / 2;
|
||
|
7 years ago
|
} else {
|
||
|
5 years ago
|
tilePosition.y++;
|
||
|
6 years ago
|
columns++;
|
||
|
5 years ago
|
targetBufferPosition.x -= TILE_WIDTH / 2;
|
||
|
6 years ago
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
4 years ago
|
bool IsWall(Point position)
|
||
|
|
{
|
||
|
|
return TileHasAny(dPiece[position.x][position.y], TileProperties::Solid) || dSpecial[position.x][position.y] != 0;
|
||
|
|
}
|
||
|
6 years ago
|
|
||
|
6 years ago
|
/**
|
||
|
|
* @brief Render a row of tile
|
||
|
5 years ago
|
* @param out Output buffer
|
||
|
5 years ago
|
* @param tilePosition dPiece coordinates
|
||
|
|
* @param targetBufferPosition Buffer coordinates
|
||
|
6 years ago
|
* @param rows Number of rows
|
||
|
|
* @param columns Tile in a row
|
||
|
6 years ago
|
*/
|
||
|
5 years ago
|
void DrawTileContent(const Surface &out, Point tilePosition, Point targetBufferPosition, int rows, int columns)
|
||
|
6 years ago
|
{
|
||
|
6 years ago
|
// Keep evaluating until MicroTiles can't affect screen
|
||
|
|
rows += MicroTileLen;
|
||
|
4 years ago
|
dRendered.reset();
|
||
|
6 years ago
|
|
||
|
|
for (int i = 0; i < rows; i++) {
|
||
|
5 years ago
|
for (int j = 0; j < columns; j++) {
|
||
|
4 years ago
|
if (InDungeonBounds(tilePosition)) {
|
||
|
4 years ago
|
#ifdef _DEBUG
|
||
|
|
DebugCoordsMap[tilePosition.x + tilePosition.y * MAXDUNX] = targetBufferPosition;
|
||
|
|
#endif
|
||
|
5 years ago
|
if (tilePosition.x + 1 < MAXDUNX && tilePosition.y - 1 >= 0 && targetBufferPosition.x + TILE_WIDTH <= gnScreenWidth) {
|
||
|
6 years ago
|
// Render objects behind walls first to prevent sprites, that are moving
|
||
|
6 years ago
|
// between tiles, from poking through the walls as they exceed the tile bounds.
|
||
|
|
// A proper fix for this would probably be to layout the sceen and render by
|
||
|
|
// sprite screen position rather than tile position.
|
||
|
4 years ago
|
if (IsWall(tilePosition) && (IsWall(tilePosition + Displacement { 1, 0 }) || (tilePosition.x > 0 && IsWall(tilePosition + Displacement { -1, 0 })))) { // Part of a wall aligned on the x-axis
|
||
|
|
if (IsTileNotSolid(tilePosition + Displacement { 1, -1 }) && IsTileNotSolid(tilePosition + Displacement { 0, -1 })) { // Has walkable area behind it
|
||
|
5 years ago
|
DrawDungeon(out, tilePosition + Direction::East, { targetBufferPosition.x + TILE_WIDTH, targetBufferPosition.y });
|
||
|
6 years ago
|
}
|
||
|
6 years ago
|
}
|
||
|
6 years ago
|
}
|
||
|
4 years ago
|
DrawDungeon(out, tilePosition, targetBufferPosition);
|
||
|
6 years ago
|
}
|
||
|
5 years ago
|
tilePosition += Direction::East;
|
||
|
5 years ago
|
targetBufferPosition.x += TILE_WIDTH;
|
||
|
6 years ago
|
}
|
||
|
|
// Return to start of row
|
||
|
5 years ago
|
tilePosition += Displacement(Direction::West) * columns;
|
||
|
5 years ago
|
targetBufferPosition.x -= columns * TILE_WIDTH;
|
||
|
6 years ago
|
|
||
|
|
// Jump to next row
|
||
|
5 years ago
|
targetBufferPosition.y += TILE_HEIGHT / 2;
|
||
|
5 years ago
|
if ((i & 1) != 0) {
|
||
|
5 years ago
|
tilePosition.x++;
|
||
|
6 years ago
|
columns--;
|
||
|
5 years ago
|
targetBufferPosition.x += TILE_WIDTH / 2;
|
||
|
6 years ago
|
} else {
|
||
|
5 years ago
|
tilePosition.y++;
|
||
|
6 years ago
|
columns++;
|
||
|
5 years ago
|
targetBufferPosition.x -= TILE_WIDTH / 2;
|
||
|
7 years ago
|
}
|
||
|
7 years ago
|
}
|
||
|
8 years ago
|
}
|
||
|
|
|
||
|
6 years ago
|
/**
|
||
|
5 years ago
|
* @brief Scale up the top left part of the buffer 2x.
|
||
|
6 years ago
|
*/
|
||
|
5 years ago
|
void Zoom(const Surface &out)
|
||
|
8 years ago
|
{
|
||
|
5 years ago
|
int viewportWidth = out.w();
|
||
|
|
int viewportOffsetX = 0;
|
||
|
5 years ago
|
if (CanPanelsCoverView()) {
|
||
|
4 years ago
|
if (IsLeftPanelOpen()) {
|
||
|
4 years ago
|
viewportWidth -= SidePanelSize.width;
|
||
|
|
viewportOffsetX = SidePanelSize.width;
|
||
|
4 years ago
|
} else if (IsRightPanelOpen()) {
|
||
|
4 years ago
|
viewportWidth -= SidePanelSize.width;
|
||
|
6 years ago
|
}
|
||
|
|
}
|
||
|
8 years ago
|
|
||
|
5 years ago
|
// We round to even for the source width and height.
|
||
|
|
// If the width / height was odd, we copy just one extra pixel / row later on.
|
||
|
5 years ago
|
const int srcWidth = (viewportWidth + 1) / 2;
|
||
|
|
const int doubleableWidth = viewportWidth / 2;
|
||
|
|
const int srcHeight = (out.h() + 1) / 2;
|
||
|
|
const int doubleableHeight = out.h() / 2;
|
||
|
5 years ago
|
|
||
|
5 years ago
|
BYTE *src = out.at(srcWidth - 1, srcHeight - 1);
|
||
|
|
BYTE *dst = out.at(viewportOffsetX + viewportWidth - 1, out.h() - 1);
|
||
|
|
const bool oddViewportWidth = (viewportWidth % 2) == 1;
|
||
|
7 years ago
|
|
||
|
5 years ago
|
for (int hgt = 0; hgt < doubleableHeight; hgt++) {
|
||
|
5 years ago
|
// Double the pixels in the line.
|
||
|
5 years ago
|
for (int i = 0; i < doubleableWidth; i++) {
|
||
|
6 years ago
|
*dst-- = *src;
|
||
|
|
*dst-- = *src;
|
||
|
5 years ago
|
--src;
|
||
|
|
}
|
||
|
|
|
||
|
|
// Copy a single extra pixel if the output width is odd.
|
||
|
5 years ago
|
if (oddViewportWidth) {
|
||
|
5 years ago
|
*dst-- = *src;
|
||
|
|
--src;
|
||
|
6 years ago
|
}
|
||
|
5 years ago
|
|
||
|
|
// Skip the rest of the source line.
|
||
|
5 years ago
|
src -= (out.pitch() - srcWidth);
|
||
|
5 years ago
|
|
||
|
|
// Double the line.
|
||
|
5 years ago
|
memcpy(dst - out.pitch() + 1, dst + 1, viewportWidth);
|
||
|
5 years ago
|
|
||
|
|
// Skip the rest of the destination line.
|
||
|
5 years ago
|
dst -= 2 * out.pitch() - viewportWidth;
|
||
|
5 years ago
|
}
|
||
|
|
if ((out.h() % 2) == 1) {
|
||
|
5 years ago
|
memcpy(dst - out.pitch() + 1, dst + 1, viewportWidth);
|
||
|
6 years ago
|
}
|
||
|
|
}
|
||
|
7 years ago
|
|
||
|
5 years ago
|
Displacement tileOffset;
|
||
|
5 years ago
|
Displacement tileShift;
|
||
|
6 years ago
|
int tileColums;
|
||
|
|
int tileRows;
|
||
|
|
|
||
|
6 years ago
|
/**
|
||
|
|
* @brief Configure render and process screen rows
|
||
|
5 years ago
|
* @param full_out Buffer to render to
|
||
|
5 years ago
|
* @param position Center of view in dPiece coordinate
|
||
|
6 years ago
|
*/
|
||
|
5 years ago
|
void DrawGame(const Surface &fullOut, Point position)
|
||
|
6 years ago
|
{
|
||
|
|
// Limit rendering to the view area
|
||
|
5 years ago
|
const Surface &out = zoomflag
|
||
|
5 years ago
|
? fullOut.subregionY(0, gnViewportHeight)
|
||
|
|
: fullOut.subregionY(0, (gnViewportHeight + 1) / 2);
|
||
|
6 years ago
|
|
||
|
6 years ago
|
// Adjust by player offset and tile grid alignment
|
||
|
4 years ago
|
Player &myPlayer = *MyPlayer;
|
||
|
5 years ago
|
Displacement offset = ScrollInfo.offset;
|
||
|
5 years ago
|
if (myPlayer.IsWalking())
|
||
|
|
offset = GetOffsetForWalking(myPlayer.AnimInfo, myPlayer._pdir, true);
|
||
|
5 years ago
|
int sx = offset.deltaX + tileOffset.deltaX;
|
||
|
|
int sy = offset.deltaY + tileOffset.deltaY;
|
||
|
7 years ago
|
|
||
|
5 years ago
|
int columns = tileColums;
|
||
|
|
int rows = tileRows;
|
||
|
6 years ago
|
|
||
|
5 years ago
|
position += tileShift;
|
||
|
6 years ago
|
|
||
|
6 years ago
|
// Skip rendering parts covered by the panels
|
||
|
5 years ago
|
if (CanPanelsCoverView()) {
|
||
|
6 years ago
|
if (zoomflag) {
|
||
|
4 years ago
|
if (IsLeftPanelOpen()) {
|
||
|
5 years ago
|
position += Displacement(Direction::East) * 2;
|
||
|
6 years ago
|
columns -= 4;
|
||
|
4 years ago
|
sx += SidePanelSize.width - TILE_WIDTH / 2;
|
||
|
6 years ago
|
}
|
||
|
4 years ago
|
if (IsRightPanelOpen()) {
|
||
|
5 years ago
|
position += Displacement(Direction::East) * 2;
|
||
|
6 years ago
|
columns -= 4;
|
||
|
|
sx += -TILE_WIDTH / 2;
|
||
|
|
}
|
||
|
|
} else {
|
||
|
4 years ago
|
if (IsLeftPanelOpen()) {
|
||
|
5 years ago
|
position += Direction::East;
|
||
|
6 years ago
|
columns -= 2;
|
||
|
|
sx += -TILE_WIDTH / 2 / 2; // SPANEL_WIDTH accounted for in Zoom()
|
||
|
|
}
|
||
|
4 years ago
|
if (IsRightPanelOpen()) {
|
||
|
5 years ago
|
position += Direction::East;
|
||
|
6 years ago
|
columns -= 2;
|
||
|
|
sx += -TILE_WIDTH / 2 / 2;
|
||
|
6 years ago
|
}
|
||
|
7 years ago
|
}
|
||
|
7 years ago
|
}
|
||
|
|
|
||
|
5 years ago
|
UpdateMissilesRendererData();
|
||
|
|
|
||
|
5 years ago
|
// Draw areas moving in and out of the screen
|
||
|
7 years ago
|
switch (ScrollInfo._sdir) {
|
||
|
5 years ago
|
case ScrollDirection::North:
|
||
|
6 years ago
|
sy -= TILE_HEIGHT;
|
||
|
5 years ago
|
position += Direction::North;
|
||
|
6 years ago
|
rows += 2;
|
||
|
7 years ago
|
break;
|
||
|
5 years ago
|
case ScrollDirection::NorthEast:
|
||
|
6 years ago
|
sy -= TILE_HEIGHT;
|
||
|
5 years ago
|
position += Direction::North;
|
||
|
6 years ago
|
columns++;
|
||
|
|
rows += 2;
|
||
|
7 years ago
|
break;
|
||
|
5 years ago
|
case ScrollDirection::East:
|
||
|
6 years ago
|
columns++;
|
||
|
7 years ago
|
break;
|
||
|
5 years ago
|
case ScrollDirection::SouthEast:
|
||
|
6 years ago
|
columns++;
|
||
|
|
rows++;
|
||
|
7 years ago
|
break;
|
||
|
5 years ago
|
case ScrollDirection::South:
|
||
|
6 years ago
|
rows += 2;
|
||
|
7 years ago
|
break;
|
||
|
5 years ago
|
case ScrollDirection::SouthWest:
|
||
|
6 years ago
|
sx -= TILE_WIDTH;
|
||
|
5 years ago
|
position += Direction::West;
|
||
|
6 years ago
|
columns++;
|
||
|
|
rows++;
|
||
|
7 years ago
|
break;
|
||
|
5 years ago
|
case ScrollDirection::West:
|
||
|
6 years ago
|
sx -= TILE_WIDTH;
|
||
|
5 years ago
|
position += Direction::West;
|
||
|
6 years ago
|
columns++;
|
||
|
7 years ago
|
break;
|
||
|
5 years ago
|
case ScrollDirection::NorthWest:
|
||
|
6 years ago
|
sx -= TILE_WIDTH / 2;
|
||
|
|
sy -= TILE_HEIGHT / 2;
|
||
|
5 years ago
|
position += Direction::NorthWest;
|
||
|
6 years ago
|
columns++;
|
||
|
|
rows++;
|
||
|
7 years ago
|
break;
|
||
|
5 years ago
|
case ScrollDirection::None:
|
||
|
5 years ago
|
break;
|
||
|
8 years ago
|
}
|
||
|
7 years ago
|
|
||
|
5 years ago
|
DrawFloor(out, position, { sx, sy }, rows, columns);
|
||
|
5 years ago
|
DrawTileContent(out, position, { sx, sy }, rows, columns);
|
||
|
6 years ago
|
|
||
|
6 years ago
|
if (!zoomflag) {
|
||
|
5 years ago
|
Zoom(fullOut.subregionY(0, gnViewportHeight));
|
||
|
7 years ago
|
}
|
||
|
8 years ago
|
}
|
||
|
|
|
||
|
5 years ago
|
/**
|
||
|
|
* @brief Start rendering of screen, town variation
|
||
|
|
* @param out Buffer to render to
|
||
|
5 years ago
|
* @param startPosition Center of view in dPiece coordinates
|
||
|
5 years ago
|
*/
|
||
|
5 years ago
|
void DrawView(const Surface &out, Point startPosition)
|
||
|
7 years ago
|
{
|
||
|
5 years ago
|
#ifdef _DEBUG
|
||
|
|
DebugCoordsMap.clear();
|
||
|
|
#endif
|
||
|
5 years ago
|
DrawGame(out, startPosition);
|
||
|
5 years ago
|
if (AutomapActive) {
|
||
|
5 years ago
|
DrawAutomap(out.subregionY(0, gnViewportHeight));
|
||
|
7 years ago
|
}
|
||
|
5 years ago
|
#ifdef _DEBUG
|
||
|
5 years ago
|
bool debugGridTextNeeded = IsDebugGridTextNeeded();
|
||
|
|
if (debugGridTextNeeded || DebugGrid) {
|
||
|
5 years ago
|
// force redrawing or debug stuff stays on panel on 640x480 resolution
|
||
|
|
force_redraw = 255;
|
||
|
5 years ago
|
char debugGridTextBuffer[10];
|
||
|
4 years ago
|
bool megaTiles = IsDebugGridInMegatiles();
|
||
|
|
|
||
|
5 years ago
|
for (auto m : DebugCoordsMap) {
|
||
|
|
Point dunCoords = { m.first % MAXDUNX, m.first / MAXDUNX };
|
||
|
4 years ago
|
if (megaTiles && (dunCoords.x % 2 == 1 || dunCoords.y % 2 == 1))
|
||
|
|
continue;
|
||
|
5 years ago
|
Point pixelCoords = m.second;
|
||
|
4 years ago
|
if (megaTiles)
|
||
|
|
pixelCoords += Displacement { 0, TILE_HEIGHT / 2 };
|
||
|
5 years ago
|
if (!zoomflag)
|
||
|
5 years ago
|
pixelCoords *= 2;
|
||
|
5 years ago
|
if (debugGridTextNeeded && GetDebugGridText(dunCoords, debugGridTextBuffer)) {
|
||
|
5 years ago
|
Size tileSize = { TILE_WIDTH, TILE_HEIGHT };
|
||
|
|
if (!zoomflag)
|
||
|
|
tileSize *= 2;
|
||
|
5 years ago
|
DrawString(out, debugGridTextBuffer, { pixelCoords - Displacement { 0, tileSize.height }, tileSize }, UiFlags::ColorRed | UiFlags::AlignCenter | UiFlags::VerticalCenter);
|
||
|
5 years ago
|
}
|
||
|
|
if (DebugGrid) {
|
||
|
4 years ago
|
auto DrawDebugSquare = [&out](Point center, Displacement hor, Displacement ver, uint8_t col) {
|
||
|
|
auto DrawLine = [&out](Point from, Point to, uint8_t col) {
|
||
|
|
int dx = to.x - from.x;
|
||
|
|
int dy = to.y - from.y;
|
||
|
|
int steps = abs(dx) > abs(dy) ? abs(dx) : abs(dy);
|
||
|
|
float ix = dx / (float)steps;
|
||
|
|
float iy = dy / (float)steps;
|
||
|
|
float sx = from.x;
|
||
|
|
float sy = from.y;
|
||
|
|
|
||
|
|
for (int i = 0; i <= steps; i++, sx += ix, sy += iy)
|
||
|
|
out.SetPixel({ (int)sx, (int)sy }, col);
|
||
|
|
};
|
||
|
|
DrawLine(center - hor, center + ver, col);
|
||
|
|
DrawLine(center + hor, center + ver, col);
|
||
|
|
DrawLine(center - hor, center - ver, col);
|
||
|
|
DrawLine(center + hor, center - ver, col);
|
||
|
5 years ago
|
};
|
||
|
|
|
||
|
5 years ago
|
Displacement hor = { TILE_WIDTH / 2, 0 };
|
||
|
|
Displacement ver = { 0, TILE_HEIGHT / 2 };
|
||
|
|
if (!zoomflag) {
|
||
|
|
hor *= 2;
|
||
|
|
ver *= 2;
|
||
|
|
}
|
||
|
|
Point center = pixelCoords + hor - ver;
|
||
|
|
|
||
|
4 years ago
|
if (megaTiles) {
|
||
|
|
hor *= 2;
|
||
|
|
ver *= 2;
|
||
|
|
}
|
||
|
|
|
||
|
5 years ago
|
uint8_t col = PAL16_BEIGE;
|
||
|
4 years ago
|
|
||
|
|
DrawDebugSquare(center, hor, ver, col);
|
||
|
5 years ago
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
#endif
|
||
|
5 years ago
|
DrawMonsterHealthBar(out);
|
||
|
5 years ago
|
DrawItemNameLabels(out);
|
||
|
5 years ago
|
|
||
|
5 years ago
|
if (stextflag != STORE_NONE && !qtextflag)
|
||
|
5 years ago
|
DrawSText(out);
|
||
|
7 years ago
|
if (invflag) {
|
||
|
5 years ago
|
DrawInv(out);
|
||
|
7 years ago
|
} else if (sbookflag) {
|
||
|
5 years ago
|
DrawSpellBook(out);
|
||
|
7 years ago
|
}
|
||
|
|
|
||
|
5 years ago
|
DrawDurIcon(out);
|
||
|
7 years ago
|
|
||
|
|
if (chrflag) {
|
||
|
5 years ago
|
DrawChr(out);
|
||
|
5 years ago
|
} else if (QuestLogIsOpen) {
|
||
|
5 years ago
|
DrawQuestLog(out);
|
||
|
4 years ago
|
} else if (IsStashOpen) {
|
||
|
|
DrawStash(out);
|
||
|
6 years ago
|
}
|
||
|
4 years ago
|
DrawLevelUpIcon(out);
|
||
|
5 years ago
|
if (ShowUniqueItemInfoBox) {
|
||
|
5 years ago
|
DrawUniqueInfo(out);
|
||
|
7 years ago
|
}
|
||
|
|
if (qtextflag) {
|
||
|
5 years ago
|
DrawQText(out);
|
||
|
7 years ago
|
}
|
||
|
|
if (spselflag) {
|
||
|
5 years ago
|
DrawSpellList(out);
|
||
|
7 years ago
|
}
|
||
|
|
if (dropGoldFlag) {
|
||
|
5 years ago
|
DrawGoldSplit(out, dropGoldValue);
|
||
|
7 years ago
|
}
|
||
|
4 years ago
|
DrawGoldWithdraw(out, WithdrawGoldValue);
|
||
|
5 years ago
|
if (HelpFlag) {
|
||
|
5 years ago
|
DrawHelp(out);
|
||
|
7 years ago
|
}
|
||
|
4 years ago
|
if (ChatLogFlag) {
|
||
|
|
DrawChatLog(out);
|
||
|
|
}
|
||
|
5 years ago
|
if (IsDiabloMsgAvailable()) {
|
||
|
5 years ago
|
DrawDiabloMsg(out);
|
||
|
7 years ago
|
}
|
||
|
5 years ago
|
if (MyPlayerIsDead) {
|
||
|
5 years ago
|
RedBack(out);
|
||
|
7 years ago
|
} else if (PauseMode != 0) {
|
||
|
5 years ago
|
gmenu_draw_pause(out);
|
||
|
7 years ago
|
}
|
||
|
|
|
||
|
5 years ago
|
DrawControllerModifierHints(out);
|
||
|
|
DrawPlrMsg(out);
|
||
|
5 years ago
|
gmenu_draw(out);
|
||
|
|
doom_draw(out);
|
||
|
5 years ago
|
DrawInfoBox(out);
|
||
|
5 years ago
|
control_update_life_mana(); // Update life/mana totals before rendering any portion of the flask.
|
||
|
|
DrawLifeFlaskUpper(out);
|
||
|
|
DrawManaFlaskUpper(out);
|
||
|
8 years ago
|
}
|
||
|
|
|
||
|
6 years ago
|
/**
|
||
|
5 years ago
|
* @brief Display the current average FPS over 1 sec
|
||
|
6 years ago
|
*/
|
||
|
5 years ago
|
void DrawFPS(const Surface &out)
|
||
|
8 years ago
|
{
|
||
|
5 years ago
|
char string[12];
|
||
|
8 years ago
|
|
||
|
5 years ago
|
if (!frameflag || !gbActive) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
frameend++;
|
||
|
|
uint32_t tc = SDL_GetTicks();
|
||
|
|
uint32_t frames = tc - framestart;
|
||
|
|
if (tc - framestart >= 1000) {
|
||
|
|
framestart = tc;
|
||
|
|
framerate = 1000 * frameend / frames;
|
||
|
|
frameend = 0;
|
||
|
|
}
|
||
|
|
snprintf(string, 12, "%i FPS", framerate);
|
||
|
4 years ago
|
DrawString(out, string, Point { 8, 68 }, UiFlags::ColorRed);
|
||
|
5 years ago
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @brief Update part of the screen from the back buffer
|
||
|
|
* @param dwX Back buffer coordinate
|
||
|
|
* @param dwY Back buffer coordinate
|
||
|
|
* @param dwWdt Back buffer coordinate
|
||
|
|
* @param dwHgt Back buffer coordinate
|
||
|
|
*/
|
||
|
5 years ago
|
void DoBlitScreen(Sint16 dwX, Sint16 dwY, Uint16 dwWdt, Uint16 dwHgt)
|
||
|
5 years ago
|
{
|
||
|
|
// In SDL1 SDL_Rect x and y are Sint16. Cast explicitly to avoid a compiler warning.
|
||
|
|
using CoordType = decltype(SDL_Rect {}.x);
|
||
|
|
SDL_Rect srcRect {
|
||
|
|
static_cast<CoordType>(dwX),
|
||
|
|
static_cast<CoordType>(dwY),
|
||
|
|
dwWdt, dwHgt
|
||
|
|
};
|
||
|
|
SDL_Rect dstRect { dwX, dwY, dwWdt, dwHgt };
|
||
|
|
|
||
|
|
BltFast(&srcRect, &dstRect);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @brief Check render pipeline and blit individual screen parts
|
||
|
|
* @param dwHgt Section of screen to update from top to bottom
|
||
|
|
* @param draw_desc Render info box
|
||
|
|
* @param draw_hp Render health bar
|
||
|
|
* @param draw_mana Render mana bar
|
||
|
|
* @param draw_sbar Render belt
|
||
|
|
* @param draw_btn Render panel buttons
|
||
|
|
*/
|
||
|
5 years ago
|
void DrawMain(int dwHgt, bool drawDesc, bool drawHp, bool drawMana, bool drawSbar, bool drawBtn)
|
||
|
5 years ago
|
{
|
||
|
|
if (!gbActive || RenderDirectlyToOutputSurface) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
assert(dwHgt >= 0 && dwHgt <= gnScreenHeight);
|
||
|
|
|
||
|
|
if (dwHgt > 0) {
|
||
|
|
DoBlitScreen(0, 0, gnScreenWidth, dwHgt);
|
||
|
|
}
|
||
|
|
if (dwHgt < gnScreenHeight) {
|
||
|
4 years ago
|
const Point mainPanelPosition = GetMainPanel().position;
|
||
|
5 years ago
|
if (drawSbar) {
|
||
|
4 years ago
|
DoBlitScreen(mainPanelPosition.x + 204, mainPanelPosition.y + 5, 232, 28);
|
||
|
5 years ago
|
}
|
||
|
|
if (drawDesc) {
|
||
|
4 years ago
|
DoBlitScreen(mainPanelPosition.x + 176, mainPanelPosition.y + 46, 288, 63);
|
||
|
5 years ago
|
}
|
||
|
|
if (drawMana) {
|
||
|
4 years ago
|
DoBlitScreen(mainPanelPosition.x + 460, mainPanelPosition.y, 88, 72);
|
||
|
|
DoBlitScreen(mainPanelPosition.x + 564, mainPanelPosition.y + 64, 56, 56);
|
||
|
5 years ago
|
}
|
||
|
|
if (drawHp) {
|
||
|
4 years ago
|
DoBlitScreen(mainPanelPosition.x + 96, mainPanelPosition.y, 88, 72);
|
||
|
5 years ago
|
}
|
||
|
|
if (drawBtn) {
|
||
|
4 years ago
|
DoBlitScreen(mainPanelPosition.x + 8, mainPanelPosition.y + 5, 72, 119);
|
||
|
|
DoBlitScreen(mainPanelPosition.x + 556, mainPanelPosition.y + 5, 72, 48);
|
||
|
5 years ago
|
if (gbIsMultiplayer) {
|
||
|
4 years ago
|
DoBlitScreen(mainPanelPosition.x + 84, mainPanelPosition.y + 91, 36, 32);
|
||
|
|
DoBlitScreen(mainPanelPosition.x + 524, mainPanelPosition.y + 91, 36, 32);
|
||
|
5 years ago
|
}
|
||
|
|
}
|
||
|
|
if (sgdwCursWdtOld != 0) {
|
||
|
|
DoBlitScreen(sgdwCursXOld, sgdwCursYOld, sgdwCursWdtOld, sgdwCursHgtOld);
|
||
|
|
}
|
||
|
|
if (sgdwCursWdt != 0) {
|
||
|
|
DoBlitScreen(sgdwCursX, sgdwCursY, sgdwCursWdt, sgdwCursHgt);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
} // namespace
|
||
|
|
|
||
|
|
Displacement GetOffsetForWalking(const AnimationInfo &animationInfo, const Direction dir, bool cameraMode /*= false*/)
|
||
|
|
{
|
||
|
|
// clang-format off
|
||
|
5 years ago
|
// South, SouthWest, West, NorthWest, North, NorthEast, East, SouthEast,
|
||
|
5 years ago
|
constexpr Displacement StartOffset[8] = { { 0, -32 }, { 32, -16 }, { 64, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { -64, 0 }, { -32, -16 } };
|
||
|
5 years ago
|
constexpr Displacement MovingOffset[8] = { { 0, 32 }, { -32, 16 }, { -64, 0 }, { -32, -16 }, { 0, -32 }, { 32, -16 }, { 64, 0 }, { 32, 16 } };
|
||
|
|
// clang-format on
|
||
|
|
|
||
|
|
float fAnimationProgress = animationInfo.GetAnimationProgress();
|
||
|
5 years ago
|
Displacement offset = MovingOffset[static_cast<size_t>(dir)];
|
||
|
5 years ago
|
offset *= fAnimationProgress;
|
||
|
|
|
||
|
|
if (cameraMode) {
|
||
|
|
offset = -offset;
|
||
|
|
} else {
|
||
|
5 years ago
|
offset += StartOffset[static_cast<size_t>(dir)];
|
||
|
5 years ago
|
}
|
||
|
|
|
||
|
|
return offset;
|
||
|
|
}
|
||
|
|
|
||
|
|
void ClearCursor() // CODE_FIX: this was supposed to be in cursor.cpp
|
||
|
|
{
|
||
|
|
sgdwCursWdt = 0;
|
||
|
|
sgdwCursWdtOld = 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
void ShiftGrid(int *x, int *y, int horizontal, int vertical)
|
||
|
|
{
|
||
|
|
*x += vertical + horizontal;
|
||
|
|
*y += vertical - horizontal;
|
||
|
|
}
|
||
|
|
|
||
|
|
int RowsCoveredByPanel()
|
||
|
|
{
|
||
|
4 years ago
|
auto &mainPanelSize = GetMainPanel().size;
|
||
|
|
if (GetScreenWidth() <= mainPanelSize.width) {
|
||
|
5 years ago
|
return 0;
|
||
|
|
}
|
||
|
|
|
||
|
4 years ago
|
int rows = mainPanelSize.height / TILE_HEIGHT;
|
||
|
5 years ago
|
if (!zoomflag) {
|
||
|
|
rows /= 2;
|
||
|
|
}
|
||
|
|
|
||
|
|
return rows;
|
||
|
|
}
|
||
|
|
|
||
|
|
void CalcTileOffset(int *offsetX, int *offsetY)
|
||
|
|
{
|
||
|
4 years ago
|
uint16_t screenWidth = GetScreenWidth();
|
||
|
|
uint16_t viewportHeight = GetViewportHeight();
|
||
|
|
|
||
|
5 years ago
|
int x;
|
||
|
|
int y;
|
||
|
|
|
||
|
|
if (zoomflag) {
|
||
|
4 years ago
|
x = screenWidth % TILE_WIDTH;
|
||
|
|
y = viewportHeight % TILE_HEIGHT;
|
||
|
5 years ago
|
} else {
|
||
|
4 years ago
|
x = (screenWidth / 2) % TILE_WIDTH;
|
||
|
|
y = (viewportHeight / 2) % TILE_HEIGHT;
|
||
|
5 years ago
|
}
|
||
|
|
|
||
|
|
if (x != 0)
|
||
|
|
x = (TILE_WIDTH - x) / 2;
|
||
|
|
if (y != 0)
|
||
|
|
y = (TILE_HEIGHT - y) / 2;
|
||
|
|
|
||
|
|
*offsetX = x;
|
||
|
|
*offsetY = y;
|
||
|
|
}
|
||
|
|
|
||
|
|
void TilesInView(int *rcolumns, int *rrows)
|
||
|
|
{
|
||
|
4 years ago
|
uint16_t screenWidth = GetScreenWidth();
|
||
|
|
uint16_t viewportHeight = GetViewportHeight();
|
||
|
|
|
||
|
|
int columns = screenWidth / TILE_WIDTH;
|
||
|
|
if ((screenWidth % TILE_WIDTH) != 0) {
|
||
|
5 years ago
|
columns++;
|
||
|
|
}
|
||
|
4 years ago
|
int rows = viewportHeight / TILE_HEIGHT;
|
||
|
|
if ((viewportHeight % TILE_HEIGHT) != 0) {
|
||
|
5 years ago
|
rows++;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (!zoomflag) {
|
||
|
|
// Half the number of tiles, rounded up
|
||
|
|
if ((columns & 1) != 0) {
|
||
|
|
columns++;
|
||
|
|
}
|
||
|
|
columns /= 2;
|
||
|
|
if ((rows & 1) != 0) {
|
||
|
|
rows++;
|
||
|
|
}
|
||
|
|
rows /= 2;
|
||
|
|
}
|
||
|
|
|
||
|
|
*rcolumns = columns;
|
||
|
|
*rrows = rows;
|
||
|
|
}
|
||
|
|
|
||
|
|
void CalcViewportGeometry()
|
||
|
|
{
|
||
|
5 years ago
|
tileShift = { 0, 0 };
|
||
|
5 years ago
|
|
||
|
|
// Adjust by player offset and tile grid alignment
|
||
|
|
int xo = 0;
|
||
|
|
int yo = 0;
|
||
|
|
CalcTileOffset(&xo, &yo);
|
||
|
5 years ago
|
tileOffset = { -xo, -yo - 1 + TILE_HEIGHT / 2 };
|
||
|
5 years ago
|
|
||
|
|
TilesInView(&tileColums, &tileRows);
|
||
|
|
int lrow = tileRows - RowsCoveredByPanel();
|
||
|
|
|
||
|
|
// Center player tile on screen
|
||
|
5 years ago
|
tileShift += Displacement(Direction::West) * (tileColums / 2);
|
||
|
|
tileShift += Displacement(Direction::North) * (lrow / 2);
|
||
|
5 years ago
|
|
||
|
|
tileRows *= 2;
|
||
|
|
|
||
|
|
// Align grid
|
||
|
|
if ((tileColums & 1) == 0) {
|
||
|
5 years ago
|
tileShift.deltaY--; // Shift player row to one that can be centered with out pixel offset
|
||
|
5 years ago
|
if ((lrow & 1) == 0) {
|
||
|
|
// Offset tile to vertically align the player when both rows and colums are even
|
||
|
|
tileRows++;
|
||
|
5 years ago
|
tileOffset.deltaY -= TILE_HEIGHT / 2;
|
||
|
5 years ago
|
}
|
||
|
|
} else if ((tileColums & 1) != 0 && (lrow & 1) != 0) {
|
||
|
|
// Offset tile to vertically align the player when both rows and colums are odd
|
||
|
5 years ago
|
tileShift += Displacement(Direction::North);
|
||
|
5 years ago
|
tileRows++;
|
||
|
5 years ago
|
tileOffset.deltaY -= TILE_HEIGHT / 2;
|
||
|
5 years ago
|
}
|
||
|
|
|
||
|
|
// Slightly lower the zoomed view
|
||
|
|
if (!zoomflag) {
|
||
|
5 years ago
|
tileOffset.deltaY += TILE_HEIGHT / 4;
|
||
|
5 years ago
|
if (yo < TILE_HEIGHT / 4)
|
||
|
|
tileRows++;
|
||
|
|
}
|
||
|
|
|
||
|
|
tileRows++; // Cover lower edge saw tooth, right edge accounted for in scrollrt_draw()
|
||
|
|
}
|
||
|
|
|
||
|
5 years ago
|
extern SDL_Surface *PalSurface;
|
||
|
5 years ago
|
|
||
|
|
void ClearScreenBuffer()
|
||
|
|
{
|
||
|
5 years ago
|
assert(PalSurface != nullptr);
|
||
|
|
SDL_FillRect(PalSurface, nullptr, 0);
|
||
|
8 years ago
|
}
|
||
|
|
|
||
|
|
#ifdef _DEBUG
|
||
|
7 years ago
|
void ScrollView()
|
||
|
8 years ago
|
{
|
||
|
5 years ago
|
bool scroll;
|
||
|
7 years ago
|
|
||
|
4 years ago
|
if (!MyPlayer->HoldItem.isEmpty())
|
||
|
7 years ago
|
return;
|
||
|
|
|
||
|
5 years ago
|
scroll = false;
|
||
|
7 years ago
|
|
||
|
5 years ago
|
if (MousePosition.x < 20) {
|
||
|
5 years ago
|
if (dmaxPosition.y - 1 <= ViewPosition.y || dminPosition.x >= ViewPosition.x) {
|
||
|
|
if (dmaxPosition.y - 1 > ViewPosition.y) {
|
||
|
5 years ago
|
ViewPosition.y++;
|
||
|
5 years ago
|
scroll = true;
|
||
|
7 years ago
|
}
|
||
|
5 years ago
|
if (dminPosition.x < ViewPosition.x) {
|
||
|
5 years ago
|
ViewPosition.x--;
|
||
|
5 years ago
|
scroll = true;
|
||
|
8 years ago
|
}
|
||
|
7 years ago
|
} else {
|
||
|
5 years ago
|
ViewPosition.y++;
|
||
|
|
ViewPosition.x--;
|
||
|
5 years ago
|
scroll = true;
|
||
|
8 years ago
|
}
|
||
|
7 years ago
|
}
|
||
|
5 years ago
|
if (MousePosition.x > gnScreenWidth - 20) {
|
||
|
5 years ago
|
if (dmaxPosition.x - 1 <= ViewPosition.x || dminPosition.y >= ViewPosition.y) {
|
||
|
|
if (dmaxPosition.x - 1 > ViewPosition.x) {
|
||
|
5 years ago
|
ViewPosition.x++;
|
||
|
5 years ago
|
scroll = true;
|
||
|
8 years ago
|
}
|
||
|
5 years ago
|
if (dminPosition.y < ViewPosition.y) {
|
||
|
5 years ago
|
ViewPosition.y--;
|
||
|
5 years ago
|
scroll = true;
|
||
|
8 years ago
|
}
|
||
|
7 years ago
|
} else {
|
||
|
5 years ago
|
ViewPosition.y--;
|
||
|
|
ViewPosition.x++;
|
||
|
5 years ago
|
scroll = true;
|
||
|
8 years ago
|
}
|
||
|
7 years ago
|
}
|
||
|
5 years ago
|
if (MousePosition.y < 20) {
|
||
|
5 years ago
|
if (dminPosition.y >= ViewPosition.y || dminPosition.x >= ViewPosition.x) {
|
||
|
|
if (dminPosition.y < ViewPosition.y) {
|
||
|
5 years ago
|
ViewPosition.y--;
|
||
|
5 years ago
|
scroll = true;
|
||
|
8 years ago
|
}
|
||
|
5 years ago
|
if (dminPosition.x < ViewPosition.x) {
|
||
|
5 years ago
|
ViewPosition.x--;
|
||
|
5 years ago
|
scroll = true;
|
||
|
8 years ago
|
}
|
||
|
7 years ago
|
} else {
|
||
|
5 years ago
|
ViewPosition.x--;
|
||
|
|
ViewPosition.y--;
|
||
|
5 years ago
|
scroll = true;
|
||
|
8 years ago
|
}
|
||
|
7 years ago
|
}
|
||
|
5 years ago
|
if (MousePosition.y > gnScreenHeight - 20) {
|
||
|
5 years ago
|
if (dmaxPosition.y - 1 <= ViewPosition.y || dmaxPosition.x - 1 <= ViewPosition.x) {
|
||
|
|
if (dmaxPosition.y - 1 > ViewPosition.y) {
|
||
|
5 years ago
|
ViewPosition.y++;
|
||
|
5 years ago
|
scroll = true;
|
||
|
7 years ago
|
}
|
||
|
5 years ago
|
if (dmaxPosition.x - 1 > ViewPosition.x) {
|
||
|
5 years ago
|
ViewPosition.x++;
|
||
|
5 years ago
|
scroll = true;
|
||
|
8 years ago
|
}
|
||
|
7 years ago
|
} else {
|
||
|
5 years ago
|
ViewPosition.x++;
|
||
|
|
ViewPosition.y++;
|
||
|
5 years ago
|
scroll = true;
|
||
|
8 years ago
|
}
|
||
|
|
}
|
||
|
7 years ago
|
|
||
|
7 years ago
|
if (scroll)
|
||
|
5 years ago
|
ScrollInfo._sdir = ScrollDirection::None;
|
||
|
8 years ago
|
}
|
||
|
6 years ago
|
#endif
|
||
|
8 years ago
|
|
||
|
7 years ago
|
void EnableFrameCount()
|
||
|
8 years ago
|
{
|
||
|
4 years ago
|
frameflag = true;
|
||
|
6 years ago
|
framestart = SDL_GetTicks();
|
||
|
8 years ago
|
}
|
||
|
|
|
||
|
5 years ago
|
void scrollrt_draw_game_screen()
|
||
|
8 years ago
|
{
|
||
|
5 years ago
|
int hgt = 0;
|
||
|
8 years ago
|
|
||
|
6 years ago
|
if (force_redraw == 255) {
|
||
|
|
force_redraw = 0;
|
||
|
5 years ago
|
hgt = gnScreenHeight;
|
||
|
8 years ago
|
}
|
||
|
|
|
||
|
5 years ago
|
if (IsHardwareCursor()) {
|
||
|
5 years ago
|
SetHardwareCursorVisible(ShouldShowCursor());
|
||
|
|
} else {
|
||
|
5 years ago
|
DrawCursor(GlobalBackBuffer());
|
||
|
7 years ago
|
}
|
||
|
7 years ago
|
|
||
|
5 years ago
|
DrawMain(hgt, false, false, false, false, false);
|
||
|
7 years ago
|
|
||
|
5 years ago
|
RenderPresent();
|
||
|
|
|
||
|
5 years ago
|
if (!IsHardwareCursor()) {
|
||
|
5 years ago
|
UndrawCursor(GlobalBackBuffer());
|
||
|
7 years ago
|
}
|
||
|
8 years ago
|
}
|
||
|
|
|
||
|
7 years ago
|
void DrawAndBlit()
|
||
|
8 years ago
|
{
|
||
|
7 years ago
|
if (!gbRunGame) {
|
||
|
7 years ago
|
return;
|
||
|
8 years ago
|
}
|
||
|
7 years ago
|
|
||
|
5 years ago
|
int hgt = 0;
|
||
|
|
bool ddsdesc = false;
|
||
|
|
bool ctrlPan = false;
|
||
|
|
|
||
|
4 years ago
|
const Rectangle &mainPanel = GetMainPanel();
|
||
|
|
|
||
|
|
if (gnScreenWidth > mainPanel.size.width || force_redraw == 255 || IsHighlightingLabelsEnabled()) {
|
||
|
5 years ago
|
drawhpflag = true;
|
||
|
|
drawmanaflag = true;
|
||
|
|
drawbtnflag = true;
|
||
|
|
drawsbarflag = true;
|
||
|
5 years ago
|
ddsdesc = false;
|
||
|
|
ctrlPan = true;
|
||
|
5 years ago
|
hgt = gnScreenHeight;
|
||
|
5 years ago
|
} else if (force_redraw == 1) {
|
||
|
5 years ago
|
ddsdesc = true;
|
||
|
|
ctrlPan = false;
|
||
|
5 years ago
|
hgt = gnViewportHeight;
|
||
|
7 years ago
|
}
|
||
|
|
|
||
|
6 years ago
|
force_redraw = 0;
|
||
|
7 years ago
|
|
||
|
5 years ago
|
const Surface &out = GlobalBackBuffer();
|
||
|
5 years ago
|
UndrawCursor(out);
|
||
|
5 years ago
|
|
||
|
5 years ago
|
nthread_UpdateProgressToNextGameTick();
|
||
|
|
|
||
|
5 years ago
|
DrawView(out, ViewPosition);
|
||
|
7 years ago
|
if (ctrlPan) {
|
||
|
5 years ago
|
DrawCtrlPan(out);
|
||
|
7 years ago
|
}
|
||
|
7 years ago
|
if (drawhpflag) {
|
||
|
5 years ago
|
DrawLifeFlaskLower(out);
|
||
|
7 years ago
|
}
|
||
|
7 years ago
|
if (drawmanaflag) {
|
||
|
5 years ago
|
DrawManaFlaskLower(out);
|
||
|
|
|
||
|
|
DrawSpell(out);
|
||
|
7 years ago
|
}
|
||
|
7 years ago
|
if (drawbtnflag) {
|
||
|
5 years ago
|
DrawCtrlBtns(out);
|
||
|
7 years ago
|
}
|
||
|
7 years ago
|
if (drawsbarflag) {
|
||
|
5 years ago
|
DrawInvBelt(out);
|
||
|
7 years ago
|
}
|
||
|
7 years ago
|
if (talkflag) {
|
||
|
5 years ago
|
DrawTalkPan(out);
|
||
|
5 years ago
|
hgt = gnScreenHeight;
|
||
|
7 years ago
|
}
|
||
|
5 years ago
|
DrawXPBar(out);
|
||
|
4 years ago
|
if (*sgOptions.Graphics.showHealthValues)
|
||
|
4 years ago
|
DrawFlaskValues(out, { mainPanel.position.x + 134, mainPanel.position.y + 28 }, MyPlayer->_pHitPoints >> 6, MyPlayer->_pMaxHP >> 6);
|
||
|
4 years ago
|
if (*sgOptions.Graphics.showManaValues)
|
||
|
4 years ago
|
DrawFlaskValues(out, { mainPanel.position.x + mainPanel.size.width - 138, mainPanel.position.y + 28 }, MyPlayer->_pMana >> 6, MyPlayer->_pMaxMana >> 6);
|
||
|
5 years ago
|
|
||
|
5 years ago
|
if (IsHardwareCursor()) {
|
||
|
5 years ago
|
SetHardwareCursorVisible(ShouldShowCursor());
|
||
|
|
} else {
|
||
|
|
DrawCursor(out);
|
||
|
|
}
|
||
|
6 years ago
|
|
||
|
5 years ago
|
DrawFPS(out);
|
||
|
6 years ago
|
|
||
|
7 years ago
|
DrawMain(hgt, ddsdesc, drawhpflag, drawmanaflag, drawsbarflag, drawbtnflag);
|
||
|
|
|
||
|
6 years ago
|
RenderPresent();
|
||
|
7 years ago
|
|
||
|
5 years ago
|
drawhpflag = false;
|
||
|
|
drawmanaflag = false;
|
||
|
|
drawbtnflag = false;
|
||
|
|
drawsbarflag = false;
|
||
|
8 years ago
|
}
|
||
|
7 years ago
|
|
||
|
5 years ago
|
} // namespace devilution
|