summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/anim-atlas.hpp31
-rw-r--r--src/chunk.hpp2
-rw-r--r--src/critter.hpp2
-rw-r--r--src/object.hpp2
-rw-r--r--src/scenery.hpp2
-rw-r--r--src/tile-atlas.hpp25
-rw-r--r--src/tile-image.hpp2
-rw-r--r--src/tile.hpp2
-rw-r--r--src/wall-atlas.cpp16
-rw-r--r--src/wall-atlas.hpp32
10 files changed, 65 insertions, 51 deletions
diff --git a/src/anim-atlas.hpp b/src/anim-atlas.hpp
index 22df30eb..2803566f 100644
--- a/src/anim-atlas.hpp
+++ b/src/anim-atlas.hpp
@@ -2,6 +2,7 @@
#include "compat/defs.hpp"
#include "rotation.hpp"
#include "anim.hpp"
+#include "src/quads.hpp"
#include <array>
#include <Corrade/Containers/BitArray.h>
#include <Corrade/Containers/String.h>
@@ -11,11 +12,23 @@
namespace floormat {
-struct anim_atlas final
+class anim_atlas final
{
- using texcoords = std::array<Vector2, 4>;
- using quad = std::array<Vector3, 4>;
+ using texcoords = Quads::texcoords;
+ using quad = Quads::quad;
+ String _name;
+ BitArray _bitmask;
+ anim_def _info;
+ std::array<uint8_t, (size_t)rotation_COUNT> _group_indices = {
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ };
+ GL::Texture2D _tex;
+
+ static decltype(_group_indices) make_group_indices(const anim_def& anim) noexcept;
+ static uint8_t rotation_to_index(StringView name);
+
+public:
anim_atlas() noexcept;
anim_atlas(String name, const ImageView2D& tex, anim_def info);
~anim_atlas() noexcept;
@@ -43,18 +56,6 @@ struct anim_atlas final
static void make_bitmask_(const ImageView2D& tex, BitArray& array);
static BitArray make_bitmask(const ImageView2D& tex);
-
-private:
- String _name;
- BitArray _bitmask;
- anim_def _info;
- std::array<uint8_t, (size_t)rotation_COUNT> _group_indices = {
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- };
- GL::Texture2D _tex;
-
- static decltype(_group_indices) make_group_indices(const anim_def& anim) noexcept;
- static uint8_t rotation_to_index(StringView name);
};
} // namespace floormat
diff --git a/src/chunk.hpp b/src/chunk.hpp
index e964fca0..a24957b1 100644
--- a/src/chunk.hpp
+++ b/src/chunk.hpp
@@ -11,7 +11,7 @@
namespace floormat {
-struct anim_atlas;
+class anim_atlas;
struct object;
struct object_proto;
class tile_iterator;
diff --git a/src/critter.hpp b/src/critter.hpp
index 81c8b601..724e2b28 100644
--- a/src/critter.hpp
+++ b/src/critter.hpp
@@ -6,7 +6,7 @@
namespace floormat {
-struct anim_atlas;
+class anim_atlas;
struct world;
struct critter_proto : object_proto
diff --git a/src/object.hpp b/src/object.hpp
index c02e4d07..50512419 100644
--- a/src/object.hpp
+++ b/src/object.hpp
@@ -12,7 +12,7 @@
namespace floormat {
template<typename T> struct object_type_;
-struct anim_atlas;
+class anim_atlas;
struct world;
struct chunk;
diff --git a/src/scenery.hpp b/src/scenery.hpp
index 70b7733c..9135b548 100644
--- a/src/scenery.hpp
+++ b/src/scenery.hpp
@@ -10,7 +10,7 @@
namespace floormat {
struct chunk;
-struct anim_atlas;
+class anim_atlas;
struct world;
enum class scenery_type : unsigned char {
diff --git a/src/tile-atlas.hpp b/src/tile-atlas.hpp
index 45251c6d..1a06db4a 100644
--- a/src/tile-atlas.hpp
+++ b/src/tile-atlas.hpp
@@ -1,5 +1,6 @@
#pragma once
#include "src/pass-mode.hpp"
+#include "src/quads.hpp"
#include <array>
#include <memory>
#include <Corrade/Containers/Optional.h>
@@ -10,11 +11,22 @@
namespace floormat {
-struct tile_atlas final
+class tile_atlas final
{
using quad = std::array<Vector3, 4>;
using texcoords = std::array<Vector2, 4>;
+ static std::unique_ptr<const texcoords[]> make_texcoords_array(Vector2ui pixel_size, Vector2ub tile_count);
+ static texcoords make_texcoords(Vector2ui pixel_size, Vector2ub tile_count, size_t i);
+
+ std::unique_ptr<const texcoords[]> texcoords_;
+ GL::Texture2D tex_;
+ String path_, name_;
+ Vector2ui size_;
+ Vector2ub dims_;
+ Optional<enum pass_mode> passability;
+
+public:
// todo remove Optional when wall atlases are fully implemented -sh 20231122
tile_atlas(StringView path, StringView name, const ImageView2D& img, Vector2ub tile_count, Optional<enum pass_mode> pass_mode);
@@ -28,17 +40,6 @@ struct tile_atlas final
Optional<enum pass_mode> pass_mode() const; // todo remove later
enum pass_mode pass_mode(enum pass_mode p) const;
void set_pass_mode(enum pass_mode p); // todo remove later
-
-private:
- static std::unique_ptr<const texcoords[]> make_texcoords_array(Vector2ui pixel_size, Vector2ub tile_count);
- static texcoords make_texcoords(Vector2ui pixel_size, Vector2ub tile_count, size_t i);
-
- std::unique_ptr<const texcoords[]> texcoords_;
- GL::Texture2D tex_;
- String path_, name_;
- Vector2ui size_;
- Vector2ub dims_;
- Optional<enum pass_mode> passability;
};
diff --git a/src/tile-image.hpp b/src/tile-image.hpp
index 907a465c..c93cc778 100644
--- a/src/tile-image.hpp
+++ b/src/tile-image.hpp
@@ -3,7 +3,7 @@
namespace floormat {
-struct tile_atlas;
+class tile_atlas;
using variant_t = uint8_t;
diff --git a/src/tile.hpp b/src/tile.hpp
index f9d6adc8..fbe2e93d 100644
--- a/src/tile.hpp
+++ b/src/tile.hpp
@@ -4,7 +4,7 @@
namespace floormat {
struct chunk;
-struct anim_atlas;
+class anim_atlas;
struct tile_proto final
{
diff --git a/src/wall-atlas.cpp b/src/wall-atlas.cpp
index 31659cca..3c2ac3cf 100644
--- a/src/wall-atlas.cpp
+++ b/src/wall-atlas.cpp
@@ -70,15 +70,13 @@ Vector2i wall_atlas::expected_size(int depth, Tag group)
}
}
-wall_atlas::wall_atlas(Info info, const ImageView2D& img,
- Array<Frame> frames,
- Array<Direction> directions,
- std::array<DirArrayIndex, 4> direction_to_DirArrayIndex)
- : _dir_array{ std::move(directions) }, _frame_array{ std::move(frames) },
- _info{ std::move(info) },
- _direction_to_Direction_array_index{ direction_to_DirArrayIndex }
+wall_atlas::wall_atlas(wall_atlas_def def, String path, const ImageView2D& img)
+ : _dir_array{std::move(def.direction_array)},
+ _frame_array{std::move(def.frames)},
+ _info{std::move(def.header)}, _path{std::move(path)},
+ _direction_to_Direction_array_index{def.direction_to_Direction_array_index}
{
- _texture.setLabel(_info.name)
+ _texture.setLabel(_path)
.setWrapping(GL::SamplerWrapping::ClampToEdge)
.setMagnificationFilter(GL::SamplerFilter::Nearest)
.setMinificationFilter(GL::SamplerFilter::Linear)
@@ -149,9 +147,7 @@ auto wall_atlas::direction(size_t dir) const -> const Direction*
uint8_t wall_atlas::direction_count() const { return (uint8_t)_dir_array.size(); }
auto wall_atlas::raw_frame_array() const -> ArrayView<const Frame> { return _frame_array; }
-auto wall_atlas::info() const -> const Info& { return _info; }
GL::Texture2D& wall_atlas::texture() { fm_debug_assert(_texture.id()); return _texture; }
-StringView wall_atlas::name() const { return _info.name; }
size_t wall_atlas::enum_to_index(enum rotation r)
{
diff --git a/src/wall-atlas.hpp b/src/wall-atlas.hpp
index 6a0abf15..e3470a56 100644
--- a/src/wall-atlas.hpp
+++ b/src/wall-atlas.hpp
@@ -67,7 +67,7 @@ struct Direction
struct Info
{
- String name = "(unnamed)"_s, description = {};
+ String name;
unsigned depth = 0;
bool operator==(const Info&) const noexcept;
@@ -75,7 +75,7 @@ struct Info
struct DirArrayIndex {
std::uint8_t val = (uint8_t)-1;
- operator bool() const { return val == (uint8_t)-1; }
+ operator bool() const { return val != (uint8_t)-1; }
bool operator==(const DirArrayIndex&) const noexcept;
};
@@ -84,6 +84,19 @@ struct DirArrayIndex {
namespace floormat {
+struct wall_atlas_def final
+{
+ bool operator==(const wall_atlas_def&) const noexcept;
+
+ Wall::Info header;
+ Array<Wall::Frame> frames;
+ Array<Wall::Direction> direction_array;
+ std::array<Wall::DirArrayIndex, 4> direction_to_Direction_array_index;
+
+ static wall_atlas_def deserialize(StringView filename);
+ void serialize(StringView filename) const;
+};
+
class wall_atlas final
{
using Frame = Wall::Frame;
@@ -97,6 +110,7 @@ class wall_atlas final
Array<Direction> _dir_array;
Array<Frame> _frame_array;
Info _info;
+ String _path;
GL::Texture2D _texture{NoCreate};
std::array<DirArrayIndex, 4> _direction_to_Direction_array_index;
@@ -106,19 +120,21 @@ public:
fm_DECLARE_DELETED_MOVE_ASSIGNMENT(wall_atlas);
wall_atlas() noexcept;
~wall_atlas() noexcept;
- wall_atlas(Info info, const ImageView2D& img,
- Array<Frame> frames, Array<Direction> directions,
- std::array<DirArrayIndex, 4> direction_to_DirArrayIndex);
- StringView name() const;
- uint8_t direction_count() const;
+ wall_atlas(wall_atlas_def def, String path, const ImageView2D& img);
+ void serialize(StringView filename) const;
const Group* group(size_t dir, Tag tag) const;
const Group* group(const Direction& dir, Tag tag) const;
const Group* group(const Direction* dir, Tag tag) const;
const Direction* direction(size_t dir) const;
+ uint8_t direction_count() const;
ArrayView<const Frame> frames(const Group& a) const;
ArrayView<const Frame> raw_frame_array() const;
- const Info& info() const;
+
+ const Info& info() const { return _info; }
+ StringView name() const { return _info.name; }
+ //StringView path() const { return _path; }
+
GL::Texture2D& texture();
static size_t enum_to_index(enum rotation x);