Skip to content

Commit

Permalink
Linter fixes + refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
rtoumazet committed Oct 30, 2024
1 parent e280b62 commit efb86cc
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 134 deletions.
28 changes: 3 additions & 25 deletions saturnin/src/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,11 @@ void runTests() {
}

std::vector<u8> texture_data;
// core::Log::info(Logger::test, "{}", arr[0x3f]);
auto os = std::ostringstream{};
auto b = ankerl::nanobench::Bench();
auto os = std::ostringstream{};
auto b = ankerl::nanobench::Bench();
b.output(&os).relative(true);

// ankerl::nanobench::Bench().output(&os).run("Direct copy", [&] {
b.run("Direct copy", [&] {
b.run("Direct copy", [&texture_data, &current_address, &row, &ec] {
texture_data.clear();
current_address = u32{0x25e00000};
for (u32 i = 0; i < 8; ++i) {
Expand All @@ -129,26 +127,6 @@ void runTests() {
texture_data.emplace_back(row.as_8bits >> DataExtraction::As8Bits::dot3_shift);
current_address += 4;
}

// ankerl::nanobench::doNotOptimizeAway(d);
});

b.run("Block copy", [&] {
texture_data.clear();
current_address = u32{0x25e00000};
// for (u32 i = 0; i < 8; ++i) {
// const auto data = ec.memory()->read(core::MemoryMapArea::vdp2_video_ram, current_address, 0x40);

// for (const auto& elem : data) {
// row.as_8bits = elem;
// texture_data.emplace_back(row.as_8bits >> DataExtraction::As8Bits::dot0_shift);
// texture_data.emplace_back(row.as_8bits >> DataExtraction::As8Bits::dot1_shift);
// texture_data.emplace_back(row.as_8bits >> DataExtraction::As8Bits::dot2_shift);
// texture_data.emplace_back(row.as_8bits >> DataExtraction::As8Bits::dot3_shift);
// }
//}

// ankerl::nanobench::doNotOptimizeAway(d);
});

core::Log::info(Logger::test, "{}", os.str());
Expand Down
7 changes: 4 additions & 3 deletions saturnin/src/video/vdp1_part.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -794,18 +794,19 @@ void distortedSpriteDraw(const EmulatorModules& modules, Vdp1Part& part) {
void polyDraw(const EmulatorModules& modules, Vdp1Part& part, CmdCtrl::CommandSelect command) {
switch (command) {
using enum CmdCtrl::CommandSelect;
using enum Logger;
case polygon_draw: {
Log::debug(Logger::vdp1, tr("Command - Polygon draw"));
Log::debug(vdp1, tr("Command - Polygon draw"));
part.common_vdp_data_.draw_type = DrawType::non_textured_polygon;
break;
}
case polyline_draw: {
Log::debug(Logger::vdp1, tr("Command - Polyline draw"));
Log::debug(vdp1, tr("Command - Polyline draw"));
part.common_vdp_data_.draw_type = DrawType::polyline;
break;
}
default: {
Log::error(Logger::vdp1, tr("Command - Unknown poly draw"));
Log::error(vdp1, tr("Command - Unknown poly draw"));
return;
}
}
Expand Down
17 changes: 2 additions & 15 deletions saturnin/src/video/vdp2/vdp2.h
Original file line number Diff line number Diff line change
Expand Up @@ -1256,21 +1256,8 @@ class Vdp2 {

void populateRenderData();

////////////////////////////////////////////////////////////////////////////////////////////////////
/// \fn auto Vdp2::canScrollScreenBeDisplayed(const ScrollScreen s) const -> bool;
///
/// \brief Determine if the scroll screen can be displayed, based on others scroll screens
/// configuration
///
/// \author Runik
/// \date 11/03/2021
///
/// \param s A ScrollScreen to process.
///
/// \returns True the scroll screen can be displayed, false if not.
////////////////////////////////////////////////////////////////////////////////////////////////////

auto canScrollScreenBeDisplayed(const ScrollScreen s) const -> bool;
// Determines if scroll screen is displayable, based on others scroll screens configuration
auto isScrollScreenDisplayable(const ScrollScreen s) const -> bool;

////////////////////////////////////////////////////////////////////////////////////////////////////
/// \fn void Vdp2::updateScrollScreenStatus(const ScrollScreen s);
Expand Down
57 changes: 15 additions & 42 deletions saturnin/src/video/vdp2/vdp2_debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,49 +192,22 @@ auto Vdp2::getDebugVramAccessBanks() const -> std::vector<VramTiming> {
const auto banks_used = getDebugVramAccessBanksUsed();
auto banks = std::vector<VramTiming>{};

const VramTiming bank_a0 = {regs_.cyca0l >> Cycxxl::t0_enum,
regs_.cyca0l >> Cycxxl::t1_enum,
regs_.cyca0l >> Cycxxl::t2_enum,
regs_.cyca0l >> Cycxxl::t3_enum,
is_normal_mode ? regs_.cyca0u >> Cycxxu::t4_enum : no_access,
is_normal_mode ? regs_.cyca0u >> Cycxxu::t5_enum : no_access,
is_normal_mode ? regs_.cyca0u >> Cycxxu::t6_enum : no_access,
is_normal_mode ? regs_.cyca0u >> Cycxxu::t7_enum : no_access};
banks.emplace_back(bank_a0);

if (banks_used[vram_bank_a1_index]) {
const VramTiming bank_a1 = {regs_.cyca0l >> Cycxxl::t0_enum,
regs_.cyca1l >> Cycxxl::t1_enum,
regs_.cyca1l >> Cycxxl::t2_enum,
regs_.cyca1l >> Cycxxl::t3_enum,
is_normal_mode ? regs_.cyca1u >> Cycxxu::t4_enum : no_access,
is_normal_mode ? regs_.cyca1u >> Cycxxu::t5_enum : no_access,
is_normal_mode ? regs_.cyca1u >> Cycxxu::t6_enum : no_access,
is_normal_mode ? regs_.cyca1u >> Cycxxu::t7_enum : no_access};
banks.emplace_back(bank_a1);
}
auto readBank = [&is_normal_mode](const Vdp2Regs::CycxxlType& cycl, const Vdp2Regs::CycxxuType& cycu) -> VramTiming {
return {cycl >> Cycxxl::t0_enum,
cycl >> Cycxxl::t1_enum,
cycl >> Cycxxl::t2_enum,
cycl >> Cycxxl::t3_enum,
is_normal_mode ? cycu >> Cycxxu::t4_enum : no_access,
is_normal_mode ? cycu >> Cycxxu::t5_enum : no_access,
is_normal_mode ? cycu >> Cycxxu::t6_enum : no_access,
is_normal_mode ? cycu >> Cycxxu::t7_enum : no_access};
};

banks.emplace_back(readBank(regs_.cyca0l, regs_.cyca0u));
if (banks_used[vram_bank_a1_index]) { banks.emplace_back(readBank(regs_.cyca1l, regs_.cyca1u)); }
banks.emplace_back(readBank(regs_.cycb0l, regs_.cycb0u));
if (banks_used[vram_bank_b1_index]) { banks.emplace_back(readBank(regs_.cycb1l, regs_.cycb1u)); }

const VramTiming bank_b0 = {regs_.cycb0l >> Cycxxl::t0_enum,
regs_.cycb0l >> Cycxxl::t1_enum,
regs_.cycb0l >> Cycxxl::t2_enum,
regs_.cycb0l >> Cycxxl::t3_enum,
is_normal_mode ? regs_.cycb0u >> Cycxxu::t4_enum : no_access,
is_normal_mode ? regs_.cycb0u >> Cycxxu::t5_enum : no_access,
is_normal_mode ? regs_.cycb0u >> Cycxxu::t6_enum : no_access,
is_normal_mode ? regs_.cycb0u >> Cycxxu::t7_enum : no_access};
banks.emplace_back(bank_b0);

if (banks_used[vram_bank_a1_index]) {
const VramTiming bank_b1 = {regs_.cycb1l >> Cycxxl::t0_enum,
regs_.cycb1l >> Cycxxl::t1_enum,
regs_.cycb1l >> Cycxxl::t2_enum,
regs_.cycb1l >> Cycxxl::t3_enum,
is_normal_mode ? regs_.cycb1u >> Cycxxu::t4_enum : no_access,
is_normal_mode ? regs_.cycb1u >> Cycxxu::t5_enum : no_access,
is_normal_mode ? regs_.cycb1u >> Cycxxu::t6_enum : no_access,
is_normal_mode ? regs_.cycb1u >> Cycxxu::t7_enum : no_access};
banks.emplace_back(bank_b1);
}
return banks;
}

Expand Down
78 changes: 29 additions & 49 deletions saturnin/src/video/vdp2/vdp2_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,55 +41,41 @@ constexpr auto bits_in_a_byte = u8{8};
void Vdp2::clearRenderData(const ScrollScreen s) { std::vector<video::Vdp2Part>().swap(vdp2_parts_[toUnderlying(s)]); }

void Vdp2::populateRenderData() {
clearRenderData(ScrollScreen::rbg1);
if (isScreenDisplayed(ScrollScreen::rbg1)) {
updateScrollScreenStatus(ScrollScreen::rbg1);
if (getScreen(ScrollScreen::rbg1).priority_number != 0) { readScrollScreenData(ScrollScreen::rbg1); }
} else {
// discardCache(ScrollScreen::rbg1);
}

clearRenderData(ScrollScreen::rbg0);
if (isScreenDisplayed(ScrollScreen::rbg0)) {
updateScrollScreenStatus(ScrollScreen::rbg0);
if (getScreen(ScrollScreen::rbg0).priority_number != 0) { readScrollScreenData(ScrollScreen::rbg0); }
} else {
// discardCache(ScrollScreen::rbg0);
}
auto is_nbg_displayed
= !(getScreen(ScrollScreen::rbg0).is_display_enabled && getScreen(ScrollScreen::rbg1).is_display_enabled);
using enum ScrollScreen;

if (is_nbg_displayed) {
clearRenderData(ScrollScreen::nbg0);
if (isScreenDisplayed(ScrollScreen::nbg0)) {
updateScrollScreenStatus(ScrollScreen::nbg0);
if (getScreen(ScrollScreen::nbg0).priority_number != 0) { readScrollScreenData(ScrollScreen::nbg0); }
auto populateRbgScreen = [this](const ScrollScreen rbg) {
clearRenderData(rbg);
if (isScreenDisplayed(rbg)) {
updateScrollScreenStatus(rbg);
if (getScreen(rbg).priority_number != 0) { readScrollScreenData(rbg); }
} else {
// discardCache(rbg);
}
};

clearRenderData(ScrollScreen::nbg1);
if (canScrollScreenBeDisplayed(ScrollScreen::nbg1)) {
if (isScreenDisplayed(ScrollScreen::nbg1)) {
updateScrollScreenStatus(ScrollScreen::nbg1);
if (getScreen(ScrollScreen::nbg1).priority_number != 0) { readScrollScreenData(ScrollScreen::nbg1); }
}
}
populateRbgScreen(rbg1);
populateRbgScreen(rbg0);

clearRenderData(ScrollScreen::nbg2);
if (canScrollScreenBeDisplayed(ScrollScreen::nbg2)) {
if (isScreenDisplayed(ScrollScreen::nbg2)) {
updateScrollScreenStatus(ScrollScreen::nbg2);
if (getScreen(ScrollScreen::nbg2).priority_number != 0) { readScrollScreenData(ScrollScreen::nbg2); }
}
} else {
// bg_[util::toUnderlying(ScrollScreen::nbg2)] = {};
auto populateNbgScreen = [this](const ScrollScreen nbg) {
clearRenderData(nbg);
if (isScrollScreenDisplayable(nbg) && isScreenDisplayed(nbg) && (getScreen(nbg).priority_number != 0)) {
readScrollScreenData(nbg);
}
};

auto is_nbg_displayed = !(getScreen(rbg0).is_display_enabled && getScreen(rbg1).is_display_enabled);

if (is_nbg_displayed) {
populateNbgScreen(nbg0);
populateNbgScreen(nbg1);
populateNbgScreen(nbg2);

if (uses_fbo) {
// WIP
if (canScrollScreenBeDisplayed(ScrollScreen::nbg3) && isScreenDisplayed(ScrollScreen::nbg3)) {
updateScrollScreenStatus(ScrollScreen::nbg3);
const auto isDirty = isCacheDirty(ScrollScreen::nbg3);
const auto priorityIsAboveZero = getScreen(ScrollScreen::nbg3).priority_number != 0;
if (isScrollScreenDisplayable(nbg3) && isScreenDisplayed(nbg3)) {
updateScrollScreenStatus(nbg3);
const auto isDirty = isCacheDirty(nbg3);
const auto priorityIsAboveZero = getScreen(nbg3).priority_number != 0;
if (isDirty && priorityIsAboveZero) {
// discardCache(ScrollScreen::nbg3);
// clearRenderData(ScrollScreen::nbg3);
Expand All @@ -116,18 +102,12 @@ void Vdp2::populateRenderData() {
// modules_.opengl()->setFboStatus(ScrollScreen::nbg3, FboStatus::to_clear);
}
} else {
clearRenderData(ScrollScreen::nbg3);
if (canScrollScreenBeDisplayed(ScrollScreen::nbg3)) {
if (isScreenDisplayed(ScrollScreen::nbg3)) {
updateScrollScreenStatus(ScrollScreen::nbg3);
if (getScreen(ScrollScreen::nbg3).priority_number != 0) { readScrollScreenData(ScrollScreen::nbg3); }
}
}
populateNbgScreen(nbg3);
}
}
}

auto Vdp2::canScrollScreenBeDisplayed(const ScrollScreen s) const -> bool {
auto Vdp2::isScrollScreenDisplayable(const ScrollScreen s) const -> bool {
const auto nbg0_color_nb = getScreen(ScrollScreen::nbg0).character_color_number;
const auto nbg1_color_nb = getScreen(ScrollScreen::nbg1).character_color_number;
switch (s) {
Expand Down

0 comments on commit efb86cc

Please sign in to comment.