Skip to content
This repository has been archived by the owner on Jan 5, 2024. It is now read-only.

Commit

Permalink
load time optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
Causeless committed Nov 5, 2023
1 parent 4a54aeb commit fce2b27
Showing 1 changed file with 12 additions and 25 deletions.
37 changes: 12 additions & 25 deletions Entities/SLTerrain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,35 +335,25 @@ namespace RTE {
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void SLTerrain::CleanAir() {
// Reference. Do not remove.
//acquire_bitmap(m_MainBitmap);
//acquire_bitmap(m_FGColorLayer->GetBitmap());

int width = m_MainBitmap->w;
int height = m_MainBitmap->h;
std::vector<int> rows(m_MainBitmap->h); // we loop through h first, because we want each thread to have sequential memory that they're touching
std::iota(std::begin(rows), std::end(rows), 0);

for (int y = 0; y < height; ++y) {
for (int x = 0; x < width; ++x) {
int matPixel = _getpixel(m_MainBitmap, x, y);
if (matPixel == MaterialColorKeys::g_MaterialCavity) {
_putpixel(m_MainBitmap, x, y, MaterialColorKeys::g_MaterialAir);
matPixel = MaterialColorKeys::g_MaterialAir;
std::for_each(std::execution::par_unseq, std::begin(rows), std::end(rows),
[&](int yPos) {
for (int xPos = 0; xPos < m_MainBitmap->w; ++xPos) {
int matPixel = _getpixel(m_MainBitmap, xPos, yPos);
if (matPixel == MaterialColorKeys::g_MaterialCavity) {
_putpixel(m_MainBitmap, xPos, yPos, MaterialColorKeys::g_MaterialAir);
matPixel = MaterialColorKeys::g_MaterialAir;
}
if (matPixel == MaterialColorKeys::g_MaterialAir) { _putpixel(m_FGColorLayer->GetBitmap(), xPos, yPos, ColorKeys::g_MaskColor); }
}
if (matPixel == MaterialColorKeys::g_MaterialAir) { _putpixel(m_FGColorLayer->GetBitmap(), x, y, ColorKeys::g_MaskColor); }
}
}
// Reference. Do not remove.
//release_bitmap(m_MainBitmap);
//release_bitmap(m_FGColorLayer->GetBitmap());
});
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void SLTerrain::CleanAirBox(const Box &box, bool wrapsX, bool wrapsY) {
// Reference. Do not remove.
//acquire_bitmap(m_MainBitmap);
//acquire_bitmap(m_FGColorLayer->GetBitmap());

int width = m_MainBitmap->w;
int height = m_MainBitmap->h;

Expand All @@ -390,9 +380,6 @@ namespace RTE {
}
}
}
// Reference. Do not remove.
//release_bitmap(m_MainBitmap);
//release_bitmap(m_FGColorLayer->GetBitmap());
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit fce2b27

Please sign in to comment.