Skip to content

Commit

Permalink
Combine two for loops.
Browse files Browse the repository at this point in the history
  • Loading branch information
Quipyowert2 committed Dec 2, 2024
1 parent 81c8ab4 commit fae47c2
Showing 1 changed file with 10 additions and 17 deletions.
27 changes: 10 additions & 17 deletions libgag/src/Sprite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,39 +209,32 @@ namespace GAGCore
texCoordBuffer.reserve(texturesNeeded);
vertices.reserve(texturesNeeded);
texCoords.reserve(texturesNeeded);
// For each sprite sheet
while (sheetNo < texturesNeeded)
{
int sheetWidth = bestSize->width * tileWidth;
int sheetHeight = bestSize->height * tileWidth;
int sheetHeight = bestSize->height * tileHeight;
std::unique_ptr<DrawableSurface> atlas = make_unique<DrawableSurface>(sheetWidth, sheetHeight);
int x = 0, y = 0;
for (int i = currentImage; i < currentImage + bestSize->numImages; i++)
// For each tile in the current sprite sheet
for (int i = 0; i < bestSize->numImages; i++)
{
DrawableSurface* image = images[i];
DrawableSurface* image = images[i + currentImage];
atlas->drawSurface(x, y, image);
TextureInfo info;
image->textureInfo = info;
image->textureInfo->texX = x;
image->textureInfo->texY = y;
TextureInfo info = { this, x, y, tileWidth, tileHeight, sheetNo };
image->texMultX = 1.f;
image->texMultY = 1.f;
image->textureInfo->w = tileWidth;
image->textureInfo->h = tileHeight;
image->textureInfo->atlasNum = sheetNo;
image->textureInfo = info;
image->texture = atlas->texture;
image->setRes(sheetWidth, sheetHeight);
x += tileWidth;
if (tileWidth + x > sheetWidth) {
x = 0;
y += tileHeight;
}
}
// Finish drawing the sprite sheet.
atlas->uploadToTexture();
for (int i = currentImage; i < currentImage + bestSize->numImages; i++)
{
DrawableSurface* image = images[i];
image->texture = atlas->texture;
image->textureInfo->sprite = this;
image->setRes(sheetWidth, sheetHeight);
}
this->atlas.push_back(std::move(atlas));
currentImage += bestSize->numImages;
sheetNo++;
Expand Down

0 comments on commit fae47c2

Please sign in to comment.