summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2022-11-22 03:19:29 +0100
committerStanislaw Halik <sthalik@misaki.pl>2022-11-22 03:19:29 +0100
commit0fa4a8542bf9eda8bd9c28da199b3e90e04279b9 (patch)
tree8a91894a3b9eebdb8a7ef3c4b3e94d169efcf8ea /src
parent966ac722d72c8d89e621987090b19f2bde0cb58c (diff)
wip
Diffstat (limited to 'src')
-rw-r--r--src/anim-atlas.cpp19
-rw-r--r--src/anim-atlas.hpp6
-rw-r--r--src/camera-offset.cpp2
3 files changed, 25 insertions, 2 deletions
diff --git a/src/anim-atlas.cpp b/src/anim-atlas.cpp
index b566d19f..345ca63e 100644
--- a/src/anim-atlas.cpp
+++ b/src/anim-atlas.cpp
@@ -2,6 +2,7 @@
#include "compat/assert.hpp"
#include "shaders/tile.hpp"
#include "tile-defs.hpp"
+#include <Corrade/Containers/BitArrayView.h>
#include <Magnum/Math/Color.h>
#include <Magnum/GL/TextureFormat.h>
@@ -31,7 +32,7 @@ decltype(anim_atlas::_group_indices) anim_atlas::make_group_indices(const anim_d
anim_atlas::anim_atlas() noexcept = default;
anim_atlas::anim_atlas(StringView name, const ImageView2D& image, anim_def info) noexcept :
- _name{name},
+ _name{name}, _bitmask{make_bit_array(image)},
_info{std::move(info)}, _group_indices{make_group_indices(_info)}
{
_tex.setWrapping(GL::SamplerWrapping::ClampToEdge)
@@ -99,4 +100,20 @@ auto anim_atlas::frame_quad(const Vector3& center, rotation r, std::size_t i) co
}};
}
+BitArray anim_atlas::make_bit_array(const ImageView2D& tex)
+{
+ fm_assert(tex.pixelSize() == 4);
+ const auto size = (std::size_t)tex.size().product();
+ BitArray array{NoInit, size};
+ const char* __restrict data = tex.data().data();
+ for (std::size_t i = 0; i < size; i++)
+ array.set(i, data[i * 4 + 3] != 0);
+ return array;
+}
+
+BitArrayView anim_atlas::bitmask() const
+{
+ return _bitmask;
+}
+
} // namespace floormat
diff --git a/src/anim-atlas.hpp b/src/anim-atlas.hpp
index e3e7243d..ce0e6176 100644
--- a/src/anim-atlas.hpp
+++ b/src/anim-atlas.hpp
@@ -3,6 +3,8 @@
#include "scenery.hpp"
#include "anim.hpp"
#include <array>
+#include <Corrade/Containers/BitArray.h>
+#include <Corrade/Containers/BitArrayView.h>
#include <Corrade/Containers/String.h>
#include <Magnum/Math/Vector2.h>
#include <Magnum/ImageView.h>
@@ -31,11 +33,14 @@ struct anim_atlas final
texcoords texcoords_for_frame(rotation r, std::size_t frame) const noexcept;
quad frame_quad(const Vector3& center, rotation r, std::size_t frame) const noexcept;
+ BitArrayView bitmask() const;
+
fm_DECLARE_DELETED_COPY_ASSIGNMENT(anim_atlas);
private:
GL::Texture2D _tex;
String _name;
+ BitArray _bitmask;
anim_def _info;
std::array<std::uint8_t, (std::size_t)rotation_COUNT> _group_indices = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
@@ -43,6 +48,7 @@ private:
static decltype(_group_indices) make_group_indices(const anim_def& anim) noexcept;
static std::uint8_t rotation_to_index(const anim_def& a, rotation r) noexcept;
+ static BitArray make_bit_array(const ImageView2D& tex);
};
} // namespace floormat
diff --git a/src/camera-offset.cpp b/src/camera-offset.cpp
index b132cdab..335a9b65 100644
--- a/src/camera-offset.cpp
+++ b/src/camera-offset.cpp
@@ -11,7 +11,7 @@ with_shifted_camera_offset::with_shifted_camera_offset(tile_shader& shader, shor
_offset{shader.camera_offset()}
{
constexpr auto chunk_size = TILE_MAX_DIM20d*dTILE_SIZE;
- const auto offset = _offset + tile_shader::project(Vector3d(x, y, 0) * chunk_size);
+ const auto offset = _offset + tile_shader::project(Vector3d(x, y, 0) * chunk_size);
_shader.set_camera_offset(offset);
}