diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2024-02-04 13:14:25 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2024-02-04 13:14:25 +0100 |
commit | 22c0347382db21803cbeaf599a473b1d13b009a3 (patch) | |
tree | e700d33fa247600f69d2016405109aabae15ab71 | |
parent | f8af6aadbf67bd2ff459d3e8fb09364342a8d080 (diff) |
b
-rw-r--r-- | draw/anim.hpp | 2 | ||||
-rw-r--r-- | draw/ground.hpp | 2 | ||||
-rw-r--r-- | draw/wall.hpp | 2 | ||||
-rw-r--r-- | editor/app.hpp | 2 | ||||
-rw-r--r-- | floormat/app.hpp | 2 | ||||
-rw-r--r-- | shaders/lightmap.hpp | 2 | ||||
-rw-r--r-- | src/chunk-collision.cpp | 4 | ||||
-rw-r--r-- | src/chunk-render.cpp | 2 | ||||
-rw-r--r-- | src/chunk-walls.cpp | 8 | ||||
-rw-r--r-- | src/chunk.hpp | 3 | ||||
-rw-r--r-- | src/critter.cpp | 2 | ||||
-rw-r--r-- | src/critter.hpp | 2 | ||||
-rw-r--r-- | src/light.cpp | 2 | ||||
-rw-r--r-- | src/light.hpp | 2 | ||||
-rw-r--r-- | src/object.cpp | 8 | ||||
-rw-r--r-- | src/object.hpp | 8 | ||||
-rw-r--r-- | src/path-search.hpp | 2 | ||||
-rw-r--r-- | src/raycast.cpp | 3 | ||||
-rw-r--r-- | src/scenery.cpp | 10 | ||||
-rw-r--r-- | src/scenery.hpp | 12 | ||||
-rw-r--r-- | src/tile.cpp | 2 | ||||
-rw-r--r-- | src/tile.hpp | 10 | ||||
-rw-r--r-- | test/app.hpp | 2 |
23 files changed, 48 insertions, 46 deletions
diff --git a/draw/anim.hpp b/draw/anim.hpp index e9ac5f89..a19af1e1 100644 --- a/draw/anim.hpp +++ b/draw/anim.hpp @@ -18,7 +18,7 @@ namespace floormat { struct tile_shader; class anim_atlas; -struct chunk; +class chunk; struct clickable; struct object; diff --git a/draw/ground.hpp b/draw/ground.hpp index c3569121..3db92756 100644 --- a/draw/ground.hpp +++ b/draw/ground.hpp @@ -3,7 +3,7 @@ namespace floormat { struct tile_shader; -struct chunk; +class chunk; struct ground_mesh { diff --git a/draw/wall.hpp b/draw/wall.hpp index 89d3d3ac..ca25f9db 100644 --- a/draw/wall.hpp +++ b/draw/wall.hpp @@ -3,7 +3,7 @@ namespace floormat { struct tile_shader; -struct chunk; +class chunk; struct wall_mesh { diff --git a/editor/app.hpp b/editor/app.hpp index 2e4eb15c..ea618bac 100644 --- a/editor/app.hpp +++ b/editor/app.hpp @@ -32,7 +32,7 @@ namespace floormat { struct fm_settings; struct floormat_main; class world; -struct chunk; +class chunk; class ground_atlas; class anim_atlas; struct object; diff --git a/floormat/app.hpp b/floormat/app.hpp index 91ca9a8b..c07c48e1 100644 --- a/floormat/app.hpp +++ b/floormat/app.hpp @@ -14,7 +14,7 @@ union any_event; struct chunk_coords; struct chunk_coords_; -struct chunk; +class chunk; struct floormat_app { diff --git a/shaders/lightmap.hpp b/shaders/lightmap.hpp index b8bbd0c7..4169b974 100644 --- a/shaders/lightmap.hpp +++ b/shaders/lightmap.hpp @@ -30,7 +30,7 @@ struct light_s final bool operator==(const light_s&) const noexcept; }; -struct chunk; +class chunk; struct lightmap_shader final : GL::AbstractShaderProgram { diff --git a/src/chunk-collision.cpp b/src/chunk-collision.cpp index 5ffbf0ec..cfb157a9 100644 --- a/src/chunk-collision.cpp +++ b/src/chunk-collision.cpp @@ -53,13 +53,13 @@ void chunk::ensure_passability() noexcept auto tile = operator[](i); if (const auto* atlas = tile.wall_north_atlas().get()) { - auto [min, max] = wall_north(i, atlas->info().depth); + auto [min, max] = wall_north(i, (float)atlas->info().depth); auto id = make_id(collision_type::geometry, atlas->info().passability, TILE_COUNT+i+1); _rtree->Insert(min.data(), max.data(), id); } if (const auto* atlas = tile.wall_west_atlas().get()) { - auto [min, max] = wall_west(i, atlas->info().depth); + auto [min, max] = wall_west(i, (float)atlas->info().depth); auto id = make_id(collision_type::geometry, atlas->info().passability, TILE_COUNT*2+i+1); _rtree->Insert(min.data(), max.data(), id); } diff --git a/src/chunk-render.cpp b/src/chunk-render.cpp index c5dd068a..b445eff9 100644 --- a/src/chunk-render.cpp +++ b/src/chunk-render.cpp @@ -55,7 +55,7 @@ auto chunk::ensure_ground_mesh() noexcept -> ground_mesh_tuple return _ground->atlases[a] < _ground->atlases[b]; }); - float hack_offset = _coord.z <= 0 ? -16 : 0; // XXX hack + float hack_offset = _coord.z <= 0 ? -16.f : 0.f; // XXX hack auto& vertexes = static_vertexes; for (auto k = 0uz; k < count; k++) diff --git a/src/chunk-walls.cpp b/src/chunk-walls.cpp index 6f17fc06..674d0a65 100644 --- a/src/chunk-walls.cpp +++ b/src/chunk-walls.cpp @@ -245,7 +245,7 @@ GL::Mesh chunk::make_wall_mesh() const auto depth_offset = depth_offset_for_group(Group_::corner, is_west); const auto pos_x = !is_west ? (float)pos.x : (float)pos.x - 1; const auto depth = tile_shader::depth_value(pos_x, pos.y, depth_offset); - variant += !is_west ? frames.size() - 1 : 1; + variant += variant_t(!is_west ? frames.size() - 1 : 1); fm_assert((size_t)(variant_t)frames.size() == frames.size()); variant = variant % (variant_t)frames.size(); const auto& frame = frames[variant]; @@ -254,7 +254,7 @@ GL::Mesh chunk::make_wall_mesh() fm_assert(i < vertexes.size()); _walls->mesh_indexes[i] = (uint16_t)k; auto& v = vertexes[i]; - auto quad = get_quad(D, Group_::corner, Depth); + auto quad = get_quad(D, Group_::corner, (float)Depth); for (auto& v : quad) v += center; for (uint8_t j = 0; j < 4; j++) @@ -266,7 +266,7 @@ GL::Mesh chunk::make_wall_mesh() auto variant = (variant_ != (uint8_t)-1 ? variant_ : vpos); const auto depth_offset = depth_offset_for_group(Group_::corner, is_west); const auto depth = tile_shader::depth_value(!is_west ? (float)pos.x : (float)pos.x - 1, depth_offset); - variant += !is_west ? frames.size() - 1 : 1; + variant += variant_t(!is_west ? frames.size() - 1 : 1); variant %= frames.size(); const auto& frame = frames[variant]; fm_assert(frame.size.x() > Depth); @@ -299,7 +299,7 @@ GL::Mesh chunk::make_wall_mesh() const auto texcoords = Quads::texcoords_at(frame.offset, frame.size, atlas->image_size()); const auto depth_offset = depth_offset_for_group(G, is_west); const auto depth = tile_shader::depth_value(pos, depth_offset); - auto quad = get_quad(D, G, Depth); + auto quad = get_quad(D, G, (float)Depth); for (auto& v : quad) v += center; auto& v = vertexes[i]; diff --git a/src/chunk.hpp b/src/chunk.hpp index 75fe4bc7..3e142abf 100644 --- a/src/chunk.hpp +++ b/src/chunk.hpp @@ -21,8 +21,9 @@ struct object_proto; class tile_iterator; class tile_const_iterator; -struct chunk final +class chunk final { +public: friend struct tile_ref; friend struct object; friend class world; diff --git a/src/critter.cpp b/src/critter.cpp index 3615589e..97a0850f 100644 --- a/src/critter.cpp +++ b/src/critter.cpp @@ -226,7 +226,7 @@ critter::operator critter_proto() const return ret; } -critter::critter(object_id id, struct chunk& c, const critter_proto& proto) : +critter::critter(object_id id, class chunk& c, const critter_proto& proto) : object{id, c, proto}, name{proto.name}, playable{proto.playable} diff --git a/src/critter.hpp b/src/critter.hpp index 29b29a84..00e01cd1 100644 --- a/src/critter.hpp +++ b/src/critter.hpp @@ -40,7 +40,7 @@ private: int allocate_frame_time(float dt); friend class world; - critter(object_id id, struct chunk& c, const critter_proto& proto); + critter(object_id id, class chunk& c, const critter_proto& proto); }; template<> struct object_type_<struct critter> : std::integral_constant<object_type, object_type::critter> {}; diff --git a/src/light.cpp b/src/light.cpp index ec4a5cb1..878a5f19 100644 --- a/src/light.cpp +++ b/src/light.cpp @@ -17,7 +17,7 @@ light_proto& light_proto::operator=(const light_proto&) = default; light_proto::~light_proto() noexcept = default; bool light_proto::operator==(const light_proto&) const = default; -light::light(object_id id, struct chunk& c, const light_proto& proto) : +light::light(object_id id, class chunk& c, const light_proto& proto) : object{id, c, proto}, max_distance{proto.max_distance}, color{proto.color}, diff --git a/src/light.hpp b/src/light.hpp index 7fc429ea..92da2a19 100644 --- a/src/light.hpp +++ b/src/light.hpp @@ -28,7 +28,7 @@ struct light final : object light_falloff falloff : 2; uint8_t enabled : 1; - light(object_id id, struct chunk& c, const light_proto& proto); + light(object_id id, class chunk& c, const light_proto& proto); Vector2 ordinal_offset(Vector2b offset) const override; float depth_offset() const override; diff --git a/src/object.cpp b/src/object.cpp index ce3bb51f..b079c9ef 100644 --- a/src/object.cpp +++ b/src/object.cpp @@ -49,7 +49,7 @@ object_proto::object_proto() = default; object_proto::object_proto(const object_proto&) = default; object_type object_proto::type_of() const noexcept { return type; } -object::object(object_id id, struct chunk& c, const object_proto& proto) : +object::object(object_id id, class chunk& c, const object_proto& proto) : id{id}, c{&c}, atlas{proto.atlas}, offset{proto.offset}, bbox_offset{proto.bbox_offset}, bbox_size{proto.bbox_size}, delta{proto.delta}, @@ -87,7 +87,7 @@ float object::ordinal(local_coords xy, Vector2b offset, Vector2s z_offset) const return vec[0] + vec[1] + Vector2(z_offset).sum(); } -struct chunk& object::chunk() const +class chunk& object::chunk() const { return *c; } @@ -159,7 +159,7 @@ point object::normalize_coords(const point& pt, Vector2i delta) } template<bool neighbor = true> -static bool do_search(struct chunk* c, chunk_coords_ coord, +static bool do_search(class chunk* c, chunk_coords_ coord, object_id id, Vector2 min, Vector2 max, Vector2b off = {}) { if constexpr(neighbor) @@ -259,7 +259,7 @@ void object::move_to(size_t& i, Vector2i delta, rotation new_r) const_cast<global_coords&>(coord) = coord_; set_bbox_(offset_, bb_offset, bb_size, pass); const_cast<rotation&>(r) = new_r; - const_cast<struct chunk*&>(c) = &c2; + const_cast<class chunk*&>(c) = &c2; i = (size_t)std::distance(es.cbegin(), it); arrayInsert(es, i, std::move(e_)); } diff --git a/src/object.hpp b/src/object.hpp index 7d9ce9f0..6db9d8bc 100644 --- a/src/object.hpp +++ b/src/object.hpp @@ -13,7 +13,7 @@ namespace floormat { template<typename T> struct object_type_; class anim_atlas; class world; -struct chunk; +class chunk; struct object_proto { @@ -41,7 +41,7 @@ struct object fm_DECLARE_DELETED_COPY_ASSIGNMENT(object); const object_id id = 0; - struct chunk* const c; + class chunk* const c; const std::shared_ptr<anim_atlas> atlas; const global_coords coord; const Vector2b offset, bbox_offset; @@ -57,7 +57,7 @@ struct object virtual float depth_offset() const = 0; float ordinal() const; float ordinal(local_coords xy, Vector2b offset, Vector2s z_offset) const; - struct chunk& chunk() const; + class chunk& chunk() const; size_t index() const; virtual bool is_virtual() const; point position() const; @@ -84,7 +84,7 @@ struct object void move_to(Vector2i delta); protected: - object(object_id id, struct chunk& c, const object_proto& proto); + object(object_id id, class chunk& c, const object_proto& proto); void set_bbox_(Vector2b offset, Vector2b bbox_offset, Vector2ub bbox_size, pass_mode pass); }; diff --git a/src/path-search.hpp b/src/path-search.hpp index 512a507f..42d99d4d 100644 --- a/src/path-search.hpp +++ b/src/path-search.hpp @@ -19,7 +19,7 @@ namespace floormat { class world; struct object; -struct chunk; +class chunk; // todo add pathfinding sub-namespace diff --git a/src/raycast.cpp b/src/raycast.cpp index dc04291a..eb3fb094 100644 --- a/src/raycast.cpp +++ b/src/raycast.cpp @@ -4,6 +4,7 @@ #include "src/object.hpp" #include "src/RTree-search.hpp" #include <cfloat> +#include <bit> #include <Corrade/Containers/StructuredBindings.h> #include <Corrade/Containers/GrowableArray.h> #include <Magnum/Math/Functions.h> @@ -17,7 +18,7 @@ template<typename T> constexpr inline auto tile_size = Math::Vector2<T>{iTILE_SI template<typename T> constexpr inline auto chunk_size = Math::Vector2<T>{TILE_MAX_DIM} * tile_size<T>; using floormat::detail_rc::bbox; -using RTree = std::decay_t<decltype(*std::declval<struct chunk>().rtree())>; +using RTree = std::decay_t<decltype(*std::declval<class chunk>().rtree())>; using Rect = typename RTree::Rect; template<class T> constexpr inline T sign_(auto&& x) { diff --git a/src/scenery.cpp b/src/scenery.cpp index e384036d..9adae347 100644 --- a/src/scenery.cpp +++ b/src/scenery.cpp @@ -65,7 +65,7 @@ enum scenery_type scenery_proto::scenery_type() const generic_scenery::operator generic_scenery_proto() const { return { .active = active, .interactive = interactive, }; } -generic_scenery::generic_scenery(object_id, struct chunk&, const generic_scenery_proto& p) : +generic_scenery::generic_scenery(object_id, class chunk&, const generic_scenery_proto& p) : active{p.active}, interactive{p.interactive} {} @@ -75,7 +75,7 @@ enum scenery_type door_scenery_proto::scenery_type() const { return scenery_type enum scenery_type door_scenery::scenery_type() const { return scenery_type::door; } door_scenery::operator door_scenery_proto() const { return { .active = active, .interactive = interactive, .closing = closing, }; } -door_scenery::door_scenery(object_id, struct chunk&, const door_scenery_proto& p) : +door_scenery::door_scenery(object_id, class chunk&, const door_scenery_proto& p) : closing{p.closing}, active{p.active}, interactive{p.interactive} {} @@ -237,7 +237,7 @@ enum scenery_type scenery::scenery_type() const ); } -scenery_variants scenery::subtype_from_proto(object_id id, struct chunk& c, const scenery_proto_variants& variant) +scenery_variants scenery::subtype_from_proto(object_id id, class chunk& c, const scenery_proto_variants& variant) { return std::visit( [&]<typename T>(const T& p) { @@ -247,7 +247,7 @@ scenery_variants scenery::subtype_from_proto(object_id id, struct chunk& c, cons ); } -scenery_variants scenery::subtype_from_scenery_type(object_id id, struct chunk& c, enum scenery_type type) +scenery_variants scenery::subtype_from_scenery_type(object_id id, class chunk& c, enum scenery_type type) { switch (type) { @@ -261,7 +261,7 @@ scenery_variants scenery::subtype_from_scenery_type(object_id id, struct chunk& fm_throw("invalid scenery type"_cf, (int)type); } -scenery::scenery(object_id id, struct chunk& c, const scenery_proto& proto) : +scenery::scenery(object_id id, class chunk& c, const scenery_proto& proto) : object{id, c, proto}, subtype{ subtype_from_proto(id, c, proto.subtype) } { #ifndef FM_NO_DEBUG diff --git a/src/scenery.hpp b/src/scenery.hpp index c462a433..e6e483fa 100644 --- a/src/scenery.hpp +++ b/src/scenery.hpp @@ -14,7 +14,7 @@ namespace floormat { template<typename... Ts> struct [[maybe_unused]] overloaded : Ts... { using Ts::operator()...; }; template<typename... Ts> overloaded(Ts...) -> overloaded<Ts...>; -struct chunk; +class chunk; class anim_atlas; class world; @@ -71,7 +71,7 @@ struct generic_scenery enum scenery_type scenery_type() const; explicit operator generic_scenery_proto() const; - generic_scenery(object_id id, struct chunk& c, const generic_scenery_proto& p); + generic_scenery(object_id id, class chunk& c, const generic_scenery_proto& p); }; struct door_scenery @@ -88,7 +88,7 @@ struct door_scenery enum scenery_type scenery_type() const; explicit operator door_scenery_proto() const; - door_scenery(object_id id, struct chunk& c, const door_scenery_proto& p); + door_scenery(object_id id, class chunk& c, const door_scenery_proto& p); }; using scenery_variants = std::variant<generic_scenery, door_scenery>; @@ -107,12 +107,12 @@ struct scenery final : object explicit operator scenery_proto() const; enum scenery_type scenery_type() const; - static scenery_variants subtype_from_proto(object_id id, struct chunk& c, const scenery_proto_variants& variants); - static scenery_variants subtype_from_scenery_type(object_id id, struct chunk& c, enum scenery_type type); + static scenery_variants subtype_from_proto(object_id id, class chunk& c, const scenery_proto_variants& variants); + static scenery_variants subtype_from_scenery_type(object_id id, class chunk& c, enum scenery_type type); private: friend class world; - scenery(object_id id, struct chunk& c, const scenery_proto& proto); + scenery(object_id id, class chunk& c, const scenery_proto& proto); }; template<> struct object_type_<scenery> : std::integral_constant<object_type, object_type::scenery> {}; diff --git a/src/tile.cpp b/src/tile.cpp index 91fb73aa..1f36d5b4 100644 --- a/src/tile.cpp +++ b/src/tile.cpp @@ -21,7 +21,7 @@ tile_image_proto tile_proto::ground() const noexcept { return { ground_atlas wall_image_proto tile_proto::wall_north() const noexcept { return { wall_north_atlas, wall_north_variant }; } wall_image_proto tile_proto::wall_west() const noexcept { return { wall_west_atlas, wall_west_variant }; } -tile_ref::tile_ref(struct chunk& c, uint8_t i) noexcept : _chunk{&c}, i{i} {} +tile_ref::tile_ref(class chunk& c, uint8_t i) noexcept : _chunk{&c}, i{i} {} std::shared_ptr<class ground_atlas> tile_ref::ground_atlas() noexcept { return _chunk->_ground ? _chunk->_ground->atlases[i] : nullptr; } std::shared_ptr<class wall_atlas> tile_ref::wall_north_atlas() noexcept { return _chunk->_walls ? _chunk->_walls->atlases[i*2+0] : nullptr; } diff --git a/src/tile.hpp b/src/tile.hpp index 3f691567..43170fe7 100644 --- a/src/tile.hpp +++ b/src/tile.hpp @@ -3,7 +3,7 @@ namespace floormat { -struct chunk; +class chunk; class anim_atlas; struct tile_proto final @@ -21,7 +21,7 @@ struct tile_proto final struct tile_ref final { - tile_ref(struct chunk& c, uint8_t i) noexcept; + tile_ref(class chunk& c, uint8_t i) noexcept; tile_image_ref ground() noexcept; wall_image_ref wall_north() noexcept; @@ -41,14 +41,14 @@ struct tile_ref final explicit operator tile_proto() const noexcept; - struct chunk& chunk() noexcept { return *_chunk; } - const struct chunk& chunk() const noexcept { return *_chunk; } + class chunk& chunk() noexcept { return *_chunk; } + const class chunk& chunk() const noexcept { return *_chunk; } size_t index() const noexcept { return i; } friend bool operator==(const tile_ref& a, const tile_ref& b) noexcept; private: - struct chunk* _chunk; + class chunk* _chunk; uint8_t i; }; diff --git a/test/app.hpp b/test/app.hpp index bd31fdf7..2ddd4bfc 100644 --- a/test/app.hpp +++ b/test/app.hpp @@ -8,7 +8,7 @@ namespace floormat { struct chunk_coords; struct chunk_coords_; -struct chunk; +class chunk; class world; struct test_app final : private FM_APPLICATION |