Skip to content

Commit

Permalink
Merge pull request #245 from clasher113/main
Browse files Browse the repository at this point in the history
Оптимизация анимации текстур
  • Loading branch information
MihailRis authored Jun 13, 2024
2 parents ad58140 + 203b8f8 commit 036564f
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 21 deletions.
2 changes: 1 addition & 1 deletion doc/ru/block-properties.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@

### Подбираемый предмет - `picking-item`

Предмет, который будет выбран при при нажатии средней кнопкой мыши на блок.
Предмет, который будет выбран при нажатии средней кнопкой мыши на блок.

Пример: блок `door:door_open` скрыт (hidden) поэтому указывается `picking-item: "door:door.item"`

Expand Down
8 changes: 5 additions & 3 deletions src/assets/assetload_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,10 @@ static TextureAnimation create_animation(
uint srcWidth = srcTex->getWidth();
uint srcHeight = srcTex->getHeight();

frame.dstPos = glm::ivec2(region.u1 * dstWidth, region.v1 * dstHeight);
frame.size = glm::ivec2(region.u2 * dstWidth, region.v2 * dstHeight) - frame.dstPos;
const int extension = 2;

frame.dstPos = glm::ivec2(region.u1 * dstWidth, region.v1 * dstHeight) - extension;
frame.size = glm::ivec2(region.u2 * dstWidth, region.v2 * dstHeight) - frame.dstPos + extension;

for (const auto& elem : frameList) {
if (!srcAtlas->has(elem.first)) {
Expand All @@ -247,7 +249,7 @@ static TextureAnimation create_animation(
if (elem.second > 0) {
frame.duration = static_cast<float>(elem.second) / 1000.0f;
}
frame.srcPos = glm::ivec2(region.u1 * srcWidth, srcHeight - region.v2 * srcHeight);
frame.srcPos = glm::ivec2(region.u1 * srcWidth, srcHeight - region.v2 * srcHeight) - extension;
animation.addFrame(frame);
}
return animation;
Expand Down
3 changes: 1 addition & 2 deletions src/frontend/debug_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@ std::shared_ptr<UINode> create_debug_panel(
glm::vec3 position = player->hitbox->position;
position[ax] = std::stoi(text);
player->teleport(position);
} catch (std::invalid_argument& _){
} catch (std::out_of_range & _) {
} catch (std::exception& _){
}
});
box->setOnEditStart([=](){
Expand Down
15 changes: 0 additions & 15 deletions src/graphics/core/TextureAnimation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,6 @@ void TextureAnimator::update(float delta) {

float srcPosY = elem.srcTexture->getHeight() - frame.size.y - frame.srcPos.y; // vertical flip

// Extensions
const int ext = 2;
for (int y = -1; y <= 1; y++) {
for (int x = -1; x <= 1; x++) {
if (x == 0 && y == 0)
continue;
glBlitFramebuffer(
frame.srcPos.x, srcPosY, frame.srcPos.x + frame.size.x, srcPosY + frame.size.y,
frame.dstPos.x+x*ext, frame.dstPos.y+y*ext,
frame.dstPos.x + frame.size.x+x*ext, frame.dstPos.y + frame.size.y+y*ext,
GL_COLOR_BUFFER_BIT, GL_NEAREST
);
}
}

glBlitFramebuffer(
frame.srcPos.x, srcPosY,
frame.srcPos.x + frame.size.x,
Expand Down

0 comments on commit 036564f

Please sign in to comment.