Skip to content

Commit

Permalink
connected rendering both types of lichen (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
chucksellick committed Feb 25, 2025
1 parent 4fb6461 commit ad3e625
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 52 deletions.
17 changes: 11 additions & 6 deletions crawl-ref/source/rltiles/dc-mon.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1214,15 +1214,20 @@ wandering_mushroom MONS_WANDERING_MUSHROOM
deathcap MONS_DEATHCAP
sleepcap MONS_SLEEPCAP

wolf_lichen MONS_WOLF_LICHEN
wolf_lichen_n_s MONS_WOLF_LICHEN_N_S
wolf_lichen_w_e MONS_WOLF_LICHEN_W_E
wolf_lichen_nw_se MONS_WOLF_LICHEN_NW_SE
wolf_lichen_ne_sw MONS_WOLF_LICHEN_NE_SW

%rim 1
%sdir misc
mold_glowing1 MONS_WOLF_LICHEN
mold_glowing2
mold_glowing3
mold_glowing4
wolf_lichen MONS_WOLF_LICHEN_MASK
wolf_lichen_n_s MONS_WOLF_LICHEN_N_S_MASK
wolf_lichen_w_e MONS_WOLF_LICHEN_W_E_MASK
wolf_lichen_nw_se MONS_WOLF_LICHEN_NW_SE_MASK
wolf_lichen_ne_sw MONS_WOLF_LICHEN_NE_SW_MASK

%rim 0
%sdir mon/fungi_plants
cobalt_lichen MONS_COBALT_LICHEN
cobalt_lichen_n_s MONS_COBALT_LICHEN_N_S
cobalt_lichen_w_e MONS_COBALT_LICHEN_W_E
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 7 additions & 3 deletions crawl-ref/source/tilecell.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,13 @@ struct packed_cell
tileidx_t bg;
tileidx_t cloud;
set<tileidx_t> icons;
// Four tiles to use as border connectors; they correspond to NE,E,SE,S in
// order (the other 4 borders are handled by tiles to the north and/or west).
FixedVector<int, 4> fg_underlay = {0,0,0,0};


// Four tiles to use to render around the edges and corners; they correspond
// to S-SE-E-NE in order. For performance each tile only deals with 4 edges,
// the other 4 are handled by the tiles to the N, NW, W and SW.
FixedVector<int, 4> edges = {0,0,0,0};
FixedVector<int, 4> edge_masks = {0,0,0,0};

bool operator ==(const packed_cell &other) const;
bool operator !=(const packed_cell &other) const { return !(*this == other); }
Expand Down
25 changes: 14 additions & 11 deletions crawl-ref/source/tiledgnbuf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ void DungeonCellBuffer::add_glyph(const char32_t &g, const VColour &col, const V
m_buf_glyphs.get_font_wrapper().store(m_buf_glyphs, sx, sy, g, col, bg);
}

static const struct coord_def _buf_offset_coords[] = {
{0,16}, {16,16}, {16,0}, {16,-16},
};

void DungeonCellBuffer::add(const packed_cell &cell, int x, int y)
{
static const coord_def edge_offsets[] = {
{0,16}, {16,16}, {16,0}, {16,-16},
};

pack_background(x, y, cell);

const tileidx_t fg_idx = cell.fg & TILE_FLAG_MASK;
Expand All @@ -69,14 +69,17 @@ void DungeonCellBuffer::add(const packed_cell &cell, int x, int y)

for (int n=0; n < 4; n++)
{
if (cell.fg_underlay[n])
if (cell.edges[n])
{
m_buf_doll.add(cell.edges[n], x, y, 1, false, false,
edge_offsets[n].x, edge_offsets[n].y);
}
if (cell.edge_masks[n])
{
m_buf_doll.add(cell.fg_underlay[n], x, y, 1, false, false,
_buf_offset_coords[n].x, _buf_offset_coords[n].y);
// Mask layer at lower z-index (to add rim around the connector)
m_buf_doll.add(cell.fg_underlay[n] + TILEP_MONS_COBALT_LICHEN_MASK
- TILEP_MONS_COBALT_LICHEN, x, y, -2, false, false,
_buf_offset_coords[n].x, _buf_offset_coords[n].y);
// Add mask layer at lower z-index. This allows us to build up an
// outline for a shape that is made up of several tiles and edges.
m_buf_doll.add(cell.edge_masks[n], x, y, -2, false, false,
edge_offsets[n].x, edge_offsets[n].y);
}
}

Expand Down
122 changes: 90 additions & 32 deletions crawl-ref/source/view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1696,41 +1696,99 @@ crawl_view_buffer view_dungeon(animation *a, bool anim_updates, view_renderer *r
return vbuf;
}

static void _pack_underlays(coord_def gc, packed_cell& cell, const monster_info& mon)
static bool _has_edge_tiles(monster_type type)
{
if (!in_bounds(gc))
switch (mons_species(type))
{
case MONS_WOLF_LICHEN:
case MONS_COBALT_LICHEN:
return true;
default:
return false;
}
}

static int _determine_edge_tile(const monster_info& origin,
const monster_info& connected, int dx, int dy)
{
auto species = mons_species(connected.type);
if (species != mons_species(origin.type))
return 0;

switch (species)
{
case MONS_WOLF_LICHEN:
return dx == 0 ? TILEP_MONS_WOLF_LICHEN_N_S
: dy == 0 ? TILEP_MONS_WOLF_LICHEN_W_E
: dy == 1 ? TILEP_MONS_WOLF_LICHEN_NW_SE
: TILEP_MONS_WOLF_LICHEN_NE_SW;
case MONS_COBALT_LICHEN:
return dx == 0 ? TILEP_MONS_COBALT_LICHEN_N_S
: dy == 0 ? TILEP_MONS_COBALT_LICHEN_W_E
: dy == 1 ? TILEP_MONS_COBALT_LICHEN_NW_SE
: TILEP_MONS_COBALT_LICHEN_NE_SW;
// Shouldn't get here unless _has_edge_tiles is wrong
default:
return 0;
}
}

static int _mask_tile_for(int tile_idx)
{
if (tile_idx >= TILEP_MONS_WOLF_LICHEN && tile_idx <= TILEP_MONS_WOLF_LICHEN_NE_SW)
return tile_idx + (TILEP_MONS_WOLF_LICHEN_NE_SW - TILEP_MONS_WOLF_LICHEN) + 1;

if (tile_idx >= TILEP_MONS_COBALT_LICHEN && tile_idx <= TILEP_MONS_COBALT_LICHEN_NE_SW)
return tile_idx + (TILEP_MONS_COBALT_LICHEN_NE_SW - TILEP_MONS_COBALT_LICHEN) + 1;

// Special cobalt units all just use the base mask
if (tile_idx >= TILEP_MONS_COBALT_LICHEN_EYESTALK
&& tile_idx <= TILEP_MONS_COBALT_LICHEN_SAC)
{
return TILEP_MONS_COBALT_LICHEN_MASK;
}

return 0;
}

static void _pack_edges(coord_def gc, packed_cell& cell, const monster_info& mon)
{
if (!in_bounds(gc) || !_has_edge_tiles(mon.type))
return;
if (mons_species(mon.type) == MONS_COBALT_LICHEN)
int edge_num = -1;
for (adjacent_iterator ri(gc, true); ri; ++ri)
{
int underlay_num = -1;
for (adjacent_iterator ri(gc, true); ri; ++ri)
{
int dx = ri->x - gc.x;
if (dx < 0)
continue;
int dy = ri->y - gc.y;
if (dy < 0 && dx < 1)
continue;
underlay_num++;
cell.fg_underlay[underlay_num] = 0;
// Get the delta to this tile
int dx = ri->x - gc.x;
// Not interested in NW, W, or SW - those edges are handled by the
// tiles in that direction
if (dx < 0)
continue;
int dy = ri->y - gc.y;
// We also let N edge be handled by tile to the N
if (dy < 0 && dx < 1)
continue;
// Now this is one of the 4 edges we handle
edge_num++;
cell.edges[edge_num] = 0;

if (!map_bounds(*ri))
continue;
const map_cell& adj_knowledge = env.map_knowledge(*ri);
if (!adj_knowledge.seen() && !adj_knowledge.mapped())
continue;
// Now we know this is a connection we *might* want to check, see if
// there's an applicable monster there first
if (!adj_knowledge.monsterinfo()
|| mons_species(adj_knowledge.monsterinfo()->type) != MONS_COBALT_LICHEN)
{
continue;
}
cell.fg_underlay[underlay_num] = dx == 0 ? TILEP_MONS_COBALT_LICHEN_N_S
: dy == 0 ? TILEP_MONS_COBALT_LICHEN_W_E
: dy == 1 ? TILEP_MONS_COBALT_LICHEN_NW_SE
: TILEP_MONS_COBALT_LICHEN_NE_SW;
}
if (!in_bounds(*ri))
continue;
const map_cell& adj_knowledge = env.map_knowledge(*ri);
if (!adj_knowledge.seen() && !adj_knowledge.mapped())
continue;
// Now we know this is a connection we *might* want to check, see if
// there's an applicable monster there first
auto connected = adj_knowledge.monsterinfo();
if (!connected)
continue;
int edge = _determine_edge_tile(mon, *connected, dx, dy);
if (!edge)
continue;
cell.edges[edge_num] = edge;
// Add mask layer at lower z-index. This allows us to build up an
// outline for a shape that is made up of several tiles and edges.
cell.edge_masks[edge_num] = _mask_tile_for(cell.edges[edge_num]);
}
}

Expand Down Expand Up @@ -1763,7 +1821,7 @@ void draw_cell(screen_cell_t *cell, const coord_def &gc,
cell->flash_colour = BLACK;
cell->flash_alpha = 0;
if (cell->tile.map_knowledge.monsterinfo())
_pack_underlays(gc, cell->tile, *cell->tile.map_knowledge.monsterinfo());
_pack_edges(gc, cell->tile, *cell->tile.map_knowledge.monsterinfo());
#endif

// Don't hide important information by recolouring monsters.
Expand Down

0 comments on commit ad3e625

Please sign in to comment.