fixing compilation issues, working on textures

This commit is contained in:
2024-09-04 02:35:01 +02:00
parent e0da415e86
commit 8ad6d84bd2
15 changed files with 315 additions and 115 deletions

View File

@@ -12,10 +12,31 @@ namespace mlx
m_depth.Init(m_descriptor.renderer->GetSwapchainImages().back().GetWidth(), m_descriptor.renderer->GetSwapchainImages().back().GetHeight());
}
Sprite& Scene::CreateSprite(std::shared_ptr<Texture> texture) noexcept
Sprite& Scene::CreateSprite(NonOwningPtr<Texture> texture) noexcept
{
std::shared_ptr<Sprite> sprite = std::make_shared<Sprite>(texture);
m_sprites.push_back(sprite);
return *sprite;
}
NonOwningPtr<Sprite> Scene::GetSpriteFromTextureAndPosition(NonOwningPtr<Texture> texture, const Vec2f& position) const
{
auto it = std::find_if(m_sprites.begin(), m_sprites.end(), [texture, position](const Sprite& sprite)
{
return sprite.GetPosition().x == position.x && sprite.GetPosition().y == position.y && sprite.GetTexture() == texture;
});
return (it != m_sprites.end() ? &(*it) : nullptr);
}
void Scene::TryEraseSpriteFromTexture(NonOwningPtr<Texture> texture)
{
do
{
auto it = std::find_if(m_sprites.begin(), m_sprites.end(), [texture, position](const Sprite& sprite)
{
return sprite.GetPosition().x == position.x && sprite.GetPosition().y == position.y && sprite.GetTexture() == texture;
});
m_sprites.erase(it);
} while(it != m_sprites.end());
}
}

View File

@@ -35,7 +35,7 @@ namespace mlx
return mesh;
}
Sprite::Sprite(std::shared_ptr<Texture> texture)
Sprite::Sprite(NonOwningPtr<Texture> texture)
{
Verify((bool)texture, "Sprite: invalid texture");
p_mesh = CreateQuad(0, 0, texture->GetWidth(), texture->GetHeight());