Skip to content

Commit

Permalink
move layer draw to f3_state, switch pixel-based drawing to line-based
Browse files Browse the repository at this point in the history
  • Loading branch information
y-ack committed Dec 3, 2023
1 parent 567acf2 commit 0cd76a1
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 22 deletions.
7 changes: 3 additions & 4 deletions src/mame/taito/taito_f3.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ class taito_f3_state : public driver_device

inline bool operator<(const mixable& rhs) const noexcept { return this->prio() < rhs.prio(); };
inline bool operator>(const mixable& rhs) const noexcept { return this->prio() > rhs.prio(); };
virtual void draw(u32* dst, int x, int y) {};
};

struct sprite_inf : mixable {
Expand All @@ -221,7 +220,6 @@ class taito_f3_state : public driver_device
bitmap_rgb32 srcbitmap{};

bool brightness; // 7400 0xf000
void draw(u32* dst, int x, int y) override;
};

struct pivot_inf : mixable {
Expand All @@ -239,7 +237,6 @@ class taito_f3_state : public driver_device
struct playfield_inf : mixable {
bitmap_ind16* srcbitmap;
bitmap_ind8* flagsbitmap;
const pen_t* clut;

int colscroll; // 4000
bool alt_tilemap; // 4000
Expand All @@ -255,7 +252,6 @@ class taito_f3_state : public driver_device
u32 reg_fx_y;
u32 reg_x_count;
u32 reg_y_count;
void draw(u32* dst, int x, int y) override;
};

struct f3_line_inf {
Expand All @@ -278,6 +274,9 @@ class taito_f3_state : public driver_device
playfield_inf pf[NUM_PLAYFIELDS];
};

virtual void draw_line(u32* dst, int y, int xs, int xe, mixable* l);
virtual void draw_line(u32* dst, int y, int xs, int xe, sprite_inf* sp);
virtual void draw_line(u32* dst, int y, int xs, int xe, playfield_inf* pf);

struct f3_playfield_line_inf
{
Expand Down
59 changes: 41 additions & 18 deletions src/mame/taito/taito_f3_v.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1755,19 +1755,29 @@ void taito_f3_state::get_pf_scroll(int pf_num, u32 &reg_sx, u32 &reg_sy)
reg_sy = sy;
}

void taito_f3_state::sprite_inf::draw(u32* dst, int y, int x)
void taito_f3_state::draw_line(u32* dst, int y, int xs, int xe, mixable* l) { };
void taito_f3_state::draw_line(u32* dst, int y, int xs, int xe, sprite_inf* sp)
{
if (u32 col = srcbitmap.pix(y, x))
*dst = col;
if (!sp->layer_enable())
return;
for (int x = xs; x < xe; x++) {
if (u32 col = sp->srcbitmap.pix(y, x))
dst[x] = col;
}
}
void taito_f3_state::playfield_inf::draw(u32* dst, int y, int x)
void taito_f3_state::draw_line(u32* dst, int y, int xs, int xe, playfield_inf* pf)
{
int y_index = ((reg_fx_y >> 16) + colscroll) & 0x1ff;
int x_index = ((reg_fx_x >> 16) + x) & 0x1ff;
if (!(flagsbitmap->pix(y_index, x_index) & 0xf0))
if (!pf->layer_enable())
return;
if (u32 col = clut[srcbitmap->pix(y_index, x_index)])
*dst = col;
const pen_t *clut = &m_palette->pen(0);
int y_index = ((pf->reg_fx_y >> 16) + pf->colscroll) & 0x1ff;
for (int x = xs; x < xe; x++) {
int x_index = ((pf->reg_fx_x >> 16) + x) & m_width_mask;
if (!(pf->flagsbitmap->pix(y_index, x_index) & 0xf0))
continue;
if (u32 col = clut[pf->srcbitmap->pix(y_index, x_index)])
dst[x] = col;
}
}

void taito_f3_state::scanline_draw_TWO(bitmap_rgb32 &bitmap, const rectangle &cliprect)
Expand All @@ -1783,6 +1793,7 @@ void taito_f3_state::scanline_draw_TWO(bitmap_rgb32 &bitmap, const rectangle &cl
y_inc = 1;
}

// acquire sprite rendering layers, playfield tilemaps, playfield scroll
f3_line_inf line_data{};
for (int sp = 0; sp < NUM_SPRITEGROUPS; ++sp) {
line_data.sp[sp].srcbitmap = bitmap_rgb32(bitmap.width(), bitmap.height());
Expand All @@ -1791,13 +1802,13 @@ void taito_f3_state::scanline_draw_TWO(bitmap_rgb32 &bitmap, const rectangle &cl
int tmap_number = pf + line_data.pf[pf].alt_tilemap * 2;
line_data.pf[pf].srcbitmap = &m_tilemap[tmap_number]->pixmap();
line_data.pf[pf].flagsbitmap = &m_tilemap[tmap_number]->flagsmap();
line_data.pf[pf].clut = &m_palette->pen(0);
get_pf_scroll(pf, line_data.pf[pf].reg_sx, line_data.pf[pf].reg_sy);
if (m_flipscreen)
line_data.pf[pf].reg_fx_y = -line_data.pf[pf].reg_sy - (256 << 16);
else
line_data.pf[pf].reg_fx_y = line_data.pf[pf].reg_sy;
}
// draw sprite layers
{
const tempsprite *sprite_ptr;
gfx_element *sprite_gfx = m_gfxdecode->gfx(2);
Expand All @@ -1819,21 +1830,34 @@ void taito_f3_state::scanline_draw_TWO(bitmap_rgb32 &bitmap, const rectangle &cl
}
}

auto prio = [](const auto& obj) -> u8 { return obj->prio(); };

for (int y = y_start; y != y_end; y += y_inc) {
read_line_ram(line_data, y);

std::array<mixable*, NUM_SPRITEGROUPS + NUM_TILEMAPS> layers = {
// sort layers
std::array<std::variant<pivot_inf*, sprite_inf*, playfield_inf*>,
NUM_SPRITEGROUPS + NUM_TILEMAPS> layers = {
&line_data.sp[3], &line_data.sp[2], &line_data.sp[1], &line_data.sp[0],
&line_data.pivot,
&line_data.pf[3], &line_data.pf[2], &line_data.pf[1], &line_data.pf[0]
};
std::stable_sort(layers.begin(), layers.end(),
[](auto a, auto b){ return *a < *b; });

for (int x = 46; x < 46 + 320; ++x) {
for (auto gfx : layers) {
gfx->draw(&bitmap.pix(y, x), y, x);
}
[prio](auto a, auto b) {
return std::visit(prio, a) < std::visit(prio, b);
});

// draw layers to framebuffer, (for now, in bottom->top order)
for (auto gfx : layers) {
std::visit([&](auto&& arg) {
using T = std::decay_t<decltype(arg)>;
if constexpr (std::is_same_v<T, sprite_inf*>)
draw_line(&bitmap.pix(y), y, 46, 46 + 320, arg);
else if constexpr (std::is_same_v<T, playfield_inf*>)
draw_line(&bitmap.pix(y), y, 46, 46 + 320, arg);
else if constexpr (std::is_same_v<T, pivot_inf*>)
draw_line(&bitmap.pix(y), y, 46, 46 + 320, arg);
}, gfx);
}

// update registers
Expand All @@ -1843,7 +1867,6 @@ void taito_f3_state::scanline_draw_TWO(bitmap_rgb32 &bitmap, const rectangle &cl
p->reg_fx_x = p->reg_sx + p->rowscroll + 10*p->x_scale;
p->reg_fx_x &= (m_width_mask << 16) | 0xffff;
}

}
}

Expand Down

0 comments on commit 0cd76a1

Please sign in to comment.