Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
rtoumazet committed Nov 6, 2024
1 parent 59f6bf3 commit 08f516e
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 31 deletions.
16 changes: 7 additions & 9 deletions saturnin/src/video/vdp2/vdp2.h
Original file line number Diff line number Diff line change
Expand Up @@ -1245,17 +1245,15 @@ class Vdp2 {
// DISPLAY methods
//--------------------------------------------------------------------------------------------------------------

////////////////////////////////////////////////////////////////////////////////////////////////////
/// \fn void Vdp2::populateRenderData();
///
/// \brief Populates data from the VDP2 memory before backend rendering.
///
/// \author Runik
/// \date 29/01/2021
////////////////////////////////////////////////////////////////////////////////////////////////////

// Populates data from the VDP2 memory before backend rendering.
void populateRenderData();

// Populates data from rotating background screens (RBG)
void populateRbgScreens();

// Populates data from normal background screens (NBG)
void populateNbgScreens();

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

Expand Down
66 changes: 44 additions & 22 deletions saturnin/src/video/vdp2/vdp2_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,41 +41,57 @@ 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() {
using enum ScrollScreen;
populateRbgScreens();
populateNbgScreens();
}

auto populateRbgScreen = [this](const ScrollScreen rbg) {
void Vdp2::populateRbgScreens() {
using enum ScrollScreen;
for (const auto rbg : {rbg1, rbg0}) {
clearRenderData(rbg);
if (isScreenDisplayed(rbg)) {
updateScrollScreenStatus(rbg);
if (getScreen(rbg).priority_number != 0) { readScrollScreenData(rbg); }
} else {
// discardCache(rbg);
}
};
}
}

populateRbgScreen(rbg1);
populateRbgScreen(rbg0);
void Vdp2::populateNbgScreens() {
using enum ScrollScreen;
auto is_nbg_displayed
= !(getScreen(ScrollScreen::rbg0).is_display_enabled && getScreen(ScrollScreen::rbg1).is_display_enabled);

auto populateNbgScreen = [this](const ScrollScreen nbg) {
clearRenderData(nbg);
if (isScrollScreenDisplayable(nbg) && isScreenDisplayed(nbg) && (getScreen(nbg).priority_number != 0)) {
readScrollScreenData(nbg);
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 is_nbg_displayed = !(getScreen(rbg0).is_display_enabled && getScreen(rbg1).is_display_enabled);
clearRenderData(ScrollScreen::nbg1);
if (isScrollScreenDisplayable(ScrollScreen::nbg1)) {
if (isScreenDisplayed(ScrollScreen::nbg1)) {
updateScrollScreenStatus(ScrollScreen::nbg1);
if (getScreen(ScrollScreen::nbg1).priority_number != 0) { readScrollScreenData(ScrollScreen::nbg1); }
}
}

if (is_nbg_displayed) {
populateNbgScreen(nbg0);
populateNbgScreen(nbg1);
populateNbgScreen(nbg2);
clearRenderData(ScrollScreen::nbg2);
if (isScrollScreenDisplayable(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)] = {};
}

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

0 comments on commit 08f516e

Please sign in to comment.