Skip to content

Commit

Permalink
SpriteHandler.h:
Browse files Browse the repository at this point in the history
* Added private function BitmapSprite::fill_sprite_data() to be used later.
  • Loading branch information
razterizer committed Dec 3, 2024
1 parent d886b3f commit df755c6
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions SpriteHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,32 @@ class BitmapSprite : public Sprite

return true;
}

template<typename T>
void fill_sprite_data(std::vector<T>& target, const ttl::Rectangle& bb, T arg)
{
int nr = std::min(bb.r_len, size.r);
int nc = std::min(bb.c_len, size.c);

auto N_trg = target.size();

for (int i = 0; i < nr; ++i)
{
for (int j = 0; j < nc; ++j)
{
// Map bounding box (i, j) to the target sprite data
int trg_row = bb.r + i;
int trg_col = bb.c + j;

// Calculate linear index into the target vector and src_data
int trg_index = trg_row * size.c + trg_col;

// Assign data to the target vector
if (trg_index < N_trg)
target[trg_index] = arg;
}
}
}

RC size { 0, 0 };
int area = 0;
Expand Down

0 comments on commit df755c6

Please sign in to comment.